ctkRangeWidget.cpp 20 KB

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