FlightDisplay.qml 18 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.FlightControls 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 50 51
    property bool showPitchIndicator:       true
    property bool showAttitudeIndicator:    true
    property bool showCompass:              true
52

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

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

Gus Grubba's avatar
Gus Grubba committed
61 62 63 64
    function showHudInstruments() {
        return videoBackground.visible || mapBackground.visible;
    }

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

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

dogmaphobic's avatar
dogmaphobic committed
103 104 105
    Menu {
        id: contextMenu

Gus Grubba's avatar
Gus Grubba committed
106 107
        ExclusiveGroup { id: backgroundDisplay }

dogmaphobic's avatar
dogmaphobic committed
108
        MenuItem {
109
            text: "Map Background"
dogmaphobic's avatar
dogmaphobic committed
110
            checkable: true
111
            checked: mapBackground.visible
Gus Grubba's avatar
Gus Grubba committed
112
            exclusiveGroup: backgroundDisplay
dogmaphobic's avatar
dogmaphobic committed
113 114
            onTriggered:
            {
115 116
                mapBackground.visible = !mapBackground.visible;
                flightDisplay.saveSetting("showMapBackground", setBool(mapBackground.visible));
Gus Grubba's avatar
Gus Grubba committed
117 118
                videoBackground.visible = mapBackground.visible ? false : videoBackground.visible;
                flightDisplay.saveSetting("showVideoBackground", setBool(videoBackground.visible));
dogmaphobic's avatar
dogmaphobic committed
119 120 121
            }
        }

122 123 124 125
        MenuItem {
            text: "Map Show Waypoints"
            checkable: true
            checked: mapBackground.showWaypoints
Gus Grubba's avatar
Gus Grubba committed
126
            enabled: mapBackground.visible
127 128 129 130 131 132 133
            onTriggered:
            {
                mapBackground.showWaypoints = !mapBackground.showWaypoints;
                flightDisplay.saveSetting("mapShowWaypoints", setBool(mapBackground.showWaypoints));
            }
        }

134
        /*
Gus Grubba's avatar
Gus Grubba committed
135
        //-- Off until Qt 5.5.x, which fixes bug in 5.4.x
136
        MenuItem {
Gus Grubba's avatar
Gus Grubba committed
137 138 139
            text: "Map Always Points North"
            checkable: true
            checked: mapBackground.alwaysNorth
140 141
            onTriggered:
            {
Gus Grubba's avatar
Gus Grubba committed
142 143
                mapBackground.alwaysNorth = !mapBackground.alwaysNorth;
                flightDisplay.saveSetting("mapAlwaysPointsNorth", setBool(mapBackground.alwaysNorth));
144 145 146 147
            }
        }
        */

Gus Grubba's avatar
Gus Grubba committed
148 149
        MenuSeparator {}

dogmaphobic's avatar
dogmaphobic committed
150
        MenuItem {
151
            id: videoMenu
Gus Grubba's avatar
Gus Grubba committed
152
            text: "Video Background"
dogmaphobic's avatar
dogmaphobic committed
153
            checkable: true
Gus Grubba's avatar
Gus Grubba committed
154 155
            checked: videoBackground.visible
            exclusiveGroup: backgroundDisplay
dogmaphobic's avatar
dogmaphobic committed
156 157
            onTriggered:
            {
Gus Grubba's avatar
Gus Grubba committed
158 159 160 161
                videoBackground.visible = !videoBackground.visible;
                flightDisplay.saveSetting("showVideoBackground", setBool(videoBackground.visible));
                mapBackground.visible = videoBackground.visible ? false : mapBackground.visible;
                flightDisplay.saveSetting("showMapBackground", setBool(mapBackground.visible));
dogmaphobic's avatar
dogmaphobic committed
162 163
            }
        }
164 165

        MenuSeparator {}
dogmaphobic's avatar
dogmaphobic committed
166 167 168

        MenuItem {
            text: "Pitch Indicator"
169 170
            checkable:  true
            checked:    showPitchIndicator
dogmaphobic's avatar
dogmaphobic committed
171 172
            onTriggered:
            {
173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196
                showPitchIndicator = !showPitchIndicator;
                flightDisplay.saveSetting("showPitchIndicator", setBool(showPitchIndicator));
            }
        }

        MenuItem {
            text: "Attitude Indicator"
            checkable:  true
            checked:    showAttitudeIndicator
            onTriggered:
            {
                showAttitudeIndicator = !showAttitudeIndicator;
                flightDisplay.saveSetting("showAttitudeIndicator", setBool(showAttitudeIndicator));
            }
        }

        MenuItem {
            text: "Compass"
            checkable: true
            checked: showCompass
            onTriggered:
            {
                showCompass = !showCompass;
                flightDisplay.saveSetting("showCompass", setBool(showCompass));
dogmaphobic's avatar
dogmaphobic committed
197 198 199 200 201 202 203 204 205 206
            }
        }

        MenuItem {
            text: "Altitude Indicator"
            checkable: true
            checked: altitudeWidget.visible
            onTriggered:
            {
                altitudeWidget.visible = !altitudeWidget.visible;
207
                flightDisplay.saveSetting("showAltitudeWidget", setBool(altitudeWidget.visible));
dogmaphobic's avatar
dogmaphobic committed
208 209 210 211 212 213 214 215 216 217
            }
        }

        MenuItem {
            text: "Current Altitude"
            checkable: true
            checked: currentAltitude.showAltitude
            onTriggered:
            {
                currentAltitude.showAltitude = !currentAltitude.showAltitude;
218
                flightDisplay.saveSetting("showCurrentAltitude", setBool(currentAltitude.showAltitude));
dogmaphobic's avatar
dogmaphobic committed
219 220 221 222 223 224 225 226 227 228
            }
        }

        MenuItem {
            text: "Current Climb Rate"
            checkable: true
            checked: currentAltitude.showClimbRate
            onTriggered:
            {
                currentAltitude.showClimbRate = !currentAltitude.showClimbRate;
229
                flightDisplay.saveSetting("showCurrentClimbRate", setBool(currentAltitude.showClimbRate));
dogmaphobic's avatar
dogmaphobic committed
230 231 232 233 234 235 236 237 238 239
            }
        }

        MenuItem {
            text: "Speed Indicator"
            checkable: true
            checked: speedWidget.visible
            onTriggered:
            {
                speedWidget.visible = !speedWidget.visible;
240
                flightDisplay.saveSetting("showSpeedWidget", setBool(speedWidget.visible));
dogmaphobic's avatar
dogmaphobic committed
241 242 243 244 245 246 247 248 249 250
            }
        }

        MenuItem {
            text: "Current Air Speed"
            checkable: true
            checked: currentSpeed.showAirSpeed
            onTriggered:
            {
                currentSpeed.showAirSpeed = !currentSpeed.showAirSpeed;
251
                flightDisplay.saveSetting("showCurrentAirSpeed", setBool(currentSpeed.showAirSpeed));
dogmaphobic's avatar
dogmaphobic committed
252 253 254 255 256 257 258 259 260 261
            }
        }

        MenuItem {
            text: "Current Ground Speed"
            checkable: true
            checked: currentSpeed.showGroundSpeed
            onTriggered:
            {
                currentSpeed.showGroundSpeed = !currentSpeed.showGroundSpeed;
262
                flightDisplay.saveSetting("showCurrentGroundSpeed", setBool(currentSpeed.showGroundSpeed));
dogmaphobic's avatar
dogmaphobic committed
263 264 265 266 267 268 269 270 271
            }
        }

        MenuSeparator {}

        MenuItem {
            text: "Restore Defaults"
            onTriggered:
            {
272
                showPitchIndicator = true;
273
                flightDisplay.saveSetting("showPitchIndicator", setBool(showPitchIndicator));
274 275 276 277
                showAttitudeIndicator = true;
                flightDisplay.saveSetting("showAttitudeIndicator", setBool(showAttitudeIndicator));
                showCompass = true;
                flightDisplay.saveSetting("showCompass", setBool(showCompass));
dogmaphobic's avatar
dogmaphobic committed
278
                altitudeWidget.visible = true;
279
                flightDisplay.saveSetting("showAltitudeWidget", setBool(altitudeWidget.visible));
dogmaphobic's avatar
dogmaphobic committed
280
                currentAltitude.showAltitude = true;
281
                flightDisplay.saveSetting("showCurrentAltitude", setBool(currentAltitude.showAltitude));
dogmaphobic's avatar
dogmaphobic committed
282
                currentAltitude.showClimbRate = true;
283
                flightDisplay.saveSetting("showCurrentClimbRate", setBool(currentAltitude.showClimbRate));
dogmaphobic's avatar
dogmaphobic committed
284
                speedWidget.visible = true;
285
                flightDisplay.saveSetting("showSpeedWidget", setBool(speedWidget.visible));
dogmaphobic's avatar
dogmaphobic committed
286
                currentSpeed.showAirSpeed = true;
287
                flightDisplay.saveSetting("showCurrentAirSpeed", setBool(currentSpeed.showAirSpeed));
dogmaphobic's avatar
dogmaphobic committed
288
                currentSpeed.showGroundSpeed = true;
289 290 291 292 293
                flightDisplay.saveSetting("showCurrentGroundSpeed", setBool(currentSpeed.showGroundSpeed));
                mapBackground.visible = false;
                flightDisplay.saveSetting("showMapBackground", setBool(mapBackground.visible));
                mapBackground.alwaysNorth = false;
                flightDisplay.saveSetting("mapAlwaysPointsNorth", setBool(mapBackground.alwaysNorth));
294 295
                mapBackground.showWaypoints = false
                flightDisplay.saveSetting("mapShowWaypoints", setBool(mapBackground.showWaypoints));
Gus Grubba's avatar
Gus Grubba committed
296 297
                videoBackground.visible = false;
                flightDisplay.saveSetting("showVideoBackground", setBool(videoBackground.visible));
dogmaphobic's avatar
dogmaphobic committed
298 299 300 301 302
            }
        }

    }

Gus Grubba's avatar
Gus Grubba committed
303 304 305 306 307 308 309 310
    QGCVideoBackground {
        id:                 videoBackground
        anchors.fill:       parent
        display:            videoDisplay
        receiver:           videoReceiver
        z:                  10
    }

dogmaphobic's avatar
dogmaphobic committed
311
    QGCMapBackground {
312 313
        id:                 mapBackground
        anchors.fill:       parent
314 315 316 317
        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
318
        readOnly:           true
319
      //interactive:        !MavManager.mavPresent
320
        z:                  10
dogmaphobic's avatar
dogmaphobic committed
321 322
    }

323
    QGCHudMessage {
Gus Grubba's avatar
Gus Grubba committed
324 325 326 327
        id:                 hudMessage
        y:                  ScreenTools.defaultFontPizelSize * (0.42)
        width:              (parent.width - 520 > 200) ? parent.width - 520 : 200
        height:             ScreenTools.defaultFontPizelSize * (2.5)
328
        anchors.horizontalCenter: parent.horizontalCenter
Gus Grubba's avatar
Gus Grubba committed
329
        z:                  mapBackground.z + 1
330 331
    }

332 333
    QGCCompassInstrument {
        id:                 compassInstrument
Don Gagne's avatar
Don Gagne committed
334 335 336
        y:                  ScreenTools.defaultFontPixelSize * (0.42)
        x:                  ScreenTools.defaultFontPixelSize * (7.1)
        size:               ScreenTools.defaultFontPixelSize * (13.3)
337
        heading:            isNaN(MavManager.heading) ? 0 : MavManager.heading
Gus Grubba's avatar
Gus Grubba committed
338
        visible:            showHudInstruments() && showCompass
339
        z:                  mapBackground.z + 2
340
        onResetRequested: {
Don Gagne's avatar
Don Gagne committed
341 342 343
            y               = ScreenTools.defaultFontPixelSize * (0.42)
            x               = ScreenTools.defaultFontPixelSize * (7.1)
            size            = ScreenTools.defaultFontPixelSize * (13.3)
344 345 346 347 348 349 350
            tForm.xScale    = 1
            tForm.yScale    = 1
        }
    }

    QGCAttitudeInstrument {
        id:                 attitudeInstrument
Don Gagne's avatar
Don Gagne committed
351 352
        y:                  ScreenTools.defaultFontPixelSize * (0.42)
        size:               ScreenTools.defaultFontPixelSize * (13.3)
353 354 355
        rollAngle:          roll
        pitchAngle:         pitch
        showPitch:          showPitchIndicator
Gus Grubba's avatar
Gus Grubba committed
356
        visible:            showHudInstruments() && showAttitudeIndicator
357
        anchors.right:      root.right
Don Gagne's avatar
Don Gagne committed
358
        anchors.rightMargin: ScreenTools.defaultFontPixelSize * (7.1)
359
        z:                  mapBackground.z + 2
360
        onResetRequested: {
Don Gagne's avatar
Don Gagne committed
361
            y                   = ScreenTools.defaultFontPixelSize * (0.42)
362
            anchors.right       = root.right
Don Gagne's avatar
Don Gagne committed
363 364
            anchors.rightMargin = ScreenTools.defaultFontPixelSize * (7.1)
            size                = ScreenTools.defaultFontPixelSize * (13.3)
365 366 367 368 369
            tForm.xScale        = 1
            tForm.yScale        = 1
        }
    }

370 371 372
    QGCArtificialHorizon {
        id:                 artificialHoriz
        anchors.fill:       parent
dogmaphobic's avatar
dogmaphobic committed
373 374
        rollAngle:          roll
        pitchAngle:         pitch
Gus Grubba's avatar
Gus Grubba committed
375
        visible:            !showHudInstruments()
dogmaphobic's avatar
dogmaphobic committed
376 377
    }

378 379 380 381
    QGCAttitudeWidget {
        id:                 attitudeWidget
        rollAngle:          roll
        pitchAngle:         pitch
Gus Grubba's avatar
Gus Grubba committed
382
        visible:            !showHudInstruments() && showAttitudeIndicator
Don Gagne's avatar
Don Gagne committed
383 384
        width:              ScreenTools.defaultFontPixelSize * (21.7)
        height:             ScreenTools.defaultFontPixelSize * (21.7)
385 386 387
        z:                  20
    }

dogmaphobic's avatar
dogmaphobic committed
388
    QGCPitchWidget {
389
        id:                 pitchWidget
Gus Grubba's avatar
Gus Grubba committed
390
        visible:            showPitchIndicator && !showHudInstruments()
dogmaphobic's avatar
dogmaphobic committed
391
        anchors.verticalCenter: parent.verticalCenter
392 393 394
        pitchAngle:         pitch
        rollAngle:          roll
        color:              Qt.rgba(0,0,0,0)
Don Gagne's avatar
Don Gagne committed
395
        size:               ScreenTools.defaultFontPixelSize * (10)
396
        z:                  30
dogmaphobic's avatar
dogmaphobic committed
397 398 399
    }

    QGCAltitudeWidget {
400 401
        id:                 altitudeWidget
        anchors.right:      parent.right
Don Gagne's avatar
Don Gagne committed
402 403
        width:              ScreenTools.defaultFontPixelSize * (5)
        height:             parent.height * 0.65 > ScreenTools.defaultFontPixelSize * (23.4) ? ScreenTools.defaultFontPixelSize * (23.4) : parent.height * 0.65
404
        altitude:           MavManager.altitudeWGS84
405
        z:                  30
dogmaphobic's avatar
dogmaphobic committed
406 407 408
    }

    QGCSpeedWidget {
409 410
        id:                 speedWidget
        anchors.left:       parent.left
Don Gagne's avatar
Don Gagne committed
411 412
        width:              ScreenTools.defaultFontPixelSize * (5)
        height:             parent.height * 0.65 > ScreenTools.defaultFontPixelSize * (23.4) ? ScreenTools.defaultFontPixelSize * (23.4) : parent.height * 0.65
413
        speed:              MavManager.groundSpeed
414
        z:                  40
dogmaphobic's avatar
dogmaphobic committed
415 416 417 418 419
    }

    QGCCurrentSpeed {
        id: currentSpeed
        anchors.left:       parent.left
Don Gagne's avatar
Don Gagne committed
420
        width:              ScreenTools.defaultFontPixelSize * (6.25)
421 422
        airspeed:           MavManager.airSpeed
        groundspeed:        MavManager.groundSpeed
dogmaphobic's avatar
dogmaphobic committed
423 424
        showAirSpeed:       true
        showGroundSpeed:    true
dogmaphobic's avatar
dogmaphobic committed
425
        visible:            (currentSpeed.showGroundSpeed || currentSpeed.showAirSpeed)
dogmaphobic's avatar
dogmaphobic committed
426 427 428 429 430
        z:                  50
    }

    QGCCurrentAltitude {
        id: currentAltitude
dogmaphobic's avatar
dogmaphobic committed
431
        anchors.right:      parent.right
Don Gagne's avatar
Don Gagne committed
432
        width:              ScreenTools.defaultFontPixelSize * (6.25)
433 434
        altitude:           MavManager.altitudeWGS84
        vertZ:              MavManager.climbRate
dogmaphobic's avatar
dogmaphobic committed
435 436 437 438
        showAltitude:       true
        showClimbRate:      true
        visible:            (currentAltitude.showAltitude || currentAltitude.showClimbRate)
        z:                  60
dogmaphobic's avatar
dogmaphobic committed
439 440 441
    }

    QGCCompass {
442 443
        id:                 compassIndicator
        y:                  root.height * 0.7
Don Gagne's avatar
Don Gagne committed
444 445 446
        x:                  root.width  * 0.5 - ScreenTools.defaultFontPixelSize * (5)
        width:              ScreenTools.defaultFontPixelSize * (10)
        height:             ScreenTools.defaultFontPixelSize * (10)
447
        heading:            isNaN(MavManager.heading) ? 0 : MavManager.heading
Gus Grubba's avatar
Gus Grubba committed
448
        visible:            !showHudInstruments() && showCompass
449
        z:                  70
dogmaphobic's avatar
dogmaphobic committed
450 451
    }

dogmaphobic's avatar
dogmaphobic committed
452 453 454
    //- Context Menu
    MouseArea {
        anchors.fill: parent
455
        z: 1000
dogmaphobic's avatar
dogmaphobic committed
456 457 458 459 460
        acceptedButtons: Qt.RightButton
        onClicked: {
            if (mouse.button == Qt.RightButton)
            {
                contextMenu.popup();
dogmaphobic's avatar
dogmaphobic committed
461 462
            }
        }
463
    }
dogmaphobic's avatar
dogmaphobic committed
464
}