FlightDisplayViewWidgets.qml 7.21 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

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 25

Item {
26
    id: _root
27

28
    property var    qgcView
29
    property bool   useLightColors
30
    property var    missionController
Don Gagne's avatar
Don Gagne committed
31

32 33 34
    property var    _activeVehicle:         QGroundControl.multiVehicleManager.activeVehicle
    property bool   _isSatellite:           _mainIsMap ? (_flightMap ? _flightMap.isSatelliteMap : true) : true
    property bool   _lightWidgetBorders:    _isSatellite
35

36
    readonly property real _margins:        ScreenTools.defaultFontPixelHeight * 0.5
dogmaphobic's avatar
dogmaphobic committed
37

38
    QGCMapPalette { id: mapPal; lightColors: useLightColors }
39
    QGCPalette    { id: qgcPal }
40

41
    function getPreferredInstrumentWidth() {
42
        if(ScreenTools.isMobile) {
43
            return ScreenTools.isTinyScreen ? mainWindow.width * 0.2 : mainWindow.width * 0.15
44 45 46 47 48
        }
        var w = mainWindow.width * 0.15
        return Math.min(w, 200)
    }

49
    function _setInstrumentWidget() {
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
        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) {
                case CustomInstrumentWidget.POS_TOP_RIGHT:
                    instrumentsLoader.state  = "topMode"
                    break;
                case CustomInstrumentWidget.POS_BOTTOM_RIGHT:
                    instrumentsLoader.state  = "bottomMode"
                    break;
                case CustomInstrumentWidget.POS_CENTER_RIGHT:
                default:
                    instrumentsLoader.state  = "centerMode"
                    break;
                }
65
            } else {
66 67 68
                // Note: We currently show alternate instruments all the time. This is a trial change for daily builds.
                // Leaving non-alternate code in for now in case the trial fails.
                var useAlternateInstruments = true//QGroundControl.settingsManager.appSettings.virtualJoystick.value || ScreenTools.isTinyScreen
69 70 71 72 73 74 75
                if(useAlternateInstruments) {
                    instrumentsLoader.source = "qrc:/qml/QGCInstrumentWidgetAlternate.qml"
                    instrumentsLoader.state  = "topMode"
                } else {
                    instrumentsLoader.source = "qrc:/qml/QGCInstrumentWidget.qml"
                    instrumentsLoader.state  = QGroundControl.settingsManager.appSettings.showLargeCompass.value == 1 ? "centerMode" : "topMode"
                }
76
            }
77 78
        } else {
            instrumentsLoader.source = ""
79 80 81 82
        }
    }

    Connections {
83 84
        target:         QGroundControl.settingsManager.appSettings.virtualJoystick
        onValueChanged: _setInstrumentWidget()
85 86
    }

87 88 89 90 91
    Connections {
        target:         QGroundControl.settingsManager.appSettings.showLargeCompass
        onValueChanged: _setInstrumentWidget()
    }

92 93 94 95
    Component.onCompleted: {
        _setInstrumentWidget()
    }

Don Gagne's avatar
Don Gagne committed
96
    //-- Map warnings
97
    Column {
Don Gagne's avatar
Don Gagne committed
98
        anchors.horizontalCenter:   parent.horizontalCenter
99
        anchors.top:                parent.verticalCenter
Don Gagne's avatar
Don Gagne committed
100 101 102 103
        spacing:                    ScreenTools.defaultFontPixelHeight

        QGCLabel {
            anchors.horizontalCenter:   parent.horizontalCenter
104
            visible:                    _activeVehicle && !_activeVehicle.coordinate.isValid && _mainIsMap
Don Gagne's avatar
Don Gagne committed
105 106
            z:                          QGroundControl.zOrderTopMost
            color:                      mapPal.text
107
            font.pointSize:             ScreenTools.largeFontPointSize
108
            text:                       qsTr("No GPS Lock for Vehicle")
Don Gagne's avatar
Don Gagne committed
109 110 111 112
        }

        QGCLabel {
            anchors.horizontalCenter:   parent.horizontalCenter
113
            visible:                    _activeVehicle && _activeVehicle.prearmError
Don Gagne's avatar
Don Gagne committed
114 115
            z:                          QGroundControl.zOrderTopMost
            color:                      mapPal.text
116
            font.pointSize:             ScreenTools.largeFontPointSize
Don Gagne's avatar
Don Gagne committed
117
            text:                       _activeVehicle ? _activeVehicle.prearmError : ""
118
        }
119 120 121 122 123 124 125 126 127 128 129 130

        QGCLabel {
            anchors.horizontalCenter:   parent.horizontalCenter
            visible:                    _activeVehicle && _activeVehicle.prearmError
            width:                      ScreenTools.defaultFontPixelWidth * 50
            horizontalAlignment:        Text.AlignHCenter
            wrapMode:                   Text.WordWrap
            z:                          QGroundControl.zOrderTopMost
            color:                      mapPal.text
            font.pointSize:             ScreenTools.largeFontPointSize
            text:                       "The vehicle has failed a pre-arm check. In order to arm the vehicle, resolve the failure or disable the arming check via the Safety tab on the Vehicle Setup page."
        }
131 132
    }

dogmaphobic's avatar
dogmaphobic committed
133
    //-- Instrument Panel
134 135
    Loader {
        id:                     instrumentsLoader
136
        anchors.margins:        ScreenTools.defaultFontPixelHeight / 2
137
        anchors.right:          parent.right
138
        z:                      QGroundControl.zOrderWidgets
139 140 141 142 143 144 145 146
        property var  qgcView:  _root.qgcView
        property real maxHeight:parent.height - (anchors.margins * 2)
        states: [
            State {
                name:   "topMode"
                AnchorChanges {
                    target:                 instrumentsLoader
                    anchors.verticalCenter: undefined
147
                    anchors.bottom:         undefined
148 149 150 151 152 153 154 155
                    anchors.top:            _root ? _root.top : undefined
                }
            },
            State {
                name:   "centerMode"
                AnchorChanges {
                    target:                 instrumentsLoader
                    anchors.top:            undefined
156
                    anchors.bottom:         undefined
157 158
                    anchors.verticalCenter: _root ? _root.verticalCenter : undefined
                }
159 160 161 162 163 164 165 166 167
            },
            State {
                name:   "bottomMode"
                AnchorChanges {
                    target:                 instrumentsLoader
                    anchors.top:            undefined
                    anchors.verticalCenter: undefined
                    anchors.bottom:         _root ? _root.bottom : undefined
                }
168 169
            }
        ]
170
    }
171
}