ctkRangeSlider.cpp 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664
  1. /*=========================================================================
  2. Library: CTK
  3. Copyright (c) 2010 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 <QMouseEvent>
  17. #include <QKeyEvent>
  18. #include <QStyleOptionSlider>
  19. #include <QApplication>
  20. #include <QStylePainter>
  21. #include <QStyle>
  22. // CTK includes
  23. #include "ctkRangeSlider.h"
  24. class ctkRangeSliderPrivate:public ctkPrivate<ctkRangeSlider>
  25. {
  26. public:
  27. ctkRangeSliderPrivate();
  28. void init();
  29. // Description:
  30. // Copied verbatim from QSliderPrivate class (see QSlider.cpp)
  31. int pixelPosToRangeValue(int pos) const;
  32. int pixelPosFromRangeValue(int val) const;
  33. // Description:
  34. // Draw the bottom and top sliders.
  35. void drawMinimumSlider( QStylePainter* painter ) const;
  36. void drawMaximumSlider( QStylePainter* painter ) const;
  37. // Description:
  38. // End points of the range on the Model
  39. int m_MaximumValue;
  40. int m_MinimumValue;
  41. // Description:
  42. // End points of the range on the GUI. This is synced with the model.
  43. int m_MaximumPosition;
  44. int m_MinimumPosition;
  45. // Description:
  46. // Controls selected ?
  47. QStyle::SubControl m_MinimumSliderSelected;
  48. QStyle::SubControl m_MaximumSliderSelected;
  49. // Description:
  50. // See QSliderPrivate::clickOffset.
  51. // Overrides this ivar
  52. int m_SubclassClickOffset;
  53. // Description:
  54. // See QSliderPrivate::position
  55. // Overrides this ivar.
  56. int m_SubclassPosition;
  57. int m_SubclassWidth;
  58. // Description:
  59. // Boolean indicates the selected handle
  60. // True for the minimum range handle, false for the maximum range handle
  61. enum Handle {
  62. NoHandle = 0x0,
  63. MinimumHandle = 0x1,
  64. MaximumHandle = 0x2
  65. };
  66. Q_DECLARE_FLAGS(Handles, Handle);
  67. ctkRangeSliderPrivate::Handles m_SelectedHandles;
  68. };
  69. // --------------------------------------------------------------------------
  70. ctkRangeSliderPrivate::ctkRangeSliderPrivate()
  71. {
  72. this->m_MinimumValue = 0;
  73. this->m_MaximumValue = 100;
  74. this->m_MinimumPosition = 0;
  75. this->m_MaximumPosition = 100;
  76. this->m_MinimumSliderSelected = QStyle::SC_None;
  77. this->m_MaximumSliderSelected = QStyle::SC_None;
  78. this->m_SubclassClickOffset = 0;
  79. this->m_SubclassPosition = 0;
  80. this->m_SubclassWidth = 0;
  81. this->m_SelectedHandles = 0;
  82. }
  83. // --------------------------------------------------------------------------
  84. void ctkRangeSliderPrivate::init()
  85. {
  86. CTK_P(ctkRangeSlider);
  87. this->m_MinimumValue = p->minimum();
  88. this->m_MaximumValue = p->maximum();
  89. this->m_MinimumPosition = p->minimum();
  90. this->m_MaximumPosition = p->maximum();
  91. p->connect(p, SIGNAL(rangeChanged(int, int)), p, SLOT(onRangeChanged(int, int)));
  92. }
  93. // --------------------------------------------------------------------------
  94. // Copied verbatim from QSliderPrivate::pixelPosToRangeValue. See QSlider.cpp
  95. //
  96. int ctkRangeSliderPrivate::pixelPosToRangeValue( int pos ) const
  97. {
  98. CTK_P(const ctkRangeSlider);
  99. QStyleOptionSlider option;
  100. p->initStyleOption( &option );
  101. QRect gr = p->style()->subControlRect( QStyle::CC_Slider,
  102. &option,
  103. QStyle::SC_SliderGroove,
  104. p );
  105. QRect sr = p->style()->subControlRect( QStyle::CC_Slider,
  106. &option,
  107. QStyle::SC_SliderHandle,
  108. p );
  109. int sliderMin, sliderMax, sliderLength;
  110. if (option.orientation == Qt::Horizontal)
  111. {
  112. sliderLength = sr.width();
  113. sliderMin = gr.x();
  114. sliderMax = gr.right() - sliderLength + 1;
  115. }
  116. else
  117. {
  118. sliderLength = sr.height();
  119. sliderMin = gr.y();
  120. sliderMax = gr.bottom() - sliderLength + 1;
  121. }
  122. return QStyle::sliderValueFromPosition( p->minimum(),
  123. p->maximum(),
  124. pos - sliderMin,
  125. sliderMax - sliderMin,
  126. option.upsideDown );
  127. }
  128. //---------------------------------------------------------------------------
  129. int ctkRangeSliderPrivate::pixelPosFromRangeValue( int val ) const
  130. {
  131. CTK_P(const ctkRangeSlider);
  132. QStyleOptionSlider option;
  133. p->initStyleOption( &option );
  134. QRect gr = p->style()->subControlRect( QStyle::CC_Slider,
  135. &option,
  136. QStyle::SC_SliderGroove,
  137. p );
  138. QRect sr = p->style()->subControlRect( QStyle::CC_Slider,
  139. &option,
  140. QStyle::SC_SliderHandle,
  141. p );
  142. int sliderMin, sliderMax, sliderLength;
  143. if (option.orientation == Qt::Horizontal)
  144. {
  145. sliderLength = sr.width();
  146. sliderMin = gr.x();
  147. sliderMax = gr.right() - sliderLength + 1;
  148. }
  149. else
  150. {
  151. sliderLength = sr.height();
  152. sliderMin = gr.y();
  153. sliderMax = gr.bottom() - sliderLength + 1;
  154. }
  155. return QStyle::sliderPositionFromValue( p->minimum(),
  156. p->maximum(),
  157. val,
  158. sliderMax - sliderMin,
  159. option.upsideDown ) + sliderMin;
  160. }
  161. //---------------------------------------------------------------------------
  162. // Draw slider at the bottom end of the range
  163. void ctkRangeSliderPrivate::drawMinimumSlider( QStylePainter* painter ) const
  164. {
  165. CTK_P(const ctkRangeSlider);
  166. QStyleOptionSlider option;
  167. p->initStyleOption( &option );
  168. option.subControls = QStyle::SC_SliderHandle;
  169. option.sliderValue = m_MinimumValue;
  170. option.sliderPosition = m_MinimumPosition;
  171. if (this->m_SelectedHandles & MinimumHandle)
  172. {
  173. option.activeSubControls = QStyle::SC_SliderHandle;
  174. option.state |= QStyle::State_Sunken;
  175. }
  176. painter->drawComplexControl(QStyle::CC_Slider, option);
  177. }
  178. //---------------------------------------------------------------------------
  179. // Draw slider at the top end of the range
  180. void ctkRangeSliderPrivate::drawMaximumSlider( QStylePainter* painter ) const
  181. {
  182. CTK_P(const ctkRangeSlider);
  183. QStyleOptionSlider option;
  184. p->Superclass::initStyleOption( &option );
  185. option.subControls = QStyle::SC_SliderHandle;
  186. option.sliderValue = m_MaximumValue;
  187. option.sliderPosition = m_MaximumPosition;
  188. if (this->m_SelectedHandles & MaximumHandle)
  189. {
  190. option.activeSubControls = QStyle::SC_SliderHandle;
  191. option.state |= QStyle::State_Sunken;
  192. }
  193. painter->drawComplexControl(QStyle::CC_Slider, option);
  194. }
  195. // --------------------------------------------------------------------------
  196. ctkRangeSlider::ctkRangeSlider(QWidget* parent)
  197. : QSlider(parent)
  198. {
  199. CTK_INIT_PRIVATE(ctkRangeSlider);
  200. ctk_d()->init();
  201. }
  202. // --------------------------------------------------------------------------
  203. ctkRangeSlider::ctkRangeSlider( Qt::Orientation o,
  204. QWidget* parentObject )
  205. :QSlider(o, parentObject)
  206. {
  207. CTK_INIT_PRIVATE(ctkRangeSlider);
  208. ctk_d()->init();
  209. }
  210. // --------------------------------------------------------------------------
  211. ctkRangeSlider::~ctkRangeSlider()
  212. {
  213. }
  214. // --------------------------------------------------------------------------
  215. int ctkRangeSlider::minimumValue() const
  216. {
  217. CTK_D(const ctkRangeSlider);
  218. return d->m_MinimumValue;
  219. }
  220. // --------------------------------------------------------------------------
  221. void ctkRangeSlider::setMinimumValue( int min )
  222. {
  223. CTK_D(ctkRangeSlider);
  224. this->setValues( min, qMax(d->m_MaximumValue,min) );
  225. }
  226. // --------------------------------------------------------------------------
  227. int ctkRangeSlider::maximumValue() const
  228. {
  229. CTK_D(const ctkRangeSlider);
  230. return d->m_MaximumValue;
  231. }
  232. // --------------------------------------------------------------------------
  233. void ctkRangeSlider::setMaximumValue( int max )
  234. {
  235. CTK_D(ctkRangeSlider);
  236. this->setValues( qMin(d->m_MinimumValue, max), max );
  237. }
  238. // --------------------------------------------------------------------------
  239. void ctkRangeSlider::setValues(int l, int u)
  240. {
  241. CTK_D(ctkRangeSlider);
  242. const int minimumValue =
  243. qBound(this->minimum(), qMin(l,u), this->maximum());
  244. const int maximumValue =
  245. qBound(this->minimum(), qMax(l,u), this->maximum());
  246. bool emitMinValChanged = (minimumValue != d->m_MinimumValue);
  247. bool emitMaxValChanged = (maximumValue != d->m_MaximumValue);
  248. d->m_MinimumValue = minimumValue;
  249. d->m_MaximumValue = maximumValue;
  250. bool emitMinPosChanged =
  251. (minimumValue != d->m_MinimumPosition);
  252. bool emitMaxPosChanged =
  253. (maximumValue != d->m_MaximumPosition);
  254. d->m_MinimumPosition = minimumValue;
  255. d->m_MaximumPosition = maximumValue;
  256. if (isSliderDown())
  257. {
  258. if (emitMinPosChanged || emitMaxPosChanged)
  259. {
  260. emit positionsChanged(minimumValue, maximumValue);
  261. }
  262. if (emitMinPosChanged)
  263. {
  264. emit minimumPositionChanged(minimumValue);
  265. }
  266. if (emitMaxPosChanged)
  267. {
  268. emit maximumPositionChanged(maximumValue);
  269. }
  270. }
  271. if (emitMinValChanged || emitMaxValChanged)
  272. {
  273. emit valuesChanged(d->m_MinimumValue,
  274. d->m_MaximumValue);
  275. }
  276. if (emitMinValChanged)
  277. {
  278. emit minimumValueChanged(minimumValue);
  279. }
  280. if (emitMaxValChanged)
  281. {
  282. emit maximumValueChanged(maximumValue);
  283. }
  284. if (emitMinPosChanged || emitMaxPosChanged ||
  285. emitMinValChanged || emitMaxValChanged)
  286. {
  287. this->update();
  288. }
  289. }
  290. // --------------------------------------------------------------------------
  291. int ctkRangeSlider::minimumPosition() const
  292. {
  293. CTK_D(const ctkRangeSlider);
  294. return d->m_MinimumPosition;
  295. }
  296. // --------------------------------------------------------------------------
  297. int ctkRangeSlider::maximumPosition() const
  298. {
  299. CTK_D(const ctkRangeSlider);
  300. return d->m_MaximumPosition;
  301. }
  302. // --------------------------------------------------------------------------
  303. void ctkRangeSlider::setMinimumPosition(int l)
  304. {
  305. CTK_D(const ctkRangeSlider);
  306. this->setPositions(l, qMax(l, d->m_MaximumPosition));
  307. }
  308. // --------------------------------------------------------------------------
  309. void ctkRangeSlider::setMaximumPosition(int u)
  310. {
  311. CTK_D(const ctkRangeSlider);
  312. this->setPositions(qMin(d->m_MinimumPosition, u), u);
  313. }
  314. // --------------------------------------------------------------------------
  315. void ctkRangeSlider::setPositions(int min, int max)
  316. {
  317. CTK_D(ctkRangeSlider);
  318. const int minPosition =
  319. qBound(this->minimum(), qMin(min, max), this->maximum());
  320. const int maxPosition =
  321. qBound(this->minimum(), qMax(min, max), this->maximum());
  322. bool emitMinPosChanged = (minPosition != d->m_MinimumPosition);
  323. bool emitMaxPosChanged = (maxPosition != d->m_MaximumPosition);
  324. if (!emitMinPosChanged && !emitMaxPosChanged)
  325. {
  326. return;
  327. }
  328. d->m_MinimumPosition = minPosition;
  329. d->m_MaximumPosition = maxPosition;
  330. if (!this->hasTracking())
  331. {
  332. this->update();
  333. }
  334. if (isSliderDown())
  335. {
  336. if (emitMinPosChanged)
  337. {
  338. emit minimumPositionChanged(d->m_MinimumPosition);
  339. }
  340. if (emitMaxPosChanged)
  341. {
  342. emit maximumPositionChanged(d->m_MaximumPosition);
  343. }
  344. if (emitMinPosChanged || emitMaxPosChanged)
  345. {
  346. emit positionsChanged(d->m_MinimumPosition, d->m_MaximumPosition);
  347. }
  348. }
  349. if (this->hasTracking())
  350. {
  351. this->triggerAction(SliderMove);
  352. this->setValues(d->m_MinimumPosition, d->m_MaximumPosition);
  353. }
  354. }
  355. // --------------------------------------------------------------------------
  356. void ctkRangeSlider::onRangeChanged(int minimum, int maximum)
  357. {
  358. Q_UNUSED(minimum);
  359. Q_UNUSED(maximum);
  360. CTK_D(ctkRangeSlider);
  361. this->setValues(d->m_MinimumValue, d->m_MaximumValue);
  362. }
  363. // --------------------------------------------------------------------------
  364. // Render
  365. void ctkRangeSlider::paintEvent( QPaintEvent* )
  366. {
  367. CTK_D(ctkRangeSlider);
  368. QStyleOptionSlider option;
  369. this->initStyleOption(&option);
  370. QStylePainter painter(this);
  371. option.subControls = QStyle::SC_SliderGroove;
  372. option.sliderPosition = this->minimum(); // don't highlight the SliderGroove
  373. painter.drawComplexControl(QStyle::CC_Slider, option);
  374. option.sliderPosition = d->m_MinimumPosition;
  375. const QRect lr = style()->subControlRect( QStyle::CC_Slider,
  376. &option,
  377. QStyle::SC_SliderHandle,
  378. this);
  379. option.sliderPosition = d->m_MaximumPosition;
  380. const QRect ur = style()->subControlRect( QStyle::CC_Slider,
  381. &option,
  382. QStyle::SC_SliderHandle,
  383. this);
  384. QRect sr = style()->subControlRect( QStyle::CC_Slider,
  385. &option,
  386. QStyle::SC_SliderGroove,
  387. this);
  388. QRect rangeBox = QRect(
  389. QPoint( qMin( lr.center().x(), ur.center().x() ), sr.center().y() - 2),
  390. QPoint(qMax( lr.center().x(), ur.center().x() ), sr.center().y() + 1));
  391. // -----------------------------
  392. // Render the range
  393. //
  394. QRect groove = this->style()->subControlRect( QStyle::CC_Slider,
  395. &option,
  396. QStyle::SC_SliderGroove,
  397. this );
  398. groove.adjust(0, 0, -1, 0);
  399. // Create default colors based on the transfer function.
  400. //
  401. QColor highlight = this->palette().color(QPalette::Normal, QPalette::Highlight);
  402. QLinearGradient gradient( groove.center().x(), groove.top(),
  403. groove.center().x(), groove.bottom());
  404. // TODO: Set this based on the supplied transfer function
  405. QColor l = Qt::darkGray;
  406. QColor u = Qt::black;
  407. gradient.setColorAt(0, highlight.darker(120));
  408. gradient.setColorAt(1, highlight.lighter(160));
  409. painter.setPen(QPen(highlight.darker(150), 0));
  410. painter.setBrush(gradient);
  411. painter.drawRect( rangeBox.intersected(groove) );
  412. // -----------------------------------
  413. // Render the sliders
  414. //
  415. if (d->m_SelectedHandles & ctkRangeSliderPrivate::MinimumHandle)
  416. {
  417. d->drawMaximumSlider( &painter );
  418. d->drawMinimumSlider( &painter );
  419. }
  420. else
  421. {
  422. d->drawMinimumSlider( &painter );
  423. d->drawMaximumSlider( &painter );
  424. }
  425. }
  426. // --------------------------------------------------------------------------
  427. // Standard Qt UI events
  428. void ctkRangeSlider::mousePressEvent(QMouseEvent* mouseEvent)
  429. {
  430. CTK_D(ctkRangeSlider);
  431. if (minimum() == maximum() || (mouseEvent->buttons() ^ mouseEvent->button()))
  432. {
  433. mouseEvent->ignore();
  434. return;
  435. }
  436. QStyleOptionSlider option;
  437. this->initStyleOption( &option );
  438. // Check if the first handle is pressed
  439. option.sliderPosition = d->m_MinimumPosition;
  440. option.sliderValue = d->m_MinimumValue;
  441. QStyle::SubControl control;
  442. control = this->style()->hitTestComplexControl( QStyle::CC_Slider,
  443. &option,
  444. mouseEvent->pos(),
  445. this);
  446. const QRect lr = this->style()->subControlRect( QStyle::CC_Slider,
  447. &option,
  448. QStyle::SC_SliderHandle,
  449. this);
  450. if (control == QStyle::SC_SliderHandle)
  451. {
  452. d->m_SubclassPosition = d->m_MinimumPosition;
  453. // save the position of the mouse inside the handle for later
  454. d->m_SubclassClickOffset = mouseEvent->x() - lr.left();
  455. this->setSliderDown(true);
  456. if (d->m_SelectedHandles != ctkRangeSliderPrivate::MinimumHandle)
  457. {
  458. d->m_SelectedHandles = ctkRangeSliderPrivate::MinimumHandle;
  459. this->update(lr);
  460. }
  461. // Accept the mouseEvent
  462. mouseEvent->accept();
  463. return;
  464. }
  465. // The user didn't press on the minimum handle,
  466. // Check if the other handle is pressed
  467. option.sliderPosition = d->m_MaximumPosition;
  468. option.sliderValue = d->m_MaximumValue;
  469. control = this->style()->hitTestComplexControl( QStyle::CC_Slider,
  470. &option,
  471. mouseEvent->pos(),
  472. this);
  473. const QRect ur = this->style()->subControlRect( QStyle::CC_Slider,
  474. &option,
  475. QStyle::SC_SliderHandle,
  476. this);
  477. if (control == QStyle::SC_SliderHandle)
  478. {
  479. d->m_SubclassPosition = d->m_MaximumPosition;
  480. // save the position of the mouse inside the handle for later
  481. d->m_SubclassClickOffset = mouseEvent->x() - ur.left();
  482. this->setSliderDown(true);
  483. if (d->m_SelectedHandles != ctkRangeSliderPrivate::MaximumHandle)
  484. {
  485. d->m_SelectedHandles = ctkRangeSliderPrivate::MaximumHandle;
  486. this->update(ur);
  487. }
  488. // Accept the mouseEvent
  489. mouseEvent->accept();
  490. return;
  491. }
  492. // if we are here, no handles have been pressed
  493. // Check if we pressed on the groove between the 2 handles
  494. control = this->style()->hitTestComplexControl( QStyle::CC_Slider,
  495. &option,
  496. mouseEvent->pos(),
  497. this);
  498. QRect sr = style()->subControlRect( QStyle::CC_Slider,
  499. &option,
  500. QStyle::SC_SliderGroove,
  501. this);
  502. if (control == QStyle::SC_SliderGroove &&
  503. mouseEvent->x() > lr.center().x() &&
  504. mouseEvent->x() < ur.center().x())
  505. {
  506. // warning lost of precision it might be fatal
  507. d->m_SubclassPosition = (d->m_MinimumPosition + d->m_MaximumPosition) / 2.;
  508. d->m_SubclassClickOffset = mouseEvent->x() - d->pixelPosFromRangeValue(d->m_SubclassPosition);
  509. d->m_SubclassWidth = (d->m_MaximumPosition - d->m_MinimumPosition) / 2;
  510. qMax(d->m_SubclassPosition - d->m_MinimumPosition, d->m_MaximumPosition - d->m_SubclassPosition);
  511. this->setSliderDown(true);
  512. if (!(d->m_SelectedHandles & QFlags<ctkRangeSliderPrivate::Handle>(
  513. ctkRangeSliderPrivate::MinimumHandle)) ||
  514. !(d->m_SelectedHandles & QFlags<ctkRangeSliderPrivate::Handle>(ctkRangeSliderPrivate::MaximumHandle)))
  515. {
  516. d->m_SelectedHandles =
  517. QFlags<ctkRangeSliderPrivate::Handle>(ctkRangeSliderPrivate::MinimumHandle) |
  518. QFlags<ctkRangeSliderPrivate::Handle>(ctkRangeSliderPrivate::MaximumHandle);
  519. this->update(lr.united(ur).united(sr));
  520. }
  521. mouseEvent->accept();
  522. return;
  523. }
  524. mouseEvent->ignore();
  525. }
  526. // --------------------------------------------------------------------------
  527. // Standard Qt UI events
  528. void ctkRangeSlider::mouseMoveEvent(QMouseEvent* mouseEvent)
  529. {
  530. CTK_D(ctkRangeSlider);
  531. if (!d->m_SelectedHandles)
  532. {
  533. mouseEvent->ignore();
  534. return;
  535. }
  536. QStyleOptionSlider option;
  537. this->initStyleOption(&option);
  538. const int m = style()->pixelMetric( QStyle::PM_MaximumDragDistance, &option, this );
  539. int newPosition = d->pixelPosToRangeValue(
  540. mouseEvent->x() - d->m_SubclassClickOffset);
  541. if (m >= 0)
  542. {
  543. const QRect r = rect().adjusted(-m, -m, m, m);
  544. if (!r.contains(mouseEvent->pos()))
  545. {
  546. newPosition = d->m_SubclassPosition;
  547. }
  548. }
  549. if (d->m_SelectedHandles == ctkRangeSliderPrivate::MinimumHandle)
  550. {
  551. this->setMinimumPosition(qMin(newPosition,d->m_MaximumPosition));
  552. }
  553. else if (d->m_SelectedHandles == ctkRangeSliderPrivate::MaximumHandle)
  554. {
  555. this->setMaximumPosition(qMax(d->m_MinimumPosition, newPosition));
  556. }
  557. else if (d->m_SelectedHandles & ctkRangeSliderPrivate::MinimumHandle &&
  558. d->m_SelectedHandles & ctkRangeSliderPrivate::MaximumHandle)
  559. {
  560. this->setPositions(newPosition - d->m_SubclassWidth, newPosition + d->m_SubclassWidth );
  561. }
  562. mouseEvent->accept();
  563. }
  564. // --------------------------------------------------------------------------
  565. // Standard Qt UI mouseEvents
  566. void ctkRangeSlider::mouseReleaseEvent(QMouseEvent* mouseEvent)
  567. {
  568. CTK_D(ctkRangeSlider);
  569. this->QSlider::mouseReleaseEvent(mouseEvent);
  570. setSliderDown(false);
  571. d->m_SelectedHandles = 0;
  572. this->update();
  573. }