QskBoundedInput: pageSize renamed to pageSteps to avoid confusion. wrong
usage when sing the wheel fixed
This commit is contained in:
parent
6b1ef043a9
commit
07bae93427
@ -21,8 +21,8 @@ namespace
|
||||
setBoundaries( 0, 100 );
|
||||
setValue( 30 );
|
||||
|
||||
setPageSize( 10 );
|
||||
setStepSize( 1 );
|
||||
setPageSteps( 10 );
|
||||
//setSnap( true );
|
||||
|
||||
#if 0
|
||||
@ -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 );
|
||||
}
|
||||
}
|
||||
|
@ -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 );
|
||||
|
@ -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 );
|
||||
@ -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 );
|
||||
}
|
||||
|
||||
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()
|
||||
{
|
||||
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 )
|
||||
@ -104,7 +116,7 @@ void QskBoundedInput::setSnap( bool snap )
|
||||
|
||||
bool QskBoundedInput::snap() const
|
||||
{
|
||||
return m_snap;
|
||||
return m_data->snap;
|
||||
}
|
||||
|
||||
void QskBoundedInput::componentComplete()
|
||||
@ -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 );
|
||||
}
|
||||
}
|
||||
@ -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;
|
||||
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@ -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 );
|
||||
}
|
||||
|
@ -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 )
|
||||
@ -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;
|
||||
@ -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();
|
||||
@ -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 );
|
||||
@ -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
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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;
|
||||
|
Loading…
x
Reference in New Issue
Block a user