FlightDisplay.qml 13.8 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 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
/*=====================================================================

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
 *   @brief QGC Main Tool Bar
 *   @author Gus Grubba <mavlink@grubba.com>
 */

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

import QGroundControl.HUDControls 1.0

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 46 47 48 49 50
    function getBool(value) {
        return value === '0' ? false : true;
    }

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

dogmaphobic's avatar
dogmaphobic committed
51 52
    Component.onCompleted:
    {
53 54 55 56 57 58 59 60 61 62 63 64 65
        mapBackground.visible               = getBool(flightDisplay.loadSetting("showMapBackground",        "0"));
        mapBackground.alwaysNorth           = getBool(flightDisplay.loadSetting("mapAlwaysPointsNorth",     "0"));
        attitudeWidget.visible              = getBool(flightDisplay.loadSetting("showAttitudeWidget",       "1"));
        attitudeWidget.displayBackground    = getBool(flightDisplay.loadSetting("showAttitudeBackground",   "1"));
        pitchWidget.visible                 = getBool(flightDisplay.loadSetting("showPitchWidget",          "1"));
        altitudeWidget.visible              = getBool(flightDisplay.loadSetting("showAltitudeWidget",       "1"));
        speedWidget.visible                 = getBool(flightDisplay.loadSetting("showSpeedWidget",          "1"));
        compassIndicator.visible            = getBool(flightDisplay.loadSetting("showCompassIndicator",     "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
66 67 68 69 70 71
    }

    Rectangle {
        id: windowBackground
        anchors.fill: parent
        anchors.centerIn: parent
dogmaphobic's avatar
dogmaphobic committed
72
        visible: !attitudeWidget.visible && !mapBackground.visible
dogmaphobic's avatar
dogmaphobic committed
73 74 75 76 77 78 79 80
        color:   Qt.hsla(0.25, 0.5, 0.45)
        z:       0
    }

    Menu {
        id: contextMenu

        MenuItem {
dogmaphobic's avatar
dogmaphobic committed
81
            text: "Main Attitude Indicators"
dogmaphobic's avatar
dogmaphobic committed
82 83 84 85 86
            checkable: true
            checked: attitudeWidget.visible
            onTriggered:
            {
                attitudeWidget.visible = !attitudeWidget.visible;
87
                flightDisplay.saveSetting("showAttitudeWidget", setBool(attitudeWidget.visible));
dogmaphobic's avatar
dogmaphobic committed
88 89 90 91
            }
        }

        MenuItem {
dogmaphobic's avatar
dogmaphobic committed
92
            text: "Display Attitude Background"
dogmaphobic's avatar
dogmaphobic committed
93 94 95 96 97
            checkable: true
            checked: attitudeWidget.displayBackground
            onTriggered:
            {
                attitudeWidget.displayBackground = !attitudeWidget.displayBackground;
98
                flightDisplay.saveSetting("showAttitudeBackground", setBool(attitudeWidget.displayBackground));
dogmaphobic's avatar
dogmaphobic committed
99 100 101 102 103 104 105 106 107 108
            }
        }

        MenuItem {
            text: "Pitch Indicator"
            checkable: true
            checked: pitchWidget.visible
            onTriggered:
            {
                pitchWidget.visible = !pitchWidget.visible;
109
                flightDisplay.saveSetting("showPitchWidget", setBool(pitchWidget.visible));
dogmaphobic's avatar
dogmaphobic committed
110 111 112 113 114 115 116 117 118 119
            }
        }

        MenuItem {
            text: "Altitude Indicator"
            checkable: true
            checked: altitudeWidget.visible
            onTriggered:
            {
                altitudeWidget.visible = !altitudeWidget.visible;
120
                flightDisplay.saveSetting("showAltitudeWidget", setBool(altitudeWidget.visible));
dogmaphobic's avatar
dogmaphobic committed
121 122 123 124 125 126 127 128 129 130
            }
        }

        MenuItem {
            text: "Current Altitude"
            checkable: true
            checked: currentAltitude.showAltitude
            onTriggered:
            {
                currentAltitude.showAltitude = !currentAltitude.showAltitude;
131
                flightDisplay.saveSetting("showCurrentAltitude", setBool(currentAltitude.showAltitude));
dogmaphobic's avatar
dogmaphobic committed
132 133 134 135 136 137 138 139 140 141
            }
        }

        MenuItem {
            text: "Current Climb Rate"
            checkable: true
            checked: currentAltitude.showClimbRate
            onTriggered:
            {
                currentAltitude.showClimbRate = !currentAltitude.showClimbRate;
142
                flightDisplay.saveSetting("showCurrentClimbRate", setBool(currentAltitude.showClimbRate));
dogmaphobic's avatar
dogmaphobic committed
143 144 145 146 147 148 149 150 151 152
            }
        }

        MenuItem {
            text: "Speed Indicator"
            checkable: true
            checked: speedWidget.visible
            onTriggered:
            {
                speedWidget.visible = !speedWidget.visible;
153
                flightDisplay.saveSetting("showSpeedWidget", setBool(speedWidget.visible));
dogmaphobic's avatar
dogmaphobic committed
154 155 156 157 158 159 160 161 162 163
            }
        }

        MenuItem {
            text: "Current Air Speed"
            checkable: true
            checked: currentSpeed.showAirSpeed
            onTriggered:
            {
                currentSpeed.showAirSpeed = !currentSpeed.showAirSpeed;
164
                flightDisplay.saveSetting("showCurrentAirSpeed", setBool(currentSpeed.showAirSpeed));
dogmaphobic's avatar
dogmaphobic committed
165 166 167 168 169 170 171 172 173 174
            }
        }

        MenuItem {
            text: "Current Ground Speed"
            checkable: true
            checked: currentSpeed.showGroundSpeed
            onTriggered:
            {
                currentSpeed.showGroundSpeed = !currentSpeed.showGroundSpeed;
175
                flightDisplay.saveSetting("showCurrentGroundSpeed", setBool(currentSpeed.showGroundSpeed));
dogmaphobic's avatar
dogmaphobic committed
176 177 178 179 180 181 182 183 184 185
            }
        }

        MenuItem {
            text: "Compass"
            checkable: true
            checked: compassIndicator.visible
            onTriggered:
            {
                compassIndicator.visible = !compassIndicator.visible;
186
                flightDisplay.saveSetting("showCompassIndicator", setBool(compassIndicator.visible));
dogmaphobic's avatar
dogmaphobic committed
187 188 189 190 191 192 193 194 195 196 197 198
            }
        }

        MenuSeparator {}

        MenuItem {
            text: "Map Background"
            checkable: true
            checked: mapBackground.visible
            onTriggered:
            {
                mapBackground.visible = !mapBackground.visible;
199
                flightDisplay.saveSetting("showMapBackground", setBool(mapBackground.visible));
dogmaphobic's avatar
dogmaphobic committed
200 201 202 203
            }
        }

        MenuItem {
dogmaphobic's avatar
dogmaphobic committed
204
            text: "Map Always Points North"
dogmaphobic's avatar
dogmaphobic committed
205
            checkable: true
dogmaphobic's avatar
dogmaphobic committed
206
            checked: mapBackground.alwaysNorth
dogmaphobic's avatar
dogmaphobic committed
207 208 209
            onTriggered:
            {
                mapBackground.alwaysNorth = !mapBackground.alwaysNorth;
210
                flightDisplay.saveSetting("mapAlwaysPointsNorth", setBool(mapBackground.alwaysNorth));
dogmaphobic's avatar
dogmaphobic committed
211 212 213
            }
        }

214 215 216
        Menu {
            id: mapTypeMenu
            title: "Map Type..."
217
            ExclusiveGroup { id: currentMapType }
218 219 220 221 222 223 224 225 226
            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;
                    }
                }
            }
227
            function addMap(map, checked) {
228
                var mItem = mapTypeMenu.addItem(map);
229 230 231
                mItem.checkable = true
                mItem.checked   = checked
                mItem.exclusiveGroup = currentMapType
232 233 234 235 236 237 238 239 240
                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);
241 242 243 244
                for (var i = 0; i < mapBackground.mapItem.supportedMapTypes.length; i++) {
                    var name = mapBackground.mapItem.supportedMapTypes[i].name;
                    addMap(name, map === name);
                }
245 246
                if(map != '')
                    setCurrentMap(map);
dogmaphobic's avatar
dogmaphobic committed
247 248 249 250 251 252 253 254 255 256
            }
        }

        MenuSeparator {}

        MenuItem {
            text: "Restore Defaults"
            onTriggered:
            {
                attitudeWidget.visible = true;
257
                flightDisplay.saveSetting("showAttitudeWidget", setBool(attitudeWidget.visible));
dogmaphobic's avatar
dogmaphobic committed
258
                attitudeWidget.displayBackground = true;
259
                flightDisplay.saveSetting("showAttitudeBackground", setBool(attitudeWidget.displayBackground));
dogmaphobic's avatar
dogmaphobic committed
260
                pitchWidget.visible = true;
261
                flightDisplay.saveSetting("showPitchWidget", setBool(pitchWidget.visible));
dogmaphobic's avatar
dogmaphobic committed
262
                altitudeWidget.visible = true;
263
                flightDisplay.saveSetting("showAltitudeWidget", setBool(altitudeWidget.visible));
dogmaphobic's avatar
dogmaphobic committed
264
                currentAltitude.showAltitude = true;
265
                flightDisplay.saveSetting("showCurrentAltitude", setBool(currentAltitude.showAltitude));
dogmaphobic's avatar
dogmaphobic committed
266
                currentAltitude.showClimbRate = true;
267
                flightDisplay.saveSetting("showCurrentClimbRate", setBool(currentAltitude.showClimbRate));
dogmaphobic's avatar
dogmaphobic committed
268
                speedWidget.visible = true;
269
                flightDisplay.saveSetting("showSpeedWidget", setBool(speedWidget.visible));
dogmaphobic's avatar
dogmaphobic committed
270
                currentSpeed.showAirSpeed = true;
271
                flightDisplay.saveSetting("showCurrentAirSpeed", setBool(currentSpeed.showAirSpeed));
dogmaphobic's avatar
dogmaphobic committed
272
                currentSpeed.showGroundSpeed = true;
273
                flightDisplay.saveSetting("showCurrentGroundSpeed", setBool(currentSpeed.showGroundSpeed));
dogmaphobic's avatar
dogmaphobic committed
274
                compassIndicator.visible = true;
275 276 277 278 279
                flightDisplay.saveSetting("showCompassIndicator", setBool(compassIndicator.visible));
                mapBackground.visible = false;
                flightDisplay.saveSetting("showMapBackground", setBool(mapBackground.visible));
                mapBackground.alwaysNorth = false;
                flightDisplay.saveSetting("mapAlwaysPointsNorth", setBool(mapBackground.alwaysNorth));
dogmaphobic's avatar
dogmaphobic committed
280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296
            }
        }

    }

    QGCMapBackground {
        id: mapBackground
        anchors.centerIn: parent
        visible:   false
        heading:   isNaN(flightDisplay.heading) ? 0 : flightDisplay.heading
        latitude:  flightDisplay.latitude
        longitude: flightDisplay.longitude
        z: 5
    }

    QGCAttitudeWidget {
        id: attitudeWidget
dogmaphobic's avatar
dogmaphobic committed
297 298 299
        anchors.centerIn:   parent
        rollAngle:          roll
        pitchAngle:         pitch
300 301
        useWhite:           !mapBackground.visible
        backgroundOpacity:  mapBackground.visible ? 0.25 : 1.0
dogmaphobic's avatar
dogmaphobic committed
302
        z:                  10
dogmaphobic's avatar
dogmaphobic committed
303 304 305 306 307 308 309
    }

    QGCPitchWidget {
        id: pitchWidget
        anchors.verticalCenter: parent.verticalCenter
        pitchAngle: pitch
        rollAngle:  roll
310 311 312
        color:      mapBackground.visible ? Qt.rgba(0,0,0,0.5) : Qt.rgba(0,0,0,0)
        opacity:    mapBackground.visible ? 1 : 0.75
        z:          mapBackground.visible ? 20 : 25
dogmaphobic's avatar
dogmaphobic committed
313 314 315 316 317 318 319 320
    }

    Image {
        anchors.centerIn: parent
        source:   "/qml/crossHair.svg"
        mipmap:   true
        width:    260
        fillMode: Image.PreserveAspectFit
321
        z:        mapBackground.visible ? 25 : 20
dogmaphobic's avatar
dogmaphobic committed
322 323 324 325 326
    }

    QGCAltitudeWidget {
        id: altitudeWidget
        anchors.right: parent.right
327
        width:     60
dogmaphobic's avatar
dogmaphobic committed
328 329 330 331 332 333 334
        altitude:  flightDisplay.altitudeWGS84
        z:         30
    }

    QGCSpeedWidget {
        id: speedWidget
        anchors.left: parent.left
335
        width:  60
dogmaphobic's avatar
dogmaphobic committed
336 337 338 339 340 341 342
        speed:  flightDisplay.groundSpeed
        z:      40
    }

    QGCCurrentSpeed {
        id: currentSpeed
        anchors.left:       parent.left
dogmaphobic's avatar
dogmaphobic committed
343
        width:              75
dogmaphobic's avatar
dogmaphobic committed
344 345 346 347
        airspeed:           flightDisplay.airSpeed
        groundspeed:        flightDisplay.groundSpeed
        showAirSpeed:       true
        showGroundSpeed:    true
dogmaphobic's avatar
dogmaphobic committed
348
        visible:            (currentSpeed.showGroundSpeed || currentSpeed.showAirSpeed)
dogmaphobic's avatar
dogmaphobic committed
349 350 351 352 353
        z:                  50
    }

    QGCCurrentAltitude {
        id: currentAltitude
dogmaphobic's avatar
dogmaphobic committed
354 355 356 357 358 359 360 361
        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
362 363 364 365
    }

    QGCCompass {
        id: compassIndicator
dogmaphobic's avatar
dogmaphobic committed
366
        y: root.height * 0.7
dogmaphobic's avatar
dogmaphobic committed
367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383
        anchors.horizontalCenter: parent.horizontalCenter
        heading: isNaN(flightDisplay.heading) ? 0 : flightDisplay.heading
        z:       70
    }

    MouseArea {
        anchors.fill: parent
        acceptedButtons: Qt.RightButton
        onClicked: {
            if (mouse.button == Qt.RightButton)
            {
                contextMenu.popup()
            }
        }
        z: 100
    }
}