FlightDisplayView.qml 24 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
    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
50
    property real   _pipSize:               flightView.width * 0.2
51 52
    property alias  _guidedController:      guidedActionsController
    property alias  _altitudeSlider:        altitudeSlider
53

54

55 56
    readonly property var       _dynamicCameras:        _activeVehicle ? _activeVehicle.dynamicCameras : null
    readonly property bool      _isCamera:              _dynamicCameras ? _dynamicCameras.cameras.count > 0 : false
Don Gagne's avatar
Don Gagne committed
57 58 59 60 61 62 63 64 65 66 67 68
    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"

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

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

95
    PlanMasterController {
96
        id:                     masterController
97
        Component.onCompleted:  start(false /* editMode */)
98 99
    }

100
    Connections {
101 102 103
        target:                     _missionController
        onResumeMissionReady:       guidedActionsController.confirmAction(guidedActionsController.actionResumeMissionReady)
        onResumeMissionUploadFail:  guidedActionsController.confirmAction(guidedActionsController.actionResumeMissionUploadFail)
104 105
    }

106 107
    Component.onCompleted: {
        setStates()
108 109 110
        if(QGroundControl.corePlugin.options.flyViewOverlay.toString().length) {
            flyViewOverlay.source = QGroundControl.corePlugin.options.flyViewOverlay
        }
111
    }
dogmaphobic's avatar
dogmaphobic committed
112

113 114 115 116 117 118 119 120 121 122 123 124 125 126
    // 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 {
127
            if (promptForMissionRemove && (_missionController.containsItems || _geoFenceController.containsItems || _rallyPointController.containsItems)) {
128 129 130 131
                // ArduPilot has a strange bug which prevents mission clear from working at certain times, so we can't show this dialog
                if (!_activeVehicle.apmFirmware) {
                    root.showDialog(missionCompleteDialogComponent, qsTr("Flight Plan complete"), showDialogDefaultWidth, StandardButton.Close)
                }
132 133 134 135 136 137 138 139 140 141 142 143
            }
            promptForMissionRemove = false
        }
    }

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

    Component {
144 145 146 147 148 149 150
        id: missionCompleteDialogComponent

        QGCViewDialog {
            QGCFlickable {
                anchors.fill:   parent
                contentHeight:  column.height

151
                ColumnLayout {
152 153 154 155 156 157 158
                    id:                 column
                    anchors.margins:    _margins
                    anchors.left:       parent.left
                    anchors.right:      parent.right
                    spacing:            ScreenTools.defaultFontPixelHeight

                    QGCLabel {
159 160 161 162
                        Layout.fillWidth:       true
                        text:                   qsTr("%1 Images Taken").arg(_activeVehicle.cameraTriggerPoints.count)
                        horizontalAlignment:    Text.AlignHCenter
                        visible:                _activeVehicle.cameraTriggerPoints.count != 0
163 164 165
                    }

                    QGCButton {
166 167
                        Layout.fillWidth:   true
                        text:               qsTr("Remove plan from vehicle")
168 169 170 171 172
                        onClicked: {
                            _planMasterController.removeAllFromVehicle()
                            hideDialog()
                        }
                    }
173 174 175 176 177 178 179

                    QGCButton {
                        Layout.fillWidth:   true
                        text:               qsTr("Leave plan on vehicle")
                        anchors.horizontalCenter:   parent.horizontalCenter
                        onClicked:                  hideDialog()
                    }
180
                }
181 182 183 184
            }
        }
    }

185 186
    QGCMapPalette { id: mapPal; lightColors: _mainIsMap ? _flightMap.isSatelliteMap : true }

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

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

        QGCPipable {
            id:                 _flightVideoPipControl
            z:                  _flightVideo.z + 3
273 274
            width:              _pipSize
            height:             _pipSize * (9/16)
275 276 277
            anchors.left:       _panel.left
            anchors.bottom:     _panel.bottom
            anchors.margins:    ScreenTools.defaultFontPixelHeight
278
            visible:            QGroundControl.videoManager.hasVideo && !QGroundControl.videoManager.fullScreen
279 280 281 282 283 284 285 286 287
            isHidden:           !_isPipVisible
            isDark:             isBackgroundDark
            onActivated: {
                _mainIsMap = !_mainIsMap
                setStates()
            }
            onHideIt: {
                setPipVisibility(!state)
            }
288 289
            onNewWidth: {
                _pipSize = newWidth
Jacob Walser's avatar
Jacob Walser committed
290
            }
dogmaphobic's avatar
dogmaphobic committed
291
        }
Don Gagne's avatar
Don Gagne committed
292

293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314
        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
315
                text:           qsTr("Multi-Vehicle")
316 317 318 319
                color:          mapPal.text
            }
        }

320
        FlightDisplayViewWidgets {
321 322
            id:                 flightDisplayViewWidgets
            z:                  _panel.z + 4
323
            height:             ScreenTools.availableHeight - (singleMultiSelector.visible ? singleMultiSelector.height + _margins : 0)
324
            anchors.left:       parent.left
325
            anchors.right:      altitudeSlider.visible ? altitudeSlider.left : parent.right
326 327
            anchors.bottom:     parent.bottom
            qgcView:            root
328
            useLightColors:     isBackgroundDark
329
            missionController:  _missionController
330
            visible:            singleVehicleView.checked && !QGroundControl.videoManager.fullScreen
331 332
        }

333 334 335 336 337
        //-------------------------------------------------------------------------
        //-- Loader helper for plugins to overlay elements over the fly view
        Loader {
            id:                 flyViewOverlay
            z:                  flightDisplayViewWidgets.z + 1
338
            visible:            !QGroundControl.videoManager.fullScreen
339 340 341 342
            height:             ScreenTools.availableHeight
            anchors.left:       parent.left
            anchors.right:      altitudeSlider.visible ? altitudeSlider.left : parent.right
            anchors.bottom:     parent.bottom
343 344

            property var qgcView: root
345 346
        }

347 348 349 350 351 352
        MultiVehicleList {
            anchors.margins:    _margins
            anchors.top:        singleMultiSelector.bottom
            anchors.right:      parent.right
            anchors.bottom:     parent.bottom
            width:              ScreenTools.defaultFontPixelWidth * 30
353
            visible:            !singleVehicleView.checked && !QGroundControl.videoManager.fullScreen
354
            z:                  _panel.z + 4
355
        }
dogmaphobic's avatar
dogmaphobic committed
356

357
        //-- Virtual Joystick
358
        Loader {
359
            id:                         virtualJoystickMultiTouch
360 361
            z:                          _panel.z + 5
            width:                      parent.width  - (_flightVideoPipControl.width / 2)
362
            height:                     Math.min(ScreenTools.availableHeight * 0.25, ScreenTools.defaultFontPixelWidth * 16)
363
            visible:                    (_virtualJoystick ? _virtualJoystick.value : false) && !QGroundControl.videoManager.fullScreen
364 365
            anchors.bottom:             _flightVideoPipControl.top
            anchors.bottomMargin:       ScreenTools.defaultFontPixelHeight * 2
366
            anchors.horizontalCenter:   flightDisplayViewWidgets.horizontalCenter
367
            source:                     "qrc:/qml/VirtualJoystick.qml"
368
            active:                     _virtualJoystick ? _virtualJoystick.value : false
Don Gagne's avatar
Don Gagne committed
369

370
            property bool useLightColors: isBackgroundDark
371 372

            property Fact _virtualJoystick: QGroundControl.settingsManager.appSettings.virtualJoystick
Don Gagne's avatar
Don Gagne committed
373
        }
374 375

        ToolStrip {
376
            visible:            (_activeVehicle ? _activeVehicle.guidedModeSupported : true) && !QGroundControl.videoManager.fullScreen
377 378 379
            id:                 toolStrip
            anchors.leftMargin: ScreenTools.defaultFontPixelWidth
            anchors.left:       _panel.left
380
            anchors.topMargin:  ScreenTools.toolbarHeight + (_margins * 2)
381 382 383 384
            anchors.top:        _panel.top
            z:                  _panel.z + 4
            title:              qsTr("Fly")
            maxHeight:          (_flightVideo.visible ? _flightVideo.y : parent.height) - toolStrip.y
385 386
            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 ]
387

388
            property bool _anyActionAvailable: _guidedController.showStartMission || _guidedController.showResumeMission || _guidedController.showChangeAlt || _guidedController.showLandAbort
389
            property bool _anySmartShotAvailable: _guidedController.showOrbit
390 391
            property var _actionModel: [
                {
392 393 394 395
                    title:      _guidedController.startMissionTitle,
                    text:       _guidedController.startMissionMessage,
                    action:     _guidedController.actionStartMission,
                    visible:    _guidedController.showStartMission
396
                },
Don Gagne's avatar
Don Gagne committed
397 398 399 400 401 402
                {
                    title:      _guidedController.continueMissionTitle,
                    text:       _guidedController.continueMissionMessage,
                    action:     _guidedController.actionContinueMission,
                    visible:    _guidedController.showContinueMission
                },
403
                {
404 405 406 407
                    title:      _guidedController.resumeMissionTitle,
                    text:       _guidedController.resumeMissionMessage,
                    action:     _guidedController.actionResumeMission,
                    visible:    _guidedController.showResumeMission
408 409
                },
                {
410 411 412 413
                    title:      _guidedController.changeAltTitle,
                    text:       _guidedController.changeAltMessage,
                    action:     _guidedController.actionChangeAlt,
                    visible:    _guidedController.showChangeAlt
414 415
                },
                {
416 417 418 419
                    title:      _guidedController.landAbortTitle,
                    text:       _guidedController.landAbortMessage,
                    action:     _guidedController.actionLandAbort,
                    visible:    _guidedController.showLandAbort
420 421 422 423
                }
            ]
            property var _smartShotModel: [
                {
424 425 426 427
                    title:      _guidedController.orbitTitle,
                    text:       _guidedController.orbitMessage,
                    action:     _guidedController.actionOrbit,
                    visible:    _guidedController.showOrbit
428 429 430 431 432
                }
            ]

            model: [
                {
433
                    name:       _guidedController.takeoffTitle,
434
                    iconSource: "/res/takeoff.svg",
435
                    action:     _guidedController.actionTakeoff
436 437
                },
                {
438
                    name:       _guidedController.landTitle,
439
                    iconSource: "/res/land.svg",
440
                    action:     _guidedController.actionLand
441 442
                },
                {
443
                    name:       _guidedController.rtlTitle,
444
                    iconSource: "/res/rtl.svg",
445
                    action:     _guidedController.actionRTL
446 447
                },
                {
448
                    name:       _guidedController.pauseTitle,
Gus Grubba's avatar
Gus Grubba committed
449
                    iconSource: "/res/pause-mission.svg",
450
                    action:     _guidedController.actionPause
451 452 453
                },
                {
                    name:       qsTr("Action"),
Gus Grubba's avatar
Gus Grubba committed
454
                    iconSource: "/res/action.svg",
455 456 457 458 459 460 461 462 463 464 465 466 467
                    action:     -1
                },
                /*
                  No firmware support any smart shots yet
                {
                    name:       qsTr("Smart"),
                    iconSource: "/qmlimages/MapCenter.svg",
                    action:     -1
                },
                */
            ]

            onClicked: {
468
                guidedActionsController.closeAll()
469 470 471
                var action = model[index].action
                if (action === -1) {
                    if (index == 4) {
472
                        guidedActionList.model   = _actionModel
473 474
                        guidedActionList.visible = true
                    } else if (index == 5) {
475
                        guidedActionList.model   = _smartShotModel
476 477 478
                        guidedActionList.visible = true
                    }
                } else {
479
                    _guidedController.confirmAction(action)
480 481 482 483 484
                }
            }
        }

        GuidedActionsController {
485
            id:                 guidedActionsController
486
            missionController:  _missionController
487
            confirmDialog:      guidedActionConfirm
DonLakeFlyer's avatar
DonLakeFlyer committed
488
            actionList:         guidedActionList
Don Gagne's avatar
Don Gagne committed
489
            altitudeSlider:     _altitudeSlider
490 491
            z:                  _flightVideoPipControl.z + 1

492
            onShowStartMissionChanged: {
493
                if (showStartMission && !showResumeMission) {
494 495 496 497
                    confirmAction(actionStartMission)
                }
            }

498 499 500 501 502 503
            onShowContinueMissionChanged: {
                if (showContinueMission) {
                    confirmAction(actionContinueMission)
                }
            }

504 505 506 507 508
            onShowResumeMissionChanged: {
                if (showResumeMission) {
                    confirmAction(actionResumeMission)
                }
            }
509 510 511 512 513 514

            onShowLandAbortChanged: {
                if (showLandAbort) {
                    confirmAction(actionLandAbort)
                }
            }
515 516 517

            /// Close all dialogs
            function closeAll() {
518
                mainWindow.enableToolbar()
519 520 521 522 523
                rootLoader.sourceComponent  = null
                guidedActionConfirm.visible = false
                guidedActionList.visible    = false
                altitudeSlider.visible      = false
            }
524 525
        }

526
        GuidedActionConfirm {
527 528 529 530
            id:                         guidedActionConfirm
            anchors.margins:            _margins
            anchors.bottom:             parent.bottom
            anchors.horizontalCenter:   parent.horizontalCenter
531 532
            guidedController:           _guidedController
            altitudeSlider:             _altitudeSlider
533 534
        }

535
        GuidedActionList {
536 537 538 539
            id:                         guidedActionList
            anchors.margins:            _margins
            anchors.bottom:             parent.bottom
            anchors.horizontalCenter:   parent.horizontalCenter
540
            guidedController:           _guidedController
541 542 543
        }

        //-- Altitude slider
DonLakeFlyer's avatar
DonLakeFlyer committed
544
        GuidedAltitudeSlider {
545 546 547 548 549 550
            id:                 altitudeSlider
            anchors.margins:    _margins
            anchors.right:      parent.right
            anchors.topMargin:  ScreenTools.toolbarHeight + _margins
            anchors.top:        parent.top
            anchors.bottom:     parent.bottom
551
            z:                  _guidedController.z
552 553 554 555 556
            radius:             ScreenTools.defaultFontPixelWidth / 2
            width:              ScreenTools.defaultFontPixelWidth * 10
            color:              qgcPal.window
            visible:            false
        }
Don Gagne's avatar
Don Gagne committed
557
    }
558
}