FlightDisplayViewWidgets.qml 11.2 KB
Newer Older
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

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
    property var    qgcView
31
    property bool   useLightColors
32
    property var    missionController
33
    property bool   showValues:             !QGroundControl.airspaceManager.airspaceVisible
Don Gagne's avatar
Don Gagne committed
34

35 36 37
    property var    _activeVehicle:         QGroundControl.multiVehicleManager.activeVehicle
    property bool   _isSatellite:           _mainIsMap ? (_flightMap ? _flightMap.isSatelliteMap : true) : true
    property bool   _lightWidgetBorders:    _isSatellite
38
    property bool   _airspaceEnabled:       QGroundControl.airmapSupported ? QGroundControl.settingsManager.airMapSettings.enableAirMap.rawValue : false
39

40
    readonly property real _margins:        ScreenTools.defaultFontPixelHeight * 0.5
dogmaphobic's avatar
dogmaphobic committed
41

42
    QGCMapPalette { id: mapPal; lightColors: useLightColors }
43
    QGCPalette    { id: qgcPal }
44

45
    function getPreferredInstrumentWidth() {
46 47 48 49
        // 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)
50 51
    }

52
    function _setInstrumentWidget() {
53 54 55 56
        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
57 58 59 60 61 62 63 64 65
                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;
66
                case CustomInstrumentWidget.POS_TOP_RIGHT:
Gus Grubba's avatar
Gus Grubba committed
67
                    instrumentsLoader.state  = "topRightMode"
68 69
                    break;
                case CustomInstrumentWidget.POS_BOTTOM_RIGHT:
Gus Grubba's avatar
Gus Grubba committed
70
                    instrumentsLoader.state  = "bottomRightMode"
71 72 73
                    break;
                case CustomInstrumentWidget.POS_CENTER_RIGHT:
                default:
Gus Grubba's avatar
Gus Grubba committed
74
                    instrumentsLoader.state  = "centerRightMode"
75 76
                    break;
                }
77
            } else {
78
                instrumentsLoader.source = "qrc:/qml/QGCInstrumentWidgetAlternate.qml"
79
            }
80 81
        } else {
            instrumentsLoader.source = ""
82 83 84 85
        }
    }

    Connections {
86 87
        target:         QGroundControl.settingsManager.appSettings.virtualJoystick
        onValueChanged: _setInstrumentWidget()
88
    }
89 90 91 92
    Connections {
        target:         QGroundControl.settingsManager.appSettings.virtualJoystickCentralized
        onValueChanged: _setInstrumentWidget()
    }
93

94 95 96 97 98
    Connections {
        target:         QGroundControl.settingsManager.appSettings.showLargeCompass
        onValueChanged: _setInstrumentWidget()
    }

Gus Grubba's avatar
Gus Grubba committed
99
    Connections {
100
        target: QGroundControl.airspaceManager
Gus Grubba's avatar
Gus Grubba committed
101
        onAirspaceVisibleChanged: {
102
             widgetRoot.showValues = !QGroundControl.airspaceManager.airspaceVisible
Gus Grubba's avatar
Gus Grubba committed
103 104 105
        }
    }

106 107 108 109
    Component.onCompleted: {
        _setInstrumentWidget()
    }

Don Gagne's avatar
Don Gagne committed
110
    //-- Map warnings
111 112 113 114 115 116 117 118 119 120

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

121
    Column {
122
        id:                         warningsCol
Don Gagne's avatar
Don Gagne committed
123
        anchors.horizontalCenter:   parent.horizontalCenter
124
        anchors.top:                parent.verticalCenter
Don Gagne's avatar
Don Gagne committed
125 126
        spacing:                    ScreenTools.defaultFontPixelHeight

127 128 129
        property bool noGPSLockVisible:     _activeVehicle && !_activeVehicle.coordinate.isValid && _mainIsMap
        property bool prearmErrorVisible:   _activeVehicle && _activeVehicle.prearmError

Don Gagne's avatar
Don Gagne committed
130 131
        QGCLabel {
            anchors.horizontalCenter:   parent.horizontalCenter
132
            visible:                    warningsCol.noGPSLockVisible
Don Gagne's avatar
Don Gagne committed
133
            z:                          QGroundControl.zOrderTopMost
134
            color:                      "black"
135
            font.pointSize:             ScreenTools.largeFontPointSize
136
            text:                       qsTr("No GPS Lock for Vehicle")
Don Gagne's avatar
Don Gagne committed
137 138 139 140
        }

        QGCLabel {
            anchors.horizontalCenter:   parent.horizontalCenter
141
            visible:                    warningsCol.prearmErrorVisible
Don Gagne's avatar
Don Gagne committed
142
            z:                          QGroundControl.zOrderTopMost
143
            color:                      "black"
144
            font.pointSize:             ScreenTools.largeFontPointSize
Don Gagne's avatar
Don Gagne committed
145
            text:                       _activeVehicle ? _activeVehicle.prearmError : ""
146
        }
147 148 149

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