Skip to content

Commit

Permalink
Rename inverted appearance methods to flippedDirection in order to
Browse files Browse the repository at this point in the history
clarify that they aren't quite the same as their QSlider counterparts.
  • Loading branch information
nyalldawson committed Nov 26, 2020
1 parent c5e0513 commit 20b0491
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 36 deletions.
13 changes: 7 additions & 6 deletions python/gui/auto_generated/qgsrangeslider.sip.in
Expand Up @@ -112,24 +112,25 @@ Returns the orientation of the slider.
.. seealso:: :py:func:`setOrientation`
%End

bool invertedAppearance() const;
bool flippedDirection() const;
%Docstring
Returns ``True`` if the slider has its values inverted.
Returns ``True`` if the slider has its values flipped.

If this property is ``False`` (the default), the minimum and maximum will be shown in its classic
position for the widget. If the value is ``True``, the minimum and maximum appear at their opposite location.

.. seealso:: :py:func:`setInvertedAppearance`
.. seealso:: :py:func:`setFlippedDirection`
%End

void setInvertedAppearance( bool inverted );
void setFlippedDirection( bool flipped );
%Docstring
Sets whether the slider has its values ``inverted``.
Sets whether the slider has its values ``flipped``.

If this property is ``False`` (the default), the minimum and maximum will be shown in its classic
position for the widget. If the value is ``True``, the minimum and maximum appear at their opposite location.
(i.e. minimum at the bottom of a vertical slider, maximum at the top of a vertical slider).

.. seealso:: :py:func:`setInvertedAppearance`
.. seealso:: :py:func:`flippedDirection`
%End

virtual void paintEvent( QPaintEvent *event );
Expand Down
46 changes: 23 additions & 23 deletions src/gui/qgsrangeslider.cpp
Expand Up @@ -162,7 +162,7 @@ int QgsRangeSlider::pixelPosToRangeValue( int pos ) const

int value = QStyle::sliderValueFromPosition( mStyleOption.minimum, mStyleOption.maximum, pos - sliderMin,
sliderMax - sliderMin );
if ( mInverted )
if ( mFlipped )
value = mStyleOption.maximum - value;
return value;
}
Expand All @@ -187,9 +187,9 @@ bool QgsRangeSlider::newHoverControl( const QPoint &pos )

mStyleOption.subControls = QStyle::SC_All;

mStyleOption.sliderPosition = mInverted ? mStyleOption.maximum - mLowerValue : mLowerValue;
mStyleOption.sliderPosition = mFlipped ? mStyleOption.maximum - mLowerValue : mLowerValue;
QRect lowerHandleRect = style()->subControlRect( QStyle::CC_Slider, &mStyleOption, QStyle::SC_SliderHandle, this );
mStyleOption.sliderPosition = mInverted ? mStyleOption.maximum - mUpperValue : mUpperValue;
mStyleOption.sliderPosition = mFlipped ? mStyleOption.maximum - mUpperValue : mUpperValue;
QRect upperHandleRect = style()->subControlRect( QStyle::CC_Slider, &mStyleOption, QStyle::SC_SliderHandle, this );

QRect grooveRect = style()->subControlRect( QStyle::CC_Slider, &mStyleOption, QStyle::SC_SliderGroove, this );
Expand Down Expand Up @@ -260,14 +260,14 @@ Qt::Orientation QgsRangeSlider::orientation() const
return mStyleOption.orientation;
}

bool QgsRangeSlider::invertedAppearance() const
bool QgsRangeSlider::flippedDirection() const
{
return mInverted;
return mFlipped;
}

void QgsRangeSlider::setInvertedAppearance( bool inverted )
void QgsRangeSlider::setFlippedDirection( bool flipped )
{
mInverted = inverted;
mFlipped = flipped;
update();
}

Expand All @@ -290,11 +290,11 @@ void QgsRangeSlider::paintEvent( QPaintEvent * )
painter.setPen( Qt::NoPen );

mStyleOption.activeSubControls = mHoverControl == Lower || mActiveControl == Lower ? QStyle::SC_SliderHandle : QStyle::SC_None;
mStyleOption.sliderPosition = mInverted ? mStyleOption.maximum - mLowerValue : mLowerValue;
mStyleOption.sliderPosition = mFlipped ? mStyleOption.maximum - mLowerValue : mLowerValue;
const QRect lowerHandleRect = style()->subControlRect( QStyle::CC_Slider, &mStyleOption, QStyle::SC_SliderHandle, nullptr );

mStyleOption.activeSubControls = mHoverControl == Upper || mActiveControl == Lower ? QStyle::SC_SliderHandle : QStyle::SC_None;
mStyleOption.sliderPosition = mInverted ? mStyleOption.maximum - mUpperValue : mUpperValue;
mStyleOption.sliderPosition = mFlipped ? mStyleOption.maximum - mUpperValue : mUpperValue;
const QRect upperHandleRect = style()->subControlRect( QStyle::CC_Slider, &mStyleOption, QStyle::SC_SliderHandle, nullptr );

const QRect grooveRect = style()->subControlRect( QStyle::CC_Slider, &mStyleOption, QStyle::SC_SliderGroove, nullptr );
Expand All @@ -303,11 +303,11 @@ void QgsRangeSlider::paintEvent( QPaintEvent * )
switch ( mStyleOption.orientation )
{
case Qt::Horizontal:
selectionRect = mInverted ? QRect( upperHandleRect.left(),
grooveRect.y(),
lowerHandleRect.right() - upperHandleRect.right(),
grooveRect.height()
)
selectionRect = mFlipped ? QRect( upperHandleRect.left(),
grooveRect.y(),
lowerHandleRect.right() - upperHandleRect.right(),
grooveRect.height()
)
: QRect( lowerHandleRect.right(),
grooveRect.y(),
upperHandleRect.left() - lowerHandleRect.right(),
Expand All @@ -316,11 +316,11 @@ void QgsRangeSlider::paintEvent( QPaintEvent * )
break;

case Qt::Vertical:
selectionRect = mInverted ? QRect( grooveRect.x(),
lowerHandleRect.bottom(),
grooveRect.width(),
upperHandleRect.top() - lowerHandleRect.top()
)
selectionRect = mFlipped ? QRect( grooveRect.x(),
lowerHandleRect.bottom(),
grooveRect.width(),
upperHandleRect.top() - lowerHandleRect.top()
)
: QRect( grooveRect.x(),
upperHandleRect.top(),
grooveRect.width(),
Expand All @@ -334,7 +334,7 @@ void QgsRangeSlider::paintEvent( QPaintEvent * )
// draw first handle
mStyleOption.subControls = QStyle::SC_SliderHandle;
mStyleOption.activeSubControls = mHoverControl == Lower || mActiveControl == Lower ? QStyle::SC_SliderHandle : QStyle::SC_None;
mStyleOption.sliderPosition = mInverted ? mStyleOption.maximum - mLowerValue : mLowerValue;
mStyleOption.sliderPosition = mFlipped ? mStyleOption.maximum - mLowerValue : mLowerValue;
if ( mActiveControl == Lower )
mStyleOption.state |= QStyle::State_Sunken;
else
Expand All @@ -343,7 +343,7 @@ void QgsRangeSlider::paintEvent( QPaintEvent * )

// draw second handle
mStyleOption.activeSubControls = mHoverControl == Upper || mActiveControl == Lower ? QStyle::SC_SliderHandle : QStyle::SC_None;
mStyleOption.sliderPosition = mInverted ? mStyleOption.maximum - mUpperValue : mUpperValue;
mStyleOption.sliderPosition = mFlipped ? mStyleOption.maximum - mUpperValue : mUpperValue;
if ( mActiveControl == Upper )
mStyleOption.state |= QStyle::State_Sunken;
else
Expand All @@ -361,10 +361,10 @@ void QgsRangeSlider::mousePressEvent( QMouseEvent *event )

event->accept();

mStyleOption.sliderPosition = mInverted ? mStyleOption.maximum - mLowerValue : mLowerValue;
mStyleOption.sliderPosition = mFlipped ? mStyleOption.maximum - mLowerValue : mLowerValue;
const bool overLowerControl = style()->hitTestComplexControl( QStyle::CC_Slider, &mStyleOption, event->pos(), this ) == QStyle::SC_SliderHandle;
const QRect lowerSliderRect = style()->subControlRect( QStyle::CC_Slider, &mStyleOption, QStyle::SC_SliderHandle, this );
mStyleOption.sliderPosition = mInverted ? mStyleOption.maximum - mUpperValue : mUpperValue;
mStyleOption.sliderPosition = mFlipped ? mStyleOption.maximum - mUpperValue : mUpperValue;
const bool overUpperControl = style()->hitTestComplexControl( QStyle::CC_Slider, &mStyleOption, event->pos(), this ) == QStyle::SC_SliderHandle;
const QRect upperSliderRect = style()->subControlRect( QStyle::CC_Slider, &mStyleOption, QStyle::SC_SliderHandle, this );

Expand Down
15 changes: 8 additions & 7 deletions src/gui/qgsrangeslider.h
Expand Up @@ -121,24 +121,25 @@ class GUI_EXPORT QgsRangeSlider : public QWidget
Qt::Orientation orientation() const;

/**
* Returns TRUE if the slider has its values inverted.
* Returns TRUE if the slider has its values flipped.
*
* If this property is FALSE (the default), the minimum and maximum will be shown in its classic
* position for the widget. If the value is TRUE, the minimum and maximum appear at their opposite location.
*
* \see setInvertedAppearance()
* \see setFlippedDirection()
*/
bool invertedAppearance() const;
bool flippedDirection() const;

/**
* Sets whether the slider has its values \a inverted.
* Sets whether the slider has its values \a flipped.
*
* If this property is FALSE (the default), the minimum and maximum will be shown in its classic
* position for the widget. If the value is TRUE, the minimum and maximum appear at their opposite location.
* (i.e. minimum at the bottom of a vertical slider, maximum at the top of a vertical slider).
*
* \see setInvertedAppearance()
* \see flippedDirection()
*/
void setInvertedAppearance( bool inverted );
void setFlippedDirection( bool flipped );

void paintEvent( QPaintEvent *event ) override;
void mousePressEvent( QMouseEvent *event ) override;
Expand Down Expand Up @@ -241,7 +242,7 @@ class GUI_EXPORT QgsRangeSlider : public QWidget
QStyle::SubControl mHoverSubControl = QStyle::SC_None;
QRect mHoverRect;

bool mInverted = false;
bool mFlipped = false;
};

#endif // QGSRANGESLIDER_H

0 comments on commit 20b0491

Please sign in to comment.