blob: e439bc31b7be054ab5b1d77a5d44d575c159a326 (
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
|
// 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.Material
import QtQuick.Controls.Material.impl
Item {
id: indicator
implicitWidth: 38
implicitHeight: 32
property T.AbstractButton control
property alias handle: handle
Material.elevation: 1
Rectangle {
width: parent.width
height: 14
radius: height / 2
y: parent.height / 2 - height / 2
color: indicator.control.enabled ? (indicator.control.checked ? indicator.control.Material.switchCheckedTrackColor : indicator.control.Material.switchUncheckedTrackColor)
: indicator.control.Material.switchDisabledTrackColor
}
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: 20
radius: width / 2
color: indicator.control.enabled ? (indicator.control.checked ? indicator.control.Material.switchCheckedHandleColor : indicator.control.Material.switchUncheckedHandleColor)
: indicator.control.Material.switchDisabledHandleColor
Behavior on x {
enabled: !indicator.control.pressed
SmoothedAnimation {
duration: 300
}
}
layer.enabled: indicator.Material.elevation > 0
layer.effect: ElevationEffect {
elevation: indicator.Material.elevation
}
}
}
|