QSkinny 0.8.0
C++/Qt UI toolkit
Loading...
Searching...
No Matches
QskShadowMetrics.h
1/******************************************************************************
2 * QSkinny - Copyright (C) The authors
3 * SPDX-License-Identifier: BSD-3-Clause
4 *****************************************************************************/
5
6#ifndef QSK_SHADOW_METRICS_H
7#define QSK_SHADOW_METRICS_H
8
9#include "QskGlobal.h"
10
11#include <qmetatype.h>
12#include <qnamespace.h>
13#include <qpoint.h>
14
15class QVariant;
16
17class QSK_EXPORT QskShadowMetrics
18{
19 Q_GADGET
20
21 Q_PROPERTY( QPointF offset READ offset WRITE setOffset )
22 Q_PROPERTY( qreal spreadRadius READ spreadRadius WRITE setSpreadRadius )
23 Q_PROPERTY( qreal blurRadius READ blurRadius WRITE setBlurRadius )
24
25 Q_PROPERTY( Qt::SizeMode sizeMode READ sizeMode WRITE setSizeMode )
26 Q_PROPERTY( ShapeMode shapeMode READ shapeMode WRITE setShapeMode )
27
28 public:
29 enum ShapeMode
30 {
31 Aligned = 0, // The shape is related to some external definition
32
33 Ellipse,
34 Rectangle
35 };
36 Q_ENUM( ShapeMode )
37
38 constexpr QskShadowMetrics( const QPointF& offset = QPointF() ) noexcept;
39
40 constexpr QskShadowMetrics( qreal spreadRadius, qreal blurRadius ) noexcept;
41
42 constexpr QskShadowMetrics( qreal spreadRadius, qreal blurRadius,
43 const QPointF& offset, Qt::SizeMode = Qt::AbsoluteSize ) noexcept;
44
45 constexpr bool operator==( const QskShadowMetrics& ) const noexcept;
46 constexpr bool operator!=( const QskShadowMetrics& ) const noexcept;
47
48 bool isNull() const noexcept;
49
50 void setSpreadRadius( qreal ) noexcept;
51 constexpr qreal spreadRadius() const noexcept;
52
53 void setBlurRadius( qreal ) noexcept;
54 constexpr qreal blurRadius() const noexcept;
55
56 constexpr qreal totalRadius() const noexcept;
57
58 void setOffsetX( qreal dx ) noexcept;
59 void setOffsetY( qreal dy ) noexcept;
60
61 void setOffset( qreal dx, qreal dy ) noexcept;
62 void setOffset( const QPointF& ) noexcept;
63
64 constexpr QPointF offset() const noexcept;
65
66 void setSizeMode( Qt::SizeMode ) noexcept;
67 constexpr Qt::SizeMode sizeMode() const noexcept;
68
69 void setShapeMode( ShapeMode ) noexcept;
70 constexpr ShapeMode shapeMode() const noexcept;
71
72 QskShadowMetrics interpolated(
73 const QskShadowMetrics&, qreal value ) const noexcept;
74
75 QskShadowMetrics toAbsolute( const QSizeF& ) const noexcept;
76
77 QRectF shadowRect( const QRectF& sourceRect ) const;
78
79 QskHashValue hash( QskHashValue seed = 0 ) const noexcept;
80
81 static QVariant interpolate( const QskShadowMetrics&,
82 const QskShadowMetrics&, qreal progress );
83
84 private:
85 QPointF m_offset;
86 qreal m_spreadRadius = 0.0;
87 qreal m_blurRadius = 0.0;
88 quint8 m_sizeMode = Qt::AbsoluteSize;
89 quint8 m_shapeMode = QskShadowMetrics::Aligned;
90};
91
92inline constexpr QskShadowMetrics::QskShadowMetrics( const QPointF& offset ) noexcept
93 : m_offset( offset )
94{
95}
96
97inline constexpr QskShadowMetrics::QskShadowMetrics(
98 qreal spreadRadius, qreal blurRadius ) noexcept
99 : m_spreadRadius( spreadRadius )
100 , m_blurRadius( blurRadius )
101{
102}
103
104inline constexpr QskShadowMetrics::QskShadowMetrics(
105 qreal spreadRadius, qreal blurRadius,
106 const QPointF& offset, Qt::SizeMode sizeMode ) noexcept
107 : m_offset( offset )
108 , m_spreadRadius( spreadRadius )
109 , m_blurRadius( blurRadius )
110 , m_sizeMode( sizeMode )
111{
112}
113
114inline constexpr bool QskShadowMetrics::operator==(
115 const QskShadowMetrics& other ) const noexcept
116{
117 return ( m_sizeMode == other.m_sizeMode )
118 && ( m_shapeMode == other.m_shapeMode )
119 && ( m_offset == other.m_offset )
120 && ( m_spreadRadius == other.m_spreadRadius )
121 && ( m_blurRadius == other.m_blurRadius )
122 && ( m_sizeMode == other.m_sizeMode );
123}
124
125inline constexpr bool QskShadowMetrics::operator!=(
126 const QskShadowMetrics& other ) const noexcept
127{
128 return !( *this == other );
129}
130
131inline void QskShadowMetrics::setSpreadRadius( qreal radius ) noexcept
132{
133 m_spreadRadius = radius;
134}
135
136inline constexpr qreal QskShadowMetrics::spreadRadius() const noexcept
137{
138 return m_spreadRadius;
139}
140
141inline void QskShadowMetrics::setBlurRadius( qreal radius ) noexcept
142{
143 m_blurRadius = radius;
144}
145
146inline constexpr qreal QskShadowMetrics::blurRadius() const noexcept
147{
148 return m_blurRadius;
149}
150
151inline constexpr qreal QskShadowMetrics::totalRadius() const noexcept
152{
153 return m_spreadRadius + m_blurRadius;
154}
155
156inline void QskShadowMetrics::setSizeMode( Qt::SizeMode sizeMode ) noexcept
157{
158 m_sizeMode = sizeMode;
159}
160
161inline constexpr Qt::SizeMode QskShadowMetrics::sizeMode() const noexcept
162{
163 return static_cast< Qt::SizeMode >( m_sizeMode );
164}
165
166inline void QskShadowMetrics::setShapeMode( ShapeMode shapeMode ) noexcept
167{
168 m_shapeMode = shapeMode;
169}
170
171inline constexpr QskShadowMetrics::ShapeMode QskShadowMetrics::shapeMode() const noexcept
172{
173 return static_cast< ShapeMode >( m_shapeMode );
174}
175
176inline void QskShadowMetrics::setOffsetX( qreal dx ) noexcept
177{
178 m_offset.rx() = dx;
179}
180
181inline void QskShadowMetrics::setOffsetY( qreal dy ) noexcept
182{
183 m_offset.ry() = dy;
184}
185
186inline void QskShadowMetrics::setOffset( qreal dx, qreal dy ) noexcept
187{
188 m_offset.rx() = dx;
189 m_offset.ry() = dy;
190}
191
192inline void QskShadowMetrics::setOffset( const QPointF& offset ) noexcept
193{
194 m_offset = offset;
195}
196
197inline constexpr QPointF QskShadowMetrics::offset() const noexcept
198{
199 return m_offset;
200}
201
202inline bool QskShadowMetrics::isNull() const noexcept
203{
204 return m_offset.isNull() &&
205 ( m_spreadRadius == 0.0 ) && ( m_blurRadius == 0.0 );
206}
207
208#ifndef QT_NO_DEBUG_STREAM
209
210QSK_EXPORT QDebug operator<<( QDebug, const QskShadowMetrics& );
211
212#endif
213
214Q_DECLARE_TYPEINFO( QskShadowMetrics, Q_MOVABLE_TYPE );
215Q_DECLARE_METATYPE( QskShadowMetrics )
216
217#endif