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
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
179 bool setFlagHint( QskAspect, int flag );
180 template< typename T > T flagHint( QskAspect, T = T() ) const;
181
182 bool setPositionHint( QskAspect, qreal );
183 bool movePositionHint( QskAspect, qreal );
184 bool movePositionHint( QskAspect, qreal from, qreal to );
185 bool resetPositionHint( QskAspect );
186 qreal positionHint( QskAspect, QskSkinHintStatus* = nullptr ) const;
187
188 bool setStrutSizeHint( QskAspect, const QSizeF& );
189 bool setStrutSizeHint( QskAspect, qreal width, qreal height );
190 bool resetStrutSizeHint( QskAspect );
191 QSizeF strutSizeHint( QskAspect, QskSkinHintStatus* = nullptr ) const;
192
193 bool setMarginHint( QskAspect, qreal );
194 bool setMarginHint( QskAspect, const QMarginsF& );
195 bool resetMarginHint( QskAspect );
196 QMarginsF marginHint( QskAspect, QskSkinHintStatus* = nullptr ) const;
197
198 bool setPaddingHint( QskAspect, qreal );
199 bool setPaddingHint( QskAspect, const QMarginsF& );
200 bool resetPaddingHint( QskAspect );
201 QMarginsF paddingHint( QskAspect, QskSkinHintStatus* = nullptr ) const;
202
203 bool setGradientHint( QskAspect, const QskGradient& );
204 QskGradient gradientHint( QskAspect, QskSkinHintStatus* = nullptr ) const;
205
206 bool setBoxShapeHint( QskAspect, const QskBoxShapeMetrics& );
207 bool resetBoxShapeHint( QskAspect );
208 QskBoxShapeMetrics boxShapeHint( QskAspect, QskSkinHintStatus* = nullptr ) const;
209
210 bool setBoxBorderMetricsHint( QskAspect, const QskBoxBorderMetrics& );
211 bool resetBoxBorderMetricsHint( QskAspect );
212 QskBoxBorderMetrics boxBorderMetricsHint(
213 QskAspect, QskSkinHintStatus* = nullptr ) const;
214
215 bool setBoxBorderColorsHint( QskAspect, const QskBoxBorderColors& );
216 bool resetBoxBorderColorsHint( QskAspect );
217 QskBoxBorderColors boxBorderColorsHint( QskAspect, QskSkinHintStatus* = nullptr ) const;
218
219 bool setShadowMetricsHint( QskAspect, const QskShadowMetrics& );
220 bool resetShadowMetricsHint( QskAspect );
221 QskShadowMetrics shadowMetricsHint( QskAspect, QskSkinHintStatus* = nullptr ) const;
222
223 bool setShadowColorHint( QskAspect, const QColor& );
224 bool resetShadowColorHint( QskAspect );
225 QColor shadowColorHint( QskAspect, QskSkinHintStatus* = nullptr ) const;
226
227 QskBoxHints boxHints( QskAspect ) const;
228
229 bool setArcMetricsHint( QskAspect, const QskArcMetrics& );
230 bool resetArcMetricsHint( QskAspect );
231 QskArcMetrics arcMetricsHint( QskAspect, QskSkinHintStatus* = nullptr ) const;
232
233 bool setStippleMetricsHint( QskAspect, const QskStippleMetrics& );
234 bool resetStippleMetricsHint( QskAspect );
235 QskStippleMetrics stippleMetricsHint( QskAspect, QskSkinHintStatus* = nullptr ) const;
236
237 bool setSpacingHint( QskAspect, qreal );
238 bool resetSpacingHint( QskAspect );
239 qreal spacingHint( QskAspect, QskSkinHintStatus* = nullptr ) const;
240
241 bool setAlignmentHint( QskAspect, Qt::Alignment );
242 bool resetAlignmentHint( QskAspect );
243 Qt::Alignment alignmentHint( QskAspect, Qt::Alignment = Qt::Alignment() ) const;
244
245 bool setTextOptionsHint( QskAspect, const QskTextOptions& );
246 bool resetTextOptionsHint( QskAspect );
247 QskTextOptions textOptionsHint( QskAspect, QskSkinHintStatus* = nullptr ) const;
248
249 bool setFontRoleHint( QskAspect, const QskFontRole& );
250 bool resetFontRoleHint( QskAspect );
251 QskFontRole fontRoleHint( QskAspect, QskSkinHintStatus* = nullptr ) const;
252
253 bool setGraphicRoleHint( QskAspect, int role );
254 bool resetGraphicRoleHint( QskAspect );
255 int graphicRoleHint( QskAspect, QskSkinHintStatus* = nullptr ) const;
256
257 bool setSymbolHint( const QskAspect, const QskGraphic& );
258 bool resetSymbolHint( const QskAspect );
259 QskGraphic symbolHint( const QskAspect, QskSkinHintStatus* = nullptr ) const;
260
261 const QskSkinHintTable& hintTable() const;
262
263 bool startHintTransitions( QskAspect::States, QskAspect::States, int index = -1 );
264 bool startHintTransitions( const QVector< QskAspect::Subcontrol >&,
265 QskAspect::States, QskAspect::States, int index = -1 );
266
267 const QskHintAnimator* runningHintAnimator( QskAspect, int index = -1 ) const;
268
269 protected:
270 virtual void updateNode( QSGNode* );
271 virtual bool isTransitionAccepted( QskAspect ) const;
272
273 virtual QskAspect::Subcontrol substitutedSubcontrol( QskAspect::Subcontrol ) const;
274
275 QskSkinHintTable& hintTable();
276
277 private:
278 Q_DISABLE_COPY( QskSkinnable )
279
280 void startHintTransition( QskAspect, int index,
281 QskAnimationHint, const QVariant& from, const QVariant& to );
282
283 QVariant animatedHint( QskAspect, QskSkinHintStatus* ) const;
284 QVariant interpolatedHint( QskAspect, QskSkinHintStatus* ) const;
285 const QVariant& storedHint( QskAspect, QskSkinHintStatus* = nullptr ) const;
286
287 friend class QskSkinStateChanger;
288 void replaceSkinStates( QskAspect::States, int sampleIndex = -1 );
289
290 class PrivateData;
291 std::unique_ptr< PrivateData > m_data;
292};
293
294template< typename T >
295inline T QskSkinnable::flagHint( QskAspect aspect, T defaultValue ) const
296{
297 const auto& hint = effectiveSkinHint( aspect );
298 if ( hint.isValid() && hint.canConvert< int >() )
299 return static_cast< T >( hint.value< int >() );
300
301 return defaultValue;
302}
303
304inline Qt::Alignment QskSkinnable::alignmentHint(
305 QskAspect aspect, Qt::Alignment defaultAlignment ) const
306{
307 return flagHint< Qt::Alignment >( aspect | QskAspect::Alignment, defaultAlignment );
308}
309
311{
312 return resetSkinHint( aspect | QskAspect::Color );
313}
314
316{
317 return resetSkinHint( aspect | QskAspect::Metric );
318}
319
320#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.