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,
226 sliderMax - sliderMin );
228 value = mStyleOption.maximum + mStyleOption.minimum - value;
232bool QgsRangeSlider::updateHoverControl(
const QPoint &pos )
234 const QRect lastHoverRect = mHoverRect;
235 const bool doesHover = testAttribute( Qt::WA_Hover );
236 if ( doesHover && newHoverControl( pos ) )
238 update( lastHoverRect );
239 update( mHoverRect );
245bool QgsRangeSlider::newHoverControl(
const QPoint &pos )
247 const Control lastHoverControl = mHoverControl;
248 const QStyle::SubControl lastHoverSubControl = mHoverSubControl;
250 mStyleOption.subControls = QStyle::SC_All;
252 mStyleOption.sliderPosition = unFlippedSliderPosition( mLowerValue );
253 const QRect lowerHandleRect = style()->subControlRect( QStyle::CC_Slider, &mStyleOption, QStyle::SC_SliderHandle,
this );
254 mStyleOption.sliderPosition = unFlippedSliderPosition( mUpperValue );
255 const QRect upperHandleRect = style()->subControlRect( QStyle::CC_Slider, &mStyleOption, QStyle::SC_SliderHandle,
this );
257 const QRect grooveRect = style()->subControlRect( QStyle::CC_Slider, &mStyleOption, QStyle::SC_SliderGroove,
this );
258 const QRect tickmarksRect = style()->subControlRect( QStyle::CC_Slider, &mStyleOption, QStyle::SC_SliderTickmarks,
this );
259 if ( lowerHandleRect.contains( pos ) )
261 mHoverRect = lowerHandleRect;
262 mHoverControl = Lower;
263 mHoverSubControl = QStyle::SC_SliderHandle;
264 setCursor( Qt::OpenHandCursor );
266 else if ( upperHandleRect.contains( pos ) )
268 mHoverRect = upperHandleRect;
269 mHoverControl = Upper;
270 mHoverSubControl = QStyle::SC_SliderHandle;
271 setCursor( Qt::OpenHandCursor );
273 else if ( grooveRect.contains( pos ) )
275 mHoverRect = grooveRect;
276 mHoverControl = None;
277 mHoverSubControl = QStyle::SC_SliderGroove;
279 if ( selectedRangeRect().contains( pos ) )
280 setCursor( Qt::OpenHandCursor );
284 else if ( tickmarksRect.contains( pos ) )
286 mHoverRect = tickmarksRect;
287 mHoverControl = None;
288 mHoverSubControl = QStyle::SC_SliderTickmarks;
293 mHoverRect = QRect();
294 mHoverControl = None;
295 mHoverSubControl = QStyle::SC_None;
298 return mHoverSubControl != lastHoverSubControl || mHoverControl != lastHoverControl;
301QRect QgsRangeSlider::selectedRangeRect()
305 mStyleOption.activeSubControls = mHoverControl == Lower || mActiveControl == Lower ? QStyle::SC_SliderHandle : QStyle::SC_None;
306 mStyleOption.sliderPosition = unFlippedSliderPosition( mLowerValue );
307 const QRect lowerHandleRect = style()->subControlRect( QStyle::CC_Slider, &mStyleOption, QStyle::SC_SliderHandle,
nullptr );
309 mStyleOption.activeSubControls = mHoverControl == Upper || mActiveControl == Lower ? QStyle::SC_SliderHandle : QStyle::SC_None;
310 mStyleOption.sliderPosition = unFlippedSliderPosition( mUpperValue );
311 const QRect upperHandleRect = style()->subControlRect( QStyle::CC_Slider, &mStyleOption, QStyle::SC_SliderHandle,
nullptr );
313 const QRect grooveRect = style()->subControlRect( QStyle::CC_Slider, &mStyleOption, QStyle::SC_SliderGroove,
nullptr );
315 switch ( mStyleOption.orientation )
318 selectionRect = mFlipped ? QRect( upperHandleRect.right(),
320 lowerHandleRect.left() - upperHandleRect.right(),
323 : QRect( lowerHandleRect.right(),
325 upperHandleRect.left() - lowerHandleRect.right(),
331 selectionRect = mFlipped ? QRect( grooveRect.x(),
332 lowerHandleRect.top(),
334 upperHandleRect.bottom() - lowerHandleRect.top()
336 : QRect( grooveRect.x(),
337 upperHandleRect.top(),
339 lowerHandleRect.bottom() - upperHandleRect.top()
344 return selectionRect.adjusted( -1, 1, 1, -1 );
349 return mFixedRangeSize;
354 if ( size == mFixedRangeSize )
357 mFixedRangeSize = size;
359 if ( mFixedRangeSize >= 0 )
365void QgsRangeSlider::applyStep(
int step )
367 switch ( mFocusControl )
371 const int newLowerValue = std::min( mUpperValue, std::min( mStyleOption.maximum, std::max( mStyleOption.minimum, mLowerValue + step ) ) );
372 if ( newLowerValue != mLowerValue )
374 mLowerValue = newLowerValue;
375 if ( mFixedRangeSize >= 0 )
377 mUpperValue = std::min( mLowerValue + mFixedRangeSize, mStyleOption.maximum );
378 mLowerValue = std::max( mStyleOption.minimum, mUpperValue - mFixedRangeSize );
388 const int newUpperValue = std::max( mLowerValue, std::min( mStyleOption.maximum, std::max( mStyleOption.minimum, mUpperValue + step ) ) );
389 if ( newUpperValue != mUpperValue )
391 mUpperValue = newUpperValue;
392 if ( mFixedRangeSize >= 0 )
394 mLowerValue = std::max( mStyleOption.minimum, mUpperValue - mFixedRangeSize );
395 mUpperValue = std::min( mLowerValue + mFixedRangeSize, mStyleOption.maximum );
407 const int previousWidth = mUpperValue - mLowerValue;
408 const int newLowerValue = std::min( mUpperValue, std::min( mStyleOption.maximum, std::max( mStyleOption.minimum, mLowerValue + step ) ) );
409 if ( newLowerValue != mLowerValue )
411 mLowerValue = newLowerValue;
412 if ( mFixedRangeSize >= 0 )
414 mUpperValue = std::min( mLowerValue + mFixedRangeSize, mStyleOption.maximum );
415 mLowerValue = std::max( mStyleOption.minimum, mUpperValue - mFixedRangeSize );
419 mUpperValue = std::min( mStyleOption.maximum, mLowerValue + previousWidth );
427 const int previousWidth = mUpperValue - mLowerValue;
428 const int newUpperValue = std::max( mLowerValue, std::min( mStyleOption.maximum, std::max( mStyleOption.minimum, mUpperValue + step ) ) );
429 if ( newUpperValue != mUpperValue )
431 mUpperValue = newUpperValue;
432 if ( mFixedRangeSize >= 0 )
434 mLowerValue = std::max( mStyleOption.minimum, mUpperValue - mFixedRangeSize );
435 mUpperValue = std::min( mLowerValue + mFixedRangeSize, mStyleOption.maximum );
439 mLowerValue = std::max( mStyleOption.minimum, mUpperValue - previousWidth );
454int QgsRangeSlider::unFlippedSliderPosition(
int value )
const
456 return mFlipped ? mStyleOption.maximum + mStyleOption.minimum - value : value;
481 mStyleOption.tickPosition = position;
487 return mStyleOption.tickPosition;
492 mStyleOption.tickInterval = interval;
498 return mStyleOption.tickInterval;
504 if ( !testAttribute( Qt::WA_WState_OwnSizePolicy ) )
506 setSizePolicy( sizePolicy().transposed() );
507 setAttribute( Qt::WA_WState_OwnSizePolicy,
false );
515 return mStyleOption.orientation;
531 QPainter painter(
this );
533 mStyleOption.initFrom(
this );
534 mStyleOption.rect = rect();
535 mStyleOption.sliderPosition = mStyleOption.minimum;
536 mStyleOption.subControls = QStyle::SC_SliderGroove | QStyle::SC_SliderTickmarks;
538 mStyleOption.activeSubControls = mHoverSubControl;
540 style()->drawComplexControl( QStyle::CC_Slider, &mStyleOption, &painter );
542 QColor color = palette().color( QPalette::Highlight );
543 color.setAlpha( 160 );
544 painter.setBrush( QBrush( color ) );
545 painter.setPen( Qt::NoPen );
546 painter.drawRect( selectedRangeRect() );
549 mStyleOption.subControls = QStyle::SC_SliderHandle;
550 mStyleOption.activeSubControls = mHoverControl == Lower || mActiveControl == Lower ? QStyle::SC_SliderHandle : QStyle::SC_None;
551 mStyleOption.sliderPosition = unFlippedSliderPosition( mLowerValue );
552 if ( mActiveControl == Lower )
553 mStyleOption.state |= QStyle::State_Sunken;
555 mStyleOption.state &= ~QStyle::State_Sunken;
556 style()->drawComplexControl( QStyle::CC_Slider, &mStyleOption, &painter );
559 mStyleOption.activeSubControls = mHoverControl == Upper || mActiveControl == Lower ? QStyle::SC_SliderHandle : QStyle::SC_None;
560 mStyleOption.sliderPosition = unFlippedSliderPosition( mUpperValue );
561 if ( mActiveControl == Upper )
562 mStyleOption.state |= QStyle::State_Sunken;
564 mStyleOption.state &= ~QStyle::State_Sunken;
565 style()->drawComplexControl( QStyle::CC_Slider, &mStyleOption, &painter );
567 if ( hasFocus() && mFocusControl != None )
570 QStyleOptionFocusRect option;
571 option.initFrom(
this );
572 option.state = QStyle::State_KeyboardFocusChange;
573 if ( mFocusControl == Lower )
575 mStyleOption.sliderPosition = unFlippedSliderPosition( mLowerValue );
576 option.rect = style()->subControlRect( QStyle::CC_Slider, &mStyleOption, QStyle::SC_SliderHandle,
this );
578 else if ( mFocusControl == Upper )
580 mStyleOption.sliderPosition = unFlippedSliderPosition( mUpperValue );
581 option.rect = style()->subControlRect( QStyle::CC_Slider, &mStyleOption, QStyle::SC_SliderHandle,
this );
583 else if ( mFocusControl == Range )
585 option.rect = selectedRangeRect();
586 if ( mStyleOption.orientation == Qt::Horizontal )
587 option.rect = option.rect.adjusted( 0, -1, 0, 1 );
589 option.rect = option.rect.adjusted( -1, 0, 1, 0 );
591 style()->drawPrimitive( QStyle::PE_FrameFocusRect, &option, &painter );
597 if ( mStyleOption.maximum == mStyleOption.minimum || (
event->buttons() ^
event->button() ) )
605 mStyleOption.sliderPosition = unFlippedSliderPosition( mLowerValue );
606 const bool overLowerControl = style()->hitTestComplexControl( QStyle::CC_Slider, &mStyleOption,
event->pos(),
this ) == QStyle::SC_SliderHandle;
607 const QRect lowerSliderRect = style()->subControlRect( QStyle::CC_Slider, &mStyleOption, QStyle::SC_SliderHandle,
this );
608 mStyleOption.sliderPosition = unFlippedSliderPosition( mUpperValue );
609 const bool overUpperControl = style()->hitTestComplexControl( QStyle::CC_Slider, &mStyleOption,
event->pos(),
this ) == QStyle::SC_SliderHandle;
610 const QRect upperSliderRect = style()->subControlRect( QStyle::CC_Slider, &mStyleOption, QStyle::SC_SliderHandle,
this );
612 const bool overSelectedRange = selectedRangeRect().contains(
event->pos() );
614 mLowerClickOffset = pick(
event->pos() - lowerSliderRect.topLeft() );
615 mUpperClickOffset = pick(
event->pos() - upperSliderRect.topLeft() );
617 mPreDragLowerValue = mLowerValue;
618 mPreDragUpperValue = mUpperValue;
619 mRangeDragOffset = 0;
621 if ( ( overLowerControl || overUpperControl ) &&
event->modifiers() & Qt::ShiftModifier )
623 mActiveControl = Range;
624 mRangeDragOffset = overUpperControl ? mUpperClickOffset : mLowerClickOffset;
625 mFocusControl = overUpperControl ? Upper : Lower;
627 else if ( overLowerControl && overUpperControl )
628 mActiveControl = Both;
629 else if ( overLowerControl )
631 mActiveControl = Lower;
632 mFocusControl = Lower;
634 else if ( overUpperControl )
636 mActiveControl = Upper;
637 mFocusControl = Upper;
639 else if ( overSelectedRange )
641 mActiveControl = Range;
642 mFocusControl = Range;
645 mActiveControl = None;
647 if ( mActiveControl != None )
649 mStartDragPos = pixelPosToRangeValue( pick(
event->pos() ) - mRangeDragOffset );
655 if ( mActiveControl == None )
663 int newPosition = pixelPosToRangeValue( pick(
event->pos() ) );
665 bool changed =
false;
666 Control destControl = mActiveControl;
667 if ( destControl == Both )
670 if ( newPosition < mStartDragPos )
673 mFocusControl = Lower;
674 if ( mUpperValue != mPreDragUpperValue )
677 mUpperValue = mPreDragUpperValue;
678 if ( mFixedRangeSize >= 0 )
681 mLowerValue = std::max( mStyleOption.minimum, mUpperValue - mFixedRangeSize );
682 mUpperValue = std::min( mLowerValue + mFixedRangeSize, mStyleOption.maximum );
686 else if ( newPosition > mStartDragPos )
689 mFocusControl = Upper;
690 if ( mLowerValue != mPreDragLowerValue )
693 mLowerValue = mPreDragLowerValue;
694 if ( mFixedRangeSize >= 0 )
697 mUpperValue = std::min( mLowerValue + mFixedRangeSize, mStyleOption.maximum );
698 mLowerValue = std::max( mStyleOption.minimum, mUpperValue - mFixedRangeSize );
705 if ( mUpperValue != mPreDragUpperValue )
708 mUpperValue = mPreDragUpperValue;
709 if ( mFixedRangeSize >= 0 )
712 mLowerValue = std::max( mStyleOption.minimum, mUpperValue - mFixedRangeSize );
713 mUpperValue = std::min( mLowerValue + mFixedRangeSize, mStyleOption.maximum );
716 if ( mLowerValue != mPreDragLowerValue )
719 mLowerValue = mPreDragLowerValue;
720 if ( mFixedRangeSize >= 0 )
723 mUpperValue = std::min( mLowerValue + mFixedRangeSize, mStyleOption.maximum );
724 mLowerValue = std::max( mStyleOption.minimum, mUpperValue - mFixedRangeSize );
730 switch ( destControl )
739 newPosition = std::min( mUpperValue, pixelPosToRangeValue( pick(
event->pos() ) - mLowerClickOffset ) );
740 if ( mLowerValue != newPosition )
742 mLowerValue = newPosition;
743 if ( mFixedRangeSize >= 0 )
746 mUpperValue = std::min( mLowerValue + mFixedRangeSize, mStyleOption.maximum );
747 mLowerValue = std::max( mStyleOption.minimum, mUpperValue - mFixedRangeSize );
758 newPosition = std::max( mLowerValue, pixelPosToRangeValue( pick(
event->pos() ) - mUpperClickOffset ) );
759 if ( mUpperValue != newPosition )
761 mUpperValue = newPosition;
762 if ( mFixedRangeSize >= 0 )
765 mLowerValue = std::max( mStyleOption.minimum, mUpperValue - mFixedRangeSize );
766 mUpperValue = std::min( mLowerValue + mFixedRangeSize, mStyleOption.maximum );
776 newPosition = pixelPosToRangeValue( pick(
event->pos() ) - mRangeDragOffset ) ;
777 int delta = newPosition - mStartDragPos;
782 const int maxDelta = mStyleOption.maximum - mPreDragUpperValue;
783 delta = std::min( maxDelta, delta );
784 mLowerValue = mPreDragLowerValue + delta;
785 mUpperValue = mPreDragUpperValue + delta;
788 else if ( delta < 0 )
792 const int maxDelta = mPreDragLowerValue - mStyleOption.minimum ;
793 delta = std::min( maxDelta, delta );
794 mLowerValue = mPreDragLowerValue - delta;
795 mUpperValue = mPreDragUpperValue - delta;
812 if ( mActiveControl == None ||
event->buttons() )
819 mActiveControl = None;
825 Control destControl = mFocusControl;
826 if ( ( destControl == Lower || destControl == Upper ) && mLowerValue == mUpperValue )
829 switch (
event->key() )
833 switch ( mStyleOption.orientation )
836 if ( destControl == Both )
837 mFocusControl = mFlipped ? Upper : Lower;
839 applyStep( mFlipped ? mSingleStep : -mSingleStep );
845 switch ( mFocusControl )
848 mFocusControl = Range;
851 mFocusControl = Upper;
856 mFocusControl = Lower;
862 switch ( mFocusControl )
867 mFocusControl = Upper;
870 mFocusControl = Lower;
873 mFocusControl = Range;
885 switch ( mStyleOption.orientation )
888 if ( destControl == Both )
889 mFocusControl = mFlipped ? Lower : Upper;
890 applyStep( mFlipped ? -mSingleStep : mSingleStep );
896 switch ( mFocusControl )
901 mFocusControl = Upper;
904 mFocusControl = Lower;
907 mFocusControl = Range;
913 switch ( mFocusControl )
916 mFocusControl = Range;
919 mFocusControl = Upper;
924 mFocusControl = Lower;
936 switch ( mStyleOption.orientation )
941 switch ( mFocusControl )
944 mFocusControl = Range;
947 mFocusControl = Upper;
952 mFocusControl = Lower;
958 switch ( mFocusControl )
961 mFocusControl = Upper;
966 mFocusControl = Lower;
969 mFocusControl = Range;
977 if ( destControl == Both )
978 mFocusControl = mFlipped ? Upper : Lower;
980 applyStep( mFlipped ? mSingleStep : -mSingleStep );
988 switch ( mStyleOption.orientation )
993 switch ( mFocusControl )
996 mFocusControl = Upper;
1001 mFocusControl = Lower;
1004 mFocusControl = Range;
1010 switch ( mFocusControl )
1013 mFocusControl = Range;
1016 mFocusControl = Upper;
1021 mFocusControl = Lower;
1029 if ( destControl == Both )
1030 mFocusControl = mFlipped ? Lower : Upper;
1032 applyStep( mFlipped ? -mSingleStep : mSingleStep );
1038 case Qt::Key_PageUp:
1040 switch ( mStyleOption.orientation )
1042 case Qt::Horizontal:
1043 if ( destControl == Both )
1044 mFocusControl = mFlipped ? Lower : Upper;
1046 applyStep( mFlipped ? -mPageStep : mPageStep );
1050 if ( destControl == Both )
1051 mFocusControl = mFlipped ? Upper : Lower;
1053 applyStep( mFlipped ? mPageStep : -mPageStep );
1059 case Qt::Key_PageDown:
1061 switch ( mStyleOption.orientation )
1063 case Qt::Horizontal:
1064 if ( destControl == Both )
1065 mFocusControl = mFlipped ? Upper : Lower;
1067 applyStep( mFlipped ? mPageStep : -mPageStep );
1071 if ( destControl == Both )
1072 mFocusControl = mFlipped ? Lower : Upper;
1074 applyStep( mFlipped ? -mPageStep : mPageStep );
1081 switch ( destControl )
1084 applyStep( mFlipped ? mUpperValue - mLowerValue : mStyleOption.minimum - mLowerValue );
1088 applyStep( mFlipped ? mStyleOption.maximum - mUpperValue : mLowerValue - mUpperValue );
1092 applyStep( mFlipped ? mStyleOption.maximum - mUpperValue : mStyleOption.minimum - mLowerValue );
1096 if ( destControl == Both )
1097 mFocusControl = mFlipped ? Upper : Lower;
1099 applyStep( mFlipped ? mStyleOption.maximum - mUpperValue : mStyleOption.minimum - mLowerValue );
1109 switch ( destControl )
1112 applyStep( mFlipped ? mStyleOption.minimum - mLowerValue : mUpperValue - mLowerValue );
1116 applyStep( mFlipped ? mLowerValue - mUpperValue : mStyleOption.maximum - mUpperValue );
1120 applyStep( mFlipped ? mStyleOption.minimum - mLowerValue : mStyleOption.maximum - mUpperValue );
1124 if ( destControl == Both )
1125 mFocusControl = mFlipped ? Lower : Upper;
1127 applyStep( mFlipped ? mStyleOption.minimum - mLowerValue : mStyleOption.maximum - mUpperValue );
1146 static constexpr int SLIDER_LENGTH = 84;
1147 static constexpr int TICK_SPACE = 5;
1149 int thick = style()->pixelMetric( QStyle::PM_SliderThickness, &mStyleOption,
this );
1150 if ( mStyleOption.tickPosition & QSlider::TicksAbove )
1151 thick += TICK_SPACE;
1152 if ( mStyleOption.tickPosition & QSlider::TicksBelow )
1153 thick += TICK_SPACE;
1154 int w = thick, h = SLIDER_LENGTH;
1155 if ( mStyleOption.orientation == Qt::Horizontal )
1159 return style()->sizeFromContents( QStyle::CT_Slider, &mStyleOption, QSize( w, h ),
this );
1165 const int length = style()->pixelMetric( QStyle::PM_SliderLength, &mStyleOption,
this );
1166 if ( mStyleOption.orientation == Qt::Horizontal )
1167 s.setWidth( length );
1169 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.