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

DonLakeFlyer's avatar
DonLakeFlyer committed
10 11 12 13 14 15 16
import QtQuick                  2.3
import QtQuick.Controls         1.2
import QtQuick.Controls.Styles  1.4

import QGroundControl               1.0
import QGroundControl.Palette       1.0
import QGroundControl.ScreenTools   1.0
17 18

QGCButton {
19 20
    property string name:           ""
    property int    group:          0
DonLakeFlyer's avatar
DonLakeFlyer committed
21 22 23
    property string defaultText:    qsTr("Not checked yet")
    property string pendingText:    ""
    property string failureText:    qsTr("Failure. Check console.")
DonLakeFlyer's avatar
DonLakeFlyer committed
24 25 26 27 28 29 30 31
    property int    state:         stateNotChecked

    readonly property int stateNotChecked:  0
    readonly property int statePending:     1
    readonly property int stateMinorIssue:  2
    readonly property int stateMajorIssue:  3
    readonly property int statePassed:      4

32 33
    property var    _color:         qgcPal.button
    property int    _nrClicked:     0
DonLakeFlyer's avatar
DonLakeFlyer committed
34
    property string _text:          name + ": " + defaultText
DonLakeFlyer's avatar
DonLakeFlyer committed
35 36
    property var    _activeVehicle: QGroundControl.multiVehicleManager.activeVehicle

DonLakeFlyer's avatar
DonLakeFlyer committed
37 38
    enabled:    (!_activeVehicle || _activeVehicle.connectionLost) ? false : preFlightCheckList._checkState >= group
    opacity:    (!_activeVehicle || _activeVehicle.connectionLost) ? 0.4 : 0.2 + (0.8 * (preFlightCheckList._checkState >= group))
DonLakeFlyer's avatar
DonLakeFlyer committed
39
    width:      40 * ScreenTools.defaultFontPixelWidth
40 41 42 43

    style: ButtonStyle {
        background: Rectangle {color:_color; border.color: qgcPal.button; radius:3}
        label: Label {
DonLakeFlyer's avatar
DonLakeFlyer committed
44 45 46 47
            text:                   _text
            wrapMode:               Text.WordWrap
            horizontalAlignment:    Text.AlignHCenter
            color:                  state > 0 ? qgcPal.mapWidgetBorderLight : qgcPal.buttonText
48 49 50
        }
    }

DonLakeFlyer's avatar
DonLakeFlyer committed
51 52
    onPendingTextChanged: { if (state === statePending) { getTextFromState(); getColorFromState(); } }
    onFailureTextChanged: { if (state === stateMajorIssue) { getTextFromState(); getColorFromState(); } }
DonLakeFlyer's avatar
DonLakeFlyer committed
53
    onStateChanged: { getTextFromState(); getColorFromState(); }
54
    onClicked: {
DonLakeFlyer's avatar
DonLakeFlyer committed
55 56 57 58
        if (state <= statePending) {
            _nrClicked = _nrClicked + 1 //Only allow click-counter to increase when not failed yet
        }
        updateItem()
59 60 61 62
    }

    function updateItem() {
        // This is the default updateFunction. It assumes the item is a MANUAL check list item, i.e. one that
DonLakeFlyer's avatar
DonLakeFlyer committed
63
        // only requires user clicks (one click if pendingText="", two clicks otherwise) for completion.
64

DonLakeFlyer's avatar
DonLakeFlyer committed
65 66 67
        if (_nrClicked === 0) {
            state = stateNotChecked
        } else if (_nrClicked === 1) {
DonLakeFlyer's avatar
DonLakeFlyer committed
68
            if (pendingText.length === 0) {
DonLakeFlyer's avatar
DonLakeFlyer committed
69 70 71 72 73 74 75
                state = statePassed
            } else {
                state = statePending
            }
        } else {
            state = statePassed
        }
76 77 78 79

        getTextFromState();
        getColorFromState();
    }
DonLakeFlyer's avatar
DonLakeFlyer committed
80

81
    function getTextFromState() {
DonLakeFlyer's avatar
DonLakeFlyer committed
82
        if (state === stateNotChecked) {
DonLakeFlyer's avatar
DonLakeFlyer committed
83
            _text = qsTr(name) + ": " + qsTr(defaultText)
DonLakeFlyer's avatar
DonLakeFlyer committed
84
        } else if (state === statePending) {
DonLakeFlyer's avatar
DonLakeFlyer committed
85
            _text = "<b>"+qsTr(name)+"</b>" +": " + pendingText
DonLakeFlyer's avatar
DonLakeFlyer committed
86 87 88
        } else if (state === stateMinorIssue) {
            _text = "<b>"+qsTr(name)+"</b>" +": " + qsTr("Minor problem")
        } else if (state === stateMajorIssue) {
DonLakeFlyer's avatar
DonLakeFlyer committed
89
            _text = "<b>"+qsTr(name)+"</b>" +": " + failureText
DonLakeFlyer's avatar
DonLakeFlyer committed
90 91 92 93 94
        } else if (state === statePassed) {
            _text = "<b>"+qsTr(name)+"</b>" +": " + qsTr("OK")
        } else {
            console.warn("Internal Error: invalid state", state)
        }
95
    }
DonLakeFlyer's avatar
DonLakeFlyer committed
96

97
    function getColorFromState() {
DonLakeFlyer's avatar
DonLakeFlyer committed
98 99 100 101 102 103 104 105 106 107 108 109 110
        if (state === stateNotChecked) {
            _color = qgcPal.button
        } else if (state === statePending) {
            _color = Qt.rgba(0.9,0.47,0.2,1)
        } else if (state === stateMinorIssue) {
            _color = Qt.rgba(1.0,0.6,0.2,1)
        } else if (state === stateMajorIssue) {
            _color = Qt.rgba(0.92,0.22,0.22,1)
        } else if (state === statePassed ) {
            _color = Qt.rgba(0.27,0.67,0.42,1)
        } else {
            console.warn("Internal Error: invalid state", state)
        }
111
    }
DonLakeFlyer's avatar
DonLakeFlyer committed
112

113 114 115 116
    function resetNrClicks() {
        _nrClicked=0;
        updateItem();
    }
117
}