QGroundControl
Ground Control Station for MAVLink Drones
Loading...
Searching...
No Matches
FactValueSlider.qml
Go to the documentation of this file.
1import QtQuick
2import QtQuick.Controls
3import QtQuick.Dialogs
4
5import QGroundControl
6import QGroundControl.Controls
7
8Rectangle {
9 height: _itemHeight
10 width: _totalSlots * _itemWidth
11 color: qgcPal.textField
12
13 property Fact fact: undefined
14 property int digitCount: 4 ///< The minimum number of digits to show for each value
15 property int incrementSlots: 1 ///< The number of visible slots to left/right of center value
16
17 property int _adjustedDigitCount: Math.max(digitCount, _model.initialValueAtPrecision.toString().length)
18 property int _totalDigitCount: _adjustedDigitCount + 1 + fact.units.length
19 property real _margins: (ScreenTools.implicitTextFieldHeight - ScreenTools.defaultFontPixelHeight) / 2
20 property real _increment: fact.increment
21 property real _value: fact.value
22 property int _decimalPlaces: fact.decimalPlaces
23 property string _units: fact.units
24 property real _prevValue: _value - _increment
25 property real _nextValue: _value + _increment
26 property real _itemWidth: (_totalDigitCount * ScreenTools.defaultFontPixelWidth) + (_margins * 2)
27 property real _itemHeight: ScreenTools.implicitTextFieldHeight
28 property var _valueModel
29 property int _totalSlots: (incrementSlots * 2) + 1
30 property int _currentIndex: _totalSlots / 2
31 property int _currentRelativeIndex: _currentIndex
32 property int _prevIncrementSlots: incrementSlots
33 property int _nextIncrementSlots: incrementSlots
34 property int _selectionWidth: 3
35 property var _model: fact.valueSliderModel()
36 property var _fact: fact
37
38 QGCPalette { id: qgcPal; colorGroupEnabled: parent.enabled }
39 QGCPalette { id: qgcPalDisabled; colorGroupEnabled: false }
40
41 function firstVisibleIndex() {
42 return valueListView.contentX / _itemWidth
43 }
44
45 function recalcRelativeIndex() {
46 _currentRelativeIndex = _currentIndex - firstVisibleIndex()
47 _prevIncrementSlots = _currentRelativeIndex
48 _nextIncrementSlots = _totalSlots - _currentRelativeIndex - 1
49 }
50
51 function reset() {
52 valueListView.positionViewAtIndex(0, ListView.Beginning)
53 _currentIndex = _model.resetInitialValue()
54 valueListView.positionViewAtIndex(_currentIndex, ListView.Center)
55 recalcRelativeIndex()
56 }
57
58 Component.onCompleted: {
59 valueListView.maximumFlickVelocity = valueListView.maximumFlickVelocity / 2
60 reset()
61 }
62
63 Connections {
64 target: _fact
65 onValueChanged: reset()
66 }
67
68 QGCPopupDialogFactory {
69 id: editDialogFactory
70
71 dialogComponent: editDialogComponent
72 }
73
74 Component {
75 id: editDialogComponent
76
77 ParameterEditorDialog {
78 fact: _fact
79 setFocus: ScreenTools.isMobile ? false : true // Works around strange android bug where wrong virtual keyboard is displayed
80 }
81 }
82
83 QGCListView {
84 id: valueListView
85 anchors.fill: parent
86 orientation: ListView.Horizontal
87 snapMode: ListView.SnapToItem
88 clip: true
89 model: _model
90
91 delegate: QGCLabel {
92 width: _itemWidth
93 height: _itemHeight
94 verticalAlignment: Text.AlignVCenter
95 horizontalAlignment: Text.AlignHCenter
96 text: value + " " + _units
97 color: qgcPal.textFieldText
98
99 MouseArea {
100 anchors.fill: parent
101 onClicked: {
102 valueListView.focus = true
103 if (_currentIndex === index) {
104 editDialogFactory.open({ title: qsTr("Value Details") })
105 } else {
106 _currentIndex = index
107 valueListView.positionViewAtIndex(_currentIndex, ListView.Center)
108 recalcRelativeIndex()
109 fact.value = value
110 }
111 }
112 }
113 }
114
115 onMovementStarted: valueListView.focus = true
116
117 onMovementEnded: {
118 _currentIndex = firstVisibleIndex() + _currentRelativeIndex
119 fact.value = _model.valueAtModelIndex(_currentIndex)
120 }
121 }
122
123 Rectangle {
124 id: leftOverlay
125 width: _itemWidth * _prevIncrementSlots
126 height: _itemHeight
127 color: qgcPal.textField
128 opacity: 0.5
129 }
130
131 Rectangle {
132 width: _itemWidth * _nextIncrementSlots
133 height: _itemHeight
134 anchors.right: parent.right
135 color: qgcPal.textField
136 opacity: 0.5
137 }
138
139 Rectangle {
140 x: _currentRelativeIndex * _itemWidth - _borderWidth
141 y: -_borderWidth
142 width: _itemWidth + (_borderWidth * 2)
143 height: _itemHeight + (_borderWidth * 2)
144 border.width: _borderWidth
145 border.color: qgcPal.brandingBlue
146 color: "transparent"
147
148 readonly property int _borderWidth: 3
149 }
150}