FlightDisplay.qml 19.1 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 24 25
/*=====================================================================

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/>.

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

/**
 * @file
26
 *   @brief QGC Main Flight Display
dogmaphobic's avatar
dogmaphobic committed
27 28 29
 *   @author Gus Grubba <mavlink@grubba.com>
 */

Gus Grubba's avatar
Gus Grubba committed
30
import QtQuick 2.4
31
import QtQuick.Controls 1.3
dogmaphobic's avatar
dogmaphobic committed
32
import QtQuick.Controls.Styles 1.2
33
import QtQuick.Dialogs 1.2
dogmaphobic's avatar
dogmaphobic committed
34

35
import QGroundControl.FlightMap 1.0
36 37 38
import QGroundControl.ScreenTools 1.0
import QGroundControl.Controls 1.0
import QGroundControl.Palette 1.0
dogmaphobic's avatar
dogmaphobic committed
39

40
Item {
dogmaphobic's avatar
dogmaphobic committed
41
    id: root
42 43

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

45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65
    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
    property real longitude:        activeVehicle ? ((activeVehicle.longitude === 0) ? defaultlongitude : activeVehicle.longitude) : defaultLongitude
    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
66

67
    property bool showPitchIndicator:       true
68

69 70 71 72 73 74 75 76
    function getBool(value) {
        return value === '0' ? false : true;
    }

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

77 78 79 80 81
    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
82 83
    }

dogmaphobic's avatar
dogmaphobic committed
84 85 86 87 88 89 90
    Connections {
        target: flightDisplay
        onShowOptionsMenuChanged: {
            contextMenu.popup();
        }
    }

dogmaphobic's avatar
dogmaphobic committed
91 92
    Component.onCompleted:
    {
93 94
        mapBackground.visible               = getBool(flightDisplay.loadSetting("showMapBackground",        "0"));
        mapBackground.alwaysNorth           = getBool(flightDisplay.loadSetting("mapAlwaysPointsNorth",     "0"));
Gus Grubba's avatar
Gus Grubba committed
95
        videoBackground.visible             = getBool(flightDisplay.loadSetting("showVideoBackground",      "0"));
96
        showPitchIndicator                  = getBool(flightDisplay.loadSetting("showPitchIndicator",       "1"));
97 98 99 100
        compassWidget.visible               = getBool(flightDisplay.loadSetting("showCompassWidget",        "0"));
        compassHUD.visible                  = getBool(flightDisplay.loadSetting("showCompassHUD",           "1"));
        attitudeWidget.visible              = getBool(flightDisplay.loadSetting("showAttitudeWidget",       "0"));
        attitudeHUD.visible                 = getBool(flightDisplay.loadSetting("showAttitudeHUD",          "1"));
101 102 103 104 105 106
        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"));
107 108
        // Insert Map Type menu before separator
        contextMenu.insertItem(2, mapBackground.mapMenu);
Gus Grubba's avatar
Gus Grubba committed
109 110 111 112
        // Video or Map. Not both:
        if(mapBackground.visible && videoBackground.visible) {
            videoBackground.visible = false;
            flightDisplay.saveSetting("showVideoBackground", setBool(videoBackground.visible));
113
        }
114 115 116 117 118 119 120 121 122 123
        // Compass HUD or Widget. Not both:
        if(compassWidget.visible && compassHUD.visible) {
            compassWidget.visible = false;
            flightDisplay.saveSetting("showCompassWidget", setBool(compassWidget.visible));
        }
        // Attitude HUD or Widget. Not both:
        if(attitudeWidget.visible && attitudeHUD.visible) {
            attitudeWidget.visible = false;
            flightDisplay.saveSetting("showAttitudeWidget", setBool(attitudeWidget.visible));
        }
124 125 126 127 128 129 130
        // 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;
131 132
    }

dogmaphobic's avatar
dogmaphobic committed
133 134 135 136
    Menu {
        id: contextMenu

        MenuItem {
137
            text: "Map Background"
dogmaphobic's avatar
dogmaphobic committed
138
            checkable: true
139
            checked: mapBackground.visible
dogmaphobic's avatar
dogmaphobic committed
140 141
            onTriggered:
            {
142
                enforceExclusiveOption(mapBackground, videoBackground, "showMapBackground", "showVideoBackground");
dogmaphobic's avatar
dogmaphobic committed
143 144 145
            }
        }

146
        /*
Gus Grubba's avatar
Gus Grubba committed
147
        //-- Off until Qt 5.5.x, which fixes bug in 5.4.x
148
        MenuItem {
Gus Grubba's avatar
Gus Grubba committed
149 150 151
            text: "Map Always Points North"
            checkable: true
            checked: mapBackground.alwaysNorth
152 153
            onTriggered:
            {
Gus Grubba's avatar
Gus Grubba committed
154 155
                mapBackground.alwaysNorth = !mapBackground.alwaysNorth;
                flightDisplay.saveSetting("mapAlwaysPointsNorth", setBool(mapBackground.alwaysNorth));
156 157 158 159
            }
        }
        */

Gus Grubba's avatar
Gus Grubba committed
160 161
        MenuSeparator {}

dogmaphobic's avatar
dogmaphobic committed
162
        MenuItem {
163
            id: videoMenu
Gus Grubba's avatar
Gus Grubba committed
164
            text: "Video Background"
dogmaphobic's avatar
dogmaphobic committed
165
            checkable: true
Gus Grubba's avatar
Gus Grubba committed
166
            checked: videoBackground.visible
dogmaphobic's avatar
dogmaphobic committed
167 168
            onTriggered:
            {
169
                enforceExclusiveOption(videoBackground, mapBackground, "showVideoBackground", "showMapBackground");
dogmaphobic's avatar
dogmaphobic committed
170 171
            }
        }
172 173

        MenuSeparator {}
dogmaphobic's avatar
dogmaphobic committed
174

175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194
        MenuItem {
            text: "Attitude Widget"
            checkable:  true
            checked:    attitudeWidget.visible
            onTriggered:
            {
                enforceExclusiveOption(attitudeWidget, attitudeHUD, "showAttitudeWidget", "showAttitudeHUD");
            }
        }

        MenuItem {
            text: "Attitude HUD"
            checkable:  true
            checked:    attitudeHUD.visible
            onTriggered:
            {
                enforceExclusiveOption(attitudeHUD, attitudeWidget, "showAttitudeHUD", "showAttitudeWidget");
            }
        }

dogmaphobic's avatar
dogmaphobic committed
195 196
        MenuItem {
            text: "Pitch Indicator"
197 198
            checkable:  true
            checked:    showPitchIndicator
199
            enabled:    attitudeHUD.visible || attitudeWidget.visible
dogmaphobic's avatar
dogmaphobic committed
200 201
            onTriggered:
            {
202 203 204 205 206 207
                showPitchIndicator = !showPitchIndicator;
                flightDisplay.saveSetting("showPitchIndicator", setBool(showPitchIndicator));
            }
        }

        MenuItem {
208 209 210
            text: "Compass Widget"
            checkable: true
            checked: compassWidget.visible
211 212
            onTriggered:
            {
213
                enforceExclusiveOption(compassWidget, compassHUD, "showCompassWidget", "showCompassHUD");
214 215 216 217
            }
        }

        MenuItem {
218
            text: "Compass HUD"
219
            checkable: true
220
            checked: compassHUD.visible
221 222
            onTriggered:
            {
223
                enforceExclusiveOption(compassHUD, compassWidget, "showCompassHUD", "showCompassWidget");
dogmaphobic's avatar
dogmaphobic committed
224 225 226 227 228 229 230 231 232 233
            }
        }

        MenuItem {
            text: "Altitude Indicator"
            checkable: true
            checked: altitudeWidget.visible
            onTriggered:
            {
                altitudeWidget.visible = !altitudeWidget.visible;
234
                flightDisplay.saveSetting("showAltitudeWidget", setBool(altitudeWidget.visible));
dogmaphobic's avatar
dogmaphobic committed
235 236 237 238 239 240 241 242 243 244
            }
        }

        MenuItem {
            text: "Current Altitude"
            checkable: true
            checked: currentAltitude.showAltitude
            onTriggered:
            {
                currentAltitude.showAltitude = !currentAltitude.showAltitude;
245
                flightDisplay.saveSetting("showCurrentAltitude", setBool(currentAltitude.showAltitude));
dogmaphobic's avatar
dogmaphobic committed
246 247 248 249 250 251 252 253 254 255
            }
        }

        MenuItem {
            text: "Current Climb Rate"
            checkable: true
            checked: currentAltitude.showClimbRate
            onTriggered:
            {
                currentAltitude.showClimbRate = !currentAltitude.showClimbRate;
256
                flightDisplay.saveSetting("showCurrentClimbRate", setBool(currentAltitude.showClimbRate));
dogmaphobic's avatar
dogmaphobic committed
257 258 259 260 261 262 263 264 265 266
            }
        }

        MenuItem {
            text: "Speed Indicator"
            checkable: true
            checked: speedWidget.visible
            onTriggered:
            {
                speedWidget.visible = !speedWidget.visible;
267
                flightDisplay.saveSetting("showSpeedWidget", setBool(speedWidget.visible));
dogmaphobic's avatar
dogmaphobic committed
268 269 270 271 272 273 274 275 276 277
            }
        }

        MenuItem {
            text: "Current Air Speed"
            checkable: true
            checked: currentSpeed.showAirSpeed
            onTriggered:
            {
                currentSpeed.showAirSpeed = !currentSpeed.showAirSpeed;
278
                flightDisplay.saveSetting("showCurrentAirSpeed", setBool(currentSpeed.showAirSpeed));
dogmaphobic's avatar
dogmaphobic committed
279 280 281 282 283 284 285 286 287 288
            }
        }

        MenuItem {
            text: "Current Ground Speed"
            checkable: true
            checked: currentSpeed.showGroundSpeed
            onTriggered:
            {
                currentSpeed.showGroundSpeed = !currentSpeed.showGroundSpeed;
289
                flightDisplay.saveSetting("showCurrentGroundSpeed", setBool(currentSpeed.showGroundSpeed));
dogmaphobic's avatar
dogmaphobic committed
290 291 292 293 294 295 296 297 298
            }
        }

        MenuSeparator {}

        MenuItem {
            text: "Restore Defaults"
            onTriggered:
            {
299
                showPitchIndicator = true;
300
                flightDisplay.saveSetting("showPitchIndicator", setBool(showPitchIndicator));
301 302 303 304 305 306 307 308
                attitudeWidget.visible = false;
                flightDisplay.saveSetting("showAttitudeWidget", setBool(attitudeWidget.visible));
                attitudeHUD.visible = true;
                flightDisplay.saveSetting("showAttitudeHUD", setBool(attitudeHUD.visible));
                compassWidget.visible = false
                flightDisplay.saveSetting("showCompassWidget", setBool(compassWidget.visible));
                compassHUD.visible = true
                flightDisplay.saveSetting("showCompassHUD", setBool(compassHUD.visible));
dogmaphobic's avatar
dogmaphobic committed
309
                altitudeWidget.visible = true;
310
                flightDisplay.saveSetting("showAltitudeWidget", setBool(altitudeWidget.visible));
dogmaphobic's avatar
dogmaphobic committed
311
                currentAltitude.showAltitude = true;
312
                flightDisplay.saveSetting("showCurrentAltitude", setBool(currentAltitude.showAltitude));
dogmaphobic's avatar
dogmaphobic committed
313
                currentAltitude.showClimbRate = true;
314
                flightDisplay.saveSetting("showCurrentClimbRate", setBool(currentAltitude.showClimbRate));
dogmaphobic's avatar
dogmaphobic committed
315
                speedWidget.visible = true;
316
                flightDisplay.saveSetting("showSpeedWidget", setBool(speedWidget.visible));
dogmaphobic's avatar
dogmaphobic committed
317
                currentSpeed.showAirSpeed = true;
318
                flightDisplay.saveSetting("showCurrentAirSpeed", setBool(currentSpeed.showAirSpeed));
dogmaphobic's avatar
dogmaphobic committed
319
                currentSpeed.showGroundSpeed = true;
320 321 322 323 324
                flightDisplay.saveSetting("showCurrentGroundSpeed", setBool(currentSpeed.showGroundSpeed));
                mapBackground.visible = false;
                flightDisplay.saveSetting("showMapBackground", setBool(mapBackground.visible));
                mapBackground.alwaysNorth = false;
                flightDisplay.saveSetting("mapAlwaysPointsNorth", setBool(mapBackground.alwaysNorth));
325 326
                mapBackground.showWaypoints = false
                flightDisplay.saveSetting("mapShowWaypoints", setBool(mapBackground.showWaypoints));
Gus Grubba's avatar
Gus Grubba committed
327 328
                videoBackground.visible = false;
                flightDisplay.saveSetting("showVideoBackground", setBool(videoBackground.visible));
dogmaphobic's avatar
dogmaphobic committed
329 330 331 332 333
            }
        }

    }

334 335
    // Video and Map backgrounds are exclusive. If one is enabled the other is disabled.

Gus Grubba's avatar
Gus Grubba committed
336 337 338 339 340 341 342 343
    QGCVideoBackground {
        id:                 videoBackground
        anchors.fill:       parent
        display:            videoDisplay
        receiver:           videoReceiver
        z:                  10
    }

344
    FlightMap {
345 346
        id:                 mapBackground
        anchors.fill:       parent
347
        mapName:            'MainFlightDisplay'
348 349
        latitude:           mapBackground.visible ? root.latitude : root.defaultLatitude
        longitude:          mapBackground.visible ? root.longitude : root.defaultLongitude
350
        readOnly:           true
351
        z:                  10
dogmaphobic's avatar
dogmaphobic committed
352 353
    }

354 355 356 357
    // Floating (Top Left) Compass Widget

    QGCCompassWidget {
        id:                 compassWidget
Don Gagne's avatar
Don Gagne committed
358 359 360
        y:                  ScreenTools.defaultFontPixelSize * (0.42)
        x:                  ScreenTools.defaultFontPixelSize * (7.1)
        size:               ScreenTools.defaultFontPixelSize * (13.3)
361
        heading:            root.heading
362
        z:                  mapBackground.z + 2
363
        onResetRequested: {
Don Gagne's avatar
Don Gagne committed
364 365 366
            y               = ScreenTools.defaultFontPixelSize * (0.42)
            x               = ScreenTools.defaultFontPixelSize * (7.1)
            size            = ScreenTools.defaultFontPixelSize * (13.3)
367 368 369 370 371
            tForm.xScale    = 1
            tForm.yScale    = 1
        }
    }

372 373 374 375 376 377 378 379
    // 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)
380
        heading:            root.heading
381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397
        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
    }

    // Floating (Top Right) Attitude Widget

    QGCAttitudeWidget {
        id:                 attitudeWidget
Don Gagne's avatar
Don Gagne committed
398 399
        y:                  ScreenTools.defaultFontPixelSize * (0.42)
        size:               ScreenTools.defaultFontPixelSize * (13.3)
400 401 402 403
        rollAngle:          roll
        pitchAngle:         pitch
        showPitch:          showPitchIndicator
        anchors.right:      root.right
Don Gagne's avatar
Don Gagne committed
404
        anchors.rightMargin: ScreenTools.defaultFontPixelSize * (7.1)
405
        z:                  mapBackground.z + 2
406
        onResetRequested: {
Don Gagne's avatar
Don Gagne committed
407
            y                   = ScreenTools.defaultFontPixelSize * (0.42)
408
            anchors.right       = root.right
Don Gagne's avatar
Don Gagne committed
409 410
            anchors.rightMargin = ScreenTools.defaultFontPixelSize * (7.1)
            size                = ScreenTools.defaultFontPixelSize * (13.3)
411 412 413 414 415
            tForm.xScale        = 1
            tForm.yScale        = 1
        }
    }

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

418 419
    QGCAttitudeHUD {
        id:                 attitudeHUD
420 421
        rollAngle:          roll
        pitchAngle:         pitch
422 423 424
        showPitch:          showPitchIndicator
        width:              ScreenTools.defaultFontPixelSize * (30)
        height:             ScreenTools.defaultFontPixelSize * (30)
425 426 427
        z:                  20
    }

dogmaphobic's avatar
dogmaphobic committed
428
    QGCAltitudeWidget {
429 430
        id:                 altitudeWidget
        anchors.right:      parent.right
Don Gagne's avatar
Don Gagne committed
431 432
        width:              ScreenTools.defaultFontPixelSize * (5)
        height:             parent.height * 0.65 > ScreenTools.defaultFontPixelSize * (23.4) ? ScreenTools.defaultFontPixelSize * (23.4) : parent.height * 0.65
433
        altitude:           root.altitudeWGS84
434
        z:                  30
dogmaphobic's avatar
dogmaphobic committed
435 436 437
    }

    QGCSpeedWidget {
438 439
        id:                 speedWidget
        anchors.left:       parent.left
Don Gagne's avatar
Don Gagne committed
440 441
        width:              ScreenTools.defaultFontPixelSize * (5)
        height:             parent.height * 0.65 > ScreenTools.defaultFontPixelSize * (23.4) ? ScreenTools.defaultFontPixelSize * (23.4) : parent.height * 0.65
442
        speed:              root.groundSpeed
443
        z:                  40
dogmaphobic's avatar
dogmaphobic committed
444 445 446 447 448
    }

    QGCCurrentSpeed {
        id: currentSpeed
        anchors.left:       parent.left
Don Gagne's avatar
Don Gagne committed
449
        width:              ScreenTools.defaultFontPixelSize * (6.25)
450 451
        airspeed:           root.airSpeed
        groundspeed:        root.groundSpeed
dogmaphobic's avatar
dogmaphobic committed
452 453
        showAirSpeed:       true
        showGroundSpeed:    true
dogmaphobic's avatar
dogmaphobic committed
454
        visible:            (currentSpeed.showGroundSpeed || currentSpeed.showAirSpeed)
dogmaphobic's avatar
dogmaphobic committed
455 456 457 458 459
        z:                  50
    }

    QGCCurrentAltitude {
        id: currentAltitude
dogmaphobic's avatar
dogmaphobic committed
460
        anchors.right:      parent.right
Don Gagne's avatar
Don Gagne committed
461
        width:              ScreenTools.defaultFontPixelSize * (6.25)
462 463
        altitude:           root.altitudeWGS84
        vertZ:              root.climbRate
dogmaphobic's avatar
dogmaphobic committed
464 465 466 467
        showAltitude:       true
        showClimbRate:      true
        visible:            (currentAltitude.showAltitude || currentAltitude.showClimbRate)
        z:                  60
dogmaphobic's avatar
dogmaphobic committed
468 469
    }

dogmaphobic's avatar
dogmaphobic committed
470 471 472
    //- Context Menu
    MouseArea {
        anchors.fill: parent
473
        z: 1000
dogmaphobic's avatar
dogmaphobic committed
474 475 476 477 478
        acceptedButtons: Qt.RightButton
        onClicked: {
            if (mouse.button == Qt.RightButton)
            {
                contextMenu.popup();
dogmaphobic's avatar
dogmaphobic committed
479 480
            }
        }
481
    }
dogmaphobic's avatar
dogmaphobic committed
482
}