GuidedActionConfirm.qml 4.78 KB
Newer Older
1 2
/****************************************************************************
 *
Gus Grubba's avatar
Gus Grubba committed
3
 * (c) 2009-2020 QGROUNDCONTROL PROJECT <http://www.qgroundcontrol.org>
4 5 6 7 8 9
 *
 * QGroundControl is licensed according to the terms in the file
 * COPYING.md in the root of the source code directory.
 *
 ****************************************************************************/

10 11 12
import QtQuick          2.12
import QtQuick.Controls 2.4
import QtQuick.Layouts  1.12
13 14 15 16 17 18

import QGroundControl               1.0
import QGroundControl.ScreenTools   1.0
import QGroundControl.Controls      1.0
import QGroundControl.Palette       1.0

19
Rectangle {
20 21 22 23 24 25
    id:                     _root
    Layout.minimumWidth:    mainLayout.width + (_margins * 2)
    Layout.preferredHeight: mainLayout.height + (_margins * 2)
    radius:                 ScreenTools.defaultFontPixelWidth / 2
    color:                  qgcPal.windowShadeLight
    visible:                false
26 27 28

    property var    guidedController
    property var    altitudeSlider
29
    property string title                                       // Currently unused
30 31 32
    property alias  message:            messageText.text
    property int    action
    property var    actionData
33
    property bool   hideTrigger:        false
34
    property var    mapIndicator
DonLakeFlyer's avatar
DonLakeFlyer committed
35 36
    property alias  optionText:         optionCheckBox.text
    property alias  optionChecked:      optionCheckBox.checked
37

38
    property real _margins:         ScreenTools.defaultFontPixelWidth / 2
39
    property bool _emergencyAction: action === guidedController.actionEmergencyStop
40

41 42
    Component.onCompleted: guidedController.confirmDialog = this

43 44
    onHideTriggerChanged: {
        if (hideTrigger) {
45
            confirmCancelled()
46 47 48
        }
    }

49 50 51 52
    function show(immediate) {
        if (immediate) {
            visible = true
        } else {
53
            // We delay showing the confirmation for a small amount in order for any other state
54 55 56 57 58
            // changes to propogate through the system. This way only the final state shows up.
            visibleTimer.restart()
        }
    }

59 60 61 62 63 64 65 66 67 68 69
    function confirmCancelled() {
        altitudeSlider.visible = false
        visible = false
        hideTrigger = false
        visibleTimer.stop()
        if (mapIndicator) {
            mapIndicator.actionCancelled()
            mapIndicator = undefined
        }
    }

70 71 72 73 74 75 76
    Timer {
        id:             visibleTimer
        interval:       1000
        repeat:         false
        onTriggered:    visible = true
    }

77 78
    QGCPalette { id: qgcPal }

79 80 81 82
    ColumnLayout {
        id:                         mainLayout
        anchors.horizontalCenter:   parent.horizontalCenter
        spacing:                    _margins
83 84 85

        QGCLabel {
            id:                     messageText
86
            Layout.fillWidth:       true
87 88 89 90
            horizontalAlignment:    Text.AlignHCenter
            wrapMode:               Text.WordWrap
        }

DonLakeFlyer's avatar
DonLakeFlyer committed
91
        QGCCheckBox {
92 93 94 95
            id:                 optionCheckBox
            Layout.alignment:   Qt.AlignHCenter
            text:               ""
            visible:            text !== ""
DonLakeFlyer's avatar
DonLakeFlyer committed
96 97
        }

98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119
        RowLayout {
            Layout.alignment:       Qt.AlignHCenter
            spacing:                ScreenTools.defaultFontPixelWidth

            SliderSwitch {
                id:                     slider
                confirmText:            qsTr("Slide to confirm")
                Layout.minimumWidth:    Math.max(implicitWidth, ScreenTools.defaultFontPixelWidth * 30)

                onAccept: {
                    _root.visible = false
                    var altitudeChange = 0
                    if (altitudeSlider.visible) {
                        altitudeChange = altitudeSlider.getAltitudeChangeValue()
                        altitudeSlider.visible = false
                    }
                    hideTrigger = false
                    guidedController.executeAction(_root.action, _root.actionData, altitudeChange, _root.optionChecked)
                    if (mapIndicator) {
                        mapIndicator.actionConfirmed()
                        mapIndicator = undefined
                    }
120
                }
121 122
            }

123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141
            Rectangle {
                height: slider.height * 0.75
                width:  height
                radius: height / 2
                color:  qgcPal.primaryButton

                QGCColoredImage {
                    anchors.margins:    parent.height / 4
                    anchors.fill:       parent
                    source:             "/res/XDelete.svg"
                    fillMode:           Image.PreserveAspectFit
                    color:              qgcPal.text
                }

                QGCMouseArea {
                    fillItem:   parent
                    onClicked:  confirmCancelled()
                }
            }
142 143 144
        }
    }
}
145