Format ctkRangeSlider
MODIFY
src/ctkrangeslider.cpp
src/ctkrangeslider.cpp
=========================================================================*/
// Qt includes
+#include <QApplication>
#include <QDebug>
-#include <QMouseEvent>
#include <QKeyEvent>
+#include <QMouseEvent>
+#include <QStyle>
#include <QStyleOptionSlider>
-#include <QApplication>
#include <QStylePainter>
-#include <QStyle>
#include <QToolTip>
// CTK includes
#include "ctkrangeslider.h"
-class ctkRangeSliderPrivate
-{
+class ctkRangeSliderPrivate {
Q_DECLARE_PUBLIC(ctkRangeSlider);
+
protected:
ctkRangeSlider* const q_ptr;
+
public:
/// Boolean indicates the selected handle
/// True for the minimum range handle, false for the maximum range handle
- enum Handle {
- NoHandle = 0x0,
- MinimumHandle = 0x1,
- MaximumHandle = 0x2
- };
+ enum Handle { NoHandle = 0x0, MinimumHandle = 0x1, MaximumHandle = 0x2 };
Q_DECLARE_FLAGS(Handles, Handle);
ctkRangeSliderPrivate(ctkRangeSlider& object);
@@ -99,9 +96,7 @@ private:
};
// --------------------------------------------------------------------------
-ctkRangeSliderPrivate::ctkRangeSliderPrivate(ctkRangeSlider& object)
- :q_ptr(&object)
-{
+ctkRangeSliderPrivate::ctkRangeSliderPrivate(ctkRangeSlider& object) : q_ptr(&object) {
this->m_MinimumValue = 0;
this->m_MaximumValue = 100;
this->m_MinimumPosition = 0;
@@ -116,8 +111,7 @@ ctkRangeSliderPrivate::ctkRangeSliderPrivate(ctkRangeSlider& object)
}
// --------------------------------------------------------------------------
-void ctkRangeSliderPrivate::init()
-{
+void ctkRangeSliderPrivate::init() {
Q_Q(ctkRangeSlider);
this->m_MinimumValue = q->minimum();
this->m_MaximumValue = q->maximum();
@@ -127,8 +121,7 @@ void ctkRangeSliderPrivate::init()
}
// --------------------------------------------------------------------------
-ctkRangeSliderPrivate::Handle ctkRangeSliderPrivate::handleAtPos(const QPoint& pos, QRect& handleRect)const
-{
+ctkRangeSliderPrivate::Handle ctkRangeSliderPrivate::handleAtPos(const QPoint& pos, QRect& handleRect) const {
Q_Q(const ctkRangeSlider);
QStyleOptionSlider option;
@@ -142,32 +135,24 @@ ctkRangeSliderPrivate::Handle ctkRangeSliderPrivate::handleAtPos(const QPoint& p
option.sliderPosition = this->m_MinimumPosition;
option.sliderValue = this->m_MinimumValue;
- QStyle::SubControl minimumControl = q->style()->hitTestComplexControl(
- QStyle::CC_Slider, &option, pos, q);
- QRect minimumHandleRect = q->style()->subControlRect(
- QStyle::CC_Slider, &option, QStyle::SC_SliderHandle, q);
+ QStyle::SubControl minimumControl = q->style()->hitTestComplexControl(QStyle::CC_Slider, &option, pos, q);
+ QRect minimumHandleRect = q->style()->subControlRect(QStyle::CC_Slider, &option, QStyle::SC_SliderHandle, q);
// Test if the pos is under the Maximum handle
option.sliderPosition = this->m_MaximumPosition;
option.sliderValue = this->m_MaximumValue;
- QStyle::SubControl maximumControl = q->style()->hitTestComplexControl(
- QStyle::CC_Slider, &option, pos, q);
- QRect maximumHandleRect = q->style()->subControlRect(
- QStyle::CC_Slider, &option, QStyle::SC_SliderHandle, q);
+ QStyle::SubControl maximumControl = q->style()->hitTestComplexControl(QStyle::CC_Slider, &option, pos, q);
+ QRect maximumHandleRect = q->style()->subControlRect(QStyle::CC_Slider, &option, QStyle::SC_SliderHandle, q);
// The pos is above both handles, select the closest handle
- if (minimumControl == QStyle::SC_SliderHandle &&
- maximumControl == QStyle::SC_SliderHandle)
- {
+ if (minimumControl == QStyle::SC_SliderHandle && maximumControl == QStyle::SC_SliderHandle) {
int minDist = 0;
int maxDist = 0;
- if (q->orientation() == Qt::Horizontal)
- {
+ if (q->orientation() == Qt::Horizontal) {
minDist = pos.x() - minimumHandleRect.left();
maxDist = maximumHandleRect.right() - pos.x();
- }
- else //if (q->orientation() == Qt::Vertical)
+ } else // if (q->orientation() == Qt::Vertical)
{
minDist = minimumHandleRect.bottom() - pos.y();
maxDist = pos.y() - maximumHandleRect.top();
@@ -176,13 +161,10 @@ ctkRangeSliderPrivate::Handle ctkRangeSliderPrivate::handleAtPos(const QPoint& p
minimumControl = minDist < maxDist ? minimumControl : QStyle::SC_None;
}
- if (minimumControl == QStyle::SC_SliderHandle)
- {
+ if (minimumControl == QStyle::SC_SliderHandle) {
handleRect = minimumHandleRect;
return MinimumHandle;
- }
- else if (maximumControl == QStyle::SC_SliderHandle)
- {
+ } else if (maximumControl == QStyle::SC_SliderHandle) {
handleRect = maximumHandleRect;
return MaximumHandle;
}
@@ -193,81 +175,54 @@ ctkRangeSliderPrivate::Handle ctkRangeSliderPrivate::handleAtPos(const QPoint& p
// --------------------------------------------------------------------------
// Copied verbatim from QSliderPrivate::pixelPosToRangeValue. See QSlider.cpp
//
-int ctkRangeSliderPrivate::pixelPosToRangeValue( int pos ) const
-{
+int ctkRangeSliderPrivate::pixelPosToRangeValue(int pos) const {
Q_Q(const ctkRangeSlider);
QStyleOptionSlider option;
q->initStyleOption(&option);
- QRect gr = q->style()->subControlRect( QStyle::CC_Slider,
- &option,
- QStyle::SC_SliderGroove,
- q );
- QRect sr = q->style()->subControlRect( QStyle::CC_Slider,
- &option,
- QStyle::SC_SliderHandle,
- q );
+ QRect gr = q->style()->subControlRect(QStyle::CC_Slider, &option, QStyle::SC_SliderGroove, q);
+ QRect sr = q->style()->subControlRect(QStyle::CC_Slider, &option, QStyle::SC_SliderHandle, q);
int sliderMin, sliderMax, sliderLength;
- if (option.orientation == Qt::Horizontal)
- {
+ if (option.orientation == Qt::Horizontal) {
sliderLength = sr.width();
sliderMin = gr.x();
sliderMax = gr.right() - sliderLength + 1;
- }
- else
- {
+ } else {
sliderLength = sr.height();
sliderMin = gr.y();
sliderMax = gr.bottom() - sliderLength + 1;
}
- return QStyle::sliderValueFromPosition( q->minimum(),
- q->maximum(),
- pos - sliderMin,
- sliderMax - sliderMin,
+ return QStyle::sliderValueFromPosition(q->minimum(), q->maximum(), pos - sliderMin, sliderMax - sliderMin,
option.upsideDown);
}
//---------------------------------------------------------------------------
-int ctkRangeSliderPrivate::pixelPosFromRangeValue( int val ) const
-{
+int ctkRangeSliderPrivate::pixelPosFromRangeValue(int val) const {
Q_Q(const ctkRangeSlider);
QStyleOptionSlider option;
q->initStyleOption(&option);
- QRect gr = q->style()->subControlRect( QStyle::CC_Slider,
- &option,
- QStyle::SC_SliderGroove,
- q );
- QRect sr = q->style()->subControlRect( QStyle::CC_Slider,
- &option,
- QStyle::SC_SliderHandle,
- q );
+ QRect gr = q->style()->subControlRect(QStyle::CC_Slider, &option, QStyle::SC_SliderGroove, q);
+ QRect sr = q->style()->subControlRect(QStyle::CC_Slider, &option, QStyle::SC_SliderHandle, q);
int sliderMin, sliderMax, sliderLength;
- if (option.orientation == Qt::Horizontal)
- {
+ if (option.orientation == Qt::Horizontal) {
sliderLength = sr.width();
sliderMin = gr.x();
sliderMax = gr.right() - sliderLength + 1;
- }
- else
- {
+ } else {
sliderLength = sr.height();
sliderMin = gr.y();
sliderMax = gr.bottom() - sliderLength + 1;
}
- return QStyle::sliderPositionFromValue( q->minimum(),
- q->maximum(),
- val,
- sliderMax - sliderMin,
- option.upsideDown ) + sliderMin;
+ return QStyle::sliderPositionFromValue(q->minimum(), q->maximum(), val, sliderMax - sliderMin, option.upsideDown) +
+ sliderMin;
}
//---------------------------------------------------------------------------
// Draw slider at the bottom end of the range
-void ctkRangeSliderPrivate::drawMinimumSlider( QStylePainter* painter ) const
-{
+void ctkRangeSliderPrivate::drawMinimumSlider(QStylePainter* painter) const {
Q_Q(const ctkRangeSlider);
QStyleOptionSlider option;
q->initMinimumSliderStyleOption(&option);
@@ -275,15 +230,13 @@ void ctkRangeSliderPrivate::drawMinimumSlider( QStylePainter* painter ) const
option.subControls = QStyle::SC_SliderHandle;
option.sliderValue = m_MinimumValue;
option.sliderPosition = m_MinimumPosition;
- if (q->isMinimumSliderDown())
- {
+ if (q->isMinimumSliderDown()) {
option.activeSubControls = QStyle::SC_SliderHandle;
option.state |= QStyle::State_Sunken;
}
#ifdef Q_OS_MAC
// On mac style, drawing just the handle actually draws also the groove.
- QRect clip = q->style()->subControlRect(QStyle::CC_Slider, &option,
- QStyle::SC_SliderHandle, q);
+ QRect clip = q->style()->subControlRect(QStyle::CC_Slider, &option, QStyle::SC_SliderHandle, q);
painter->setClipRect(clip);
#endif
painter->drawComplexControl(QStyle::CC_Slider, option);
@@ -291,8 +244,7 @@ void ctkRangeSliderPrivate::drawMinimumSlider( QStylePainter* painter ) const
//---------------------------------------------------------------------------
// Draw slider at the top end of the range
-void ctkRangeSliderPrivate::drawMaximumSlider( QStylePainter* painter ) const
-{
+void ctkRangeSliderPrivate::drawMaximumSlider(QStylePainter* painter) const {
Q_Q(const ctkRangeSlider);
QStyleOptionSlider option;
q->initMaximumSliderStyleOption(&option);
@@ -300,238 +252,186 @@ void ctkRangeSliderPrivate::drawMaximumSlider( QStylePainter* painter ) const
option.subControls = QStyle::SC_SliderHandle;
option.sliderValue = m_MaximumValue;
option.sliderPosition = m_MaximumPosition;
- if (q->isMaximumSliderDown())
- {
+ if (q->isMaximumSliderDown()) {
option.activeSubControls = QStyle::SC_SliderHandle;
option.state |= QStyle::State_Sunken;
}
#ifdef Q_OS_MAC
// On mac style, drawing just the handle actually draws also the groove.
- QRect clip = q->style()->subControlRect(QStyle::CC_Slider, &option,
- QStyle::SC_SliderHandle, q);
+ QRect clip = q->style()->subControlRect(QStyle::CC_Slider, &option, QStyle::SC_SliderHandle, q);
painter->setClipRect(clip);
#endif
painter->drawComplexControl(QStyle::CC_Slider, option);
}
// --------------------------------------------------------------------------
-ctkRangeSlider::ctkRangeSlider(QWidget* _parent)
- : QSlider(_parent)
- , d_ptr(new ctkRangeSliderPrivate(*this))
-{
+ctkRangeSlider::ctkRangeSlider(QWidget* _parent) : QSlider(_parent), d_ptr(new ctkRangeSliderPrivate(*this)) {
Q_D(ctkRangeSlider);
d->init();
}
// --------------------------------------------------------------------------
-ctkRangeSlider::ctkRangeSlider( Qt::Orientation o,
- QWidget* parentObject )
- :QSlider(o, parentObject)
- , d_ptr(new ctkRangeSliderPrivate(*this))
-{
+ctkRangeSlider::ctkRangeSlider(Qt::Orientation o, QWidget* parentObject)
+ : QSlider(o, parentObject), d_ptr(new ctkRangeSliderPrivate(*this)) {
Q_D(ctkRangeSlider);
d->init();
}
// --------------------------------------------------------------------------
-ctkRangeSlider::ctkRangeSlider(ctkRangeSliderPrivate* impl, QWidget* _parent)
- : QSlider(_parent)
- , d_ptr(impl)
-{
+ctkRangeSlider::ctkRangeSlider(ctkRangeSliderPrivate* impl, QWidget* _parent) : QSlider(_parent), d_ptr(impl) {
Q_D(ctkRangeSlider);
d->init();
}
// --------------------------------------------------------------------------
-ctkRangeSlider::ctkRangeSlider( ctkRangeSliderPrivate* impl, Qt::Orientation o,
- QWidget* parentObject )
- :QSlider(o, parentObject)
- , d_ptr(impl)
-{
+ctkRangeSlider::ctkRangeSlider(ctkRangeSliderPrivate* impl, Qt::Orientation o, QWidget* parentObject)
+ : QSlider(o, parentObject), d_ptr(impl) {
Q_D(ctkRangeSlider);
d->init();
}
// --------------------------------------------------------------------------
-ctkRangeSlider::~ctkRangeSlider()
-{
-}
+ctkRangeSlider::~ctkRangeSlider() {}
// --------------------------------------------------------------------------
-int ctkRangeSlider::minimumValue() const
-{
+int ctkRangeSlider::minimumValue() const {
Q_D(const ctkRangeSlider);
return d->m_MinimumValue;
}
// --------------------------------------------------------------------------
-void ctkRangeSlider::setMinimumValue( int min )
-{
+void ctkRangeSlider::setMinimumValue(int min) {
Q_D(ctkRangeSlider);
this->setValues(min, qMax(d->m_MaximumValue, min));
}
// --------------------------------------------------------------------------
-int ctkRangeSlider::maximumValue() const
-{
+int ctkRangeSlider::maximumValue() const {
Q_D(const ctkRangeSlider);
return d->m_MaximumValue;
}
// --------------------------------------------------------------------------
-void ctkRangeSlider::setMaximumValue( int max )
-{
+void ctkRangeSlider::setMaximumValue(int max) {
Q_D(ctkRangeSlider);
this->setValues(qMin(d->m_MinimumValue, max), max);
}
// --------------------------------------------------------------------------
-void ctkRangeSlider::setValues(int l, int u)
-{
+void ctkRangeSlider::setValues(int l, int u) {
Q_D(ctkRangeSlider);
- const int minValue =
- qBound(this->minimum(), qMin(l,u), this->maximum());
- const int maxValue =
- qBound(this->minimum(), qMax(l,u), this->maximum());
+ const int minValue = qBound(this->minimum(), qMin(l, u), this->maximum());
+ const int maxValue = qBound(this->minimum(), qMax(l, u), this->maximum());
bool emitMinValChanged = (minValue != d->m_MinimumValue);
bool emitMaxValChanged = (maxValue != d->m_MaximumValue);
d->m_MinimumValue = minValue;
d->m_MaximumValue = maxValue;
- bool emitMinPosChanged =
- (minValue != d->m_MinimumPosition);
- bool emitMaxPosChanged =
- (maxValue != d->m_MaximumPosition);
+ bool emitMinPosChanged = (minValue != d->m_MinimumPosition);
+ bool emitMaxPosChanged = (maxValue != d->m_MaximumPosition);
d->m_MinimumPosition = minValue;
d->m_MaximumPosition = maxValue;
- if (isSliderDown())
- {
- if (emitMinPosChanged || emitMaxPosChanged)
- {
+ if (isSliderDown()) {
+ if (emitMinPosChanged || emitMaxPosChanged) {
emit positionsChanged(d->m_MinimumPosition, d->m_MaximumPosition);
}
- if (emitMinPosChanged)
- {
+ if (emitMinPosChanged) {
emit minimumPositionChanged(d->m_MinimumPosition);
}
- if (emitMaxPosChanged)
- {
+ if (emitMaxPosChanged) {
emit maximumPositionChanged(d->m_MaximumPosition);
}
}
- if (emitMinValChanged || emitMaxValChanged)
- {
- emit valuesChanged(d->m_MinimumValue,
- d->m_MaximumValue);
+ if (emitMinValChanged || emitMaxValChanged) {
+ emit valuesChanged(d->m_MinimumValue, d->m_MaximumValue);
}
- if (emitMinValChanged)
- {
+ if (emitMinValChanged) {
emit minimumValueChanged(d->m_MinimumValue);
}
- if (emitMaxValChanged)
- {
+ if (emitMaxValChanged) {
emit maximumValueChanged(d->m_MaximumValue);
}
- if (emitMinPosChanged || emitMaxPosChanged ||
- emitMinValChanged || emitMaxValChanged)
- {
+ if (emitMinPosChanged || emitMaxPosChanged || emitMinValChanged || emitMaxValChanged) {
this->update();
}
}
// --------------------------------------------------------------------------
-int ctkRangeSlider::minimumPosition() const
-{
+int ctkRangeSlider::minimumPosition() const {
Q_D(const ctkRangeSlider);
return d->m_MinimumPosition;
}
// --------------------------------------------------------------------------
-int ctkRangeSlider::maximumPosition() const
-{
+int ctkRangeSlider::maximumPosition() const {
Q_D(const ctkRangeSlider);
return d->m_MaximumPosition;
}
// --------------------------------------------------------------------------
-void ctkRangeSlider::setMinimumPosition(int l)
-{
+void ctkRangeSlider::setMinimumPosition(int l) {
Q_D(const ctkRangeSlider);
this->setPositions(l, qMax(l, d->m_MaximumPosition));
}
// --------------------------------------------------------------------------
-void ctkRangeSlider::setMaximumPosition(int u)
-{
+void ctkRangeSlider::setMaximumPosition(int u) {
Q_D(const ctkRangeSlider);
this->setPositions(qMin(d->m_MinimumPosition, u), u);
}
// --------------------------------------------------------------------------
-void ctkRangeSlider::setPositions(int min, int max)
-{
+void ctkRangeSlider::setPositions(int min, int max) {
Q_D(ctkRangeSlider);
- const int minPosition =
- qBound(this->minimum(), qMin(min, max), this->maximum());
- const int maxPosition =
- qBound(this->minimum(), qMax(min, max), this->maximum());
+ const int minPosition = qBound(this->minimum(), qMin(min, max), this->maximum());
+ const int maxPosition = qBound(this->minimum(), qMax(min, max), this->maximum());
bool emitMinPosChanged = (minPosition != d->m_MinimumPosition);
bool emitMaxPosChanged = (maxPosition != d->m_MaximumPosition);
- if (!emitMinPosChanged && !emitMaxPosChanged)
- {
+ if (!emitMinPosChanged && !emitMaxPosChanged) {
return;
}
d->m_MinimumPosition = minPosition;
d->m_MaximumPosition = maxPosition;
- if (!this->hasTracking())
- {
+ if (!this->hasTracking()) {
this->update();
}
- if (isSliderDown())
- {
- if (emitMinPosChanged)
- {
+ if (isSliderDown()) {
+ if (emitMinPosChanged) {
emit minimumPositionChanged(d->m_MinimumPosition);
}
- if (emitMaxPosChanged)
- {
+ if (emitMaxPosChanged) {
emit maximumPositionChanged(d->m_MaximumPosition);
}
- if (emitMinPosChanged || emitMaxPosChanged)
- {
+ if (emitMinPosChanged || emitMaxPosChanged) {
emit positionsChanged(d->m_MinimumPosition, d->m_MaximumPosition);
}
}
- if (this->hasTracking())
- {
+ if (this->hasTracking()) {
this->triggerAction(SliderMove);
this->setValues(d->m_MinimumPosition, d->m_MaximumPosition);
}
}
// --------------------------------------------------------------------------
-void ctkRangeSlider::setSymmetricMoves(bool symmetry)
-{
+void ctkRangeSlider::setSymmetricMoves(bool symmetry) {
Q_D(ctkRangeSlider);
d->m_SymmetricMoves = symmetry;
}
// --------------------------------------------------------------------------
-bool ctkRangeSlider::symmetricMoves()const
-{
+bool ctkRangeSlider::symmetricMoves() const {
Q_D(const ctkRangeSlider);
return d->m_SymmetricMoves;
}
// --------------------------------------------------------------------------
-void ctkRangeSlider::onRangeChanged(int _minimum, int _maximum)
-{
+void ctkRangeSlider::onRangeChanged(int _minimum, int _maximum) {
Q_UNUSED(_minimum);
Q_UNUSED(_maximum);
Q_D(ctkRangeSlider);
@@ -540,8 +440,7 @@ void ctkRangeSlider::onRangeChanged(int _minimum, int _maximum)
// --------------------------------------------------------------------------
// Render
-void ctkRangeSlider::paintEvent( QPaintEvent* )
-{
+void ctkRangeSlider::paintEvent(QPaintEvent*) {
Q_D(ctkRangeSlider);
QStyleOptionSlider option;
this->initStyleOption(&option);
@@ -556,57 +455,35 @@ void ctkRangeSlider::paintEvent( QPaintEvent* )
painter.drawComplexControl(QStyle::CC_Slider, option);
option.sliderPosition = d->m_MinimumPosition;
- const QRect lr = style()->subControlRect( QStyle::CC_Slider,
- &option,
- QStyle::SC_SliderHandle,
- this);
+ const QRect lr = style()->subControlRect(QStyle::CC_Slider, &option, QStyle::SC_SliderHandle, this);
option.sliderPosition = d->m_MaximumPosition;
- const QRect ur = style()->subControlRect( QStyle::CC_Slider,
- &option,
- QStyle::SC_SliderHandle,
- this);
+ const QRect ur = style()->subControlRect(QStyle::CC_Slider, &option, QStyle::SC_SliderHandle, this);
- QRect sr = style()->subControlRect( QStyle::CC_Slider,
- &option,
- QStyle::SC_SliderGroove,
- this);
+ QRect sr = style()->subControlRect(QStyle::CC_Slider, &option, QStyle::SC_SliderGroove, this);
QRect rangeBox;
- if (option.orientation == Qt::Horizontal)
- {
- rangeBox = QRect(
- QPoint(qMin( lr.center().x(), ur.center().x() ), sr.center().y() - 2),
+ if (option.orientation == Qt::Horizontal) {
+ rangeBox = QRect(QPoint(qMin(lr.center().x(), ur.center().x()), sr.center().y() - 2),
QPoint(qMax(lr.center().x(), ur.center().x()), sr.center().y() + 1));
- }
- else
- {
- rangeBox = QRect(
- QPoint(sr.center().x() - 2, qMin( lr.center().y(), ur.center().y() )),
+ } else {
+ rangeBox = QRect(QPoint(sr.center().x() - 2, qMin(lr.center().y(), ur.center().y())),
QPoint(sr.center().x() + 1, qMax(lr.center().y(), ur.center().y())));
}
// -----------------------------
// Render the range
//
- QRect groove = this->style()->subControlRect( QStyle::CC_Slider,
- &option,
- QStyle::SC_SliderGroove,
- this );
+ QRect groove = this->style()->subControlRect(QStyle::CC_Slider, &option, QStyle::SC_SliderGroove, this);
groove.adjust(0, 0, -1, 0);
// Create default colors based on the transfer function.
//
QColor highlight = this->palette().color(QPalette::Normal, QPalette::Highlight);
QLinearGradient gradient;
- if (option.orientation == Qt::Horizontal)
- {
- gradient = QLinearGradient( groove.center().x(), groove.top(),
- groove.center().x(), groove.bottom());
- }
- else
- {
- gradient = QLinearGradient( groove.left(), groove.center().y(),
- groove.right(), groove.center().y());
+ if (option.orientation == Qt::Horizontal) {
+ gradient = QLinearGradient(groove.center().x(), groove.top(), groove.center().x(), groove.bottom());
+ } else {
+ gradient = QLinearGradient(groove.left(), groove.center().y(), groove.right(), groove.center().y());
}
// TODO: Set this based on the supplied transfer function
@@ -623,13 +500,10 @@ void ctkRangeSlider::paintEvent( QPaintEvent* )
// -----------------------------------
// Render the sliders
//
- if (this->isMinimumSliderDown())
- {
+ if (this->isMinimumSliderDown()) {
d->drawMaximumSlider(&painter);
d->drawMinimumSlider(&painter);
- }
- else
- {
+ } else {
d->drawMinimumSlider(&painter);
d->drawMaximumSlider(&painter);
}
@@ -637,16 +511,13 @@ void ctkRangeSlider::paintEvent( QPaintEvent* )
// --------------------------------------------------------------------------
// Standard Qt UI events
-void ctkRangeSlider::mousePressEvent(QMouseEvent* mouseEvent)
-{
+void ctkRangeSlider::mousePressEvent(QMouseEvent* mouseEvent) {
Q_D(ctkRangeSlider);
- if (minimum() == maximum() || (mouseEvent->buttons() ^ mouseEvent->button()))
- {
+ if (minimum() == maximum() || (mouseEvent->buttons() ^ mouseEvent->button())) {
mouseEvent->ignore();
return;
}
- int mepos = this->orientation() == Qt::Horizontal ?
- mouseEvent->pos().x() : mouseEvent->pos().y();
+ int mepos = this->orientation() == Qt::Horizontal ? mouseEvent->pos().x() : mouseEvent->pos().y();
QStyleOptionSlider option;
this->initStyleOption(&option);
@@ -654,19 +525,17 @@ void ctkRangeSlider::mousePressEvent(QMouseEvent* mouseEvent)
QRect handleRect;
ctkRangeSliderPrivate::Handle handle_ = d->handleAtPos(mouseEvent->pos(), handleRect);
- if (handle_ != ctkRangeSliderPrivate::NoHandle)
- {
- d->m_SubclassPosition = (handle_ == ctkRangeSliderPrivate::MinimumHandle)?
- d->m_MinimumPosition : d->m_MaximumPosition;
+ if (handle_ != ctkRangeSliderPrivate::NoHandle) {
+ d->m_SubclassPosition =
+ (handle_ == ctkRangeSliderPrivate::MinimumHandle) ? d->m_MinimumPosition : d->m_MaximumPosition;
// save the position of the mouse inside the handle for later
- d->m_SubclassClickOffset = mepos - (this->orientation() == Qt::Horizontal ?
- handleRect.left() : handleRect.top());
+ d->m_SubclassClickOffset =
+ mepos - (this->orientation() == Qt::Horizontal ? handleRect.left() : handleRect.top());
this->setSliderDown(true);
- if (d->m_SelectedHandles != handle_)
- {
+ if (d->m_SelectedHandles != handle_) {
d->m_SelectedHandles = handle_;
this->update(handleRect);
}
@@ -678,27 +547,20 @@ void ctkRangeSlider::mousePressEvent(QMouseEvent* mouseEvent)
// if we are here, no handles have been pressed
// Check if we pressed on the groove between the 2 handles
- QStyle::SubControl control = this->style()->hitTestComplexControl(
- QStyle::CC_Slider, &option, mouseEvent->pos(), this);
- QRect sr = style()->subControlRect(
- QStyle::CC_Slider, &option, QStyle::SC_SliderGroove, this);
- int minCenter = (this->orientation() == Qt::Horizontal ?
- handleRect.left() : handleRect.top());
- int maxCenter = (this->orientation() == Qt::Horizontal ?
- handleRect.right() : handleRect.bottom());
- if (control == QStyle::SC_SliderGroove &&
- mepos > minCenter && mepos < maxCenter)
- {
+ QStyle::SubControl control =
+ this->style()->hitTestComplexControl(QStyle::CC_Slider, &option, mouseEvent->pos(), this);
+ QRect sr = style()->subControlRect(QStyle::CC_Slider, &option, QStyle::SC_SliderGroove, this);
+ int minCenter = (this->orientation() == Qt::Horizontal ? handleRect.left() : handleRect.top());
+ int maxCenter = (this->orientation() == Qt::Horizontal ? handleRect.right() : handleRect.bottom());
+ if (control == QStyle::SC_SliderGroove && mepos > minCenter && mepos < maxCenter) {
// warning lost of precision it might be fatal
d->m_SubclassPosition = (d->m_MinimumPosition + d->m_MaximumPosition) / 2.;
d->m_SubclassClickOffset = mepos - d->pixelPosFromRangeValue(d->m_SubclassPosition);
d->m_SubclassWidth = (d->m_MaximumPosition - d->m_MinimumPosition) / 2;
qMax(d->m_SubclassPosition - d->m_MinimumPosition, d->m_MaximumPosition - d->m_SubclassPosition);
this->setSliderDown(true);
- if (!this->isMinimumSliderDown() || !this->isMaximumSliderDown())
- {
- d->m_SelectedHandles =
- QFlags<ctkRangeSliderPrivate::Handle>(ctkRangeSliderPrivate::MinimumHandle) |
+ if (!this->isMinimumSliderDown() || !this->isMaximumSliderDown()) {
+ d->m_SelectedHandles = QFlags<ctkRangeSliderPrivate::Handle>(ctkRangeSliderPrivate::MinimumHandle) |
QFlags<ctkRangeSliderPrivate::Handle>(ctkRangeSliderPrivate::MaximumHandle);
this->update(handleRect.united(sr));
}
@@ -710,16 +572,13 @@ void ctkRangeSlider::mousePressEvent(QMouseEvent* mouseEvent)
// --------------------------------------------------------------------------
// Standard Qt UI events
-void ctkRangeSlider::mouseMoveEvent(QMouseEvent* mouseEvent)
-{
+void ctkRangeSlider::mouseMoveEvent(QMouseEvent* mouseEvent) {
Q_D(ctkRangeSlider);
- if (!d->m_SelectedHandles)
- {
+ if (!d->m_SelectedHandles) {
mouseEvent->ignore();
return;
}
- int mepos = this->orientation() == Qt::Horizontal ?
- mouseEvent->pos().x() : mouseEvent->pos().y();
+ int mepos = this->orientation() == Qt::Horizontal ? mouseEvent->pos().x() : mouseEvent->pos().y();
QStyleOptionSlider option;
this->initStyleOption(&option);
@@ -728,43 +587,35 @@ void ctkRangeSlider::mouseMoveEvent(QMouseEvent* mouseEvent)
int newPosition = d->pixelPosToRangeValue(mepos - d->m_SubclassClickOffset);
- if (m >= 0)
- {
+ if (m >= 0) {
const QRect r = rect().adjusted(-m, -m, m, m);
- if (!r.contains(mouseEvent->pos()))
- {
+ if (!r.contains(mouseEvent->pos())) {
newPosition = d->m_SubclassPosition;
}
}
// Only the lower/left slider is down
- if (this->isMinimumSliderDown() && !this->isMaximumSliderDown())
- {
+ if (this->isMinimumSliderDown() && !this->isMaximumSliderDown()) {
double newMinPos = qMin(newPosition, d->m_MaximumPosition);
- this->setPositions(newMinPos, d->m_MaximumPosition +
- (d->m_SymmetricMoves ? d->m_MinimumPosition - newMinPos : 0));
+ this->setPositions(newMinPos,
+ d->m_MaximumPosition + (d->m_SymmetricMoves ? d->m_MinimumPosition - newMinPos : 0));
}
// Only the upper/right slider is down
- else if (this->isMaximumSliderDown() && !this->isMinimumSliderDown())
- {
+ else if (this->isMaximumSliderDown() && !this->isMinimumSliderDown()) {
double newMaxPos = qMax(d->m_MinimumPosition, newPosition);
- this->setPositions(d->m_MinimumPosition -
- (d->m_SymmetricMoves ? newMaxPos - d->m_MaximumPosition: 0),
+ this->setPositions(d->m_MinimumPosition - (d->m_SymmetricMoves ? newMaxPos - d->m_MaximumPosition : 0),
newMaxPos);
}
// Both handles are down (the user clicked in between the handles)
- else if (this->isMinimumSliderDown() && this->isMaximumSliderDown())
- {
- this->setPositions(newPosition - d->m_SubclassWidth,
- newPosition + d->m_SubclassWidth );
+ else if (this->isMinimumSliderDown() && this->isMaximumSliderDown()) {
+ this->setPositions(newPosition - d->m_SubclassWidth, newPosition + d->m_SubclassWidth);
}
mouseEvent->accept();
}
// --------------------------------------------------------------------------
// Standard Qt UI mouseEvents
-void ctkRangeSlider::mouseReleaseEvent(QMouseEvent* mouseEvent)
-{
+void ctkRangeSlider::mouseReleaseEvent(QMouseEvent* mouseEvent) {
Q_D(ctkRangeSlider);
this->QSlider::mouseReleaseEvent(mouseEvent);
@@ -775,53 +626,44 @@ void ctkRangeSlider::mouseReleaseEvent(QMouseEvent* mouseEvent)
}
// --------------------------------------------------------------------------
-bool ctkRangeSlider::isMinimumSliderDown()const
-{
+bool ctkRangeSlider::isMinimumSliderDown() const {
Q_D(const ctkRangeSlider);
return d->m_SelectedHandles & ctkRangeSliderPrivate::MinimumHandle;
}
// --------------------------------------------------------------------------
-bool ctkRangeSlider::isMaximumSliderDown()const
-{
+bool ctkRangeSlider::isMaximumSliderDown() const {
Q_D(const ctkRangeSlider);
return d->m_SelectedHandles & ctkRangeSliderPrivate::MaximumHandle;
}
// --------------------------------------------------------------------------
-void ctkRangeSlider::initMinimumSliderStyleOption(QStyleOptionSlider* option) const
-{
+void ctkRangeSlider::initMinimumSliderStyleOption(QStyleOptionSlider* option) const {
this->initStyleOption(option);
}
// --------------------------------------------------------------------------
-void ctkRangeSlider::initMaximumSliderStyleOption(QStyleOptionSlider* option) const
-{
+void ctkRangeSlider::initMaximumSliderStyleOption(QStyleOptionSlider* option) const {
this->initStyleOption(option);
}
// --------------------------------------------------------------------------
-QString ctkRangeSlider::handleToolTip()const
-{
+QString ctkRangeSlider::handleToolTip() const {
Q_D(const ctkRangeSlider);
return d->m_HandleToolTip;
}
// --------------------------------------------------------------------------
-void ctkRangeSlider::setHandleToolTip(const QString& _toolTip)
-{
+void ctkRangeSlider::setHandleToolTip(const QString& _toolTip) {
Q_D(ctkRangeSlider);
d->m_HandleToolTip = _toolTip;
}
// --------------------------------------------------------------------------
-bool ctkRangeSlider::event(QEvent* _event)
-{
+bool ctkRangeSlider::event(QEvent* _event) {
Q_D(ctkRangeSlider);
- switch(_event->type())
- {
- case QEvent::ToolTip:
- {
+ switch (_event->type()) {
+ case QEvent::ToolTip: {
QHelpEvent* helpEvent = static_cast<QHelpEvent*>(_event);
QStyleOptionSlider opt;
// Test the MinimumHandle
@@ -829,11 +671,8 @@ bool ctkRangeSlider::event(QEvent* _event)
opt.sliderValue = d->m_MinimumValue;
this->initStyleOption(&opt);
QStyle::SubControl hoveredControl =
- this->style()->hitTestComplexControl(
- QStyle::CC_Slider, &opt, helpEvent->pos(), this);
- if (!d->m_HandleToolTip.isEmpty() &&
- hoveredControl == QStyle::SC_SliderHandle)
- {
+ this->style()->hitTestComplexControl(QStyle::CC_Slider, &opt, helpEvent->pos(), this);
+ if (!d->m_HandleToolTip.isEmpty() && hoveredControl == QStyle::SC_SliderHandle) {
QToolTip::showText(helpEvent->globalPos(), d->m_HandleToolTip.arg(this->minimumValue()));
_event->accept();
return true;
@@ -842,11 +681,8 @@ bool ctkRangeSlider::event(QEvent* _event)
opt.sliderPosition = d->m_MaximumPosition;
opt.sliderValue = d->m_MaximumValue;
this->initStyleOption(&opt);
- hoveredControl = this->style()->hitTestComplexControl(
- QStyle::CC_Slider, &opt, helpEvent->pos(), this);
- if (!d->m_HandleToolTip.isEmpty() &&
- hoveredControl == QStyle::SC_SliderHandle)
- {
+ hoveredControl = this->style()->hitTestComplexControl(QStyle::CC_Slider, &opt, helpEvent->pos(), this);
+ if (!d->m_HandleToolTip.isEmpty() && hoveredControl == QStyle::SC_SliderHandle) {
QToolTip::showText(helpEvent->globalPos(), d->m_HandleToolTip.arg(this->maximumValue()));
_event->accept();
return true;

MODIFY
src/ctkrangeslider.h
src/ctkrangeslider.h
@@ -45,8 +45,7 @@ class ctkRangeSliderPrivate;
/// TODO: support triggerAction(QAbstractSlider::SliderSingleStepSub) that
/// moves both values at a time.
/// \sa ctkDoubleRangeSlider, ctkDoubleSlider, ctkRangeWidget
-class ctkRangeSlider : public QSlider
-{
+class ctkRangeSlider : public QSlider {
Q_OBJECT
Q_PROPERTY(int minimumValue READ minimumValue WRITE setMinimumValue)
Q_PROPERTY(int maximumValue READ maximumValue WRITE setMaximumValue)

Format ctkRangeSlider