ctkDoubleRangeSlider.cpp 20 KB

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