QGroundControl
Ground Control Station for MAVLink Drones
Loading...
Searching...
No Matches
MissionItemEditor.qml
Go to the documentation of this file.
1import QtQuick
2import QtQuick.Controls
3import QtQuick.Dialogs
4import QtQml
5import QtQuick.Layouts
6
7import QGroundControl
8import QGroundControl.Controls
9import QGroundControl.FactControls
10
11/// Mission item edit control
12Rectangle {
13 required property var missionItem ///< MissionItem associated with this editor
14 required property var map ///< Map control
15
16 signal clicked
17 signal remove
18 signal selectNextNotReadyItem
19 signal editorExpandedAndLoaded
20
21 id: _root
22 height: _currentItem ? (editorLoader.y + editorLoader.height + _innerMargin) : (topRowLayout.y + topRowLayout.height + _margin)
23 color: _currentItem ? qgcPal.accent : qgcPal.windowCard
24 radius: _radius
25 opacity: _currentItem ? 1.0 : 0.7
26 border.width: _readyForSave ? 0 : 2
27 border.color: qgcPal.errorText
28
29 property var _masterController: missionItem.masterController
30 property var _missionController: _masterController.missionController
31 property bool _currentItem: missionItem.isCurrentItem
32 property color _outerTextColor: _currentItem ? qgcPal.accentText : qgcPal.textPrimary
33 property bool _noMissionItemsAdded: _missionController.visualItems ? _missionController.visualItems.count <= 1 : true
34 property real _sectionSpacer: ScreenTools.defaultFontPixelWidth / 2 // spacing between section headings
35 property bool _singleComplexItem: _missionController.complexMissionItems.length === 1
36 property bool _readyForSave: missionItem.readyForSaveState === VisualMissionItem.ReadyForSave
37
38 readonly property real _editFieldWidth: Math.min(width - _innerMargin * 2, ScreenTools.defaultFontPixelWidth * 12)
39 readonly property real _margin: ScreenTools.defaultFontPixelWidth / 2
40 readonly property real _innerMargin: 2
41 readonly property real _radius: ScreenTools.defaultFontPixelWidth / 2
42 readonly property real _hamburgerSize: commandPicker.height * 0.75
43 readonly property real _trashSize: commandPicker.height * 0.75
44 readonly property bool _waypointsOnlyMode: QGroundControl.corePlugin.options.missionWaypointsOnly
45
46 QGCPalette {
47 id: qgcPal
48 colorGroupEnabled: enabled
49 }
50
51 FocusScope {
52 id: currentItemScope
53 anchors.fill: parent
54
55 MouseArea {
56 anchors.fill: parent
57 onClicked: {
58 if (mainWindow.allowViewSwitch()) {
59 currentItemScope.focus = true
60 _root.clicked()
61 }
62 }
63 }
64 }
65
66 MissionItemMenu {
67 id: itemMenu
68 missionItem: _root.missionItem
69 }
70
71 Row {
72 id: topRowLayout
73 anchors.margins: _margin
74 anchors.left: parent.left
75 anchors.top: parent.top
76 spacing: _margin
77
78 Rectangle {
79 id: notReadyForSaveIndicator
80 anchors.verticalCenter: parent.verticalCenter
81 width: _hamburgerSize
82 height: width
83 color: qgcPal.errorIndicator
84 radius: width / 2
85 visible: !_readyForSave
86
87 QGCLabel {
88 id: readyForSaveLabel
89 anchors.centerIn: parent
90 //: Indicator in Plan view to show mission item is not ready for save/send
91 text: qsTr("?")
92 color: qgcPal.indicatorText
93 font.pointSize: ScreenTools.smallFontPointSize
94 }
95 }
96
97 QGCColoredImage {
98 id: deleteButton
99 anchors.verticalCenter: parent.verticalCenter
100 height: _hamburgerSize
101 width: height
102 sourceSize.height: height
103 fillMode: Image.PreserveAspectFit
104 mipmap: true
105 smooth: true
106 color: qgcPal.accentText
107 visible: _currentItem && missionItem.sequenceNumber !== 0
108 source: "/res/TrashDelete.svg"
109
110 QGCMouseArea {
111 fillItem: parent
112 onClicked: remove()
113 }
114 }
115
116 Item {
117 id: commandPicker
118 anchors.verticalCenter: parent.verticalCenter
119 height: ScreenTools.implicitComboBoxHeight
120 width: innerLayout.width
121 visible: !commandLabel.visible
122
123 RowLayout {
124 id: innerLayout
125 anchors.verticalCenter: parent.verticalCenter
126 spacing: _padding
127
128 property real _padding: ScreenTools.comboBoxPadding
129
130 QGCLabel { text: missionItem.commandName }
131
132 QGCColoredImage {
133 height: ScreenTools.defaultFontPixelWidth
134 width: height
135 fillMode: Image.PreserveAspectFit
136 smooth: true
137 antialiasing: true
138 color: qgcPal.textPrimary
139 source: "/qmlimages/arrow-down.png"
140 }
141 }
142
143 QGCMouseArea {
144 fillItem: parent
145 onClicked: commandDialogFactory.open()
146 }
147
148 QGCPopupDialogFactory {
149 id: commandDialogFactory
150
151 dialogComponent: commandDialog
152 }
153
154 Component {
155 id: commandDialog
156
157 MissionCommandDialog {
158 vehicle: _masterController.controllerVehicle
159 missionItem: _root.missionItem
160 map: _root.map
161 // FIXME: Disabling fly through commands doesn't work since you may need to change from an RTL to something else
162 flyThroughCommandsAllowed: true //_missionController.flyThroughCommandsAllowed
163 }
164 }
165 }
166
167 QGCLabel {
168 id: commandLabel
169 anchors.verticalCenter: parent.verticalCenter
170 width: commandPicker.width
171 height: commandPicker.height
172 visible: !missionItem.isCurrentItem || !missionItem.isSimpleItem || _waypointsOnlyMode || missionItem.isTakeoffItem
173 verticalAlignment: Text.AlignVCenter
174 text: missionItem.commandName
175 color: _outerTextColor
176 }
177 }
178
179 QGCColoredImage {
180 id: hamburger
181 anchors.margins: _margin
182 anchors.right: parent.right
183 anchors.verticalCenter: topRowLayout.verticalCenter
184 width: _hamburgerSize
185 height: _hamburgerSize
186 sourceSize.height: _hamburgerSize
187 source: "qrc:/qmlimages/Hamburger.svg"
188 visible: missionItem.isCurrentItem && missionItem.sequenceNumber !== 0
189 color: qgcPal.accentText
190
191 QGCMouseArea {
192 fillItem: hamburger
193 onClicked: (position) => {
194 currentItemScope.focus = true
195 itemMenu.openAt(hamburger, position)
196 }
197 }
198 }
199
200 /*
201 QGCLabel {
202 id: notReadyForSaveLabel
203 anchors.margins: _margin
204 anchors.left: notReadyForSaveIndicator.right
205 anchors.right: parent.right
206 anchors.top: commandPicker.bottom
207 visible: _currentItem && !_readyForSave
208 text: missionItem.readyForSaveState === VisualMissionItem.NotReadyForSaveTerrain ?
209 qsTr("Incomplete: Waiting on terrain data.") :
210 qsTr("Incomplete: Item not fully specified.")
211 wrapMode: Text.WordWrap
212 horizontalAlignment: Text.AlignHCenter
213 color: qgcPal.errorText
214 }
215
216*/
217
218 MissionItemEditorLoader {
219 id: editorLoader
220 anchors.margins: _innerMargin
221 anchors.left: parent.left
222 anchors.top: topRowLayout.bottom
223 missionItem: _root.missionItem
224 availableWidth: _root.width - (anchors.margins * 2)
225 active: _currentItem
226 }
227
228 onHeightChanged: {
229 if (_currentItem && editorLoader.status === Loader.Ready) {
230 _editorHeightSettleTimer.restart()
231 }
232 }
233
234 Timer {
235 id: _editorHeightSettleTimer
236 interval: 100
237 onTriggered: _root.editorExpandedAndLoaded()
238 }
239}