QGroundControl
Ground Control Station for MAVLink Drones
Loading...
Searching...
No Matches
FactTextFieldSlider2.qml
Go to the documentation of this file.
1import QtQuick
2import QtQuick.Controls
3import QtQuick.Layouts
4
5import QGroundControl
6import QGroundControl.Controls
7import QGroundControl.FactControls
8
9Row {
10 id: sliderRoot
11 width: parent.width
12
13 property Fact fact: null
14 property var _factValue: fact ? fact.value : null
15 property bool _loadComplete: false
16
17 property real _range: Math.abs(fact.max - fact.min)
18 property real _minIncrement: _range/50
19 property int precision: 2
20
21 on_FactValueChanged: {
22 slide.value = fact.value
23 }
24
25 Component.onCompleted: {
26 slide.from = fact.min
27 slide.to = fact.max
28 slide.value = fact.value
29 _loadComplete = true
30 }
31
32 // Used to find width of value string
33 QGCLabel {
34 id: textMeasure
35 visible: false
36 text: fact.value.toFixed(precision)
37 }
38
39 // Param name, value, description and slider adjustment
40 Column {
41 id: sliderColumn
42 width: parent.width
43 spacing: _margins/2
44
45 // Param name and value
46 Row {
47 spacing: _margins
48
49 QGCLabel {
50 text: fact.name
51 font.bold: true
52 font.pointSize: ScreenTools.defaultFontPointSize * 1.1
53 anchors.verticalCenter: parent.verticalCenter
54 }
55
56 // Row container for Value: xx.xx +/- (different spacing than parent)
57 Row {
58 spacing: ScreenTools.defaultFontPixelWidth
59 anchors.verticalCenter: parent.verticalCenter
60
61 QGCLabel {
62 text: qsTr("Value: ")
63 anchors.verticalCenter: parent.verticalCenter
64 }
65
66 FactTextField {
67 anchors.verticalCenter: parent.verticalCenter
68 fact: sliderRoot.fact
69 showUnits: false
70 showHelp: false
71 text: fact.value.toFixed(precision)
72 width: textMeasure.width + ScreenTools.defaultFontPixelWidth*2 // Fudged, nothing else seems to work
73 }
74
75 QGCLabel {
76 text: fact.units
77 anchors.verticalCenter: parent.verticalCenter
78 }
79
80 QGCButton {
81 height: parent.height
82 width: height
83 text: "-"
84 anchors.verticalCenter: parent.verticalCenter
85
86 onClicked: fact.value = Math.max(Math.min(fact.value - _minIncrement, fact.max), fact.min)
87 }
88
89 QGCButton {
90 height: parent.height
91 width: height
92 text: "+"
93 anchors.verticalCenter: parent.verticalCenter
94
95 onClicked: fact.value = Math.max(Math.min(fact.value + _minIncrement, fact.max), fact.min)
96 }
97 } // Row - container for Value: xx.xx +/- (different spacing than parent)
98 } // Row - Param name and value
99
100 QGCLabel {
101 text: fact.shortDescription
102 }
103
104 // Slider, with minimum and maximum values labeled
105 Row {
106 width: parent.width
107 spacing: _margins
108
109 QGCLabel {
110 id: minLabel
111 width: ScreenTools.defaultFontPixelWidth * 10
112 text: fact.min.toFixed(precision)
113 horizontalAlignment: Text.AlignRight
114 }
115
116 QGCSlider {
117 id: slide
118 width: parent.width - minLabel.width - maxLabel.width - _margins * 2
119 stepSize: fact.increment ? Math.max(fact.increment, _minIncrement) : _minIncrement
120 mouseWheelSupport: false
121
122 onValueChanged: {
123 if (_loadComplete) {
124 if (Math.abs(fact.value - value) >= _minIncrement) { // prevent binding loop
125 fact.value = value
126 }
127 }
128 }
129 } // Slider
130
131 QGCLabel {
132 id: maxLabel
133 width: ScreenTools.defaultFontPixelWidth * 10
134 text: fact.max.toFixed(precision)
135 }
136 } // Row - Slider with minimum and maximum values labeled
137 } // Column - Param name, value, description and slider adjustment
138} // Row