QskSlider::inverted introduced
This commit is contained in:
parent
db1e9a7e44
commit
12dfac153d
@ -77,6 +77,7 @@ class QskSlider::PrivateData
|
|||||||
PrivateData( Qt::Orientation orientation )
|
PrivateData( Qt::Orientation orientation )
|
||||||
: pressedValue( 0 )
|
: pressedValue( 0 )
|
||||||
, hasOrigin( false )
|
, hasOrigin( false )
|
||||||
|
, inverted( false )
|
||||||
, tracking( true )
|
, tracking( true )
|
||||||
, dragging( false )
|
, dragging( false )
|
||||||
, orientation( orientation )
|
, orientation( orientation )
|
||||||
@ -89,6 +90,7 @@ class QskSlider::PrivateData
|
|||||||
qreal origin = 0.0;
|
qreal origin = 0.0;
|
||||||
|
|
||||||
bool hasOrigin : 1;
|
bool hasOrigin : 1;
|
||||||
|
bool inverted : 1;
|
||||||
bool tracking : 1;
|
bool tracking : 1;
|
||||||
bool dragging : 1;
|
bool dragging : 1;
|
||||||
uint orientation : 2;
|
uint orientation : 2;
|
||||||
@ -140,6 +142,22 @@ Qt::Orientation QskSlider::orientation() const
|
|||||||
return static_cast< Qt::Orientation >( m_data->orientation );
|
return static_cast< Qt::Orientation >( m_data->orientation );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void QskSlider::setInverted( bool on )
|
||||||
|
{
|
||||||
|
if ( on != m_data->inverted )
|
||||||
|
{
|
||||||
|
m_data->inverted = on;
|
||||||
|
update();
|
||||||
|
|
||||||
|
Q_EMIT invertedChanged( on );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool QskSlider::isInverted() const
|
||||||
|
{
|
||||||
|
return m_data->inverted;
|
||||||
|
}
|
||||||
|
|
||||||
void QskSlider::setOrigin( qreal origin )
|
void QskSlider::setOrigin( qreal origin )
|
||||||
{
|
{
|
||||||
if ( isComponentComplete() )
|
if ( isComponentComplete() )
|
||||||
@ -226,6 +244,9 @@ void QskSlider::mousePressEvent( QMouseEvent* event )
|
|||||||
else
|
else
|
||||||
ratio = ( scaleRect.bottom() - pos.y() ) / scaleRect.height();
|
ratio = ( scaleRect.bottom() - pos.y() ) / scaleRect.height();
|
||||||
|
|
||||||
|
if ( m_data->inverted )
|
||||||
|
ratio = 1.0 - ratio;
|
||||||
|
|
||||||
setValue( valueFromRatio( ratio ) );
|
setValue( valueFromRatio( ratio ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -243,17 +264,21 @@ void QskSlider::mouseMoveEvent( QMouseEvent* event )
|
|||||||
const auto mousePos = qskMousePosition( event );
|
const auto mousePos = qskMousePosition( event );
|
||||||
const auto r = subControlRect( Scale );
|
const auto r = subControlRect( Scale );
|
||||||
|
|
||||||
|
auto length = boundaryLength();
|
||||||
|
if ( m_data->inverted )
|
||||||
|
length = -length;
|
||||||
|
|
||||||
qreal newValue;
|
qreal newValue;
|
||||||
|
|
||||||
if ( m_data->orientation == Qt::Horizontal )
|
if ( m_data->orientation == Qt::Horizontal )
|
||||||
{
|
{
|
||||||
const auto distance = mousePos.x() - m_data->pressedPos.x();
|
const auto distance = mousePos.x() - m_data->pressedPos.x();
|
||||||
newValue = m_data->pressedValue + distance / r.width() * boundaryLength();
|
newValue = m_data->pressedValue + distance / r.width() * length;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
const auto distance = mousePos.y() - m_data->pressedPos.y();
|
const auto distance = mousePos.y() - m_data->pressedPos.y();
|
||||||
newValue = m_data->pressedValue - distance / r.height() * boundaryLength();
|
newValue = m_data->pressedValue - distance / r.height() * length;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( m_data->tracking )
|
if ( m_data->tracking )
|
||||||
@ -279,8 +304,11 @@ void QskSlider::mouseReleaseEvent( QMouseEvent* )
|
|||||||
|
|
||||||
void QskSlider::keyPressEvent( QKeyEvent* event )
|
void QskSlider::keyPressEvent( QKeyEvent* event )
|
||||||
{
|
{
|
||||||
if ( const auto offset = qskKeyOffset( orientation(), event->key() ) )
|
if ( auto offset = qskKeyOffset( orientation(), event->key() ) )
|
||||||
{
|
{
|
||||||
|
if ( m_data->inverted )
|
||||||
|
offset = -offset;
|
||||||
|
|
||||||
increment( offset * stepSize() );
|
increment( offset * stepSize() );
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -16,6 +16,9 @@ class QSK_EXPORT QskSlider : public QskBoundedValueInput
|
|||||||
Q_PROPERTY( Qt::Orientation orientation READ orientation
|
Q_PROPERTY( Qt::Orientation orientation READ orientation
|
||||||
WRITE setOrientation NOTIFY orientationChanged )
|
WRITE setOrientation NOTIFY orientationChanged )
|
||||||
|
|
||||||
|
Q_PROPERTY( bool inverted READ isInverted
|
||||||
|
WRITE setInverted NOTIFY invertedChanged )
|
||||||
|
|
||||||
Q_PROPERTY( bool tracking READ isTracking
|
Q_PROPERTY( bool tracking READ isTracking
|
||||||
WRITE setTracking NOTIFY trackingChanged )
|
WRITE setTracking NOTIFY trackingChanged )
|
||||||
|
|
||||||
@ -36,6 +39,9 @@ class QSK_EXPORT QskSlider : public QskBoundedValueInput
|
|||||||
void setOrientation( Qt::Orientation );
|
void setOrientation( Qt::Orientation );
|
||||||
Qt::Orientation orientation() const;
|
Qt::Orientation orientation() const;
|
||||||
|
|
||||||
|
void setInverted( bool );
|
||||||
|
bool isInverted() const;
|
||||||
|
|
||||||
void resetOrigin();
|
void resetOrigin();
|
||||||
qreal origin() const;
|
qreal origin() const;
|
||||||
|
|
||||||
@ -51,6 +57,7 @@ class QSK_EXPORT QskSlider : public QskBoundedValueInput
|
|||||||
|
|
||||||
Q_SIGNALS:
|
Q_SIGNALS:
|
||||||
void orientationChanged( Qt::Orientation );
|
void orientationChanged( Qt::Orientation );
|
||||||
|
void invertedChanged( bool );
|
||||||
void trackingChanged( bool );
|
void trackingChanged( bool );
|
||||||
void originChanged( qreal );
|
void originChanged( qreal );
|
||||||
|
|
||||||
|
@ -251,6 +251,12 @@ QRectF QskSliderSkinlet::fillRect(
|
|||||||
auto pos1 = slider->valueAsRatio( slider->origin() );
|
auto pos1 = slider->valueAsRatio( slider->origin() );
|
||||||
auto pos2 = qBound( 0.0, slider->positionHint( Q::Handle ), 1.0 );
|
auto pos2 = qBound( 0.0, slider->positionHint( Q::Handle ), 1.0 );
|
||||||
|
|
||||||
|
if ( slider->isInverted() )
|
||||||
|
{
|
||||||
|
pos1 = 1.0 - pos1;
|
||||||
|
pos2 = 1.0 - pos2;
|
||||||
|
}
|
||||||
|
|
||||||
if ( pos1 > pos2 )
|
if ( pos1 > pos2 )
|
||||||
qSwap( pos1, pos2 );
|
qSwap( pos1, pos2 );
|
||||||
|
|
||||||
@ -293,7 +299,10 @@ QRectF QskSliderSkinlet::handleRect(
|
|||||||
if ( handleSize.width() < 0.0 )
|
if ( handleSize.width() < 0.0 )
|
||||||
handleSize.setWidth( handleSize.height() );
|
handleSize.setWidth( handleSize.height() );
|
||||||
|
|
||||||
center.setX( r.left() + pos * r.width() );
|
if ( slider->isInverted() )
|
||||||
|
center.setX( r.right() - pos * r.width() );
|
||||||
|
else
|
||||||
|
center.setX( r.left() + pos * r.width() );
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -303,7 +312,10 @@ QRectF QskSliderSkinlet::handleRect(
|
|||||||
if ( handleSize.height() < 0.0 )
|
if ( handleSize.height() < 0.0 )
|
||||||
handleSize.setHeight( handleSize.width() );
|
handleSize.setHeight( handleSize.width() );
|
||||||
|
|
||||||
center.setY( r.bottom() - pos * r.height() );
|
if ( slider->isInverted() )
|
||||||
|
center.setY( r.top() + pos * r.height() );
|
||||||
|
else
|
||||||
|
center.setY( r.bottom() - pos * r.height() );
|
||||||
}
|
}
|
||||||
|
|
||||||
QRectF handleRect( 0, 0, handleSize.width(), handleSize.height() );
|
QRectF handleRect( 0, 0, handleSize.width(), handleSize.height() );
|
||||||
@ -319,7 +331,9 @@ QRectF QskSliderSkinlet::tickRect( const QskSlider* slider,
|
|||||||
if ( !tickValue.canConvert< qreal >() )
|
if ( !tickValue.canConvert< qreal >() )
|
||||||
return QRectF();
|
return QRectF();
|
||||||
|
|
||||||
const auto tickPos = slider->valueAsRatio( tickValue.value< qreal >() );
|
auto tickPos = slider->valueAsRatio( tickValue.value< qreal >() );
|
||||||
|
if ( slider->isInverted() )
|
||||||
|
tickPos = 1.0 - tickPos;
|
||||||
|
|
||||||
const auto r = subControlRect( slider, contentsRect, Q::Scale );
|
const auto r = subControlRect( slider, contentsRect, Q::Scale );
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user