QGroundControl
Ground Control Station for MAVLink Drones
Loading...
Searching...
No Matches
APMAirframeComponent.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: pageComponent
13
14 Component {
15 id: pageComponent
16
17 ColumnLayout {
18 id: mainColumn
19 width: availableWidth
20
21 property real _minW: ScreenTools.defaultFontPixelWidth * 20
22 property real _boxWidth: _minW
23 property real _boxSpace: ScreenTools.defaultFontPixelWidth
24 property real _margins: ScreenTools.defaultFontPixelWidth
25 property Fact _frameClass: controller.getParameterFact(-1, "FRAME_CLASS")
26 property Fact _frameType: controller.getParameterFact(-1, "FRAME_TYPE", false) // FRAME_TYPE is not available on all Rover versions
27 property bool _frameTypeAvailable: controller.vehicle.multiRotor
28
29 readonly property real spacerHeight: ScreenTools.defaultFontPixelHeight
30
31 onWidthChanged: computeDimensions()
32 Component.onCompleted: computeDimensions()
33
34 function computeDimensions() {
35 var sw = 0
36 var rw = 0
37 var idx = Math.floor(mainColumn.width / (_minW + ScreenTools.defaultFontPixelWidth))
38 if(idx < 1) {
39 _boxWidth = mainColumn.width
40 _boxSpace = 0
41 } else {
42 _boxSpace = 0
43 if(idx > 1) {
44 _boxSpace = ScreenTools.defaultFontPixelWidth
45 sw = _boxSpace * (idx - 1)
46 }
47 rw = mainColumn.width - sw
48 _boxWidth = rw / idx
49 }
50 }
51
52 APMAirframeComponentController { id: controller; }
53
54 QGCLabel {
55 id: helpText
56 Layout.fillWidth: true
57 text: (_frameClass.rawValue === 0 ?
58 qsTr("Airframe is currently not set.") :
59 qsTr("Currently set to frame class '%1'").arg(_frameClass.enumStringValue) +
60 (_frameTypeAvailable ? qsTr(" and frame type '%2'").arg(_frameType.enumStringValue) : "") +
61 qsTr(".", "period for end of sentence")) +
62 qsTr(" To change this configuration, select the desired frame class below and then reboot the vehicle.")
63 font.bold: true
64 wrapMode: Text.WordWrap
65 }
66
67 Item {
68 id: lastSpacer
69 height: parent.spacerHeight
70 width: 10
71 }
72
73 Flow {
74 id: flowView
75 Layout.fillWidth: true
76 spacing: _boxSpace
77
78 ButtonGroup {
79 id: airframeTypeExclusive
80 }
81
82 Repeater {
83 model: controller.frameClassModel
84
85 // Outer summary item rectangle
86 Rectangle {
87 id: outerRect
88 width: _boxWidth
89 height: ScreenTools.defaultFontPixelHeight * 14
90 color: qgcPal.window
91
92 readonly property real titleHeight: ScreenTools.defaultFontPixelHeight * 1.75
93 readonly property real innerMargin: ScreenTools.defaultFontPixelWidth
94
95 MouseArea {
96 anchors.fill: parent
97 onClicked: {
98 if (!airframeCheckBox.checked || !combo.valid) {
99 if (_frameTypeAvailable && object.defaultFrameType != -1) {
100 _frameType.rawValue = object.defaultFrameType
101 }
102 airframeCheckBox.checked = true
103 }
104 }
105 }
106
107 QGCLabel {
108 id: title
109 text: object.name
110 }
111
112 Rectangle {
113 id: imageComboRect
114 anchors.topMargin: ScreenTools.defaultFontPixelHeight / 2
115 anchors.top: title.bottom
116 anchors.bottom: parent.bottom
117 anchors.left: parent.left
118 anchors.right: parent.right
119 color: airframeCheckBox.checked ? qgcPal.buttonHighlight : qgcPal.windowShade
120 opacity: combo.valid ? 1.0 : 0.5
121
122 ColumnLayout {
123 anchors.margins: innerMargin
124 anchors.fill: parent
125 spacing: innerMargin
126
127 Image {
128 id: image
129 Layout.fillWidth: true
130 Layout.fillHeight: true
131 fillMode: Image.PreserveAspectFit
132 smooth: true
133 antialiasing: true
134 sourceSize.width: width
135 source: airframeCheckBox.checked ? object.imageResource : object.imageResourceDefault
136 }
137
138 QGCCheckBox {
139 // Although this item is invisible we still use it to manage state
140 id: airframeCheckBox
141 checked: object.frameClass === _frameClass.rawValue
142 buttonGroup: airframeTypeExclusive
143 visible: false
144
145 onCheckedChanged: {
146 if (checked) {
147 _frameClass.rawValue = object.frameClass
148 }
149 }
150 }
151
152 QGCLabel {
153 text: qsTr("Frame Type")
154 font.pointSize: ScreenTools.smallFontPointSize
155 color: qgcPal.buttonHighlightText
156 visible: airframeCheckBox.checked && object.frameTypeSupported
157 }
158
159 QGCComboBox {
160 id: combo
161 Layout.fillWidth: true
162 model: object.frameTypeEnumStrings
163 visible: airframeCheckBox.checked && object.frameTypeSupported
164 onActivated: (index) => { _frameType.rawValue = object.frameTypeEnumValues[index] }
165
166 property bool valid: true
167
168 function checkFrameType(value) {
169 return value == _frameType.rawValue
170 }
171
172 function selectFrameType() {
173 var index = object.frameTypeEnumValues.findIndex(checkFrameType)
174 if (index == -1 && combo.visible) {
175 // Frame Class/Type is set to an invalid combination
176 combo.valid = false
177 } else {
178 combo.currentIndex = index
179 combo.valid = true
180 }
181 }
182
183 Component.onCompleted: selectFrameType()
184
185 Connections {
186 target: _frameTypeAvailable ? _frameType : null
187 ignoreUnknownSignals: true
188 function onRawValueChanged(value) { combo.selectFrameType() }
189 }
190 }
191 }
192 }
193
194 QGCLabel {
195 anchors.fill: imageComboRect
196 text: qsTr("Invalid setting for FRAME_TYPE. Click to Reset.")
197 wrapMode: Text.WordWrap
198 visible: !combo.valid
199 }
200 }
201 } // Repeater - summary boxes
202 } // Flow - summary boxes
203 } // Column
204 } // Component
205} // SetupPage