QSkinny 0.8.0
C++/Qt UI toolkit
Loading...
Searching...
No Matches
QskLayoutMetrics.h
1/******************************************************************************
2 * QSkinny - Copyright (C) The authors
3 * SPDX-License-Identifier: BSD-3-Clause
4 *****************************************************************************/
5
6#ifndef QSK_LAYOUT_METRICS_H
7#define QSK_LAYOUT_METRICS_H
8
9#include "QskGlobal.h"
10#include <qglobal.h>
11#include <qmetatype.h>
12#include <limits>
13
14class QSK_EXPORT QskLayoutMetrics
15{
16 Q_GADGET
17
18 Q_PROPERTY( qreal minimum READ minimum WRITE setMinimum )
19 Q_PROPERTY( qreal preferred READ preferred WRITE setPreferred )
20 Q_PROPERTY( qreal maximum READ maximum WRITE setMaximum )
21
22 public:
23 constexpr QskLayoutMetrics() noexcept = default;
24 constexpr QskLayoutMetrics( qreal minimum, qreal preferred, qreal maximum ) noexcept;
25
26 void normalize() noexcept;
27
28 QskLayoutMetrics normalized() const noexcept;
29 constexpr bool isDefault() const noexcept;
30
31 qreal metric( int which ) const noexcept;
32 void setMetric( int which, qreal metric ) noexcept;
33
34 constexpr bool operator==( const QskLayoutMetrics& ) const noexcept;
35 constexpr bool operator!=( const QskLayoutMetrics& ) const noexcept;
36
37 void setMinimum( qreal value ) noexcept;
38 constexpr qreal minimum() const noexcept;
39
40 void setPreferred( qreal value ) noexcept;
41 constexpr qreal preferred() const noexcept;
42
43 void setMaximum( qreal value ) noexcept;
44 constexpr qreal maximum() const noexcept;
45
46 void setMetrics( qreal minimum, qreal preferred, qreal maximum ) noexcept;
47 void expandTo( const QskLayoutMetrics& ) noexcept;
48
49 void expandMinimum( qreal value ) noexcept;
50 void expandPreferred( qreal value ) noexcept;
51 void expandMaximum( qreal value ) noexcept;
52
53 static qreal combined( int which, qreal value1, qreal value2 ) noexcept;
54 static constexpr qreal unlimited = std::numeric_limits< float >::max();
55
56 private:
57 qreal m_minimum = 0.0;
58 qreal m_preferred = 0.0;
59 qreal m_maximum = QskLayoutMetrics::unlimited;
60};
61
62Q_DECLARE_TYPEINFO( QskLayoutMetrics, Q_MOVABLE_TYPE );
63Q_DECLARE_METATYPE( QskLayoutMetrics )
64
65QT_WARNING_PUSH
66QT_WARNING_DISABLE_CLANG("-Wfloat-equal")
67QT_WARNING_DISABLE_GCC("-Wfloat-equal")
68QT_WARNING_DISABLE_INTEL(1572)
69
70inline constexpr QskLayoutMetrics::QskLayoutMetrics(
71 qreal minimum, qreal preferred, qreal maximum ) noexcept
72 : m_minimum( minimum )
73 , m_preferred( preferred )
74 , m_maximum( maximum )
75{
76}
77
78inline constexpr qreal QskLayoutMetrics::minimum() const noexcept
79{
80 return m_minimum;
81}
82
83inline void QskLayoutMetrics::setMinimum( qreal value ) noexcept
84{
85 m_minimum = value;
86}
87
88inline constexpr qreal QskLayoutMetrics::preferred() const noexcept
89{
90 return m_preferred;
91}
92
93inline void QskLayoutMetrics::setPreferred( qreal value ) noexcept
94{
95 m_preferred = value;
96}
97
98inline constexpr qreal QskLayoutMetrics::maximum() const noexcept
99{
100 return m_maximum;
101}
102
103inline void QskLayoutMetrics::setMaximum( qreal value ) noexcept
104{
105 m_maximum = value;
106}
107
108inline void QskLayoutMetrics::expandMinimum( qreal value ) noexcept
109{
110 if ( value > m_minimum )
111 m_minimum = value;
112}
113
114inline void QskLayoutMetrics::expandPreferred( qreal value ) noexcept
115{
116 if ( value > m_preferred )
117 m_preferred = value;
118}
119
120inline void QskLayoutMetrics::expandMaximum( qreal value ) noexcept
121{
122 if ( value > m_maximum )
123 m_maximum = value;
124}
125
126inline void QskLayoutMetrics::setMetrics(
127 qreal minimum, qreal preferred, qreal maximum ) noexcept
128{
129 m_minimum = minimum;
130 m_preferred = preferred;
131 m_maximum = maximum;
132}
133
134inline qreal QskLayoutMetrics::metric( int which ) const noexcept
135{
136 switch( which )
137 {
138 case Qt::MinimumSize:
139 return m_minimum;
140
141 case Qt::PreferredSize:
142 return m_preferred;
143
144 case Qt::MaximumSize:
145 return m_maximum;
146 }
147
148 return 0.0;
149}
150
151inline constexpr bool QskLayoutMetrics::isDefault() const noexcept
152{
153 return ( m_minimum == 0.0 ) && ( m_preferred == 0.0 )
154 && ( m_maximum == QskLayoutMetrics::unlimited );
155}
156
157inline constexpr bool QskLayoutMetrics::operator==(
158 const QskLayoutMetrics& other ) const noexcept
159{
160 return ( m_preferred == other.m_preferred )
161 && ( m_minimum == other.m_minimum )
162 && ( m_maximum == other.m_maximum );
163}
164
165inline constexpr bool QskLayoutMetrics::operator!=(
166 const QskLayoutMetrics& other ) const noexcept
167{
168 return !( *this == other );
169}
170
171inline QskLayoutMetrics QskLayoutMetrics::normalized() const noexcept
172{
173 auto hint = *this;
174 hint.normalize();
175 return hint;
176}
177
178QT_WARNING_POP
179
180#ifndef QT_NO_DEBUG_STREAM
181
182class QDebug;
183QSK_EXPORT QDebug operator<<( QDebug, const QskLayoutMetrics& );
184
185#endif
186
187#endif