FlightDisplayViewWidgets.qml 11.3 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
 *
 * QGroundControl is licensed according to the terms in the file
 * COPYING.md in the root of the source code directory.
 *
 ****************************************************************************/
9

10 11
import QtQuick                  2.3
import QtQuick.Controls         1.2
12
import QtQuick.Controls.Styles  1.4
13
import QtQuick.Dialogs          1.2
14 15
import QtLocation               5.3
import QtPositioning            5.3
16
import QtQuick.Layouts          1.2
17

Gus Grubba's avatar
Gus Grubba committed
18 19 20 21 22 23
import QGroundControl               1.0
import QGroundControl.ScreenTools   1.0
import QGroundControl.Controls      1.0
import QGroundControl.Palette       1.0
import QGroundControl.Vehicle       1.0
import QGroundControl.FlightMap     1.0
24
import QGroundControl.Airspace      1.0
Gus Grubba's avatar
Gus Grubba committed
25
import QGroundControl.Airmap        1.0
26 27

Item {
Gus Grubba's avatar
Gus Grubba committed
28
    id: widgetRoot
29

30 31
    readonly property real  _rightPanelWidth: Math.min(parent.width / 3, ScreenTools.defaultFontPixelWidth * 30)

32
    property bool   useLightColors
33
    property var    missionController
34
    property bool   showValues:             !QGroundControl.airspaceManager.airspaceVisible
Don Gagne's avatar
Don Gagne committed
35

36
    property bool   _lightWidgetBorders:    true
37
    property bool   _airspaceEnabled:       QGroundControl.airmapSupported ? QGroundControl.settingsManager.airMapSettings.enableAirMap.rawValue : false
38

39
    readonly property real _margins:        ScreenTools.defaultFontPixelHeight * 0.5
40
    readonly property bool _useAlternateInstrumentPanel:        QGroundControl.settingsManager.flyViewSettings.alternateInstrumentPanel.value
dogmaphobic's avatar
dogmaphobic committed
41

42
    function getPreferredInstrumentWidth() {
43 44 45 46
        // Don't allow instrument panel to chew more than 1/4 of full window
        var defaultWidth = ScreenTools.defaultFontPixelWidth * 30
        var maxWidth = mainWindow.width * 0.25
        return Math.min(maxWidth, defaultWidth)
47 48
    }

49
    function _setInstrumentWidget() {
50 51 52 53
        if(QGroundControl.corePlugin.options.instrumentWidget) {
            if(QGroundControl.corePlugin.options.instrumentWidget.source.toString().length) {
                instrumentsLoader.source = QGroundControl.corePlugin.options.instrumentWidget.source
                switch(QGroundControl.corePlugin.options.instrumentWidget.widgetPosition) {
Gus Grubba's avatar
Gus Grubba committed
54 55 56 57 58 59 60 61 62
                case CustomInstrumentWidget.POS_TOP_LEFT:
                    instrumentsLoader.state  = "topLeftMode"
                    break;
                case CustomInstrumentWidget.POS_BOTTOM_LEFT:
                    instrumentsLoader.state  = "bottomLeftMode"
                    break;
                case CustomInstrumentWidget.POS_CENTER_LEFT:
                    instrumentsLoader.state  = "centerLeftMode"
                    break;
63
                case CustomInstrumentWidget.POS_TOP_RIGHT:
Gus Grubba's avatar
Gus Grubba committed
64
                    instrumentsLoader.state  = "topRightMode"
65 66
                    break;
                case CustomInstrumentWidget.POS_BOTTOM_RIGHT:
Gus Grubba's avatar
Gus Grubba committed
67
                    instrumentsLoader.state  = "bottomRightMode"
68 69 70
                    break;
                case CustomInstrumentWidget.POS_CENTER_RIGHT:
                default:
Gus Grubba's avatar
Gus Grubba committed
71
                    instrumentsLoader.state  = "centerRightMode"
72 73
                    break;
                }
74
            } else {
75 76 77 78 79 80
                if(_useAlternateInstrumentPanel){
                    instrumentsLoader.source = "qrc:/qml/QGCInstrumentWidgetAlternate.qml"
                }
                else{
                    instrumentsLoader.source = "qrc:/qml/QGCInstrumentWidget.qml"
                }
81
            }
82 83
        } else {
            instrumentsLoader.source = ""
84 85
        }
    }
86 87 88 89
    Connections {
        target:          QGroundControl.settingsManager.flyViewSettings.alternateInstrumentPanel
        onValueChanged:  _setInstrumentWidget()
    }
90 91

    Connections {
92 93
        target:         QGroundControl.settingsManager.appSettings.virtualJoystick
        onValueChanged: _setInstrumentWidget()
94
    }
95 96 97 98
    Connections {
        target:         QGroundControl.settingsManager.appSettings.virtualJoystickCentralized
        onValueChanged: _setInstrumentWidget()
    }
99

100 101 102 103 104
    Connections {
        target:         QGroundControl.settingsManager.appSettings.showLargeCompass
        onValueChanged: _setInstrumentWidget()
    }

Gus Grubba's avatar
Gus Grubba committed
105
    Connections {
106
        target: QGroundControl.airspaceManager
Gus Grubba's avatar
Gus Grubba committed
107
        onAirspaceVisibleChanged: {
108
             widgetRoot.showValues = !QGroundControl.airspaceManager.airspaceVisible
Gus Grubba's avatar
Gus Grubba committed
109 110 111
        }
    }

112 113 114 115
    Component.onCompleted: {
        _setInstrumentWidget()
    }

Don Gagne's avatar
Don Gagne committed
116
    //-- Map warnings
117 118 119 120 121 122 123 124 125 126

    Rectangle {
        anchors.margins:    -ScreenTools.defaultFontPixelHeight
        anchors.fill:       warningsCol
        color:              "white"
        opacity:            0.5
        radius:             ScreenTools.defaultFontPixelWidth / 2
        visible:            warningsCol.noGPSLockVisible || warningsCol.prearmErrorVisible
    }

127
    Column {
128
        id:                         warningsCol
Don Gagne's avatar
Don Gagne committed
129
        anchors.horizontalCenter:   parent.horizontalCenter
130
        anchors.top:                parent.verticalCenter
Don Gagne's avatar
Don Gagne committed
131 132
        spacing:                    ScreenTools.defaultFontPixelHeight

133
        property bool noGPSLockVisible:     activeVehicle && !activeVehicle.coordinate.isValid && mainIsMap
134
        property bool prearmErrorVisible:   activeVehicle && !activeVehicle.armed && activeVehicle.prearmError
135

Don Gagne's avatar
Don Gagne committed
136 137
        QGCLabel {
            anchors.horizontalCenter:   parent.horizontalCenter
138
            visible:                    warningsCol.noGPSLockVisible
Don Gagne's avatar
Don Gagne committed
139
            z:                          QGroundControl.zOrderTopMost
140
            color:                      "black"
141
            font.pointSize:             ScreenTools.largeFontPointSize
142
            text:                       qsTr("No GPS Lock for Vehicle")
Don Gagne's avatar
Don Gagne committed
143 144 145 146
        }

        QGCLabel {
            anchors.horizontalCenter:   parent.horizontalCenter
147
            visible:                    warningsCol.prearmErrorVisible
Don Gagne's avatar
Don Gagne committed
148
            z:                          QGroundControl.zOrderTopMost
149
            color:                      "black"
150
            font.pointSize:             ScreenTools.largeFontPointSize
Gus Grubba's avatar
Gus Grubba committed
151
            text:                       activeVehicle ? activeVehicle.prearmError : ""
152
        }
153 154 155

        QGCLabel {
            anchors.horizontalCenter:   parent.horizontalCenter
156
            visible:                    warningsCol.prearmErrorVisible
157 158 159 160
            width:                      ScreenTools.defaultFontPixelWidth * 50
            horizontalAlignment:        Text.AlignHCenter
            wrapMode:                   Text.WordWrap
            z:                          QGroundControl.zOrderTopMost
161
            color:                      "black"
162
            font.pointSize:             ScreenTools.largeFontPointSize
163
            text:                       "The vehicle has failed a pre-arm check. In order to arm the vehicle, resolve the failure."
164
        }
165
    }
Gus Grubba's avatar
Gus Grubba committed
166 167 168 169
    Column {
        id:                     instrumentsColumn
        spacing:                ScreenTools.defaultFontPixelHeight * 0.25
        anchors.top:            parent.top
170 171
        anchors.topMargin:      QGroundControl.corePlugin.options.instrumentWidget ? (QGroundControl.corePlugin.options.instrumentWidget.widgetTopMargin + _toolsMargin) : 0
        anchors.margins:        _toolsMargin
172
        anchors.right:          parent.right
Gus Grubba's avatar
Gus Grubba committed
173 174 175 176
        //-------------------------------------------------------
        // Airmap Airspace Control
        AirspaceControl {
            id:                 airspaceControl
177
            width:              _rightPanelWidth
178
            planView:           false
179
            visible:            _airspaceEnabled
Gus Grubba's avatar
Gus Grubba committed
180 181 182 183 184
        }
        //-------------------------------------------------------
        //-- Instrument Panel
        Loader {
            id:                         instrumentsLoader
185
            anchors.margins:            _toolsMargin
Gus Grubba's avatar
Gus Grubba committed
186
            property real maxHeight:    widgetRoot ? widgetRoot.height - instrumentsColumn.y - airspaceControl.height - (ScreenTools.defaultFontPixelHeight * 4) : 0
Gus Grubba's avatar
Gus Grubba committed
187 188 189 190 191 192 193
            states: [
                State {
                    name:   "topRightMode"
                    AnchorChanges {
                        target:                 instrumentsLoader
                        anchors.verticalCenter: undefined
                        anchors.bottom:         undefined
194 195
                        anchors.top:            widgetRoot ? widgetRoot.top : undefined
                        anchors.right:          widgetRoot ? widgetRoot.right : undefined
Gus Grubba's avatar
Gus Grubba committed
196 197 198 199 200 201 202 203 204
                        anchors.left:           undefined
                    }
                },
                State {
                    name:   "centerRightMode"
                    AnchorChanges {
                        target:                 instrumentsLoader
                        anchors.top:            undefined
                        anchors.bottom:         undefined
205 206
                        anchors.verticalCenter: widgetRoot ? widgetRoot.verticalCenter : undefined
                        anchors.right:          widgetRoot ? widgetRoot.right : undefined
Gus Grubba's avatar
Gus Grubba committed
207 208 209 210 211 212 213 214 215
                        anchors.left:           undefined
                    }
                },
                State {
                    name:   "bottomRightMode"
                    AnchorChanges {
                        target:                 instrumentsLoader
                        anchors.top:            undefined
                        anchors.verticalCenter: undefined
216 217
                        anchors.bottom:         widgetRoot ? widgetRoot.bottom : undefined
                        anchors.right:          widgetRoot ? widgetRoot.right : undefined
Gus Grubba's avatar
Gus Grubba committed
218 219 220 221 222 223 224 225 226
                        anchors.left:           undefined
                    }
                },
                State {
                    name:   "topLeftMode"
                    AnchorChanges {
                        target:                 instrumentsLoader
                        anchors.verticalCenter: undefined
                        anchors.bottom:         undefined
227
                        anchors.top:            widgetRoot ? widgetRoot.top : undefined
Gus Grubba's avatar
Gus Grubba committed
228
                        anchors.right:          undefined
229
                        anchors.left:           widgetRoot ? widgetRoot.left : undefined
Gus Grubba's avatar
Gus Grubba committed
230 231 232 233 234 235 236 237
                    }
                },
                State {
                    name:   "centerLeftMode"
                    AnchorChanges {
                        target:                 instrumentsLoader
                        anchors.top:            undefined
                        anchors.bottom:         undefined
238
                        anchors.verticalCenter: widgetRoot ? widgetRoot.verticalCenter : undefined
Gus Grubba's avatar
Gus Grubba committed
239
                        anchors.right:          undefined
240
                        anchors.left:           widgetRoot ? widgetRoot.left : undefined
Gus Grubba's avatar
Gus Grubba committed
241 242 243 244 245 246 247 248
                    }
                },
                State {
                    name:   "bottomLeftMode"
                    AnchorChanges {
                        target:                 instrumentsLoader
                        anchors.top:            undefined
                        anchors.verticalCenter: undefined
249
                        anchors.bottom:         widgetRoot ? widgetRoot.bottom : undefined
Gus Grubba's avatar
Gus Grubba committed
250
                        anchors.right:          undefined
251
                        anchors.left:           widgetRoot ? widgetRoot.left : undefined
Gus Grubba's avatar
Gus Grubba committed
252
                    }
253
                }
Gus Grubba's avatar
Gus Grubba committed
254 255
            ]
        }
256
    }
257
}