FlightDisplay.qml 15.2 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 30 31 32 33
 *   @author Gus Grubba <mavlink@grubba.com>
 */

import QtQuick 2.3
import QtQuick.Controls 1.2
import QtQuick.Controls.Styles 1.2

34
import QGroundControl.FlightControls 1.0
dogmaphobic's avatar
dogmaphobic committed
35 36 37 38 39 40 41 42

Rectangle {
    id: root
    color: Qt.rgba(0,0,0,0);

    property real roll:    isNaN(flightDisplay.roll)    ? 0 : flightDisplay.roll
    property real pitch:   isNaN(flightDisplay.pitch)   ? 0 : flightDisplay.pitch

43 44 45
    property bool showPitchIndicator:       true
    property bool showAttitudeIndicator:    true
    property bool showCompass:              true
46

47 48 49 50 51 52 53 54
    function getBool(value) {
        return value === '0' ? false : true;
    }

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

dogmaphobic's avatar
dogmaphobic committed
55 56
    Component.onCompleted:
    {
57 58
        mapBackground.visible               = getBool(flightDisplay.loadSetting("showMapBackground",        "0"));
        mapBackground.alwaysNorth           = getBool(flightDisplay.loadSetting("mapAlwaysPointsNorth",     "0"));
59 60
        showAttitudeIndicator               = getBool(flightDisplay.loadSetting("showAttitudeIndicator",    "1"));
        showPitchIndicator                  = getBool(flightDisplay.loadSetting("showPitchIndicator",       "1"));
61
        showCompass                         = getBool(flightDisplay.loadSetting("showCompass",              "1"));
62 63 64 65 66 67 68
        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"));
        mapTypeMenu.update();
dogmaphobic's avatar
dogmaphobic committed
69 70 71 72 73 74
    }

    Menu {
        id: contextMenu

        MenuItem {
75
            text: "Map Background"
dogmaphobic's avatar
dogmaphobic committed
76
            checkable: true
77
            checked: mapBackground.visible
dogmaphobic's avatar
dogmaphobic committed
78 79
            onTriggered:
            {
80 81
                mapBackground.visible = !mapBackground.visible;
                flightDisplay.saveSetting("showMapBackground", setBool(mapBackground.visible));
dogmaphobic's avatar
dogmaphobic committed
82 83 84
            }
        }

85
        /*
dogmaphobic's avatar
dogmaphobic committed
86
        MenuItem {
87
            text: "Map Always Points North"
dogmaphobic's avatar
dogmaphobic committed
88
            checkable: true
89
            checked: mapBackground.alwaysNorth
dogmaphobic's avatar
dogmaphobic committed
90 91
            onTriggered:
            {
92 93
                mapBackground.alwaysNorth = !mapBackground.alwaysNorth;
                flightDisplay.saveSetting("mapAlwaysPointsNorth", setBool(mapBackground.alwaysNorth));
dogmaphobic's avatar
dogmaphobic committed
94 95
            }
        }
96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134
        */

        Menu {
            id: mapTypeMenu
            title: "Map Type..."
            ExclusiveGroup { id: currentMapType }
            function setCurrentMap(map) {
                for (var i = 0; i < mapBackground.mapItem.supportedMapTypes.length; i++) {
                    if (map === mapBackground.mapItem.supportedMapTypes[i].name) {
                        mapBackground.mapItem.activeMapType = mapBackground.mapItem.supportedMapTypes[i]
                        flightDisplay.saveSetting("currentMapType", map);
                        return;
                    }
                }
            }
            function addMap(map, checked) {
                var mItem = mapTypeMenu.addItem(map);
                mItem.checkable = true
                mItem.checked   = checked
                mItem.exclusiveGroup = currentMapType
                var menuSlot = function() {setCurrentMap(map);};
                mItem.triggered.connect(menuSlot);
            }
            function update() {
                clear()
                var map = ''
                if (mapBackground.mapItem.supportedMapTypes.length > 0)
                    map = mapBackground.mapItem.activeMapType.name;
                map = flightDisplay.loadSetting("currentMapType", map);
                for (var i = 0; i < mapBackground.mapItem.supportedMapTypes.length; i++) {
                    var name = mapBackground.mapItem.supportedMapTypes[i].name;
                    addMap(name, map === name);
                }
                if(map != '')
                    setCurrentMap(map);
            }
        }

        MenuSeparator {}
dogmaphobic's avatar
dogmaphobic committed
135 136 137

        MenuItem {
            text: "Pitch Indicator"
138 139
            checkable:  true
            checked:    showPitchIndicator
dogmaphobic's avatar
dogmaphobic committed
140 141
            onTriggered:
            {
142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165
                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
166 167 168 169 170 171 172 173 174 175
            }
        }

        MenuItem {
            text: "Altitude Indicator"
            checkable: true
            checked: altitudeWidget.visible
            onTriggered:
            {
                altitudeWidget.visible = !altitudeWidget.visible;
176
                flightDisplay.saveSetting("showAltitudeWidget", setBool(altitudeWidget.visible));
dogmaphobic's avatar
dogmaphobic committed
177 178 179 180 181 182 183 184 185 186
            }
        }

        MenuItem {
            text: "Current Altitude"
            checkable: true
            checked: currentAltitude.showAltitude
            onTriggered:
            {
                currentAltitude.showAltitude = !currentAltitude.showAltitude;
187
                flightDisplay.saveSetting("showCurrentAltitude", setBool(currentAltitude.showAltitude));
dogmaphobic's avatar
dogmaphobic committed
188 189 190 191 192 193 194 195 196 197
            }
        }

        MenuItem {
            text: "Current Climb Rate"
            checkable: true
            checked: currentAltitude.showClimbRate
            onTriggered:
            {
                currentAltitude.showClimbRate = !currentAltitude.showClimbRate;
198
                flightDisplay.saveSetting("showCurrentClimbRate", setBool(currentAltitude.showClimbRate));
dogmaphobic's avatar
dogmaphobic committed
199 200 201 202 203 204 205 206 207 208
            }
        }

        MenuItem {
            text: "Speed Indicator"
            checkable: true
            checked: speedWidget.visible
            onTriggered:
            {
                speedWidget.visible = !speedWidget.visible;
209
                flightDisplay.saveSetting("showSpeedWidget", setBool(speedWidget.visible));
dogmaphobic's avatar
dogmaphobic committed
210 211 212 213 214 215 216 217 218 219
            }
        }

        MenuItem {
            text: "Current Air Speed"
            checkable: true
            checked: currentSpeed.showAirSpeed
            onTriggered:
            {
                currentSpeed.showAirSpeed = !currentSpeed.showAirSpeed;
220
                flightDisplay.saveSetting("showCurrentAirSpeed", setBool(currentSpeed.showAirSpeed));
dogmaphobic's avatar
dogmaphobic committed
221 222 223 224 225 226 227 228 229 230
            }
        }

        MenuItem {
            text: "Current Ground Speed"
            checkable: true
            checked: currentSpeed.showGroundSpeed
            onTriggered:
            {
                currentSpeed.showGroundSpeed = !currentSpeed.showGroundSpeed;
231
                flightDisplay.saveSetting("showCurrentGroundSpeed", setBool(currentSpeed.showGroundSpeed));
dogmaphobic's avatar
dogmaphobic committed
232 233 234 235 236 237 238 239 240
            }
        }

        MenuSeparator {}

        MenuItem {
            text: "Restore Defaults"
            onTriggered:
            {
241
                showPitchIndicator = true;
242
                flightDisplay.saveSetting("showPitchIndicator", setBool(showPitchIndicator));
243 244 245 246
                showAttitudeIndicator = true;
                flightDisplay.saveSetting("showAttitudeIndicator", setBool(showAttitudeIndicator));
                showCompass = true;
                flightDisplay.saveSetting("showCompass", setBool(showCompass));
dogmaphobic's avatar
dogmaphobic committed
247
                altitudeWidget.visible = true;
248
                flightDisplay.saveSetting("showAltitudeWidget", setBool(altitudeWidget.visible));
dogmaphobic's avatar
dogmaphobic committed
249
                currentAltitude.showAltitude = true;
250
                flightDisplay.saveSetting("showCurrentAltitude", setBool(currentAltitude.showAltitude));
dogmaphobic's avatar
dogmaphobic committed
251
                currentAltitude.showClimbRate = true;
252
                flightDisplay.saveSetting("showCurrentClimbRate", setBool(currentAltitude.showClimbRate));
dogmaphobic's avatar
dogmaphobic committed
253
                speedWidget.visible = true;
254
                flightDisplay.saveSetting("showSpeedWidget", setBool(speedWidget.visible));
dogmaphobic's avatar
dogmaphobic committed
255
                currentSpeed.showAirSpeed = true;
256
                flightDisplay.saveSetting("showCurrentAirSpeed", setBool(currentSpeed.showAirSpeed));
dogmaphobic's avatar
dogmaphobic committed
257
                currentSpeed.showGroundSpeed = true;
258 259 260 261 262
                flightDisplay.saveSetting("showCurrentGroundSpeed", setBool(currentSpeed.showGroundSpeed));
                mapBackground.visible = false;
                flightDisplay.saveSetting("showMapBackground", setBool(mapBackground.visible));
                mapBackground.alwaysNorth = false;
                flightDisplay.saveSetting("mapAlwaysPointsNorth", setBool(mapBackground.alwaysNorth));
dogmaphobic's avatar
dogmaphobic committed
263 264 265 266 267 268
            }
        }

    }

    QGCMapBackground {
269 270 271 272 273 274 275
        id:                 mapBackground
        anchors.fill:       parent
        heading:            0 // isNaN(flightDisplay.heading) ? 0 : flightDisplay.heading
        latitude:           mapBackground.visible ? ((flightDisplay.latitude  === 0) ?   37.803784 : flightDisplay.latitude)  :   37.803784
        longitude:          mapBackground.visible ? ((flightDisplay.longitude === 0) ? -122.462276 : flightDisplay.longitude) : -122.462276
        interactive:        !flightDisplay.mavPresent
        z:                  10
dogmaphobic's avatar
dogmaphobic committed
276 277
    }

278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315
    QGCCompassInstrument {
        id:                 compassInstrument
        y:                  5
        x:                  85
        size:               160
        heading:            isNaN(flightDisplay.heading) ? 0 : flightDisplay.heading
        visible:            mapBackground.visible && showCompass
        z:                  mapBackground.z + 1
        onResetRequested: {
            y               = 5
            x               = 85
            size            = 160
            tForm.xScale    = 1
            tForm.yScale    = 1
        }
    }

    QGCAttitudeInstrument {
        id:                 attitudeInstrument
        y:                  5
        size:               160
        rollAngle:          roll
        pitchAngle:         pitch
        showPitch:          showPitchIndicator
        visible:            mapBackground.visible && showAttitudeIndicator
        anchors.right:      root.right
        anchors.rightMargin: 85
        z:                  mapBackground.z + 1
        onResetRequested: {
            y                   = 5
            anchors.right       = root.right
            anchors.rightMargin = 85
            size                = 160
            tForm.xScale        = 1
            tForm.yScale        = 1
        }
    }

dogmaphobic's avatar
dogmaphobic committed
316
    QGCAttitudeWidget {
317
        id:                 attitudeWidget
dogmaphobic's avatar
dogmaphobic committed
318 319 320
        anchors.centerIn:   parent
        rollAngle:          roll
        pitchAngle:         pitch
321 322
        showAttitude:       showAttitudeIndicator
        visible:            !mapBackground.visible
dogmaphobic's avatar
dogmaphobic committed
323
        z:                  10
dogmaphobic's avatar
dogmaphobic committed
324 325 326
    }

    QGCPitchWidget {
327 328
        id:                 pitchWidget
        visible:            showPitchIndicator && !mapBackground.visible
dogmaphobic's avatar
dogmaphobic committed
329
        anchors.verticalCenter: parent.verticalCenter
330 331 332 333 334
        pitchAngle:         pitch
        rollAngle:          roll
        color:              Qt.rgba(0,0,0,0)
        size:               120
        z:                  30
dogmaphobic's avatar
dogmaphobic committed
335 336 337
    }

    QGCAltitudeWidget {
338 339 340 341 342
        id:                 altitudeWidget
        anchors.right:      parent.right
        width:              60
        altitude:           flightDisplay.altitudeWGS84
        z:                  30
dogmaphobic's avatar
dogmaphobic committed
343 344 345
    }

    QGCSpeedWidget {
346 347 348 349 350
        id:                 speedWidget
        anchors.left:       parent.left
        width:              60
        speed:              flightDisplay.groundSpeed
        z:                  40
dogmaphobic's avatar
dogmaphobic committed
351 352 353 354 355
    }

    QGCCurrentSpeed {
        id: currentSpeed
        anchors.left:       parent.left
dogmaphobic's avatar
dogmaphobic committed
356
        width:              75
dogmaphobic's avatar
dogmaphobic committed
357 358 359 360
        airspeed:           flightDisplay.airSpeed
        groundspeed:        flightDisplay.groundSpeed
        showAirSpeed:       true
        showGroundSpeed:    true
dogmaphobic's avatar
dogmaphobic committed
361
        visible:            (currentSpeed.showGroundSpeed || currentSpeed.showAirSpeed)
dogmaphobic's avatar
dogmaphobic committed
362 363 364 365 366
        z:                  50
    }

    QGCCurrentAltitude {
        id: currentAltitude
dogmaphobic's avatar
dogmaphobic committed
367 368 369 370 371 372 373 374
        anchors.right:      parent.right
        width:              75
        altitude:           flightDisplay.altitudeWGS84
        vertZ:              flightDisplay.climbRate
        showAltitude:       true
        showClimbRate:      true
        visible:            (currentAltitude.showAltitude || currentAltitude.showClimbRate)
        z:                  60
dogmaphobic's avatar
dogmaphobic committed
375 376 377
    }

    QGCCompass {
378 379 380 381 382 383 384 385
        id:                 compassIndicator
        y:                  root.height * 0.7
        x:                  root.width  * 0.5 - 60
        width:              120
        height:             120
        heading:            isNaN(flightDisplay.heading) ? 0 : flightDisplay.heading
        visible:            !mapBackground.visible && showCompass
        z:                  70
dogmaphobic's avatar
dogmaphobic committed
386 387
    }

388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413
    // Button at upper left corner
    Item {
        id:             optionsButton
        x:              5
        y:              5
        width:          30
        height:         30
        opacity:        0.85
        z:              1000
        Image {
            id:             buttomImg
            anchors.fill:   parent
            source:         "/qml/buttonMore.svg"
            mipmap:         true
            smooth:         true
            antialiasing:   true
            fillMode:       Image.PreserveAspectFit
        }
        MouseArea {
            anchors.fill: parent
            acceptedButtons: Qt.LeftButton
            onClicked: {
                if (mouse.button == Qt.LeftButton)
                {
                    contextMenu.popup()
                }
dogmaphobic's avatar
dogmaphobic committed
414 415
            }
        }
416
    }
dogmaphobic's avatar
dogmaphobic committed
417
}