-
Notifications
You must be signed in to change notification settings - Fork 16
/
SwitchIndicator.qml
73 lines (58 loc) · 1.91 KB
/
SwitchIndicator.qml
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
// Copyright (C) 2017 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
import QtQuick
import QtQuick.Templates as T
import QtQuick.Controls.impl
Rectangle {
id: indicator
property T.AbstractButton control
implicitWidth: 40
implicitHeight: 16
radius: 2
border.color: Theme.colours.mid
gradient: Theme.controlBackgroundGradient
Rectangle {
x: indicator.control.mirrored ? handle.x : 0
width: indicator.control.mirrored ? parent.width - handle.x : handle.x + handle.width
height: parent.height
opacity: indicator.control.checked ? 1 : 0
Behavior on opacity {
enabled: !indicator.control.down
NumberAnimation { duration: 80 }
}
radius: 2
border.color: Theme.colours.mid
border.width: indicator.control.enabled ? 1 : 0
gradient: Theme.controlForegroundGradient
}
Rectangle {
id: handle
x: Math.max(0, Math.min(parent.width - width, indicator.control.visualPosition * parent.width - (width / 2)))
y: (parent.height - height) / 2
width: 20
height: 16
radius: 2
gradient: Theme.getForegroundGradient(control)
border.width: 1
border.color: "transparent"
Rectangle {
width: parent.width
height: parent.height
border.color: Theme.getForegroundColour(control)
color: "transparent"
radius: 2
Rectangle {
x: 1; y: 1
width: parent.width - 2
height: parent.height - 2
border.color: Theme.colours.mid
color: "transparent"
radius: 2
}
}
Behavior on x {
enabled: !indicator.control.down
SmoothedAnimation { velocity: 200 }
}
}
}