ctkRangeWidget.cpp 21 KB

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