ctkSliderWidget.cpp 20 KB

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