QSkinny 0.8.0
C++/Qt UI toolkit
Loading...
Searching...
No Matches
QskSkinnable.h
1/******************************************************************************
2 * QSkinny - Copyright (C) The authors
3 * SPDX-License-Identifier: BSD-3-Clause
4 *****************************************************************************/
5
6#ifndef QSK_SKINNABLE_H
7#define QSK_SKINNABLE_H
8
9#include "QskAspect.h"
10#include <memory>
11
12typedef unsigned int QRgb;
13class QSizeF;
14class QRectF;
15class QColor;
16class QFont;
17class QMarginsF;
18struct QMetaObject;
19class QVariant;
20class QDebug;
21
22class QSGNode;
23class QQuickItem;
24
25class QskArcMetrics;
26class QskControl;
28class QskHintAnimator;
29class QskColorFilter;
35class QskTextOptions;
36class QskBoxHints;
37class QskGradient;
38class QskGraphic;
39class QskFontRole;
40
41class QskSkin;
42class QskSkinlet;
45
46class QSK_EXPORT QskSkinHintStatus
47{
48 public:
49 enum Source : quint8
50 {
51 NoSource = 0,
52
55 Animator
56 };
57
59 : source( NoSource )
60 {
61 }
62
63 inline bool isValid() const
64 {
65 return source > 0;
66 }
67
70};
71
72#ifndef QT_NO_DEBUG_STREAM
73
74class QDebug;
75QSK_EXPORT QDebug operator<<( QDebug, const QskSkinHintStatus& );
76
77#endif
78
79class QSK_EXPORT QskSkinnable
80{
81 public:
83 virtual ~QskSkinnable();
84
85 void setSkinlet( const QskSkinlet* );
86 const QskSkinlet* skinlet() const;
87
88 QFont effectiveFont( QskAspect ) const;
89 qreal effectiveFontHeight( QskAspect ) const;
90 QskColorFilter effectiveGraphicFilter( QskAspect::Subcontrol ) const;
91
92 void setSubcontrolProxy( QskAspect::Subcontrol, QskAspect::Subcontrol proxy );
93 void resetSubcontrolProxy( QskAspect::Subcontrol );
94 QskAspect::Subcontrol subcontrolProxy( QskAspect::Subcontrol ) const;
95
96 bool setAnimationHint( QskAspect, QskAnimationHint );
97 QskAnimationHint animationHint( QskAspect, QskSkinHintStatus* = nullptr ) const;
98 bool hasAnimationHint( QskAspect ) const;
99
100 bool setSkinHint( QskAspect, const QVariant& );
101 bool resetSkinHint( QskAspect );
102
103 bool moveSkinHint( QskAspect, const QVariant& );
104 bool moveSkinHint( QskAspect, const QVariant&, const QVariant& );
105
107 QskAspect::States, QskSkinHintStatus* status = nullptr ) const;
108
109 QVariant effectiveSkinHint( QskAspect, QskSkinHintStatus* = nullptr ) const;
110 virtual QskAspect::Variation effectiveVariation() const;
111
112 virtual QskAspect::Section section() const;
113
114 QskSkinHintStatus hintStatus( QskAspect ) const;
115
116 QRectF subControlRect( const QRectF&, QskAspect::Subcontrol ) const;
117 QRectF subControlContentsRect( const QRectF&, QskAspect::Subcontrol ) const;
118
119 QSizeF outerBoxSize( QskAspect, const QSizeF& innerBoxSize ) const;
120 QSizeF innerBoxSize( QskAspect, const QSizeF& outerBoxSize ) const;
121
122 QRectF innerBox( QskAspect, const QRectF& outerBox ) const;
123 QRectF outerBox( QskAspect, const QRectF& innerBox ) const;
124
125 QMarginsF innerPadding( QskAspect, const QSizeF& ) const;
126
127 const QskSkinlet* effectiveSkinlet() const;
128 QskSkin* effectiveSkin() const;
129
130 void startTransition( QskAspect,
131 QskAnimationHint, const QVariant& from, const QVariant& to );
132
133 void startTransition( QskAspect, int index,
134 QskAnimationHint, const QVariant& from, const QVariant& to );
135
136 QskAspect::Subcontrol effectiveSubcontrol( QskAspect::Subcontrol ) const;
137
138 QskControl* controlCast();
139 const QskControl* controlCast() const;
140
141 virtual QQuickItem* owningItem() const = 0;
142 virtual const QMetaObject* metaObject() const = 0;
143
144 void debug( QskAspect ) const;
145 void debug( QskAspect::State ) const;
146 void debug( QDebug, QskAspect ) const;
147 void debug( QDebug, QskAspect::State ) const;
148
149 void setSkinStates( QskAspect::States );
150 void setSkinStateFlag( QskAspect::State, bool on = true );
151
152 void addSkinStates( QskAspect::States );
153 void clearSkinStates( QskAspect::States );
154
155 bool hasSkinState( QskAspect::State ) const;
156 QskAspect::States skinStates() const;
157
158 const char* skinStatesAsPrintable() const;
159 const char* skinStatesAsPrintable( QskAspect::States ) const;
160
161 // type aware methods for accessing skin hints
162
163 bool setColor( QskAspect, Qt::GlobalColor );
164 bool setColor( QskAspect, QRgb );
165 bool setColor( QskAspect, const QColor& );
166
167 bool moveColor( QskAspect, Qt::GlobalColor );
168 bool moveColor( QskAspect, QRgb );
169 bool moveColor( QskAspect, const QColor& );
170
171 bool resetColor( QskAspect );
172 QColor color( QskAspect, QskSkinHintStatus* = nullptr ) const;
173
174 bool setMetric( QskAspect, qreal );
175 bool moveMetric( QskAspect, qreal );
176 bool resetMetric( QskAspect );
177 qreal metric( QskAspect, QskSkinHintStatus* = nullptr ) const;
178 qreal metric( QskAspect, qreal defaultValue ) const;
179
180 bool setFlagHint( QskAspect, int flag );
181 template< typename T > T flagHint( QskAspect, T = T() ) const;
182
183 bool setPositionHint( QskAspect, qreal );
184 bool movePositionHint( QskAspect, qreal );
185 bool movePositionHint( QskAspect, qreal from, qreal to );
186 bool resetPositionHint( QskAspect );
187 qreal positionHint( QskAspect, QskSkinHintStatus* = nullptr ) const;
188
189 bool setStrutSizeHint( QskAspect, const QSizeF& );
190 bool setStrutSizeHint( QskAspect, qreal width, qreal height );
191 bool resetStrutSizeHint( QskAspect );
192 QSizeF strutSizeHint( QskAspect, QskSkinHintStatus* = nullptr ) const;
193
194 bool setMarginHint( QskAspect, qreal );
195 bool setMarginHint( QskAspect, const QMarginsF& );
196 bool resetMarginHint( QskAspect );
197 QMarginsF marginHint( QskAspect, QskSkinHintStatus* = nullptr ) const;
198
199 bool setPaddingHint( QskAspect, qreal );
200 bool setPaddingHint( QskAspect, const QMarginsF& );
201 bool resetPaddingHint( QskAspect );
202 QMarginsF paddingHint( QskAspect, QskSkinHintStatus* = nullptr ) const;
203
204 bool setGradientHint( QskAspect, const QskGradient& );
205 QskGradient gradientHint( QskAspect, QskSkinHintStatus* = nullptr ) const;
206
207 bool setBoxShapeHint( QskAspect, const QskBoxShapeMetrics& );
208 bool resetBoxShapeHint( QskAspect );
209 QskBoxShapeMetrics boxShapeHint( QskAspect, QskSkinHintStatus* = nullptr ) const;
210
211 bool setBoxBorderMetricsHint( QskAspect, const QskBoxBorderMetrics& );
212 bool resetBoxBorderMetricsHint( QskAspect );
213 QskBoxBorderMetrics boxBorderMetricsHint(
214 QskAspect, QskSkinHintStatus* = nullptr ) const;
215
216 bool setBoxBorderColorsHint( QskAspect, const QskBoxBorderColors& );
217 bool resetBoxBorderColorsHint( QskAspect );
218 QskBoxBorderColors boxBorderColorsHint( QskAspect, QskSkinHintStatus* = nullptr ) const;
219
220 bool setShadowMetricsHint( QskAspect, const QskShadowMetrics& );
221 bool resetShadowMetricsHint( QskAspect );
222 QskShadowMetrics shadowMetricsHint( QskAspect, QskSkinHintStatus* = nullptr ) const;
223
224 bool setShadowColorHint( QskAspect, const QColor& );
225 bool resetShadowColorHint( QskAspect );
226 QColor shadowColorHint( QskAspect, QskSkinHintStatus* = nullptr ) const;
227
228 QskBoxHints boxHints( QskAspect ) const;
229
230 bool setArcMetricsHint( QskAspect, const QskArcMetrics& );
231 bool resetArcMetricsHint( QskAspect );
232 QskArcMetrics arcMetricsHint( QskAspect, QskSkinHintStatus* = nullptr ) const;
233
234 bool setStippleMetricsHint( QskAspect, const QskStippleMetrics& );
235 bool resetStippleMetricsHint( QskAspect );
236 QskStippleMetrics stippleMetricsHint( QskAspect, QskSkinHintStatus* = nullptr ) const;
237
238 bool setSpacingHint( QskAspect, qreal );
239 bool resetSpacingHint( QskAspect );
240 qreal spacingHint( QskAspect, QskSkinHintStatus* = nullptr ) const;
241
242 bool setAlignmentHint( QskAspect, Qt::Alignment );
243 bool resetAlignmentHint( QskAspect );
244 Qt::Alignment alignmentHint( QskAspect, Qt::Alignment = Qt::Alignment() ) const;
245
246 bool setTextOptionsHint( QskAspect, const QskTextOptions& );
247 bool resetTextOptionsHint( QskAspect );
248 QskTextOptions textOptionsHint( QskAspect, QskSkinHintStatus* = nullptr ) const;
249
250 bool setFontRoleHint( QskAspect, const QskFontRole& );
251 bool resetFontRoleHint( QskAspect );
252 QskFontRole fontRoleHint( QskAspect, QskSkinHintStatus* = nullptr ) const;
253
254 bool setGraphicRoleHint( QskAspect, int role );
255 bool resetGraphicRoleHint( QskAspect );
256 int graphicRoleHint( QskAspect, QskSkinHintStatus* = nullptr ) const;
257
258 bool setSymbolHint( const QskAspect, const QskGraphic& );
259 bool resetSymbolHint( const QskAspect );
260 QskGraphic symbolHint( const QskAspect, QskSkinHintStatus* = nullptr ) const;
261
262 const QskSkinHintTable& hintTable() const;
263
264 bool startHintTransitions( QskAspect::States, QskAspect::States, int index = -1 );
265 bool startHintTransitions( const QVector< QskAspect::Subcontrol >&,
266 QskAspect::States, QskAspect::States, int index = -1 );
267
268 const QskHintAnimator* runningHintAnimator( QskAspect, int index = -1 ) const;
269
270 protected:
271 virtual void updateNode( QSGNode* );
272 virtual bool isTransitionAccepted( QskAspect ) const;
273
274 virtual QskAspect::Subcontrol substitutedSubcontrol( QskAspect::Subcontrol ) const;
275
276 QskSkinHintTable& hintTable();
277
278 private:
279 Q_DISABLE_COPY( QskSkinnable )
280
281 void startHintTransition( QskAspect, int index,
282 QskAnimationHint, const QVariant& from, const QVariant& to );
283
284 QVariant animatedHint( QskAspect, QskSkinHintStatus* ) const;
285 QVariant interpolatedHint( QskAspect, QskSkinHintStatus* ) const;
286 const QVariant& storedHint( QskAspect, QskSkinHintStatus* = nullptr ) const;
287
288 friend class QskSkinStateChanger;
289 void replaceSkinStates( QskAspect::States, int sampleIndex = -1 );
290
291 class PrivateData;
292 std::unique_ptr< PrivateData > m_data;
293};
294
295template< typename T >
296inline T QskSkinnable::flagHint( QskAspect aspect, T defaultValue ) const
297{
298 const auto& hint = effectiveSkinHint( aspect );
299 if ( hint.isValid() && hint.canConvert< int >() )
300 return static_cast< T >( hint.value< int >() );
301
302 return defaultValue;
303}
304
305inline Qt::Alignment QskSkinnable::alignmentHint(
306 QskAspect aspect, Qt::Alignment defaultAlignment ) const
307{
308 return flagHint< Qt::Alignment >( aspect | QskAspect::Alignment, defaultAlignment );
309}
310
312{
313 return resetSkinHint( aspect | QskAspect::Color );
314}
315
317{
318 return resetSkinHint( aspect | QskAspect::Metric );
319}
320
321#endif
Lookup key for a QskSkinHintTable.
Definition QskAspect.h:15
Variation
Some sort of variation.
Definition QskAspect.h:82
Type
Represents the type of the Aspect.
Definition QskAspect.h:21
Subcontrol
For use within the rendering or lay-outing of a specific QskSkinnable.
Definition QskAspect.h:104
Base class of all controls.
Definition QskControl.h:23
A paint device for scalable graphics.
Definition QskGraphic.h:28
bool isValid() const
Describes the rendering interface of a QskControl. Change the skinlet to change the appearance of the...
Definition QskSkinlet.h:34
QVariant effectiveSkinHint(QskAspect, QskSkinHintStatus *=nullptr) const
Find the value for a specific aspect.
bool resetColor(QskAspect)
Removes a color hint from the local table.
bool resetSkinHint(QskAspect)
Remove a hint from the local hint table.
virtual const QMetaObject * metaObject() const =0
T flagHint(QskAspect, T=T()) const
Retrieves a flag hint.
Qt::Alignment alignmentHint(QskAspect, Qt::Alignment=Qt::Alignment()) const
Retrieves an alignment hint.
bool resetMetric(QskAspect)
Removes a metric hint from the local table.