QGroundControl
Ground Control Station for MAVLink Drones
Loading...
Searching...
No Matches
ActuatorSlider.qml
Go to the documentation of this file.
1import QtQuick
2import QtQuick.Controls
3import QtQuick.Layouts
4
5import QGroundControl
6import QGroundControl.Controls
7
8Column {
9 property var channel
10 property alias value: channelSlider.value
11
12 // If the default value is NaN, we add a small range
13 // below, which snaps into place
14 property var snap: isNaN(channel.defaultValue)
15 property var span: channel.max - channel.min
16 property var snapRange: span * 0.15
17 property var defaultVal: snap ? channel.min - snapRange : channel.defaultValue
18 property var blockUpdates: true // avoid slider changes on startup
19
20 id: root
21
22 Layout.alignment: Qt.AlignTop
23
24 readonly property int _sliderHeight: 6
25
26 function stopTimer() {
27 sendTimer.stop();
28 }
29
30 function stop() {
31 channelSlider.value = defaultVal;
32 stopTimer();
33 }
34
35 signal actuatorValueChanged(real value, real sliderValue)
36
37 QGCSlider {
38 id: channelSlider
39 orientation: Qt.Vertical
40 from: snap ? channel.min - snapRange : channel.min
41 to: channel.max
42 stepSize: (channel.max-channel.min)/100
43 value: defaultVal
44 live: true
45 anchors.horizontalCenter: parent.horizontalCenter
46 height: ScreenTools.defaultFontPixelHeight * _sliderHeight
47
48 onValueChanged: {
49 if (blockUpdates)
50 return;
51 if (snap) {
52 if (value < channel.min) {
53 if (value < channel.min - snapRange/2) {
54 value = channel.min - snapRange;
55 } else {
56 value = channel.min;
57 }
58 }
59 }
60 sendTimer.start()
61 }
62
63 Timer {
64 id: sendTimer
65 interval: 50
66 triggeredOnStart: true
67 repeat: true
68 running: false
69 onTriggered: {
70 var sendValue = channelSlider.value;
71 if (sendValue < channel.min - snapRange/2) {
72 sendValue = channel.defaultValue;
73 }
74 root.actuatorValueChanged(sendValue, channelSlider.value)
75 }
76 }
77
78 Component.onCompleted: {
79 blockUpdates = false;
80 }
81 }
82
83 QGCLabel {
84 id: channelLabel
85 anchors.horizontalCenter: parent.horizontalCenter
86 text: channel.label
87 width: contentHeight
88 height: contentWidth
89 transform: [
90 Rotation { origin.x: 0; origin.y: 0; angle: -90 },
91 Translate { y: channelLabel.height + 5 }
92 ]
93 }
94} // Column