ctkDoubleRangeSlider.cpp 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641
  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 <QHBoxLayout>
  17. // CTK includes
  18. #include "ctkRangeSlider.h"
  19. #include "ctkDoubleRangeSlider.h"
  20. //-----------------------------------------------------------------------------
  21. class ctkDoubleRangeSliderPrivate
  22. {
  23. Q_DECLARE_PUBLIC(ctkDoubleRangeSlider);
  24. protected:
  25. ctkDoubleRangeSlider* const q_ptr;
  26. public:
  27. ctkDoubleRangeSliderPrivate(ctkDoubleRangeSlider& object);
  28. int toInt(double _value)const;
  29. double minFromInt(int _value)const;
  30. double maxFromInt(int _value)const;
  31. double safeMinFromInt(int _value)const;
  32. double safeMaxFromInt(int _value)const;
  33. void init();
  34. void connectSlider();
  35. void updateMinOffset(double value);
  36. void updateMaxOffset(double value);
  37. ctkRangeSlider* Slider;
  38. double Minimum;
  39. double Maximum;
  40. bool SettingRange;
  41. // we should have a MinValueOffset and MinPositionOffset (and MinimumOffset?)
  42. double MinOffset;
  43. // we should have a MaxValueOffset and MaxPositionOffset (and MaximumOffset?)
  44. double MaxOffset;
  45. double SingleStep;
  46. double MinValue;
  47. double MaxValue;
  48. };
  49. // --------------------------------------------------------------------------
  50. ctkDoubleRangeSliderPrivate::ctkDoubleRangeSliderPrivate(ctkDoubleRangeSlider& object)
  51. :q_ptr(&object)
  52. {
  53. // the initial values will be overwritten in
  54. // ctkDoubleRangeSliderPrivate::init()
  55. this->Slider = 0;
  56. this->Minimum = 0.;
  57. this->Maximum = 99.;
  58. this->SettingRange = false;
  59. this->MinOffset = 0.;
  60. this->MaxOffset = 0.;
  61. this->SingleStep = 1.;
  62. this->MinValue = 0.;
  63. this->MaxValue = 99.;
  64. }
  65. // --------------------------------------------------------------------------
  66. void ctkDoubleRangeSliderPrivate::init()
  67. {
  68. Q_Q(ctkDoubleRangeSlider);
  69. this->Slider = new ctkRangeSlider(q);
  70. QHBoxLayout* l = new QHBoxLayout(q);
  71. l->addWidget(this->Slider);
  72. l->setContentsMargins(0,0,0,0);
  73. this->Minimum = this->Slider->minimum();
  74. this->Maximum = this->Slider->maximum();
  75. this->MinValue = this->Slider->minimumValue();
  76. this->MaxValue = this->Slider->maximumValue();
  77. this->SingleStep = this->Slider->singleStep();
  78. q->setSizePolicy(this->Slider->sizePolicy());
  79. q->setAttribute(Qt::WA_WState_OwnSizePolicy, false);
  80. this->connectSlider();
  81. }
  82. // --------------------------------------------------------------------------
  83. void ctkDoubleRangeSliderPrivate::connectSlider()
  84. {
  85. Q_Q(ctkDoubleRangeSlider);
  86. q->connect(this->Slider, SIGNAL(valuesChanged(int,int)),
  87. q, SLOT(onValuesChanged(int,int)));
  88. q->connect(this->Slider, SIGNAL(minimumPositionChanged(int)),
  89. q, SLOT(onMinPosChanged(int)));
  90. q->connect(this->Slider, SIGNAL(maximumPositionChanged(int)),
  91. q, SLOT(onMaxPosChanged(int)));
  92. q->connect(this->Slider, SIGNAL(positionsChanged(int,int)),
  93. q, SLOT(onPositionsChanged(int,int)));
  94. q->connect(this->Slider, SIGNAL(sliderPressed()),
  95. q, SIGNAL(sliderPressed()));
  96. q->connect(this->Slider, SIGNAL(sliderReleased()),
  97. q, SIGNAL(sliderReleased()));
  98. q->connect(this->Slider, SIGNAL(rangeChanged(int,int)),
  99. q, SLOT(onRangeChanged(int,int)));
  100. }
  101. // --------------------------------------------------------------------------
  102. int ctkDoubleRangeSliderPrivate::toInt(double doubleValue)const
  103. {
  104. double tmp = doubleValue / this->SingleStep;
  105. static const double minInt = std::numeric_limits<int>::min();
  106. static const double maxInt = std::numeric_limits<int>::max();
  107. #ifndef QT_NO_DEBUG
  108. if (tmp < minInt || tmp > maxInt)
  109. {
  110. qWarning() << __FUNCTION__ << ": value " << doubleValue
  111. << " for singleStep " << this->SingleStep
  112. << " is out of integer bounds !";
  113. }
  114. #endif
  115. tmp = qBound(minInt, tmp, maxInt);
  116. int intValue = qRound(tmp);
  117. //qDebug() << __FUNCTION__ << doubleValue << tmp << intValue;
  118. return intValue;
  119. }
  120. // --------------------------------------------------------------------------
  121. double ctkDoubleRangeSliderPrivate::minFromInt(int intValue)const
  122. {
  123. double doubleValue = this->SingleStep * (this->MinOffset + intValue) ;
  124. return doubleValue;
  125. }
  126. // --------------------------------------------------------------------------
  127. double ctkDoubleRangeSliderPrivate::maxFromInt(int intValue)const
  128. {
  129. double doubleValue = this->SingleStep * (this->MaxOffset + intValue) ;
  130. return doubleValue;
  131. }
  132. // --------------------------------------------------------------------------
  133. double ctkDoubleRangeSliderPrivate::safeMinFromInt(int intValue)const
  134. {
  135. return qBound(this->Minimum, this->minFromInt(intValue), this->Maximum);
  136. }
  137. // --------------------------------------------------------------------------
  138. double ctkDoubleRangeSliderPrivate::safeMaxFromInt(int intValue)const
  139. {
  140. return qBound(this->Minimum, this->maxFromInt(intValue), this->Maximum);
  141. }
  142. // --------------------------------------------------------------------------
  143. void ctkDoubleRangeSliderPrivate::updateMinOffset(double value)
  144. {
  145. this->MinOffset = (value / this->SingleStep) - this->toInt(value);
  146. }
  147. // --------------------------------------------------------------------------
  148. void ctkDoubleRangeSliderPrivate::updateMaxOffset(double value)
  149. {
  150. this->MaxOffset = (value / this->SingleStep) - this->toInt(value);
  151. }
  152. // --------------------------------------------------------------------------
  153. ctkDoubleRangeSlider::ctkDoubleRangeSlider(QWidget* _parent) : Superclass(_parent)
  154. , d_ptr(new ctkDoubleRangeSliderPrivate(*this))
  155. {
  156. Q_D(ctkDoubleRangeSlider);
  157. d->init();
  158. }
  159. // --------------------------------------------------------------------------
  160. ctkDoubleRangeSlider::ctkDoubleRangeSlider(Qt::Orientation _orientation, QWidget* _parent)
  161. : Superclass(_parent)
  162. , d_ptr(new ctkDoubleRangeSliderPrivate(*this))
  163. {
  164. Q_D(ctkDoubleRangeSlider);
  165. d->init();
  166. this->setOrientation(_orientation);
  167. }
  168. // --------------------------------------------------------------------------
  169. ctkDoubleRangeSlider::~ctkDoubleRangeSlider()
  170. {
  171. }
  172. // --------------------------------------------------------------------------
  173. void ctkDoubleRangeSlider::setMinimum(double min)
  174. {
  175. Q_D(ctkDoubleRangeSlider);
  176. double oldMin = d->Minimum;
  177. d->Minimum = min;
  178. if (d->Minimum >= d->MinValue)
  179. {// TBD: use same offset
  180. d->updateMinOffset(d->Minimum);
  181. }
  182. if (d->Minimum >= d->MaxValue)
  183. {// TBD: use same offset
  184. d->updateMaxOffset(d->Minimum);
  185. }
  186. d->SettingRange = true;
  187. d->Slider->setMinimum(d->toInt(min));
  188. d->SettingRange = false;
  189. if (d->Minimum != oldMin)
  190. {
  191. emit this->rangeChanged(d->Minimum, d->Maximum);
  192. }
  193. }
  194. // --------------------------------------------------------------------------
  195. double ctkDoubleRangeSlider::minimum()const
  196. {
  197. Q_D(const ctkDoubleRangeSlider);
  198. return d->Minimum;
  199. }
  200. // --------------------------------------------------------------------------
  201. void ctkDoubleRangeSlider::setMaximum(double max)
  202. {
  203. Q_D(ctkDoubleRangeSlider);
  204. double oldMax = d->Maximum;
  205. d->Maximum = max;
  206. if (d->Maximum <= d->MinValue)
  207. {// TBD: use same offset
  208. d->updateMinOffset(d->Maximum);
  209. }
  210. if (d->Maximum <= d->MaxValue)
  211. {// TBD: use same offset ?
  212. d->updateMaxOffset(d->Maximum);
  213. }
  214. d->SettingRange = true;
  215. d->Slider->setMaximum(d->toInt(max));
  216. d->SettingRange = false;
  217. if (d->Maximum != oldMax)
  218. {
  219. emit this->rangeChanged(d->Minimum, d->Maximum);
  220. }
  221. }
  222. // --------------------------------------------------------------------------
  223. double ctkDoubleRangeSlider::maximum()const
  224. {
  225. Q_D(const ctkDoubleRangeSlider);
  226. return d->Maximum;
  227. }
  228. // --------------------------------------------------------------------------
  229. void ctkDoubleRangeSlider::setRange(double min, double max)
  230. {
  231. Q_D(ctkDoubleRangeSlider);
  232. double oldMin = d->Minimum;
  233. double oldMax = d->Maximum;
  234. d->Minimum = min;
  235. d->Maximum = max;
  236. if (d->Minimum >= d->MinValue)
  237. {// TBD: use same offset
  238. d->updateMinOffset(d->Minimum);
  239. }
  240. if (d->Minimum >= d->MaxValue)
  241. {// TBD: use same offset
  242. d->updateMaxOffset(d->Minimum);
  243. }
  244. if (d->Maximum <= d->MinValue)
  245. {// TBD: use same offset
  246. d->updateMinOffset(d->Maximum);
  247. }
  248. if (d->Maximum <= d->MaxValue)
  249. {// TBD: use same offset ?
  250. d->updateMaxOffset(d->Maximum);
  251. }
  252. d->SettingRange = true;
  253. d->Slider->setRange(d->toInt(min), d->toInt(max));
  254. d->SettingRange = false;
  255. if (d->Minimum != oldMin || d->Maximum != oldMax)
  256. {
  257. emit this->rangeChanged(d->Minimum, d->Maximum);
  258. }
  259. }
  260. // --------------------------------------------------------------------------
  261. double ctkDoubleRangeSlider::minimumPosition()const
  262. {
  263. Q_D(const ctkDoubleRangeSlider);
  264. return d->safeMinFromInt(d->Slider->minimumPosition());
  265. }
  266. // --------------------------------------------------------------------------
  267. void ctkDoubleRangeSlider::setMinimumPosition(double minPos)
  268. {
  269. Q_D(ctkDoubleRangeSlider);
  270. d->Slider->setMinimumPosition(d->toInt(minPos));
  271. }
  272. // --------------------------------------------------------------------------
  273. double ctkDoubleRangeSlider::maximumPosition()const
  274. {
  275. Q_D(const ctkDoubleRangeSlider);
  276. return d->safeMaxFromInt(d->Slider->maximumPosition());
  277. }
  278. // --------------------------------------------------------------------------
  279. void ctkDoubleRangeSlider::setMaximumPosition(double maxPos)
  280. {
  281. Q_D(ctkDoubleRangeSlider);
  282. d->Slider->setMaximumPosition(d->toInt(maxPos));
  283. }
  284. // --------------------------------------------------------------------------
  285. void ctkDoubleRangeSlider::setPositions(double minPos, double maxPos)
  286. {
  287. Q_D(ctkDoubleRangeSlider);
  288. d->Slider->setPositions(d->toInt(minPos), d->toInt(maxPos));
  289. }
  290. // --------------------------------------------------------------------------
  291. double ctkDoubleRangeSlider::minimumValue()const
  292. {
  293. Q_D(const ctkDoubleRangeSlider);
  294. return d->MinValue;
  295. }
  296. // --------------------------------------------------------------------------
  297. void ctkDoubleRangeSlider::setMinimumValue(double newMinValue)
  298. {
  299. Q_D(ctkDoubleRangeSlider);
  300. newMinValue = qBound(d->Minimum, newMinValue, d->Maximum);
  301. d->updateMinOffset(newMinValue);
  302. if (newMinValue >= d->MaxValue)
  303. {
  304. d->updateMaxOffset(newMinValue);
  305. }
  306. int newIntValue = d->toInt(newMinValue);
  307. if (newIntValue != d->Slider->minimumValue())
  308. {
  309. // d->Slider will emit a minimumValueChanged signal that is connected to
  310. // ctkDoubleSlider::onValueChanged
  311. d->Slider->setMinimumValue(newIntValue);
  312. }
  313. else
  314. {
  315. double oldValue = d->MinValue;
  316. d->MinValue = newMinValue;
  317. // don't emit a valuechanged signal if the new value is quite
  318. // similar to the old value.
  319. if (qAbs(newMinValue - oldValue) > (d->SingleStep * 0.000000001))
  320. {
  321. emit this->valuesChanged(newMinValue, this->maximumValue());
  322. emit this->minimumValueChanged(newMinValue);
  323. }
  324. }
  325. }
  326. // --------------------------------------------------------------------------
  327. double ctkDoubleRangeSlider::maximumValue()const
  328. {
  329. Q_D(const ctkDoubleRangeSlider);
  330. return d->MaxValue;
  331. }
  332. // --------------------------------------------------------------------------
  333. void ctkDoubleRangeSlider::setMaximumValue(double newMaxValue)
  334. {
  335. Q_D(ctkDoubleRangeSlider);
  336. newMaxValue = qBound(d->Minimum, newMaxValue, d->Maximum);
  337. d->updateMaxOffset(newMaxValue);
  338. if (newMaxValue <= d->MinValue)
  339. {
  340. d->updateMinOffset(newMaxValue);
  341. }
  342. int newIntValue = d->toInt(newMaxValue);
  343. if (newIntValue != d->Slider->maximumValue())
  344. {
  345. // d->Slider will emit a maximumValueChanged signal that is connected to
  346. // ctkDoubleSlider::onValueChanged
  347. d->Slider->setMaximumValue(newIntValue);
  348. }
  349. else
  350. {
  351. double oldValue = d->MaxValue;
  352. d->MaxValue = newMaxValue;
  353. // don't emit a valuechanged signal if the new value is quite
  354. // similar to the old value.
  355. if (qAbs(newMaxValue - oldValue) > (d->SingleStep * 0.000000001))
  356. {
  357. emit this->valuesChanged(this->minimumValue(), newMaxValue);
  358. emit this->maximumValueChanged(newMaxValue);
  359. }
  360. }
  361. }
  362. // --------------------------------------------------------------------------
  363. void ctkDoubleRangeSlider::setValues(double newMinVal, double newMaxVal)
  364. {
  365. Q_D(ctkDoubleRangeSlider);
  366. // We can't call setMinimumValue() and setMaximumValue() as they would
  367. // generate an inconsistent state. when minimumValueChanged() is fired the
  368. // new max value wouldn't be updated yet.
  369. double newMinValue = qBound(d->Minimum, qMin(newMinVal, newMaxVal), d->Maximum);
  370. double newMaxValue = qBound(d->Minimum, qMax(newMinVal, newMaxVal), d->Maximum);
  371. d->updateMinOffset(newMinValue);
  372. d->updateMaxOffset(newMaxValue);
  373. int newMinIntValue = d->toInt(newMinValue);
  374. int newMaxIntValue = d->toInt(newMaxValue);
  375. if (newMinIntValue != d->Slider->minimumValue() ||
  376. newMaxIntValue != d->Slider->maximumValue())
  377. {
  378. // d->Slider will emit a maximumValueChanged signal that is connected to
  379. // ctkDoubleSlider::onValueChanged
  380. d->Slider->setValues(newMinIntValue, newMaxIntValue);
  381. }
  382. else
  383. {
  384. double oldMinValue = d->MinValue;
  385. double oldMaxValue = d->MaxValue;
  386. d->MinValue = newMinValue;
  387. d->MaxValue = newMaxValue;
  388. // don't emit a valuechanged signal if the new value is quite
  389. // similar to the old value.
  390. bool minChanged = qAbs(newMinValue - oldMinValue) > (d->SingleStep * 0.000000001);
  391. bool maxChanged = qAbs(newMaxValue - oldMaxValue) > (d->SingleStep * 0.000000001);
  392. if (minChanged || maxChanged)
  393. {
  394. emit this->valuesChanged(newMinValue, newMaxValue);
  395. if (minChanged)
  396. {
  397. emit this->minimumValueChanged(newMinValue);
  398. }
  399. if (maxChanged)
  400. {
  401. emit this->maximumValueChanged(newMaxValue);
  402. }
  403. }
  404. }
  405. }
  406. // --------------------------------------------------------------------------
  407. double ctkDoubleRangeSlider::singleStep()const
  408. {
  409. Q_D(const ctkDoubleRangeSlider);
  410. return d->SingleStep;
  411. }
  412. // --------------------------------------------------------------------------
  413. void ctkDoubleRangeSlider::setSingleStep(double newStep)
  414. {
  415. Q_D(ctkDoubleRangeSlider);
  416. d->SingleStep = newStep;
  417. // The following can fire A LOT of signals that shouldn't be
  418. // fired.
  419. bool oldBlockSignals = this->blockSignals(true);
  420. d->updateMinOffset(d->MinValue);
  421. d->updateMaxOffset(d->MaxValue);
  422. // update the new values of the ctkRangeSlider
  423. double _minvalue = d->MinValue;
  424. double _maxvalue = d->MaxValue;
  425. // calling setMinimum or setMaximum can change the values MinimumValue
  426. // and MaximumValue, this is why we re-set them later.
  427. this->setMinimum(d->Minimum);
  428. this->setMaximum(d->Maximum);
  429. this->setMinimumValue(_minvalue);
  430. this->setMinimumPosition(_minvalue);
  431. this->setMaximumValue(_maxvalue);
  432. this->setMaximumPosition(_maxvalue);
  433. this->blockSignals(oldBlockSignals);
  434. }
  435. // --------------------------------------------------------------------------
  436. double ctkDoubleRangeSlider::tickInterval()const
  437. {
  438. Q_D(const ctkDoubleRangeSlider);
  439. return d->SingleStep * d->Slider->tickInterval();
  440. }
  441. // --------------------------------------------------------------------------
  442. void ctkDoubleRangeSlider::setTickInterval(double newTickInterval)
  443. {
  444. Q_D(ctkDoubleRangeSlider);
  445. d->Slider->setTickInterval(d->toInt(newTickInterval));
  446. }
  447. // --------------------------------------------------------------------------
  448. bool ctkDoubleRangeSlider::hasTracking()const
  449. {
  450. Q_D(const ctkDoubleRangeSlider);
  451. return d->Slider->hasTracking();
  452. }
  453. // --------------------------------------------------------------------------
  454. void ctkDoubleRangeSlider::setTracking(bool enable)
  455. {
  456. Q_D(ctkDoubleRangeSlider);
  457. d->Slider->setTracking(enable);
  458. }
  459. // --------------------------------------------------------------------------
  460. void ctkDoubleRangeSlider::triggerAction( QAbstractSlider::SliderAction action)
  461. {
  462. Q_D(ctkDoubleRangeSlider);
  463. d->Slider->triggerAction(action);
  464. }
  465. // --------------------------------------------------------------------------
  466. void ctkDoubleRangeSlider::setOrientation(Qt::Orientation newOrientation)
  467. {
  468. Q_D(ctkDoubleRangeSlider);
  469. if (this->orientation() == newOrientation)
  470. {
  471. return;
  472. }
  473. if (!testAttribute(Qt::WA_WState_OwnSizePolicy))
  474. {
  475. QSizePolicy sp = this->sizePolicy();
  476. sp.transpose();
  477. this->setSizePolicy(sp);
  478. this->setAttribute(Qt::WA_WState_OwnSizePolicy, false);
  479. }
  480. // d->Slider will take care of calling updateGeometry
  481. d->Slider->setOrientation(newOrientation);
  482. }
  483. // --------------------------------------------------------------------------
  484. Qt::Orientation ctkDoubleRangeSlider::orientation()const
  485. {
  486. Q_D(const ctkDoubleRangeSlider);
  487. return d->Slider->orientation();
  488. }
  489. // --------------------------------------------------------------------------
  490. bool ctkDoubleRangeSlider::symmetricMoves()const
  491. {
  492. Q_D(const ctkDoubleRangeSlider);
  493. return d->Slider->symmetricMoves();
  494. }
  495. // --------------------------------------------------------------------------
  496. void ctkDoubleRangeSlider::setSymmetricMoves(bool symmetry)
  497. {
  498. Q_D(ctkDoubleRangeSlider);
  499. d->Slider->setSymmetricMoves(symmetry);
  500. }
  501. // --------------------------------------------------------------------------
  502. void ctkDoubleRangeSlider::onValuesChanged(int newMinValue, int newMaxValue)
  503. {
  504. Q_D(ctkDoubleRangeSlider);
  505. double doubleNewMinValue = d->safeMinFromInt(newMinValue);
  506. double doubleNewMaxValue = d->safeMaxFromInt(newMaxValue);
  507. bool emitMinValueChanged = (d->MinValue != doubleNewMinValue);
  508. bool emitMaxValueChanged = (d->MaxValue != doubleNewMaxValue);
  509. if (!emitMinValueChanged && !emitMaxValueChanged)
  510. {
  511. return;
  512. }
  513. d->MinValue = doubleNewMinValue;
  514. d->MaxValue = doubleNewMaxValue;
  515. emit this->valuesChanged(d->MinValue, d->MaxValue);
  516. if (emitMinValueChanged)
  517. {
  518. emit this->minimumValueChanged(d->MinValue);
  519. }
  520. if (emitMaxValueChanged)
  521. {
  522. emit this->maximumValueChanged(d->MaxValue);
  523. }
  524. }
  525. // --------------------------------------------------------------------------
  526. void ctkDoubleRangeSlider::onMinPosChanged(int newPosition)
  527. {
  528. Q_D(const ctkDoubleRangeSlider);
  529. emit this->minimumPositionChanged(d->safeMinFromInt(newPosition));
  530. }
  531. // --------------------------------------------------------------------------
  532. void ctkDoubleRangeSlider::onMaxPosChanged(int newPosition)
  533. {
  534. Q_D(const ctkDoubleRangeSlider);
  535. emit this->maximumPositionChanged(d->safeMaxFromInt(newPosition));
  536. }
  537. // --------------------------------------------------------------------------
  538. void ctkDoubleRangeSlider::onPositionsChanged(int min, int max)
  539. {
  540. Q_D(const ctkDoubleRangeSlider);
  541. emit this->positionsChanged(d->safeMinFromInt(min), d->safeMaxFromInt(max));
  542. }
  543. // --------------------------------------------------------------------------
  544. void ctkDoubleRangeSlider::onRangeChanged(int min, int max)
  545. {
  546. Q_D(const ctkDoubleRangeSlider);
  547. if (!d->SettingRange)
  548. {
  549. this->setRange(d->minFromInt(min), d->maxFromInt(max));
  550. }
  551. }
  552. // --------------------------------------------------------------------------
  553. ctkRangeSlider* ctkDoubleRangeSlider::slider()const
  554. {
  555. Q_D(const ctkDoubleRangeSlider);
  556. return d->Slider;
  557. }
  558. // --------------------------------------------------------------------------
  559. void ctkDoubleRangeSlider::setSlider(ctkRangeSlider* slider)
  560. {
  561. Q_D(ctkDoubleRangeSlider);
  562. slider->setOrientation(d->Slider->orientation());
  563. slider->setMinimum(d->Slider->minimum());
  564. slider->setMaximum(d->Slider->maximum());
  565. slider->setValues(d->Slider->minimumValue(), d->Slider->maximumValue());
  566. slider->setSingleStep(d->Slider->singleStep());
  567. slider->setTracking(d->Slider->hasTracking());
  568. slider->setTickInterval(d->Slider->tickInterval());
  569. delete d->Slider;
  570. qobject_cast<QHBoxLayout*>(this->layout())->addWidget(slider);
  571. d->Slider = slider;
  572. d->connectSlider();
  573. }