QSkinny 0.8.0
C++/Qt UI toolkit
Loading...
Searching...
No Matches
QskBoundedRangeInput.cpp
1/******************************************************************************
2 * QSkinny - Copyright (C) The authors
3 * SPDX-License-Identifier: BSD-3-Clause
4 *****************************************************************************/
5
6#include "QskBoundedRangeInput.h"
7#include "QskIntervalF.h"
8#include "QskFunctions.h"
9
10QskBoundedRangeInput::QskBoundedRangeInput( QQuickItem* parent )
11 : QskBoundedInput( parent )
12{
13}
14
15QskBoundedRangeInput::QskBoundedRangeInput(
16 const QskIntervalF& range, QQuickItem* parent )
17 : QskBoundedInput( parent )
18 , m_range( range )
19{
20}
21
22QskBoundedRangeInput::~QskBoundedRangeInput()
23{
24}
25
26void QskBoundedRangeInput::setLowerValueAsRatio( qreal ratio )
27{
28 ratio = qBound( 0.0, ratio, 1.0 );
29 setLowerValue( minimum() + ratio * boundaryLength() );
30}
31
32qreal QskBoundedRangeInput::lowerValueAsRatio() const
33{
34 return ( lowerValue() - minimum() ) / boundaryLength();
35}
36
37void QskBoundedRangeInput::setUpperValueAsRatio( qreal ratio )
38{
39 ratio = qBound( 0.0, ratio, 1.0 );
40 setUpperValue( minimum() + ratio * boundaryLength() );
41}
42
43qreal QskBoundedRangeInput::upperValueAsRatio() const
44{
45 return ( upperValue() - minimum() ) / boundaryLength();
46}
47
48void QskBoundedRangeInput::setLowerValue( qreal value )
49{
50 if ( isComponentComplete() )
51 {
52 value = qMin( value, m_range.upperBound() );
53 value = boundedValue( value );
54 }
55
56 setRange( QskIntervalF( value, m_range.upperBound() ) );
57}
58
59qreal QskBoundedRangeInput::lowerValue() const
60{
61 return m_range.lowerBound();
62}
63
64void QskBoundedRangeInput::setUpperValue( qreal value )
65{
66 if ( isComponentComplete() )
67 {
68 value = qMax( m_range.lowerBound(), value );
69 value = boundedValue( value );
70 }
71
72 setRange( QskIntervalF( m_range.lowerBound(), value ) );
73}
74
75qreal QskBoundedRangeInput::upperValue() const
76{
77 return m_range.upperBound();
78}
79
80void QskBoundedRangeInput::setRange( qreal lowerValue, qreal upperValue )
81{
82 setRange( QskIntervalF( lowerValue, upperValue ) );
83}
84
85void QskBoundedRangeInput::setRange( const QskIntervalF& range )
86{
87 auto newRange = range;
88
89 if ( isComponentComplete() )
90 {
91 newRange = alignedInterval( newRange );
92 newRange = fixupRange( newRange );
93 }
94
95 setRangeInternal( range );
96}
97
98void QskBoundedRangeInput::resetRange()
99{
100 if ( m_range.isValid() )
101 {
102 m_range.invalidate();
103 Q_EMIT rangeChanged( m_range );
104 }
105}
106
107void QskBoundedRangeInput::setRangeInternal( const QskIntervalF& range )
108{
109 if ( range != m_range )
110 {
111 const auto oldRange = m_range;
112 m_range = range;
113
114 if ( !qskFuzzyCompare( m_range.lowerBound(), oldRange.lowerBound() ) )
115 Q_EMIT lowerValueChanged( m_range.lowerBound() );
116
117 if ( !qskFuzzyCompare( m_range.upperBound(), oldRange.upperBound() ) )
118 Q_EMIT upperValueChanged( m_range.upperBound() );
119
120 Q_EMIT rangeChanged( m_range );
121 }
122}
123
124QskIntervalF QskBoundedRangeInput::range() const
125{
126 return m_range;
127}
128
129void QskBoundedRangeInput::alignInput()
130{
131 setRangeInternal( alignedInterval( m_range ) );
132}
133
134QskIntervalF QskBoundedRangeInput::fixupRange( const QskIntervalF& range ) const
135{
136 return range;
137}
138
139#include "moc_QskBoundedRangeInput.cpp"