QskBoundedInput::incrementForKeys added

This commit is contained in:
Uwe Rathmann 2023-02-23 14:33:35 +01:00
parent 7f24cbb95b
commit 06704511d2
4 changed files with 39 additions and 12 deletions

View File

@ -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;
}
}

View File

@ -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;

View File

@ -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 )

View File

@ -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;