ctkRangeWidget.cpp 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678
  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. d->MinimumSpinBox->setMinimum(qMin(min,max));
  225. d->MaximumSpinBox->setMaximum(qMax(min,max));
  226. // SpinBox can truncate the range (depending on decimals).
  227. // use Spinbox's range to set Slider's range
  228. d->SettingRange = true;
  229. d->Slider->setRange(d->MinimumSpinBox->minimum(), d->MaximumSpinBox->maximum());
  230. d->SettingRange = false;
  231. Q_ASSERT(d->equal(d->MinimumSpinBox->minimum(), d->Slider->minimum()));
  232. Q_ASSERT(d->equal(d->MaximumSpinBox->maximum(), d->Slider->maximum()));
  233. d->updateSpinBoxWidth();
  234. }
  235. // --------------------------------------------------------------------------
  236. void ctkRangeWidget::onSliderRangeChanged(double min, double max)
  237. {
  238. Q_D(ctkRangeWidget);
  239. if (!d->SettingRange)
  240. {
  241. this->setRange(min, max);
  242. }
  243. }
  244. /*
  245. // --------------------------------------------------------------------------
  246. double ctkRangeWidget::sliderPosition()const
  247. {
  248. return d->Slider->sliderPosition();
  249. }
  250. // --------------------------------------------------------------------------
  251. void ctkRangeWidget::setSliderPosition(double position)
  252. {
  253. d->Slider->setSliderPosition(position);
  254. }
  255. */
  256. /*
  257. // --------------------------------------------------------------------------
  258. double ctkRangeWidget::previousSliderPosition()
  259. {
  260. return d->Slider->previousSliderPosition();
  261. }
  262. */
  263. // --------------------------------------------------------------------------
  264. void ctkRangeWidget::values(double &minValue, double &maxValue)const
  265. {
  266. Q_D(const ctkRangeWidget);
  267. Q_ASSERT(d->equal(d->Slider->minimumValue(), d->MinimumSpinBox->value()));
  268. Q_ASSERT(d->equal(d->Slider->maximumValue(), d->MaximumSpinBox->value()));
  269. minValue = d->Changing ? d->MinimumValueBeforeChange : d->Slider->minimumValue();
  270. maxValue = d->Changing ? d->MaximumValueBeforeChange : d->Slider->maximumValue();
  271. }
  272. // --------------------------------------------------------------------------
  273. double ctkRangeWidget::minimumValue()const
  274. {
  275. Q_D(const ctkRangeWidget);
  276. Q_ASSERT(d->equal(d->Slider->minimumValue(), d->MinimumSpinBox->value()));
  277. return d->Changing ? d->MinimumValueBeforeChange : d->Slider->minimumValue();
  278. }
  279. // --------------------------------------------------------------------------
  280. double ctkRangeWidget::maximumValue()const
  281. {
  282. Q_D(const ctkRangeWidget);
  283. Q_ASSERT(d->equal(d->Slider->maximumValue(), d->MaximumSpinBox->value()));
  284. return d->Changing ? d->MaximumValueBeforeChange : d->Slider->maximumValue();
  285. }
  286. // --------------------------------------------------------------------------
  287. void ctkRangeWidget::setMinimumValue(double _value)
  288. {
  289. Q_D(ctkRangeWidget);
  290. // disable the tracking temporally to emit the
  291. // signal valueChanged if changeValue() is called
  292. bool isChanging = d->Changing;
  293. d->Changing = false;
  294. d->MinimumSpinBox->setValue(_value);
  295. Q_ASSERT(d->equal(d->Slider->minimumValue(), d->MinimumSpinBox->value()));
  296. // restore the prop
  297. d->Changing = isChanging;
  298. }
  299. // --------------------------------------------------------------------------
  300. void ctkRangeWidget::setMaximumValue(double _value)
  301. {
  302. Q_D(ctkRangeWidget);
  303. // disable the tracking temporally to emit the
  304. // signal valueChanged if changeValue() is called
  305. bool isChanging = d->Changing;
  306. d->Changing = false;
  307. d->MaximumSpinBox->setValue(_value);
  308. Q_ASSERT(d->equal(d->Slider->maximumValue(), d->MaximumSpinBox->value()));
  309. // restore the prop
  310. d->Changing = isChanging;
  311. }
  312. // --------------------------------------------------------------------------
  313. void ctkRangeWidget::setValues(double newMinimumValue, double newMaximumValue)
  314. {
  315. Q_D(ctkRangeWidget);
  316. // disable the tracking temporally to emit the
  317. // signal valueChanged if changeValue() is called
  318. bool isChanging = d->Changing;
  319. d->Changing = false;
  320. // the pb here is that setting the spinbox separately will fired 2 signals and
  321. // between the state will be inconsistent
  322. d->MinimumSpinBox->setValue(newMinimumValue);
  323. d->MaximumSpinBox->setValue(newMaximumValue);
  324. Q_ASSERT(d->equal(d->Slider->minimumValue(), d->MinimumSpinBox->value()));
  325. Q_ASSERT(d->equal(d->Slider->maximumValue(), d->MaximumSpinBox->value()));
  326. // restore the prop
  327. d->Changing = isChanging;
  328. }
  329. // --------------------------------------------------------------------------
  330. void ctkRangeWidget::setMinimumToMaximumSpinBox(double minimum)
  331. {
  332. Q_D(ctkRangeWidget);
  333. d->MaximumSpinBox->setMinimum(minimum);
  334. }
  335. // --------------------------------------------------------------------------
  336. void ctkRangeWidget::setMaximumToMinimumSpinBox(double maximum)
  337. {
  338. Q_D(ctkRangeWidget);
  339. d->MinimumSpinBox->setMaximum(maximum);
  340. }
  341. // --------------------------------------------------------------------------
  342. void ctkRangeWidget::startChanging()
  343. {
  344. Q_D(ctkRangeWidget);
  345. if (d->Tracking)
  346. {
  347. return;
  348. }
  349. d->Changing = true;
  350. d->MinimumValueBeforeChange = this->minimumValue();
  351. d->MaximumValueBeforeChange = this->maximumValue();
  352. }
  353. // --------------------------------------------------------------------------
  354. void ctkRangeWidget::stopChanging()
  355. {
  356. Q_D(ctkRangeWidget);
  357. if (d->Tracking)
  358. {
  359. return;
  360. }
  361. d->Changing = false;
  362. bool emitMinValChanged = qAbs(this->minimumValue() - d->MinimumValueBeforeChange) > (this->singleStep() * 0.000000001);
  363. bool emitMaxValChanged = qAbs(this->maximumValue() - d->MaximumValueBeforeChange) > (this->singleStep() * 0.000000001);
  364. if (emitMinValChanged || emitMaxValChanged)
  365. {
  366. // emit the valuesChanged signal first
  367. emit this->valuesChanged(this->minimumValue(), this->maximumValue());
  368. }
  369. if (emitMinValChanged)
  370. {
  371. emit this->minimumValueChanged(this->minimumValue());
  372. }
  373. if (emitMaxValChanged)
  374. {
  375. emit this->maximumValueChanged(this->maximumValue());
  376. }
  377. }
  378. // --------------------------------------------------------------------------
  379. void ctkRangeWidget::changeMinimumValue(double newValue)
  380. {
  381. Q_D(ctkRangeWidget);
  382. //if (d->Tracking)
  383. {
  384. emit this->minimumValueIsChanging(newValue);
  385. }
  386. if (!d->Changing)
  387. {
  388. emit this->valuesChanged(newValue, this->maximumValue());
  389. emit this->minimumValueChanged(newValue);
  390. }
  391. }
  392. // --------------------------------------------------------------------------
  393. void ctkRangeWidget::changeMaximumValue(double newValue)
  394. {
  395. Q_D(ctkRangeWidget);
  396. //if (d->Tracking)
  397. {
  398. emit this->maximumValueIsChanging(newValue);
  399. }
  400. if (!d->Changing)
  401. {
  402. emit this->valuesChanged(this->minimumValue(), newValue);
  403. emit this->maximumValueChanged(newValue);
  404. }
  405. }
  406. // --------------------------------------------------------------------------
  407. void ctkRangeWidget::changeValues(double newMinValue, double newMaxValue)
  408. {
  409. Q_D(ctkRangeWidget);
  410. d->MinimumSpinBox->setValue(newMinValue);
  411. d->MaximumSpinBox->setValue(newMaxValue);
  412. }
  413. // --------------------------------------------------------------------------
  414. bool ctkRangeWidget::eventFilter(QObject *obj, QEvent *event)
  415. {
  416. if (event->type() == QEvent::MouseButtonPress)
  417. {
  418. QMouseEvent *mouseEvent = static_cast<QMouseEvent *>(event);
  419. if (mouseEvent->button() & Qt::LeftButton)
  420. {
  421. this->startChanging();
  422. }
  423. }
  424. else if (event->type() == QEvent::MouseButtonRelease)
  425. {
  426. QMouseEvent *mouseEvent = static_cast<QMouseEvent *>(event);
  427. if (mouseEvent->button() & Qt::LeftButton)
  428. {
  429. // here we might prevent ctkRangeWidget::stopChanging
  430. // from sending a valueChanged() event as the spinbox might
  431. // send a valueChanged() after eventFilter() is done.
  432. this->stopChanging();
  433. }
  434. }
  435. // standard event processing
  436. return this->Superclass::eventFilter(obj, event);
  437. }
  438. // --------------------------------------------------------------------------
  439. double ctkRangeWidget::singleStep()const
  440. {
  441. Q_D(const ctkRangeWidget);
  442. Q_ASSERT(d->equal(d->Slider->singleStep(), d->MinimumSpinBox->singleStep()) &&
  443. d->equal(d->Slider->singleStep(), d->MaximumSpinBox->singleStep()));
  444. return d->Slider->singleStep();
  445. }
  446. // --------------------------------------------------------------------------
  447. void ctkRangeWidget::setSingleStep(double step)
  448. {
  449. Q_D(ctkRangeWidget);
  450. d->MinimumSpinBox->setSingleStep(step);
  451. d->MaximumSpinBox->setSingleStep(step);
  452. d->Slider->setSingleStep(d->MinimumSpinBox->singleStep());
  453. Q_ASSERT(d->equal(d->Slider->singleStep(), d->MinimumSpinBox->singleStep()) &&
  454. d->equal(d->Slider->singleStep(), d->MaximumSpinBox->singleStep()));
  455. }
  456. // --------------------------------------------------------------------------
  457. int ctkRangeWidget::decimals()const
  458. {
  459. Q_D(const ctkRangeWidget);
  460. Q_ASSERT(d->MinimumSpinBox->decimals() == d->MaximumSpinBox->decimals());
  461. return d->MinimumSpinBox->decimals();
  462. }
  463. // --------------------------------------------------------------------------
  464. void ctkRangeWidget::setDecimals(int newDecimals)
  465. {
  466. Q_D(ctkRangeWidget);
  467. d->MinimumSpinBox->setDecimals(newDecimals);
  468. d->MaximumSpinBox->setDecimals(newDecimals);
  469. // The number of decimals can change the range values
  470. // i.e. 50.55 with 2 decimals -> 51 with 0 decimals
  471. // As the SpinBox range change doesn't fire signals,
  472. // we have to do the synchronization manually here
  473. d->Slider->setMinimum(d->MinimumSpinBox->minimum());
  474. d->Slider->setMaximum(d->MaximumSpinBox->maximum());
  475. }
  476. // --------------------------------------------------------------------------
  477. QString ctkRangeWidget::prefix()const
  478. {
  479. Q_D(const ctkRangeWidget);
  480. Q_ASSERT(d->MinimumSpinBox->prefix() == d->MaximumSpinBox->prefix());
  481. return d->MinimumSpinBox->prefix();
  482. }
  483. // --------------------------------------------------------------------------
  484. void ctkRangeWidget::setPrefix(const QString& newPrefix)
  485. {
  486. Q_D(ctkRangeWidget);
  487. d->MinimumSpinBox->setPrefix(newPrefix);
  488. d->MaximumSpinBox->setPrefix(newPrefix);
  489. }
  490. // --------------------------------------------------------------------------
  491. QString ctkRangeWidget::suffix()const
  492. {
  493. Q_D(const ctkRangeWidget);
  494. Q_ASSERT(d->MinimumSpinBox->suffix() == d->MaximumSpinBox->suffix());
  495. return d->MinimumSpinBox->suffix();
  496. }
  497. // --------------------------------------------------------------------------
  498. void ctkRangeWidget::setSuffix(const QString& newSuffix)
  499. {
  500. Q_D(ctkRangeWidget);
  501. d->MinimumSpinBox->setSuffix(newSuffix);
  502. d->MaximumSpinBox->setSuffix(newSuffix);
  503. }
  504. // --------------------------------------------------------------------------
  505. double ctkRangeWidget::tickInterval()const
  506. {
  507. Q_D(const ctkRangeWidget);
  508. return d->Slider->tickInterval();
  509. }
  510. // --------------------------------------------------------------------------
  511. void ctkRangeWidget::setTickInterval(double ti)
  512. {
  513. Q_D(ctkRangeWidget);
  514. d->Slider->setTickInterval(ti);
  515. }
  516. // -------------------------------------------------------------------------
  517. void ctkRangeWidget::reset()
  518. {
  519. this->setMinimumValue(this->minimum());
  520. this->setMaximumValue(this->maximum());
  521. }
  522. // -------------------------------------------------------------------------
  523. void ctkRangeWidget::setSpinBoxAlignment(Qt::Alignment alignment)
  524. {
  525. Q_D(ctkRangeWidget);
  526. if (d->SpinBoxAlignment == alignment)
  527. {
  528. return;
  529. }
  530. d->SpinBoxAlignment = alignment;
  531. d->relayout();
  532. }
  533. // -------------------------------------------------------------------------
  534. Qt::Alignment ctkRangeWidget::spinBoxAlignment()const
  535. {
  536. Q_D(const ctkRangeWidget);
  537. return d->SpinBoxAlignment;
  538. }
  539. // -------------------------------------------------------------------------
  540. void ctkRangeWidget::setSpinBoxTextAlignment(Qt::Alignment alignment)
  541. {
  542. Q_D(ctkRangeWidget);
  543. d->MinimumSpinBox->setAlignment(alignment);
  544. d->MaximumSpinBox->setAlignment(alignment);
  545. }
  546. // -------------------------------------------------------------------------
  547. Qt::Alignment ctkRangeWidget::spinBoxTextAlignment()const
  548. {
  549. Q_D(const ctkRangeWidget);
  550. Q_ASSERT(d->MinimumSpinBox->alignment() == d->MaximumSpinBox->alignment());
  551. return d->MinimumSpinBox->alignment();
  552. }
  553. // -------------------------------------------------------------------------
  554. void ctkRangeWidget::setTracking(bool enable)
  555. {
  556. Q_D(ctkRangeWidget);
  557. d->Tracking = enable;
  558. }
  559. // -------------------------------------------------------------------------
  560. bool ctkRangeWidget::hasTracking()const
  561. {
  562. Q_D(const ctkRangeWidget);
  563. return d->Tracking;
  564. }
  565. // -------------------------------------------------------------------------
  566. bool ctkRangeWidget::isAutoSpinBoxWidth()const
  567. {
  568. Q_D(const ctkRangeWidget);
  569. return d->AutoSpinBoxWidth;
  570. }
  571. // -------------------------------------------------------------------------
  572. void ctkRangeWidget::setAutoSpinBoxWidth(bool autoWidth)
  573. {
  574. Q_D(ctkRangeWidget);
  575. d->AutoSpinBoxWidth = autoWidth;
  576. d->updateSpinBoxWidth();
  577. }
  578. // -------------------------------------------------------------------------
  579. ctkDoubleRangeSlider* ctkRangeWidget::slider()const
  580. {
  581. Q_D(const ctkRangeWidget);
  582. return d->Slider;
  583. }
  584. // -------------------------------------------------------------------------
  585. void ctkRangeWidget::setSlider(ctkDoubleRangeSlider* slider)
  586. {
  587. Q_D(ctkRangeWidget);
  588. slider->setOrientation(d->Slider->orientation());
  589. slider->setMinimum(d->Slider->minimum());
  590. slider->setMaximum(d->Slider->maximum());
  591. slider->setValues(d->Slider->minimumValue(), d->Slider->maximumValue());
  592. slider->setSingleStep(d->Slider->singleStep());
  593. slider->setTracking(d->Slider->hasTracking());
  594. slider->setTickInterval(d->Slider->tickInterval());
  595. delete d->Slider;
  596. d->Slider = slider;
  597. d->connectSlider();
  598. d->relayout();
  599. }