6#include "QskBoundedValueInput.h"
7#include "QskFunctions.h"
12class QskBoundedValueInput::PrivateData
19QskBoundedValueInput::QskBoundedValueInput( QQuickItem* parent )
21 , m_data( new PrivateData )
25QskBoundedValueInput::~QskBoundedValueInput()
29void QskBoundedValueInput::setDecimals(
int decimals )
31 decimals = qBound( 0, decimals, DBL_MAX_10_EXP + DBL_DIG );
32 if ( decimals != m_data->decimals )
34 m_data->decimals = decimals;
41int QskBoundedValueInput::decimals()
const
43 return m_data->decimals;
46void QskBoundedValueInput::alignInput()
48 auto value = alignedValue( m_data->value );
49 value = fixupValue( value );
51 setValueInternal( value );
54qreal QskBoundedValueInput::fixupValue( qreal value )
const
59void QskBoundedValueInput::setValueAsRatio( qreal ratio )
61 ratio = qBound( 0.0, ratio, 1.0 );
62 setValue( minimum() + ratio * boundaryLength() );
65qreal QskBoundedValueInput::valueAsRatio()
const
67 return valueAsRatio( m_data->value );
70void QskBoundedValueInput::setValue( qreal value )
72 if ( isComponentComplete() )
74 value = alignedValue( value );
75 value = fixupValue( value );
78 setValueInternal( value );
81qreal QskBoundedValueInput::value()
const
86void QskBoundedValueInput::increment( qreal offset )
88 setValue( m_data->value + offset );
91void QskBoundedValueInput::setValueInternal( qreal value )
93 if ( !qskFuzzyCompare( value, m_data->value ) )
95 m_data->value = value;
96 Q_EMIT valueChanged( value );
102QString QskBoundedValueInput::valueText()
const
104 return textFromValue( value() );
107QString QskBoundedValueInput::textFromValue( qreal value )
const
109 return locale().toString( value,
'f', m_data->decimals );
112#include "moc_QskBoundedValueInput.cpp"