FlightDisplayView.qml 9.62 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
/*=====================================================================

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

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

Don Gagne's avatar
Don Gagne committed
24
import QtQuick                  2.5
25 26 27
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

Don Gagne's avatar
Don Gagne committed
46
    property real availableHeight: parent.height
dogmaphobic's avatar
dogmaphobic committed
47 48 49

    readonly property bool isBackgroundDark: _mainIsMap ? (_flightMap ? _flightMap.isSatelliteMap : true) : true

50
    property var _activeVehicle:    multiVehicleManager.activeVehicle
51

52 53 54 55 56 57 58
    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
59

60 61
    readonly property string _mapName:                  "FlightDisplayView"
    readonly property string _showMapBackgroundKey:     "/showMapBackground"
62
    readonly property string _mainIsMapKey:             "MainFlyWindowIsMap"
dogmaphobic's avatar
dogmaphobic committed
63
    readonly property string _PIPVisibleKey:            "IsPIPVisible"
Don Gagne's avatar
Don Gagne committed
64

dogmaphobic's avatar
dogmaphobic committed
65 66
    property bool _mainIsMap:           QGroundControl.loadBoolGlobalSetting(_mainIsMapKey,  true)
    property bool _isPipVisible:        QGroundControl.loadBoolGlobalSetting(_PIPVisibleKey, true)
Don Gagne's avatar
Don Gagne committed
67

68 69
    property real _roll:                _activeVehicle ? (isNaN(_activeVehicle.roll)    ? _defaultRoll    : _activeVehicle.roll)    : _defaultRoll
    property real _pitch:               _activeVehicle ? (isNaN(_activeVehicle.pitch)   ? _defaultPitch   : _activeVehicle.pitch)   : _defaultPitch
70
    property real _heading:             _activeVehicle ? (isNaN(_activeVehicle.heading) ? _defaultHeading : _activeVehicle.heading) : _defaultHeading
71

72
    property real _altitudeWGS84:       _activeVehicle ? _activeVehicle.altitudeWGS84 : _defaultAltitudeWGS84
73 74 75
    property real _groundSpeed:         _activeVehicle ? _activeVehicle.groundSpeed   : _defaultGroundSpeed
    property real _airSpeed:            _activeVehicle ? _activeVehicle.airSpeed      : _defaultAirSpeed
    property real _climbRate:           _activeVehicle ? _activeVehicle.climbRate     : _defaultClimbRate
76

77
    property var  _savedZoomLevel:      0
Don Gagne's avatar
Don Gagne committed
78

79
    property real pipSize:              mainWindow.width * 0.2
80

81
    FlightDisplayViewController { id: _controller }
82

83
    function setStates() {
84
        if(_mainIsMap) {
85 86 87 88 89 90 91 92
            //-- Adjust Margins
            _flightMapContainer.state   = "fullMode"
            _flightVideo.state          = "pipMode"
            //-- Save/Restore Map Zoom Level
            if(_savedZoomLevel != 0)
                _flightMap.zoomLevel = _savedZoomLevel
            else
                _savedZoomLevel = _flightMap.zoomLevel
93
        } else {
94 95 96 97 98 99
            //-- Adjust Margins
            _flightMapContainer.state   = "pipMode"
            _flightVideo.state          = "fullMode"
            //-- Set Map Zoom Level
            _savedZoomLevel = _flightMap.zoomLevel
            _flightMap.zoomLevel = _savedZoomLevel - 3
100
        }
Don Gagne's avatar
Don Gagne committed
101 102
    }

103 104 105
    function setPipVisibility(state) {
        _isPipVisible = state;
        QGroundControl.saveBoolGlobalSetting(_PIPVisibleKey, state)
106 107
    }

108 109 110
    Component.onCompleted: {
        widgetsLoader.source = "FlightDisplayViewWidgets.qml"
        setStates()
111
    }
dogmaphobic's avatar
dogmaphobic committed
112

113 114 115
    //-- Map View
    //   For whatever reason, if FlightDisplayViewMap is the root item, changing
    //   width/height has no effect.
dogmaphobic's avatar
dogmaphobic committed
116
    Item {
117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136
        id: _flightMapContainer
        z:  _mainIsMap ? root.z + 1 : root.z + 2
        anchors.left:   root.left
        anchors.bottom: root.bottom
        visible:        _mainIsMap || _isPipVisible
        width:          _mainIsMap ? root.width  : pipSize
        height:         _mainIsMap ? root.height : pipSize * (9/16)
        states: [
            State {
                name:   "pipMode"
                PropertyChanges {
                    target:             _flightMapContainer
                    anchors.margins:    ScreenTools.defaultFontPixelHeight
                }
            },
            State {
                name:   "fullMode"
                PropertyChanges {
                    target:             _flightMapContainer
                    anchors.margins:    0
137
                }
138
            }
139 140 141 142
        ]
        FlightDisplayViewMap {
            id:             _flightMap
            anchors.fill:   parent
143
        }
144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167
    }

    //-- Video View
    FlightDisplayViewVideo {
        id:             _flightVideo
        z:              _mainIsMap ? root.z + 2 : root.z + 1
        width:          !_mainIsMap ? root.width  : pipSize
        height:         !_mainIsMap ? root.height : pipSize * (9/16)
        anchors.left:   root.left
        anchors.bottom: root.bottom
        visible:        _controller.hasVideo && (!_mainIsMap || _isPipVisible)
        states: [
            State {
                name:   "pipMode"
                PropertyChanges {
                    target: _flightVideo
                    anchors.margins:    ScreenTools.defaultFontPixelHeight
                }
            },
            State {
                name:   "fullMode"
                PropertyChanges {
                    target: _flightVideo
                    anchors.margins:    0
dogmaphobic's avatar
dogmaphobic committed
168 169
                }
            }
170
        ]
dogmaphobic's avatar
dogmaphobic committed
171 172
    }

173 174 175 176 177 178 179 180 181 182 183 184 185
    QGCPipable {
        id:                 _flightVideoPipControl
        z:                  _flightVideo.z + 3
        width:              pipSize
        height:             pipSize * (9/16)
        anchors.left:       root.left
        anchors.bottom:     root.bottom
        anchors.margins:    ScreenTools.defaultFontPixelHeight
        isHidden:           !_isPipVisible
        isDark:             isBackgroundDark
        onActivated: {
            _mainIsMap = !_mainIsMap
            setStates()
dogmaphobic's avatar
dogmaphobic committed
186
        }
187 188
        onHideIt: {
            setPipVisibility(!state)
dogmaphobic's avatar
dogmaphobic committed
189
        }
190
    }
Don Gagne's avatar
Don Gagne committed
191

192
    //-- Widgets
Don Gagne's avatar
Don Gagne committed
193
    Loader {
194
        id:                 widgetsLoader
195
        z:                  root.z + 4
dogmaphobic's avatar
dogmaphobic committed
196 197 198
        anchors.right:      parent.right
        anchors.left:       parent.left
        anchors.bottom:     parent.bottom
Don Gagne's avatar
Don Gagne committed
199
        height:             availableHeight
200
        property bool isBackgroundDark: root.isBackgroundDark
Don Gagne's avatar
Don Gagne committed
201
    }
dogmaphobic's avatar
dogmaphobic committed
202

203
    //-- Virtual Joystick
Don Gagne's avatar
Don Gagne committed
204
    Item {
Don Gagne's avatar
Don Gagne committed
205
        id:                         multiTouchItem
206 207
        z:                          root.z + 5
        width:                      parent.width  - (_flightVideoPipControl.width / 2)
Don Gagne's avatar
Don Gagne committed
208 209
        height:                     thumbAreaHeight
        visible:                    QGroundControl.virtualTabletJoystick
210
        anchors.bottom:             _flightVideoPipControl.top
Don Gagne's avatar
Don Gagne committed
211 212
        anchors.bottomMargin:       ScreenTools.defaultFontPixelHeight * 2
        anchors.horizontalCenter:   parent.horizontalCenter
Don Gagne's avatar
Don Gagne committed
213

214
        readonly property real thumbAreaHeight: Math.min(parent.height * 0.25, ScreenTools.defaultFontPixelWidth * 16)
Don Gagne's avatar
Don Gagne committed
215 216 217 218

        QGCMapPalette { id: mapPal; lightColors: !isBackgroundDark }

        Timer {
Don Gagne's avatar
Don Gagne committed
219 220
            interval:   40  // 25Hz, same as real joystick rate
            running:    QGroundControl.virtualTabletJoystick && _activeVehicle
Don Gagne's avatar
Don Gagne committed
221 222 223 224 225 226 227 228 229
            repeat:     true
            onTriggered: {
                if (_activeVehicle) {
                    _activeVehicle.virtualTabletJoystickValue(rightStick.xAxis, rightStick.yAxis, leftStick.xAxis, leftStick.yAxis)
                }
            }
        }

        JoystickThumbPad {
Don Gagne's avatar
Don Gagne committed
230 231 232 233 234 235 236 237 238
            id:                     leftStick
            anchors.leftMargin:     xPositionDelta
            anchors.bottomMargin:   -yPositionDelta
            anchors.left:           parent.left
            anchors.bottom:         parent.bottom
            width:                  parent.thumbAreaHeight
            height:                 parent.thumbAreaHeight
            yAxisThrottle:          true
            lightColors:            !isBackgroundDark
Don Gagne's avatar
Don Gagne committed
239 240 241
        }

        JoystickThumbPad {
Don Gagne's avatar
Don Gagne committed
242 243 244 245 246 247 248 249
            id:                     rightStick
            anchors.rightMargin:    -xPositionDelta
            anchors.bottomMargin:   -yPositionDelta
            anchors.right:          parent.right
            anchors.bottom:         parent.bottom
            width:                  parent.thumbAreaHeight
            height:                 parent.thumbAreaHeight
            lightColors:            !isBackgroundDark
Don Gagne's avatar
Don Gagne committed
250 251
        }
    }
252
}