QskBoundedInput: pageSize renamed to pageSteps to avoid confusion. wrong

usage when sing the wheel fixed
This commit is contained in:
Uwe Rathmann 2024-10-22 11:55:22 +02:00
parent 6b1ef043a9
commit 07bae93427
6 changed files with 56 additions and 44 deletions

View File

@ -21,8 +21,8 @@ namespace
setBoundaries( 0, 100 ); setBoundaries( 0, 100 );
setValue( 30 ); setValue( 30 );
setPageSize( 10 );
setStepSize( 1 ); setStepSize( 1 );
setPageSteps( 10 );
//setSnap( true ); //setSnap( true );
#if 0 #if 0
@ -63,7 +63,7 @@ namespace
{ {
auto spinBox = new QskSpinBox( 0.0, 100.0, 1.0, this ); auto spinBox = new QskSpinBox( 0.0, 100.0, 1.0, this );
spinBox->setSizePolicy( Qt::Horizontal, QskSizePolicy::Fixed ); spinBox->setSizePolicy( Qt::Horizontal, QskSizePolicy::Fixed );
spinBox->setPageSize( 5 ); spinBox->setPageSteps( 5 );
spinBox->setValue( 35 ); spinBox->setValue( 35 );
} }
} }

View File

@ -98,7 +98,7 @@ namespace
slider->setBoundaries( min, max ); slider->setBoundaries( min, max );
slider->setValue( value ); slider->setValue( value );
slider->setStepSize( 1.0 ); slider->setStepSize( 1.0 );
slider->setPageSize( 10.0 ); slider->setPageSteps( 10 );
connect( slider, &QskSlider::valueChanged, connect( slider, &QskSlider::valueChanged,
this, &SliderBox::valueChanged ); this, &SliderBox::valueChanged );

View File

@ -12,11 +12,18 @@
QSK_SYSTEM_STATE( QskBoundedInput, ReadOnly, ( QskAspect::FirstSystemState << 1 ) ) QSK_SYSTEM_STATE( QskBoundedInput, ReadOnly, ( QskAspect::FirstSystemState << 1 ) )
class QskBoundedInput::PrivateData
{
public:
qreal stepSize = 0.1;
uint pageSteps = 1;
bool snap = false;
};
QskBoundedInput::QskBoundedInput( QQuickItem* parent ) QskBoundedInput::QskBoundedInput( QQuickItem* parent )
: Inherited( parent ) : Inherited( parent )
, m_stepSize( 0.1 ) , m_data( new PrivateData )
, m_pageSize( 1 )
, m_snap( false )
{ {
setFocusPolicy( Qt::StrongFocus ); setFocusPolicy( Qt::StrongFocus );
setAcceptedMouseButtons( Qt::LeftButton ); setAcceptedMouseButtons( Qt::LeftButton );
@ -38,64 +45,69 @@ void QskBoundedInput::setStepSize( qreal stepSize )
if ( qFuzzyIsNull( stepSize ) ) if ( qFuzzyIsNull( stepSize ) )
stepSize = 0.0; stepSize = 0.0;
if ( qFuzzyCompare( m_stepSize, stepSize ) ) if ( qFuzzyCompare( m_data->stepSize, stepSize ) )
return; return;
m_stepSize = stepSize; m_data->stepSize = stepSize;
Q_EMIT stepSizeChanged( stepSize ); Q_EMIT stepSizeChanged( stepSize );
if ( isComponentComplete() ) if ( isComponentComplete() )
{ {
if ( m_snap && stepSize ) if ( m_data->snap && stepSize )
alignInput(); alignInput();
} }
} }
qreal QskBoundedInput::stepSize() const qreal QskBoundedInput::stepSize() const
{ {
return m_stepSize; return m_data->stepSize;
} }
void QskBoundedInput::setPageSize( int pageSize ) void QskBoundedInput::setPageSteps( uint pageSteps )
{ {
if ( m_pageSize == pageSize ) if ( m_data->pageSteps == pageSteps )
return; return;
m_pageSize = pageSize; m_data->pageSteps = pageSteps;
Q_EMIT pageSizeChanged( pageSize ); Q_EMIT pageStepsChanged( pageSteps );
} }
int QskBoundedInput::pageSize() const uint QskBoundedInput::pageSteps() const
{ {
return m_pageSize; return m_data->pageSteps;
}
qreal QskBoundedInput::pageSize() const
{
return m_data->pageSteps * m_data->stepSize;
} }
void QskBoundedInput::stepUp() void QskBoundedInput::stepUp()
{ {
increment( m_stepSize ); increment( m_data->stepSize );
} }
void QskBoundedInput::stepDown() void QskBoundedInput::stepDown()
{ {
increment( -m_stepSize ); increment( -m_data->stepSize );
} }
void QskBoundedInput::pageUp() void QskBoundedInput::pageUp()
{ {
increment( m_pageSize * m_stepSize ); increment( pageSize() );
} }
void QskBoundedInput::pageDown() void QskBoundedInput::pageDown()
{ {
increment( -m_pageSize * m_stepSize ); increment( -pageSize() );
} }
void QskBoundedInput::setSnap( bool snap ) void QskBoundedInput::setSnap( bool snap )
{ {
if ( m_snap == snap ) if ( m_data->snap == snap )
return; return;
m_snap = snap; m_data->snap = snap;
Q_EMIT snapChanged( snap ); Q_EMIT snapChanged( snap );
if ( isComponentComplete() && snap ) if ( isComponentComplete() && snap )
@ -104,7 +116,7 @@ void QskBoundedInput::setSnap( bool snap )
bool QskBoundedInput::snap() const bool QskBoundedInput::snap() const
{ {
return m_snap; return m_data->snap;
} }
void QskBoundedInput::componentComplete() void QskBoundedInput::componentComplete()
@ -128,9 +140,9 @@ qreal QskBoundedInput::alignedValue( qreal value ) const
if ( value > minimum() && value < maximum() ) if ( value > minimum() && value < maximum() )
{ {
if ( m_snap && m_stepSize ) if ( m_data->snap && m_data->stepSize )
{ {
value = qRound( value / m_stepSize ) * m_stepSize; value = qRound( value / m_data->stepSize ) * m_data->stepSize;
value = boundedValue( value ); value = boundedValue( value );
} }
} }
@ -140,9 +152,9 @@ qreal QskBoundedInput::alignedValue( qreal value ) const
QskIntervalF QskBoundedInput::alignedInterval( const QskIntervalF& interval ) const QskIntervalF QskBoundedInput::alignedInterval( const QskIntervalF& interval ) const
{ {
if ( m_snap ) if ( m_data->snap )
{ {
if ( const auto step = m_stepSize ) if ( const auto step = m_data->stepSize )
{ {
const qreal lower = std::floor( interval.lowerBound() / step ) * step; const qreal lower = std::floor( interval.lowerBound() / step ) * step;
const qreal upper = std::ceil( interval.upperBound() / step ) * step; const qreal upper = std::ceil( interval.upperBound() / step ) * step;
@ -182,24 +194,24 @@ qreal QskBoundedInput::incrementForKey( const QKeyEvent* event ) const
switch( event->key() ) switch( event->key() )
{ {
case Qt::Key_Up: case Qt::Key_Up:
return m_stepSize; return m_data->stepSize;
case Qt::Key_Down: case Qt::Key_Down:
return -m_stepSize; return -m_data->stepSize;
case Qt::Key_PageUp: case Qt::Key_PageUp:
return m_pageSize; return pageSize();
case Qt::Key_PageDown: case Qt::Key_PageDown:
return -m_pageSize; return -pageSize();
default: default:
{ {
if ( qskIsStandardKeyInput( event, QKeySequence::MoveToNextChar ) ) if ( qskIsStandardKeyInput( event, QKeySequence::MoveToNextChar ) )
return m_stepSize; return m_data->stepSize;
if ( qskIsStandardKeyInput( event, QKeySequence::MoveToPreviousChar ) ) if ( qskIsStandardKeyInput( event, QKeySequence::MoveToPreviousChar ) )
return -m_stepSize; return -m_data->stepSize;
} }
} }
@ -230,9 +242,9 @@ void QskBoundedInput::wheelEvent( QWheelEvent* event )
return; return;
} }
auto offset = qskWheelIncrement( event ) * m_stepSize; auto offset = qskWheelIncrement( event ) * m_data->stepSize;
if ( event->modifiers() & ( Qt::ControlModifier | Qt::ShiftModifier ) ) if ( event->modifiers() & ( Qt::ControlModifier | Qt::ShiftModifier ) )
offset *= m_pageSize; offset *= m_data->pageSteps;
increment( offset ); increment( offset );
} }

View File

@ -15,7 +15,7 @@ class QSK_EXPORT QskBoundedInput : public QskBoundedControl
Q_OBJECT Q_OBJECT
Q_PROPERTY( qreal stepSize READ stepSize WRITE setStepSize NOTIFY stepSizeChanged ) Q_PROPERTY( qreal stepSize READ stepSize WRITE setStepSize NOTIFY stepSizeChanged )
Q_PROPERTY( int pageSize READ pageSize WRITE setPageSize NOTIFY pageSizeChanged ) Q_PROPERTY( uint pageSteps READ pageSteps WRITE setPageSteps NOTIFY pageStepsChanged )
Q_PROPERTY( bool snap READ snap WRITE setSnap NOTIFY snapChanged ) Q_PROPERTY( bool snap READ snap WRITE setSnap NOTIFY snapChanged )
Q_PROPERTY( bool readOnly READ isReadOnly WRITE setReadOnly NOTIFY readOnlyChanged ) Q_PROPERTY( bool readOnly READ isReadOnly WRITE setReadOnly NOTIFY readOnlyChanged )
@ -29,7 +29,8 @@ class QSK_EXPORT QskBoundedInput : public QskBoundedControl
~QskBoundedInput() override; ~QskBoundedInput() override;
qreal stepSize() const; qreal stepSize() const;
int pageSize() const; qreal pageSize() const; // pageSteps() * stepSize()
uint pageSteps() const;
void setSnap( bool ); void setSnap( bool );
bool snap() const; bool snap() const;
@ -39,7 +40,7 @@ class QSK_EXPORT QskBoundedInput : public QskBoundedControl
public Q_SLOTS: public Q_SLOTS:
void setStepSize( qreal ); void setStepSize( qreal );
void setPageSize( int ); void setPageSteps( uint );
void stepUp(); void stepUp();
void stepDown(); void stepDown();
@ -50,7 +51,7 @@ class QSK_EXPORT QskBoundedInput : public QskBoundedControl
Q_SIGNALS: Q_SIGNALS:
void stepSizeChanged( qreal ); void stepSizeChanged( qreal );
void pageSizeChanged( qreal ); void pageStepsChanged( qreal );
void snapChanged( bool ); void snapChanged( bool );
void readOnlyChanged( bool ); void readOnlyChanged( bool );
@ -71,9 +72,8 @@ class QSK_EXPORT QskBoundedInput : public QskBoundedControl
qreal incrementForKey( const QKeyEvent* ) const; qreal incrementForKey( const QKeyEvent* ) const;
private: private:
qreal m_stepSize = 0.1; class PrivateData;
int m_pageSize = 1; std::unique_ptr< PrivateData > m_data;
bool m_snap = false;
}; };
#endif #endif

View File

@ -131,7 +131,7 @@ void QskSlider::mousePressEvent( QMouseEvent* event )
setSkinStateFlag( Pressed ); setSkinStateFlag( Pressed );
Q_EMIT pressedChanged( true ); Q_EMIT pressedChanged( true );
} }
else if ( !pageSize() ) else if ( pageSteps() == 0 )
{ {
// Case 2: pageSize is not used, we're done here // Case 2: pageSize is not used, we're done here
} }

View File

@ -256,7 +256,7 @@ void QskSpinBox::mousePressEvent( QMouseEvent* event )
{ {
auto offset = stepSize(); auto offset = stepSize();
if ( event->modifiers() & ( Qt::ControlModifier | Qt::ShiftModifier ) ) if ( event->modifiers() & ( Qt::ControlModifier | Qt::ShiftModifier ) )
offset *= pageSize(); offset *= pageSteps();
if ( subcontrol == QskSpinBox::DownPanel ) if ( subcontrol == QskSpinBox::DownPanel )
offset = -offset; offset = -offset;