QGroundControl
Ground Control Station for MAVLink Drones
Loading...
Searching...
No Matches
AirframeComponent.qml
Go to the documentation of this file.
1import QtQuick
2import QtQuick.Controls
3import QtQuick.Dialogs
4import QtQuick.Layouts
5
6import QGroundControl
7import QGroundControl.FactControls
8import QGroundControl.Controls
9
10SetupPage {
11 id: airframePage
12 pageComponent: (controller && controller.showCustomConfigPanel) ? customFrame : pageComponent
13
14 readonly property string _unknownImage: "qrc:/qmlimages/Airframe/AirframeUnknown.svg"
15 // Keys match AirframeType::category
16 readonly property var _categoryKeys: [ "", "Copter", "Plane", "VTOL", "Rover", "Other" ]
17 readonly property var _categoryLabels: [ qsTr("All"), qsTr("Copter"), qsTr("Plane"), qsTr("VTOL"), qsTr("Rover"), qsTr("Other") ]
18 readonly property real _cardWidth: ScreenTools.defaultFontPixelWidth * 22
19 readonly property real _detailPanelWidth: ScreenTools.defaultFontPixelWidth * 40
20 // The airframe picker sits beside the cards when two card columns and the picker fit, otherwise it stacks below
21 readonly property bool _wide: availableWidth >= _cardWidth * 2 + _detailPanelWidth + _margins * 4
22
23 property int _categoryIndex: _currentCategoryIndex()
24 property var _selectedType: _typeByName(controller.currentAirframeType)
25 property var _pendingAirframe: null
26
27 readonly property var _currentType: _typeByName(controller.currentAirframeType)
28 readonly property var _visibleTypes: controller.airframeTypes.filter(type => _typeShown(type))
29 readonly property int _effectiveAutostartId: _pendingAirframe ? _pendingAirframe.autostartId : controller.currentAutostartId
30
31 function _typeByName(name) {
32 for (const type of controller.airframeTypes) {
33 if (type.name === name) {
34 return type
35 }
36 }
37 return null
38 }
39
40 function _currentCategoryIndex() {
41 const type = _typeByName(controller.currentAirframeType)
42 return type ? Math.max(_categoryKeys.indexOf(type.category), 0) : 0
43 }
44
45 function _categoryLabel(key) {
46 const index = _categoryKeys.indexOf(key)
47 return index > 0 ? _categoryLabels[index] : _categoryLabels[_categoryLabels.length - 1]
48 }
49
50 function _typeShown(type) {
51 const key = _categoryKeys[_categoryIndex]
52 return key === "" || type.category === key
53 }
54
55 function _pick(airframe) {
56 if (airframe.autostartId === controller.currentAutostartId) {
57 _clearPending()
58 return
59 }
60 _pendingAirframe = airframe
61 controller.autostartId = airframe.autostartId
62 }
63
64 function _clearPending() {
65 _pendingAirframe = null
66 controller.autostartId = controller.currentAutostartId
67 }
68
69 AirframeComponentController {
70 id: controller
71 }
72
73 QGCPalette {
74 id: qgcPal
75 }
76
77 Component {
78 id: customFrame
79 Column {
80 width: availableWidth
81 spacing: ScreenTools.defaultFontPixelHeight * 4
82 Item {
83 width: 1
84 height: 1
85 }
86 QGCLabel {
87 anchors.horizontalCenter: parent.horizontalCenter
88 width: parent.width * 0.5
89 height: ScreenTools.defaultFontPixelHeight * 4
90 wrapMode: Text.WordWrap
91 text: qsTr("Your vehicle is using a custom airframe configuration. ") +
92 qsTr("This configuration can only be modified through the Parameter Editor.\n\n") +
93 qsTr("If you want to reset your airframe configuration and select a standard configuration, click 'Reset' below.")
94 }
95 QGCButton {
96 text: qsTr("Reset")
97 enabled: sys_autostart
98 anchors.horizontalCenter: parent.horizontalCenter
99 property Fact sys_autostart: controller.getParameterFact(-1, "SYS_AUTOSTART")
100 onClicked: {
101 if(sys_autostart) {
102 sys_autostart.value = 0
103 }
104 }
105 }
106 }
107 }
108
109 component ImageWell: Rectangle {
110 property alias source: wellImage.source
111
112 radius: ScreenTools.defaultBorderRadius
113 color: "white" // The airframe artwork is black line art on white
114
115 Image {
116 id: wellImage
117 anchors.fill: parent
118 anchors.margins: parent.width * 0.06
119 fillMode: Image.PreserveAspectFit
120 smooth: true
121 mipmap: true
122 }
123 }
124
125 Component {
126 id: pageComponent
127
128 ColumnLayout {
129 width: Math.max(availableWidth, implicitWidth)
130 height: airframePage._wide ? Math.max(availableHeight, implicitHeight) : implicitHeight
131 spacing: _margins
132
133 ConfigRowsPanel {
134 RowLayout {
135 Layout.fillWidth: true
136 spacing: ScreenTools.defaultFontPixelWidth * 2
137
138 ImageWell {
139 Layout.preferredWidth: ScreenTools.defaultFontPixelHeight * 6
140 Layout.preferredHeight: Layout.preferredWidth
141 source: airframePage._currentType ? airframePage._currentType.imageResource : _unknownImage
142 }
143
144 ColumnLayout {
145 Layout.fillWidth: true
146 spacing: ScreenTools.defaultFontPixelHeight * 0.25
147
148 QGCLabel {
149 text: qsTr("Connected airframe")
150 font.pointSize: ScreenTools.smallFontPointSize
151 font.bold: true
152 font.capitalization: Font.AllUppercase
153 color: qgcPal.textSecondary
154 }
155
156 QGCLabel {
157 Layout.fillWidth: true
158 wrapMode: Text.WordWrap
159 font.bold: true
160 font.pointSize: ScreenTools.largeFontPointSize
161 text: airframePage._currentType ? controller.currentVehicleName : qsTr("Airframe is not set")
162 }
163
164 QGCLabel {
165 Layout.fillWidth: true
166 wrapMode: Text.WordWrap
167 font.family: airframePage._currentType ? ScreenTools.fixedFontFamily : ScreenTools.normalFontFamily
168 color: qgcPal.textSecondary
169 text: airframePage._currentType ?
170 qsTr("SYS_AUTOSTART %1 - %2").arg(controller.currentAutostartId).arg(controller.currentAirframeType) :
171 qsTr("Select a frame type below, then choose your airframe.")
172 }
173 }
174 }
175 }
176
177 ConfigRowsPanel {
178 ConfigRowsFilterBar {
179 objectName: "airframe_filter"
180 filterLabels: airframePage._categoryLabels
181 filterIndex: airframePage._categoryIndex
182 summary: qsTr("Showing %1 of %2 frame types.").arg(airframePage._visibleTypes.length).arg(controller.airframeTypes.length)
183 onFilterActivated: (index) => { airframePage._categoryIndex = index }
184 }
185 }
186
187 GridLayout {
188 Layout.fillWidth: true
189 Layout.fillHeight: airframePage._wide
190 columns: airframePage._wide ? 2 : 1
191 columnSpacing: _margins
192 rowSpacing: _margins
193
194 ConfigRowsPanel {
195 Layout.fillHeight: airframePage._wide
196
197 QGCLabel {
198 Layout.fillWidth: true
199 color: qgcPal.textSecondary
200 visible: airframePage._visibleTypes.length === 0
201 text: qsTr("No frame types match.")
202 }
203
204 QGCFlickable {
205 id: cardFlickable
206 Layout.fillWidth: true
207 Layout.fillHeight: airframePage._wide
208 Layout.preferredHeight: airframePage._wide ? -1 : contentHeight
209 contentWidth: width
210 contentHeight: cardFlow.height
211 interactive: airframePage._wide
212
213 Flow {
214 id: cardFlow
215 width: cardFlickable.width
216 spacing: _margins
217
218 Repeater {
219 model: airframePage._visibleTypes
220
221 Rectangle {
222 id: card
223 objectName: "airframeTypeBox_" + index
224 width: airframePage._cardWidth
225 implicitHeight: cardLayout.implicitHeight + _margins * 2
226 radius: ScreenTools.defaultBorderRadius * 2
227 color: airframeTypeSelected ? qgcPal.accentSubtle : qgcPal.windowCard
228 border.color: airframeTypeSelected || cardMouseArea.containsMouse ? qgcPal.accent : qgcPal.borderSubtle
229
230 required property var modelData
231 required property int index
232
233 property string airframeTypeName: modelData.name
234 property bool airframeTypeSelected: airframePage._selectedType === modelData
235
236 MouseArea {
237 id: cardMouseArea
238 anchors.fill: parent
239 hoverEnabled: true
240 onClicked: {
241 if (airframePage._selectedType !== card.modelData) {
242 airframePage._clearPending()
243 airframePage._selectedType = card.modelData
244 }
245 }
246 }
247
248 ColumnLayout {
249 id: cardLayout
250 anchors.fill: parent
251 anchors.margins: _margins
252 spacing: _margins / 2
253
254 ImageWell {
255 Layout.fillWidth: true
256 Layout.preferredHeight: ScreenTools.defaultFontPixelHeight * 6
257 source: card.modelData.imageResource
258
259 QGCChip {
260 x: _margins
261 y: _margins
262 text: qsTr("Current")
263 textColor: qgcPal.colorGreen
264 visible: card.modelData.name === controller.currentAirframeType
265 }
266 }
267
268 QGCLabel {
269 Layout.fillWidth: true
270 elide: Text.ElideRight
271 font.bold: true
272 text: card.modelData.name
273 }
274
275 QGCLabel {
276 color: qgcPal.textSecondary
277 font.pointSize: ScreenTools.smallFontPointSize
278 text: airframePage._categoryLabel(card.modelData.category) + " - " +
279 qsTr("%n airframe(s)", "", card.modelData.airframes.length)
280 }
281 }
282 }
283 }
284 }
285 }
286 }
287
288 ConfigRowsPanel {
289 Layout.fillWidth: !airframePage._wide
290 Layout.fillHeight: airframePage._wide
291 Layout.preferredWidth: airframePage._wide ? airframePage._detailPanelWidth : -1
292
293 ImageWell {
294 Layout.fillWidth: airframePage._wide
295 Layout.preferredWidth: airframePage._wide ? -1 : Layout.preferredHeight
296 Layout.preferredHeight: ScreenTools.defaultFontPixelHeight * 8
297 visible: airframePage._selectedType !== null
298 source: airframePage._selectedType ? airframePage._selectedType.imageResource : ""
299 }
300
301 QGCLabel {
302 Layout.fillWidth: true
303 wrapMode: Text.WordWrap
304 font.bold: true
305 font.capitalization: Font.AllUppercase
306 text: airframePage._selectedType ? airframePage._selectedType.name : qsTr("Airframes")
307 }
308
309 QGCLabel {
310 Layout.fillWidth: true
311 wrapMode: Text.WordWrap
312 color: qgcPal.textSecondary
313 text: airframePage._selectedType ?
314 airframePage._categoryLabel(airframePage._selectedType.category) + " - " +
315 qsTr("%n airframe(s)", "", airframePage._selectedType.airframes.length) :
316 qsTr("Select a frame type to choose an airframe.")
317 }
318
319 QGCFlickable {
320 id: optionFlickable
321 Layout.fillWidth: true
322 Layout.fillHeight: airframePage._wide
323 Layout.preferredHeight: airframePage._wide ? -1 : contentHeight
324 Layout.minimumHeight: airframePage._wide ? ScreenTools.defaultFontPixelHeight * 6 : 0
325 contentWidth: width
326 contentHeight: optionColumn.height
327 interactive: airframePage._wide
328
329 Column {
330 id: optionColumn
331 width: optionFlickable.width
332 spacing: _margins / 2
333
334 Repeater {
335 model: airframePage._selectedType ? airframePage._selectedType.airframes : []
336
337 Rectangle {
338 id: option
339 objectName: "airframeOption_" + index
340 width: optionColumn.width
341 height: optionRow.implicitHeight + _margins
342 radius: ScreenTools.defaultBorderRadius
343 color: checked ? qgcPal.accentSubtle : qgcPal.windowCard
344 border.color: checked || optionMouseArea.containsMouse ? qgcPal.accent : qgcPal.borderSubtle
345
346 required property var modelData
347 required property int index
348
349 readonly property int autostartId: modelData.autostartId
350 readonly property bool checked: autostartId === airframePage._effectiveAutostartId
351
352 MouseArea {
353 id: optionMouseArea
354 anchors.fill: parent
355 hoverEnabled: true
356 onClicked: airframePage._pick(option.modelData)
357 }
358
359 RowLayout {
360 id: optionRow
361 anchors.left: parent.left
362 anchors.right: parent.right
363 anchors.margins: _margins / 2
364 anchors.verticalCenter: parent.verticalCenter
365 spacing: _margins
366
367 QGCLabel {
368 Layout.fillWidth: true
369 wrapMode: Text.WordWrap
370 text: option.modelData.text
371 }
372
373 QGCChip {
374 text: qsTr("Current")
375 textColor: qgcPal.colorGreen
376 visible: option.autostartId === controller.currentAutostartId
377 }
378
379 QGCLabel {
380 font.family: ScreenTools.fixedFontFamily
381 font.pointSize: ScreenTools.smallFontPointSize
382 color: qgcPal.textSecondary
383 text: option.autostartId
384 }
385 }
386 }
387 }
388 }
389 }
390
391 QGCLabel {
392 objectName: "airframeSetup_pendingLabel"
393 Layout.fillWidth: true
394 wrapMode: Text.WordWrap
395 color: airframePage._pendingAirframe ? qgcPal.warningText : qgcPal.textSecondary
396 text: airframePage._pendingAirframe ?
397 qsTr("Selected: %1 (%2). Click 'Apply and Restart' to change the airframe.")
398 .arg(airframePage._pendingAirframe.text)
399 .arg(airframePage._pendingAirframe.autostartId) :
400 qsTr("Choose an airframe, then click 'Apply and Restart'.")
401 }
402
403 RowLayout {
404 Layout.fillWidth: true
405 spacing: _margins
406
407 Item {
408 Layout.fillWidth: true
409 }
410
411 QGCButton {
412 objectName: "airframeSetup_discardButton"
413 text: qsTr("Discard")
414 visible: airframePage._pendingAirframe !== null
415 onClicked: airframePage._clearPending()
416 }
417
418 QGCButton {
419 objectName: "airframeSetup_applyButton"
420 text: qsTr("Apply and Restart")
421 primary: true
422 visible: airframePage._pendingAirframe !== null
423 onClicked: QGroundControl.showMessageDialog(airframePage, qsTr("Apply and Restart"),
424 qsTr("Clicking 'Apply' will save the changes you have made to your airframe configuration.<br><br>\
425 All vehicle parameters other than Radio Calibration will be reset.<br><br>\
426 Your vehicle will also be restarted in order to complete the process."),
427 Dialog.Apply | Dialog.Cancel,
428 function() { controller.changeAutostart() })
429 }
430 }
431 }
432 }
433 }
434 }
435} // SetupPage