From 06704511d2e1d2e53a8704e2203c2b97e895e384 Mon Sep 17 00:00:00 2001 From: Uwe Rathmann Date: Thu, 23 Feb 2023 14:33:35 +0100 Subject: [PATCH] QskBoundedInput::incrementForKeys added --- src/controls/QskBoundedInput.cpp | 41 ++++++++++++++++++++++------- src/controls/QskBoundedInput.h | 2 ++ src/controls/QskBoundedValueInput.h | 4 ++- src/controls/QskSlider.h | 4 ++- 4 files changed, 39 insertions(+), 12 deletions(-) diff --git a/src/controls/QskBoundedInput.cpp b/src/controls/QskBoundedInput.cpp index 4b6e647b..e34152ae 100644 --- a/src/controls/QskBoundedInput.cpp +++ b/src/controls/QskBoundedInput.cpp @@ -177,21 +177,42 @@ bool QskBoundedInput::isReadOnly() const return hasSkinState( ReadOnly ); } +qreal QskBoundedInput::incrementForKey( const QKeyEvent* event ) const +{ + switch( event->key() ) + { + case Qt::Key_Up: + return m_stepSize; + + case Qt::Key_Down: + return -m_stepSize; + + case Qt::Key_PageUp: + return m_pageSize; + + case Qt::Key_PageDown: + return -m_pageSize; + + default: + { + if ( qskIsStandardKeyInput( event, QKeySequence::MoveToNextChar ) ) + return m_stepSize; + + if ( qskIsStandardKeyInput( event, QKeySequence::MoveToPreviousChar ) ) + return -m_stepSize; + } + } + + return 0.0; +} + void QskBoundedInput::keyPressEvent( QKeyEvent* event ) { if ( !isReadOnly() ) { - if ( event->key() == Qt::Key_Up || - qskIsStandardKeyInput( event, QKeySequence::MoveToNextChar ) ) + if ( const auto offset = incrementForKey( event ) ) { - increment( m_stepSize ); - return; - } - - if ( event->key() == Qt::Key_Down || - qskIsStandardKeyInput( event, QKeySequence::MoveToPreviousChar ) ) - { - increment( -m_stepSize ); + increment( offset ); return; } } diff --git a/src/controls/QskBoundedInput.h b/src/controls/QskBoundedInput.h index e1154a01..92a2a81e 100644 --- a/src/controls/QskBoundedInput.h +++ b/src/controls/QskBoundedInput.h @@ -68,6 +68,8 @@ class QSK_EXPORT QskBoundedInput : public QskBoundedControl qreal alignedValue( qreal ) const; QskIntervalF alignedInterval( const QskIntervalF& ) const; + qreal incrementForKey( const QKeyEvent* ) const; + private: qreal m_stepSize = 0.1; int m_pageSize = 1; diff --git a/src/controls/QskBoundedValueInput.h b/src/controls/QskBoundedValueInput.h index 60909ce1..a0d826fc 100644 --- a/src/controls/QskBoundedValueInput.h +++ b/src/controls/QskBoundedValueInput.h @@ -12,7 +12,9 @@ class QSK_EXPORT QskBoundedValueInput : public QskBoundedInput { Q_OBJECT - Q_PROPERTY( qreal value READ value WRITE setValue NOTIFY valueChanged ) + Q_PROPERTY( qreal value READ value + WRITE setValue NOTIFY valueChanged ) + Q_PROPERTY( qreal valueAsRatio READ valueAsRatio WRITE setValueAsRatio NOTIFY valueChanged ) diff --git a/src/controls/QskSlider.h b/src/controls/QskSlider.h index fe75294a..2bc99ab7 100644 --- a/src/controls/QskSlider.h +++ b/src/controls/QskSlider.h @@ -17,7 +17,9 @@ class QSK_EXPORT QskSlider : public QskBoundedValueInput Q_PROPERTY( Qt::Orientation orientation READ orientation WRITE setOrientation NOTIFY orientationChanged ) - Q_PROPERTY( bool tracking READ isTracking WRITE setTracking NOTIFY trackingChanged ) + Q_PROPERTY( bool tracking READ isTracking + WRITE setTracking NOTIFY trackingChanged ) + Q_PROPERTY( qreal handlePosition READ handlePosition ) using Inherited = QskBoundedValueInput;