ctkRangeWidget.cpp 23 KB

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