QGroundControl
Ground Control Station for MAVLink Drones
Loading...
Searching...
No Matches
VehicleSummary.qml
Go to the documentation of this file.
1import QtQuick
2import QtQuick.Controls
3import QtQuick.Layouts
4
5import QGroundControl
6import QGroundControl.Controls
7
8Rectangle {
9 id: _summaryRoot
10 anchors.fill: parent
11 anchors.rightMargin: ScreenTools.defaultFontPixelWidth
12 anchors.leftMargin: ScreenTools.defaultFontPixelWidth
13 color: qgcPal.window
14
15 signal componentRequested(var vehicleComponent)
16
17 readonly property var _vehicle: QGroundControl.multiVehicleManager.activeVehicle
18 readonly property var _components: _vehicle ? _vehicle.autopilotPlugin.vehicleComponents : []
19 // Components are listed in the order recommended for setting up a vehicle
20 readonly property var _requiredComponents: _components.filter(vehicleComponent => vehicleComponent.requiresSetup).sort((a, b) => a.setupOrder - b.setupOrder)
21 readonly property int _readyCount: _requiredComponents.filter(vehicleComponent => vehicleComponent.setupComplete).length
22 readonly property int _remainingCount: _requiredComponents.length - _readyCount
23 readonly property var _nextComponent: _findNextComponent()
24 readonly property real _minCardWidth: ScreenTools.isTinyScreen ? ScreenTools.defaultFontPixelWidth * 28 : ScreenTools.defaultFontPixelWidth * 36
25 readonly property real _spacing: ScreenTools.defaultFontPixelHeight * 0.5
26 // Column counts come from the page width rather than the grid's own, which a grid cannot size itself from
27 readonly property real _panelContentWidth: width - _spacing * 2
28 readonly property real _readinessWidth: ScreenTools.defaultFontPixelWidth * 34
29 readonly property bool _wideTop: width >= ScreenTools.defaultFontPixelWidth * 90
30 readonly property real _checklistWidth: _panelContentWidth - _spacing * 2 - (_wideTop ? _readinessWidth + _spacing : 0)
31
32 function _findNextComponent() {
33 for (let i = 0; i < _requiredComponents.length; i++) {
34 const vehicleComponent = _requiredComponents[i]
35 if (!vehicleComponent.setupComplete && vehicleComponent.setupSource.toString() !== "") {
36 return vehicleComponent
37 }
38 }
39 return null
40 }
41
42 QGCPalette {
43 id: qgcPal
44 colorGroupEnabled: enabled
45 }
46
47 QGCFlickable {
48 anchors.fill: parent
49 contentHeight: summaryColumn.height
50 contentWidth: _summaryRoot.width
51 flickableDirection: Flickable.VerticalFlick
52
53 ColumnLayout {
54 id: summaryColumn
55 width: _summaryRoot.width
56 spacing: _summaryRoot._spacing
57
58 GridLayout {
59 Layout.fillWidth: true
60 columns: _summaryRoot._wideTop ? 2 : 1
61 columnSpacing: _summaryRoot._spacing
62 rowSpacing: _summaryRoot._spacing
63 visible: _summaryRoot._requiredComponents.length > 0
64
65 Rectangle {
66 Layout.fillHeight: true
67 Layout.preferredWidth: _summaryRoot._readinessWidth
68 implicitHeight: readinessLayout.implicitHeight + _summaryRoot._spacing * 2
69 color: qgcPal.windowPanel
70 border.color: qgcPal.borderSubtle
71 radius: ScreenTools.defaultBorderRadius * 2
72
73 ColumnLayout {
74 id: readinessLayout
75 anchors.fill: parent
76 anchors.margins: _summaryRoot._spacing
77 spacing: _summaryRoot._spacing
78
79 QGCCaptionLabel {
80 Layout.alignment: Qt.AlignHCenter
81 text: qsTr("Vehicle setup")
82 }
83
84 Canvas {
85 id: ring
86 Layout.alignment: Qt.AlignHCenter
87 Layout.preferredWidth: ScreenTools.defaultFontPixelHeight * 7
88 Layout.preferredHeight: Layout.preferredWidth
89
90 readonly property real progress: _summaryRoot._readyCount / Math.max(1, _summaryRoot._requiredComponents.length)
91 readonly property real _lineWidth: ScreenTools.defaultFontPixelHeight * 0.6
92
93 onProgressChanged: requestPaint()
94 onWidthChanged: requestPaint()
95 onPaint: {
96 const context = getContext("2d")
97 const center = width / 2
98 const radius = center - _lineWidth / 2
99 context.reset()
100 context.lineWidth = _lineWidth
101 context.strokeStyle = qgcPal.borderSubtle
102 context.beginPath()
103 context.arc(center, center, radius, 0, 2 * Math.PI)
104 context.stroke()
105 if (progress > 0) {
106 context.strokeStyle = qgcPal.colorGreen
107 context.beginPath()
108 context.arc(center, center, radius, -Math.PI / 2, -Math.PI / 2 + 2 * Math.PI * progress)
109 context.stroke()
110 }
111 }
112
113 Connections {
114 target: qgcPal
115 function onPaletteChanged() {
116 ring.requestPaint()
117 }
118 }
119
120 ColumnLayout {
121 anchors.centerIn: parent
122 spacing: 0
123
124 QGCLabel {
125 Layout.alignment: Qt.AlignHCenter
126 text: qsTr("%1/%2").arg(_summaryRoot._readyCount).arg(_summaryRoot._requiredComponents.length)
127 font.pointSize: ScreenTools.largeFontPointSize
128 font.bold: true
129 }
130
131 QGCLabel {
132 Layout.alignment: Qt.AlignHCenter
133 text: qsTr("required")
134 font.pointSize: ScreenTools.smallFontPointSize
135 color: qgcPal.textSecondary
136 }
137 }
138 }
139
140 QGCChip {
141 Layout.alignment: Qt.AlignHCenter
142 text: _summaryRoot._remainingCount > 0 ?
143 qsTr("%n component(s) need setup", "", _summaryRoot._remainingCount) :
144 qsTr("Required setup complete")
145 textColor: _summaryRoot._remainingCount > 0 ? qgcPal.errorText : qgcPal.successText
146 }
147
148 QGCButton {
149 objectName: "vehicleSummary_continueSetup"
150 Layout.alignment: Qt.AlignHCenter
151 primary: true
152 text: _summaryRoot._nextComponent ? qsTr("Continue setup: %1").arg(_summaryRoot._nextComponent.name) : ""
153 visible: _summaryRoot._nextComponent !== null
154 onClicked: _summaryRoot.componentRequested(_summaryRoot._nextComponent)
155 }
156 }
157 }
158
159 Rectangle {
160 Layout.fillWidth: true
161 Layout.fillHeight: true
162 implicitHeight: checklistLayout.implicitHeight + _summaryRoot._spacing * 2
163 color: qgcPal.windowPanel
164 border.color: qgcPal.borderSubtle
165 radius: ScreenTools.defaultBorderRadius * 2
166
167 ColumnLayout {
168 id: checklistLayout
169 anchors.fill: parent
170 anchors.margins: _summaryRoot._spacing
171 spacing: _summaryRoot._spacing
172
173 VehicleSummaryHeader {
174 text: qsTr("Required setup")
175 }
176
177 GridLayout {
178 Layout.fillWidth: true
179 columns: Math.max(1, Math.floor(_summaryRoot._checklistWidth / (ScreenTools.defaultFontPixelWidth * 28)))
180 columnSpacing: ScreenTools.defaultFontPixelWidth
181 rowSpacing: ScreenTools.defaultFontPixelWidth
182
183 Repeater {
184 model: _summaryRoot._requiredComponents
185
186 VehicleSummaryTile {
187 objectName: "vehicleSummary_tile_" + modelData.name
188 text: modelData.name
189 done: modelData.setupComplete
190 next: modelData === _summaryRoot._nextComponent
191 clickable: modelData.setupSource.toString() !== ""
192 onClicked: _summaryRoot.componentRequested(modelData)
193
194 required property var modelData
195 }
196 }
197 }
198
199 QGCLabel {
200 Layout.fillWidth: true
201 Layout.fillHeight: true
202 wrapMode: Text.WordWrap
203 font.pointSize: ScreenTools.smallFontPointSize
204 color: qgcPal.textSecondary
205 text: qsTr("Select a component to open its setup page. The other components are listed below.")
206 }
207 }
208 }
209 }
210
211 Rectangle {
212 Layout.fillWidth: true
213 implicitHeight: settingsLayout.implicitHeight + _summaryRoot._spacing * 2
214 color: qgcPal.windowPanel
215 border.color: qgcPal.borderSubtle
216 radius: ScreenTools.defaultBorderRadius * 2
217
218 ColumnLayout {
219 id: settingsLayout
220 anchors.fill: parent
221 anchors.margins: _summaryRoot._spacing
222 spacing: _summaryRoot._spacing
223
224 VehicleSummaryHeader {
225 text: qsTr("Current settings")
226 }
227
228 VehicleSummaryMasonry {
229 Layout.fillWidth: true
230 minColumnWidth: _summaryRoot._minCardWidth
231 spacing: _summaryRoot._spacing
232 model: _summaryRoot._components
233
234 delegate: VehicleSummaryCard {
235 vehicleComponent: modelData
236 visible: hasContent
237 onClicked: _summaryRoot.componentRequested(modelData)
238
239 required property var modelData
240 }
241 }
242 }
243 }
244 }
245 }
246}