FlightDisplayWidget.qml 8.06 KB
Newer Older
dogmaphobic's avatar
dogmaphobic committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
/*=====================================================================

QGroundControl Open Source Ground Control Station

(c) 2009, 2015 QGROUNDCONTROL PROJECT <http://www.qgroundcontrol.org>

This file is part of the QGROUNDCONTROL project

    QGROUNDCONTROL is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    QGROUNDCONTROL is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with QGROUNDCONTROL. If not, see <http://www.gnu.org/licenses/>.

======================================================================*/

24 25 26 27
import QtQuick                  2.4
import QtQuick.Controls         1.3
import QtQuick.Controls.Styles  1.2
import QtQuick.Dialogs          1.2
dogmaphobic's avatar
dogmaphobic committed
28

29 30 31 32 33 34
import QGroundControl.FlightMap     1.0
import QGroundControl.ScreenTools   1.0
import QGroundControl.Controls      1.0
import QGroundControl.Palette       1.0

/// Flight Display Widget
35
Item {
dogmaphobic's avatar
dogmaphobic committed
36
    id: root
37 38

    property var __qgcPal: QGCPalette { colorGroupEnabled: enabled }
dogmaphobic's avatar
dogmaphobic committed
39

40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
    property var activeVehicle: multiVehicleManager.activeVehicle

    readonly property real defaultLatitude:         37.803784
    readonly property real defaultLongitude:        -122.462276
    readonly property real defaultRoll:             0
    readonly property real defaultPitch:            0
    readonly property real defaultHeading:          0
    readonly property real defaultAltitudeWGS84:    0
    readonly property real defaultGroundSpeed:      0
    readonly property real defaultAirSpeed:         0
    readonly property real defaultClimbRate:        0

    property real roll:             activeVehicle ? (isNaN(activeVehicle.roll) ? defaultRoll : activeVehicle.roll) : defaultRoll
    property real pitch:            activeVehicle ? (isNaN(activeVehicle.pitch) ? defaultPitch : activeVehicle.pitch) : defaultPitch
    property real latitude:         activeVehicle ? ((activeVehicle.latitude  === 0) ? defaultLatitude : activeVehicle.latitude) : defaultLatitude
Don Gagne's avatar
Don Gagne committed
55
    property real longitude:        activeVehicle ? ((activeVehicle.longitude === 0) ? defaultLongitude : activeVehicle.longitude) : defaultLongitude
56 57 58 59 60
    property real heading:          activeVehicle ? (isNaN(activeVehicle.heading) ? defaultHeading : activeVehicle.heading) : defaultHeading
    property real altitudeWGS84:    activeVehicle ? activeVehicle.altitudeWGS84 : defaultAltitudeWGS84
    property real groundSpeed:      activeVehicle ? activeVehicle.groundSpeed : defaultGroundSpeed
    property real airSpeed:         activeVehicle ? activeVehicle.airSpeed : defaultAirSpeed
    property real climbRate:        activeVehicle ? activeVehicle.climbRate : defaultClimbRate
dogmaphobic's avatar
dogmaphobic committed
61

62
    property bool showPitchIndicator:       true
63

64 65 66 67 68 69 70 71
    function getBool(value) {
        return value === '0' ? false : true;
    }

    function setBool(value) {
        return value ? "1" : "0";
    }

72 73 74 75 76
    function enforceExclusiveOption(setWidget, alternateWidget, defaultSetting, alternateSetting) {
        setWidget.visible = !setWidget.visible;
        flightDisplay.saveSetting(defaultSetting, setBool(setWidget.visible));
        alternateWidget.visible = setWidget.visible ? false : alternateWidget.visible;
        flightDisplay.saveSetting(alternateSetting, setBool(alternateWidget.visible));
Gus Grubba's avatar
Gus Grubba committed
77 78
    }

dogmaphobic's avatar
dogmaphobic committed
79 80 81 82 83 84 85
    Connections {
        target: flightDisplay
        onShowOptionsMenuChanged: {
            contextMenu.popup();
        }
    }

dogmaphobic's avatar
dogmaphobic committed
86 87
    Component.onCompleted:
    {
Don Gagne's avatar
Don Gagne committed
88 89
        videoBackground.visible = getBool(flightDisplay.loadSetting("showVideoBackground", "0"));

90 91 92 93 94 95 96
        // Disable video if we don't have support for it
        if(!flightDisplay.hasVideo) {
            videoBackground.visible = false;
            flightDisplay.saveSetting("showVideoBackground", setBool(videoBackground.visible));
        }
        // Enable/Disable menu accordingly
        videoMenu.enabled = flightDisplay.hasVideo;
97 98
    }

dogmaphobic's avatar
dogmaphobic committed
99 100 101 102
    Menu {
        id: contextMenu

        MenuItem {
103
            id: videoMenu
Gus Grubba's avatar
Gus Grubba committed
104
            text: "Video Background"
dogmaphobic's avatar
dogmaphobic committed
105
            checkable: true
Gus Grubba's avatar
Gus Grubba committed
106
            checked: videoBackground.visible
Don Gagne's avatar
Don Gagne committed
107
            onToggled: videoBackground.visible = checked
dogmaphobic's avatar
dogmaphobic committed
108 109 110
        }
    }

111 112
    // Video and Map backgrounds are exclusive. If one is enabled the other is disabled.

Gus Grubba's avatar
Gus Grubba committed
113 114 115 116 117 118 119 120
    QGCVideoBackground {
        id:                 videoBackground
        anchors.fill:       parent
        display:            videoDisplay
        receiver:           videoReceiver
        z:                  10
    }

121 122 123 124 125 126 127 128
    // HUD (lower middle) Compass

    QGCCompassHUD {
        id:                 compassHUD
        y:                  root.height * 0.7
        x:                  root.width  * 0.5 - ScreenTools.defaultFontPixelSize * (5)
        width:              ScreenTools.defaultFontPixelSize * (10)
        height:             ScreenTools.defaultFontPixelSize * (10)
129
        heading:            root.heading
130
        active:             multiVehicleManager.activeVehicleAvailable
131 132 133 134 135 136 137 138 139 140
        z:                  70
    }

    // Sky/Ground background (visible when no Map or Video is enabled)

    QGCArtificialHorizon {
        id:                 artificialHoriz
        anchors.fill:       parent
        rollAngle:          roll
        pitchAngle:         pitch
Don Gagne's avatar
Don Gagne committed
141
        visible:            !videoBackground.visible
142 143 144
    }

    // HUD (center) Attitude Indicator
dogmaphobic's avatar
dogmaphobic committed
145

146 147
    QGCAttitudeHUD {
        id:                 attitudeHUD
148 149
        rollAngle:          roll
        pitchAngle:         pitch
150 151 152
        showPitch:          showPitchIndicator
        width:              ScreenTools.defaultFontPixelSize * (30)
        height:             ScreenTools.defaultFontPixelSize * (30)
153
        active:             multiVehicleManager.activeVehicleAvailable
154 155 156
        z:                  20
    }

dogmaphobic's avatar
dogmaphobic committed
157
    QGCAltitudeWidget {
158 159
        id:                 altitudeWidget
        anchors.right:      parent.right
Don Gagne's avatar
Don Gagne committed
160 161
        width:              ScreenTools.defaultFontPixelSize * (5)
        height:             parent.height * 0.65 > ScreenTools.defaultFontPixelSize * (23.4) ? ScreenTools.defaultFontPixelSize * (23.4) : parent.height * 0.65
162
        altitude:           root.altitudeWGS84
163
        z:                  30
dogmaphobic's avatar
dogmaphobic committed
164 165 166
    }

    QGCSpeedWidget {
167 168
        id:                 speedWidget
        anchors.left:       parent.left
Don Gagne's avatar
Don Gagne committed
169 170
        width:              ScreenTools.defaultFontPixelSize * (5)
        height:             parent.height * 0.65 > ScreenTools.defaultFontPixelSize * (23.4) ? ScreenTools.defaultFontPixelSize * (23.4) : parent.height * 0.65
171
        speed:              root.groundSpeed
172
        z:                  40
dogmaphobic's avatar
dogmaphobic committed
173 174 175 176 177
    }

    QGCCurrentSpeed {
        id: currentSpeed
        anchors.left:       parent.left
Don Gagne's avatar
Don Gagne committed
178
        width:              ScreenTools.defaultFontPixelSize * (6.25)
179 180
        airspeed:           root.airSpeed
        groundspeed:        root.groundSpeed
181
        active:             multiVehicleManager.activeVehicleAvailable
dogmaphobic's avatar
dogmaphobic committed
182 183
        showAirSpeed:       true
        showGroundSpeed:    true
dogmaphobic's avatar
dogmaphobic committed
184
        visible:            (currentSpeed.showGroundSpeed || currentSpeed.showAirSpeed)
dogmaphobic's avatar
dogmaphobic committed
185 186 187 188 189
        z:                  50
    }

    QGCCurrentAltitude {
        id: currentAltitude
dogmaphobic's avatar
dogmaphobic committed
190
        anchors.right:      parent.right
Don Gagne's avatar
Don Gagne committed
191
        width:              ScreenTools.defaultFontPixelSize * (6.25)
192 193
        altitude:           root.altitudeWGS84
        vertZ:              root.climbRate
dogmaphobic's avatar
dogmaphobic committed
194 195
        showAltitude:       true
        showClimbRate:      true
196
        active:             multiVehicleManager.activeVehicleAvailable
dogmaphobic's avatar
dogmaphobic committed
197 198
        visible:            (currentAltitude.showAltitude || currentAltitude.showClimbRate)
        z:                  60
dogmaphobic's avatar
dogmaphobic committed
199 200
    }

Don Gagne's avatar
Don Gagne committed
201 202 203 204 205 206
    QGCButton {
        anchors.margins:    ScreenTools.defaultFontPixelWidth
        anchors.right:      parent.right
        anchors.bottom:     parent.bottom
        text:               "Options"
        menu:               contextMenu
207
    }
dogmaphobic's avatar
dogmaphobic committed
208
}