-
-
Notifications
You must be signed in to change notification settings - Fork 5k
Expand file tree
/
Copy pathAM32SettingSlider.qml
More file actions
92 lines (78 loc) · 2.87 KB
/
Copy pathAM32SettingSlider.qml
File metadata and controls
92 lines (78 loc) · 2.87 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
import QtQuick
import QtQuick.Controls
import QGroundControl
import QGroundControl.Controls
Column {
id: control
property string label: ""
property var setting: null
property var fact: setting ? setting.fact : null
property real value: fact ? fact.rawValue : 0
property real from: fact ? fact.min : 0
property real to: fact ? fact.max : 100
// fact.increment may be NaN if not set - default to 1
property real stepSize: (fact && !isNaN(fact.increment)) ? fact.increment : 1
property int decimalPlaces: fact ? fact.decimalPlaces : 0
property bool enabled: true
signal userValueChanged(real newValue)
spacing: ScreenTools.defaultFontPixelHeight / 4
QGCLabel {
text: label + (setting && setting.hasPendingChanges ? " *" : "")
color: setting && setting.hasPendingChanges ? qgcPal.colorOrange : qgcPal.text
anchors.horizontalCenter: parent.horizontalCenter
}
Slider {
id: slider
width: ScreenTools.defaultFontPixelWidth * 28
from: parent.from
to: parent.to
value: parent.value
stepSize: parent.stepSize
snapMode: Slider.SnapAlways
enabled: parent.enabled
onMoved: control.userValueChanged(value)
onPressedChanged: if (!pressed) value = Qt.binding(function() { return control.value })
// Visual handle
handle: Rectangle {
x: slider.leftPadding + slider.visualPosition * (slider.availableWidth - width)
y: slider.topPadding + slider.availableHeight / 2 - height / 2
implicitWidth: ScreenTools.defaultFontPixelHeight
implicitHeight: implicitWidth
radius: width / 2
color: slider.pressed ? qgcPal.buttonHighlight : qgcPal.button
border.color: qgcPal.text
}
// Value display
ToolTip {
parent: slider.handle
visible: slider.pressed
text: slider.value.toFixed(decimalPlaces)
}
// Slider fill direction (left to right)
background: Rectangle {
x: slider.leftPadding
y: slider.topPadding + slider.availableHeight / 2 - height / 2
implicitWidth: 200
implicitHeight: 4
width: slider.availableWidth
height: implicitHeight
radius: 2
color: qgcPal.window
border.color: qgcPal.text
border.width: 1
// Progress fill from left to right
Rectangle {
width: slider.visualPosition * parent.width
height: parent.height
color: qgcPal.text
radius: parent.radius
}
}
}
// Value label
QGCLabel {
text: value.toFixed(decimalPlaces)
anchors.horizontalCenter: parent.horizontalCenter
font.pointSize: ScreenTools.smallFontPointSize
}
}