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 text: control.title
93 enabled: true
94
95 onActivated: {
96 control.visible = false
97 var sliderOutputValue = 0
98 if (guidedValueSlider.visible) {
99 sliderOutputValue = guidedValueSlider.getOutputValue()
100 guidedValueSlider.visible = false
101 }
102 hideTrigger = false
103 let success = guidedController.executeAction(control.action, control.actionData, sliderOutputValue, control.optionChecked)
104 if (mapIndicator) {
105 if (success) {
106 mapIndicator.actionConfirmed()
107 } else {
108 mapIndicator.actionCancelled()
109 }
110 mapIndicator = undefined
111 }
112 }
113 }
114
115 QGCCheckBox {
116 id: optionCheckBox
117 visible: text !== ""
118 }
119
120 QGCColoredImage {
121 id: closeButton
122 Layout.alignment: Qt.AlignTop
123 width: height
124 height: ScreenTools.defaultFontPixelHeight * 0.5
125 source: "/res/XDelete.svg"
126 fillMode: Image.PreserveAspectFit
127 color: qgcPal.text
128
129 QGCMouseArea {
130 fillItem: parent
131 onClicked: confirmCancelled()
132 }
133 }
134 }
135}