6#include "QskBoundedValueInput.h"
7#include "QskFunctions.h"
14 value = input->boundedValue( value );
16 if ( value > input->minimum() && value < input->maximum() )
18 if ( input->isSnapping() && input->stepSize() )
20 const auto step = input->stepSize();
22 value = qRound( value / step ) * step;
23 value = input->boundedValue( value );
30class QskBoundedValueInput::PrivateData
37QskBoundedValueInput::QskBoundedValueInput( QQuickItem* parent )
39 , m_data( new PrivateData )
43QskBoundedValueInput::~QskBoundedValueInput()
47void QskBoundedValueInput::setDecimals(
int decimals )
49 decimals = qBound( 0, decimals, DBL_MAX_10_EXP + DBL_DIG );
50 if ( decimals != m_data->decimals )
52 m_data->decimals = decimals;
59int QskBoundedValueInput::decimals()
const
61 return m_data->decimals;
64void QskBoundedValueInput::keyPressEvent( QKeyEvent* event )
66 switch( event->key() )
69 setValue( minimum() );
73 setValue( maximum() );
77 Inherited::keyPressEvent( event );
80void QskBoundedValueInput::alignInput()
82 auto value = qskAlignedValue(
this, m_data->value );
83 value = fixupValue( value );
85 setValueInternal( value );
88qreal QskBoundedValueInput::fixupValue( qreal value )
const
93void QskBoundedValueInput::setValueAsRatio( qreal ratio )
95 ratio = qBound( 0.0, ratio, 1.0 );
96 setValue( minimum() + ratio * boundaryLength() );
99qreal QskBoundedValueInput::valueAsRatio()
const
101 return valueAsRatio( m_data->value );
104void QskBoundedValueInput::setValue( qreal value )
106 if ( isComponentComplete() )
108 value = qskAlignedValue(
this, value );
109 value = fixupValue( value );
112 setValueInternal( value );
115qreal QskBoundedValueInput::value()
const
117 return m_data->value;
120void QskBoundedValueInput::increment( qreal offset )
122 setValue( m_data->value + offset );
125void QskBoundedValueInput::setValueInternal( qreal value )
127 if ( !qskFuzzyCompare( value, m_data->value ) )
129 m_data->value = value;
130 Q_EMIT valueChanged( value );
136QString QskBoundedValueInput::valueText()
const
138 return textFromValue( value() );
141QString QskBoundedValueInput::textFromValue( qreal value )
const
143 return locale().toString( value,
'f', m_data->decimals );
146#include "moc_QskBoundedValueInput.cpp"