FlightDisplay.qml 13.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 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 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
            }
        }

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

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

        MenuSeparator {}

        MenuItem {
            text: "Restore Defaults"
            onTriggered:
            {
                attitudeWidget.visible = true;
259
                flightDisplay.saveSetting("showAttitudeWidget", setBool(attitudeWidget.visible));
dogmaphobic's avatar
dogmaphobic committed
260
                attitudeWidget.displayBackground = true;
261
                flightDisplay.saveSetting("showAttitudeBackground", setBool(attitudeWidget.displayBackground));
dogmaphobic's avatar
dogmaphobic committed
262
                pitchWidget.visible = true;
263
                flightDisplay.saveSetting("showPitchWidget", setBool(pitchWidget.visible));
dogmaphobic's avatar
dogmaphobic committed
264
                altitudeWidget.visible = true;
265
                flightDisplay.saveSetting("showAltitudeWidget", setBool(altitudeWidget.visible));
dogmaphobic's avatar
dogmaphobic committed
266
                currentAltitude.showAltitude = true;
267
                flightDisplay.saveSetting("showCurrentAltitude", setBool(currentAltitude.showAltitude));
dogmaphobic's avatar
dogmaphobic committed
268
                currentAltitude.showClimbRate = true;
269
                flightDisplay.saveSetting("showCurrentClimbRate", setBool(currentAltitude.showClimbRate));
dogmaphobic's avatar
dogmaphobic committed
270
                speedWidget.visible = true;
271
                flightDisplay.saveSetting("showSpeedWidget", setBool(speedWidget.visible));
dogmaphobic's avatar
dogmaphobic committed
272
                currentSpeed.showAirSpeed = true;
273
                flightDisplay.saveSetting("showCurrentAirSpeed", setBool(currentSpeed.showAirSpeed));
dogmaphobic's avatar
dogmaphobic committed
274
                currentSpeed.showGroundSpeed = true;
275
                flightDisplay.saveSetting("showCurrentGroundSpeed", setBool(currentSpeed.showGroundSpeed));
dogmaphobic's avatar
dogmaphobic committed
276
                compassIndicator.visible = true;
277 278 279 280 281
                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
282 283 284 285 286 287
            }
        }

    }

    QGCMapBackground {
288 289 290 291 292 293 294
        id:             mapBackground
        anchors.fill:   parent
        visible:        false
        heading:        isNaN(flightDisplay.heading) ? 0 : flightDisplay.heading
        latitude:       flightDisplay.latitude
        longitude:      flightDisplay.longitude
        z:              5
dogmaphobic's avatar
dogmaphobic committed
295 296 297
    }

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

    QGCPitchWidget {
308
        id:         pitchWidget
dogmaphobic's avatar
dogmaphobic committed
309 310 311
        anchors.verticalCenter: parent.verticalCenter
        pitchAngle: pitch
        rollAngle:  roll
312 313 314
        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
315 316 317 318 319 320 321 322
    }

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

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

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

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

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

    QGCCompass {
        id: compassIndicator
dogmaphobic's avatar
dogmaphobic committed
368
        y: root.height * 0.7
dogmaphobic's avatar
dogmaphobic committed
369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385
        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
    }
}