blob: 8ce306bbe4be0099f05684f40c27f518d723c191 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
|
// Copyright (C) 2025 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
// Qt-Security score:significant reason:default
import QtQuick
import QtQuick.Templates as T
import QtQuick.Controls.impl
import Qt.labs.StyleKit
import Qt.labs.StyleKit.impl
T.Switch {
id: control
implicitWidth: Math.max(implicitBackgroundWidth + leftInset + rightInset,
implicitContentWidth + leftPadding + rightPadding)
implicitHeight: Math.max(implicitBackgroundHeight + topInset + bottomInset,
implicitContentHeight + topPadding + bottomPadding,
implicitIndicatorHeight + topPadding + bottomPadding)
leftPadding: switchLayout.padding.left
topPadding: switchLayout.padding.top
rightPadding: switchLayout.padding.right
bottomPadding: switchLayout.padding.bottom
spacing: styleReader.spacing
StyleKitControl.controlType: styleReader.type
StyleKitReader {
id: styleReader
type: StyleKitReader.SwitchControl
enabled: control.enabled
focused: control.activeFocus
hovered: control.hovered
pressed: control.pressed
checked: control.checked
palette: control.palette
}
StyleKitLayout {
id: switchLayout
container: control
contentMargins {
left: styleReader.leftPadding
right: styleReader.rightPadding
top: styleReader.topPadding
bottom: styleReader.bottomPadding
}
layoutItems: [
// We don't lay out the contentItem here because it occupies the remaining space
// as calculated by control internal logic.
StyleKitLayoutItem {
id: indicatorItem
item: control.indicator
alignment: styleReader.indicator.alignment
margins.left: styleReader.indicator.leftMargin
margins.right: styleReader.indicator.rightMargin
margins.top: styleReader.indicator.topMargin
margins.bottom: styleReader.indicator.bottomMargin
fillWidth: styleReader.indicator.implicitWidth === Style.Stretch
fillHeight: styleReader.indicator.implicitHeight === Style.Stretch
}
]
spacing: styleReader.spacing
mirrored: control.mirrored
}
indicator: IndicatorDelegate {
parentControl: control
indicatorProperties: styleReader.indicator
x: indicatorItem.x
y: indicatorItem.y
width: indicatorItem.width
height: indicatorItem.height
HandleDelegate {
parentControl: control
handleProperties: styleReader.handle
x: control.checked
? indicator.width - width - styleReader.handle.rightMargin
: styleReader.handle.leftMargin
y: styleReader.handle.topMargin - styleReader.handle.bottomMargin
+ (indicator.height - height) / 2
z: 1
Behavior on x { NumberAnimation { duration: 50 } } // factor animation out to a style property!
}
}
contentItem: CheckLabel {
text: control.text
font: styleReader.font
color: styleReader.text.color
horizontalAlignment: styleReader.text.alignment & Qt.AlignHorizontal_Mask
verticalAlignment: styleReader.text.alignment & Qt.AlignVertical_Mask
}
background: BackgroundDelegate {
parentControl: control
backgroundProperties: styleReader.background
}
}
|