FlightDisplayView.qml 6.63 KB
Newer Older
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
/*=====================================================================

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/>.

======================================================================*/

import QtQuick                  2.4
import QtQuick.Controls         1.3
import QtQuick.Controls.Styles  1.2
import QtQuick.Dialogs          1.2
28
import QtLocation               5.3
29
import QtPositioning            5.2
30

31
import QGroundControl               1.0
Don Gagne's avatar
Don Gagne committed
32
import QGroundControl.FlightDisplay 1.0
33 34 35 36
import QGroundControl.FlightMap     1.0
import QGroundControl.ScreenTools   1.0
import QGroundControl.Controls      1.0
import QGroundControl.Palette       1.0
37
import QGroundControl.Vehicle       1.0
38
import QGroundControl.Controllers   1.0
39 40 41 42 43

/// Flight Display View
Item {
    id: root

44
    QGCPalette { id: qgcPal; colorGroupEnabled: enabled }
45 46 47

    property var _activeVehicle: multiVehicleManager.activeVehicle

48 49 50 51 52 53 54 55
    readonly property var  _defaultVehicleCoordinate:   QtPositioning.coordinate(37.803784, -122.462276)
    readonly property real _defaultRoll:                0
    readonly property real _defaultPitch:               0
    readonly property real _defaultHeading:             0
    readonly property real _defaultAltitudeWGS84:       0
    readonly property real _defaultGroundSpeed:         0
    readonly property real _defaultAirSpeed:            0
    readonly property real _defaultClimbRate:           0
56

57 58
    readonly property string _mapName:                  "FlightDisplayView"
    readonly property string _showMapBackgroundKey:     "/showMapBackground"
59
    readonly property string _mainIsMapKey:             "MainFlyWindowIsMap"
Don Gagne's avatar
Don Gagne committed
60

61
    property bool _mainIsMap:           QGroundControl.loadBoolGlobalSetting(_mainIsMapKey, true)
Don Gagne's avatar
Don Gagne committed
62

63 64
    property real _roll:                _activeVehicle ? (isNaN(_activeVehicle.roll)    ? _defaultRoll    : _activeVehicle.roll)    : _defaultRoll
    property real _pitch:               _activeVehicle ? (isNaN(_activeVehicle.pitch)   ? _defaultPitch   : _activeVehicle.pitch)   : _defaultPitch
65
    property real _heading:             _activeVehicle ? (isNaN(_activeVehicle.heading) ? _defaultHeading : _activeVehicle.heading) : _defaultHeading
66

67
    property var  _vehicleCoordinate:   _activeVehicle ? (_activeVehicle.coordinateValid ? _activeVehicle.coordinate : _defaultVehicleCoordinate) : _defaultVehicleCoordinate
68

69
    property real _altitudeWGS84:       _activeVehicle ? _activeVehicle.altitudeWGS84 : _defaultAltitudeWGS84
70 71 72
    property real _groundSpeed:         _activeVehicle ? _activeVehicle.groundSpeed   : _defaultGroundSpeed
    property real _airSpeed:            _activeVehicle ? _activeVehicle.airSpeed      : _defaultAirSpeed
    property real _climbRate:           _activeVehicle ? _activeVehicle.climbRate     : _defaultClimbRate
73

74 75 76
    property var  _flightMap:           null
    property var  _flightVideo:         null
    property var  _savedZoomLevel:      0
Don Gagne's avatar
Don Gagne committed
77

78 79
    property real _pipSize:             ScreenTools.isAndroid ? ScreenTools.defaultFontPixelSize * (8) : ScreenTools.defaultFontPixelSize * (9)

80
    FlightDisplayViewController { id: _controller }
81 82 83 84 85

    MissionController {
        id: _missionController
        Component.onCompleted: start(false /* editMode */)
    }
86

87 88 89 90 91 92 93 94 95 96 97
    function reloadContents() {
        if(_flightVideo) {
            _flightVideo.visible = false
        }
        if(_mainIsMap) {
            mainLoader.source   = "FlightDisplayViewMap.qml"
            pipLoader.source    = "FlightDisplayViewVideo.qml"
        } else {
            mainLoader.source   = "FlightDisplayViewVideo.qml"
            pipLoader.source    = "FlightDisplayViewMap.qml"
        }
Don Gagne's avatar
Don Gagne committed
98 99
    }

100
    Component.onCompleted: {
101 102
        reloadContents();
        widgetsLoader.source    = "FlightDisplayViewWidgets.qml"
103 104
    }

105 106 107 108 109 110 111 112 113 114 115 116 117 118 119
    //-- Main Window
    Loader {
        id:                 mainLoader
        anchors.fill:       parent
        onLoaded: {
            if(_mainIsMap) {
                _flightMap   = item
                if(_savedZoomLevel != 0)
                    _flightMap.zoomLevel = _savedZoomLevel
                else
                    _savedZoomLevel = _flightMap.zoomLevel
                _flightMap.updateMapPosition(true /* force */)
            } else {
                _flightVideo = item
                _flightVideo.visible = true
Don Gagne's avatar
Don Gagne committed
120 121
            }
        }
122
    }
dogmaphobic's avatar
dogmaphobic committed
123

124 125 126 127 128 129 130
    //-- PIP Window
    Rectangle {
        id:                 pip
        visible:            _controller.hasVideo
        anchors.margins:    ScreenTools.defaultFontPixelHeight
        anchors.left:       parent.left
        anchors.bottom:     parent.bottom
131 132
        height:             _pipSize
        width:              _pipSize * (16/9)
133 134 135 136 137 138 139 140
        color:              "#000010"
        border.width:       4
        radius:             4
        border.color: {
            if(_mainIsMap && _flightMap != null)
                return _flightMap.isSatelliteMap ? Qt.rgba(1,1,1,0.75) :  Qt.rgba(0,0,0,0.75)
            else
                return Qt.rgba(0,0,0,0.75)
141
        }
142 143 144 145 146 147 148 149 150 151 152 153
        Loader {
            id:                 pipLoader
            anchors.fill:       parent
            anchors.margins:    2
            onLoaded: {
                if(_mainIsMap) {
                    _flightVideo = item
                    _flightVideo.visible = true
                } else {
                    _flightMap = item
                    _savedZoomLevel = _flightMap.zoomLevel
                    _flightMap.zoomLevel = _savedZoomLevel - 3
154
                }
155 156
                pip.visible = _controller.hasVideo
            }
157
        }
158 159
        MouseArea {
            anchors.fill: parent
160 161 162 163
            onClicked: {
                _mainIsMap = !_mainIsMap
                pip.visible = false
                reloadContents();
164
                QGroundControl.saveBoolGlobalSetting(_mainIsMapKey, _mainIsMap)
165
            }
166
        }
167
    }
Don Gagne's avatar
Don Gagne committed
168

169
    //-- Widgets
Don Gagne's avatar
Don Gagne committed
170
    Loader {
171 172
        id:                 widgetsLoader
        anchors.fill:       parent
Don Gagne's avatar
Don Gagne committed
173
    }
174
}