FlightDisplayView.qml 12.9 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 37
    property bool activeVehicleJoystickEnabled: _activeVehicle ? _activeVehicle.joystickEnabled : false

38
    property var _activeVehicle:        QGroundControl.multiVehicleManager.activeVehicle
39 40
    property bool _mainIsMap:           QGroundControl.videoManager.hasVideo ? QGroundControl.loadBoolGlobalSetting(_mainIsMapKey,  true) : true
    property bool _isPipVisible:        QGroundControl.videoManager.hasVideo ? QGroundControl.loadBoolGlobalSetting(_PIPVisibleKey, true) : false
41 42 43
    property real _savedZoomLevel:      0
    property real _margins:             ScreenTools.defaultFontPixelWidth / 2
    property real _pipSize:             mainWindow.width * 0.2
44

Don Gagne's avatar
Don Gagne committed
45 46 47 48 49 50 51 52 53 54 55 56
    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"

57
    function setStates() {
58
        QGroundControl.saveBoolGlobalSetting(_mainIsMapKey, _mainIsMap)
59
        if(_mainIsMap) {
60 61 62 63 64 65 66 67
            //-- Adjust Margins
            _flightMapContainer.state   = "fullMode"
            _flightVideo.state          = "pipMode"
            //-- Save/Restore Map Zoom Level
            if(_savedZoomLevel != 0)
                _flightMap.zoomLevel = _savedZoomLevel
            else
                _savedZoomLevel = _flightMap.zoomLevel
68
        } else {
69 70 71 72 73 74
            //-- Adjust Margins
            _flightMapContainer.state   = "pipMode"
            _flightVideo.state          = "fullMode"
            //-- Set Map Zoom Level
            _savedZoomLevel = _flightMap.zoomLevel
            _flightMap.zoomLevel = _savedZoomLevel - 3
75
        }
Don Gagne's avatar
Don Gagne committed
76 77
    }

78 79 80
    function setPipVisibility(state) {
        _isPipVisible = state;
        QGroundControl.saveBoolGlobalSetting(_PIPVisibleKey, state)
81 82
    }

83
    function px4JoystickCheck() {
84
        if ( _activeVehicle && !_activeVehicle.supportsManualControl && (QGroundControl.settingsManager.appSettings.virtualJoystick.value || _activeVehicle.joystickEnabled)) {
85 86 87 88 89 90
            px4JoystickSupport.open()
        }
    }

    MessageDialog {
        id:     px4JoystickSupport
91 92 93
        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.")
94 95 96
    }

    Connections {
97
        target: QGroundControl.multiVehicleManager
98 99 100 101
        onActiveVehicleChanged: px4JoystickCheck()
    }

    Connections {
102 103
        target:         QGroundControl.settingsManager.appSettings.virtualJoystick
        onValueChanged: px4JoystickCheck()
104 105 106 107
    }

    onActiveVehicleJoystickEnabledChanged: px4JoystickCheck()

108 109
    Component.onCompleted: {
        setStates()
110
        px4JoystickCheck()
111
    }
dogmaphobic's avatar
dogmaphobic committed
112

113 114
    QGCMapPalette { id: mapPal; lightColors: _mainIsMap ? _flightMap.isSatelliteMap : true }

115 116 117 118 119 120 121 122 123 124 125 126 127
    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
128 129
            width:          _mainIsMap ? _panel.width  : _pipSize
            height:         _mainIsMap ? _panel.height : _pipSize * (9/16)
130 131 132 133 134 135 136 137 138 139 140 141 142 143
            states: [
                State {
                    name:   "pipMode"
                    PropertyChanges {
                        target:             _flightMapContainer
                        anchors.margins:    ScreenTools.defaultFontPixelHeight
                    }
                },
                State {
                    name:   "fullMode"
                    PropertyChanges {
                        target:             _flightMapContainer
                        anchors.margins:    0
                    }
144
                }
145 146
            ]
            FlightDisplayViewMap {
147 148 149 150
                id:                 _flightMap
                anchors.fill:       parent
                flightWidgets:      flightDisplayViewWidgets
                rightPanelWidth:    ScreenTools.defaultFontPixelHeight * 9
151
            }
152
        }
153

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

        QGCPipable {
            id:                 _flightVideoPipControl
            z:                  _flightVideo.z + 3
196 197
            width:              _pipSize
            height:             _pipSize * (9/16)
198 199 200
            anchors.left:       _panel.left
            anchors.bottom:     _panel.bottom
            anchors.margins:    ScreenTools.defaultFontPixelHeight
201
            visible:            QGroundControl.videoManager.hasVideo
202 203 204 205 206 207 208 209 210
            isHidden:           !_isPipVisible
            isDark:             isBackgroundDark
            onActivated: {
                _mainIsMap = !_mainIsMap
                setStates()
            }
            onHideIt: {
                setPipVisibility(!state)
            }
dogmaphobic's avatar
dogmaphobic committed
211
        }
Don Gagne's avatar
Don Gagne committed
212

213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239
        Row {
            id:                     singleMultiSelector
            anchors.topMargin:      ScreenTools.toolbarHeight + _margins
            anchors.rightMargin:    _margins
            anchors.right:          parent.right
            anchors.top:            parent.top
            spacing:                ScreenTools.defaultFontPixelWidth
            z:                      _panel.z + 4
            visible:                QGroundControl.multiVehicleManager.vehicles.count > 1

            ExclusiveGroup { id: multiVehicleSelectorGroup }

            QGCRadioButton {
                id:             singleVehicleView
                exclusiveGroup: multiVehicleSelectorGroup
                text:           qsTr("Single")
                checked:        true
                color:          mapPal.text
            }

            QGCRadioButton {
                exclusiveGroup: multiVehicleSelectorGroup
                text:           qsTr("Multi-Vehicle (WIP)")
                color:          mapPal.text
            }
        }

240
        FlightDisplayViewWidgets {
241 242 243 244 245 246 247 248
            id:                 flightDisplayViewWidgets
            z:                  _panel.z + 4
            height:             ScreenTools.availableHeight
            anchors.left:       parent.left
            anchors.right:      parent.right
            anchors.bottom:     parent.bottom
            qgcView:            root
            isBackgroundDark:   root.isBackgroundDark
249 250 251
            visible:            singleVehicleView.checked
        }

252 253 254 255 256 257 258 259
        // Button to start/stop video recording
        Item {
            z:                  _flightVideoPipControl.z + 1
            anchors.margins:    ScreenTools.defaultFontPixelHeight / 2
            anchors.bottom:     _flightVideo.bottom
            anchors.right:      _flightVideo.right
            height:             ScreenTools.defaultFontPixelHeight * 2
            width:              height
260
            visible:            QGroundControl.videoManager.videoRunning && QGroundControl.videoManager.recordingEnabled
261 262 263 264 265 266
            opacity:            0.75

            Rectangle {
                anchors.top:        parent.top
                anchors.bottom:     parent.bottom
                width:              height
267
                radius:             QGroundControl.videoManager && QGroundControl.videoManager.videoReceiver && QGroundControl.videoManager.videoReceiver.recording ? 0 : height
268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283
                color:              "red"
            }

            QGCColoredImage {
                anchors.top:                parent.top
                anchors.bottom:             parent.bottom
                anchors.horizontalCenter:   parent.horizontalCenter
                width:                      height * 0.625
                sourceSize.width:           width
                source:                     "/qmlimages/CameraIcon.svg"
                fillMode:                   Image.PreserveAspectFit
                color:                      "white"
            }

            MouseArea {
                anchors.fill:   parent
284
                onClicked:      QGroundControl.videoManager.videoReceiver && QGroundControl.videoManager.videoReceiver.recording ? QGroundControl.videoManager.videoReceiver.stopRecording() : QGroundControl.videoManager.videoReceiver.startRecording()
285 286 287
            }
        }

288 289 290 291 292 293 294 295
        MultiVehicleList {
            anchors.margins:    _margins
            anchors.top:        singleMultiSelector.bottom
            anchors.right:      parent.right
            anchors.bottom:     parent.bottom
            width:              ScreenTools.defaultFontPixelWidth * 30
            visible:            !singleVehicleView.checked
            z:                  _panel.z + 4
296
        }
dogmaphobic's avatar
dogmaphobic committed
297

298

299
        //-- Virtual Joystick
300
        Loader {
301
            id:                         virtualJoystickMultiTouch
302 303
            z:                          _panel.z + 5
            width:                      parent.width  - (_flightVideoPipControl.width / 2)
304
            height:                     Math.min(ScreenTools.availableHeight * 0.25, ScreenTools.defaultFontPixelWidth * 16)
305
            visible:                    _virtualJoystick.value
306 307
            anchors.bottom:             _flightVideoPipControl.top
            anchors.bottomMargin:       ScreenTools.defaultFontPixelHeight * 2
308
            anchors.horizontalCenter:   flightDisplayViewWidgets.horizontalCenter
309
            source:                     "qrc:/qml/VirtualJoystick.qml"
310
            active:                     _virtualJoystick.value
Don Gagne's avatar
Don Gagne committed
311 312

            property bool useLightColors: root.isBackgroundDark
313 314

            property Fact _virtualJoystick: QGroundControl.settingsManager.appSettings.virtualJoystick
Don Gagne's avatar
Don Gagne committed
315 316
        }
    }
317
}