ctkRangeWidget.cpp 22 KB

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