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 objectName: "airframeSetup_applyButton"
106 anchors.right: parent.right
107 text: qsTr("Apply and Restart")
108 onClicked: QGroundControl.showMessageDialog(airframePage, qsTr("Apply and Restart"),
109 qsTr("Clicking 'Apply' will save the changes you have made to your airframe configuration.<br><br>\
110 All vehicle parameters other than Radio Calibration will be reset.<br><br>\
111 Your vehicle will also be restarted in order to complete the process."),
112 Dialog.Apply | Dialog.Cancel,
113 function() { controller.changeAutostart() })
114
115 }
116 }
117
118 Item {
119 id: lastSpacer
120 height: parent.spacerHeight
121 width: 10
122 }
123
124 Flow {
125 id: flowView
126 width: parent.width
127 spacing: _boxSpace
128
129 ButtonGroup {
130 id: airframeTypeExclusive
131 }
132
133 Repeater {
134 model: controller.airframeTypes
135
136 // Outer summary item rectangle
137 Rectangle {
138 objectName: "airframeTypeBox_" + index
139 width: _boxWidth
140 height: ScreenTools.defaultFontPixelHeight * 14
141 color: qgcPal.window
142
143 property string airframeTypeName: modelData.name
144 property bool airframeTypeSelected: airframeCheckBox.checked
145
146 readonly property real titleHeight: ScreenTools.defaultFontPixelHeight * 1.75
147 readonly property real innerMargin: ScreenTools.defaultFontPixelWidth
148
149 MouseArea {
150 anchors.fill: parent
151
152 onClicked: {
153 applyButton.primary = true
154 airframeCheckBox.checked = true
155 }
156 }
157
158 QGCLabel {
159 id: title
160 text: modelData.name
161 }
162
163 Rectangle {
164 anchors.topMargin: ScreenTools.defaultFontPixelHeight / 2
165 anchors.top: title.bottom
166 anchors.bottom: parent.bottom
167 anchors.left: parent.left
168 anchors.right: parent.right
169 color: airframeCheckBox.checked ? qgcPal.buttonHighlight : qgcPal.windowShade
170
171 Image {
172 id: image
173 anchors.margins: innerMargin
174 anchors.top: parent.top
175 anchors.bottom: combo.top
176 anchors.left: parent.left
177 anchors.right: parent.right
178 fillMode: Image.PreserveAspectFit
179 smooth: true
180 mipmap: true
181 source: modelData.imageResource
182 }
183
184 QGCCheckBox {
185 // Although this item is invisible we still use it to manage state
186 id: airframeCheckBox
187 checked: modelData.name === controller.currentAirframeType
188 buttonGroup: airframeTypeExclusive
189 visible: false
190
191 onCheckedChanged: {
192 if (checked && combo.currentIndex !== -1) {
193 controller.autostartId = modelData.airframes[combo.currentIndex].autostartId
194 }
195 }
196 }
197
198 QGCComboBox {
199 id: combo
200 objectName: modelData.name + "ComboBox"
201 anchors.margins: innerMargin
202 anchors.bottom: parent.bottom
203 anchors.left: parent.left
204 anchors.right: parent.right
205 model: modelData.airframes
206 textRole: "text"
207
208 Component.onCompleted: {
209 if (airframeCheckBox.checked) {
210 currentIndex = controller.currentVehicleIndex
211 }
212 }
213
214 onActivated: (index) => {
215 applyButton.primary = true
216 airframeCheckBox.checked = true;
217 console.log("combo change", index)
218 controller.autostartId = modelData.airframes[index].autostartId
219 }
220 }
221 }
222 }
223 } // Repeater - summary boxes
224 } // Flow - summary boxes
225 } // Column
226 } // Component
227} // SetupPage