blob: cba135269fc8a05fa6f6d22bf7a245135bf4aacc (
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
|
// Copyright (C) 2018 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
import QtQuick 2.12
Item {
id: root
property int value: 50
property int maximumValue: 99
property alias label: label.text
property alias tapEnabled: tap.enabled
property alias pressed: tap.pressed
signal tapped
Rectangle {
id: slot
anchors.top: parent.top
anchors.bottom: parent.bottom
anchors.margins: 10
anchors.topMargin: 30
anchors.bottomMargin: 30
anchors.horizontalCenter: parent.horizontalCenter
width: 10
color: "black"
radius: width / 2
smooth: true
}
Rectangle {
id: glow
anchors.fill: knob
anchors.margins: -5
anchors.leftMargin: -2
anchors.horizontalCenterOffset: 1
radius: 5
color: "#4400FFFF"
opacity: tap.pressed || tapFlash.running ? 1 : 0
FlashAnimation on visible {
id: tapFlash
}
}
Rectangle {
id: knob
objectName: "Slider Knob"
width: parent.width - 2
height: 20
radius: 5
color: "darkgray"
border.color: "black"
property bool programmatic: false
property real multiplier: root.maximumValue / (dragHandler.yAxis.maximum - dragHandler.yAxis.minimum)
onYChanged: if (!programmatic) root.value = root.maximumValue - (knob.y - dragHandler.yAxis.minimum) * multiplier
transformOrigin: Item.Center
function setValue(value) { knob.y = dragHandler.yAxis.maximum - value / knob.multiplier }
DragHandler {
id: dragHandler
objectName: root.objectName + " DragHandler"
xAxis.enabled: false
yAxis.minimum: slot.y
yAxis.maximum: slot.height + slot.y - knob.height
}
TapHandler {
id: tap
objectName: root.objectName + " TapHandler"
gesturePolicy: TapHandler.DragThreshold
onTapped: {
tapFlash.start()
root.tapped
}
}
}
Text {
color: "red"
anchors.top: slot.bottom
anchors.horizontalCenter: parent.horizontalCenter
text: root.value
}
Text {
id: label
font.pointSize: 9
color: "red"
anchors.bottom: slot.top
anchors.bottomMargin: 5
anchors.horizontalCenter: parent.horizontalCenter
verticalAlignment: Text.AlignBottom
}
Component.onCompleted: {
knob.programmatic = true
knob.setValue(root.value)
knob.programmatic = false
}
}
|