FlightDisplayView.qml 23.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


11 12
import QtQuick                  2.3
import QtQuick.Controls         1.2
13
import QtQuick.Controls.Styles  1.4
14
import QtQuick.Dialogs          1.2
15 16 17
import QtLocation               5.3
import QtPositioning            5.3
import QtMultimedia             5.5
18
import QtQuick.Layouts          1.2
19

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

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

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

Don Gagne's avatar
Don Gagne committed
37 38
    property alias  guidedController:   guidedActionsController

39 40
    property bool activeVehicleJoystickEnabled: _activeVehicle ? _activeVehicle.joystickEnabled : false

41 42 43 44 45 46 47 48 49 50 51 52
    property var    _planMasterController:  masterController
    property var    _missionController:     _planMasterController.missionController
    property var    _geoFenceController:    _planMasterController.geoFenceController
    property var    _rallyPointController:  _planMasterController.rallyPointController
    property var    _activeVehicle:         QGroundControl.multiVehicleManager.activeVehicle
    property bool   _mainIsMap:             QGroundControl.videoManager.hasVideo ? QGroundControl.loadBoolGlobalSetting(_mainIsMapKey,  true) : true
    property bool   _isPipVisible:          QGroundControl.videoManager.hasVideo ? QGroundControl.loadBoolGlobalSetting(_PIPVisibleKey, true) : false
    property real   _savedZoomLevel:        0
    property real   _margins:               ScreenTools.defaultFontPixelWidth / 2
    property real   _pipSize:               mainWindow.width * 0.2
    property alias  _guidedController:      guidedActionsController
    property alias  _altitudeSlider:        altitudeSlider
53

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.settingsManager.appSettings.virtualJoystick.value || _activeVehicle.joystickEnabled)) {
95 96 97 98
            px4JoystickSupport.open()
        }
    }

99 100
    PlanElemementMasterController {
        id:                     masterController
101
        Component.onCompleted:  start(false /* editMode */)
102 103
    }

104 105 106
    Connections {
        target:                 _missionController
        onResumeMissionReady:   guidedActionsController.confirmAction(guidedActionsController.actionResumeMissionReady)
107 108
    }

109 110
    MessageDialog {
        id:     px4JoystickSupport
111 112 113
        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.")
114 115 116
    }

    Connections {
117
        target:                 QGroundControl.multiVehicleManager
118 119 120 121
        onActiveVehicleChanged: px4JoystickCheck()
    }

    Connections {
122 123
        target:         QGroundControl.settingsManager.appSettings.virtualJoystick
        onValueChanged: px4JoystickCheck()
124 125 126 127
    }

    onActiveVehicleJoystickEnabledChanged: px4JoystickCheck()

128 129
    Component.onCompleted: {
        setStates()
130
        px4JoystickCheck()
131 132 133
        if(QGroundControl.corePlugin.options.flyViewOverlay.toString().length) {
            flyViewOverlay.source = QGroundControl.corePlugin.options.flyViewOverlay
        }
134
    }
dogmaphobic's avatar
dogmaphobic committed
135

136 137 138 139 140 141 142 143 144 145 146 147 148 149
    // The following code is used to track vehicle states such that we prompt to remove mission from vehicle when mission completes

    property bool vehicleArmed:                 _activeVehicle ? _activeVehicle.armed : true // true here prevents pop up from showing during shutdown
    property bool vehicleWasArmed:              false
    property bool vehicleInMissionFlightMode:   _activeVehicle ? (_activeVehicle.flightMode === _activeVehicle.missionFlightMode) : false
    property bool promptForMissionRemove:       false

    onVehicleArmedChanged: {
        if (vehicleArmed) {
            if (!promptForMissionRemove) {
                promptForMissionRemove = vehicleInMissionFlightMode
                vehicleWasArmed = true
            }
        } else {
150
            if (promptForMissionRemove && (_missionController.containsItems || _geoFenceController.containsItems || _rallyPointController.containsItems)) {
151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169
                root.showDialog(removeMissionDialogComponent, qsTr("Flight complete"), showDialogDefaultWidth, StandardButton.No | StandardButton.Yes)
            }
            promptForMissionRemove = false
        }
    }

    onVehicleInMissionFlightModeChanged: {
        if (!promptForMissionRemove && vehicleArmed) {
            promptForMissionRemove = true
        }
    }

    Component {
        id: removeMissionDialogComponent

        QGCViewMessage {
            message: qsTr("Do you want to remove the mission from the vehicle?")

            function accept() {
170 171 172
                _missionController.removeAllFromVehicle()
                _geoFenceController.removeAllFromVehicle()
                _rallyPointController.removeAllFromVehicle()
173 174 175 176 177 178
                hideDialog()

            }
        }
    }

179 180
    QGCMapPalette { id: mapPal; lightColors: _mainIsMap ? _flightMap.isSatelliteMap : true }

181 182 183 184 185 186 187 188 189 190 191 192 193
    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
194 195
            width:          _mainIsMap ? _panel.width  : _pipSize
            height:         _mainIsMap ? _panel.height : _pipSize * (9/16)
196 197 198 199 200 201 202 203 204 205 206 207 208 209
            states: [
                State {
                    name:   "pipMode"
                    PropertyChanges {
                        target:             _flightMapContainer
                        anchors.margins:    ScreenTools.defaultFontPixelHeight
                    }
                },
                State {
                    name:   "fullMode"
                    PropertyChanges {
                        target:             _flightMapContainer
                        anchors.margins:    0
                    }
210
                }
211 212
            ]
            FlightDisplayViewMap {
213 214
                id:                         _flightMap
                anchors.fill:               parent
215
                planMasterController:       masterController
216 217 218 219 220
                guidedActionsController:    _guidedController
                flightWidgets:              flightDisplayViewWidgets
                rightPanelWidth:            ScreenTools.defaultFontPixelHeight * 9
                qgcView:                    root
                scaleState:                 (_mainIsMap && flyViewOverlay.item) ? (flyViewOverlay.item.scaleState ? flyViewOverlay.item.scaleState : "bottomMode") : "bottomMode"
221
            }
222
        }
223

224
        //-- Video View
225
        Item {
226 227
            id:             _flightVideo
            z:              _mainIsMap ? _panel.z + 2 : _panel.z + 1
228 229
            width:          !_mainIsMap ? _panel.width  : _pipSize
            height:         !_mainIsMap ? _panel.height : _pipSize * (9/16)
230 231
            anchors.left:   _panel.left
            anchors.bottom: _panel.bottom
232
            visible:        QGroundControl.videoManager.hasVideo && (!_mainIsMap || _isPipVisible)
233 234 235 236 237 238 239 240 241 242 243 244 245 246
            states: [
                State {
                    name:   "pipMode"
                    PropertyChanges {
                        target: _flightVideo
                        anchors.margins:    ScreenTools.defaultFontPixelHeight
                    }
                },
                State {
                    name:   "fullMode"
                    PropertyChanges {
                        target: _flightVideo
                        anchors.margins:    0
                    }
247
                }
248
            ]
249
            //-- Video Streaming
250 251 252 253 254
            FlightDisplayViewVideo {
                anchors.fill:   parent
                visible:        QGroundControl.videoManager.isGStreamer
            }
            //-- UVC Video (USB Camera or Video Device)
255 256
            Loader {
                id:             cameraLoader
257 258
                anchors.fill:   parent
                visible:        !QGroundControl.videoManager.isGStreamer
259
                source:         QGroundControl.videoManager.uvcEnabled ? "qrc:/qml/FlightDisplayViewUVC.qml" : "qrc:/qml/FlightDisplayViewDummy.qml"
260
            }
dogmaphobic's avatar
dogmaphobic committed
261
        }
262 263 264 265

        QGCPipable {
            id:                 _flightVideoPipControl
            z:                  _flightVideo.z + 3
266 267
            width:              _pipSize
            height:             _pipSize * (9/16)
268 269 270
            anchors.left:       _panel.left
            anchors.bottom:     _panel.bottom
            anchors.margins:    ScreenTools.defaultFontPixelHeight
271
            visible:            QGroundControl.videoManager.hasVideo
272 273 274 275 276 277 278 279 280
            isHidden:           !_isPipVisible
            isDark:             isBackgroundDark
            onActivated: {
                _mainIsMap = !_mainIsMap
                setStates()
            }
            onHideIt: {
                setPipVisibility(!state)
            }
dogmaphobic's avatar
dogmaphobic committed
281
        }
Don Gagne's avatar
Don Gagne committed
282

283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309
        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
            }
        }

310
        FlightDisplayViewWidgets {
311 312 313 314
            id:                 flightDisplayViewWidgets
            z:                  _panel.z + 4
            height:             ScreenTools.availableHeight
            anchors.left:       parent.left
315
            anchors.right:      altitudeSlider.visible ? altitudeSlider.left : parent.right
316 317
            anchors.bottom:     parent.bottom
            qgcView:            root
318
            useLightColors:     isBackgroundDark
319
            missionController:  _missionController
320 321 322
            visible:            singleVehicleView.checked
        }

323 324 325 326 327 328 329 330 331
        //-------------------------------------------------------------------------
        //-- Loader helper for plugins to overlay elements over the fly view
        Loader {
            id:                 flyViewOverlay
            z:                  flightDisplayViewWidgets.z + 1
            height:             ScreenTools.availableHeight
            anchors.left:       parent.left
            anchors.right:      altitudeSlider.visible ? altitudeSlider.left : parent.right
            anchors.bottom:     parent.bottom
332 333

            property var qgcView: root
334 335
        }

336 337 338 339 340 341 342 343
        // 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
344
            visible:            QGroundControl.videoManager.videoRunning && QGroundControl.videoManager.recordingEnabled
345 346 347 348 349 350
            opacity:            0.75

            Rectangle {
                anchors.top:        parent.top
                anchors.bottom:     parent.bottom
                width:              height
351
                radius:             QGroundControl.videoManager && QGroundControl.videoManager.videoReceiver && QGroundControl.videoManager.videoReceiver.recording ? 0 : height
352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367
                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
368
                onClicked:      QGroundControl.videoManager.videoReceiver && QGroundControl.videoManager.videoReceiver.recording ? QGroundControl.videoManager.videoReceiver.stopRecording() : QGroundControl.videoManager.videoReceiver.startRecording()
369 370 371
            }
        }

372 373 374 375 376 377 378 379
        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
380
        }
dogmaphobic's avatar
dogmaphobic committed
381

382

383
        //-- Virtual Joystick
384
        Loader {
385
            id:                         virtualJoystickMultiTouch
386 387
            z:                          _panel.z + 5
            width:                      parent.width  - (_flightVideoPipControl.width / 2)
388
            height:                     Math.min(ScreenTools.availableHeight * 0.25, ScreenTools.defaultFontPixelWidth * 16)
389
            visible:                    _virtualJoystick ? _virtualJoystick.value : false
390 391
            anchors.bottom:             _flightVideoPipControl.top
            anchors.bottomMargin:       ScreenTools.defaultFontPixelHeight * 2
392
            anchors.horizontalCenter:   flightDisplayViewWidgets.horizontalCenter
393
            source:                     "qrc:/qml/VirtualJoystick.qml"
394
            active:                     _virtualJoystick ? _virtualJoystick.value : false
Don Gagne's avatar
Don Gagne committed
395

396
            property bool useLightColors: isBackgroundDark
397 398

            property Fact _virtualJoystick: QGroundControl.settingsManager.appSettings.virtualJoystick
Don Gagne's avatar
Don Gagne committed
399
        }
400 401

        ToolStrip {
402
            visible:            _activeVehicle ? _activeVehicle.guidedModeSupported : true
403 404 405 406 407 408 409 410
            id:                 toolStrip
            anchors.leftMargin: ScreenTools.defaultFontPixelWidth
            anchors.left:       _panel.left
            anchors.topMargin:  ScreenTools.toolbarHeight + _margins
            anchors.top:        _panel.top
            z:                  _panel.z + 4
            title:              qsTr("Fly")
            maxHeight:          (_flightVideo.visible ? _flightVideo.y : parent.height) - toolStrip.y
411 412
            buttonVisible:      [ _guidedController.showTakeoff || !_guidedController.showLand, _guidedController.showLand && !_guidedController.showTakeoff, true, true, true, _guidedController.smartShotsAvailable ]
            buttonEnabled:      [ _guidedController.showTakeoff, _guidedController.showLand, _guidedController.showRTL, _guidedController.showPause, _anyActionAvailable, _anySmartShotAvailable ]
413

414
            property bool _anyActionAvailable: _guidedController.showStartMission || _guidedController.showResumeMission || _guidedController.showChangeAlt || _guidedController.showLandAbort
415
            property bool _anySmartShotAvailable: _guidedController.showOrbit
416 417
            property var _actionModel: [
                {
418 419 420 421
                    title:      _guidedController.startMissionTitle,
                    text:       _guidedController.startMissionMessage,
                    action:     _guidedController.actionStartMission,
                    visible:    _guidedController.showStartMission
422 423
                },
                {
424 425 426 427
                    title:      _guidedController.resumeMissionTitle,
                    text:       _guidedController.resumeMissionMessage,
                    action:     _guidedController.actionResumeMission,
                    visible:    _guidedController.showResumeMission
428 429
                },
                {
430 431 432 433
                    title:      _guidedController.changeAltTitle,
                    text:       _guidedController.changeAltMessage,
                    action:     _guidedController.actionChangeAlt,
                    visible:    _guidedController.showChangeAlt
434 435
                },
                {
436 437 438 439
                    title:      _guidedController.landAbortTitle,
                    text:       _guidedController.landAbortMessage,
                    action:     _guidedController.actionLandAbort,
                    visible:    _guidedController.showLandAbort
440 441 442 443
                }
            ]
            property var _smartShotModel: [
                {
444 445 446 447
                    title:      _guidedController.orbitTitle,
                    text:       _guidedController.orbitMessage,
                    action:     _guidedController.actionOrbit,
                    visible:    _guidedController.showOrbit
448 449 450 451 452
                }
            ]

            model: [
                {
453
                    name:       _guidedController.takeoffTitle,
454
                    iconSource: "/res/takeoff.svg",
455
                    action:     _guidedController.actionTakeoff
456 457
                },
                {
458
                    name:       _guidedController.landTitle,
459
                    iconSource: "/res/land.svg",
460
                    action:     _guidedController.actionLand
461 462
                },
                {
463
                    name:       _guidedController.rtlTitle,
464
                    iconSource: "/res/rtl.svg",
465
                    action:     _guidedController.actionRTL
466 467
                },
                {
468
                    name:       _guidedController.pauseTitle,
Gus Grubba's avatar
Gus Grubba committed
469
                    iconSource: "/res/pause-mission.svg",
470
                    action:     _guidedController.actionPause
471 472 473
                },
                {
                    name:       qsTr("Action"),
Gus Grubba's avatar
Gus Grubba committed
474
                    iconSource: "/res/action.svg",
475 476 477 478 479 480 481 482 483 484 485 486 487
                    action:     -1
                },
                /*
                  No firmware support any smart shots yet
                {
                    name:       qsTr("Smart"),
                    iconSource: "/qmlimages/MapCenter.svg",
                    action:     -1
                },
                */
            ]

            onClicked: {
488 489
                //-- Dismiss any other dialog
                rootLoader.sourceComponent  = null
490
                guidedActionConfirm.visible = false
491 492
                guidedActionList.visible    = false
                altitudeSlider.visible      = false
493 494 495
                var action = model[index].action
                if (action === -1) {
                    if (index == 4) {
496
                        guidedActionList.model   = _actionModel
497 498
                        guidedActionList.visible = true
                    } else if (index == 5) {
499
                        guidedActionList.model   = _smartShotModel
500 501 502
                        guidedActionList.visible = true
                    }
                } else {
503
                    _guidedController.confirmAction(action)
504 505 506 507 508
                }
            }
        }

        GuidedActionsController {
509
            id:                 guidedActionsController
510
            missionController:  _missionController
511
            confirmDialog:      guidedActionConfirm
512 513
            z:                  _flightVideoPipControl.z + 1

514
            onShowStartMissionChanged: {
515
                if (showStartMission && !showResumeMission) {
516 517 518 519
                    confirmAction(actionStartMission)
                }
            }

520 521 522 523 524 525
            onShowContinueMissionChanged: {
                if (showContinueMission) {
                    confirmAction(actionContinueMission)
                }
            }

526 527 528 529 530
            onShowResumeMissionChanged: {
                if (showResumeMission) {
                    confirmAction(actionResumeMission)
                }
            }
531 532
        }

533
        GuidedActionConfirm {
534 535 536 537
            id:                         guidedActionConfirm
            anchors.margins:            _margins
            anchors.bottom:             parent.bottom
            anchors.horizontalCenter:   parent.horizontalCenter
538 539
            guidedController:           _guidedController
            altitudeSlider:             _altitudeSlider
540 541
        }

542
        GuidedActionList {
543 544 545 546
            id:                         guidedActionList
            anchors.margins:            _margins
            anchors.bottom:             parent.bottom
            anchors.horizontalCenter:   parent.horizontalCenter
547 548
            guidedController:           _guidedController
            altitudeSlider:             _altitudeSlider
549 550 551
        }

        //-- Altitude slider
DonLakeFlyer's avatar
DonLakeFlyer committed
552
        GuidedAltitudeSlider {
553 554 555 556 557 558
            id:                 altitudeSlider
            anchors.margins:    _margins
            anchors.right:      parent.right
            anchors.topMargin:  ScreenTools.toolbarHeight + _margins
            anchors.top:        parent.top
            anchors.bottom:     parent.bottom
559
            z:                  _guidedController.z
560 561 562 563 564
            radius:             ScreenTools.defaultFontPixelWidth / 2
            width:              ScreenTools.defaultFontPixelWidth * 10
            color:              qgcPal.window
            visible:            false
        }
Don Gagne's avatar
Don Gagne committed
565
    }
566
}