API cleanup of the Bounded controls

This commit is contained in:
Uwe Rathmann 2024-11-21 13:54:01 +01:00
parent 109fc7d7f4
commit d87c8e3d0b
9 changed files with 51 additions and 63 deletions

View File

@ -23,7 +23,7 @@ static inline bool qskHasOrigin( const QskSlider* )
static inline qreal qskTickValue( const QskSlider* slider, int index )
{
if( slider->snap() )
if( slider->isSnapping() && slider->stepSize() )
return slider->minimum() + index * slider->stepSize();
if ( qskHasOrigin( slider ) )
@ -119,7 +119,7 @@ int QskMaterial3SliderSkinlet::sampleCount( const QskSkinnable* skinnable,
{
const auto slider = static_cast< const QskSlider* >( skinnable );
if( slider->snap() )
if( slider->isSnapping() && slider->stepSize() )
return qCeil( slider->boundaryLength() / slider->stepSize() ) + 1;
// min/origin/max or max

View File

@ -17,7 +17,7 @@ namespace
public:
enum Style
{
Continous,
Continuous,
Discrete,
Centered
};
@ -33,15 +33,15 @@ namespace
{
case Discrete:
{
setSnap( true );
setSnapping( true );
setStepSize( 5 );
setPageSteps( 4 );
break;
}
case Continous:
case Continuous:
{
setSnap( false );
setSnapping( false );
setStepSize( 1 );
setPageSteps( 10 );
@ -104,7 +104,7 @@ InputPage::InputPage( QQuickItem* parent )
{
const auto orientation = static_cast< Qt::Orientation >( i + 1 );
sliders[i].continous = new Slider( orientation, Slider::Continous );
sliders[i].continous = new Slider( orientation, Slider::Continuous );
sliders[i].discrete = new Slider( orientation, Slider::Discrete );
}

View File

@ -20,7 +20,7 @@ Slider::Slider( const QString& text, qreal min, qreal max,
m_slider = new QskSlider( this );
m_slider->setBoundaries( min, max );
m_slider->setStepSize( step );
m_slider->setSnap( true );
m_slider->setSnapping( true );
m_slider->setValue( value );
m_valueLabel = new QskTextLabel( this );

View File

@ -53,9 +53,9 @@ class QSK_EXPORT QskBoundedControl : public QskControl
void componentComplete() override;
private:
void adjustBoundaries( bool increasing );
private:
qreal m_minimum;
qreal m_maximum;
};

View File

@ -18,7 +18,7 @@ class QskBoundedInput::PrivateData
qreal stepSize = 0.1;
uint pageSteps = 1;
bool snap = false;
bool snapping = false;
};
QskBoundedInput::QskBoundedInput( QQuickItem* parent )
@ -53,7 +53,7 @@ void QskBoundedInput::setStepSize( qreal stepSize )
if ( isComponentComplete() )
{
if ( m_data->snap && stepSize )
if ( m_data->snapping && stepSize )
alignInput();
}
}
@ -102,21 +102,21 @@ void QskBoundedInput::pageDown()
increment( -pageSize() );
}
void QskBoundedInput::setSnap( bool snap )
void QskBoundedInput::setSnapping( bool on )
{
if ( m_data->snap == snap )
if ( m_data->snapping == on )
return;
m_data->snap = snap;
Q_EMIT snapChanged( snap );
m_data->snapping = on;
Q_EMIT snappingChanged( on );
if ( isComponentComplete() && snap )
if ( isComponentComplete() && m_data->snapping )
alignInput();
}
bool QskBoundedInput::snap() const
bool QskBoundedInput::isSnapping() const
{
return m_data->snap;
return m_data->snapping;
}
void QskBoundedInput::componentComplete()
@ -134,38 +134,6 @@ void QskBoundedInput::alignInput()
{
}
qreal QskBoundedInput::alignedValue( qreal value ) const
{
value = boundedValue( value );
if ( value > minimum() && value < maximum() )
{
if ( m_data->snap && m_data->stepSize )
{
value = qRound( value / m_data->stepSize ) * m_data->stepSize;
value = boundedValue( value );
}
}
return value;
}
QskIntervalF QskBoundedInput::alignedInterval( const QskIntervalF& interval ) const
{
if ( m_data->snap )
{
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;
return QskIntervalF( lower, upper );
}
}
return interval;
}
void QskBoundedInput::setReadOnly( bool readOnly )
{
if ( readOnly == isReadOnly() )

View File

@ -17,7 +17,7 @@ class QSK_EXPORT QskBoundedInput : public QskBoundedControl
Q_PROPERTY( qreal stepSize READ stepSize WRITE setStepSize NOTIFY stepSizeChanged )
Q_PROPERTY( uint pageSteps READ pageSteps WRITE setPageSteps NOTIFY pageStepsChanged )
Q_PROPERTY( bool snap READ snap WRITE setSnap NOTIFY snapChanged )
Q_PROPERTY( bool snapping READ isSnapping WRITE setSnapping NOTIFY snappingChanged )
Q_PROPERTY( bool readOnly READ isReadOnly WRITE setReadOnly NOTIFY readOnlyChanged )
using Inherited = QskBoundedControl;
@ -30,10 +30,10 @@ class QSK_EXPORT QskBoundedInput : public QskBoundedControl
qreal stepSize() const;
qreal pageSize() const; // pageSteps() * stepSize()
uint pageSteps() const;
uint pageSteps() const;
void setSnap( bool );
bool snap() const;
void setSnapping( bool );
bool isSnapping() const;
void setReadOnly( bool );
bool isReadOnly() const;
@ -52,7 +52,7 @@ class QSK_EXPORT QskBoundedInput : public QskBoundedControl
Q_SIGNALS:
void stepSizeChanged( qreal );
void pageStepsChanged( qreal );
void snapChanged( bool );
void snappingChanged( bool );
void readOnlyChanged( bool );
@ -66,9 +66,6 @@ class QSK_EXPORT QskBoundedInput : public QskBoundedControl
void componentComplete() override;
virtual void alignInput();
qreal alignedValue( qreal ) const;
QskIntervalF alignedInterval( const QskIntervalF& ) const;
qreal incrementForKey( const QKeyEvent* ) const;
private:

View File

@ -88,7 +88,9 @@ void QskBoundedRangeInput::setRange( const QskIntervalF& range )
if ( isComponentComplete() )
{
newRange = alignedInterval( newRange );
if ( isSnapping() && stepSize() )
newRange = newRange.fuzzyAligned( stepSize() );
newRange = fixupRange( newRange );
}
@ -128,7 +130,11 @@ QskIntervalF QskBoundedRangeInput::range() const
void QskBoundedRangeInput::alignInput()
{
setRangeInternal( alignedInterval( m_range ) );
auto newRange = m_range;
if ( isSnapping() && stepSize() )
newRange = newRange.fuzzyAligned( stepSize() );
setRangeInternal( newRange );
}
QskIntervalF QskBoundedRangeInput::fixupRange( const QskIntervalF& range ) const

View File

@ -9,6 +9,24 @@
#include <qlocale.h>
#include <cfloat>
static qreal qskAlignedValue( const QskBoundedValueInput* input, qreal value )
{
value = input->boundedValue( value );
if ( value > input->minimum() && value < input->maximum() )
{
if ( input->isSnapping() && input->stepSize() )
{
const auto step = input->stepSize();
value = qRound( value / step ) * step;
value = input->boundedValue( value );
}
}
return value;
}
class QskBoundedValueInput::PrivateData
{
public:
@ -45,7 +63,7 @@ int QskBoundedValueInput::decimals() const
void QskBoundedValueInput::alignInput()
{
auto value = alignedValue( m_data->value );
auto value = qskAlignedValue( this, m_data->value );
value = fixupValue( value );
setValueInternal( value );
@ -71,7 +89,7 @@ void QskBoundedValueInput::setValue( qreal value )
{
if ( isComponentComplete() )
{
value = alignedValue( value );
value = qskAlignedValue( this, value );
value = fixupValue( value );
}

View File

@ -73,7 +73,6 @@ class QSK_EXPORT QskProgressIndicator : public QskBoundedControl
private:
void setValueInternal( qreal value );
void adjustBoundaries( bool increasing );
void adjustValue();
class PrivateData;