key handling of bounded inputs improved

This commit is contained in:
Uwe Rathmann 2024-11-28 15:59:59 +01:00
parent d9a66e4a98
commit db1e9a7e44
8 changed files with 92 additions and 9 deletions

View File

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

View File

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

View File

@ -16,6 +16,7 @@ QSK_SUBCONTROL( Dial, Needle )
Dial::Dial( QQuickItem* parent )
: QskBoundedValueInput( parent )
{
setReadOnly( true );
}
QVector< QString > Dial::tickLabels() const

View File

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

View File

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

View File

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

View File

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

View File

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