6#include "QskBoundedRangeInput.h"
7#include "QskIntervalF.h"
8#include "QskFunctions.h"
10QskBoundedRangeInput::QskBoundedRangeInput( QQuickItem* parent )
15QskBoundedRangeInput::QskBoundedRangeInput(
22QskBoundedRangeInput::~QskBoundedRangeInput()
26void QskBoundedRangeInput::setLowerValueAsRatio( qreal ratio )
28 ratio = qBound( 0.0, ratio, 1.0 );
29 setLowerValue( minimum() + ratio * boundaryLength() );
32qreal QskBoundedRangeInput::lowerValueAsRatio()
const
34 return ( lowerValue() - minimum() ) / boundaryLength();
37void QskBoundedRangeInput::setUpperValueAsRatio( qreal ratio )
39 ratio = qBound( 0.0, ratio, 1.0 );
40 setUpperValue( minimum() + ratio * boundaryLength() );
43qreal QskBoundedRangeInput::upperValueAsRatio()
const
45 return ( upperValue() - minimum() ) / boundaryLength();
48void QskBoundedRangeInput::setLowerValue( qreal value )
50 if ( isComponentComplete() )
52 value = qMin( value, m_range.upperBound() );
53 value = boundedValue( value );
59qreal QskBoundedRangeInput::lowerValue()
const
61 return m_range.lowerBound();
64void QskBoundedRangeInput::setUpperValue( qreal value )
66 if ( isComponentComplete() )
68 value = qMax( m_range.lowerBound(), value );
69 value = boundedValue( value );
75qreal QskBoundedRangeInput::upperValue()
const
77 return m_range.upperBound();
80void QskBoundedRangeInput::setRange( qreal lowerValue, qreal upperValue )
85void QskBoundedRangeInput::setRange(
const QskIntervalF& range )
87 auto newRange = range;
89 if ( isComponentComplete() )
91 newRange = alignedInterval( newRange );
92 newRange = fixupRange( newRange );
95 setRangeInternal( range );
98void QskBoundedRangeInput::resetRange()
100 if ( m_range.isValid() )
102 m_range.invalidate();
103 Q_EMIT rangeChanged( m_range );
107void QskBoundedRangeInput::setRangeInternal(
const QskIntervalF& range )
109 if ( range != m_range )
111 const auto oldRange = m_range;
114 if ( !qskFuzzyCompare( m_range.lowerBound(), oldRange.lowerBound() ) )
115 Q_EMIT lowerValueChanged( m_range.lowerBound() );
117 if ( !qskFuzzyCompare( m_range.upperBound(), oldRange.upperBound() ) )
118 Q_EMIT upperValueChanged( m_range.upperBound() );
120 Q_EMIT rangeChanged( m_range );
129void QskBoundedRangeInput::alignInput()
131 setRangeInternal( alignedInterval( m_range ) );
139#include "moc_QskBoundedRangeInput.cpp"