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