key handling of bounded inputs improved
This commit is contained in:
parent
d9a66e4a98
commit
db1e9a7e44
@ -44,6 +44,8 @@ LightDisplay::LightDisplay( QQuickItem* parent )
|
|||||||
setAlignmentHint( ValueText, Qt::AlignRight );
|
setAlignmentHint( ValueText, Qt::AlignRight );
|
||||||
|
|
||||||
setBoundaries( 0, 100 );
|
setBoundaries( 0, 100 );
|
||||||
|
setStepSize( 1.0 );
|
||||||
|
setPageSteps( 10 );
|
||||||
}
|
}
|
||||||
|
|
||||||
bool LightDisplay::isPressed() const
|
bool LightDisplay::isPressed() const
|
||||||
@ -106,6 +108,22 @@ void LightDisplay::mouseReleaseEvent( QMouseEvent* /*event*/ )
|
|||||||
setSkinStateFlag( Pressed, false );
|
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
|
qreal LightDisplay::angleFromPoint( const QRectF& rect, const QPointF& point ) const
|
||||||
{
|
{
|
||||||
const QPointF circlePos( point.x() - rect.center().x(),
|
const QPointF circlePos( point.x() - rect.center().x(),
|
||||||
|
@ -29,6 +29,8 @@ class LightDisplay : public QskBoundedValueInput
|
|||||||
void mouseMoveEvent( QMouseEvent* ) override;
|
void mouseMoveEvent( QMouseEvent* ) override;
|
||||||
void mouseReleaseEvent( QMouseEvent* ) override;
|
void mouseReleaseEvent( QMouseEvent* ) override;
|
||||||
|
|
||||||
|
void keyPressEvent( QKeyEvent* ) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
qreal angleFromPoint( const QRectF&, const QPointF& ) const;
|
qreal angleFromPoint( const QRectF&, const QPointF& ) const;
|
||||||
bool arcContainsPoint( const QRectF&, const QPointF& ) const;
|
bool arcContainsPoint( const QRectF&, const QPointF& ) const;
|
||||||
|
@ -16,6 +16,7 @@ QSK_SUBCONTROL( Dial, Needle )
|
|||||||
Dial::Dial( QQuickItem* parent )
|
Dial::Dial( QQuickItem* parent )
|
||||||
: QskBoundedValueInput( parent )
|
: QskBoundedValueInput( parent )
|
||||||
{
|
{
|
||||||
|
setReadOnly( true );
|
||||||
}
|
}
|
||||||
|
|
||||||
QVector< QString > Dial::tickLabels() const
|
QVector< QString > Dial::tickLabels() const
|
||||||
|
@ -172,15 +172,6 @@ qreal QskBoundedInput::incrementForKey( const QKeyEvent* event ) const
|
|||||||
|
|
||||||
case Qt::Key_PageDown:
|
case Qt::Key_PageDown:
|
||||||
return -pageSize();
|
return -pageSize();
|
||||||
|
|
||||||
default:
|
|
||||||
{
|
|
||||||
if ( qskIsStandardKeyInput( event, QKeySequence::MoveToNextChar ) )
|
|
||||||
return m_data->stepSize;
|
|
||||||
|
|
||||||
if ( qskIsStandardKeyInput( event, QKeySequence::MoveToPreviousChar ) )
|
|
||||||
return -m_data->stepSize;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0.0;
|
return 0.0;
|
||||||
|
@ -61,6 +61,22 @@ int QskBoundedValueInput::decimals() const
|
|||||||
return m_data->decimals;
|
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()
|
void QskBoundedValueInput::alignInput()
|
||||||
{
|
{
|
||||||
auto value = qskAlignedValue( this, m_data->value );
|
auto value = qskAlignedValue( this, m_data->value );
|
||||||
|
@ -51,6 +51,8 @@ class QSK_EXPORT QskBoundedValueInput : public QskBoundedInput
|
|||||||
void decimalsChanged( int );
|
void decimalsChanged( int );
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
void keyPressEvent( QKeyEvent* ) override;
|
||||||
|
|
||||||
virtual qreal fixupValue( qreal ) const;
|
virtual qreal fixupValue( qreal ) const;
|
||||||
void alignInput() override;
|
void alignInput() override;
|
||||||
|
|
||||||
|
@ -49,6 +49,28 @@ static QRectF qskSliderSelectionRect( const QskSlider* slider )
|
|||||||
return r;
|
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
|
class QskSlider::PrivateData
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
@ -255,6 +277,35 @@ void QskSlider::mouseReleaseEvent( QMouseEvent* )
|
|||||||
setSkinStateFlag( Pressed, false );
|
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()
|
void QskSlider::moveHandle()
|
||||||
{
|
{
|
||||||
QskAnimationHint hint;
|
QskAnimationHint hint;
|
||||||
|
@ -59,6 +59,8 @@ class QSK_EXPORT QskSlider : public QskBoundedValueInput
|
|||||||
void mouseMoveEvent( QMouseEvent* ) override;
|
void mouseMoveEvent( QMouseEvent* ) override;
|
||||||
void mouseReleaseEvent( QMouseEvent* ) override;
|
void mouseReleaseEvent( QMouseEvent* ) override;
|
||||||
|
|
||||||
|
void keyPressEvent( QKeyEvent* ) override;
|
||||||
|
|
||||||
void aboutToShow() override;
|
void aboutToShow() override;
|
||||||
void componentComplete() override;
|
void componentComplete() override;
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user