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: true // UI won't show until parameters are ready
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.windowTransparentText
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.windowTransparentText
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: control.waitForParameters
72
73 contentComponent: flightModeContentComponent
74 expandedComponent: flightModeExpandedComponent
75
76 onExpandedChanged: {
77 if (!expanded) {
78 editMode = false
79 }
80 }
81 }
82 }
83
84 Component {
85 id: flightModeContentComponent
86
87 ColumnLayout {
88 id: modeColumn
89 spacing: ScreenTools.defaultFontPixelWidth / 2
90
91 property var activeVehicle: QGroundControl.multiVehicleManager.activeVehicle
92 property var flightModeSettings: QGroundControl.settingsManager.flightModeSettings
93 property var hiddenFlightModesFact: null
94 property var hiddenFlightModesList: []
95
96 Component.onCompleted: {
97 // Hidden flight modes are classified by firmware and vehicle class
98 var hiddenFlightModesPropPrefix
99 if (activeVehicle.px4Firmware) {
100 hiddenFlightModesPropPrefix = "px4HiddenFlightModes"
101 } else if (activeVehicle.apmFirmware) {
102 hiddenFlightModesPropPrefix = "apmHiddenFlightModes"
103 } else {
104 control.allowEditMode = false
105 }
106 if (control.allowEditMode) {
107 var hiddenFlightModesProp = hiddenFlightModesPropPrefix + activeVehicle.vehicleClassInternalName()
108 if (flightModeSettings.hasOwnProperty(hiddenFlightModesProp)) {
109 hiddenFlightModesFact = flightModeSettings[hiddenFlightModesProp]
110 // Split string into list of flight modes
111 if (hiddenFlightModesFact && hiddenFlightModesFact.value !== "") {
112 hiddenFlightModesList = hiddenFlightModesFact.value.split(",")
113 }
114 } else {
115 control.allowEditMode = false
116 }
117 }
118 hiddenModesLabel.calcVisible()
119 }
120
121 Connections {
122 target: control
123 function onEditModeChanged() {
124 if (editMode) {
125 for (var i=0; i<modeRepeater.count; i++) {
126 var button = modeRepeater.itemAt(i).children[0]
127 var checkBox = modeRepeater.itemAt(i).children[1]
128
129 checkBox.checked = !hiddenFlightModesList.find(item => { return item === button.text } )
130 }
131 }
132 }
133 }
134
135 QGCDelayButton {
136 id: vtolTransitionButton
137 Layout.fillWidth: true
138 text: _vtolInFWDFlight ? qsTr("Transition to Multi-Rotor") : qsTr("Transition to Fixed Wing")
139 visible: _isVTOL && _vehicleInAir
140
141 onActivated: {
142 _activeVehicle.vtolInFwdFlight = !_vtolInFWDFlight
143 mainWindow.closeIndicatorDrawer()
144 }
145 }
146
147 Repeater {
148 id: modeRepeater
149 model: activeVehicle ? activeVehicle.flightModes : []
150
151 RowLayout {
152 spacing: ScreenTools.defaultFontPixelWidth
153 visible: editMode || !hiddenFlightModesList.find(item => { return item === modelData } )
154
155 QGCDelayButton {
156 id: modeButton
157 text: modelData
158 delay: flightModeSettings.requireModeChangeConfirmation.rawValue ? defaultDelay : 0
159 Layout.fillWidth: true
160
161 onActivated: {
162 if (editMode) {
163 parent.children[1].toggle()
164 parent.children[1].clicked()
165 } else {
166 //var controller = globals.guidedControllerFlyView
167 //controller.confirmAction(controller.actionSetFlightMode, modelData)
168 activeVehicle.flightMode = modelData
169 mainWindow.closeIndicatorDrawer()
170 }
171 }
172 }
173
174 QGCCheckBoxSlider {
175 visible: editMode
176
177 onClicked: {
178 hiddenFlightModesList = []
179 for (var i=0; i<modeRepeater.count; i++) {
180 var checkBox = modeRepeater.itemAt(i).children[1]
181 if (!checkBox.checked) {
182 hiddenFlightModesList.push(modeRepeater.model[i])
183 }
184 }
185 hiddenFlightModesFact.value = hiddenFlightModesList.join(",")
186 hiddenModesLabel.calcVisible()
187 }
188 }
189 }
190 }
191
192 QGCLabel {
193 id: hiddenModesLabel
194 text: qsTr("Some Modes Hidden")
195 Layout.fillWidth: true
196 font.pointSize: ScreenTools.smallFontPointSize
197 horizontalAlignment: Text.AlignHCenter
198 visible: false
199
200 function calcVisible() {
201 hiddenModesLabel.visible = hiddenFlightModesList.length > 0
202 }
203 }
204 }
205 }
206
207 Component {
208 id: flightModeExpandedComponent
209
210 ColumnLayout {
211 Layout.preferredWidth: ScreenTools.defaultFontPixelWidth * 60
212 spacing: margins / 2
213
214 property var qgcPal: QGroundControl.globalPalette
215 property real margins: ScreenTools.defaultFontPixelHeight
216 property var flightModeSettings: QGroundControl.settingsManager.flightModeSettings
217
218 Loader {
219 Layout.fillWidth: true
220 source: _activeVehicle.expandedToolbarIndicatorSource("FlightMode")
221 }
222
223 SettingsGroupLayout {
224 Layout.fillWidth: true
225
226 FactCheckBoxSlider {
227 Layout.fillWidth: true
228 text: qsTr("Click and Hold to Confirm Mode Change")
229 fact: flightModeSettings.requireModeChangeConfirmation
230 }
231
232 RowLayout {
233 Layout.fillWidth: true
234 enabled: control.allowEditMode
235
236 QGCLabel {
237 Layout.fillWidth: true
238 text: qsTr("Edit Displayed Flight Modes")
239 }
240
241 QGCCheckBoxSlider {
242 onClicked: control.editMode = checked
243 }
244 }
245
246 LabelledButton {
247 Layout.fillWidth: true
248 label: qsTr("Flight Modes")
249 buttonText: qsTr("Configure")
250 visible: _activeVehicle.autopilotPlugin.knownVehicleComponentAvailable(AutoPilotPlugin.KnownFlightModesVehicleComponent) &&
251 QGroundControl.corePlugin.showAdvancedUI
252
253 onClicked: {
254 mainWindow.showKnownVehicleComponentConfigPage(AutoPilotPlugin.KnownFlightModesVehicleComponent)
255 mainWindow.closeIndicatorDrawer()
256 }
257 }
258 }
259 }
260 }
261}