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
4
5import QGroundControl
6import QGroundControl.FactControls
7import QGroundControl.Controls
8
9SetupPage {
10 id: airframePage
11 pageComponent: (controller && controller.showCustomConfigPanel) ? customFrame : pageComponent
12
13 AirframeComponentController {
14 id: controller
15 }
16
17 Component {
18 id: customFrame
19 Column {
20 width: availableWidth
21 spacing: ScreenTools.defaultFontPixelHeight * 4
22 Item {
23 width: 1
24 height: 1
25 }
26 QGCLabel {
27 anchors.horizontalCenter: parent.horizontalCenter
28 width: parent.width * 0.5
29 height: ScreenTools.defaultFontPixelHeight * 4
30 wrapMode: Text.WordWrap
31 text: qsTr("Your vehicle is using a custom airframe configuration. ") +
32 qsTr("This configuration can only be modified through the Parameter Editor.\n\n") +
33 qsTr("If you want to reset your airframe configuration and select a standard configuration, click 'Reset' below.")
34 }
35 QGCButton {
36 text: qsTr("Reset")
37 enabled: sys_autostart
38 anchors.horizontalCenter: parent.horizontalCenter
39 property Fact sys_autostart: controller.getParameterFact(-1, "SYS_AUTOSTART")
40 onClicked: {
41 if(sys_autostart) {
42 sys_autostart.value = 0
43 }
44 }
45 }
46 }
47 }
48
49 Component {
50 id: pageComponent
51
52 Column {
53 id: mainColumn
54 width: availableWidth
55
56 property real _minW: ScreenTools.defaultFontPixelWidth * 30
57 property real _boxWidth: _minW
58 property real _boxSpace: ScreenTools.defaultFontPixelWidth
59
60 readonly property real spacerHeight: ScreenTools.defaultFontPixelHeight
61
62 onWidthChanged: {
63 computeDimensions()
64 }
65
66 Component.onCompleted: computeDimensions()
67
68 function computeDimensions() {
69 var sw = 0
70 var rw = 0
71 var idx = Math.floor(mainColumn.width / (_minW + ScreenTools.defaultFontPixelWidth))
72 if(idx < 1) {
73 _boxWidth = mainColumn.width
74 _boxSpace = 0
75 } else {
76 _boxSpace = 0
77 if(idx > 1) {
78 _boxSpace = ScreenTools.defaultFontPixelWidth
79 sw = _boxSpace * (idx - 1)
80 }
81 rw = mainColumn.width - sw
82 _boxWidth = rw / idx
83 }
84 }
85
86 Item {
87 id: helpApplyRow
88 anchors.left: parent.left
89 anchors.right: parent.right
90 height: Math.max(helpText.contentHeight, applyButton.height)
91
92 QGCLabel {
93 id: helpText
94 width: parent.width - applyButton.width - 5
95 text: (controller.currentVehicleName != "" ?
96 qsTr("You've connected a %1.").arg(controller.currentVehicleName) :
97 qsTr("Airframe is not set.")) +
98 qsTr(" To change this configuration, select the desired airframe below then click 'Apply and Restart'.")
99 font.bold: true
100 wrapMode: Text.WordWrap
101 }
102
103 QGCButton {
104 id: applyButton
105 anchors.right: parent.right
106 text: qsTr("Apply and Restart")
107 onClicked: QGroundControl.showMessageDialog(airframePage, qsTr("Apply and Restart"),
108 qsTr("Clicking 'Apply' will save the changes you have made to your airframe configuration.<br><br>\
109 All vehicle parameters other than Radio Calibration will be reset.<br><br>\
110 Your vehicle will also be restarted in order to complete the process."),
111 Dialog.Apply | Dialog.Cancel,
112 function() { controller.changeAutostart() })
113
114 }
115 }
116
117 Item {
118 id: lastSpacer
119 height: parent.spacerHeight
120 width: 10
121 }
122
123 Flow {
124 id: flowView
125 width: parent.width
126 spacing: _boxSpace
127
128 ButtonGroup {
129 id: airframeTypeExclusive
130 }
131
132 Repeater {
133 model: controller.airframeTypes
134
135 // Outer summary item rectangle
136 Rectangle {
137 width: _boxWidth
138 height: ScreenTools.defaultFontPixelHeight * 14
139 color: qgcPal.window
140
141 readonly property real titleHeight: ScreenTools.defaultFontPixelHeight * 1.75
142 readonly property real innerMargin: ScreenTools.defaultFontPixelWidth
143
144 MouseArea {
145 anchors.fill: parent
146
147 onClicked: {
148 applyButton.primary = true
149 airframeCheckBox.checked = true
150 }
151 }
152
153 QGCLabel {
154 id: title
155 text: modelData.name
156 }
157
158 Rectangle {
159 anchors.topMargin: ScreenTools.defaultFontPixelHeight / 2
160 anchors.top: title.bottom
161 anchors.bottom: parent.bottom
162 anchors.left: parent.left
163 anchors.right: parent.right
164 color: airframeCheckBox.checked ? qgcPal.buttonHighlight : qgcPal.windowShade
165
166 Image {
167 id: image
168 anchors.margins: innerMargin
169 anchors.top: parent.top
170 anchors.bottom: combo.top
171 anchors.left: parent.left
172 anchors.right: parent.right
173 fillMode: Image.PreserveAspectFit
174 smooth: true
175 mipmap: true
176 source: modelData.imageResource
177 }
178
179 QGCCheckBox {
180 // Although this item is invisible we still use it to manage state
181 id: airframeCheckBox
182 checked: modelData.name === controller.currentAirframeType
183 buttonGroup: airframeTypeExclusive
184 visible: false
185
186 onCheckedChanged: {
187 if (checked && combo.currentIndex !== -1) {
188 console.log("check box change", combo.currentIndex)
189 controller.autostartId = modelData.airframes[combo.currentIndex].autostartId
190 }
191 }
192 }
193
194 QGCComboBox {
195 id: combo
196 objectName: modelData.airframeType + "ComboBox"
197 anchors.margins: innerMargin
198 anchors.bottom: parent.bottom
199 anchors.left: parent.left
200 anchors.right: parent.right
201 model: modelData.airframes
202 textRole: "text"
203
204 Component.onCompleted: {
205 if (airframeCheckBox.checked) {
206 currentIndex = controller.currentVehicleIndex
207 }
208 }
209
210 onActivated: (index) => {
211 applyButton.primary = true
212 airframeCheckBox.checked = true;
213 console.log("combo change", index)
214 controller.autostartId = modelData.airframes[index].autostartId
215 }
216 }
217 }
218 }
219 } // Repeater - summary boxes
220 } // Flow - summary boxes
221 } // Column
222 } // Component
223} // SetupPage