6#include "QskBoundedControl.h"
7#include "QskFunctions.h"
8#include "QskIntervalF.h"
10QskBoundedControl::QskBoundedControl( QQuickItem* parent )
15QskBoundedControl::QskBoundedControl( qreal min, qreal max, QQuickItem* parent )
17 , m_minimum( qMin( min, max ) )
18 , m_maximum( qMax( min, max ) )
22QskBoundedControl::~QskBoundedControl()
26void QskBoundedControl::setMinimum( qreal minimum )
28 if ( qskFuzzyCompare( m_minimum, minimum ) )
32 Q_EMIT minimumChanged( minimum );
34 if ( isComponentComplete() )
35 adjustBoundaries(
false );
37 Q_EMIT boundariesChanged( boundaries() );
41qreal QskBoundedControl::minimum()
const
46void QskBoundedControl::setMaximum( qreal maximum )
48 if ( qskFuzzyCompare( m_maximum, maximum ) )
52 Q_EMIT maximumChanged( maximum );
54 if ( isComponentComplete() )
55 adjustBoundaries(
true );
57 Q_EMIT boundariesChanged( boundaries() );
61qreal QskBoundedControl::maximum()
const
66void QskBoundedControl::setBoundaries( qreal min, qreal max )
71 const auto oldMin = m_minimum;
72 const auto oldMax = m_maximum;
74 if ( min == oldMin && max == oldMax )
80 if ( isComponentComplete() )
81 adjustBoundaries(
false );
83 if ( m_minimum != oldMin )
84 Q_EMIT minimumChanged( m_minimum );
86 if ( m_maximum != oldMax )
87 Q_EMIT maximumChanged( m_maximum );
89 Q_EMIT boundariesChanged( boundaries() );
93void QskBoundedControl::setBoundaries(
const QskIntervalF& boundaries )
95 setBoundaries( boundaries.lowerBound(), boundaries.upperBound() );
103void QskBoundedControl::adjustBoundaries(
bool increasing )
105 if ( m_maximum >= m_minimum )
110 m_minimum = m_maximum;
111 Q_EMIT minimumChanged( m_minimum );
115 m_maximum = m_minimum;
116 Q_EMIT maximumChanged( m_maximum );
119 Q_EMIT boundariesChanged( boundaries() );
123qreal QskBoundedControl::boundaryLength()
const
125 return m_maximum - m_minimum;
128void QskBoundedControl::componentComplete()
131 adjustBoundaries(
true );
134qreal QskBoundedControl::boundedValue( qreal value )
const
136 if ( qskFuzzyCompare( value, minimum() ) )
139 if ( qskFuzzyCompare( value, maximum() ) )
142 return qBound( minimum(), value, maximum() );
145qreal QskBoundedControl::valueAsRatio( qreal value )
const
147 const auto range = m_maximum - m_minimum;
148 if ( qFuzzyIsNull( range ) )
151 return ( value - m_minimum ) / range;
154qreal QskBoundedControl::valueFromRatio( qreal ratio )
const
156 ratio = qBound( 0.0, ratio, 1.0 );
157 return m_minimum + ratio * ( m_maximum - m_minimum );
160#include "moc_QskBoundedControl.cpp"
Base class of all controls.
void componentComplete() override