ctkDoubleRangeSlider.cpp 20 KB

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