QGroundControl
Ground Control Station for MAVLink Drones
Loading...
Searching...
No Matches
GuidedActionConfirm.qml
Go to the documentation of this file.
1import QtQuick
2import QtQuick.Controls
3import QtQuick.Layouts
4
5import QGroundControl
6import QGroundControl.Controls
7
8Item {
9 id: control
10 width: mainLayout.width
11 visible: false
12
13 property var guidedController
14 property var guidedValueSlider
15 property var messageDisplay
16 property string title
17 property string message
18 property int action
19 property var actionData
20 property bool hideTrigger: false
21 property var mapIndicator
22 property alias optionText: optionCheckBox.text
23 property alias optionChecked: optionCheckBox.checked
24
25 property real _margins: 2
26 property bool _emergencyAction: action === guidedController.actionEmergencyStop
27
28 Component.onCompleted: guidedController.confirmDialog = this
29
30 onHideTriggerChanged: {
31 if (hideTrigger) {
32 confirmCancelled()
33 }
34 }
35
36 function show(immediate) {
37 if (immediate) {
38 _reallyShow()
39 } else {
40 // We delay showing the confirmation for a small amount in order for any other state
41 // changes to propogate through the system. This way only the final state shows up.
42 visibleTimer.restart()
43 }
44 }
45
46 function reset() {
47 visible = false
48 guidedValueSlider.visible = false
49 hideTrigger = false
50 visibleTimer.stop()
51 messageDisplay.opacity = 1.0
52 messageFadeTimer.stop()
53 messageOpacityAnimation.stop()
54 }
55
56 // Cancel the current pending action and notify its map indicator.
57 // Pass incomingIndicator when superseding one action with another (e.g. from confirmAction):
58 // if the old and new indicator are the same object, actionCancelled() is intentionally skipped
59 // so that a show() call made before confirmAction() is not undone (e.g. goto -> goto).
60 // Omit incomingIndicator (or pass undefined) for explicit user cancellation via the X button
61 // or auto-hide trigger, where the indicator must always be notified.
62 function confirmCancelled(incomingIndicator) {
63 reset()
64 if (mapIndicator && mapIndicator !== incomingIndicator) {
65 mapIndicator.actionCancelled()
66 }
67 mapIndicator = undefined
68 }
69
70 function _reallyShow() {
71 visible = true
72 messageDisplay.opacity = 1.0
73 messageFadeTimer.start()
74 }
75
76 Timer {
77 id: visibleTimer
78 interval: 1000
79 repeat: false
80 onTriggered: _reallyShow()
81 }
82
83 QGCPalette { id: qgcPal }
84
85 RowLayout {
86 id: mainLayout
87 y: 2
88 height: parent.height - 4
89 spacing: ScreenTools.defaultFontPixelWidth
90
91 QGCDelayButton {
92 objectName: "guidedActionConfirmButton"
93 text: control.title
94 enabled: true
95 primary: true
96
97 onActivated: {
98 control.visible = false
99 var sliderOutputValue = 0
100 if (guidedValueSlider.visible) {
101 sliderOutputValue = guidedValueSlider.getOutputValue()
102 guidedValueSlider.visible = false
103 }
104 hideTrigger = false
105 let success = guidedController.executeAction(control.action, control.actionData, sliderOutputValue, control.optionChecked)
106 if (mapIndicator) {
107 if (success) {
108 mapIndicator.actionConfirmed()
109 } else {
110 mapIndicator.actionCancelled()
111 }
112 mapIndicator = undefined
113 }
114 }
115 }
116
117 QGCCheckBox {
118 id: optionCheckBox
119 visible: text !== ""
120 }
121
122 Item {
123 id: closeButton
124 Layout.alignment: Qt.AlignTop
125 Layout.preferredWidth: ScreenTools.minTouchPixels
126 Layout.preferredHeight: ScreenTools.minTouchPixels
127
128 QGCColoredImage {
129 anchors.centerIn: parent
130 width: height
131 height: ScreenTools.defaultFontPixelHeight * 0.5
132 source: "/res/XDelete.svg"
133 fillMode: Image.PreserveAspectFit
134 color: qgcPal.textPrimary
135 }
136
137 QGCMouseArea {
138 fillItem: parent
139 onClicked: confirmCancelled()
140 }
141 }
142 }
143}