QGroundControl
Ground Control Station for MAVLink Drones
Loading...
Searching...
No Matches
VehicleSummaryCard.qml
Go to the documentation of this file.
1import QtQuick
2import QtQuick.Layouts
3
4import QGroundControl
5import QGroundControl.Controls
6
7/// A component's card on the Summary page: its name, whether it still needs setup and its values. A component that
8/// does not supply summaryItems shows its summaryQmlSource instead.
9Rectangle {
10 id: control
11
12 required property var vehicleComponent
13
14 objectName: "vehicleSummary_card_" + vehicleComponent.name
15
16 signal clicked()
17
18 readonly property bool hasContent: _items.length > 0 || vehicleComponent.summaryQmlSource.toString() !== ""
19 readonly property bool _needsSetup: vehicleComponent.requiresSetup && !vehicleComponent.setupComplete
20 readonly property bool _clickable: vehicleComponent.setupSource.toString() !== ""
21 readonly property var _items: vehicleComponent.summaryItems
22 readonly property var _sections: _buildSections(_items)
23 readonly property real _margins: ScreenTools.defaultFontPixelWidth * 1.5
24
25 implicitWidth: cardLayout.implicitWidth + _margins * 2
26 implicitHeight: cardLayout.implicitHeight + _margins * 2
27 radius: ScreenTools.defaultBorderRadius * 2
28 color: qgcPal.windowCard
29 border.color: _needsSetup ? qgcPal.colorRed : (_clickable && mouseArea.containsMouse) ? qgcPal.accent : qgcPal.borderSubtle
30
31 QGCPalette { id: qgcPal }
32
33 // Items grouped by their group, in order of first appearance. Items without a group make up a section with no title.
34 function _buildSections(items) {
35 const sections = []
36 const byTitle = {}
37 for (let i = 0; i < items.length; i++) {
38 const title = items[i].group
39 if (!(title in byTitle)) {
40 byTitle[title] = { title: title, items: [] }
41 sections.push(byTitle[title])
42 }
43 byTitle[title].items.push(items[i])
44 }
45 return sections
46 }
47
48 MouseArea {
49 id: mouseArea
50 anchors.fill: parent
51 hoverEnabled: true
52 cursorShape: control._clickable ? Qt.PointingHandCursor : Qt.ArrowCursor
53 onClicked: {
54 if (control._clickable) {
55 control.clicked()
56 }
57 }
58 }
59
60 ColumnLayout {
61 id: cardLayout
62 anchors.fill: parent
63 anchors.margins: control._margins
64 spacing: ScreenTools.defaultFontPixelHeight * 0.5
65
66 RowLayout {
67 Layout.fillWidth: true
68 spacing: ScreenTools.defaultFontPixelWidth
69
70 Rectangle {
71 implicitWidth: ScreenTools.defaultFontPixelHeight * 0.5
72 implicitHeight: implicitWidth
73 radius: implicitWidth / 2
74 color: !control.vehicleComponent.requiresSetup ? "transparent" : control._needsSetup ? qgcPal.colorRed : qgcPal.colorGreen
75 border.color: control.vehicleComponent.requiresSetup ? color : qgcPal.textSecondary
76 }
77
78 VehicleSummaryLabel {
79 Layout.fillWidth: true
80 text: control.vehicleComponent.name
81 font.bold: true
82 font.capitalization: Font.AllUppercase
83 font.letterSpacing: ScreenTools.defaultFontPixelWidth * 0.1
84 elide: Text.ElideRight
85 }
86
87 QGCChip {
88 text: qsTr("Setup required")
89 textColor: qgcPal.errorText
90 visible: control._needsSetup
91 }
92
93 QGCLabel {
94 text: "›"
95 color: qgcPal.textSecondary
96 visible: control._clickable
97 }
98 }
99
100 Repeater {
101 model: control._sections
102
103 Rectangle {
104 id: section
105 Layout.fillWidth: true
106 implicitHeight: sectionLayout.implicitHeight + _padding * 2
107 radius: ScreenTools.defaultBorderRadius
108 color: "transparent"
109 border.color: _titled ? qgcPal.borderSubtle : "transparent"
110
111 required property var modelData
112
113 readonly property bool _titled: modelData.title !== ""
114 readonly property real _padding: _titled ? ScreenTools.defaultFontPixelWidth : 0
115
116 ColumnLayout {
117 id: sectionLayout
118 anchors.fill: parent
119 anchors.margins: section._padding
120 spacing: ScreenTools.defaultFontPixelHeight * 0.3
121
122 QGCLabel {
123 text: section.modelData.title
124 font.bold: true
125 visible: section._titled
126 }
127
128 Flow {
129 Layout.fillWidth: true
130 spacing: ScreenTools.defaultFontPixelWidth * 0.5
131
132 Repeater {
133 model: section.modelData.items
134
135 Rectangle {
136 width: Math.min(implicitWidth, parent.width)
137 implicitWidth: cellLayout.implicitWidth + ScreenTools.defaultFontPixelWidth * 2
138 implicitHeight: cellLayout.implicitHeight + ScreenTools.defaultFontPixelHeight * 0.6
139 radius: ScreenTools.defaultBorderRadius
140 color: qgcPal.windowInset
141 border.color: modelData.state === VehicleSummaryState.Attention ? qgcPal.warningText : qgcPal.borderSubtle
142
143 required property var modelData
144
145 ColumnLayout {
146 id: cellLayout
147 anchors.centerIn: parent
148 width: parent.width - ScreenTools.defaultFontPixelWidth * 2
149 spacing: 0
150
151 QGCCaptionLabel {
152 Layout.fillWidth: true
153 text: modelData.caption
154 wrapMode: Text.WordWrap
155 }
156
157 QGCLabel {
158 Layout.fillWidth: true
159 text: modelData.value
160 wrapMode: Text.WordWrap
161 font.bold: modelData.state === VehicleSummaryState.Attention
162 color: modelData.state === VehicleSummaryState.Attention ? qgcPal.warningText :
163 modelData.state === VehicleSummaryState.Muted ? qgcPal.textSecondary : qgcPal.textPrimary
164 }
165 }
166 }
167 }
168 }
169 }
170 }
171 }
172
173 Loader {
174 Layout.fillWidth: true
175 Layout.preferredHeight: item ? item.implicitHeight : 0
176 source: control._items.length === 0 ? control.vehicleComponent.summaryQmlSource : ""
177
178 property var vehicleComponent: control.vehicleComponent
179 }
180 }
181}