17#include "moc_qgsrangeslider.cpp"
29 mStyleOption.minimum = 0;
30 mStyleOption.maximum = 100;
33 setFocusPolicy( Qt::FocusPolicy( style()->styleHint( QStyle::SH_Button_FocusPolicy ) ) );
34 QSizePolicy sp( QSizePolicy::Expanding, QSizePolicy::Fixed, QSizePolicy::Slider );
35 if ( mStyleOption.orientation == Qt::Vertical )
38 setAttribute( Qt::WA_WState_OwnSizePolicy,
false );
40 setAttribute( Qt::WA_Hover );
41 setMouseTracking(
true );
46 return mStyleOption.maximum;
51 if ( mStyleOption.maximum ==
maximum )
55 mStyleOption.minimum = std::min(
maximum, mStyleOption.minimum );
60 mUpperValue = std::min( mUpperValue,
maximum );
61 mLowerValue = std::min( mLowerValue,
maximum );
70 return mStyleOption.minimum;
75 if ( mStyleOption.minimum ==
minimum )
78 mStyleOption.maximum = std::max(
minimum, mStyleOption.maximum );
83 mUpperValue = std::max( mUpperValue,
minimum );
84 mLowerValue = std::max( mLowerValue,
minimum );
96 if ( mStyleOption.minimum ==
minimum && mStyleOption.maximum ==
maximum )
100 mStyleOption.maximum =
maximum;
103 if ( mUpperValue <
minimum || mLowerValue < minimum || mUpperValue >
maximum || mLowerValue >
maximum )
105 mUpperValue = std::min(
maximum, std::max( mUpperValue,
minimum ) );
106 mLowerValue = std::min(
maximum, std::max( mLowerValue,
minimum ) );
123 mLowerValue = std::min( mStyleOption.maximum, std::max( mStyleOption.minimum,
lowerValue ) );
124 if ( mFixedRangeSize >= 0 )
126 mUpperValue = std::min( mLowerValue + mFixedRangeSize, mStyleOption.maximum );
127 mLowerValue = std::max( mStyleOption.minimum, mUpperValue - mFixedRangeSize );
131 mUpperValue = std::max( mLowerValue, mUpperValue );
148 mUpperValue = std::max( mStyleOption.minimum, std::min( mStyleOption.maximum,
upperValue ) );
149 if ( mFixedRangeSize >= 0 )
151 mLowerValue = std::max( mStyleOption.minimum, mUpperValue - mFixedRangeSize );
152 mUpperValue = std::min( mLowerValue + mFixedRangeSize, mStyleOption.maximum );
156 mLowerValue = std::min( mLowerValue, mUpperValue );
165 if ( lower == mLowerValue && upper == mUpperValue )
169 std::swap( lower, upper );
171 mLowerValue = std::min( mStyleOption.maximum, std::max( mStyleOption.minimum, lower ) );
172 mUpperValue = std::min( mStyleOption.maximum, std::max( mStyleOption.minimum, upper ) );
173 if ( mFixedRangeSize >= 0 )
175 mUpperValue = std::min( mLowerValue + mFixedRangeSize, mStyleOption.maximum );
176 mLowerValue = std::max( mStyleOption.minimum, mUpperValue - mFixedRangeSize );
180 mUpperValue = std::min( mStyleOption.maximum, std::max( mStyleOption.minimum, upper ) );
188 switch (
event->type() )
190 case QEvent::HoverEnter:
191 case QEvent::HoverLeave:
192 case QEvent::HoverMove:
193 if (
const QHoverEvent *he =
static_cast<const QHoverEvent *
>(
event ) )
194 updateHoverControl( he->pos() );
199 return QWidget::event(
event );
202int QgsRangeSlider::pick(
const QPoint &pt )
const
204 return mStyleOption.orientation == Qt::Horizontal ? pt.x() : pt.y();
207int QgsRangeSlider::pixelPosToRangeValue(
int pos )
const
209 const QRect gr = style()->subControlRect( QStyle::CC_Slider, &mStyleOption, QStyle::SC_SliderGroove,
this );
210 const QRect sr = style()->subControlRect( QStyle::CC_Slider, &mStyleOption, QStyle::SC_SliderHandle,
this );
211 int sliderMin, sliderMax, sliderLength;
212 if ( mStyleOption.orientation == Qt::Horizontal )
214 sliderLength = sr.width();
216 sliderMax = gr.right() - sliderLength + 1;
220 sliderLength = sr.height();
222 sliderMax = gr.bottom() - sliderLength + 1;
225 int value = QStyle::sliderValueFromPosition( mStyleOption.minimum, mStyleOption.maximum, pos - sliderMin, sliderMax - sliderMin );
227 value = mStyleOption.maximum + mStyleOption.minimum - value;
231bool QgsRangeSlider::updateHoverControl(
const QPoint &pos )
233 const QRect lastHoverRect = mHoverRect;
234 const bool doesHover = testAttribute( Qt::WA_Hover );
235 if ( doesHover && newHoverControl( pos ) )
237 update( lastHoverRect );
238 update( mHoverRect );
244bool QgsRangeSlider::newHoverControl(
const QPoint &pos )
246 const Control lastHoverControl = mHoverControl;
247 const QStyle::SubControl lastHoverSubControl = mHoverSubControl;
249 mStyleOption.subControls = QStyle::SC_All;
251 mStyleOption.sliderPosition = unFlippedSliderPosition( mLowerValue );
252 const QRect lowerHandleRect = style()->subControlRect( QStyle::CC_Slider, &mStyleOption, QStyle::SC_SliderHandle,
this );
253 mStyleOption.sliderPosition = unFlippedSliderPosition( mUpperValue );
254 const QRect upperHandleRect = style()->subControlRect( QStyle::CC_Slider, &mStyleOption, QStyle::SC_SliderHandle,
this );
256 const QRect grooveRect = style()->subControlRect( QStyle::CC_Slider, &mStyleOption, QStyle::SC_SliderGroove,
this );
257 const QRect tickmarksRect = style()->subControlRect( QStyle::CC_Slider, &mStyleOption, QStyle::SC_SliderTickmarks,
this );
258 if ( lowerHandleRect.contains( pos ) )
260 mHoverRect = lowerHandleRect;
261 mHoverControl = Lower;
262 mHoverSubControl = QStyle::SC_SliderHandle;
263 setCursor( Qt::OpenHandCursor );
265 else if ( upperHandleRect.contains( pos ) )
267 mHoverRect = upperHandleRect;
268 mHoverControl = Upper;
269 mHoverSubControl = QStyle::SC_SliderHandle;
270 setCursor( Qt::OpenHandCursor );
272 else if ( grooveRect.contains( pos ) )
274 mHoverRect = grooveRect;
275 mHoverControl = None;
276 mHoverSubControl = QStyle::SC_SliderGroove;
278 if ( selectedRangeRect().contains( pos ) )
279 setCursor( Qt::OpenHandCursor );
283 else if ( tickmarksRect.contains( pos ) )
285 mHoverRect = tickmarksRect;
286 mHoverControl = None;
287 mHoverSubControl = QStyle::SC_SliderTickmarks;
292 mHoverRect = QRect();
293 mHoverControl = None;
294 mHoverSubControl = QStyle::SC_None;
297 return mHoverSubControl != lastHoverSubControl || mHoverControl != lastHoverControl;
300QRect QgsRangeSlider::selectedRangeRect()
304 mStyleOption.activeSubControls = mHoverControl == Lower || mActiveControl == Lower ? QStyle::SC_SliderHandle : QStyle::SC_None;
305 mStyleOption.sliderPosition = unFlippedSliderPosition( mLowerValue );
306 const QRect lowerHandleRect = style()->subControlRect( QStyle::CC_Slider, &mStyleOption, QStyle::SC_SliderHandle,
nullptr );
308 mStyleOption.activeSubControls = mHoverControl == Upper || mActiveControl == Lower ? QStyle::SC_SliderHandle : QStyle::SC_None;
309 mStyleOption.sliderPosition = unFlippedSliderPosition( mUpperValue );
310 const QRect upperHandleRect = style()->subControlRect( QStyle::CC_Slider, &mStyleOption, QStyle::SC_SliderHandle,
nullptr );
312 const QRect grooveRect = style()->subControlRect( QStyle::CC_Slider, &mStyleOption, QStyle::SC_SliderGroove,
nullptr );
314 switch ( mStyleOption.orientation )
317 selectionRect = mFlipped ? QRect( upperHandleRect.right(), grooveRect.y(), lowerHandleRect.left() - upperHandleRect.right(), grooveRect.height() )
318 : QRect( lowerHandleRect.right(), grooveRect.y(), upperHandleRect.left() - lowerHandleRect.right(), grooveRect.height() );
322 selectionRect = mFlipped ? QRect( grooveRect.x(), lowerHandleRect.top(), grooveRect.width(), upperHandleRect.bottom() - lowerHandleRect.top() )
323 : QRect( grooveRect.x(), upperHandleRect.top(), grooveRect.width(), lowerHandleRect.bottom() - upperHandleRect.top() );
327 return selectionRect.adjusted( -1, 1, 1, -1 );
332 return mFixedRangeSize;
337 if ( size == mFixedRangeSize )
340 mFixedRangeSize = size;
342 if ( mFixedRangeSize >= 0 )
348void QgsRangeSlider::applyStep(
int step )
350 switch ( mFocusControl )
354 const int newLowerValue = std::min( mUpperValue, std::min( mStyleOption.maximum, std::max( mStyleOption.minimum, mLowerValue + step ) ) );
355 if ( newLowerValue != mLowerValue )
357 mLowerValue = newLowerValue;
358 if ( mFixedRangeSize >= 0 )
360 mUpperValue = std::min( mLowerValue + mFixedRangeSize, mStyleOption.maximum );
361 mLowerValue = std::max( mStyleOption.minimum, mUpperValue - mFixedRangeSize );
371 const int newUpperValue = std::max( mLowerValue, std::min( mStyleOption.maximum, std::max( mStyleOption.minimum, mUpperValue + step ) ) );
372 if ( newUpperValue != mUpperValue )
374 mUpperValue = newUpperValue;
375 if ( mFixedRangeSize >= 0 )
377 mLowerValue = std::max( mStyleOption.minimum, mUpperValue - mFixedRangeSize );
378 mUpperValue = std::min( mLowerValue + mFixedRangeSize, mStyleOption.maximum );
390 const int previousWidth = mUpperValue - mLowerValue;
391 const int newLowerValue = std::min( mUpperValue, std::min( mStyleOption.maximum, std::max( mStyleOption.minimum, mLowerValue + step ) ) );
392 if ( newLowerValue != mLowerValue )
394 mLowerValue = newLowerValue;
395 if ( mFixedRangeSize >= 0 )
397 mUpperValue = std::min( mLowerValue + mFixedRangeSize, mStyleOption.maximum );
398 mLowerValue = std::max( mStyleOption.minimum, mUpperValue - mFixedRangeSize );
402 mUpperValue = std::min( mStyleOption.maximum, mLowerValue + previousWidth );
410 const int previousWidth = mUpperValue - mLowerValue;
411 const int newUpperValue = std::max( mLowerValue, std::min( mStyleOption.maximum, std::max( mStyleOption.minimum, mUpperValue + step ) ) );
412 if ( newUpperValue != mUpperValue )
414 mUpperValue = newUpperValue;
415 if ( mFixedRangeSize >= 0 )
417 mLowerValue = std::max( mStyleOption.minimum, mUpperValue - mFixedRangeSize );
418 mUpperValue = std::min( mLowerValue + mFixedRangeSize, mStyleOption.maximum );
422 mLowerValue = std::max( mStyleOption.minimum, mUpperValue - previousWidth );
437int QgsRangeSlider::unFlippedSliderPosition(
int value )
const
439 return mFlipped ? mStyleOption.maximum + mStyleOption.minimum - value : value;
464 mStyleOption.tickPosition = position;
470 return mStyleOption.tickPosition;
475 mStyleOption.tickInterval = interval;
481 return mStyleOption.tickInterval;
487 if ( !testAttribute( Qt::WA_WState_OwnSizePolicy ) )
489 setSizePolicy( sizePolicy().transposed() );
490 setAttribute( Qt::WA_WState_OwnSizePolicy,
false );
498 return mStyleOption.orientation;
514 QPainter painter(
this );
516 mStyleOption.initFrom(
this );
517 mStyleOption.rect = rect();
518 mStyleOption.sliderPosition = mStyleOption.minimum;
519 mStyleOption.subControls = QStyle::SC_SliderGroove | QStyle::SC_SliderTickmarks;
521 mStyleOption.activeSubControls = mHoverSubControl;
523 style()->drawComplexControl( QStyle::CC_Slider, &mStyleOption, &painter );
525 QColor color = palette().color( QPalette::Highlight );
526 color.setAlpha( 160 );
527 painter.setBrush( QBrush( color ) );
528 painter.setPen( Qt::NoPen );
529 painter.drawRect( selectedRangeRect() );
532 mStyleOption.subControls = QStyle::SC_SliderHandle;
533 mStyleOption.activeSubControls = mHoverControl == Lower || mActiveControl == Lower ? QStyle::SC_SliderHandle : QStyle::SC_None;
534 mStyleOption.sliderPosition = unFlippedSliderPosition( mLowerValue );
535 if ( mActiveControl == Lower )
536 mStyleOption.state |= QStyle::State_Sunken;
538 mStyleOption.state &= ~QStyle::State_Sunken;
539 style()->drawComplexControl( QStyle::CC_Slider, &mStyleOption, &painter );
542 mStyleOption.activeSubControls = mHoverControl == Upper || mActiveControl == Lower ? QStyle::SC_SliderHandle : QStyle::SC_None;
543 mStyleOption.sliderPosition = unFlippedSliderPosition( mUpperValue );
544 if ( mActiveControl == Upper )
545 mStyleOption.state |= QStyle::State_Sunken;
547 mStyleOption.state &= ~QStyle::State_Sunken;
548 style()->drawComplexControl( QStyle::CC_Slider, &mStyleOption, &painter );
550 if ( hasFocus() && mFocusControl != None )
553 QStyleOptionFocusRect option;
554 option.initFrom(
this );
555 option.state = QStyle::State_KeyboardFocusChange;
556 if ( mFocusControl == Lower )
558 mStyleOption.sliderPosition = unFlippedSliderPosition( mLowerValue );
559 option.rect = style()->subControlRect( QStyle::CC_Slider, &mStyleOption, QStyle::SC_SliderHandle,
this );
561 else if ( mFocusControl == Upper )
563 mStyleOption.sliderPosition = unFlippedSliderPosition( mUpperValue );
564 option.rect = style()->subControlRect( QStyle::CC_Slider, &mStyleOption, QStyle::SC_SliderHandle,
this );
566 else if ( mFocusControl == Range )
568 option.rect = selectedRangeRect();
569 if ( mStyleOption.orientation == Qt::Horizontal )
570 option.rect = option.rect.adjusted( 0, -1, 0, 1 );
572 option.rect = option.rect.adjusted( -1, 0, 1, 0 );
574 style()->drawPrimitive( QStyle::PE_FrameFocusRect, &option, &painter );
580 if ( mStyleOption.maximum == mStyleOption.minimum || (
event->buttons() ^
event->button() ) )
588 mStyleOption.sliderPosition = unFlippedSliderPosition( mLowerValue );
589 const bool overLowerControl = style()->hitTestComplexControl( QStyle::CC_Slider, &mStyleOption,
event->pos(),
this ) == QStyle::SC_SliderHandle;
590 const QRect lowerSliderRect = style()->subControlRect( QStyle::CC_Slider, &mStyleOption, QStyle::SC_SliderHandle,
this );
591 mStyleOption.sliderPosition = unFlippedSliderPosition( mUpperValue );
592 const bool overUpperControl = style()->hitTestComplexControl( QStyle::CC_Slider, &mStyleOption,
event->pos(),
this ) == QStyle::SC_SliderHandle;
593 const QRect upperSliderRect = style()->subControlRect( QStyle::CC_Slider, &mStyleOption, QStyle::SC_SliderHandle,
this );
595 const bool overSelectedRange = selectedRangeRect().contains(
event->pos() );
597 mLowerClickOffset = pick(
event->pos() - lowerSliderRect.topLeft() );
598 mUpperClickOffset = pick(
event->pos() - upperSliderRect.topLeft() );
600 mPreDragLowerValue = mLowerValue;
601 mPreDragUpperValue = mUpperValue;
602 mRangeDragOffset = 0;
604 if ( ( overLowerControl || overUpperControl ) &&
event->modifiers() & Qt::ShiftModifier )
606 mActiveControl = Range;
607 mRangeDragOffset = overUpperControl ? mUpperClickOffset : mLowerClickOffset;
608 mFocusControl = overUpperControl ? Upper : Lower;
610 else if ( overLowerControl && overUpperControl )
611 mActiveControl = Both;
612 else if ( overLowerControl )
614 mActiveControl = Lower;
615 mFocusControl = Lower;
617 else if ( overUpperControl )
619 mActiveControl = Upper;
620 mFocusControl = Upper;
622 else if ( overSelectedRange )
624 mActiveControl = Range;
625 mFocusControl = Range;
628 mActiveControl = None;
630 if ( mActiveControl != None )
632 mStartDragPos = pixelPosToRangeValue( pick(
event->pos() ) - mRangeDragOffset );
638 if ( mActiveControl == None )
646 int newPosition = pixelPosToRangeValue( pick(
event->pos() ) );
648 bool changed =
false;
649 Control destControl = mActiveControl;
650 if ( destControl == Both )
653 if ( newPosition < mStartDragPos )
656 mFocusControl = Lower;
657 if ( mUpperValue != mPreDragUpperValue )
660 mUpperValue = mPreDragUpperValue;
661 if ( mFixedRangeSize >= 0 )
664 mLowerValue = std::max( mStyleOption.minimum, mUpperValue - mFixedRangeSize );
665 mUpperValue = std::min( mLowerValue + mFixedRangeSize, mStyleOption.maximum );
669 else if ( newPosition > mStartDragPos )
672 mFocusControl = Upper;
673 if ( mLowerValue != mPreDragLowerValue )
676 mLowerValue = mPreDragLowerValue;
677 if ( mFixedRangeSize >= 0 )
680 mUpperValue = std::min( mLowerValue + mFixedRangeSize, mStyleOption.maximum );
681 mLowerValue = std::max( mStyleOption.minimum, mUpperValue - mFixedRangeSize );
688 if ( mUpperValue != mPreDragUpperValue )
691 mUpperValue = mPreDragUpperValue;
692 if ( mFixedRangeSize >= 0 )
695 mLowerValue = std::max( mStyleOption.minimum, mUpperValue - mFixedRangeSize );
696 mUpperValue = std::min( mLowerValue + mFixedRangeSize, mStyleOption.maximum );
699 if ( mLowerValue != mPreDragLowerValue )
702 mLowerValue = mPreDragLowerValue;
703 if ( mFixedRangeSize >= 0 )
706 mUpperValue = std::min( mLowerValue + mFixedRangeSize, mStyleOption.maximum );
707 mLowerValue = std::max( mStyleOption.minimum, mUpperValue - mFixedRangeSize );
713 switch ( destControl )
722 newPosition = std::min( mUpperValue, pixelPosToRangeValue( pick(
event->pos() ) - mLowerClickOffset ) );
723 if ( mLowerValue != newPosition )
725 mLowerValue = newPosition;
726 if ( mFixedRangeSize >= 0 )
729 mUpperValue = std::min( mLowerValue + mFixedRangeSize, mStyleOption.maximum );
730 mLowerValue = std::max( mStyleOption.minimum, mUpperValue - mFixedRangeSize );
741 newPosition = std::max( mLowerValue, pixelPosToRangeValue( pick(
event->pos() ) - mUpperClickOffset ) );
742 if ( mUpperValue != newPosition )
744 mUpperValue = newPosition;
745 if ( mFixedRangeSize >= 0 )
748 mLowerValue = std::max( mStyleOption.minimum, mUpperValue - mFixedRangeSize );
749 mUpperValue = std::min( mLowerValue + mFixedRangeSize, mStyleOption.maximum );
759 newPosition = pixelPosToRangeValue( pick(
event->pos() ) - mRangeDragOffset );
760 int delta = newPosition - mStartDragPos;
765 const int maxDelta = mStyleOption.maximum - mPreDragUpperValue;
766 delta = std::min( maxDelta, delta );
767 mLowerValue = mPreDragLowerValue + delta;
768 mUpperValue = mPreDragUpperValue + delta;
771 else if ( delta < 0 )
775 const int maxDelta = mPreDragLowerValue - mStyleOption.minimum;
776 delta = std::min( maxDelta, delta );
777 mLowerValue = mPreDragLowerValue - delta;
778 mUpperValue = mPreDragUpperValue - delta;
795 if ( mActiveControl == None ||
event->buttons() )
802 mActiveControl = None;
808 Control destControl = mFocusControl;
809 if ( ( destControl == Lower || destControl == Upper ) && mLowerValue == mUpperValue )
812 switch (
event->key() )
816 switch ( mStyleOption.orientation )
819 if ( destControl == Both )
820 mFocusControl = mFlipped ? Upper : Lower;
822 applyStep( mFlipped ? mSingleStep : -mSingleStep );
828 switch ( mFocusControl )
831 mFocusControl = Range;
834 mFocusControl = Upper;
839 mFocusControl = Lower;
845 switch ( mFocusControl )
850 mFocusControl = Upper;
853 mFocusControl = Lower;
856 mFocusControl = Range;
868 switch ( mStyleOption.orientation )
871 if ( destControl == Both )
872 mFocusControl = mFlipped ? Lower : Upper;
873 applyStep( mFlipped ? -mSingleStep : mSingleStep );
879 switch ( mFocusControl )
884 mFocusControl = Upper;
887 mFocusControl = Lower;
890 mFocusControl = Range;
896 switch ( mFocusControl )
899 mFocusControl = Range;
902 mFocusControl = Upper;
907 mFocusControl = Lower;
919 switch ( mStyleOption.orientation )
924 switch ( mFocusControl )
927 mFocusControl = Range;
930 mFocusControl = Upper;
935 mFocusControl = Lower;
941 switch ( mFocusControl )
944 mFocusControl = Upper;
949 mFocusControl = Lower;
952 mFocusControl = Range;
960 if ( destControl == Both )
961 mFocusControl = mFlipped ? Upper : Lower;
963 applyStep( mFlipped ? mSingleStep : -mSingleStep );
971 switch ( mStyleOption.orientation )
976 switch ( mFocusControl )
979 mFocusControl = Upper;
984 mFocusControl = Lower;
987 mFocusControl = Range;
993 switch ( mFocusControl )
996 mFocusControl = Range;
999 mFocusControl = Upper;
1004 mFocusControl = Lower;
1012 if ( destControl == Both )
1013 mFocusControl = mFlipped ? Lower : Upper;
1015 applyStep( mFlipped ? -mSingleStep : mSingleStep );
1021 case Qt::Key_PageUp:
1023 switch ( mStyleOption.orientation )
1025 case Qt::Horizontal:
1026 if ( destControl == Both )
1027 mFocusControl = mFlipped ? Lower : Upper;
1029 applyStep( mFlipped ? -mPageStep : mPageStep );
1033 if ( destControl == Both )
1034 mFocusControl = mFlipped ? Upper : Lower;
1036 applyStep( mFlipped ? mPageStep : -mPageStep );
1042 case Qt::Key_PageDown:
1044 switch ( mStyleOption.orientation )
1046 case Qt::Horizontal:
1047 if ( destControl == Both )
1048 mFocusControl = mFlipped ? Upper : Lower;
1050 applyStep( mFlipped ? mPageStep : -mPageStep );
1054 if ( destControl == Both )
1055 mFocusControl = mFlipped ? Lower : Upper;
1057 applyStep( mFlipped ? -mPageStep : mPageStep );
1064 switch ( destControl )
1067 applyStep( mFlipped ? mUpperValue - mLowerValue : mStyleOption.minimum - mLowerValue );
1071 applyStep( mFlipped ? mStyleOption.maximum - mUpperValue : mLowerValue - mUpperValue );
1075 applyStep( mFlipped ? mStyleOption.maximum - mUpperValue : mStyleOption.minimum - mLowerValue );
1079 if ( destControl == Both )
1080 mFocusControl = mFlipped ? Upper : Lower;
1082 applyStep( mFlipped ? mStyleOption.maximum - mUpperValue : mStyleOption.minimum - mLowerValue );
1092 switch ( destControl )
1095 applyStep( mFlipped ? mStyleOption.minimum - mLowerValue : mUpperValue - mLowerValue );
1099 applyStep( mFlipped ? mLowerValue - mUpperValue : mStyleOption.maximum - mUpperValue );
1103 applyStep( mFlipped ? mStyleOption.minimum - mLowerValue : mStyleOption.maximum - mUpperValue );
1107 if ( destControl == Both )
1108 mFocusControl = mFlipped ? Lower : Upper;
1110 applyStep( mFlipped ? mStyleOption.minimum - mLowerValue : mStyleOption.maximum - mUpperValue );
1129 static constexpr int SLIDER_LENGTH = 84;
1130 static constexpr int TICK_SPACE = 5;
1132 int thick = style()->pixelMetric( QStyle::PM_SliderThickness, &mStyleOption,
this );
1133 if ( mStyleOption.tickPosition & QSlider::TicksAbove )
1134 thick += TICK_SPACE;
1135 if ( mStyleOption.tickPosition & QSlider::TicksBelow )
1136 thick += TICK_SPACE;
1137 int w = thick, h = SLIDER_LENGTH;
1138 if ( mStyleOption.orientation == Qt::Horizontal )
1142 return style()->sizeFromContents( QStyle::CT_Slider, &mStyleOption, QSize( w, h ),
this );
1148 const int length = style()->pixelMetric( QStyle::PM_SliderLength, &mStyleOption,
this );
1149 if ( mStyleOption.orientation == Qt::Horizontal )
1150 s.setWidth( length );
1152 s.setHeight( length );
A slider control with two interactive endpoints, for interactive selection of a range of values.
void setUpperValue(int value)
Sets the upper value for the range currently selected in the widget.
void setRangeLimits(int minimum, int maximum)
Sets the minimum and maximum range limits for values allowed in the widget.
QgsRangeSlider(QWidget *parent=nullptr)
Constructor for QgsRangeSlider, with the specified parent widget.
void setOrientation(Qt::Orientation orientation)
Sets the orientation of the slider.
void setTickInterval(int interval)
Sets the interval for tick marks shown in the widget.
int upperValue() const
Returns the upper value for the range selected in the widget.
int tickInterval() const
Returns the interval for tick marks shown in the widget.
void paintEvent(QPaintEvent *event) override
void fixedRangeSizeChanged(int size)
Emitted when the widget's fixed range size is changed.
void rangeLimitsChanged(int minimum, int maximum)
Emitted when the limits of values allowed in the widget is changed.
QSize sizeHint() const override
void keyPressEvent(QKeyEvent *event) override
void mouseMoveEvent(QMouseEvent *event) override
void rangeChanged(int minimum, int maximum)
Emitted when the range selected in the widget is changed.
int maximum() const
Returns the maximum value allowed by the widget.
void mousePressEvent(QMouseEvent *event) override
bool event(QEvent *event) override
void setSingleStep(int step)
Sets the single step value for the widget.
void setMinimum(int minimum)
Sets the minimum value allowed in the widget.
void setPageStep(int step)
Sets the page step value for the widget.
Qt::Orientation orientation() const
Returns the orientation of the slider.
void setMaximum(int maximum)
Sets the maximum value allowed in the widget.
int pageStep() const
Returns the page step value for the widget.
void setFlippedDirection(bool flipped)
Sets whether the slider has its values flipped.
int fixedRangeSize() const
Returns the slider's fixed range size, or -1 if not set.
int minimum() const
Returns the minimum value allowed by the widget.
QSize minimumSizeHint() const override
void setRange(int lower, int upper)
Sets the current range selected in the widget.
void setLowerValue(int value)
Sets the lower value for the range currently selected in the widget.
int lowerValue() const
Returns the lower value for the range selected in the widget.
void setTickPosition(QSlider::TickPosition position)
Sets the position of the tick marks shown in the widget.
void setFixedRangeSize(int size)
Sets the slider's fixed range size.
void mouseReleaseEvent(QMouseEvent *event) override
bool flippedDirection() const
Returns true if the slider has its values flipped.
QSlider::TickPosition tickPosition() const
Returns the position of the tick marks shown in the widget.
int singleStep() const
Returns the single step value for the widget.