FlightDisplay.qml 18.9 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
import QGroundControl.MavManager 1.0
37 38 39
import QGroundControl.ScreenTools 1.0
import QGroundControl.Controls 1.0
import QGroundControl.Palette 1.0
dogmaphobic's avatar
dogmaphobic committed
40

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

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

46 47
    property real roll:    isNaN(MavManager.roll)    ? 0 : MavManager.roll
    property real pitch:   isNaN(MavManager.pitch)   ? 0 : MavManager.pitch
dogmaphobic's avatar
dogmaphobic committed
48

49
    property bool showPitchIndicator:       true
50

51 52 53 54 55 56 57 58
    function getBool(value) {
        return value === '0' ? false : true;
    }

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

59 60 61 62 63
    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
64 65
    }

dogmaphobic's avatar
dogmaphobic committed
66 67 68 69 70 71 72
    Connections {
        target: flightDisplay
        onShowOptionsMenuChanged: {
            contextMenu.popup();
        }
    }

dogmaphobic's avatar
dogmaphobic committed
73 74
    Component.onCompleted:
    {
75
        mapBackground.visible               = getBool(flightDisplay.loadSetting("showMapBackground",        "0"));
76
        mapBackground.showWaypoints         = getBool(flightDisplay.loadSetting("mapShowWaypoints",         "0"));
77
        mapBackground.alwaysNorth           = getBool(flightDisplay.loadSetting("mapAlwaysPointsNorth",     "0"));
Gus Grubba's avatar
Gus Grubba committed
78
        videoBackground.visible             = getBool(flightDisplay.loadSetting("showVideoBackground",      "0"));
79
        showPitchIndicator                  = getBool(flightDisplay.loadSetting("showPitchIndicator",       "1"));
80 81 82 83
        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"));
84 85 86 87 88 89
        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"));
90 91
        // Insert Map Type menu before separator
        contextMenu.insertItem(2, mapBackground.mapMenu);
Gus Grubba's avatar
Gus Grubba committed
92 93 94 95
        // Video or Map. Not both:
        if(mapBackground.visible && videoBackground.visible) {
            videoBackground.visible = false;
            flightDisplay.saveSetting("showVideoBackground", setBool(videoBackground.visible));
96
        }
97 98 99 100 101 102 103 104 105 106
        // 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));
        }
107 108 109 110 111 112 113
        // 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;
114 115
    }

dogmaphobic's avatar
dogmaphobic committed
116 117 118 119
    Menu {
        id: contextMenu

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

129 130 131 132
        MenuItem {
            text: "Map Show Waypoints"
            checkable: true
            checked: mapBackground.showWaypoints
Gus Grubba's avatar
Gus Grubba committed
133
            enabled: mapBackground.visible
134 135 136 137 138 139 140
            onTriggered:
            {
                mapBackground.showWaypoints = !mapBackground.showWaypoints;
                flightDisplay.saveSetting("mapShowWaypoints", setBool(mapBackground.showWaypoints));
            }
        }

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

Gus Grubba's avatar
Gus Grubba committed
155 156
        MenuSeparator {}

dogmaphobic's avatar
dogmaphobic committed
157
        MenuItem {
158
            id: videoMenu
Gus Grubba's avatar
Gus Grubba committed
159
            text: "Video Background"
dogmaphobic's avatar
dogmaphobic committed
160
            checkable: true
Gus Grubba's avatar
Gus Grubba committed
161
            checked: videoBackground.visible
dogmaphobic's avatar
dogmaphobic committed
162 163
            onTriggered:
            {
164
                enforceExclusiveOption(videoBackground, mapBackground, "showVideoBackground", "showMapBackground");
dogmaphobic's avatar
dogmaphobic committed
165 166
            }
        }
167 168

        MenuSeparator {}
dogmaphobic's avatar
dogmaphobic committed
169

170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189
        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
190 191
        MenuItem {
            text: "Pitch Indicator"
192 193
            checkable:  true
            checked:    showPitchIndicator
194
            enabled:    attitudeHUD.visible || attitudeWidget.visible
dogmaphobic's avatar
dogmaphobic committed
195 196
            onTriggered:
            {
197 198 199 200 201 202
                showPitchIndicator = !showPitchIndicator;
                flightDisplay.saveSetting("showPitchIndicator", setBool(showPitchIndicator));
            }
        }

        MenuItem {
203 204 205
            text: "Compass Widget"
            checkable: true
            checked: compassWidget.visible
206 207
            onTriggered:
            {
208
                enforceExclusiveOption(compassWidget, compassHUD, "showCompassWidget", "showCompassHUD");
209 210 211 212
            }
        }

        MenuItem {
213
            text: "Compass HUD"
214
            checkable: true
215
            checked: compassHUD.visible
216 217
            onTriggered:
            {
218
                enforceExclusiveOption(compassHUD, compassWidget, "showCompassHUD", "showCompassWidget");
dogmaphobic's avatar
dogmaphobic committed
219 220 221 222 223 224 225 226 227 228
            }
        }

        MenuItem {
            text: "Altitude Indicator"
            checkable: true
            checked: altitudeWidget.visible
            onTriggered:
            {
                altitudeWidget.visible = !altitudeWidget.visible;
229
                flightDisplay.saveSetting("showAltitudeWidget", setBool(altitudeWidget.visible));
dogmaphobic's avatar
dogmaphobic committed
230 231 232 233 234 235 236 237 238 239
            }
        }

        MenuItem {
            text: "Current Altitude"
            checkable: true
            checked: currentAltitude.showAltitude
            onTriggered:
            {
                currentAltitude.showAltitude = !currentAltitude.showAltitude;
240
                flightDisplay.saveSetting("showCurrentAltitude", setBool(currentAltitude.showAltitude));
dogmaphobic's avatar
dogmaphobic committed
241 242 243 244 245 246 247 248 249 250
            }
        }

        MenuItem {
            text: "Current Climb Rate"
            checkable: true
            checked: currentAltitude.showClimbRate
            onTriggered:
            {
                currentAltitude.showClimbRate = !currentAltitude.showClimbRate;
251
                flightDisplay.saveSetting("showCurrentClimbRate", setBool(currentAltitude.showClimbRate));
dogmaphobic's avatar
dogmaphobic committed
252 253 254 255 256 257 258 259 260 261
            }
        }

        MenuItem {
            text: "Speed Indicator"
            checkable: true
            checked: speedWidget.visible
            onTriggered:
            {
                speedWidget.visible = !speedWidget.visible;
262
                flightDisplay.saveSetting("showSpeedWidget", setBool(speedWidget.visible));
dogmaphobic's avatar
dogmaphobic committed
263 264 265 266 267 268 269 270 271 272
            }
        }

        MenuItem {
            text: "Current Air Speed"
            checkable: true
            checked: currentSpeed.showAirSpeed
            onTriggered:
            {
                currentSpeed.showAirSpeed = !currentSpeed.showAirSpeed;
273
                flightDisplay.saveSetting("showCurrentAirSpeed", setBool(currentSpeed.showAirSpeed));
dogmaphobic's avatar
dogmaphobic committed
274 275 276 277 278 279 280 281 282 283
            }
        }

        MenuItem {
            text: "Current Ground Speed"
            checkable: true
            checked: currentSpeed.showGroundSpeed
            onTriggered:
            {
                currentSpeed.showGroundSpeed = !currentSpeed.showGroundSpeed;
284
                flightDisplay.saveSetting("showCurrentGroundSpeed", setBool(currentSpeed.showGroundSpeed));
dogmaphobic's avatar
dogmaphobic committed
285 286 287 288 289 290 291 292 293
            }
        }

        MenuSeparator {}

        MenuItem {
            text: "Restore Defaults"
            onTriggered:
            {
294
                showPitchIndicator = true;
295
                flightDisplay.saveSetting("showPitchIndicator", setBool(showPitchIndicator));
296 297 298 299 300 301 302 303
                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
304
                altitudeWidget.visible = true;
305
                flightDisplay.saveSetting("showAltitudeWidget", setBool(altitudeWidget.visible));
dogmaphobic's avatar
dogmaphobic committed
306
                currentAltitude.showAltitude = true;
307
                flightDisplay.saveSetting("showCurrentAltitude", setBool(currentAltitude.showAltitude));
dogmaphobic's avatar
dogmaphobic committed
308
                currentAltitude.showClimbRate = true;
309
                flightDisplay.saveSetting("showCurrentClimbRate", setBool(currentAltitude.showClimbRate));
dogmaphobic's avatar
dogmaphobic committed
310
                speedWidget.visible = true;
311
                flightDisplay.saveSetting("showSpeedWidget", setBool(speedWidget.visible));
dogmaphobic's avatar
dogmaphobic committed
312
                currentSpeed.showAirSpeed = true;
313
                flightDisplay.saveSetting("showCurrentAirSpeed", setBool(currentSpeed.showAirSpeed));
dogmaphobic's avatar
dogmaphobic committed
314
                currentSpeed.showGroundSpeed = true;
315 316 317 318 319
                flightDisplay.saveSetting("showCurrentGroundSpeed", setBool(currentSpeed.showGroundSpeed));
                mapBackground.visible = false;
                flightDisplay.saveSetting("showMapBackground", setBool(mapBackground.visible));
                mapBackground.alwaysNorth = false;
                flightDisplay.saveSetting("mapAlwaysPointsNorth", setBool(mapBackground.alwaysNorth));
320 321
                mapBackground.showWaypoints = false
                flightDisplay.saveSetting("mapShowWaypoints", setBool(mapBackground.showWaypoints));
Gus Grubba's avatar
Gus Grubba committed
322 323
                videoBackground.visible = false;
                flightDisplay.saveSetting("showVideoBackground", setBool(videoBackground.visible));
dogmaphobic's avatar
dogmaphobic committed
324 325 326 327 328
            }
        }

    }

329 330
    // Video and Map backgrounds are exclusive. If one is enabled the other is disabled.

Gus Grubba's avatar
Gus Grubba committed
331 332 333 334 335 336 337 338
    QGCVideoBackground {
        id:                 videoBackground
        anchors.fill:       parent
        display:            videoDisplay
        receiver:           videoReceiver
        z:                  10
    }

339
    FlightMap {
340 341
        id:                 mapBackground
        anchors.fill:       parent
342 343 344 345
        mapName:            'MainFlightDisplay'
        heading:            0 // isNaN(MavManager.heading) ? 0 : MavManager.heading
        latitude:           mapBackground.visible ? ((MavManager.latitude  === 0) ?   37.803784 : MavManager.latitude)  :   37.803784
        longitude:          mapBackground.visible ? ((MavManager.longitude === 0) ? -122.462276 : MavManager.longitude) : -122.462276
346
        readOnly:           true
347
      //interactive:        !MavManager.mavPresent
348
        z:                  10
dogmaphobic's avatar
dogmaphobic committed
349 350
    }

351
    QGCHudMessage {
Gus Grubba's avatar
Gus Grubba committed
352 353 354 355
        id:                 hudMessage
        y:                  ScreenTools.defaultFontPizelSize * (0.42)
        width:              (parent.width - 520 > 200) ? parent.width - 520 : 200
        height:             ScreenTools.defaultFontPizelSize * (2.5)
356
        anchors.horizontalCenter: parent.horizontalCenter
Gus Grubba's avatar
Gus Grubba committed
357
        z:                  mapBackground.z + 1
358 359
    }

360 361 362 363
    // Floating (Top Left) Compass Widget

    QGCCompassWidget {
        id:                 compassWidget
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
        heading:            isNaN(MavManager.heading) ? 0 : MavManager.heading
368
        z:                  mapBackground.z + 2
369
        onResetRequested: {
Don Gagne's avatar
Don Gagne committed
370 371 372
            y               = ScreenTools.defaultFontPixelSize * (0.42)
            x               = ScreenTools.defaultFontPixelSize * (7.1)
            size            = ScreenTools.defaultFontPixelSize * (13.3)
373 374 375 376 377
            tForm.xScale    = 1
            tForm.yScale    = 1
        }
    }

378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403
    // 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)
        heading:            isNaN(MavManager.heading) ? 0 : MavManager.heading
        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
404 405
        y:                  ScreenTools.defaultFontPixelSize * (0.42)
        size:               ScreenTools.defaultFontPixelSize * (13.3)
406 407 408 409
        rollAngle:          roll
        pitchAngle:         pitch
        showPitch:          showPitchIndicator
        anchors.right:      root.right
Don Gagne's avatar
Don Gagne committed
410
        anchors.rightMargin: ScreenTools.defaultFontPixelSize * (7.1)
411
        z:                  mapBackground.z + 2
412
        onResetRequested: {
Don Gagne's avatar
Don Gagne committed
413
            y                   = ScreenTools.defaultFontPixelSize * (0.42)
414
            anchors.right       = root.right
Don Gagne's avatar
Don Gagne committed
415 416
            anchors.rightMargin = ScreenTools.defaultFontPixelSize * (7.1)
            size                = ScreenTools.defaultFontPixelSize * (13.3)
417 418 419 420 421
            tForm.xScale        = 1
            tForm.yScale        = 1
        }
    }

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

424 425
    QGCAttitudeHUD {
        id:                 attitudeHUD
426 427
        rollAngle:          roll
        pitchAngle:         pitch
428 429 430
        showPitch:          showPitchIndicator
        width:              ScreenTools.defaultFontPixelSize * (30)
        height:             ScreenTools.defaultFontPixelSize * (30)
431 432 433
        z:                  20
    }

dogmaphobic's avatar
dogmaphobic committed
434
    QGCAltitudeWidget {
435 436
        id:                 altitudeWidget
        anchors.right:      parent.right
Don Gagne's avatar
Don Gagne committed
437 438
        width:              ScreenTools.defaultFontPixelSize * (5)
        height:             parent.height * 0.65 > ScreenTools.defaultFontPixelSize * (23.4) ? ScreenTools.defaultFontPixelSize * (23.4) : parent.height * 0.65
439
        altitude:           MavManager.altitudeWGS84
440
        z:                  30
dogmaphobic's avatar
dogmaphobic committed
441 442 443
    }

    QGCSpeedWidget {
444 445
        id:                 speedWidget
        anchors.left:       parent.left
Don Gagne's avatar
Don Gagne committed
446 447
        width:              ScreenTools.defaultFontPixelSize * (5)
        height:             parent.height * 0.65 > ScreenTools.defaultFontPixelSize * (23.4) ? ScreenTools.defaultFontPixelSize * (23.4) : parent.height * 0.65
448
        speed:              MavManager.groundSpeed
449
        z:                  40
dogmaphobic's avatar
dogmaphobic committed
450 451 452 453 454
    }

    QGCCurrentSpeed {
        id: currentSpeed
        anchors.left:       parent.left
Don Gagne's avatar
Don Gagne committed
455
        width:              ScreenTools.defaultFontPixelSize * (6.25)
456 457
        airspeed:           MavManager.airSpeed
        groundspeed:        MavManager.groundSpeed
dogmaphobic's avatar
dogmaphobic committed
458 459
        showAirSpeed:       true
        showGroundSpeed:    true
dogmaphobic's avatar
dogmaphobic committed
460
        visible:            (currentSpeed.showGroundSpeed || currentSpeed.showAirSpeed)
dogmaphobic's avatar
dogmaphobic committed
461 462 463 464 465
        z:                  50
    }

    QGCCurrentAltitude {
        id: currentAltitude
dogmaphobic's avatar
dogmaphobic committed
466
        anchors.right:      parent.right
Don Gagne's avatar
Don Gagne committed
467
        width:              ScreenTools.defaultFontPixelSize * (6.25)
468 469
        altitude:           MavManager.altitudeWGS84
        vertZ:              MavManager.climbRate
dogmaphobic's avatar
dogmaphobic committed
470 471 472 473
        showAltitude:       true
        showClimbRate:      true
        visible:            (currentAltitude.showAltitude || currentAltitude.showClimbRate)
        z:                  60
dogmaphobic's avatar
dogmaphobic committed
474 475
    }

dogmaphobic's avatar
dogmaphobic committed
476 477 478
    //- Context Menu
    MouseArea {
        anchors.fill: parent
479
        z: 1000
dogmaphobic's avatar
dogmaphobic committed
480 481 482 483 484
        acceptedButtons: Qt.RightButton
        onClicked: {
            if (mouse.button == Qt.RightButton)
            {
                contextMenu.popup();
dogmaphobic's avatar
dogmaphobic committed
485 486
            }
        }
487
    }
dogmaphobic's avatar
dogmaphobic committed
488
}