blob: 45aab5ed36e2b7fb0ea12240904dbbfdeda8fd2b (
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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
|
// Copyright (C) 2024 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.Controls.impl
import QtQuick.Controls.FluentWinUI3.impl as Impl
import QtQuick.Templates as T
T.Slider {
id: control
implicitWidth: Math.max(implicitBackgroundWidth + leftInset + rightInset,
implicitHandleWidth + leftPadding + rightPadding)
implicitHeight: Math.max(implicitBackgroundHeight + topInset + bottomInset,
implicitHandleHeight + topPadding + bottomPadding)
topPadding: horizontal ? __config.topPadding : __config.leftPadding || 0
leftPadding: horizontal ? __config.leftPadding : __config.bottomPadding || 0
rightPadding: horizontal ? __config.rightPadding : __config.topPadding || 0
bottomPadding: horizontal ? __config.bottomPadding : __config.rightPadding || 0
readonly property string __currentState: [
!control.enabled && "disabled",
control.enabled && !control.pressed && control.hovered && "hovered",
control.pressed && "pressed"
].filter(Boolean).join("_") || "normal"
readonly property var __config: Config.controls.slider[__currentState] || {}
readonly property Item __focusFrameTarget: control
readonly property real __steps: Math.abs(to - from) / stepSize
readonly property bool __isDiscrete: stepSize >= Number.EPSILON
&& Math.abs(Math.round(__steps) - __steps) < Number.EPSILON
readonly property bool __isHighContrast: Application.styleHints.accessibility.contrastPreference === Qt.HighContrast
handle: ItemGroup {
x: Math.round(control.leftPadding + (control.horizontal
? control.visualPosition * (control.availableWidth - width)
: (control.availableWidth - width) / 2))
y: Math.round(control.topPadding + (control.horizontal
? (control.availableHeight - height) / 2
: control.visualPosition * (control.availableHeight - height)))
Impl.StyleImage {
visible: !control.__isHighContrast
imageConfig: control.__config.handle
}
Rectangle {
visible: control.__isHighContrast
implicitWidth: control.__config.handle.width
implicitHeight: control.__config.handle.height
color: control.palette.buttonText
radius: width / 2
}
property HoverHandler _hoverHandler: HoverHandler {
parent: control.handle
target: control.handle
}
property Rectangle indicator: Rectangle {
property real diameter: !control.enabled ? 10
: control.pressed ? 8
: control.__isHighContrast && !control.hovered ? 0
: control.handle?._hoverHandler.hovered ? 14 : 10
parent: control.handle
width: diameter
height: diameter
radius: diameter * 0.5
x: (control.__config.handle.width - width) / 2
y: (control.__config.handle.height - height) / 2
color: control.enabled ? (control.hovered ? Qt.rgba(control.palette.accent.r, control.palette.accent.g, control.palette.accent.b, 0.9020)
: control.pressed ? Qt.rgba(control.palette.accent.r, control.palette.accent.g, control.palette.accent.b, 0.8)
: control.palette.accent)
: control.palette.accent
Behavior on diameter {
// From WindowsUI 3 Animation Values
NumberAnimation {
duration: 167
easing.type: Easing.OutCubic
}
}
}
}
background: Item {
implicitWidth: control.horizontal
? (control.__config.groove.width)
: (control.__config.groove.height)
implicitHeight: control.horizontal
? (control.__config.groove.height)
: (control.__config.groove.width)
property Item _background: Impl.StyleImage {
visible: !control.__isHighContrast
parent: control.background
width: parent.width
height: parent.height
imageConfig: control.__config.background
property Item groove: Impl.StyleImage {
parent: control.background._background
x: control.leftPadding - control.leftInset + (control.horizontal
? control.__config.handle.width / 2
: (control.availableWidth - width) / 2)
y: control.topPadding - control.topInset + (control.horizontal
? ((control.availableHeight - height) / 2)
: control.__config.handle.height / 2)
width: control.horizontal
? control.availableWidth - control.__config.handle.width
: implicitWidth
height: control.horizontal
? implicitHeight
: control.availableHeight - control.__config.handle.width
imageConfig: control.__config.groove
horizontal: control.horizontal
property Rectangle track: Rectangle {
parent: control.background._background.groove
y: control.horizontal ? 0 : parent.height - (parent.height * control.position)
implicitWidth: control.horizontal ? control.__config.track.width : control.__config.track.height
implicitHeight: control.horizontal ? control.__config.track.height : control.__config.track.width
width: control.horizontal ? parent.width * control.position : parent.width
height: control.horizontal ? parent.height : parent.height * control.position
radius: control.__config.track.height * 0.5
color: control.palette.accent
}
}
property Repeater ticksTop: Repeater {
parent: control.__isHighContrast ? control.background._highContrastBackground : control.background._background.groove
model: control.__isDiscrete ? Math.floor(control.__steps) + 1 : 0
delegate: Rectangle {
width: control.horizontal ? 1 : 4
height: control.horizontal ? 4 : 1
x: control.horizontal
? 6 + index * (parent.width - 2 * 6 - width) / (control.background._background.ticksTop.model - 1)
: -4 - width
y: control.horizontal
? -4 - height
: 6 + index * (parent.height - 2 * 6 - height) / (control.background._background.ticksTop.model - 1)
color: Application.styleHints.colorScheme == Qt.Light ? "#9C000000" : "#9AFFFFFF"
required property int index
}
}
property Repeater ticksBottom: Repeater {
parent: control.__isHighContrast ? control.background._highContrastBackground : control.background._background.groove
model: control.__isDiscrete ? Math.floor(control.__steps) + 1 : 0
delegate: Rectangle {
width: control.horizontal ? 1 : 4
height: control.horizontal ? 4 : 1
x: control.horizontal
? 6 + index * (parent.width - 2 * 6 - width) / (control.background._background.ticksBottom.model - 1)
: parent.width + 4
y: control.horizontal
? parent.height + 4
: 6 + index * (parent.height - 2 * 6 - height) / (control.background._background.ticksBottom.model - 1)
color: Application.styleHints.colorScheme == Qt.Light ? "#9C000000" : "#9AFFFFFF"
required property int index
}
}
}
property Item _highContrastBackground: Rectangle {
parent: control.background
visible: control.__isHighContrast
implicitWidth: control.horizontal ? 200 : 4
implicitHeight: control.horizontal ? 4 : 200
x: control.leftPadding - control.leftInset + (control.horizontal
? control.__config.handle.width / 2
: (control.availableWidth - width) / 2)
y: control.topPadding - control.topInset + (control.horizontal
? ((control.availableHeight - height) / 2)
: control.__config.handle.height / 2)
width: control.horizontal
? control.availableWidth - control.__config.handle.width
: implicitWidth
height: control.horizontal
? implicitHeight
: control.availableHeight - control.__config.handle.width
radius: 2
color: control.palette.buttonText
scale: control.horizontal && control.mirrored ? -1 : 1
Rectangle {
y: control.horizontal ? 0 : parent.height - (parent.height * control.position)
implicitWidth: control.horizontal ? parent.width * control.position : parent.width
implicitHeight: control.horizontal ? parent.height : parent.height * control.position
radius: 2
color: control.palette.highlight
}
}
}
}
|