5import QGroundControl.Controls
7/// The PreFlightCheckButton supports creating a button which the user then has to verify/click to confirm a check.
8/// It also supports failing the check based on values from within the system: telemetry or QGC app values. These
9/// controls are normally placed within a PreFlightCheckGroup.
11/// Two types of checks may be included on the button:
12/// Manual - This is simply a check which the user must verify and confirm. It is not based on any system state.
13/// Telemetry - This type of check can fail due to some state within the system. A telemetry check failure can be
14/// a hard stop in that there is no way to pass the checklist until the system state resolves itself.
15/// Or it can also optionally be override by the user.
16/// If a button uses both manual and telemetry checks, the telemetry check takes precendence and must be passed first.
18 property string name: ""
19 property string manualText: "" ///< text to show for a manual check, "" signals no manual check
20 property string telemetryTextFailure ///< text to show if telemetry check failed (override not allowed)
21 property bool telemetryFailure: false ///< true: telemetry check failing, false: telemetry check passing
22 property bool allowTelemetryFailureOverride: false ///< true: user can click past telemetry failure
23 property bool passed: _manualState === _statePassed && _telemetryState === _statePassed
24 property bool failed: _manualState === _stateFailed || _telemetryState === _stateFailed
26 property int _manualState: manualText === "" ? _statePassed : _statePending
27 property int _telemetryState: _statePassed
28 property int _horizontalPadding: ScreenTools.defaultFontPixelWidth
29 property int _verticalPadding: Math.round(ScreenTools.defaultFontPixelHeight / 2)
30 property real _stateFlagWidth: ScreenTools.defaultFontPixelWidth * 4
32 readonly property int _statePending: 0 ///< Telemetry check is failing or manual check not yet verified, user can click to make it pass
33 readonly property int _stateFailed: 1 ///< Telemetry check is failing, user cannot click to make it pass
34 readonly property int _statePassed: 2 ///< Check has passed
36 readonly property color _passedColor: "#86cc6a"
37 readonly property color _pendingColor: "#f7a81f"
38 readonly property color _failedColor: "#c31818"
40 property string _text: "<b>" + name +"</b>: " +
41 ((_telemetryState !== _statePassed) ?
42 telemetryTextFailure :
43 (_manualState !== _statePassed ? manualText : qsTr("Passed")))
44 property color _color: _telemetryState === _statePassed && _manualState === _statePassed ?
46 (_telemetryState == _stateFailed ?
48 (_telemetryState === _statePending || _manualState === _statePending ?
52 width: 40 * ScreenTools.defaultFontPixelWidth
53 topPadding: _verticalPadding
54 bottomPadding: _verticalPadding
55 leftPadding: (_horizontalPadding * 2) + _stateFlagWidth
56 rightPadding: _horizontalPadding
58 background: Rectangle {
60 border.color: qgcPal.button;
64 anchors.left: parent.left
65 anchors.top: parent.top
66 anchors.bottom: parent.bottom
67 width: _stateFlagWidth
71 contentItem: QGCLabel {
72 wrapMode: Text.WordWrap
73 horizontalAlignment: Text.AlignHCenter
74 color: qgcPal.buttonText
78 function _updateTelemetryState() {
79 if (telemetryFailure) {
80 // We have a new telemetry failure, reset user pass
81 _telemetryState = allowTelemetryFailureOverride ? _statePending : _stateFailed
83 _telemetryState = _statePassed
87 onTelemetryFailureChanged: _updateTelemetryState()
88 onAllowTelemetryFailureOverrideChanged: _updateTelemetryState()
91 if (telemetryFailure && !allowTelemetryFailureOverride) {
92 // No way to proceed past this failure
95 if (telemetryFailure && allowTelemetryFailureOverride && _telemetryState !== _statePassed) {
96 // User is allowed to proceed past this failure
97 _telemetryState = _statePassed
100 if (manualText !== "") {
101 // User is confirming a manual check
102 _manualState = (_manualState === _statePassed) ? _statePending : _statePassed
106 onPassedChanged: callButtonPassedChanged()
107 onParentChanged: callButtonPassedChanged()
109 function callButtonPassedChanged() {
110 if (typeof parent.buttonPassedChanged === "function") {
111 parent.buttonPassedChanged()
116 _manualState = manualText === "" ? _statePassed : _statePending
117 if (telemetryFailure) {
118 _telemetryState = allowTelemetryFailureOverride ? _statePending : _stateFailed
120 _telemetryState = _statePassed