FlightDisplayView.qml 9.92 KB
Newer Older
1 2 3 4 5 6 7 8
/****************************************************************************
 *
 *   (c) 2009-2016 QGROUNDCONTROL PROJECT <http://www.qgroundcontrol.org>
 *
 * QGroundControl is licensed according to the terms in the file
 * COPYING.md in the root of the source code directory.
 *
 ****************************************************************************/
9 10


Don Gagne's avatar
Don Gagne committed
11
import QtQuick                  2.5
12 13 14
import QtQuick.Controls         1.3
import QtQuick.Controls.Styles  1.2
import QtQuick.Dialogs          1.2
15
import QtLocation               5.3
16
import QtPositioning            5.2
17
import QtMultimedia             5.5
18

19
import QGroundControl               1.0
Don Gagne's avatar
Don Gagne committed
20
import QGroundControl.FlightDisplay 1.0
21 22 23 24
import QGroundControl.FlightMap     1.0
import QGroundControl.ScreenTools   1.0
import QGroundControl.Controls      1.0
import QGroundControl.Palette       1.0
25
import QGroundControl.Vehicle       1.0
26
import QGroundControl.Controllers   1.0
Don Gagne's avatar
Don Gagne committed
27
import QGroundControl.FactSystem    1.0
28 29

/// Flight Display View
30 31 32
QGCView {
    id:             root
    viewPanel:      _panel
33

34
    QGCPalette { id: qgcPal; colorGroupEnabled: enabled }
35

36
    property var _activeVehicle:        QGroundControl.multiVehicleManager.activeVehicle
37 38
    property bool _mainIsMap:           QGroundControl.videoManager.hasVideo ? QGroundControl.loadBoolGlobalSetting(_mainIsMapKey,  true) : true
    property bool _isPipVisible:        QGroundControl.videoManager.hasVideo ? QGroundControl.loadBoolGlobalSetting(_PIPVisibleKey, true) : false
Don Gagne's avatar
Don Gagne committed
39

Don Gagne's avatar
Don Gagne committed
40 41 42
    property real _roll:                _activeVehicle ? _activeVehicle.roll.value    : _defaultRoll
    property real _pitch:               _activeVehicle ? _activeVehicle.pitch.value   : _defaultPitch
    property real _heading:             _activeVehicle ? _activeVehicle.heading.value : _defaultHeading
43

Don Gagne's avatar
Don Gagne committed
44

Don Gagne's avatar
Don Gagne committed
45 46 47
    property Fact _emptyFact:               Fact { }
    property Fact _groundSpeedFact:         _activeVehicle ? _activeVehicle.groundSpeed      : _emptyFact
    property Fact _airSpeedFact:            _activeVehicle ? _activeVehicle.airSpeed         : _emptyFact
48

49 50
    property bool activeVehicleJoystickEnabled: _activeVehicle ? _activeVehicle.joystickEnabled : false

Don Gagne's avatar
Don Gagne committed
51
    property real _savedZoomLevel:      0
Don Gagne's avatar
Don Gagne committed
52

53
    property real pipSize:              mainWindow.width * 0.2
54

Don Gagne's avatar
Don Gagne committed
55 56 57 58 59 60 61 62 63 64 65 66
    readonly property bool      isBackgroundDark:       _mainIsMap ? (_flightMap ? _flightMap.isSatelliteMap : true) : true
    readonly property real      _defaultRoll:           0
    readonly property real      _defaultPitch:          0
    readonly property real      _defaultHeading:        0
    readonly property real      _defaultAltitudeAMSL:   0
    readonly property real      _defaultGroundSpeed:    0
    readonly property real      _defaultAirSpeed:       0
    readonly property string    _mapName:               "FlightDisplayView"
    readonly property string    _showMapBackgroundKey:  "/showMapBackground"
    readonly property string    _mainIsMapKey:          "MainFlyWindowIsMap"
    readonly property string    _PIPVisibleKey:         "IsPIPVisible"

67
    function setStates() {
68
        QGroundControl.saveBoolGlobalSetting(_mainIsMapKey, _mainIsMap)
69
        if(_mainIsMap) {
70 71 72 73 74 75 76 77
            //-- Adjust Margins
            _flightMapContainer.state   = "fullMode"
            _flightVideo.state          = "pipMode"
            //-- Save/Restore Map Zoom Level
            if(_savedZoomLevel != 0)
                _flightMap.zoomLevel = _savedZoomLevel
            else
                _savedZoomLevel = _flightMap.zoomLevel
78
        } else {
79 80 81 82 83 84
            //-- Adjust Margins
            _flightMapContainer.state   = "pipMode"
            _flightVideo.state          = "fullMode"
            //-- Set Map Zoom Level
            _savedZoomLevel = _flightMap.zoomLevel
            _flightMap.zoomLevel = _savedZoomLevel - 3
85
        }
Don Gagne's avatar
Don Gagne committed
86 87
    }

88 89 90
    function setPipVisibility(state) {
        _isPipVisible = state;
        QGroundControl.saveBoolGlobalSetting(_PIPVisibleKey, state)
91 92
    }

93
    function px4JoystickCheck() {
94
        if ( _activeVehicle && !_activeVehicle.supportsManualControl && (QGroundControl.virtualTabletJoystick || _activeVehicle.joystickEnabled)) {
95 96 97 98 99 100
            px4JoystickSupport.open()
        }
    }

    MessageDialog {
        id:     px4JoystickSupport
101 102 103
        text:   qsTr("Joystick support requires MAVLink MANUAL_CONTROL support. ") +
                qsTr("The firmware you are running does not normally support this. ") +
                qsTr("It will only work if you have modified the firmware to add MANUAL_CONTROL support.")
104 105 106
    }

    Connections {
107
        target: QGroundControl.multiVehicleManager
108 109 110 111 112 113 114 115 116 117
        onActiveVehicleChanged: px4JoystickCheck()
    }

    Connections {
        target: QGroundControl
        onVirtualTabletJoystickChanged: px4JoystickCheck()
    }

    onActiveVehicleJoystickEnabledChanged: px4JoystickCheck()

118 119 120
    Component.onCompleted: {
        widgetsLoader.source = "FlightDisplayViewWidgets.qml"
        setStates()
121
        px4JoystickCheck()
122
    }
dogmaphobic's avatar
dogmaphobic committed
123

124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152
    QGCViewPanel {
        id:             _panel
        anchors.fill:   parent

        //-- Map View
        //   For whatever reason, if FlightDisplayViewMap is the _panel item, changing
        //   width/height has no effect.
        Item {
            id: _flightMapContainer
            z:  _mainIsMap ? _panel.z + 1 : _panel.z + 2
            anchors.left:   _panel.left
            anchors.bottom: _panel.bottom
            visible:        _mainIsMap || _isPipVisible
            width:          _mainIsMap ? _panel.width  : pipSize
            height:         _mainIsMap ? _panel.height : pipSize * (9/16)
            states: [
                State {
                    name:   "pipMode"
                    PropertyChanges {
                        target:             _flightMapContainer
                        anchors.margins:    ScreenTools.defaultFontPixelHeight
                    }
                },
                State {
                    name:   "fullMode"
                    PropertyChanges {
                        target:             _flightMapContainer
                        anchors.margins:    0
                    }
153
                }
154 155 156 157
            ]
            FlightDisplayViewMap {
                id:             _flightMap
                anchors.fill:   parent
Don Gagne's avatar
Don Gagne committed
158
                flightWidgets:  widgetsLoader.item
159
            }
160
        }
161

162
        //-- Video View
163
        Item {
164 165 166 167 168 169
            id:             _flightVideo
            z:              _mainIsMap ? _panel.z + 2 : _panel.z + 1
            width:          !_mainIsMap ? _panel.width  : pipSize
            height:         !_mainIsMap ? _panel.height : pipSize * (9/16)
            anchors.left:   _panel.left
            anchors.bottom: _panel.bottom
170
            visible:        QGroundControl.videoManager.hasVideo && (!_mainIsMap || _isPipVisible)
171 172 173 174 175 176 177 178 179 180 181 182 183 184
            states: [
                State {
                    name:   "pipMode"
                    PropertyChanges {
                        target: _flightVideo
                        anchors.margins:    ScreenTools.defaultFontPixelHeight
                    }
                },
                State {
                    name:   "fullMode"
                    PropertyChanges {
                        target: _flightVideo
                        anchors.margins:    0
                    }
185
                }
186
            ]
187
            //-- Video Streaming
188 189 190 191 192
            FlightDisplayViewVideo {
                anchors.fill:   parent
                visible:        QGroundControl.videoManager.isGStreamer
            }
            //-- UVC Video (USB Camera or Video Device)
193 194
            Loader {
                id:             cameraLoader
195 196
                anchors.fill:   parent
                visible:        !QGroundControl.videoManager.isGStreamer
197
                source:         QGroundControl.videoManager.uvcEnabled ? "qrc:/qml/FlightDisplayViewUVC.qml" : "qrc:/qml/FlightDisplayViewDummy.qml"
198
            }
dogmaphobic's avatar
dogmaphobic committed
199
        }
200 201 202 203 204 205 206 207 208

        QGCPipable {
            id:                 _flightVideoPipControl
            z:                  _flightVideo.z + 3
            width:              pipSize
            height:             pipSize * (9/16)
            anchors.left:       _panel.left
            anchors.bottom:     _panel.bottom
            anchors.margins:    ScreenTools.defaultFontPixelHeight
209
            visible:            QGroundControl.videoManager.hasVideo
210 211 212 213 214 215 216 217 218
            isHidden:           !_isPipVisible
            isDark:             isBackgroundDark
            onActivated: {
                _mainIsMap = !_mainIsMap
                setStates()
            }
            onHideIt: {
                setPipVisibility(!state)
            }
dogmaphobic's avatar
dogmaphobic committed
219
        }
Don Gagne's avatar
Don Gagne committed
220

221 222
        //-- Widgets
        Loader {
223 224
            id:             widgetsLoader
            z:              _panel.z + 4
225 226 227 228
            height:         ScreenTools.availableHeight
            anchors.left:   parent.left
            anchors.right:  parent.right
            anchors.bottom: parent.bottom
229 230
            asynchronous:   true
            visible:        status == Loader.Ready
231

232 233 234
            property bool isBackgroundDark: root.isBackgroundDark
            property var qgcView: root
        }
dogmaphobic's avatar
dogmaphobic committed
235

236
        //-- Virtual Joystick
237
        Loader {
238
            id:                         virtualJoystickMultiTouch
239 240
            z:                          _panel.z + 5
            width:                      parent.width  - (_flightVideoPipControl.width / 2)
241
            height:                     Math.min(ScreenTools.availableHeight * 0.25, ScreenTools.defaultFontPixelWidth * 16)
242 243 244
            visible:                    QGroundControl.virtualTabletJoystick
            anchors.bottom:             _flightVideoPipControl.top
            anchors.bottomMargin:       ScreenTools.defaultFontPixelHeight * 2
245
            anchors.horizontalCenter:   widgetsLoader.horizontalCenter
246 247
            source:                     "qrc:/qml/VirtualJoystick.qml"
            active:                     QGroundControl.virtualTabletJoystick
Don Gagne's avatar
Don Gagne committed
248 249

            property bool useLightColors: root.isBackgroundDark
Don Gagne's avatar
Don Gagne committed
250 251
        }
    }
252
}