ctkRangeWidget.cpp 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685
  1. /*=========================================================================
  2. Library: CTK
  3. Copyright (c) Kitware Inc.
  4. Licensed under the Apache License, Version 2.0 (the "License");
  5. you may not use this file except in compliance with the License.
  6. You may obtain a copy of the License at
  7. http://www.commontk.org/LICENSE
  8. Unless required by applicable law or agreed to in writing, software
  9. distributed under the License is distributed on an "AS IS" BASIS,
  10. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  11. See the License for the specific language governing permissions and
  12. limitations under the License.
  13. =========================================================================*/
  14. // Qt includes
  15. #include <QDebug>
  16. #include <QMouseEvent>
  17. // CTK includes
  18. #include "ctkRangeWidget.h"
  19. #include "ui_ctkRangeWidget.h"
  20. //-----------------------------------------------------------------------------
  21. class ctkRangeWidgetPrivate: public Ui_ctkRangeWidget
  22. {
  23. Q_DECLARE_PUBLIC(ctkRangeWidget);
  24. protected:
  25. ctkRangeWidget* const q_ptr;
  26. public:
  27. ctkRangeWidgetPrivate(ctkRangeWidget& object);
  28. void connectSlider();
  29. void updateSpinBoxWidth();
  30. int synchronizedSpinBoxWidth()const;
  31. void synchronizeSiblingSpinBox(int newWidth);
  32. static bool equal(double v1, double v2);
  33. void relayout();
  34. bool Tracking;
  35. bool Changing;
  36. bool SettingRange;
  37. double MinimumValueBeforeChange;
  38. double MaximumValueBeforeChange;
  39. bool AutoSpinBoxWidth;
  40. Qt::Alignment SpinBoxAlignment;
  41. };
  42. // --------------------------------------------------------------------------
  43. bool ctkRangeWidgetPrivate::equal(double v1, double v2)
  44. {
  45. return qAbs(v1 - v2) < 0.0001;
  46. }
  47. // --------------------------------------------------------------------------
  48. ctkRangeWidgetPrivate::ctkRangeWidgetPrivate(ctkRangeWidget& object)
  49. :q_ptr(&object)
  50. {
  51. this->Tracking = true;
  52. this->Changing = false;
  53. this->SettingRange = false;
  54. this->MinimumValueBeforeChange = 0.;
  55. this->MaximumValueBeforeChange = 0.;
  56. this->AutoSpinBoxWidth = true;
  57. this->SpinBoxAlignment = Qt::AlignVCenter;
  58. }
  59. // --------------------------------------------------------------------------
  60. void ctkRangeWidgetPrivate::connectSlider()
  61. {
  62. Q_Q(ctkRangeWidget);
  63. QObject::connect(this->Slider, SIGNAL(valuesChanged(double, double)),
  64. q, SLOT(changeValues(double,double)));
  65. QObject::connect(this->Slider, SIGNAL(minimumValueChanged(double)),
  66. q, SLOT(changeMinimumValue(double)));
  67. QObject::connect(this->Slider, SIGNAL(maximumValueChanged(double)),
  68. q, SLOT(changeMaximumValue(double)));
  69. QObject::connect(this->MinimumSpinBox, SIGNAL(valueChanged(double)),
  70. this->Slider, SLOT(setMinimumValue(double)));
  71. QObject::connect(this->MaximumSpinBox, SIGNAL(valueChanged(double)),
  72. this->Slider, SLOT(setMaximumValue(double)));
  73. QObject::connect(this->MinimumSpinBox, SIGNAL(valueChanged(double)),
  74. q, SLOT(setMinimumToMaximumSpinBox(double)));
  75. QObject::connect(this->MaximumSpinBox, SIGNAL(valueChanged(double)),
  76. q, SLOT(setMaximumToMinimumSpinBox(double)));
  77. QObject::connect(this->Slider, SIGNAL(sliderPressed()),
  78. q, SLOT(startChanging()));
  79. QObject::connect(this->Slider, SIGNAL(sliderReleased()),
  80. q, SLOT(stopChanging()));
  81. QObject::connect(this->Slider, SIGNAL(rangeChanged(double, double)),
  82. q, SLOT(onSliderRangeChanged(double, double)));
  83. }
  84. // --------------------------------------------------------------------------
  85. void ctkRangeWidgetPrivate::updateSpinBoxWidth()
  86. {
  87. int spinBoxWidth = this->synchronizedSpinBoxWidth();
  88. if (this->AutoSpinBoxWidth)
  89. {
  90. this->MinimumSpinBox->setMinimumWidth(spinBoxWidth);
  91. this->MaximumSpinBox->setMinimumWidth(spinBoxWidth);
  92. }
  93. else
  94. {
  95. this->MinimumSpinBox->setMinimumWidth(0);
  96. this->MaximumSpinBox->setMinimumWidth(0);
  97. }
  98. this->synchronizeSiblingSpinBox(spinBoxWidth);
  99. }
  100. // --------------------------------------------------------------------------
  101. int ctkRangeWidgetPrivate::synchronizedSpinBoxWidth()const
  102. {
  103. Q_Q(const ctkRangeWidget);
  104. //Q_ASSERT(this->MinimumSpinBox->sizeHint() == this->MaximumSpinBox->sizeHint());
  105. int maxWidth = qMax(this->MinimumSpinBox->sizeHint().width(),
  106. this->MaximumSpinBox->sizeHint().width());
  107. if (!q->parent())
  108. {
  109. return maxWidth;
  110. }
  111. QList<ctkRangeWidget*> siblings =
  112. q->parent()->findChildren<ctkRangeWidget*>();
  113. foreach(ctkRangeWidget* sibling, siblings)
  114. {
  115. maxWidth = qMax(maxWidth, qMax(sibling->d_func()->MaximumSpinBox->sizeHint().width(),
  116. sibling->d_func()->MaximumSpinBox->sizeHint().width()));
  117. }
  118. return maxWidth;
  119. }
  120. // --------------------------------------------------------------------------
  121. void ctkRangeWidgetPrivate::synchronizeSiblingSpinBox(int width)
  122. {
  123. Q_Q(const ctkRangeWidget);
  124. QList<ctkRangeWidget*> siblings =
  125. q->parent()->findChildren<ctkRangeWidget*>();
  126. foreach(ctkRangeWidget* sibling, siblings)
  127. {
  128. if (sibling != q && sibling->isAutoSpinBoxWidth())
  129. {
  130. sibling->d_func()->MinimumSpinBox->setMinimumWidth(width);
  131. sibling->d_func()->MaximumSpinBox->setMinimumWidth(width);
  132. }
  133. }
  134. }
  135. // --------------------------------------------------------------------------
  136. void ctkRangeWidgetPrivate::relayout()
  137. {
  138. this->GridLayout->removeWidget(this->MinimumSpinBox);
  139. this->GridLayout->removeWidget(this->MaximumSpinBox);
  140. this->GridLayout->removeWidget(this->Slider);
  141. if (this->SpinBoxAlignment & Qt::AlignTop)
  142. {
  143. this->GridLayout->addWidget(this->MinimumSpinBox,0,0);
  144. this->GridLayout->addWidget(this->MaximumSpinBox,0,2);
  145. this->GridLayout->addWidget(this->Slider,1,0,1,3);
  146. }
  147. else if (this->SpinBoxAlignment & Qt::AlignVCenter)
  148. {
  149. this->GridLayout->addWidget(this->MinimumSpinBox,0,0);
  150. this->GridLayout->addWidget(this->Slider,0,1);
  151. this->GridLayout->addWidget(this->MaximumSpinBox,0,2);
  152. }
  153. else if (this->SpinBoxAlignment & Qt::AlignBottom)
  154. {
  155. this->GridLayout->addWidget(this->MinimumSpinBox,1,0);
  156. this->GridLayout->addWidget(this->MaximumSpinBox,1,2);
  157. this->GridLayout->addWidget(this->Slider,0, 0, 1, 3);
  158. }
  159. }
  160. // --------------------------------------------------------------------------
  161. ctkRangeWidget::ctkRangeWidget(QWidget* _parent) : Superclass(_parent)
  162. , d_ptr(new ctkRangeWidgetPrivate(*this))
  163. {
  164. Q_D(ctkRangeWidget);
  165. d->setupUi(this);
  166. d->MinimumSpinBox->setMinimum(d->Slider->minimum());
  167. d->MinimumSpinBox->setMaximum(d->Slider->maximum());
  168. d->MaximumSpinBox->setMinimum(d->Slider->minimum());
  169. d->MaximumSpinBox->setMaximum(d->Slider->maximum());
  170. d->MinimumSpinBox->setValue(d->Slider->minimumValue());
  171. d->MaximumSpinBox->setValue(d->Slider->maximumValue());
  172. d->connectSlider();
  173. d->MinimumSpinBox->installEventFilter(this);
  174. d->MaximumSpinBox->installEventFilter(this);
  175. }
  176. // --------------------------------------------------------------------------
  177. ctkRangeWidget::~ctkRangeWidget()
  178. {
  179. }
  180. // --------------------------------------------------------------------------
  181. double ctkRangeWidget::minimum()const
  182. {
  183. Q_D(const ctkRangeWidget);
  184. Q_ASSERT(d->equal(d->MinimumSpinBox->minimum(),d->Slider->minimum()));
  185. return d->Slider->minimum();
  186. }
  187. // --------------------------------------------------------------------------
  188. double ctkRangeWidget::maximum()const
  189. {
  190. Q_D(const ctkRangeWidget);
  191. Q_ASSERT(d->equal(d->MaximumSpinBox->maximum(), d->Slider->maximum()));
  192. return d->Slider->maximum();
  193. }
  194. // --------------------------------------------------------------------------
  195. void ctkRangeWidget::setMinimum(double min)
  196. {
  197. Q_D(ctkRangeWidget);
  198. d->MinimumSpinBox->setMinimum(min);
  199. // SpinBox can truncate min (depending on decimals).
  200. // use Spinbox's min to set Slider's min
  201. d->SettingRange = true;
  202. d->Slider->setMinimum(d->MinimumSpinBox->minimum());
  203. d->SettingRange = false;
  204. Q_ASSERT(d->equal(d->MinimumSpinBox->minimum(),d->Slider->minimum()));
  205. d->updateSpinBoxWidth();
  206. }
  207. // --------------------------------------------------------------------------
  208. void ctkRangeWidget::setMaximum(double max)
  209. {
  210. Q_D(ctkRangeWidget);
  211. d->MaximumSpinBox->setMaximum(max);
  212. // SpinBox can truncate max (depending on decimals).
  213. // use Spinbox's max to set Slider's max
  214. d->SettingRange = true;
  215. d->Slider->setMaximum(d->MaximumSpinBox->maximum());
  216. d->SettingRange = false;
  217. Q_ASSERT(d->equal(d->MaximumSpinBox->maximum(), d->Slider->maximum()));
  218. d->updateSpinBoxWidth();
  219. }
  220. // --------------------------------------------------------------------------
  221. void ctkRangeWidget::setRange(double min, double max)
  222. {
  223. Q_D(ctkRangeWidget);
  224. double oldMin = d->MinimumSpinBox->minimum();
  225. double oldMax = d->MaximumSpinBox->maximum();
  226. d->MinimumSpinBox->setMinimum(qMin(min,max));
  227. d->MaximumSpinBox->setMaximum(qMax(min,max));
  228. // SpinBox can truncate the range (depending on decimals).
  229. // use Spinbox's range to set Slider's range
  230. d->SettingRange = true;
  231. d->Slider->setRange(d->MinimumSpinBox->minimum(), d->MaximumSpinBox->maximum());
  232. d->SettingRange = false;
  233. Q_ASSERT(d->equal(d->MinimumSpinBox->minimum(), d->Slider->minimum()));
  234. Q_ASSERT(d->equal(d->MaximumSpinBox->maximum(), d->Slider->maximum()));
  235. d->updateSpinBoxWidth();
  236. if (oldMin != d->MinimumSpinBox->minimum() ||
  237. oldMax != d->MaximumSpinBox->maximum())
  238. {
  239. emit rangeChanged(d->MinimumSpinBox->minimum(), d->MaximumSpinBox->maximum());
  240. }
  241. }
  242. // --------------------------------------------------------------------------
  243. void ctkRangeWidget::onSliderRangeChanged(double min, double max)
  244. {
  245. Q_D(ctkRangeWidget);
  246. if (!d->SettingRange)
  247. {
  248. this->setRange(min, max);
  249. }
  250. }
  251. /*
  252. // --------------------------------------------------------------------------
  253. double ctkRangeWidget::sliderPosition()const
  254. {
  255. return d->Slider->sliderPosition();
  256. }
  257. // --------------------------------------------------------------------------
  258. void ctkRangeWidget::setSliderPosition(double position)
  259. {
  260. d->Slider->setSliderPosition(position);
  261. }
  262. */
  263. /*
  264. // --------------------------------------------------------------------------
  265. double ctkRangeWidget::previousSliderPosition()
  266. {
  267. return d->Slider->previousSliderPosition();
  268. }
  269. */
  270. // --------------------------------------------------------------------------
  271. void ctkRangeWidget::values(double &minValue, double &maxValue)const
  272. {
  273. Q_D(const ctkRangeWidget);
  274. Q_ASSERT(d->equal(d->Slider->minimumValue(), d->MinimumSpinBox->value()));
  275. Q_ASSERT(d->equal(d->Slider->maximumValue(), d->MaximumSpinBox->value()));
  276. minValue = d->Changing ? d->MinimumValueBeforeChange : d->Slider->minimumValue();
  277. maxValue = d->Changing ? d->MaximumValueBeforeChange : d->Slider->maximumValue();
  278. }
  279. // --------------------------------------------------------------------------
  280. double ctkRangeWidget::minimumValue()const
  281. {
  282. Q_D(const ctkRangeWidget);
  283. Q_ASSERT(d->equal(d->Slider->minimumValue(), d->MinimumSpinBox->value()));
  284. return d->Changing ? d->MinimumValueBeforeChange : d->Slider->minimumValue();
  285. }
  286. // --------------------------------------------------------------------------
  287. double ctkRangeWidget::maximumValue()const
  288. {
  289. Q_D(const ctkRangeWidget);
  290. Q_ASSERT(d->equal(d->Slider->maximumValue(), d->MaximumSpinBox->value()));
  291. return d->Changing ? d->MaximumValueBeforeChange : d->Slider->maximumValue();
  292. }
  293. // --------------------------------------------------------------------------
  294. void ctkRangeWidget::setMinimumValue(double _value)
  295. {
  296. Q_D(ctkRangeWidget);
  297. // disable the tracking temporally to emit the
  298. // signal valueChanged if changeValue() is called
  299. bool isChanging = d->Changing;
  300. d->Changing = false;
  301. d->MinimumSpinBox->setValue(_value);
  302. Q_ASSERT(d->equal(d->Slider->minimumValue(), d->MinimumSpinBox->value()));
  303. // restore the prop
  304. d->Changing = isChanging;
  305. }
  306. // --------------------------------------------------------------------------
  307. void ctkRangeWidget::setMaximumValue(double _value)
  308. {
  309. Q_D(ctkRangeWidget);
  310. // disable the tracking temporally to emit the
  311. // signal valueChanged if changeValue() is called
  312. bool isChanging = d->Changing;
  313. d->Changing = false;
  314. d->MaximumSpinBox->setValue(_value);
  315. Q_ASSERT(d->equal(d->Slider->maximumValue(), d->MaximumSpinBox->value()));
  316. // restore the prop
  317. d->Changing = isChanging;
  318. }
  319. // --------------------------------------------------------------------------
  320. void ctkRangeWidget::setValues(double newMinimumValue, double newMaximumValue)
  321. {
  322. Q_D(ctkRangeWidget);
  323. // disable the tracking temporally to emit the
  324. // signal valueChanged if changeValue() is called
  325. bool isChanging = d->Changing;
  326. d->Changing = false;
  327. // the pb here is that setting the spinbox separately will fired 2 signals and
  328. // between the state will be inconsistent
  329. d->MinimumSpinBox->setValue(newMinimumValue);
  330. d->MaximumSpinBox->setValue(newMaximumValue);
  331. Q_ASSERT(d->equal(d->Slider->minimumValue(), d->MinimumSpinBox->value()));
  332. Q_ASSERT(d->equal(d->Slider->maximumValue(), d->MaximumSpinBox->value()));
  333. // restore the prop
  334. d->Changing = isChanging;
  335. }
  336. // --------------------------------------------------------------------------
  337. void ctkRangeWidget::setMinimumToMaximumSpinBox(double minimum)
  338. {
  339. Q_D(ctkRangeWidget);
  340. d->MaximumSpinBox->setMinimum(minimum);
  341. }
  342. // --------------------------------------------------------------------------
  343. void ctkRangeWidget::setMaximumToMinimumSpinBox(double maximum)
  344. {
  345. Q_D(ctkRangeWidget);
  346. d->MinimumSpinBox->setMaximum(maximum);
  347. }
  348. // --------------------------------------------------------------------------
  349. void ctkRangeWidget::startChanging()
  350. {
  351. Q_D(ctkRangeWidget);
  352. if (d->Tracking)
  353. {
  354. return;
  355. }
  356. d->Changing = true;
  357. d->MinimumValueBeforeChange = this->minimumValue();
  358. d->MaximumValueBeforeChange = this->maximumValue();
  359. }
  360. // --------------------------------------------------------------------------
  361. void ctkRangeWidget::stopChanging()
  362. {
  363. Q_D(ctkRangeWidget);
  364. if (d->Tracking)
  365. {
  366. return;
  367. }
  368. d->Changing = false;
  369. bool emitMinValChanged = qAbs(this->minimumValue() - d->MinimumValueBeforeChange) > (this->singleStep() * 0.000000001);
  370. bool emitMaxValChanged = qAbs(this->maximumValue() - d->MaximumValueBeforeChange) > (this->singleStep() * 0.000000001);
  371. if (emitMinValChanged || emitMaxValChanged)
  372. {
  373. // emit the valuesChanged signal first
  374. emit this->valuesChanged(this->minimumValue(), this->maximumValue());
  375. }
  376. if (emitMinValChanged)
  377. {
  378. emit this->minimumValueChanged(this->minimumValue());
  379. }
  380. if (emitMaxValChanged)
  381. {
  382. emit this->maximumValueChanged(this->maximumValue());
  383. }
  384. }
  385. // --------------------------------------------------------------------------
  386. void ctkRangeWidget::changeMinimumValue(double newValue)
  387. {
  388. Q_D(ctkRangeWidget);
  389. //if (d->Tracking)
  390. {
  391. emit this->minimumValueIsChanging(newValue);
  392. }
  393. if (!d->Changing)
  394. {
  395. emit this->valuesChanged(newValue, this->maximumValue());
  396. emit this->minimumValueChanged(newValue);
  397. }
  398. }
  399. // --------------------------------------------------------------------------
  400. void ctkRangeWidget::changeMaximumValue(double newValue)
  401. {
  402. Q_D(ctkRangeWidget);
  403. //if (d->Tracking)
  404. {
  405. emit this->maximumValueIsChanging(newValue);
  406. }
  407. if (!d->Changing)
  408. {
  409. emit this->valuesChanged(this->minimumValue(), newValue);
  410. emit this->maximumValueChanged(newValue);
  411. }
  412. }
  413. // --------------------------------------------------------------------------
  414. void ctkRangeWidget::changeValues(double newMinValue, double newMaxValue)
  415. {
  416. Q_D(ctkRangeWidget);
  417. d->MinimumSpinBox->setValue(newMinValue);
  418. d->MaximumSpinBox->setValue(newMaxValue);
  419. }
  420. // --------------------------------------------------------------------------
  421. bool ctkRangeWidget::eventFilter(QObject *obj, QEvent *event)
  422. {
  423. if (event->type() == QEvent::MouseButtonPress)
  424. {
  425. QMouseEvent *mouseEvent = static_cast<QMouseEvent *>(event);
  426. if (mouseEvent->button() & Qt::LeftButton)
  427. {
  428. this->startChanging();
  429. }
  430. }
  431. else if (event->type() == QEvent::MouseButtonRelease)
  432. {
  433. QMouseEvent *mouseEvent = static_cast<QMouseEvent *>(event);
  434. if (mouseEvent->button() & Qt::LeftButton)
  435. {
  436. // here we might prevent ctkRangeWidget::stopChanging
  437. // from sending a valueChanged() event as the spinbox might
  438. // send a valueChanged() after eventFilter() is done.
  439. this->stopChanging();
  440. }
  441. }
  442. // standard event processing
  443. return this->Superclass::eventFilter(obj, event);
  444. }
  445. // --------------------------------------------------------------------------
  446. double ctkRangeWidget::singleStep()const
  447. {
  448. Q_D(const ctkRangeWidget);
  449. Q_ASSERT(d->equal(d->Slider->singleStep(), d->MinimumSpinBox->singleStep()) &&
  450. d->equal(d->Slider->singleStep(), d->MaximumSpinBox->singleStep()));
  451. return d->Slider->singleStep();
  452. }
  453. // --------------------------------------------------------------------------
  454. void ctkRangeWidget::setSingleStep(double step)
  455. {
  456. Q_D(ctkRangeWidget);
  457. d->MinimumSpinBox->setSingleStep(step);
  458. d->MaximumSpinBox->setSingleStep(step);
  459. d->Slider->setSingleStep(d->MinimumSpinBox->singleStep());
  460. Q_ASSERT(d->equal(d->Slider->singleStep(), d->MinimumSpinBox->singleStep()) &&
  461. d->equal(d->Slider->singleStep(), d->MaximumSpinBox->singleStep()));
  462. }
  463. // --------------------------------------------------------------------------
  464. int ctkRangeWidget::decimals()const
  465. {
  466. Q_D(const ctkRangeWidget);
  467. Q_ASSERT(d->MinimumSpinBox->decimals() == d->MaximumSpinBox->decimals());
  468. return d->MinimumSpinBox->decimals();
  469. }
  470. // --------------------------------------------------------------------------
  471. void ctkRangeWidget::setDecimals(int newDecimals)
  472. {
  473. Q_D(ctkRangeWidget);
  474. d->MinimumSpinBox->setDecimals(newDecimals);
  475. d->MaximumSpinBox->setDecimals(newDecimals);
  476. // The number of decimals can change the range values
  477. // i.e. 50.55 with 2 decimals -> 51 with 0 decimals
  478. // As the SpinBox range change doesn't fire signals,
  479. // we have to do the synchronization manually here
  480. d->Slider->setMinimum(d->MinimumSpinBox->minimum());
  481. d->Slider->setMaximum(d->MaximumSpinBox->maximum());
  482. }
  483. // --------------------------------------------------------------------------
  484. QString ctkRangeWidget::prefix()const
  485. {
  486. Q_D(const ctkRangeWidget);
  487. Q_ASSERT(d->MinimumSpinBox->prefix() == d->MaximumSpinBox->prefix());
  488. return d->MinimumSpinBox->prefix();
  489. }
  490. // --------------------------------------------------------------------------
  491. void ctkRangeWidget::setPrefix(const QString& newPrefix)
  492. {
  493. Q_D(ctkRangeWidget);
  494. d->MinimumSpinBox->setPrefix(newPrefix);
  495. d->MaximumSpinBox->setPrefix(newPrefix);
  496. }
  497. // --------------------------------------------------------------------------
  498. QString ctkRangeWidget::suffix()const
  499. {
  500. Q_D(const ctkRangeWidget);
  501. Q_ASSERT(d->MinimumSpinBox->suffix() == d->MaximumSpinBox->suffix());
  502. return d->MinimumSpinBox->suffix();
  503. }
  504. // --------------------------------------------------------------------------
  505. void ctkRangeWidget::setSuffix(const QString& newSuffix)
  506. {
  507. Q_D(ctkRangeWidget);
  508. d->MinimumSpinBox->setSuffix(newSuffix);
  509. d->MaximumSpinBox->setSuffix(newSuffix);
  510. }
  511. // --------------------------------------------------------------------------
  512. double ctkRangeWidget::tickInterval()const
  513. {
  514. Q_D(const ctkRangeWidget);
  515. return d->Slider->tickInterval();
  516. }
  517. // --------------------------------------------------------------------------
  518. void ctkRangeWidget::setTickInterval(double ti)
  519. {
  520. Q_D(ctkRangeWidget);
  521. d->Slider->setTickInterval(ti);
  522. }
  523. // -------------------------------------------------------------------------
  524. void ctkRangeWidget::reset()
  525. {
  526. this->setMinimumValue(this->minimum());
  527. this->setMaximumValue(this->maximum());
  528. }
  529. // -------------------------------------------------------------------------
  530. void ctkRangeWidget::setSpinBoxAlignment(Qt::Alignment alignment)
  531. {
  532. Q_D(ctkRangeWidget);
  533. if (d->SpinBoxAlignment == alignment)
  534. {
  535. return;
  536. }
  537. d->SpinBoxAlignment = alignment;
  538. d->relayout();
  539. }
  540. // -------------------------------------------------------------------------
  541. Qt::Alignment ctkRangeWidget::spinBoxAlignment()const
  542. {
  543. Q_D(const ctkRangeWidget);
  544. return d->SpinBoxAlignment;
  545. }
  546. // -------------------------------------------------------------------------
  547. void ctkRangeWidget::setSpinBoxTextAlignment(Qt::Alignment alignment)
  548. {
  549. Q_D(ctkRangeWidget);
  550. d->MinimumSpinBox->setAlignment(alignment);
  551. d->MaximumSpinBox->setAlignment(alignment);
  552. }
  553. // -------------------------------------------------------------------------
  554. Qt::Alignment ctkRangeWidget::spinBoxTextAlignment()const
  555. {
  556. Q_D(const ctkRangeWidget);
  557. Q_ASSERT(d->MinimumSpinBox->alignment() == d->MaximumSpinBox->alignment());
  558. return d->MinimumSpinBox->alignment();
  559. }
  560. // -------------------------------------------------------------------------
  561. void ctkRangeWidget::setTracking(bool enable)
  562. {
  563. Q_D(ctkRangeWidget);
  564. d->Tracking = enable;
  565. }
  566. // -------------------------------------------------------------------------
  567. bool ctkRangeWidget::hasTracking()const
  568. {
  569. Q_D(const ctkRangeWidget);
  570. return d->Tracking;
  571. }
  572. // -------------------------------------------------------------------------
  573. bool ctkRangeWidget::isAutoSpinBoxWidth()const
  574. {
  575. Q_D(const ctkRangeWidget);
  576. return d->AutoSpinBoxWidth;
  577. }
  578. // -------------------------------------------------------------------------
  579. void ctkRangeWidget::setAutoSpinBoxWidth(bool autoWidth)
  580. {
  581. Q_D(ctkRangeWidget);
  582. d->AutoSpinBoxWidth = autoWidth;
  583. d->updateSpinBoxWidth();
  584. }
  585. // -------------------------------------------------------------------------
  586. ctkDoubleRangeSlider* ctkRangeWidget::slider()const
  587. {
  588. Q_D(const ctkRangeWidget);
  589. return d->Slider;
  590. }
  591. // -------------------------------------------------------------------------
  592. void ctkRangeWidget::setSlider(ctkDoubleRangeSlider* slider)
  593. {
  594. Q_D(ctkRangeWidget);
  595. slider->setOrientation(d->Slider->orientation());
  596. slider->setMinimum(d->Slider->minimum());
  597. slider->setMaximum(d->Slider->maximum());
  598. slider->setValues(d->Slider->minimumValue(), d->Slider->maximumValue());
  599. slider->setSingleStep(d->Slider->singleStep());
  600. slider->setTracking(d->Slider->hasTracking());
  601. slider->setTickInterval(d->Slider->tickInterval());
  602. delete d->Slider;
  603. d->Slider = slider;
  604. d->connectSlider();
  605. d->relayout();
  606. }