Skip to content

Commit

Permalink
QskBoundedInput: pageSize renamed to pageSteps to avoid confusion. wrong
Browse files Browse the repository at this point in the history
usage when sing the wheel fixed
  • Loading branch information
uwerat committed Oct 22, 2024
1 parent 6b1ef04 commit 07bae93
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 44 deletions.
4 changes: 2 additions & 2 deletions examples/gallery/inputs/InputPage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ namespace
setBoundaries( 0, 100 );
setValue( 30 );

setPageSize( 10 );
setStepSize( 1 );
setPageSteps( 10 );
//setSnap( true );

#if 0
Expand Down Expand Up @@ -63,7 +63,7 @@ namespace
{
auto spinBox = new QskSpinBox( 0.0, 100.0, 1.0, this );
spinBox->setSizePolicy( Qt::Horizontal, QskSizePolicy::Fixed );
spinBox->setPageSize( 5 );
spinBox->setPageSteps( 5 );
spinBox->setValue( 35 );
}
}
Expand Down
2 changes: 1 addition & 1 deletion playground/charts/ChartView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ namespace
slider->setBoundaries( min, max );
slider->setValue( value );
slider->setStepSize( 1.0 );
slider->setPageSize( 10.0 );
slider->setPageSteps( 10 );

connect( slider, &QskSlider::valueChanged,
this, &SliderBox::valueChanged );
Expand Down
76 changes: 44 additions & 32 deletions src/controls/QskBoundedInput.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,18 @@

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 )
: Inherited( parent )
, m_stepSize( 0.1 )
, m_pageSize( 1 )
, m_snap( false )
, m_data( new PrivateData )
{
setFocusPolicy( Qt::StrongFocus );
setAcceptedMouseButtons( Qt::LeftButton );
Expand All @@ -38,64 +45,69 @@ void QskBoundedInput::setStepSize( qreal stepSize )
if ( qFuzzyIsNull( stepSize ) )
stepSize = 0.0;

if ( qFuzzyCompare( m_stepSize, stepSize ) )
if ( qFuzzyCompare( m_data->stepSize, stepSize ) )
return;

m_stepSize = stepSize;
m_data->stepSize = stepSize;
Q_EMIT stepSizeChanged( stepSize );

if ( isComponentComplete() )
{
if ( m_snap && stepSize )
if ( m_data->snap && stepSize )
alignInput();
}
}

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;

m_pageSize = pageSize;
Q_EMIT pageSizeChanged( pageSize );
m_data->pageSteps = pageSteps;
Q_EMIT pageStepsChanged( pageSteps );
}

uint QskBoundedInput::pageSteps() const
{
return m_data->pageSteps;
}

int QskBoundedInput::pageSize() const
qreal QskBoundedInput::pageSize() const
{
return m_pageSize;
return m_data->pageSteps * m_data->stepSize;
}

void QskBoundedInput::stepUp()
{
increment( m_stepSize );
increment( m_data->stepSize );
}

void QskBoundedInput::stepDown()
{
increment( -m_stepSize );
increment( -m_data->stepSize );
}

void QskBoundedInput::pageUp()
{
increment( m_pageSize * m_stepSize );
increment( pageSize() );
}

void QskBoundedInput::pageDown()
{
increment( -m_pageSize * m_stepSize );
increment( -pageSize() );
}

void QskBoundedInput::setSnap( bool snap )
{
if ( m_snap == snap )
if ( m_data->snap == snap )
return;

m_snap = snap;
m_data->snap = snap;
Q_EMIT snapChanged( snap );

if ( isComponentComplete() && snap )
Expand All @@ -104,7 +116,7 @@ void QskBoundedInput::setSnap( bool snap )

bool QskBoundedInput::snap() const
{
return m_snap;
return m_data->snap;
}

void QskBoundedInput::componentComplete()
Expand All @@ -128,9 +140,9 @@ qreal QskBoundedInput::alignedValue( qreal value ) const

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 );
}
}
Expand All @@ -140,9 +152,9 @@ qreal QskBoundedInput::alignedValue( qreal value ) 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 upper = std::ceil( interval.upperBound() / step ) * step;
Expand Down Expand Up @@ -182,24 +194,24 @@ qreal QskBoundedInput::incrementForKey( const QKeyEvent* event ) const
switch( event->key() )
{
case Qt::Key_Up:
return m_stepSize;
return m_data->stepSize;

case Qt::Key_Down:
return -m_stepSize;
return -m_data->stepSize;

case Qt::Key_PageUp:
return m_pageSize;
return pageSize();

case Qt::Key_PageDown:
return -m_pageSize;
return -pageSize();

default:
{
if ( qskIsStandardKeyInput( event, QKeySequence::MoveToNextChar ) )
return m_stepSize;
return m_data->stepSize;

if ( qskIsStandardKeyInput( event, QKeySequence::MoveToPreviousChar ) )
return -m_stepSize;
return -m_data->stepSize;
}
}

Expand Down Expand Up @@ -230,9 +242,9 @@ void QskBoundedInput::wheelEvent( QWheelEvent* event )
return;
}

auto offset = qskWheelIncrement( event ) * m_stepSize;
auto offset = qskWheelIncrement( event ) * m_data->stepSize;
if ( event->modifiers() & ( Qt::ControlModifier | Qt::ShiftModifier ) )
offset *= m_pageSize;
offset *= m_data->pageSteps;

increment( offset );
}
Expand Down
14 changes: 7 additions & 7 deletions src/controls/QskBoundedInput.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class QSK_EXPORT QskBoundedInput : public QskBoundedControl
Q_OBJECT

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 readOnly READ isReadOnly WRITE setReadOnly NOTIFY readOnlyChanged )
Expand All @@ -29,7 +29,8 @@ class QSK_EXPORT QskBoundedInput : public QskBoundedControl
~QskBoundedInput() override;

qreal stepSize() const;
int pageSize() const;
qreal pageSize() const; // pageSteps() * stepSize()
uint pageSteps() const;

void setSnap( bool );
bool snap() const;
Expand All @@ -39,7 +40,7 @@ class QSK_EXPORT QskBoundedInput : public QskBoundedControl

public Q_SLOTS:
void setStepSize( qreal );
void setPageSize( int );
void setPageSteps( uint );

void stepUp();
void stepDown();
Expand All @@ -50,7 +51,7 @@ class QSK_EXPORT QskBoundedInput : public QskBoundedControl

Q_SIGNALS:
void stepSizeChanged( qreal );
void pageSizeChanged( qreal );
void pageStepsChanged( qreal );
void snapChanged( bool );

void readOnlyChanged( bool );
Expand All @@ -71,9 +72,8 @@ class QSK_EXPORT QskBoundedInput : public QskBoundedControl
qreal incrementForKey( const QKeyEvent* ) const;

private:
qreal m_stepSize = 0.1;
int m_pageSize = 1;
bool m_snap = false;
class PrivateData;
std::unique_ptr< PrivateData > m_data;
};

#endif
2 changes: 1 addition & 1 deletion src/controls/QskSlider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ void QskSlider::mousePressEvent( QMouseEvent* event )
setSkinStateFlag( Pressed );
Q_EMIT pressedChanged( true );
}
else if ( !pageSize() )
else if ( pageSteps() == 0 )
{
// Case 2: pageSize is not used, we're done here
}
Expand Down
2 changes: 1 addition & 1 deletion src/controls/QskSpinBox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ void QskSpinBox::mousePressEvent( QMouseEvent* event )
{
auto offset = stepSize();
if ( event->modifiers() & ( Qt::ControlModifier | Qt::ShiftModifier ) )
offset *= pageSize();
offset *= pageSteps();

if ( subcontrol == QskSpinBox::DownPanel )
offset = -offset;
Expand Down

0 comments on commit 07bae93

Please sign in to comment.