Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qqstylekitcontrolproperties.cpp
Go to the documentation of this file.
1// Copyright (C) 2025 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
8
10
11// ************* ControlStyleProperties ****************
12
13/*!
14 \qmltype ControlStyleProperties
15 \nativetype QQStyleKitControlProperties
16 \inqmlmodule Qt.labs.StyleKit
17 \brief Defines the stylable properties for a control.
18
19 ControlStyleProperties defines the stylable properties for a
20 control: the visual building blocks \l background, \l indicator, \l handle,
21 and \l text, as well as layout properties like \l padding, \l spacing,
22 and \l transition.
23
24 The style properties are accessed through inherited types such as
25 \l ControlStyle and \l StyleReader.
26
27 \labs
28
29 \sa ControlStyle, StyleReader, ControlStateStyle, DelegateStyle
30*/
31
32/*!
33 \qmlproperty DelegateStyle ControlStyleProperties::background
34
35 Grouped property for styling the background of a control.
36
37 The background delegate is typically the main visual rectangle behind
38 the control. Use it to set \l {DelegateStyle::color}{colors},
39 \l {DelegateStyle::border}{borders},
40 \l {DelegateStyle::radius}{radii},
41 \l {DelegateStyle::shadow}{shadows},
42 \l {DelegateStyle::gradient}{gradients},
43 and \l {DelegateStyle::image}{images}.
44
45 \note The default \l {Style.fallbackStyle}{fallback style} sets \c {background.visible}
46 to \c false for controls that typically should not draw a background,
47 such as \l [QtQuickControls]{CheckBox}, \l [QtQuickControls]{RadioButton},
48 and \l [QtQuickControls]{Slider}. To show their background, set
49 \c {background.visible} to \c true explicitly.
50*/
51
52/*!
53 \qmlproperty real ControlStyleProperties::bottomPadding
54
55 The \l [QtQuickControls]{Control Layout}{bottom padding}
56 of the control. If not set, falls back to \l padding.
57
58 \sa padding, topPadding, leftPadding, rightPadding
59*/
60
61/*!
62 \qmlproperty HandleStyle ControlStyleProperties::handle
63
64 Grouped property for styling the handle of a control.
65
66 The handle is used by controls such as \l [QtQuickControls]{Switch},
67 \l [QtQuickControls]{Slider}, and \l [QtQuickControls]{RangeSlider}.
68 For a RangeSlider, the two handles can be styled individually through
69 \l {HandleStyle.first}{handle.first} and \l {HandleStyle.second}{handle.second}.
70
71 \sa HandleStyle, DelegateStyle
72*/
73
74/*!
75 \qmlproperty IndicatorStyle ControlStyleProperties::indicator
76
77 Grouped property for styling the indicator of a control. For a
78 \l {StylableControls::}{checkBox}, the indicator is the
79 frame, and its \l {IndicatorStyle::}{foreground} is the check mark.
80 For a \l {StylableControls::}{slider}, the indicator is
81 the groove, and the foreground is the fill.
82
83 \sa DelegateStyle
84*/
85
86/*!
87 \qmlproperty real ControlStyleProperties::leftPadding
88
89 The \l [QtQuickControls]{Control Layout}{left padding} of the control. If not set, falls back to
90 \l padding.
91
92 \sa padding, rightPadding, topPadding, bottomPadding
93*/
94
95/*!
96 \qmlproperty real ControlStyleProperties::padding
97
98 The uniform spacing between the
99 \l [QtQuickControls]{Control Layout}{control's content area and the
100 bounds of the control}. Setting this provides a default value for
101 \l leftPadding, \l rightPadding, \l topPadding, and \l bottomPadding.
102 Each side can be overridden individually.
103
104 \sa leftPadding, rightPadding, topPadding, bottomPadding
105*/
106
107/*!
108 \qmlproperty real ControlStyleProperties::rightPadding
109
110 The \l [QtQuickControls]{Control Layout}{right padding} of the control.
111 If not set, falls back to \l padding.
112
113 \sa padding, leftPadding, topPadding, bottomPadding
114*/
115
116/*!
117 \qmlproperty real ControlStyleProperties::spacing
118
119 The spacing between visual elements inside the control, for example
120 between an indicator and a label.
121*/
122
123/*!
124 \qmlproperty TextStyle ControlStyleProperties::text
125
126 Grouped property for styling the text label of a control.
127*/
128
129/*!
130 \qmlproperty real ControlStyleProperties::topPadding
131
132 The \l [QtQuickControls]{Control Layout}{top padding}
133 of the control. If not set, falls back to \l padding.
134
135 \sa padding, bottomPadding, leftPadding, rightPadding
136*/
137
138/*!
139 \qmlproperty Transition ControlStyleProperties::transition
140
141 A \l [QtQuick]{Transition} used to animate style properties when the
142 control enters a new state, such as \l {ControlStateStyle::}{hovered}
143 or \l {ControlStateStyle::}{pressed}. If set
144 to \c null (the default), property changes are applied immediately
145 without animation.
146
147 \snippet DelegateStyle_transitions.qml custom transition
148
149 To avoid repeating the same target properties for each delegate,
150 StyleKit provides \l StyleAnimation for convenience, which can be
151 used instead of, or in combination with, the
152 \l {Animation and Transitions in Qt Quick}{standard animations:}
153
154 \snippet DelegateStyle_transitions.qml transition
155
156 \note For color properties that participate in a transition, prefer
157 \l {Qt.alpha} over \c "transparent"
158 (e.g. \c {menuBarItem.background.color: Qt.alpha(palette.accent, 0)}).
159 \c "transparent" is \c {Qt.rgba(0, 0, 0, 0)}, which can pull interpolated
160 colors toward black during the transition.
161*/
162
163// ************* DelegateStyle ****************
164
165/*!
166 \qmltype DelegateStyle
167 \nativetype QQStyleKitDelegateProperties
168 \inqmlmodule Qt.labs.StyleKit
169 \brief Defines the visual appearance of an element within a control.
170
171 DelegateStyle describes the visual appearance of a visual element
172 within a \l ControlStyle, such as its \l {ControlStyleProperties::}{background},
173 \l {ControlStyleProperties::}{indicator}, or a sub-element like
174 \l {IndicatorStyle::foreground}{indicator.foreground}.
175 It provides properties for controlling
176 \l {DelegateStyle::width}{size},
177 \l {DelegateStyle::}{color}, \l {DelegateStyle::}{border},
178 \l {DelegateStyle::}{radius}, \l {DelegateStyle::}{shadow},
179 \l {DelegateStyle::}{image}, \l {DelegateStyle::}{opacity}, and more.
180
181 \labs
182
183 \sa ControlStyle, ControlStateStyle,
184 {qtlabsstylekit-fallbackstyle.html}{FallbackStyle Reference}
185*/
186
187/*!
188 \qmlproperty Qt::Alignment DelegateStyle::alignment
189
190 The alignment of the delegate within its parent. The default
191 value is \c {Qt.AlignLeft | Qt.AlignVCenter}.
192*/
193
194/*!
195 \qmlproperty BorderStyle DelegateStyle::border
196
197 Grouped property for styling the border of this delegate.
198*/
199
200/*!
201 \qmlproperty real DelegateStyle::bottomLeftRadius
202
203 The bottom-left corner radius. If not set, falls back to \l radius.
204
205 \sa radius, topLeftRadius, topRightRadius, bottomRightRadius
206*/
207
208/*!
209 \qmlproperty real DelegateStyle::bottomMargin
210
211 The bottom margin of this delegate. If not set, falls back to
212 \l margins.
213
214 \sa margins, topMargin, leftMargin, rightMargin
215*/
216
217/*!
218 \qmlproperty real DelegateStyle::bottomRightRadius
219
220 The bottom-right corner radius. If not set, falls back to \l radius.
221
222 \sa radius, topLeftRadius, topRightRadius, bottomLeftRadius
223*/
224
225/*!
226 \qmlproperty bool DelegateStyle::clip
227
228 Whether the delegate clips its contents. The default value is \c false.
229*/
230
231/*!
232 \qmlproperty color DelegateStyle::color
233
234 The fill color of this delegate. The default value is \c transparent.
235
236 Unlike a Quick \l [QtQuick]{Rectangle}, where a gradient replaces
237 the color, StyleKit draws the \l gradient on top of the color. This
238 means you can use a semi-transparent gradient as an overlay (for
239 example, a subtle shading effect) while the color shows through
240 underneath.
241
242 \snippet ControlStateStyle_properties.qml color and gradient
243
244 \sa gradient, opacity
245*/
246
247/*!
248 \qmlproperty QObject DelegateStyle::data
249
250 An arbitrary object that can be used for passing
251 custom data from the style to a custom \l delegate component.
252
253 This allows you to define custom style properties beyond what the
254 StyleKit API provides. The data object can vary between states and
255 themes, making it possible to style elements in a custom \l delegate
256 that are not covered by the built-in properties.
257
258 The following snippet uses a custom delegate that draws an overlay
259 \l Text whose color varies depending on the control's state. The delegate
260 inherits \l StyledItem, which is optional but ensures the rest of
261 the button background is rendered normally.
262
263 \snippet DelegateStyle_delegates.qml data
264
265 \note The \c data object is propagated as a whole. Unlike regular style
266 properties, individual properties \e inside the data object do not
267 propagate separately.
268
269 \sa delegate
270*/
271
272/*!
273 \qmlproperty Component DelegateStyle::delegate
274
275 The delegate used to render the DelegateStyle in a
276 \l {Qt Quick Controls}{Qt Quick Control}.
277
278 The default value is \c null, in which case \l StyledItem is used
279 for rendering instead. If you want to hide the delegate altogether
280 (and prevent if from being created), set \l visible to \c false.
281
282 The delegate needs to define the following required properties:
283 \qml
284 required property DelegateStyle delegateStyle
285 required property QtObject control
286 \endqml
287
288 \c delegateStyle points to the DelegateStyle that describes how the
289 delegate should be styled. \c control points to the
290 \l {Qt Quick Controls}{Qt Quick Control} that owns the delegate. The latter
291 can be used to resolve additional information about the control not
292 available from the style.
293
294 If you know the specific type of the owning control, you can use it
295 instead of \l QtObject for the \c control property. For example, since
296 a handle delegate in the snippet below is always used inside a Slider, the
297 type can be set to \l {Qt Quick Templates 2 QML Types}{T.Slider}:
298
299 \snippet DelegateStyle_delegates.qml delegate
300
301 \note If a DelegateStyle has a \l {shadow}{drop shadow} defined, it will be
302 drawn separately by a \l {ShadowStyle::delegate}{shadow delegate.}
303
304 \sa data, visible, StyledItem
305*/
306
307/*!
308 \qmlproperty Gradient DelegateStyle::gradient
309
310 The gradient of this delegate. The default value is \c null (no gradient).
311
312 Unlike a Quick \l [QtQuick]{Rectangle}, where a gradient replaces
313 the color, StyleKit draws the \l gradient on top of the color. This
314 means you can use a semi-transparent gradient as an overlay (for
315 example, a subtle shading effect) while the color shows through
316 underneath.
317
318 \snippet ControlStateStyle_properties.qml color and gradient
319
320 \sa color
321*/
322
323/*!
324 \qmlproperty ImageStyle DelegateStyle::image
325
326 Grouped property for placing an image inside this delegate.
327
328 \sa ImageStyle
329*/
330
331/*!
332 \qmlproperty real DelegateStyle::width
333
334 The width of this delegate.
335
336 \note This property will only set the delegate width when \l fillWidth is \c false. This also
337 applies when \l fillWidth is set higher up in the style hierarchy, for example
338 in the \l {Style::fallbackStyle}{fallback style}.
339
340 If this delegate is at the root of the control — for example the
341 \l {ControlStyleProperties::background}{background} or the
342 \l {ControlStyleProperties::indicator}{indicator} — it will also be included when
343 calculating the \l [QtQuick]{Item::implicitWidth}{implicit width} of the control, even when \l fillWidth is \c true.
344
345 \sa height, fillWidth, minimumWidth, {StyleKit Property Resolution}
346*/
347
348/*!
349 \qmlproperty real DelegateStyle::height
350
351 The height of this delegate.
352
353 \note This property will only set the delegate height when \l fillHeight is \c false. This also
354 applies when \l fillHeight is set higher up in the style hierarchy, for example
355 in the \l {Style::fallbackStyle}{fallback style}.
356
357 If this delegate is at the root of the control — for example the
358 \l {ControlStyleProperties::background}{background} or the
359 \l {ControlStyleProperties::indicator}{indicator} — it will also be included when
360 calculating the \l [QtQuick]{Item::implicitHeight}{implicit height} of the control, even when \l fillHeight is \c true.
361
362 \sa width, fillHeight, minimumHeight, {StyleKit Property Resolution}
363*/
364
365/*!
366 \qmlproperty real DelegateStyle::leftMargin
367
368 The left margin of this delegate. If not set, falls back to
369 \l margins.
370
371 \sa margins, rightMargin, topMargin, bottomMargin
372*/
373
374/*!
375 \qmlproperty real DelegateStyle::margins
376
377 The uniform margin around this delegate. Setting this provides a
378 default value for \l leftMargin, \l rightMargin, \l topMargin,
379 and \l bottomMargin. Each side can be overridden individually.
380
381 \sa leftMargin, rightMargin, topMargin, bottomMargin
382*/
383
384/*!
385 \qmlproperty real DelegateStyle::minimumWidth
386
387 The minimum width of this delegate. The delegate will not be sized
388 smaller than this value.
389*/
390
391/*!
392 \qmlproperty real DelegateStyle::minimumHeight
393
394 The minimum height of this delegate. The delegate will not be sized
395 smaller than this value.
396*/
397
398/*!
399 \qmlproperty bool DelegateStyle::fillWidth
400
401 Whether the delegate should fill the available width of the parent item.
402
403 Some delegates, such as the groove of a \l [QtQuickControls]{Slider}, are
404 often expected to fill the available width of the control, rather than
405 having a fixed implicit width. This can be achieved by setting
406 \c fillWidth to \c true. To add some space between the delegate and the
407 edges of its parent, use the \l margins properties.
408
409 If \c fillWidth is \c false, the delegate's width is determined by its \l width.
410
411 \sa fillHeight, width
412*/
413
414/*!
415 \qmlproperty bool DelegateStyle::fillHeight
416
417 Whether the delegate should fill the available height of the parent item.
418
419 Some delegates, such as the foreground of a checkbox indicator, are often expected
420 to fill the available height (and width) of the indicator, rather than
421 having a fixed height. This can be achieved by setting
422 \c fillHeight to \c true. To add some space between the delegate and the
423 edges of its parent, use the \l margins properties.
424
425 If \c fillHeight is \c false, the delegate's height is determined by its \l height.
426
427 \sa fillWidth, height
428*/
429
430/*!
431 \qmlproperty real DelegateStyle::opacity
432
433 The opacity of this delegate, from \c 0.0 (fully transparent) to
434 \c 1.0 (fully opaque). The default value is \c 1.0.
435
436 \sa visible, color
437*/
438
439/*!
440 \qmlproperty real DelegateStyle::radius
441
442 The corner radius applied to all four corners of this delegate.
443 Individual corners can be overridden with \l topLeftRadius,
444 \l topRightRadius, \l bottomLeftRadius, and \l bottomRightRadius.
445
446 \sa topLeftRadius, topRightRadius, bottomLeftRadius, bottomRightRadius
447*/
448
449/*!
450 \qmlproperty real DelegateStyle::rightMargin
451
452 The right margin of this delegate. If not set, falls back to
453 \l margins.
454
455 \sa margins, leftMargin, topMargin, bottomMargin
456*/
457
458/*!
459 \qmlproperty real DelegateStyle::rotation
460
461 The rotation of this delegate, in degrees.
462*/
463
464/*!
465 \qmlproperty real DelegateStyle::scale
466
467 The scale factor of this delegate. The default value is \c 1.0.
468*/
469
470/*!
471 \qmlproperty ShadowStyle DelegateStyle::shadow
472
473 Grouped property for styling a drop shadow behind this delegate.
474
475 \sa ShadowStyle
476*/
477
478/*!
479 \qmlproperty real DelegateStyle::topLeftRadius
480
481 The top-left corner radius. If not set, falls back to \l radius.
482
483 \sa radius, topRightRadius, bottomLeftRadius, bottomRightRadius
484*/
485
486/*!
487 \qmlproperty real DelegateStyle::topMargin
488
489 The top margin of this delegate. If not set, falls back to
490 \l margins.
491
492 \sa margins, bottomMargin, leftMargin, rightMargin
493*/
494
495/*!
496 \qmlproperty real DelegateStyle::topRightRadius
497
498 The top-right corner radius. If not set, falls back to \l radius.
499
500 \sa radius, topLeftRadius, bottomLeftRadius, bottomRightRadius
501*/
502
503/*!
504 \qmlproperty bool DelegateStyle::visible
505
506 Whether this delegate is visible. The default value is \c true.
507
508 \note Although the default value is \c true, the
509 \l {Style::fallbackStyle}{fallback style} (which overrides many of the default
510 values) sets \c {background.visible} to \c false for controls that typically
511 should not draw a background, such as \l [QtQuickControls]{CheckBox},
512 \l [QtQuickControls]{RadioButton}, and \l [QtQuickControls]{Slider}.
513
514 When \c visible is \c false, the \l delegate will not be created. If you need
515 a hidden delegate to be created, consider setting \l opacity to \c 0 instead.
516
517 \sa opacity
518*/
519
520// ************* ImageStyle ****************
521
522/*!
523 \qmltype ImageStyle
524 \nativetype QQStyleKitImageProperties
525 \inqmlmodule Qt.labs.StyleKit
526 \brief Defines the image style for a delegate.
527
528 ImageStyle provides properties for placing an image inside a
529 \l DelegateStyle. It is available as the
530 \l {DelegateStyle::image}{image} grouped property on any delegate.
531
532 \labs
533
534 \sa DelegateStyle, ControlStyle, ControlStateStyle,
535 {qtlabsstylekit-fallbackstyle.html}{FallbackStyle Reference}
536*/
537
538/*!
539 \qmlproperty color ImageStyle::color
540
541 A color overlay applied to the image. This is typically used to tint
542 monochrome icons to match the style's color scheme.
543*/
544
545/*!
546 \qmlproperty enumeration ImageStyle::fillMode
547
548 How the image should be scaled or tiled within the delegate. The
549 value is one of the \l [QtQuick]{Image::fillMode}{Image.fillMode}
550 enum values.
551*/
552
553/*!
554 \qmlproperty url ImageStyle::source
555
556 The URL of the image to display inside the delegate.
557*/
558
559// ************* BorderStyle ****************
560
561/*!
562 \qmltype BorderStyle
563 \nativetype QQStyleKitBorderProperties
564 \inqmlmodule Qt.labs.StyleKit
565 \brief Defines the border style for a delegate.
566
567 BorderStyle provides properties for the border drawn around a
568 \l DelegateStyle. It is available as the
569 \l {DelegateStyle::border}{border} grouped property on any delegate.
570
571 \labs
572
573 \sa DelegateStyle, ControlStyle, ControlStateStyle,
574 {qtlabsstylekit-fallbackstyle.html}{FallbackStyle Reference}
575*/
576
577/*!
578 \qmlproperty color BorderStyle::color
579
580 The color of the border. The default value is \c transparent.
581*/
582
583/*!
584 \qmlproperty real BorderStyle::width
585
586 The width of the border in pixels.
587*/
588
589// ************* ShadowStyle ****************
590
591/*!
592 \qmltype ShadowStyle
593 \nativetype QQStyleKitShadowProperties
594 \inqmlmodule Qt.labs.StyleKit
595 \brief Defines the drop shadow style for a delegate.
596
597 ShadowStyle provides properties for rendering a drop shadow behind
598 a \l DelegateStyle. It is available as the
599 \l {DelegateStyle::shadow}{shadow} grouped property on any delegate.
600
601 \snippet DelegateStyle_shadow.qml drop shadow
602
603 By adjusting scale and color, shadows can also be used to create
604 glow effects. The following snippet adds a diffuse white glow to
605 the handle of a \l [QtQuickControls]{Switch} that intensifies
606 when checked:
607
608 \snippet DelegateStyle_shadow.qml glow
609
610 \labs
611
612 \sa DelegateStyle, ControlStyle, ControlStateStyle,
613 {qtlabsstylekit-fallbackstyle.html}{FallbackStyle Reference}
614*/
615
616/*!
617 \qmlproperty real ShadowStyle::blur
618
619 The blur of the shadow. A value of \c 0.0 produces a sharp shadow, while
620 larger values produce a softer, more diffuse shadow.
621 The default value is \c 10.0.
622*/
623
624/*!
625 \qmlproperty color ShadowStyle::color
626
627 The color of the shadow. The default value is \c transparent, which
628 means that no shadow will be drawn by default.
629
630 \sa visible, opacity
631*/
632
633/*!
634 \qmlproperty Component ShadowStyle::delegate
635
636 A custom QML \l [QML]{Component} that replaces the default shadow
637 rendering. When set, StyleKit instantiates this component instead
638 of drawing the default shadow.
639*/
640
641/*!
642 \qmlproperty real ShadowStyle::horizontalOffset
643
644 The horizontal offset of the shadow from the delegate, in pixels.
645*/
646
647/*!
648 \qmlproperty real ShadowStyle::opacity
649
650 The opacity of the shadow, from \c 0.0 (fully transparent) to
651 \c 1.0 (fully opaque). The default value is \c 1.0.
652
653 \sa visible, color
654*/
655
656/*!
657 \qmlproperty real ShadowStyle::scale
658
659 The scale factor of the shadow relative to the delegate.
660 The default value is \c 1.0.
661*/
662
663/*!
664 \qmlproperty real ShadowStyle::verticalOffset
665
666 The vertical offset of the shadow from the delegate, in pixels.
667*/
668
669/*!
670 \qmlproperty bool ShadowStyle::visible
671
672 Whether the shadow is visible. The default value is \c true.
673
674 However, since the default shadow \l color is \c transparent,
675 the shadow will not be visible unless a different color is set.
676
677 \sa opacity
678*/
679
680// ************* HandleStyle ****************
681
682/*!
683 \qmltype HandleStyle
684 \nativetype QQStyleKitHandleProperties
685 \inqmlmodule Qt.labs.StyleKit
686 \inherits DelegateStyle
687 \brief Defines the handle style for controls such as \l [QtQuickControls]{Switch},
688 \l [QtQuickControls]{Slider} and \l [QtQuickControls]{RangeSlider}.
689
690 HandleStyle extends \l DelegateStyle with properties that are specific to
691 styling a handle.
692
693 Some controls have more than one handle. For example,
694 \l [QtQuickControls]{RangeSlider} has both a \l [QtQuickControls]{RangeSlider::}{first} and a \l [QtQuickControls]{RangeSlider::}{second} handle.
695 These can be styled independently using the \l first and \l second
696 sub-handles, \c {slider.handle.first} and \c {slider.handle.second}.
697 Properties not set on a sub-handle fall back to the handle itself.
698
699 \labs
700
701 \sa DelegateStyle, ControlStyle, ControlStateStyle,
702 {qtlabsstylekit-fallbackstyle.html}{FallbackStyle Reference}
703*/
704
705/*!
706 \qmlproperty DelegateStyle HandleStyle::first
707
708 Grouped property for styling the first handle of for example a
709 \l [QtQuickControls]{RangeSlider}. Unset properties fall back to
710 the HandleStyle itself.
711*/
712
713/*!
714 \qmlproperty DelegateStyle HandleStyle::second
715
716 Grouped property for styling the second handle of for example a
717 \l [QtQuickControls]{RangeSlider}. Unset properties fall back to
718 the HandleStyle itself.
719*/
720
721// ************* SubIndicatorStyle ****************
722
723/*!
724 \qmltype SubIndicatorStyle
725 \nativetype QQStyleKitIndicatorProperties
726 \inqmlmodule Qt.labs.StyleKit
727 \inherits DelegateStyle
728 \brief Defines the style for a sub-indicator delegate.
729
730 SubIndicatorStyle extends \l DelegateStyle with a \l foreground
731 property. It is used for styling sub-indicator delegates such as
732 \l {IndicatorStyle::first}{indicator.first} and
733 \l {IndicatorStyle::second}{indicator.second} in controls
734 with multiple indicators, like \l [QtQuickControls]{SpinBox}.
735 For SpinBox, \c {indicator.first} styles the increment button, and
736 \c {indicator.second} styles the decrement button.
737 It is equivalent to \l IndicatorStyle, but does not itself
738 contain sub-indicators.
739
740 \labs
741
742 \sa IndicatorStyle, DelegateStyle, ControlStyle, ControlStateStyle,
743 {qtlabsstylekit-fallbackstyle.html}{FallbackStyle Reference}
744*/
745
746/*!
747 \qmlproperty DelegateStyle SubIndicatorStyle::foreground
748
749 Grouped property for styling the foreground element of this
750 indicator. The foreground typically represents a checkmark, icon
751 or arrow rendered inside the indicator.
752*/
753
754// ************* IndicatorStyle ****************
755
756/*!
757 \qmltype IndicatorStyle
758 \nativetype QQStyleKitIndicatorWithSubTypes
759 \inqmlmodule Qt.labs.StyleKit
760 \inherits DelegateStyle
761 \brief Defines the style for a control's indicator.
762
763 IndicatorStyle extends \l DelegateStyle with properties that are specific to
764 styling an indicator.
765
766 The IndicatorStyle itself describes the indicator background, while the
767 \l foreground describes the content drawn inside it. For example,
768 \c {checkBox.indicator} styles the check box frame and
769 \c {checkBox.indicator.foreground} styles the check mark. For
770 \l {StylableControls::}{switchControl},
771 \l {StylableControls::}{slider} and
772 \l {StylableControls::}{progressBar}, the indicator styles
773 the groove and the foreground styles the fill.
774
775 \snippet DelegateStyle_indicator.qml checkBox
776
777 Some controls have more than one indicator. For example,
778 \l [QtQuickControls]{SpinBox} has both an increment and a decrement
779 button. These can be styled independently using the \l first and \l second
780 sub-indicators, \c {spinBox.indicator.first} and
781 \c {spinBox.indicator.second}. For SpinBox, \c {indicator.first} styles
782 the increment button, and \c {indicator.second} styles the decrement
783 button. Properties not set on a sub-indicator fall back to the indicator
784 itself.
785
786 \note The \c up and \c down properties are kept as aliases for
787 \c first and \c second for backward compatibility. New code
788 should use \c first and \c second, as these names are generic and can be
789 used by controls with sub-indicators that do not represent up/down actions.
790 The compatibility aliases may be removed in a future version.
791
792 \snippet DelegateStyle_indicator.qml up and down indicator
793
794 \labs
795
796 \sa SubIndicatorStyle, DelegateStyle, ControlStyle, ControlStateStyle,
797 {qtlabsstylekit-fallbackstyle.html}{FallbackStyle Reference}
798*/
799
800/*!
801 \qmlproperty DelegateStyle IndicatorStyle::foreground
802
803 Grouped property for styling the foreground element of this
804 indicator. For example, \c {checkBox.indicator} describes
805 the check box frame, while \c {checkBox.indicator.foreground} is the check mark.
806
807 For controls like \l {StylableControls::}{slider},
808 \l {StylableControls::}{progressBar}, and
809 \l {StylableControls::}{switchControl}, the \c {indicator.foreground}
810 represents the progress track or fill within the groove, while the \c indicator
811 itself represents the groove.
812*/
813
814/*!
815 \qmlproperty SubIndicatorStyle IndicatorStyle::first
816
817 Grouped property for styling the first sub-indicator of controls that
818 expose multiple indicators. For \l [QtQuickControls]{SpinBox}, this
819 styles the increment button.
820 Unset properties fall back to the indicator itself.
821
822 \note The \c up property is kept as an alias for \c first for backward
823 compatibility. New code should use \c first, as this name is generic
824 and can be used by controls with sub-indicators that do not represent
825 up actions. The compatibility alias may be removed in a future version.
826
827 \sa second
828*/
829
830/*!
831 \qmlproperty SubIndicatorStyle IndicatorStyle::second
832
833 Grouped property for styling the second sub-indicator of for example a
834 \l [QtQuickControls]{SpinBox}.
835 Unset properties fall back to the indicator itself.
836
837 \note The \c down property is kept as an alias for \c second for backward
838 compatibility. New code should use \c second, as this name is generic
839 and can be used by controls with sub-indicators that do not represent
840 down actions. The compatibility alias may be removed in a future version.
841
842 \sa first
843*/
844
845// ************* TextStyle ****************
846
847/*!
848 \qmltype TextStyle
849 \nativetype QQStyleKitTextProperties
850 \inqmlmodule Qt.labs.StyleKit
851 \brief Defines the text style for a control's label.
852
853 TextStyle provides properties for controlling the appearance of
854 text labels within a control, such as
855 \l color, \l alignment and \l padding,
856 and certain font-related properties such as
857 \l {TextStyle::}{bold},
858 \l {TextStyle::}{italic}, and
859 \l {TextStyle::pointSize}{font size}.
860
861 It is available as the \l {ControlStyleProperties::text}{text}
862 grouped property on every \l ControlStateStyle.
863
864 \labs
865
866 \sa DelegateStyle, ControlStyle, ControlStateStyle,
867 {qtlabsstylekit-fallbackstyle.html}{FallbackStyle Reference}
868*/
869
870/*!
871 \qmlproperty Qt::Alignment TextStyle::alignment
872
873 The alignment of the text within its available area.
874*/
875
876/*!
877 \qmlproperty bool TextStyle::bold
878
879 Whether the text should be rendered in bold. The default value
880 is \c false.
881
882 \sa italic
883*/
884
885/*!
886 \qmlproperty real TextStyle::bottomPadding
887
888 The bottom padding around the text. If not set, falls back to
889 \l padding.
890
891 \sa padding, topPadding, leftPadding, rightPadding
892*/
893
894/*!
895 \qmlproperty color TextStyle::color
896
897 The color of the text.
898*/
899
900/*!
901 \qmlproperty bool TextStyle::italic
902
903 Whether the text should be rendered in italic. The default value
904 is \c false.
905
906 \sa bold
907*/
908
909/*!
910 \qmlproperty real TextStyle::leftPadding
911
912 The left padding around the text. If not set, falls back to
913 \l padding.
914
915 \sa padding, rightPadding, topPadding, bottomPadding
916*/
917
918/*!
919 \qmlproperty real TextStyle::padding
920
921 The uniform padding around the text. Setting this provides a
922 default value for \l leftPadding, \l rightPadding, \l topPadding,
923 and \l bottomPadding. Each side can be overridden individually.
924
925 \sa leftPadding, rightPadding, topPadding, bottomPadding
926*/
927
928/*!
929 \qmlproperty real TextStyle::pointSize
930
931 The point size of the text font.
932*/
933
934/*!
935 \qmlproperty real TextStyle::rightPadding
936
937 The right padding around the text. If not set, falls back to
938 \l padding.
939
940 \sa padding, leftPadding, topPadding, bottomPadding
941*/
942
943/*!
944 \qmlproperty real TextStyle::topPadding
945
946 The top padding around the text. If not set, falls back to
947 \l padding.
948
949 \sa padding, bottomPadding, leftPadding, rightPadding
950*/
951
952/*!
953 \qmlproperty TextStyle TextStyle::first
954
955 Grouped property for styling the first text element in controls that
956 expose two separate text labels. Unset properties fall back to
957 \l {ControlStyleProperties::text}{text} itself.
958
959 \sa second
960*/
961
962/*!
963 \qmlproperty TextStyle TextStyle::second
964
965 Grouped property for styling the second text element in controls that
966 expose two separate text labels. Unset properties fall back to
967 \l {ControlStyleProperties::text}{text} itself.
968
969 \sa first
970*/
971
972// ************* QQStyleKitPropertyGroup ****************
973
974QQStyleKitPropertyGroup::QQStyleKitPropertyGroup(QQSK::PropertyGroup, QObject *parent)
975 : QObject(parent)
976{
977}
978
979QQStyleKitControlProperties *QQStyleKitPropertyGroup::controlProperties() const
980{
982 Q_ASSERT(qobject_cast<const QQStyleKitControlProperties *>(this));
983 auto *self = const_cast<QQStyleKitPropertyGroup *>(this);
984 return static_cast<QQStyleKitControlProperties *>(self);
985 }
986 Q_ASSERT(qobject_cast<const QQStyleKitControlProperties *>(parent()));
987 return static_cast<QQStyleKitControlProperties *>(parent());
988}
989
990template<typename T>
991T *QQStyleKitPropertyGroup::lazyCreateGroup(T * const &ptr, QQSK::PropertyGroup group) const
992{
993 T *nestedGroup = QQSK::lazyCreate(ptr, controlProperties(), group);
994
995 // Nested groups inherit path flags from their parents
996 nestedGroup->m_pathFlags = m_pathFlags;
997
998 if (group == QQSK::PropertyGroup::DelegateSubtype1) {
999 /* The subtype is stripped from a group's core path, and stored as a flag. This is because
1000 * during style property look-up, we want to check many different alternative paths where
1001 * the core group path can occur, some with, and some without, the subtype included.
1002 * Whether or not to include a subtype is therefore decided as late as possible, when
1003 * creating a QQStyleKitPropertyPath, and then depending on the usage. */
1004 nestedGroup->m_pathFlags.setFlag(QQSK::PropertyPathFlag::DelegateSubtype1);
1005 nestedGroup->m_groupSpace = m_groupSpace;
1006 } else if (group == QQSK::PropertyGroup::DelegateSubtype2) {
1007 nestedGroup->m_pathFlags.setFlag(QQSK::PropertyPathFlag::DelegateSubtype2);
1008 nestedGroup->m_groupSpace = m_groupSpace;
1009 } else {
1010 /* Calculate the available property ID space for the nested group. This is done by
1011 * dividing the available space inside _this_ group on the number of potential groups
1012 * that _this_ group can potentially contain. */
1013 const PropertyPathId nestedGroupIndex = PropertyPathId(group);
1014 const PropertyPathId nestedGroupSize = m_groupSpace.size / nestedGroupCount;
1015 nestedGroup->m_groupSpace.size = nestedGroupSize;
1016 nestedGroup->m_groupSpace.start = m_groupSpace.start + (nestedGroupIndex * nestedGroupSize);
1017 /* Ensure that we haven’t exhausted the available PropertyPathId space. There must be
1018 * enough room remaining to assign IDs for all properties defined in QQSK::Property.
1019 * If this assertion triggers, consider switching to a wider PropertyPathId type or
1020 * optimizing how the space is allocated. For example, certain nested paths (such as
1021 * control.handle.indicator) can never occur, yet we currently reserve INNER_GROUP_COUNT
1022 * for every nesting level, which is wasteful. */
1023 Q_ASSERT(nestedGroupSize >= PropertyPathId(QQSK::Property::COUNT));
1024 }
1025 return nestedGroup;
1026}
1027
1029 const QQStyleKitControl *control, const std::function<void (QQStyleKitReader *reader)> &f) const
1030{
1031 /* Iterate through all existing style readers that are _potentially_ affected by any changes
1032 * to the given control in the style, and call the provided function for each. */
1033 const QQStyleKitStyle *controlStyle = control->style();
1034 if (!controlStyle)
1035 return;
1036
1037 const QQStyleKitExtendableControlType controlType = control->controlType();
1038
1039 for (QQStyleKitReader *reader : QQStyleKitReader::s_allReaders) {
1040 QQStyleKitStyle *readerStyle = reader->style();
1041 if (!readerStyle || !readerStyle->dependsOn(controlStyle))
1042 continue;
1043
1044 const QQStyleKitExtendableControlType readerType = reader->controlType();
1045 const auto baseTypes = QQStyleKitPropertyResolver::baseTypesForType(readerType);
1046 if (readerType != controlType && !baseTypes.contains(controlType))
1047 continue;
1048
1049 f(reader);
1050 }
1051}
1052
1053/* This macro will check if the caller has the same group path as \a GROUP_PATH.
1054 * This is needed since a QQSK::Property (e.g Color) can sometimes be a
1055 * property in several different subclasses of QQStyleKitPropertyGroup.
1056 * For example, both control.background.color and control.indicator.color has a
1057 * color property. But the group path differs, so they are in reality two completely
1058 * different properties. And in that case, when the former changes value, we want to
1059 * emit changes globally only to that property, and not the latter.
1060 * The caller of this macro will therefore need to go through all the usages of its
1061 * subclass in the API, to figure out which group itself is an instance of. For the
1062 * one that is a match, the macro will go through all potentially affected readers
1063 * and emit the same signal for them. */
1064#define CONDITIONALLY_EMIT_SIGNALS_GLOBALLY_FOR(GROUP_PATH) if
1065 (this == controlProperties() -> GROUP_PATH ) {
1066 forEachRelevantStyleReader(controlProperties()->asQQStyleKitState()->control(),
1067 [&](QQStyleKitReader *reader) {
1068 /* Since this function doesn't know exactly which properties have changed (we only \
1069 * have the templated changedSignals), we need to brute-force clear all properties \
1070 * from the readers local storage to ensure that stale values for all the affected \
1071 * properties are removed. When we then emit the changed signals, the control that \
1072 * uses the reader will end up reading the changed properties directly from the \
1073 * style, since the local storage in the reader is empty. */
1074 reader->clearLocalStorage();
1075 ((reader-> GROUP_PATH ->*changedSignals)(), ...);
1076 });
1077 return; \
1078}
1079
1080template<typename SUBCLASS>
1081void QQStyleKitPropertyGroup::handleStylePropertyChanged(void (SUBCLASS::*changedSignal)()) {
1082 handleStylePropertiesChanged<SUBCLASS>(changedSignal);
1083}
1084
1085template <typename SUBCLASS, typename... CHANGED_SIGNALS>
1086void QQStyleKitPropertyGroup::handleStylePropertiesChanged(CHANGED_SIGNALS... changedSignals)
1087{
1088 /* This function will check which subclass of QQStyleKitProperties this
1089 * group is (nested) inside. Based on that, it will decide if the signals
1090 * should be emitted locally or not, and if the changed properties affects
1091 * all existing QQStyleKitReaders, and therefore will need to be
1092 * emitted 'globally'. Note that it only makes sense to call this function
1093 * for changed properties that are available from a QQStyleKitReader.
1094 * Properities only available from e.g QQStyleKitControl (such as
1095 * variations), are anyway not readable from a QQStyleKitReader. */
1096 static_assert(std::is_base_of<QQStyleKitPropertyGroup, SUBCLASS>::value,
1097 "SUBCLASS must inherit QQStyleKitPropertyGroup");
1098
1099 auto *group = static_cast<SUBCLASS *>(this);
1100 const QQSK::Subclass objectWrittenTo = controlProperties()->subclass();
1101
1102 if (objectWrittenTo == QQSK::Subclass::QQStyleKitState) {
1103 ((group->*changedSignals)(), ...);
1104 if (shouldEmitGlobally()) {
1105 // Notify all relevant StyleReaders that the given properties has changed in the style
1106 group->emitGlobally(changedSignals...);
1107 }
1108 return;
1109 }
1110
1111 if (objectWrittenTo == QQSK::Subclass::QQStyleKitReader) {
1112 /* Unless the StyleReader has told us not to emit any signals (because it's only
1113 * syncing it's own local storage with old values before starting a transition), we
1114 * emit the signal like normal. This will cause the control to repaint (perhaps
1115 * using a transition). */
1116 if (shouldEmitLocally()) {
1117 QQStyleKitReader *reader = controlProperties()->asQQStyleKitReader();
1118 /* Readers notify their consumer in two different ways depending on who is
1119 * consuming them. A QML control binds to the reader's change signals, so we
1120 * emit those directly. A widget consumer (m_target set) doesn't listen on
1121 * signals; it repaints in response to a QEvent::StyleAnimationUpdate posted
1122 * to the widget, and only while a transition is actually running. */
1123 if (!reader->m_target)
1124 ((group->*changedSignals)(), ...);
1125 else
1126 QCoreApplication::postEvent(reader->m_target, new QEvent(QEvent::StyleAnimationUpdate));
1127 }
1128 return;
1129 }
1130
1131 Q_UNREACHABLE();
1132}
1133
1134void QQStyleKitPropertyGroup::emitChangedForAllStylePropertiesRecursive(EmitFlags emitFlags)
1135{
1136 /* This function will emit changed signals for all style properties in the
1137 * StyleKit API (for a single QQStyleKitReader), which is needed after
1138 * doing a style-, or theme change. */
1139 const QMetaObject *meta = metaObject();
1140 if (meta->inherits(&QQStyleKitControlProperties::staticMetaObject)) {
1141 /* Subclasses of QQStyleKitControlProperties, such as QQStyleKitReader, add
1142 * properties that describe the state of the control (hovered, checked, etc.)
1143 * rather than its style. Those should not be emitted from here. */
1144 meta = &QQStyleKitControlProperties::staticMetaObject;
1145 }
1146
1147 const int startIndex = QQStyleKitPropertyGroup::staticMetaObject.propertyOffset();
1148 for (int i = startIndex; i < meta->propertyCount(); ++i) {
1149 const QMetaProperty prop = meta->property(i);
1150 const QMetaObject* propMetaObject = QMetaType::fromName(prop.typeName()).metaObject();
1151 if (propMetaObject && propMetaObject->inherits(&QQStyleKitPropertyGroup::staticMetaObject)) {
1152 /* Nested groups are handled by forEachExistingNestedGroup() below. Reading them
1153 * through their property getters from here would lazily create them. */
1154 continue;
1155 }
1156
1157 if (!emitFlags.testFlag(EmitFlag::AllProperties)) {
1158 // Only emit for color properties when the Colors flag is set
1159 if (emitFlags.testFlag(EmitFlag::Colors)) {
1160 if (prop.metaType() != QMetaType::fromType<QColor>())
1161 continue;
1162 }
1163 }
1164
1165 /* Emit the changed signal for the property.
1166 * Note: even if we call invoke() for every style property, only the signals that
1167 * are connected to something (e.g. a binding) end up doing any real work. If
1168 * isSignalConnected() is false, the emit will exit early. */
1169 Q_ASSERT(prop.hasNotifySignal());
1170 QMetaMethod notify = prop.notifySignal();
1171 notify.invoke(this, Qt::DirectConnection);
1172 }
1173
1174 /* Recurse into the nested groups, but only the ones that have been created. Since
1175 * nested groups are lazily created when first read, a group that doesn't exist has
1176 * never been read, so there are no bindings to it that would need to be notified. */
1177 forEachExistingNestedGroup([emitFlags](QQStyleKitPropertyGroup *group) {
1178 group->emitChangedForAllStylePropertiesRecursive(emitFlags);
1179 });
1180}
1181
1183 const std::function<void (QQStyleKitPropertyGroup *)> &f) const
1184{
1185 /* Subclasses with nested groups should override this function and call f for
1186 * each nested group that has been created, mirroring the groups that the subclass
1187 * creates with lazyCreateGroup(). Nested groups are lazily created when read, so a
1188 * group that hasn't been created has never been read either. Using the member
1189 * pointers directly (as opposed to the property getters) avoids creating them by
1190 * accident. Overrides should not call this base implementation. */
1191 Q_UNUSED(f);
1192
1193#ifdef QT_DEBUG
1194 /* Verify that this group has no nested groups, since it would otherwise need to
1195 * override this function. */
1196 const QMetaObject *meta = metaObject();
1197 const int startIndex = QQStyleKitPropertyGroup::staticMetaObject.propertyOffset();
1198 for (int i = startIndex; i < meta->propertyCount(); ++i) {
1199 const QMetaProperty prop = meta->property(i);
1200 const QMetaObject *propMetaObject = QMetaType::fromName(prop.typeName()).metaObject();
1201 Q_ASSERT_X(!propMetaObject || !propMetaObject->inherits(&QQStyleKitPropertyGroup::staticMetaObject),
1202 meta->className(), "Classes with nested property groups must override forEachExistingNestedGroup()");
1203 }
1204#endif
1205}
1206
1207bool QQStyleKitPropertyGroup::shouldEmitLocally()
1208{
1209 return !controlProperties()->asQQStyleKitReader()->dontEmitChangedSignals();
1210}
1211
1212bool QQStyleKitPropertyGroup::shouldEmitGlobally()
1213{
1214 QQStyleKitStyle *parentStyle = controlProperties()->style();
1215 if (!parentStyle)
1216 return false;
1217
1218 if (parentStyle->loaded() && !parentStyle->m_isUpdatingPalette) {
1219 /* When a property has changed in the 'global' QQStyleKitStyle itself, it can
1220 * potentially affect all control instances. We therefore need to go through all
1221 * QQStyleKitReaders and inform that their own local property that matches the
1222 * 'global' property needs to be re-read. We emit the signals directly, omitting any
1223 * applied transitions in the QQStyleKitReaders, to optimize for speed. The exception
1224 * is if we're just updating the palette in the Style to match the palette in the current
1225 * control / QQStyleKitReader. Such a change will only affect a single control. */
1226 return true;
1227 }
1228
1229 return false;
1230}
1231
1232// ************* QQStyleKitImageProperties ****************
1233
1234QQStyleKitImageProperties::QQStyleKitImageProperties(QQSK::PropertyGroup group, QQStyleKitControlProperties *parent)
1235 : QQStyleKitPropertyGroup(group, parent)
1236{
1237}
1238
1239template <typename... CHANGED_SIGNALS>
1240void QQStyleKitImageProperties::emitGlobally(CHANGED_SIGNALS... changedSignals) const
1241{
1242 // Go through all instances of QQStyleKitImageProperties
1243 CONDITIONALLY_EMIT_SIGNALS_GLOBALLY_FOR(background()->image());
1244 CONDITIONALLY_EMIT_SIGNALS_GLOBALLY_FOR(handle()->image());
1245 CONDITIONALLY_EMIT_SIGNALS_GLOBALLY_FOR(indicator()->image());
1246 CONDITIONALLY_EMIT_SIGNALS_GLOBALLY_FOR(indicator()->foreground()->image());
1247}
1248
1249QUrl QQStyleKitImageProperties::source() const
1250{
1251 return styleProperty<QUrl>(QQSK::Property::Source);
1252}
1253
1254void QQStyleKitImageProperties::setSource(const QUrl &source)
1255{
1256 if (setStyleProperty(QQSK::Property::Source, source))
1257 handleStylePropertyChanged(&QQStyleKitImageProperties::sourceChanged);
1258}
1259
1260QColor QQStyleKitImageProperties::color() const
1261{
1262 return styleProperty<QColor>(QQSK::Property::Color);
1263}
1264
1265void QQStyleKitImageProperties::setColor(const QColor &color)
1266{
1267 if (setStyleProperty(QQSK::Property::Color, color))
1268 handleStylePropertyChanged(&QQStyleKitImageProperties::colorChanged);
1269}
1270
1271QQuickImage::FillMode QQStyleKitImageProperties::fillMode() const
1272{
1273 return styleProperty<QQuickImage::FillMode>(QQSK::Property::FillMode);
1274}
1275
1276void QQStyleKitImageProperties::setFillMode(QQuickImage::FillMode fillMode)
1277{
1278 if (setStyleProperty(QQSK::Property::FillMode, fillMode))
1279 handleStylePropertyChanged(&QQStyleKitImageProperties::fillModeChanged);
1280}
1281
1282// ************* QQStyleKitBorderProperties ****************
1283
1284QQStyleKitBorderProperties::QQStyleKitBorderProperties(QQSK::PropertyGroup group, QQStyleKitControlProperties *parent)
1285 : QQStyleKitPropertyGroup(group, parent)
1286{
1287}
1288
1289template <typename... CHANGED_SIGNALS>
1290void QQStyleKitBorderProperties::emitGlobally(CHANGED_SIGNALS... changedSignals) const
1291{
1292 // Go through all instances of QQStyleKitBorderProperties
1293 CONDITIONALLY_EMIT_SIGNALS_GLOBALLY_FOR(background()->border());
1294 CONDITIONALLY_EMIT_SIGNALS_GLOBALLY_FOR(handle()->border());
1295 CONDITIONALLY_EMIT_SIGNALS_GLOBALLY_FOR(indicator()->border());
1296 CONDITIONALLY_EMIT_SIGNALS_GLOBALLY_FOR(indicator()->foreground()->border());
1297}
1298
1299qreal QQStyleKitBorderProperties::width() const
1300{
1301 return styleProperty<qreal>(QQSK::Property::Width);
1302}
1303
1304void QQStyleKitBorderProperties::setWidth(qreal width)
1305{
1306 if (setStyleProperty(QQSK::Property::Width, width))
1307 handleStylePropertyChanged(&QQStyleKitBorderProperties::widthChanged);
1308}
1309
1310QColor QQStyleKitBorderProperties::color() const
1311{
1312 return styleProperty<QColor>(QQSK::Property::Color, Qt::transparent);
1313}
1314
1315void QQStyleKitBorderProperties::setColor(const QColor &color)
1316{
1317 if (setStyleProperty(QQSK::Property::Color, color))
1318 handleStylePropertyChanged(&QQStyleKitBorderProperties::colorChanged);
1319}
1320
1321// ************* QQStyleKitShadowProperties ****************
1322
1323QQStyleKitShadowProperties::QQStyleKitShadowProperties(QQSK::PropertyGroup group, QQStyleKitControlProperties *parent)
1324 : QQStyleKitPropertyGroup(group, parent)
1325{
1326}
1327
1328template <typename... CHANGED_SIGNALS>
1329void QQStyleKitShadowProperties::emitGlobally(CHANGED_SIGNALS... changedSignals) const
1330{
1331 // Go through all instances of QQStyleKitShadowProperties
1332 CONDITIONALLY_EMIT_SIGNALS_GLOBALLY_FOR(background()->shadow());
1333 CONDITIONALLY_EMIT_SIGNALS_GLOBALLY_FOR(handle()->shadow());
1334 CONDITIONALLY_EMIT_SIGNALS_GLOBALLY_FOR(indicator()->shadow());
1335 CONDITIONALLY_EMIT_SIGNALS_GLOBALLY_FOR(indicator()->foreground()->shadow());
1336}
1337
1338QColor QQStyleKitShadowProperties::color() const
1339{
1340 return styleProperty<QColor>(QQSK::Property::Color, Qt::transparent);
1341}
1342
1343void QQStyleKitShadowProperties::setColor(QColor color)
1344{
1345 if (setStyleProperty(QQSK::Property::Color, color))
1346 handleStylePropertyChanged(&QQStyleKitShadowProperties::colorChanged);
1347}
1348
1349qreal QQStyleKitShadowProperties::opacity() const
1350{
1351 return styleProperty<qreal>(QQSK::Property::Opacity, 1.0);
1352}
1353
1354void QQStyleKitShadowProperties::setOpacity(qreal opacity)
1355{
1356 if (setStyleProperty(QQSK::Property::Opacity, opacity))
1357 handleStylePropertyChanged(&QQStyleKitShadowProperties::opacityChanged);
1358}
1359
1360qreal QQStyleKitShadowProperties::scale() const
1361{
1362 return styleProperty<qreal>(QQSK::Property::Scale, 1.0);
1363}
1364
1365void QQStyleKitShadowProperties::setScale(qreal scale)
1366{
1367 if (setStyleProperty(QQSK::Property::Scale, scale))
1368 handleStylePropertyChanged(&QQStyleKitShadowProperties::scaleChanged);
1369}
1370
1371qreal QQStyleKitShadowProperties::verticalOffset() const
1372{
1373 return styleProperty<qreal>(QQSK::Property::VOffset);
1374}
1375
1376void QQStyleKitShadowProperties::setVerticalOffset(qreal verticalOffset)
1377{
1378 if (setStyleProperty(QQSK::Property::VOffset, verticalOffset))
1379 handleStylePropertyChanged(&QQStyleKitShadowProperties::verticalOffsetChanged);
1380}
1381
1382qreal QQStyleKitShadowProperties::horizontalOffset() const
1383{
1384 return styleProperty<qreal>(QQSK::Property::HOffset);
1385}
1386
1387void QQStyleKitShadowProperties::setHorizontalOffset(qreal horizontalOffset)
1388{
1389 if (setStyleProperty(QQSK::Property::HOffset, horizontalOffset))
1390 handleStylePropertyChanged(&QQStyleKitShadowProperties::horizontalOffsetChanged);
1391}
1392
1393qreal QQStyleKitShadowProperties::blur() const
1394{
1395 return styleProperty<qreal>(QQSK::Property::Blur, 10.0);
1396}
1397
1398void QQStyleKitShadowProperties::setBlur(qreal blur)
1399{
1400 if (setStyleProperty(QQSK::Property::Blur, blur))
1401 handleStylePropertyChanged(&QQStyleKitShadowProperties::blurChanged);
1402}
1403
1404bool QQStyleKitShadowProperties::visible() const
1405{
1406 return styleProperty<bool>(QQSK::Property::Visible, true);
1407}
1408
1409void QQStyleKitShadowProperties::setVisible(bool visible)
1410{
1411 if (setStyleProperty(QQSK::Property::Visible, visible))
1412 handleStylePropertyChanged(&QQStyleKitShadowProperties::visibleChanged);
1413}
1414
1415QQmlComponent *QQStyleKitShadowProperties::delegate() const
1416{
1417 return styleProperty<QQmlComponent *>(QQSK::Property::Delegate);
1418}
1419
1420void QQStyleKitShadowProperties::setDelegate(QQmlComponent *delegate)
1421{
1422 if (setStyleProperty(QQSK::Property::Delegate, delegate))
1423 handleStylePropertyChanged(&QQStyleKitShadowProperties::delegateChanged);
1424}
1425
1426// ************* QQStyleKitDelegateProperties ****************
1427
1428QQStyleKitDelegateProperties::QQStyleKitDelegateProperties(QQSK::PropertyGroup group, QQStyleKitControlProperties *parent)
1429 : QQStyleKitPropertyGroup(group, parent)
1430{
1431}
1432
1433template <typename... CHANGED_SIGNALS>
1434void QQStyleKitDelegateProperties::emitGlobally(CHANGED_SIGNALS... changedSignals) const
1435{
1436 // Go through all instances of QQStyleKitDelegateProperties
1440 CONDITIONALLY_EMIT_SIGNALS_GLOBALLY_FOR(indicator()->foreground());
1441}
1442
1443void QQStyleKitDelegateProperties::forEachExistingNestedGroup(
1444 const std::function<void (QQStyleKitPropertyGroup *)> &f) const
1445{
1446 // Keep in sync with the nested groups this class creates with lazyCreateGroup()
1447 if (m_image)
1448 f(m_image);
1449 if (m_border)
1450 f(m_border);
1451 if (m_shadow)
1452 f(m_shadow);
1453}
1454
1455qreal QQStyleKitDelegateProperties::radius() const
1456{
1457 return styleProperty<qreal>(QQSK::Property::Radius);
1458}
1459
1460void QQStyleKitDelegateProperties::setRadius(qreal radius)
1461{
1462 if (setStyleProperty(QQSK::Property::Radius, radius))
1463 handleStylePropertiesChanged<QQStyleKitDelegateProperties>(
1464 &QQStyleKitDelegateProperties::radiusChanged,
1465 &QQStyleKitDelegateProperties::topLeftRadiusChanged,
1466 &QQStyleKitDelegateProperties::topRightRadiusChanged,
1467 &QQStyleKitDelegateProperties::bottomLeftRadiusChanged,
1468 &QQStyleKitDelegateProperties::bottomRightRadiusChanged);
1469}
1470
1471qreal QQStyleKitDelegateProperties::topLeftRadius() const
1472{
1473 return styleProperty<qreal>(QQSK::Property::TopLeftRadius, QQSK::Property::Radius);
1474}
1475
1476void QQStyleKitDelegateProperties::setTopLeftRadius(qreal radius)
1477{
1478 if (setStyleProperty(QQSK::Property::TopLeftRadius, radius))
1479 handleStylePropertyChanged(&QQStyleKitDelegateProperties::topLeftRadiusChanged);
1480}
1481
1482qreal QQStyleKitDelegateProperties::topRightRadius() const
1483{
1484 return styleProperty<qreal>(QQSK::Property::TopRightRadius, QQSK::Property::Radius);
1485}
1486
1487void QQStyleKitDelegateProperties::setTopRightRadius(qreal radius)
1488{
1489 if (setStyleProperty(QQSK::Property::TopRightRadius, radius))
1490 handleStylePropertyChanged(&QQStyleKitDelegateProperties::topRightRadiusChanged);
1491}
1492
1493qreal QQStyleKitDelegateProperties::bottomLeftRadius() const
1494{
1495 return styleProperty<qreal>(QQSK::Property::BottomLeftRadius, QQSK::Property::Radius);
1496}
1497
1498void QQStyleKitDelegateProperties::setBottomLeftRadius(qreal radius)
1499{
1500 if (setStyleProperty(QQSK::Property::BottomLeftRadius, radius))
1501 handleStylePropertyChanged(&QQStyleKitDelegateProperties::bottomLeftRadiusChanged);
1502}
1503
1504qreal QQStyleKitDelegateProperties::bottomRightRadius() const
1505{
1506 return styleProperty<qreal>(QQSK::Property::BottomRightRadius, QQSK::Property::Radius);
1507}
1508
1509void QQStyleKitDelegateProperties::setBottomRightRadius(qreal radius)
1510{
1511 if (setStyleProperty(QQSK::Property::BottomRightRadius, radius))
1512 handleStylePropertyChanged(&QQStyleKitDelegateProperties::bottomRightRadiusChanged);
1513}
1514
1515qreal QQStyleKitDelegateProperties::scale() const
1516{
1517 return styleProperty<qreal>(QQSK::Property::Scale, 1.0);
1518}
1519
1520void QQStyleKitDelegateProperties::setScale(qreal scale)
1521{
1522 if (setStyleProperty(QQSK::Property::Scale, scale))
1523 handleStylePropertyChanged(&QQStyleKitDelegateProperties::scaleChanged);
1524}
1525
1526qreal QQStyleKitDelegateProperties::rotation() const
1527{
1528 return styleProperty<qreal>(QQSK::Property::Rotation);
1529}
1530
1531void QQStyleKitDelegateProperties::setRotation(qreal rotation)
1532{
1533 if (setStyleProperty(QQSK::Property::Rotation, rotation))
1534 handleStylePropertyChanged(&QQStyleKitDelegateProperties::rotationChanged);
1535}
1536
1537qreal QQStyleKitDelegateProperties::width() const
1538{
1539 return styleProperty<qreal>(QQSK::Property::Width);
1540}
1541
1542void QQStyleKitDelegateProperties::setWidth(qreal width)
1543{
1544 if (setStyleProperty(QQSK::Property::Width, width))
1545 handleStylePropertyChanged(&QQStyleKitDelegateProperties::widthChanged);
1546}
1547
1548qreal QQStyleKitDelegateProperties::height() const
1549{
1550 return styleProperty<qreal>(QQSK::Property::Height);
1551}
1552
1553void QQStyleKitDelegateProperties::setHeight(qreal height)
1554{
1555 if (setStyleProperty(QQSK::Property::Height, height))
1556 handleStylePropertyChanged(&QQStyleKitDelegateProperties::heightChanged);
1557}
1558
1559qreal QQStyleKitDelegateProperties::minimumWidth() const
1560{
1561 return styleProperty<qreal>(QQSK::Property::MinimumWidth);
1562}
1563
1564void QQStyleKitDelegateProperties::setMinimumWidth(qreal width)
1565{
1566 if (setStyleProperty(QQSK::Property::MinimumWidth, width))
1567 handleStylePropertyChanged(&QQStyleKitDelegateProperties::minimumWidthChanged);
1568}
1569
1570qreal QQStyleKitDelegateProperties::minimumHeight() const
1571{
1572 return styleProperty<qreal>(QQSK::Property::MinimumHeight);
1573}
1574
1575void QQStyleKitDelegateProperties::setMinimumHeight(qreal height)
1576{
1577 if (setStyleProperty(QQSK::Property::MinimumHeight, height))
1578 handleStylePropertyChanged(&QQStyleKitDelegateProperties::minimumHeightChanged);
1579}
1580
1581bool QQStyleKitDelegateProperties::fillWidth() const
1582{
1583 return styleProperty<bool>(QQSK::Property::FillWidth);
1584}
1585
1586void QQStyleKitDelegateProperties::setFillWidth(bool fill)
1587{
1588 if (setStyleProperty(QQSK::Property::FillWidth, fill))
1589 handleStylePropertyChanged(&QQStyleKitDelegateProperties::fillWidthChanged);
1590}
1591
1592bool QQStyleKitDelegateProperties::fillHeight() const
1593{
1594 return styleProperty<bool>(QQSK::Property::FillHeight);
1595}
1596
1597void QQStyleKitDelegateProperties::setFillHeight(bool fill)
1598{
1599 if (setStyleProperty(QQSK::Property::FillHeight, fill))
1600 handleStylePropertyChanged(&QQStyleKitDelegateProperties::fillHeightChanged);
1601}
1602
1603qreal QQStyleKitDelegateProperties::margins() const
1604{
1605 return styleProperty<qreal>(QQSK::Property::Margins);
1606}
1607
1608void QQStyleKitDelegateProperties::setMargins(qreal margins)
1609{
1610 if (setStyleProperty(QQSK::Property::Margins, margins))
1611 handleStylePropertiesChanged<QQStyleKitDelegateProperties>(
1612 &QQStyleKitDelegateProperties::marginsChanged,
1613 &QQStyleKitDelegateProperties::leftMarginChanged,
1614 &QQStyleKitDelegateProperties::rightMarginChanged,
1615 &QQStyleKitDelegateProperties::topMarginChanged,
1616 &QQStyleKitDelegateProperties::bottomMarginChanged);
1617}
1618
1619qreal QQStyleKitDelegateProperties::leftMargin() const
1620{
1621 return styleProperty<qreal>(QQSK::Property::LeftMargin, QQSK::Property::Margins);
1622}
1623
1624void QQStyleKitDelegateProperties::setLeftMargin(qreal margin)
1625{
1626 if (setStyleProperty(QQSK::Property::LeftMargin, margin))
1627 handleStylePropertyChanged(&QQStyleKitDelegateProperties::leftMarginChanged);
1628}
1629
1630qreal QQStyleKitDelegateProperties::rightMargin() const
1631{
1632 return styleProperty<qreal>(QQSK::Property::RightMargin, QQSK::Property::Margins);
1633}
1634
1635void QQStyleKitDelegateProperties::setRightMargin(qreal margin)
1636{
1637 if (setStyleProperty(QQSK::Property::RightMargin, margin))
1638 handleStylePropertyChanged(&QQStyleKitDelegateProperties::rightMarginChanged);
1639}
1640
1641qreal QQStyleKitDelegateProperties::topMargin() const
1642{
1643 return styleProperty<qreal>(QQSK::Property::TopMargin, QQSK::Property::Margins);
1644}
1645
1646void QQStyleKitDelegateProperties::setTopMargin(qreal margin)
1647{
1648 if (setStyleProperty(QQSK::Property::TopMargin, margin))
1649 handleStylePropertyChanged(&QQStyleKitDelegateProperties::topMarginChanged);
1650}
1651
1652qreal QQStyleKitDelegateProperties::bottomMargin() const
1653{
1654 return styleProperty<qreal>(QQSK::Property::BottomMargin, QQSK::Property::Margins);
1655}
1656
1657void QQStyleKitDelegateProperties::setBottomMargin(qreal margin)
1658{
1659 if (setStyleProperty(QQSK::Property::BottomMargin, margin))
1660 handleStylePropertyChanged(&QQStyleKitDelegateProperties::bottomMarginChanged);
1661}
1662
1663Qt::Alignment QQStyleKitDelegateProperties::alignment() const
1664{
1665 return styleProperty<Qt::Alignment>(QQSK::Property::Alignment, Qt::AlignLeft | Qt::AlignVCenter);
1666}
1667
1668void QQStyleKitDelegateProperties::setAlignment(Qt::Alignment alignment)
1669{
1670 if (setStyleProperty(QQSK::Property::Alignment, alignment))
1671 handleStylePropertyChanged(&QQStyleKitDelegateProperties::alignmentChanged);
1672}
1673
1674qreal QQStyleKitDelegateProperties::opacity() const
1675{
1676 return styleProperty<qreal>(QQSK::Property::Opacity, 1.0);
1677}
1678
1679void QQStyleKitDelegateProperties::setOpacity(qreal opacity)
1680{
1681 if (setStyleProperty(QQSK::Property::Opacity, opacity))
1682 handleStylePropertyChanged(&QQStyleKitDelegateProperties::opacityChanged);
1683}
1684
1685QColor QQStyleKitDelegateProperties::color() const
1686{
1687 return styleProperty<QColor>(QQSK::Property::Color, Qt::transparent);
1688}
1689
1690void QQStyleKitDelegateProperties::setColor(const QColor &color)
1691{
1692 if (setStyleProperty(QQSK::Property::Color, color))
1693 handleStylePropertyChanged(&QQStyleKitDelegateProperties::colorChanged);
1694}
1695
1696bool QQStyleKitDelegateProperties::visible() const
1697{
1698 return styleProperty<bool>(QQSK::Property::Visible, true);
1699}
1700
1701void QQStyleKitDelegateProperties::setVisible(bool visible)
1702{
1703 if (setStyleProperty(QQSK::Property::Visible, visible))
1704 handleStylePropertyChanged(&QQStyleKitDelegateProperties::visibleChanged);
1705}
1706
1707bool QQStyleKitDelegateProperties::clip() const
1708{
1709 return styleProperty<bool>(QQSK::Property::Clip, false);
1710}
1711
1712void QQStyleKitDelegateProperties::setClip(bool clip)
1713{
1714 if (setStyleProperty(QQSK::Property::Clip, clip))
1715 handleStylePropertyChanged(&QQStyleKitDelegateProperties::clipChanged);
1716}
1717
1718QQuickGradient *QQStyleKitDelegateProperties::gradient() const
1719{
1720 return styleProperty<QQuickGradient *>(QQSK::Property::Gradient);
1721}
1722
1723void QQStyleKitDelegateProperties::setGradient(QQuickGradient *gradient)
1724{
1725 if (setStyleProperty(QQSK::Property::Gradient, gradient))
1726 handleStylePropertyChanged(&QQStyleKitDelegateProperties::gradientChanged);
1727}
1728
1729QObject *QQStyleKitDelegateProperties::data() const
1730{
1731 return styleProperty<QObject *>(QQSK::Property::Data);
1732}
1733
1734void QQStyleKitDelegateProperties::setData(QObject *data)
1735{
1736 if (setStyleProperty(QQSK::Property::Data, data))
1737 handleStylePropertyChanged(&QQStyleKitDelegateProperties::dataChanged);
1738}
1739
1740QQmlComponent *QQStyleKitDelegateProperties::delegate() const
1741{
1742 return styleProperty<QQmlComponent *>(QQSK::Property::Delegate);
1743}
1744
1745void QQStyleKitDelegateProperties::setDelegate(QQmlComponent *delegate)
1746{
1747 if (setStyleProperty(QQSK::Property::Delegate, delegate))
1748 handleStylePropertyChanged(&QQStyleKitDelegateProperties::delegateChanged);
1749}
1750
1751QQStyleKitBorderProperties *QQStyleKitDelegateProperties::border() const
1752{
1753 return lazyCreateGroup(m_border, QQSK::PropertyGroup::Border);
1754}
1755
1756QQStyleKitShadowProperties *QQStyleKitDelegateProperties::shadow() const
1757{
1758 return lazyCreateGroup(m_shadow, QQSK::PropertyGroup::Shadow);
1759}
1760
1761QQStyleKitImageProperties *QQStyleKitDelegateProperties::image() const
1762{
1763 return lazyCreateGroup(m_image, QQSK::PropertyGroup::Image);
1764}
1765
1766// ************* QQStyleKitHandleProperties ****************
1767
1768QQStyleKitHandleProperties::QQStyleKitHandleProperties(QQSK::PropertyGroup group, QQStyleKitControlProperties *parent)
1769 : QQStyleKitDelegateProperties(group, parent)
1770{
1771}
1772
1773void QQStyleKitHandleProperties::forEachExistingNestedGroup(
1774 const std::function<void (QQStyleKitPropertyGroup *)> &f) const
1775{
1776 // Keep in sync with the nested groups this class creates with lazyCreateGroup()
1777 QQStyleKitDelegateProperties::forEachExistingNestedGroup(f);
1778 if (m_first)
1779 f(m_first);
1780 if (m_second)
1781 f(m_second);
1782}
1783
1784QQStyleKitDelegateProperties *QQStyleKitHandleProperties::first() const
1785{
1786 return lazyCreateGroup(m_first, QQSK::PropertyGroup::DelegateSubtype1);
1787}
1788
1789QQStyleKitDelegateProperties *QQStyleKitHandleProperties::second() const
1790{
1791 return lazyCreateGroup(m_second, QQSK::PropertyGroup::DelegateSubtype2);
1792}
1793
1794// ************* QQStyleKitIndicatorProperties ****************
1795
1796QQStyleKitIndicatorProperties::QQStyleKitIndicatorProperties(
1797 QQSK::PropertyGroup group, QQStyleKitControlProperties *parent)
1798 : QQStyleKitDelegateProperties(group, parent)
1799{
1800}
1801
1802template <typename... CHANGED_SIGNALS>
1803void QQStyleKitIndicatorProperties::emitGlobally(CHANGED_SIGNALS... changedSignals) const
1804{
1805 // Go through all instances of QQStyleKitIndicatorProperties
1806 CONDITIONALLY_EMIT_SIGNALS_GLOBALLY_FOR(indicator()->first());
1807 CONDITIONALLY_EMIT_SIGNALS_GLOBALLY_FOR(indicator()->second());
1808}
1809
1810void QQStyleKitIndicatorProperties::forEachExistingNestedGroup(
1811 const std::function<void (QQStyleKitPropertyGroup *)> &f) const
1812{
1813 // Keep in sync with the nested groups this class creates with lazyCreateGroup()
1814 QQStyleKitDelegateProperties::forEachExistingNestedGroup(f);
1815 if (m_foreground)
1816 f(m_foreground);
1817}
1818
1819QQStyleKitDelegateProperties *QQStyleKitIndicatorProperties::foreground() const
1820{
1821 return lazyCreateGroup(m_foreground, QQSK::PropertyGroup::Foreground);
1822}
1823
1824// ************* QQStyleKitIndicatorWithSubTypes ****************
1825
1826QQStyleKitIndicatorWithSubTypes::QQStyleKitIndicatorWithSubTypes(
1827 QQSK::PropertyGroup group, QQStyleKitControlProperties *parent)
1828 : QQStyleKitDelegateProperties(group, parent)
1829{
1830}
1831
1832template <typename... CHANGED_SIGNALS>
1833void QQStyleKitIndicatorWithSubTypes::emitGlobally(CHANGED_SIGNALS... changedSignals) const
1834{
1835 // Go through all instances of QQStyleKitIndicatorWithSubTypes
1837}
1838
1839void QQStyleKitIndicatorWithSubTypes::forEachExistingNestedGroup(
1840 const std::function<void (QQStyleKitPropertyGroup *)> &f) const
1841{
1842 // Keep in sync with the nested groups this class creates with lazyCreateGroup()
1843 QQStyleKitDelegateProperties::forEachExistingNestedGroup(f);
1844 if (m_foreground)
1845 f(m_foreground);
1846 if (m_first)
1847 f(m_first);
1848 if (m_second)
1849 f(m_second);
1850}
1851
1852QQStyleKitDelegateProperties *QQStyleKitIndicatorWithSubTypes::foreground() const
1853{
1854 return lazyCreateGroup(m_foreground, QQSK::PropertyGroup::Foreground);
1855}
1856
1857QQStyleKitIndicatorProperties *QQStyleKitIndicatorWithSubTypes::up() const
1858{
1859 return first();
1860}
1861
1862QQStyleKitIndicatorProperties *QQStyleKitIndicatorWithSubTypes::down() const
1863{
1864 return second();
1865}
1866
1867QQStyleKitIndicatorProperties *QQStyleKitIndicatorWithSubTypes::first() const
1868{
1869 return lazyCreateGroup(m_first, QQSK::PropertyGroup::DelegateSubtype1);
1870}
1871
1872QQStyleKitIndicatorProperties *QQStyleKitIndicatorWithSubTypes::second() const
1873{
1874 return lazyCreateGroup(m_second, QQSK::PropertyGroup::DelegateSubtype2);
1875}
1876
1877// ************* QQStyleKitTextProperties ****************
1878QQStyleKitTextProperties::QQStyleKitTextProperties(QQSK::PropertyGroup group, QQStyleKitControlProperties *parent)
1879 : QQStyleKitPropertyGroup(group, parent)
1880{
1881}
1882
1883template <typename... CHANGED_SIGNALS>
1884void QQStyleKitTextProperties::emitGlobally(CHANGED_SIGNALS... changedSignals) const
1885{
1889}
1890
1891void QQStyleKitTextProperties::forEachExistingNestedGroup(
1892 const std::function<void (QQStyleKitPropertyGroup *)> &f) const
1893{
1894 // Keep in sync with the nested groups this class creates with lazyCreateGroup()
1895 if (m_first)
1896 f(m_first);
1897 if (m_second)
1898 f(m_second);
1899}
1900
1901QColor QQStyleKitTextProperties::color() const
1902{
1903 return styleProperty<QColor>(QQSK::Property::Color);
1904}
1905
1906void QQStyleKitTextProperties::setColor(const QColor &color)
1907{
1908 if (setStyleProperty(QQSK::Property::Color, color))
1909 handleStylePropertyChanged(&QQStyleKitTextProperties::colorChanged);
1910}
1911
1912Qt::Alignment QQStyleKitTextProperties::alignment() const
1913{
1914 return styleProperty<Qt::Alignment>(QQSK::Property::Alignment);
1915}
1916
1917void QQStyleKitTextProperties::setAlignment(Qt::Alignment alignment)
1918{
1919 if (setStyleProperty(QQSK::Property::Alignment, alignment))
1920 handleStylePropertyChanged(&QQStyleKitTextProperties::alignmentChanged);
1921}
1922
1923bool QQStyleKitTextProperties::bold() const
1924{
1925 return styleProperty<bool>(QQSK::Property::Bold, false);
1926}
1927
1928void QQStyleKitTextProperties::setBold(bool bold)
1929{
1930 if (setStyleProperty(QQSK::Property::Bold, bold))
1931 handleStylePropertyChanged(&QQStyleKitTextProperties::boldChanged);
1932}
1933
1934bool QQStyleKitTextProperties::italic() const
1935{
1936 return styleProperty<bool>(QQSK::Property::Italic, false);
1937}
1938
1939void QQStyleKitTextProperties::setItalic(bool italic)
1940{
1941 if (setStyleProperty(QQSK::Property::Italic, italic))
1942 handleStylePropertyChanged(&QQStyleKitTextProperties::italicChanged);
1943}
1944
1945qreal QQStyleKitTextProperties::pointSize() const
1946{
1947 return styleProperty<qreal>(QQSK::Property::PointSize, QFont().pointSize());
1948}
1949
1950void QQStyleKitTextProperties::setPointSize(qreal pointSize)
1951{
1952 if (setStyleProperty(QQSK::Property::PointSize, pointSize))
1953 handleStylePropertyChanged(&QQStyleKitTextProperties::pointSizeChanged);
1954}
1955
1956qreal QQStyleKitTextProperties::padding() const
1957{
1958 return styleProperty<qreal>(QQSK::Property::Padding);
1959}
1960
1961void QQStyleKitTextProperties::setPadding(qreal padding)
1962{
1963 if (setStyleProperty(QQSK::Property::Padding, padding))
1964 handleStylePropertiesChanged<QQStyleKitTextProperties>(
1965 &QQStyleKitTextProperties::paddingChanged,
1966 &QQStyleKitTextProperties::leftPaddingChanged,
1967 &QQStyleKitTextProperties::rightPaddingChanged,
1968 &QQStyleKitTextProperties::topPaddingChanged,
1969 &QQStyleKitTextProperties::bottomPaddingChanged);
1970}
1971
1972qreal QQStyleKitTextProperties::leftPadding() const
1973{
1974 return styleProperty<qreal>(QQSK::Property::LeftPadding, QQSK::Property::Padding);
1975}
1976
1977void QQStyleKitTextProperties::setLeftPadding(qreal padding)
1978{
1979 if (setStyleProperty(QQSK::Property::LeftPadding, padding))
1980 handleStylePropertyChanged(&QQStyleKitTextProperties::leftPaddingChanged);
1981}
1982
1983qreal QQStyleKitTextProperties::rightPadding() const
1984{
1985 return styleProperty<qreal>(QQSK::Property::RightPadding, QQSK::Property::Padding);
1986}
1987
1988void QQStyleKitTextProperties::setRightPadding(qreal padding)
1989{
1990 if (setStyleProperty(QQSK::Property::RightPadding, padding))
1991 handleStylePropertyChanged(&QQStyleKitTextProperties::rightPaddingChanged);
1992}
1993
1994qreal QQStyleKitTextProperties::topPadding() const
1995{
1996 return styleProperty<qreal>(QQSK::Property::TopPadding, QQSK::Property::Padding);
1997}
1998
1999void QQStyleKitTextProperties::setTopPadding(qreal padding)
2000{
2001 if (setStyleProperty(QQSK::Property::TopPadding, padding))
2002 handleStylePropertyChanged(&QQStyleKitTextProperties::topPaddingChanged);
2003}
2004
2005qreal QQStyleKitTextProperties::bottomPadding() const
2006{
2007 return styleProperty<qreal>(QQSK::Property::BottomPadding, QQSK::Property::Padding);
2008}
2009
2010void QQStyleKitTextProperties::setBottomPadding(qreal padding)
2011{
2012 if (setStyleProperty(QQSK::Property::BottomPadding, padding))
2013 handleStylePropertyChanged(&QQStyleKitTextProperties::bottomPaddingChanged);
2014}
2015
2016QQStyleKitTextProperties *QQStyleKitTextProperties::first() const
2017{
2018 return lazyCreateGroup(m_first, QQSK::PropertyGroup::DelegateSubtype1);
2019}
2020
2021QQStyleKitTextProperties *QQStyleKitTextProperties::second() const
2022{
2023 return lazyCreateGroup(m_second, QQSK::PropertyGroup::DelegateSubtype2);
2024}
2025
2026// ************* QQStyleKitControlProperties ****************
2027
2028QQStyleKitControlProperties::QQStyleKitControlProperties(QQSK::PropertyGroup group, QObject *parent)
2029 : QQStyleKitPropertyGroup(group, parent)
2030{
2031 /* Calculate the free space storage ID space that can accommodate all unique style
2032 * properties that may be applied to a control. Since we'll prepend different states
2033 * and subtypes during the property propagation lookup phase later, we need to reserve
2034 * ID space for them both already now. More docs about the property space is written in
2035 * the implementation of QQStyleKitPropertyPath. */
2036 m_groupSpace.size = nestedGroupsStartSize;
2037 m_groupSpace.start = 0;
2038
2039 if (group == QQSK::PropertyGroup::GlobalFlag) {
2040 /* A property path may include pseudo-groups that offers a convenient API for
2041 * reading properties with specific options applied. The 'global' group is one such
2042 * pseudo-group. When it is prefixed to a property path, it indicates that the property
2043 * should be read directly from the style, bypassing any active transitions that might
2044 * otherwise affect its value.
2045 * Note: The global group should be ignored when computing a PropertyPathId, as it
2046 * only affect _where_ the property should be read from, not its ID. */
2047 m_pathFlags.setFlag(QQSK::PropertyPathFlag::Global);
2048 }
2049}
2050
2051QQStyleKitStyle *QQStyleKitControlProperties::style() const
2052{
2053 if (subclass() == QQSK::Subclass::QQStyleKitState) {
2054 /* A QQStyleKitControlState (and its subclasses) should always be a (grand)child of a
2055 * QQStyleKitStyle. And it belongs to that style, even it that style is not the
2056 * currently active application style. This is opposed to a QQStyleKitReader,
2057 * that normally belongs / communicates with the currently active style.
2058 * NOTE: a style can also be a fallback style for another style (which can be recursive,
2059 * meaning that a fallback style can also have its own fallback style, and so on). But
2060 * this function will return the nearest style, and not the root style */
2061 QObject *obj = parent();
2062 while (obj && !obj->metaObject()->inherits(&QQStyleKitStyle::staticMetaObject))
2063 obj = obj->parent();
2064 return obj ? static_cast<QQStyleKitStyle *>(obj) : nullptr;
2065 }
2066
2067 if (subclass() == QQSK::Subclass::QQStyleKitReader) {
2068 const auto *reader = static_cast<const QQStyleKitReader *>(this);
2069 if (reader->m_explicitStyle)
2070 return reader->m_explicitStyle;
2071 }
2072
2073 // For a QQStyleKitReader without an explicit style, we return the currently active style for now
2074 return QQStyleKitStyle::current();
2075}
2076
2077QQSK::Subclass QQStyleKitControlProperties::subclass() const
2078{
2079 /* QQStyleKitControlProperties is subclassed by several different classes in this
2080 * framework. As such, it's basically just an interface because it only declares the
2081 * different properties that can be read or written to in a QQStyleKitStyle, such as
2082 * hovered.background.color or pressed.indicator.foreground.color. It says nothing
2083 * about how those properties are stored, instead that is up to each individual
2084 * subclass to decide */
2085 if (metaObject()->inherits(&QQStyleKitReader::staticMetaObject))
2086 return QQSK::Subclass::QQStyleKitReader;
2087 if (metaObject()->inherits(&QQStyleKitControlState::staticMetaObject))
2088 return QQSK::Subclass::QQStyleKitState;
2089 Q_UNREACHABLE();
2090}
2091
2092QQStyleKitReader *QQStyleKitControlProperties::asQQStyleKitReader() const
2093{
2094 Q_ASSERT(subclass() == QQSK::Subclass::QQStyleKitReader);
2095 return static_cast<QQStyleKitReader *>(const_cast<QQStyleKitControlProperties *>(this));
2096}
2097
2098QQStyleKitControlState *QQStyleKitControlProperties::asQQStyleKitState() const
2099{
2100 Q_ASSERT(subclass() == QQSK::Subclass::QQStyleKitState);
2101 Q_ASSERT(metaObject()->inherits(&QQStyleKitControlState::staticMetaObject));
2102 return static_cast<QQStyleKitControlState *>(const_cast<QQStyleKitControlProperties *>(this));
2103}
2104
2105void QQStyleKitControlProperties::forEachUsedDelegate(
2106 std::function<void (QQStyleKitDelegateProperties *, QQSK::Delegate, const QString &)> f)
2107{
2108 // If adding more delegates here, remember to keep StyleAnimation.qml in sync
2109 if (m_background)
2110 f(m_background, QQSK::Delegate::Background, "background"_L1);
2111
2112 if (m_indicator) {
2113 f(m_indicator, QQSK::Delegate::Indicator, "indicator"_L1);
2114 if (m_indicator->m_foreground)
2115 f(m_indicator->m_foreground, QQSK::Delegate::IndicatorForeground, "indicator.foreground"_L1);
2116 if (m_indicator->m_first) {
2117 f(m_indicator->m_first, QQSK::Delegate::IndicatorFirst, "indicator.first"_L1);
2118 if (m_indicator->m_first->m_foreground)
2119 f(m_indicator->m_first->m_foreground, QQSK::Delegate::IndicatorFirstForeground, "indicator.first.foreground"_L1);
2120 }
2121 if (m_indicator->m_second) {
2122 f(m_indicator->m_second, QQSK::Delegate::IndicatorSecond, "indicator.second"_L1);
2123 if (m_indicator->m_second->m_foreground)
2124 f(m_indicator->m_second->m_foreground, QQSK::Delegate::IndicatorSecondForeground, "indicator.second.foreground"_L1);
2125 }
2126 }
2127
2128 if (m_handle) {
2129 f(m_handle, QQSK::Delegate::Handle, "handle"_L1);
2130 if (m_handle->m_first)
2131 f(m_handle->m_first, QQSK::Delegate::HandleFirst, "handle.first"_L1);
2132 if (m_handle->m_second)
2133 f(m_handle->m_second, QQSK::Delegate::HandleSecond, "handle.second"_L1);
2134 }
2135}
2136
2137void QQStyleKitControlProperties::emitChangedForAllStyleProperties(EmitFlags emitFlags)
2138{
2139 /* This brute-force function will emit update signals for _all_ style properties
2140 * in the QQStyleKitStyle API. Doing so is typically needed after a style-, or theme
2141 * change, as we don't know which properties are affected by such a big change. */
2142 emitChangedForAllStylePropertiesRecursive(emitFlags);
2143}
2144
2145template <typename... CHANGED_SIGNALS>
2146void QQStyleKitControlProperties::emitGlobally(CHANGED_SIGNALS... changedSignals) const
2147{
2148 forEachRelevantStyleReader(asQQStyleKitState()->control(), [&](QQStyleKitReader *reader) {
2149 /* Since this function doesn't know exactly which properties have changed (we only
2150 * have the templated changedSignals), we need to brute-force clear all properties
2151 * from the readers local storage to ensure that stale values for all the affected
2152 * properties are removed. When we then emit the changed signals, the control that
2153 * uses the reader will end up reading the changed properties directly from the
2154 * style, since the local storage in the reader is empty. */
2155 reader->clearLocalStorage();
2156 ((reader->*changedSignals)(), ...);
2157 });
2158}
2159
2160void QQStyleKitControlProperties::forEachExistingNestedGroup(
2161 const std::function<void (QQStyleKitPropertyGroup *)> &f) const
2162{
2163 // Keep in sync with the nested groups this class creates with lazyCreateGroup()
2164 if (m_background)
2165 f(m_background);
2166 if (m_handle)
2167 f(m_handle);
2168 if (m_indicator)
2169 f(m_indicator);
2170 if (m_text)
2171 f(m_text);
2172}
2173
2174qreal QQStyleKitControlProperties::spacing() const
2175{
2176 return styleProperty<qreal>(QQSK::Property::Spacing);
2177}
2178
2179void QQStyleKitControlProperties::setSpacing(qreal spacing)
2180{
2181 if (setStyleProperty(QQSK::Property::Spacing, spacing))
2182 handleStylePropertyChanged(&QQStyleKitControlProperties::spacingChanged);
2183}
2184
2185qreal QQStyleKitControlProperties::padding() const
2186{
2187 return styleProperty<qreal>(QQSK::Property::Padding);
2188}
2189
2190void QQStyleKitControlProperties::setPadding(qreal padding)
2191{
2192 if (setStyleProperty(QQSK::Property::Padding, padding))
2193 handleStylePropertiesChanged<QQStyleKitControlProperties>(
2194 &QQStyleKitControlProperties::paddingChanged,
2195 &QQStyleKitControlProperties::leftPaddingChanged,
2196 &QQStyleKitControlProperties::rightPaddingChanged,
2197 &QQStyleKitControlProperties::topPaddingChanged,
2198 &QQStyleKitControlProperties::bottomPaddingChanged);
2199}
2200
2201qreal QQStyleKitControlProperties::leftPadding() const
2202{
2203 return styleProperty<qreal>(QQSK::Property::LeftPadding, QQSK::Property::Padding);
2204}
2205
2206void QQStyleKitControlProperties::setLeftPadding(qreal leftPadding)
2207{
2208 if (setStyleProperty(QQSK::Property::LeftPadding, leftPadding))
2209 handleStylePropertyChanged(&QQStyleKitControlProperties::leftPaddingChanged);
2210}
2211
2212qreal QQStyleKitControlProperties::rightPadding() const
2213{
2214 return styleProperty<qreal>(QQSK::Property::RightPadding, QQSK::Property::Padding);
2215}
2216
2217void QQStyleKitControlProperties::setRightPadding(qreal rightPadding)
2218{
2219 if (setStyleProperty(QQSK::Property::RightPadding, rightPadding))
2220 handleStylePropertyChanged(&QQStyleKitControlProperties::rightPaddingChanged);
2221}
2222
2223qreal QQStyleKitControlProperties::topPadding() const
2224{
2225 return styleProperty<qreal>(QQSK::Property::TopPadding, QQSK::Property::Padding);
2226}
2227
2228void QQStyleKitControlProperties::setTopPadding(qreal topPadding)
2229{
2230 if (setStyleProperty(QQSK::Property::TopPadding, topPadding))
2231 handleStylePropertyChanged(&QQStyleKitControlProperties::topPaddingChanged);
2232}
2233
2234qreal QQStyleKitControlProperties::bottomPadding() const
2235{
2236 return styleProperty<qreal>(QQSK::Property::BottomPadding, QQSK::Property::Padding);
2237}
2238
2239void QQStyleKitControlProperties::setBottomPadding(qreal bottomPadding)
2240{
2241 if (setStyleProperty(QQSK::Property::BottomPadding, bottomPadding))
2242 handleStylePropertyChanged(&QQStyleKitControlProperties::bottomPaddingChanged);
2243}
2244
2245QQuickTransition *QQStyleKitControlProperties::transition() const
2246{
2247 return styleProperty<QQuickTransition *>(QQSK::Property::Transition);
2248}
2249
2250void QQStyleKitControlProperties::setTransition(QQuickTransition *transition)
2251{
2252 if (setStyleProperty(QQSK::Property::Transition, transition))
2253 handleStylePropertyChanged(&QQStyleKitControlProperties::transitionChanged);
2254}
2255
2256QQStyleKitTextProperties *QQStyleKitControlProperties::text() const
2257{
2258 return lazyCreateGroup(m_text, QQSK::PropertyGroup::Text);
2259}
2260
2261QQStyleKitDelegateProperties *QQStyleKitControlProperties::background() const
2262{
2263 return lazyCreateGroup(m_background, QQSK::PropertyGroup::Background);
2264}
2265
2266QQStyleKitHandleProperties *QQStyleKitControlProperties::handle() const
2267{
2268 return lazyCreateGroup(m_handle, QQSK::PropertyGroup::Handle);
2269}
2270
2271QQStyleKitIndicatorWithSubTypes *QQStyleKitControlProperties::indicator() const
2272{
2273 return lazyCreateGroup(m_indicator, QQSK::PropertyGroup::Indicator);
2274}
2275
2276QT_END_NAMESPACE
2277
2278#include "moc_qqstylekitcontrolproperties_p.cpp"
T * lazyCreateGroup(T *const &ptr, QQSK::PropertyGroup group) const
void forEachRelevantStyleReader(const QQStyleKitControl *control, const std::function< void(QQStyleKitReader *reader)> &f) const
void handleStylePropertyChanged(void(SUBCLASS::*changedSignal)())
virtual void forEachExistingNestedGroup(const std::function< void(QQStyleKitPropertyGroup *)> &f) const
void handleStylePropertiesChanged(CHANGED_SIGNALS... changedSignals)
QQStyleKitControlProperties * controlProperties() const
Combined button and popup list for selecting options.
#define CONDITIONALLY_EMIT_SIGNALS_GLOBALLY_FOR(GROUP_PATH)