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: qgcPal.successText
37 readonly property color _pendingColor: qgcPal.warningText
38 readonly property color _failedColor: qgcPal.errorText
40 property string _text: "<b>" + name +"</b>: " +
41 ((_telemetryState !== _statePassed) ?
42 telemetryTextFailure :
43 (manualText !== "" ? manualText : qsTr("Passed")))
44 property color _color: _telemetryState === _statePassed && _manualState === _statePassed ?
46 (_telemetryState == _stateFailed ?
48 (_telemetryState === _statePending || _manualState === _statePending ?
52 width: parent ? parent.width : 0
53 topPadding: _verticalPadding
54 bottomPadding: _verticalPadding
55 leftPadding: (_horizontalPadding * 2) + _stateFlagWidth
56 rightPadding: _horizontalPadding
58 // QGCButton's own palette id isn't visible from this file, so locked (disabled) checks need their own
59 QGCPalette { id: qgcPal; colorGroupEnabled: enabled }
61 background: Rectangle {
62 color: qgcPal.windowCard
63 border.color: qgcPal.borderSubtle
67 anchors.left: parent.left
68 anchors.top: parent.top
69 anchors.bottom: parent.bottom
70 width: _stateFlagWidth
73 source: "/qmlimages/checkbox-check.svg"
74 color: qgcPal.textPrimary
76 fillMode: Image.PreserveAspectFit
77 width: Math.min(parent.width, parent.height) * 0.6
79 sourceSize.height: height
81 anchors.centerIn: parent
86 contentItem: QGCLabel {
87 wrapMode: Text.WordWrap
88 horizontalAlignment: Text.AlignHCenter
89 color: qgcPal.textPrimary
93 function _updateTelemetryState() {
94 if (telemetryFailure) {
95 // We have a new telemetry failure, reset user pass
96 _telemetryState = allowTelemetryFailureOverride ? _statePending : _stateFailed
98 _telemetryState = _statePassed
102 onTelemetryFailureChanged: _updateTelemetryState()
103 onAllowTelemetryFailureOverrideChanged: _updateTelemetryState()
106 if (telemetryFailure && !allowTelemetryFailureOverride) {
107 // No way to proceed past this failure
110 if (telemetryFailure && allowTelemetryFailureOverride && _telemetryState !== _statePassed) {
111 // User is allowed to proceed past this failure
112 _telemetryState = _statePassed
115 if (manualText !== "") {
116 // User is confirming a manual check
117 _manualState = (_manualState === _statePassed) ? _statePending : _statePassed
121 onPassedChanged: callButtonPassedChanged()
122 onParentChanged: callButtonPassedChanged()
124 function callButtonPassedChanged() {
125 if (typeof parent.buttonPassedChanged === "function") {
126 parent.buttonPassedChanged()
131 _manualState = manualText === "" ? _statePassed : _statePending
132 if (telemetryFailure) {
133 _telemetryState = allowTelemetryFailureOverride ? _statePending : _stateFailed
135 _telemetryState = _statePassed