FlightDisplayWidget.qml 14.5 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:
    {
88
        mapBackground.visible               = getBool(flightDisplay.loadSetting("showMapBackground",        "0"));
Gus Grubba's avatar
Gus Grubba committed
89
        videoBackground.visible             = getBool(flightDisplay.loadSetting("showVideoBackground",      "0"));
90
        showPitchIndicator                  = getBool(flightDisplay.loadSetting("showPitchIndicator",       "1"));
91 92 93 94 95 96
        altitudeWidget.visible              = getBool(flightDisplay.loadSetting("showAltitudeWidget",       "1"));
        speedWidget.visible                 = getBool(flightDisplay.loadSetting("showSpeedWidget",          "1"));
        currentSpeed.showAirSpeed           = getBool(flightDisplay.loadSetting("showCurrentAirSpeed",      "1"));
        currentSpeed.showGroundSpeed        = getBool(flightDisplay.loadSetting("showCurrentGroundSpeed",   "1"));
        currentAltitude.showClimbRate       = getBool(flightDisplay.loadSetting("showCurrentClimbRate",     "1"));
        currentAltitude.showAltitude        = getBool(flightDisplay.loadSetting("showCurrentAltitude",      "1"));
97

98 99
        // Insert Map Type menu before separator
        contextMenu.insertItem(2, mapBackground.mapMenu);
Gus Grubba's avatar
Gus Grubba committed
100 101 102 103
        // Video or Map. Not both:
        if(mapBackground.visible && videoBackground.visible) {
            videoBackground.visible = false;
            flightDisplay.saveSetting("showVideoBackground", setBool(videoBackground.visible));
104
        }
105 106 107 108 109 110 111
        // 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;
112 113
    }

dogmaphobic's avatar
dogmaphobic committed
114 115 116 117
    Menu {
        id: contextMenu

        MenuItem {
118
            text: "Map Background"
dogmaphobic's avatar
dogmaphobic committed
119
            checkable: true
120
            checked: mapBackground.visible
dogmaphobic's avatar
dogmaphobic committed
121 122
            onTriggered:
            {
123
                enforceExclusiveOption(mapBackground, videoBackground, "showMapBackground", "showVideoBackground");
dogmaphobic's avatar
dogmaphobic committed
124 125 126
            }
        }

Gus Grubba's avatar
Gus Grubba committed
127 128
        MenuSeparator {}

dogmaphobic's avatar
dogmaphobic committed
129
        MenuItem {
130
            id: videoMenu
Gus Grubba's avatar
Gus Grubba committed
131
            text: "Video Background"
dogmaphobic's avatar
dogmaphobic committed
132
            checkable: true
Gus Grubba's avatar
Gus Grubba committed
133
            checked: videoBackground.visible
dogmaphobic's avatar
dogmaphobic committed
134 135
            onTriggered:
            {
136
                enforceExclusiveOption(videoBackground, mapBackground, "showVideoBackground", "showMapBackground");
dogmaphobic's avatar
dogmaphobic committed
137 138
            }
        }
139 140

        MenuSeparator {}
dogmaphobic's avatar
dogmaphobic committed
141 142 143

        MenuItem {
            text: "Pitch Indicator"
144 145
            checkable:  true
            checked:    showPitchIndicator
146
            enabled:    attitudeHUD.visible || attitudeWidget.visible
dogmaphobic's avatar
dogmaphobic committed
147 148
            onTriggered:
            {
149 150 151 152 153
                showPitchIndicator = !showPitchIndicator;
                flightDisplay.saveSetting("showPitchIndicator", setBool(showPitchIndicator));
            }
        }

dogmaphobic's avatar
dogmaphobic committed
154 155 156 157 158 159 160
        MenuItem {
            text: "Altitude Indicator"
            checkable: true
            checked: altitudeWidget.visible
            onTriggered:
            {
                altitudeWidget.visible = !altitudeWidget.visible;
161
                flightDisplay.saveSetting("showAltitudeWidget", setBool(altitudeWidget.visible));
dogmaphobic's avatar
dogmaphobic committed
162 163 164 165 166 167 168 169 170 171
            }
        }

        MenuItem {
            text: "Current Altitude"
            checkable: true
            checked: currentAltitude.showAltitude
            onTriggered:
            {
                currentAltitude.showAltitude = !currentAltitude.showAltitude;
172
                flightDisplay.saveSetting("showCurrentAltitude", setBool(currentAltitude.showAltitude));
dogmaphobic's avatar
dogmaphobic committed
173 174 175 176 177 178 179 180 181 182
            }
        }

        MenuItem {
            text: "Current Climb Rate"
            checkable: true
            checked: currentAltitude.showClimbRate
            onTriggered:
            {
                currentAltitude.showClimbRate = !currentAltitude.showClimbRate;
183
                flightDisplay.saveSetting("showCurrentClimbRate", setBool(currentAltitude.showClimbRate));
dogmaphobic's avatar
dogmaphobic committed
184 185 186 187 188 189 190 191 192 193
            }
        }

        MenuItem {
            text: "Speed Indicator"
            checkable: true
            checked: speedWidget.visible
            onTriggered:
            {
                speedWidget.visible = !speedWidget.visible;
194
                flightDisplay.saveSetting("showSpeedWidget", setBool(speedWidget.visible));
dogmaphobic's avatar
dogmaphobic committed
195 196 197 198 199 200 201 202 203 204
            }
        }

        MenuItem {
            text: "Current Air Speed"
            checkable: true
            checked: currentSpeed.showAirSpeed
            onTriggered:
            {
                currentSpeed.showAirSpeed = !currentSpeed.showAirSpeed;
205
                flightDisplay.saveSetting("showCurrentAirSpeed", setBool(currentSpeed.showAirSpeed));
dogmaphobic's avatar
dogmaphobic committed
206 207 208 209 210 211 212 213 214 215
            }
        }

        MenuItem {
            text: "Current Ground Speed"
            checkable: true
            checked: currentSpeed.showGroundSpeed
            onTriggered:
            {
                currentSpeed.showGroundSpeed = !currentSpeed.showGroundSpeed;
216
                flightDisplay.saveSetting("showCurrentGroundSpeed", setBool(currentSpeed.showGroundSpeed));
dogmaphobic's avatar
dogmaphobic committed
217 218 219 220 221 222 223 224 225
            }
        }

        MenuSeparator {}

        MenuItem {
            text: "Restore Defaults"
            onTriggered:
            {
226
                showPitchIndicator = true;
227
                flightDisplay.saveSetting("showPitchIndicator", setBool(showPitchIndicator));
228 229 230 231
                attitudeWidget.visible = false;
                flightDisplay.saveSetting("showAttitudeWidget", setBool(attitudeWidget.visible));
                compassWidget.visible = false
                flightDisplay.saveSetting("showCompassWidget", setBool(compassWidget.visible));
dogmaphobic's avatar
dogmaphobic committed
232
                altitudeWidget.visible = true;
233
                flightDisplay.saveSetting("showAltitudeWidget", setBool(altitudeWidget.visible));
dogmaphobic's avatar
dogmaphobic committed
234
                currentAltitude.showAltitude = true;
235
                flightDisplay.saveSetting("showCurrentAltitude", setBool(currentAltitude.showAltitude));
dogmaphobic's avatar
dogmaphobic committed
236
                currentAltitude.showClimbRate = true;
237
                flightDisplay.saveSetting("showCurrentClimbRate", setBool(currentAltitude.showClimbRate));
dogmaphobic's avatar
dogmaphobic committed
238
                speedWidget.visible = true;
239
                flightDisplay.saveSetting("showSpeedWidget", setBool(speedWidget.visible));
dogmaphobic's avatar
dogmaphobic committed
240
                currentSpeed.showAirSpeed = true;
241
                flightDisplay.saveSetting("showCurrentAirSpeed", setBool(currentSpeed.showAirSpeed));
dogmaphobic's avatar
dogmaphobic committed
242
                currentSpeed.showGroundSpeed = true;
243 244 245
                flightDisplay.saveSetting("showCurrentGroundSpeed", setBool(currentSpeed.showGroundSpeed));
                mapBackground.visible = false;
                flightDisplay.saveSetting("showMapBackground", setBool(mapBackground.visible));
Gus Grubba's avatar
Gus Grubba committed
246 247
                videoBackground.visible = false;
                flightDisplay.saveSetting("showVideoBackground", setBool(videoBackground.visible));
dogmaphobic's avatar
dogmaphobic committed
248 249 250 251 252
            }
        }

    }

253 254
    // Video and Map backgrounds are exclusive. If one is enabled the other is disabled.

Gus Grubba's avatar
Gus Grubba committed
255 256 257 258 259 260 261 262
    QGCVideoBackground {
        id:                 videoBackground
        anchors.fill:       parent
        display:            videoDisplay
        receiver:           videoReceiver
        z:                  10
    }

263
    FlightMap {
264 265
        id:                 mapBackground
        anchors.fill:       parent
266
        mapName:            'FlightDisplayWidget'
267 268
        latitude:           mapBackground.visible ? root.latitude : root.defaultLatitude
        longitude:          mapBackground.visible ? root.longitude : root.defaultLongitude
269
        z:                  10
dogmaphobic's avatar
dogmaphobic committed
270 271
    }

272 273 274 275 276 277 278 279
    // 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)
280
        heading:            root.heading
281
        active:             multiVehicleManager.activeVehicleAvailable
282 283 284 285 286 287 288 289 290 291 292 293 294 295
        z:                  70
    }

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

    QGCArtificialHorizon {
        id:                 artificialHoriz
        anchors.fill:       parent
        rollAngle:          roll
        pitchAngle:         pitch
        visible:            !videoBackground.visible && !mapBackground.visible
    }

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

297 298
    QGCAttitudeHUD {
        id:                 attitudeHUD
299 300
        rollAngle:          roll
        pitchAngle:         pitch
301 302 303
        showPitch:          showPitchIndicator
        width:              ScreenTools.defaultFontPixelSize * (30)
        height:             ScreenTools.defaultFontPixelSize * (30)
304
        active:             multiVehicleManager.activeVehicleAvailable
305 306 307
        z:                  20
    }

dogmaphobic's avatar
dogmaphobic committed
308
    QGCAltitudeWidget {
309 310
        id:                 altitudeWidget
        anchors.right:      parent.right
Don Gagne's avatar
Don Gagne committed
311 312
        width:              ScreenTools.defaultFontPixelSize * (5)
        height:             parent.height * 0.65 > ScreenTools.defaultFontPixelSize * (23.4) ? ScreenTools.defaultFontPixelSize * (23.4) : parent.height * 0.65
313
        altitude:           root.altitudeWGS84
314
        z:                  30
dogmaphobic's avatar
dogmaphobic committed
315 316 317
    }

    QGCSpeedWidget {
318 319
        id:                 speedWidget
        anchors.left:       parent.left
Don Gagne's avatar
Don Gagne committed
320 321
        width:              ScreenTools.defaultFontPixelSize * (5)
        height:             parent.height * 0.65 > ScreenTools.defaultFontPixelSize * (23.4) ? ScreenTools.defaultFontPixelSize * (23.4) : parent.height * 0.65
322
        speed:              root.groundSpeed
323
        z:                  40
dogmaphobic's avatar
dogmaphobic committed
324 325 326 327 328
    }

    QGCCurrentSpeed {
        id: currentSpeed
        anchors.left:       parent.left
Don Gagne's avatar
Don Gagne committed
329
        width:              ScreenTools.defaultFontPixelSize * (6.25)
330 331
        airspeed:           root.airSpeed
        groundspeed:        root.groundSpeed
332
        active:             multiVehicleManager.activeVehicleAvailable
dogmaphobic's avatar
dogmaphobic committed
333 334
        showAirSpeed:       true
        showGroundSpeed:    true
dogmaphobic's avatar
dogmaphobic committed
335
        visible:            (currentSpeed.showGroundSpeed || currentSpeed.showAirSpeed)
dogmaphobic's avatar
dogmaphobic committed
336 337 338 339 340
        z:                  50
    }

    QGCCurrentAltitude {
        id: currentAltitude
dogmaphobic's avatar
dogmaphobic committed
341
        anchors.right:      parent.right
Don Gagne's avatar
Don Gagne committed
342
        width:              ScreenTools.defaultFontPixelSize * (6.25)
343 344
        altitude:           root.altitudeWGS84
        vertZ:              root.climbRate
dogmaphobic's avatar
dogmaphobic committed
345 346
        showAltitude:       true
        showClimbRate:      true
347
        active:             multiVehicleManager.activeVehicleAvailable
dogmaphobic's avatar
dogmaphobic committed
348 349
        visible:            (currentAltitude.showAltitude || currentAltitude.showClimbRate)
        z:                  60
dogmaphobic's avatar
dogmaphobic committed
350 351
    }

dogmaphobic's avatar
dogmaphobic committed
352 353 354
    //- Context Menu
    MouseArea {
        anchors.fill: parent
355
        z: 1000
dogmaphobic's avatar
dogmaphobic committed
356 357 358 359 360
        acceptedButtons: Qt.RightButton
        onClicked: {
            if (mouse.button == Qt.RightButton)
            {
                contextMenu.popup();
dogmaphobic's avatar
dogmaphobic committed
361 362
            }
        }
363
    }
dogmaphobic's avatar
dogmaphobic committed
364
}