QSkinny 0.8.0
C++/Qt UI toolkit
Loading...
Searching...
No Matches
QskBoxBorderMetrics.h
1/******************************************************************************
2 * QSkinny - Copyright (C) The authors
3 * SPDX-License-Identifier: BSD-3-Clause
4 *****************************************************************************/
5
6#ifndef QSK_BOX_BORDER_METRICS_H
7#define QSK_BOX_BORDER_METRICS_H
8
9#include "QskMargins.h"
10
11#include <qmetatype.h>
12#include <qnamespace.h>
13#include <qsize.h>
14
15class QVariant;
16
17class QSK_EXPORT QskBoxBorderMetrics
18{
19 Q_GADGET
20
21 Q_PROPERTY( QskMargins widths READ widths WRITE setWidths )
22 Q_PROPERTY( Qt::SizeMode sizeMode READ sizeMode WRITE setSizeMode )
23
24 Q_PROPERTY( qreal left READ left WRITE setLeft )
25 Q_PROPERTY( qreal top READ top WRITE setTop )
26 Q_PROPERTY( qreal right READ right WRITE setRight )
27 Q_PROPERTY( qreal bottom READ bottom WRITE setBottom )
28
29 public:
30 constexpr QskBoxBorderMetrics() noexcept;
31
32 constexpr QskBoxBorderMetrics(
33 qreal width, Qt::SizeMode = Qt::AbsoluteSize ) noexcept;
34
35 constexpr QskBoxBorderMetrics( qreal left, qreal top,
36 qreal right, qreal bottom, Qt::SizeMode = Qt::AbsoluteSize ) noexcept;
37
38 constexpr QskBoxBorderMetrics( const QskMargins& widths,
39 Qt::SizeMode sizeMode = Qt::AbsoluteSize ) noexcept;
40
41 constexpr QskBoxBorderMetrics( const QMarginsF& widths,
42 Qt::SizeMode sizeMode = Qt::AbsoluteSize ) noexcept;
43
44 constexpr bool operator==( const QskBoxBorderMetrics& ) const noexcept;
45 constexpr bool operator!=( const QskBoxBorderMetrics& ) const noexcept;
46
47 constexpr bool isNull() const noexcept;
48
49 void setWidthAt( Qt::Edges, qreal width ) noexcept;
50 qreal widthAt( Qt::Edge ) const noexcept;
51
52 void setWidths( const QskMargins& ) noexcept;
53 constexpr const QskMargins& widths() const noexcept;
54
55 constexpr qreal left() const noexcept;
56 constexpr qreal top() const noexcept;
57 constexpr qreal right() const noexcept;
58 constexpr qreal bottom() const noexcept;
59
60 void setLeft( qreal ) noexcept;
61 void setTop( qreal ) noexcept;
62 void setRight( qreal ) noexcept;
63 void setBottom( qreal ) noexcept;
64
65 void setSizeMode( Qt::SizeMode ) noexcept;
66 constexpr Qt::SizeMode sizeMode() const noexcept;
67
68 QskBoxBorderMetrics interpolated(
69 const QskBoxBorderMetrics&, qreal value ) const noexcept;
70
71 QskBoxBorderMetrics toAbsolute( const QSizeF& ) const noexcept;
72
73 QskHashValue hash( QskHashValue seed = 0 ) const noexcept;
74
75 static QVariant interpolate( const QskBoxBorderMetrics&,
76 const QskBoxBorderMetrics&, qreal progress );
77
78 constexpr bool isEquidistant() const noexcept;
79
80 QRectF adjustedRect( const QRectF& ) const;
81
82 private:
83 QskMargins m_widths;
84 Qt::SizeMode m_sizeMode;
85};
86
87inline constexpr QskBoxBorderMetrics::QskBoxBorderMetrics() noexcept
88 : m_sizeMode( Qt::AbsoluteSize )
89{
90}
91
92inline constexpr QskBoxBorderMetrics::QskBoxBorderMetrics(
93 qreal width, Qt::SizeMode sizeMode ) noexcept
94 : m_widths( width )
95 , m_sizeMode( sizeMode )
96{
97}
98
99inline constexpr QskBoxBorderMetrics::QskBoxBorderMetrics(
100 const QMarginsF& widths, Qt::SizeMode sizeMode ) noexcept
101 : m_widths( widths )
102 , m_sizeMode( sizeMode )
103{
104}
105
106inline constexpr QskBoxBorderMetrics::QskBoxBorderMetrics(
107 const QskMargins& widths, Qt::SizeMode sizeMode ) noexcept
108 : m_widths( widths )
109 , m_sizeMode( sizeMode )
110{
111}
112
113inline constexpr QskBoxBorderMetrics::QskBoxBorderMetrics(
114 qreal left, qreal top, qreal right, qreal bottom, Qt::SizeMode sizeMode ) noexcept
115 : m_widths( left, top, right, bottom )
116 , m_sizeMode( sizeMode )
117{
118}
119
120inline constexpr bool QskBoxBorderMetrics::operator==(
121 const QskBoxBorderMetrics& other ) const noexcept
122{
123 return ( m_sizeMode == other.m_sizeMode ) && ( m_widths == other.m_widths );
124}
125
126inline constexpr bool QskBoxBorderMetrics::operator!=(
127 const QskBoxBorderMetrics& other ) const noexcept
128{
129 return !( *this == other );
130}
131
132inline constexpr bool QskBoxBorderMetrics::isNull() const noexcept
133{
134 return m_widths.isNull();
135}
136
137inline constexpr bool QskBoxBorderMetrics::isEquidistant() const noexcept
138{
139 return m_widths.isEquidistant();
140}
141
142inline constexpr const QskMargins& QskBoxBorderMetrics::widths() const noexcept
143{
144 return m_widths;
145}
146
147inline qreal QskBoxBorderMetrics::widthAt( Qt::Edge edge ) const noexcept
148{
149 return m_widths.marginAt( edge );
150}
151
152inline constexpr qreal QskBoxBorderMetrics::left() const noexcept
153{
154 return m_widths.left();
155}
156
157inline constexpr qreal QskBoxBorderMetrics::top() const noexcept
158{
159 return m_widths.top();
160}
161
162inline constexpr qreal QskBoxBorderMetrics::right() const noexcept
163{
164 return m_widths.right();
165}
166
167inline constexpr qreal QskBoxBorderMetrics::bottom() const noexcept
168{
169 return m_widths.bottom();
170}
171
172inline void QskBoxBorderMetrics::setLeft( qreal left ) noexcept
173{
174 return m_widths.setLeft( left );
175}
176
177inline void QskBoxBorderMetrics::setTop( qreal top ) noexcept
178{
179 return m_widths.setTop( top );
180}
181
182inline void QskBoxBorderMetrics::setRight( qreal right ) noexcept
183{
184 return m_widths.setRight( right );
185}
186
187inline void QskBoxBorderMetrics::setBottom( qreal bottom ) noexcept
188{
189 return m_widths.setBottom( bottom );
190}
191
192inline constexpr Qt::SizeMode QskBoxBorderMetrics::sizeMode() const noexcept
193{
194 return m_sizeMode;
195}
196
197#ifndef QT_NO_DEBUG_STREAM
198
199class QDebug;
200QSK_EXPORT QDebug operator<<( QDebug, const QskBoxBorderMetrics& );
201
202#endif
203
204Q_DECLARE_TYPEINFO( QskBoxBorderMetrics, Q_MOVABLE_TYPE );
205Q_DECLARE_METATYPE( QskBoxBorderMetrics )
206
207#endif