7import QGroundControl.FactControls
8import QGroundControl.Controls
12 pageComponent: (controller && controller.showCustomConfigPanel) ? customFrame : pageComponent
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
23 property int _categoryIndex: _currentCategoryIndex()
24 property var _selectedType: _typeByName(controller.currentAirframeType)
25 property var _pendingAirframe: null
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
31 function _typeByName(name) {
32 for (const type of controller.airframeTypes) {
33 if (type.name === name) {
40 function _currentCategoryIndex() {
41 const type = _typeByName(controller.currentAirframeType)
42 return type ? Math.max(_categoryKeys.indexOf(type.category), 0) : 0
45 function _categoryLabel(key) {
46 const index = _categoryKeys.indexOf(key)
47 return index > 0 ? _categoryLabels[index] : _categoryLabels[_categoryLabels.length - 1]
50 function _typeShown(type) {
51 const key = _categoryKeys[_categoryIndex]
52 return key === "" || type.category === key
55 function _pick(airframe) {
56 if (airframe.autostartId === controller.currentAutostartId) {
60 _pendingAirframe = airframe
61 controller.autostartId = airframe.autostartId
64 function _clearPending() {
65 _pendingAirframe = null
66 controller.autostartId = controller.currentAutostartId
69 AirframeComponentController {
81 spacing: ScreenTools.defaultFontPixelHeight * 4
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.")
97 enabled: sys_autostart
98 anchors.horizontalCenter: parent.horizontalCenter
99 property Fact sys_autostart: controller.getParameterFact(-1, "SYS_AUTOSTART")
102 sys_autostart.value = 0
109 component ImageWell: Rectangle {
110 property alias source: wellImage.source
112 radius: ScreenTools.defaultBorderRadius
113 color: "white" // The airframe artwork is black line art on white
118 anchors.margins: parent.width * 0.06
119 fillMode: Image.PreserveAspectFit
129 width: Math.max(availableWidth, implicitWidth)
130 height: airframePage._wide ? Math.max(availableHeight, implicitHeight) : implicitHeight
135 Layout.fillWidth: true
136 spacing: ScreenTools.defaultFontPixelWidth * 2
139 Layout.preferredWidth: ScreenTools.defaultFontPixelHeight * 6
140 Layout.preferredHeight: Layout.preferredWidth
141 source: airframePage._currentType ? airframePage._currentType.imageResource : _unknownImage
145 Layout.fillWidth: true
146 spacing: ScreenTools.defaultFontPixelHeight * 0.25
149 text: qsTr("Connected airframe")
150 font.pointSize: ScreenTools.smallFontPointSize
152 font.capitalization: Font.AllUppercase
153 color: qgcPal.textSecondary
157 Layout.fillWidth: true
158 wrapMode: Text.WordWrap
160 font.pointSize: ScreenTools.largeFontPointSize
161 text: airframePage._currentType ? controller.currentVehicleName : qsTr("Airframe is not set")
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.")
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 }
188 Layout.fillWidth: true
189 Layout.fillHeight: airframePage._wide
190 columns: airframePage._wide ? 2 : 1
191 columnSpacing: _margins
195 Layout.fillHeight: airframePage._wide
198 Layout.fillWidth: true
199 color: qgcPal.textSecondary
200 visible: airframePage._visibleTypes.length === 0
201 text: qsTr("No frame types match.")
206 Layout.fillWidth: true
207 Layout.fillHeight: airframePage._wide
208 Layout.preferredHeight: airframePage._wide ? -1 : contentHeight
210 contentHeight: cardFlow.height
211 interactive: airframePage._wide
215 width: cardFlickable.width
219 model: airframePage._visibleTypes
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
230 required property var modelData
231 required property int index
233 property string airframeTypeName: modelData.name
234 property bool airframeTypeSelected: airframePage._selectedType === modelData
241 if (airframePage._selectedType !== card.modelData) {
242 airframePage._clearPending()
243 airframePage._selectedType = card.modelData
251 anchors.margins: _margins
252 spacing: _margins / 2
255 Layout.fillWidth: true
256 Layout.preferredHeight: ScreenTools.defaultFontPixelHeight * 6
257 source: card.modelData.imageResource
262 text: qsTr("Current")
263 textColor: qgcPal.colorGreen
264 visible: card.modelData.name === controller.currentAirframeType
269 Layout.fillWidth: true
270 elide: Text.ElideRight
272 text: card.modelData.name
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)
289 Layout.fillWidth: !airframePage._wide
290 Layout.fillHeight: airframePage._wide
291 Layout.preferredWidth: airframePage._wide ? airframePage._detailPanelWidth : -1
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 : ""
302 Layout.fillWidth: true
303 wrapMode: Text.WordWrap
305 font.capitalization: Font.AllUppercase
306 text: airframePage._selectedType ? airframePage._selectedType.name : qsTr("Airframes")
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.")
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
326 contentHeight: optionColumn.height
327 interactive: airframePage._wide
331 width: optionFlickable.width
332 spacing: _margins / 2
335 model: airframePage._selectedType ? airframePage._selectedType.airframes : []
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
346 required property var modelData
347 required property int index
349 readonly property int autostartId: modelData.autostartId
350 readonly property bool checked: autostartId === airframePage._effectiveAutostartId
356 onClicked: airframePage._pick(option.modelData)
361 anchors.left: parent.left
362 anchors.right: parent.right
363 anchors.margins: _margins / 2
364 anchors.verticalCenter: parent.verticalCenter
368 Layout.fillWidth: true
369 wrapMode: Text.WordWrap
370 text: option.modelData.text
374 text: qsTr("Current")
375 textColor: qgcPal.colorGreen
376 visible: option.autostartId === controller.currentAutostartId
380 font.family: ScreenTools.fixedFontFamily
381 font.pointSize: ScreenTools.smallFontPointSize
382 color: qgcPal.textSecondary
383 text: option.autostartId
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'.")
404 Layout.fillWidth: true
408 Layout.fillWidth: true
412 objectName: "airframeSetup_discardButton"
413 text: qsTr("Discard")
414 visible: airframePage._pendingAirframe !== null
415 onClicked: airframePage._clearPending()
419 objectName: "airframeSetup_applyButton"
420 text: qsTr("Apply and Restart")
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() })