ctkRangeWidget.cpp 23 KB

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