ctkRangeSlider.cpp 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663
  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. painter.drawComplexControl(QStyle::CC_Slider, option);
  373. option.sliderPosition = d->m_MinimumPosition;
  374. const QRect lr = style()->subControlRect( QStyle::CC_Slider,
  375. &option,
  376. QStyle::SC_SliderHandle,
  377. this);
  378. option.sliderPosition = d->m_MaximumPosition;
  379. const QRect ur = style()->subControlRect( QStyle::CC_Slider,
  380. &option,
  381. QStyle::SC_SliderHandle,
  382. this);
  383. QRect sr = style()->subControlRect( QStyle::CC_Slider,
  384. &option,
  385. QStyle::SC_SliderGroove,
  386. this);
  387. QRect rangeBox = QRect(
  388. QPoint( qMin( lr.center().x(), ur.center().x() ), sr.center().y() - 2),
  389. QPoint(qMax( lr.center().x(), ur.center().x() ), sr.center().y() + 1));
  390. // -----------------------------
  391. // Render the range
  392. //
  393. QRect groove = this->style()->subControlRect( QStyle::CC_Slider,
  394. &option,
  395. QStyle::SC_SliderGroove,
  396. this );
  397. groove.adjust(0, 0, -1, 0);
  398. // Create default colors based on the transfer function.
  399. //
  400. QColor highlight = this->palette().color(QPalette::Normal, QPalette::Highlight);
  401. QLinearGradient gradient( groove.center().x(), groove.top(),
  402. groove.center().x(), groove.bottom());
  403. // TODO: Set this based on the supplied transfer function
  404. QColor l = Qt::darkGray;
  405. QColor u = Qt::black;
  406. gradient.setColorAt(0, highlight.darker(120));
  407. gradient.setColorAt(1, highlight.lighter(160));
  408. painter.setPen(QPen(highlight.darker(150), 0));
  409. painter.setBrush(gradient);
  410. painter.drawRect( rangeBox.intersected(groove) );
  411. // -----------------------------------
  412. // Render the sliders
  413. //
  414. if (d->m_SelectedHandles & ctkRangeSliderPrivate::MinimumHandle)
  415. {
  416. d->drawMaximumSlider( &painter );
  417. d->drawMinimumSlider( &painter );
  418. }
  419. else
  420. {
  421. d->drawMinimumSlider( &painter );
  422. d->drawMaximumSlider( &painter );
  423. }
  424. }
  425. // --------------------------------------------------------------------------
  426. // Standard Qt UI events
  427. void ctkRangeSlider::mousePressEvent(QMouseEvent* mouseEvent)
  428. {
  429. CTK_D(ctkRangeSlider);
  430. if (minimum() == maximum() || (mouseEvent->buttons() ^ mouseEvent->button()))
  431. {
  432. mouseEvent->ignore();
  433. return;
  434. }
  435. QStyleOptionSlider option;
  436. this->initStyleOption( &option );
  437. // Check if the first handle is pressed
  438. option.sliderPosition = d->m_MinimumPosition;
  439. option.sliderValue = d->m_MinimumValue;
  440. QStyle::SubControl control;
  441. control = this->style()->hitTestComplexControl( QStyle::CC_Slider,
  442. &option,
  443. mouseEvent->pos(),
  444. this);
  445. const QRect lr = this->style()->subControlRect( QStyle::CC_Slider,
  446. &option,
  447. QStyle::SC_SliderHandle,
  448. this);
  449. if (control == QStyle::SC_SliderHandle)
  450. {
  451. d->m_SubclassPosition = d->m_MinimumPosition;
  452. // save the position of the mouse inside the handle for later
  453. d->m_SubclassClickOffset = mouseEvent->x() - lr.left();
  454. this->setSliderDown(true);
  455. if (d->m_SelectedHandles != ctkRangeSliderPrivate::MinimumHandle)
  456. {
  457. d->m_SelectedHandles = ctkRangeSliderPrivate::MinimumHandle;
  458. this->update(lr);
  459. }
  460. // Accept the mouseEvent
  461. mouseEvent->accept();
  462. return;
  463. }
  464. // The user didn't press on the minimum handle,
  465. // Check if the other handle is pressed
  466. option.sliderPosition = d->m_MaximumPosition;
  467. option.sliderValue = d->m_MaximumValue;
  468. control = this->style()->hitTestComplexControl( QStyle::CC_Slider,
  469. &option,
  470. mouseEvent->pos(),
  471. this);
  472. const QRect ur = this->style()->subControlRect( QStyle::CC_Slider,
  473. &option,
  474. QStyle::SC_SliderHandle,
  475. this);
  476. if (control == QStyle::SC_SliderHandle)
  477. {
  478. d->m_SubclassPosition = d->m_MaximumPosition;
  479. // save the position of the mouse inside the handle for later
  480. d->m_SubclassClickOffset = mouseEvent->x() - ur.left();
  481. this->setSliderDown(true);
  482. if (d->m_SelectedHandles != ctkRangeSliderPrivate::MaximumHandle)
  483. {
  484. d->m_SelectedHandles = ctkRangeSliderPrivate::MaximumHandle;
  485. this->update(ur);
  486. }
  487. // Accept the mouseEvent
  488. mouseEvent->accept();
  489. return;
  490. }
  491. // if we are here, no handles have been pressed
  492. // Check if we pressed on the groove between the 2 handles
  493. control = this->style()->hitTestComplexControl( QStyle::CC_Slider,
  494. &option,
  495. mouseEvent->pos(),
  496. this);
  497. QRect sr = style()->subControlRect( QStyle::CC_Slider,
  498. &option,
  499. QStyle::SC_SliderGroove,
  500. this);
  501. if (control == QStyle::SC_SliderGroove &&
  502. mouseEvent->x() > lr.center().x() &&
  503. mouseEvent->x() < ur.center().x())
  504. {
  505. // warning lost of precision it might be fatal
  506. d->m_SubclassPosition = (d->m_MinimumPosition + d->m_MaximumPosition) / 2.;
  507. d->m_SubclassClickOffset = mouseEvent->x() - d->pixelPosFromRangeValue(d->m_SubclassPosition);
  508. d->m_SubclassWidth = (d->m_MaximumPosition - d->m_MinimumPosition) / 2;
  509. qMax(d->m_SubclassPosition - d->m_MinimumPosition, d->m_MaximumPosition - d->m_SubclassPosition);
  510. this->setSliderDown(true);
  511. if (!(d->m_SelectedHandles & QFlags<ctkRangeSliderPrivate::Handle>(
  512. ctkRangeSliderPrivate::MinimumHandle)) ||
  513. !(d->m_SelectedHandles & QFlags<ctkRangeSliderPrivate::Handle>(ctkRangeSliderPrivate::MaximumHandle)))
  514. {
  515. d->m_SelectedHandles =
  516. QFlags<ctkRangeSliderPrivate::Handle>(ctkRangeSliderPrivate::MinimumHandle) |
  517. QFlags<ctkRangeSliderPrivate::Handle>(ctkRangeSliderPrivate::MaximumHandle);
  518. this->update(lr.united(ur).united(sr));
  519. }
  520. mouseEvent->accept();
  521. return;
  522. }
  523. mouseEvent->ignore();
  524. }
  525. // --------------------------------------------------------------------------
  526. // Standard Qt UI events
  527. void ctkRangeSlider::mouseMoveEvent(QMouseEvent* mouseEvent)
  528. {
  529. CTK_D(ctkRangeSlider);
  530. if (!d->m_SelectedHandles)
  531. {
  532. mouseEvent->ignore();
  533. return;
  534. }
  535. QStyleOptionSlider option;
  536. this->initStyleOption(&option);
  537. const int m = style()->pixelMetric( QStyle::PM_MaximumDragDistance, &option, this );
  538. int newPosition = d->pixelPosToRangeValue(
  539. mouseEvent->x() - d->m_SubclassClickOffset);
  540. if (m >= 0)
  541. {
  542. const QRect r = rect().adjusted(-m, -m, m, m);
  543. if (!r.contains(mouseEvent->pos()))
  544. {
  545. newPosition = d->m_SubclassPosition;
  546. }
  547. }
  548. if (d->m_SelectedHandles == ctkRangeSliderPrivate::MinimumHandle)
  549. {
  550. this->setMinimumPosition(qMin(newPosition,d->m_MaximumPosition));
  551. }
  552. else if (d->m_SelectedHandles == ctkRangeSliderPrivate::MaximumHandle)
  553. {
  554. this->setMaximumPosition(qMax(d->m_MinimumPosition, newPosition));
  555. }
  556. else if (d->m_SelectedHandles & ctkRangeSliderPrivate::MinimumHandle &&
  557. d->m_SelectedHandles & ctkRangeSliderPrivate::MaximumHandle)
  558. {
  559. this->setPositions(newPosition - d->m_SubclassWidth, newPosition + d->m_SubclassWidth );
  560. }
  561. mouseEvent->accept();
  562. }
  563. // --------------------------------------------------------------------------
  564. // Standard Qt UI mouseEvents
  565. void ctkRangeSlider::mouseReleaseEvent(QMouseEvent* mouseEvent)
  566. {
  567. CTK_D(ctkRangeSlider);
  568. this->QSlider::mouseReleaseEvent(mouseEvent);
  569. setSliderDown(false);
  570. d->m_SelectedHandles = 0;
  571. this->update();
  572. }