-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSlider.qml
More file actions
103 lines (79 loc) · 2.37 KB
/
Slider.qml
File metadata and controls
103 lines (79 loc) · 2.37 KB
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
import QtQuick 2.0
Rectangle {
id: slider
property alias text: titleText.text
width: root.buttonWidth
height: root.buttonHeight
color: "#555"
property real value: 0
property real maximum: typeof(max) === 'undefined' ? 100 : max
property real minimum: typeof(min) === 'undefined' ? 0 : min
onValueChanged: {
// console.log("onchange: " + value)
var intOnly = typeof(integerOnly) !== 'undefined' ?
integerOnly : false;
var act = action.arg(intOnly ? Math.round(value) : value);
console.log("Running cmd '" + act + "'");
// run action
root.runCommand(act);
}
Column {
anchors.fill: parent
anchors.margins: 10
spacing: 10
Text {
id: titleText
text: title
color: "white"
wrapMode: Text.WordWrap
font.pointSize: root.fontSize
}
Rectangle {
id: base
color: Qt.lighter(slider.color, 1.5)
width: parent.width
height: titleText.text.length > 0 ?
parent.height - titleText.height - parent.spacing :
parent.height
onWidthChanged: {
handle.x = (value/maximum) * base.width
}
Rectangle {
id: handle
color: "#333"
anchors.verticalCenter: parent.verticalCenter
width: 10
height: parent.height
onXChanged: {
if (x + width > base.width)
x = base.width - width;
if (x < 0)
x = 0;
}
}
Label {
id: valueLabel
text: Math.round(value)
}
}
}
MouseArea {
anchors.fill: parent
drag.target: handle
drag.axis: Drag.XAxis
drag.minimumX: 0
drag.maximumX: base.width - handle.width
onClicked: {
handle.x = mouse.x - handle.width;
updateValue();
}
onReleased: {
updateValue();
}
}
function updateValue() {
slider.value = (maximum - minimum) *
handle.x / (base.width - handle.width) +
minimum;
}
}