diff --git a/examples/iotdashboard/LightDisplay.cpp b/examples/iotdashboard/LightDisplay.cpp index 1eb762e0..3e48c461 100644 --- a/examples/iotdashboard/LightDisplay.cpp +++ b/examples/iotdashboard/LightDisplay.cpp @@ -44,6 +44,8 @@ LightDisplay::LightDisplay( QQuickItem* parent ) setAlignmentHint( ValueText, Qt::AlignRight ); setBoundaries( 0, 100 ); + setStepSize( 1.0 ); + setPageSteps( 10 ); } bool LightDisplay::isPressed() const @@ -106,6 +108,22 @@ void LightDisplay::mouseReleaseEvent( QMouseEvent* /*event*/ ) setSkinStateFlag( Pressed, false ); } +void LightDisplay::keyPressEvent( QKeyEvent* event ) +{ + switch( event->key() ) + { + case Qt::Key_Left: + increment( -stepSize() ); + return; + + case Qt::Key_Right: + increment( stepSize() ); + return; + } + + Inherited::keyPressEvent( event ); +} + qreal LightDisplay::angleFromPoint( const QRectF& rect, const QPointF& point ) const { const QPointF circlePos( point.x() - rect.center().x(), diff --git a/examples/iotdashboard/LightDisplay.h b/examples/iotdashboard/LightDisplay.h index 9b978f11..928426ff 100644 --- a/examples/iotdashboard/LightDisplay.h +++ b/examples/iotdashboard/LightDisplay.h @@ -29,6 +29,8 @@ class LightDisplay : public QskBoundedValueInput void mouseMoveEvent( QMouseEvent* ) override; void mouseReleaseEvent( QMouseEvent* ) override; + void keyPressEvent( QKeyEvent* ) override; + private: qreal angleFromPoint( const QRectF&, const QPointF& ) const; bool arcContainsPoint( const QRectF&, const QPointF& ) const; diff --git a/playground/dials/Dial.cpp b/playground/dials/Dial.cpp index 7c842183..b4c0bd35 100644 --- a/playground/dials/Dial.cpp +++ b/playground/dials/Dial.cpp @@ -16,6 +16,7 @@ QSK_SUBCONTROL( Dial, Needle ) Dial::Dial( QQuickItem* parent ) : QskBoundedValueInput( parent ) { + setReadOnly( true ); } QVector< QString > Dial::tickLabels() const diff --git a/src/controls/QskBoundedInput.cpp b/src/controls/QskBoundedInput.cpp index 84e75896..396337af 100644 --- a/src/controls/QskBoundedInput.cpp +++ b/src/controls/QskBoundedInput.cpp @@ -172,15 +172,6 @@ qreal QskBoundedInput::incrementForKey( const QKeyEvent* event ) const case Qt::Key_PageDown: return -pageSize(); - - default: - { - if ( qskIsStandardKeyInput( event, QKeySequence::MoveToNextChar ) ) - return m_data->stepSize; - - if ( qskIsStandardKeyInput( event, QKeySequence::MoveToPreviousChar ) ) - return -m_data->stepSize; - } } return 0.0; diff --git a/src/controls/QskBoundedValueInput.cpp b/src/controls/QskBoundedValueInput.cpp index 50031151..4deace08 100644 --- a/src/controls/QskBoundedValueInput.cpp +++ b/src/controls/QskBoundedValueInput.cpp @@ -61,6 +61,22 @@ int QskBoundedValueInput::decimals() const return m_data->decimals; } +void QskBoundedValueInput::keyPressEvent( QKeyEvent* event ) +{ + switch( event->key() ) + { + case Qt::Key_Home: + setValue( minimum() ); + break; + + case Qt::Key_End: + setValue( maximum() ); + break; + } + + Inherited::keyPressEvent( event ); +} + void QskBoundedValueInput::alignInput() { auto value = qskAlignedValue( this, m_data->value ); diff --git a/src/controls/QskBoundedValueInput.h b/src/controls/QskBoundedValueInput.h index bd63b7e5..6f30bb74 100644 --- a/src/controls/QskBoundedValueInput.h +++ b/src/controls/QskBoundedValueInput.h @@ -51,6 +51,8 @@ class QSK_EXPORT QskBoundedValueInput : public QskBoundedInput void decimalsChanged( int ); protected: + void keyPressEvent( QKeyEvent* ) override; + virtual qreal fixupValue( qreal ) const; void alignInput() override; diff --git a/src/controls/QskSlider.cpp b/src/controls/QskSlider.cpp index ad4e776c..02652602 100644 --- a/src/controls/QskSlider.cpp +++ b/src/controls/QskSlider.cpp @@ -49,6 +49,28 @@ static QRectF qskSliderSelectionRect( const QskSlider* slider ) return r; } +static inline int qskKeyOffset( Qt::Orientation orientation, int key ) +{ + if ( orientation == Qt::Horizontal ) + { + if ( key == Qt::Key_Left ) + return -1; + + if ( key == Qt::Key_Right ) + return 1; + } + else + { + if ( key == Qt::Key_Down ) + return -1; + + if ( key == Qt::Key_Up ) + return 1; + } + + return 0; +} + class QskSlider::PrivateData { public: @@ -255,6 +277,35 @@ void QskSlider::mouseReleaseEvent( QMouseEvent* ) setSkinStateFlag( Pressed, false ); } +void QskSlider::keyPressEvent( QKeyEvent* event ) +{ + if ( const auto offset = qskKeyOffset( orientation(), event->key() ) ) + { + increment( offset * stepSize() ); + return; + } + + if ( m_data->hasOrigin ) + { + switch( event->key() ) + { + case Qt::Key_Home: + { + setValue( origin() ); + return; + } + + case Qt::Key_End: + { + // we have 2 endpoints - better do nothing + return; + } + } + } + + Inherited::keyPressEvent( event ); +} + void QskSlider::moveHandle() { QskAnimationHint hint; diff --git a/src/controls/QskSlider.h b/src/controls/QskSlider.h index 10d4ef27..c0fd33ae 100644 --- a/src/controls/QskSlider.h +++ b/src/controls/QskSlider.h @@ -59,6 +59,8 @@ class QSK_EXPORT QskSlider : public QskBoundedValueInput void mouseMoveEvent( QMouseEvent* ) override; void mouseReleaseEvent( QMouseEvent* ) override; + void keyPressEvent( QKeyEvent* ) override; + void aboutToShow() override; void componentComplete() override;