ctkDoubleRangeSlider.cpp 21 KB

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