QGroundControl
Ground Control Station for MAVLink Drones
Loading...
Searching...
No Matches
FlightModeIndicator.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
9Item {
10 id: control
11 Layout.preferredWidth: mainLayout.width
12
13 property bool showIndicator: true
14 property bool waitForParameters: false
15
16 property real fontPointSize: ScreenTools.largeFontPointSize
17 property var activeVehicle: QGroundControl.multiVehicleManager.activeVehicle
18 property bool allowEditMode: true
19 property bool editMode: false
20
21 property bool _isVTOL: activeVehicle ? activeVehicle.vtol : false
22 property bool _vtolInFWDFlight: activeVehicle ? activeVehicle.vtolInFwdFlight : false
23 property var _vehicleInAir: activeVehicle ? activeVehicle.flying || activeVehicle.landing : false
24
25 QGCPalette { id: qgcPal }
26
27 RowLayout {
28 id: mainLayout
29 anchors.verticalCenter: parent.verticalCenter
30 spacing: ScreenTools.defaultFontPixelWidth / 2
31
32 QGCColoredImage {
33 id: flightModeIcon
34 Layout.preferredWidth: ScreenTools.defaultFontPixelWidth * 3
35 Layout.preferredHeight: ScreenTools.defaultFontPixelHeight
36 fillMode: Image.PreserveAspectFit
37 mipmap: true
38 color: qgcPal.text
39 source: "/qmlimages/FlightModesComponentIcon.png"
40 }
41
42 QGCLabel {
43 id: flightModeLabel
44 text: activeVehicle ? activeVehicle.flightMode : qsTr("N/A", "No data to display")
45 color: qgcPal.text
46 font.pointSize: fontPointSize
47
48 }
49
50 QGCLabel {
51 id: vtolModeLabel
52 Layout.alignment: Qt.AlignVCenter
53 horizontalAlignment: Text.AlignHCenter
54 text: _vtolInFWDFlight ? qsTr("FW\nVTOL") : qsTr("MR\nVTOL")
55 font.pointSize: ScreenTools.smallFontPointSize
56 wrapMode: Text.WordWrap
57 visible: _isVTOL
58 }
59 }
60
61 MouseArea {
62 anchors.fill: mainLayout
63 onClicked: mainWindow.showIndicatorDrawer(drawerComponent, control)
64 }
65
66 Component {
67 id: drawerComponent
68
69 ToolIndicatorPage {
70 showExpand: true
71 waitForParameters: false
72 expandedComponentWaitForParameters: true
73
74 contentComponent: flightModeContentComponent
75 expandedComponent: flightModeExpandedComponent
76
77 onExpandedChanged: {
78 if (!expanded) {
79 editMode = false
80 }
81 }
82 }
83 }
84
85 Component {
86 id: flightModeContentComponent
87
88 ColumnLayout {
89 id: modeColumn
90 spacing: ScreenTools.defaultFontPixelWidth / 2
91
92 property var activeVehicle: QGroundControl.multiVehicleManager.activeVehicle
93 property var flightModeSettings: QGroundControl.settingsManager.flightModeSettings
94 property var hiddenFlightModesFact: null
95 property var hiddenFlightModesList: []
96
97 Component.onCompleted: {
98 // Hidden flight modes are classified by firmware and vehicle class
99 var hiddenFlightModesPropPrefix
100 if (activeVehicle.px4Firmware) {
101 hiddenFlightModesPropPrefix = "px4HiddenFlightModes"
102 } else if (activeVehicle.apmFirmware) {
103 hiddenFlightModesPropPrefix = "apmHiddenFlightModes"
104 } else {
105 control.allowEditMode = false
106 }
107 if (control.allowEditMode) {
108 var hiddenFlightModesProp = hiddenFlightModesPropPrefix + activeVehicle.vehicleClassInternalName()
109 if (flightModeSettings.hasOwnProperty(hiddenFlightModesProp)) {
110 hiddenFlightModesFact = flightModeSettings[hiddenFlightModesProp]
111 // Split string into list of flight modes
112 if (hiddenFlightModesFact && hiddenFlightModesFact.value !== "") {
113 hiddenFlightModesList = hiddenFlightModesFact.value.split(",")
114 }
115 } else {
116 control.allowEditMode = false
117 }
118 }
119 hiddenModesLabel.calcVisible()
120 }
121
122 Connections {
123 target: control
124 function onEditModeChanged() {
125 if (editMode) {
126 for (var i=0; i<modeRepeater.count; i++) {
127 var button = modeRepeater.itemAt(i).children[0]
128 var checkBox = modeRepeater.itemAt(i).children[1]
129
130 checkBox.checked = !hiddenFlightModesList.find(item => { return item === button.text } )
131 }
132 }
133 }
134 }
135
136 QGCDelayButton {
137 id: vtolTransitionButton
138 Layout.fillWidth: true
139 text: _vtolInFWDFlight ? qsTr("Transition to Multi-Rotor") : qsTr("Transition to Fixed Wing")
140 visible: _isVTOL && _vehicleInAir
141
142 onActivated: {
143 _activeVehicle.vtolInFwdFlight = !_vtolInFWDFlight
144 mainWindow.closeIndicatorDrawer()
145 }
146 }
147
148 Repeater {
149 id: modeRepeater
150 model: activeVehicle ? activeVehicle.flightModes : []
151
152 RowLayout {
153 spacing: ScreenTools.defaultFontPixelWidth
154 visible: editMode || !hiddenFlightModesList.find(item => { return item === modelData } )
155
156 QGCDelayButton {
157 id: modeButton
158 text: modelData
159 delay: flightModeSettings.requireModeChangeConfirmation.rawValue ? defaultDelay : 0
160 Layout.fillWidth: true
161
162 onActivated: {
163 if (editMode) {
164 parent.children[1].toggle()
165 parent.children[1].clicked()
166 } else {
167 //var controller = globals.guidedControllerFlyView
168 //controller.confirmAction(controller.actionSetFlightMode, modelData)
169 activeVehicle.flightMode = modelData
170 mainWindow.closeIndicatorDrawer()
171 }
172 }
173 }
174
175 QGCCheckBoxSlider {
176 visible: editMode
177
178 onClicked: {
179 hiddenFlightModesList = []
180 for (var i=0; i<modeRepeater.count; i++) {
181 var checkBox = modeRepeater.itemAt(i).children[1]
182 if (!checkBox.checked) {
183 hiddenFlightModesList.push(modeRepeater.model[i])
184 }
185 }
186 hiddenFlightModesFact.value = hiddenFlightModesList.join(",")
187 hiddenModesLabel.calcVisible()
188 }
189 }
190 }
191 }
192
193 QGCLabel {
194 id: hiddenModesLabel
195 text: qsTr("Some Modes Hidden")
196 Layout.fillWidth: true
197 font.pointSize: ScreenTools.smallFontPointSize
198 horizontalAlignment: Text.AlignHCenter
199 visible: false
200
201 function calcVisible() {
202 hiddenModesLabel.visible = hiddenFlightModesList.length > 0
203 }
204 }
205 }
206 }
207
208 Component {
209 id: flightModeExpandedComponent
210
211 ColumnLayout {
212 Layout.preferredWidth: ScreenTools.defaultFontPixelWidth * 60
213 spacing: margins / 2
214
215 property var qgcPal: QGroundControl.globalPalette
216 property real margins: ScreenTools.defaultFontPixelHeight
217 property var flightModeSettings: QGroundControl.settingsManager.flightModeSettings
218
219 Loader {
220 Layout.fillWidth: true
221 source: _activeVehicle.expandedToolbarIndicatorSource("FlightMode")
222 }
223
224 SettingsGroupLayout {
225 Layout.fillWidth: true
226
227 FactCheckBoxSlider {
228 Layout.fillWidth: true
229 text: qsTr("Click and Hold to Confirm Mode Change")
230 fact: flightModeSettings.requireModeChangeConfirmation
231 }
232
233 RowLayout {
234 Layout.fillWidth: true
235 enabled: control.allowEditMode
236
237 QGCLabel {
238 Layout.fillWidth: true
239 text: qsTr("Edit Displayed Flight Modes")
240 }
241
242 QGCCheckBoxSlider {
243 onClicked: control.editMode = checked
244 }
245 }
246
247 LabelledButton {
248 Layout.fillWidth: true
249 label: qsTr("Flight Modes")
250 buttonText: qsTr("Configure")
251 visible: _activeVehicle.autopilotPlugin.knownVehicleComponentAvailable(AutoPilotPlugin.KnownFlightModesVehicleComponent) &&
252 QGroundControl.corePlugin.showAdvancedUI
253
254 onClicked: {
255 mainWindow.showKnownVehicleComponentConfigPage(AutoPilotPlugin.KnownFlightModesVehicleComponent)
256 mainWindow.closeIndicatorDrawer()
257 }
258 }
259 }
260 }
261 }
262}