FlightDisplayView.qml 33.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
import QtLocation               5.3
import QtPositioning            5.3
17
import QtQuick.Layouts          1.2
Patrick José Pereira's avatar
Patrick José Pereira committed
18
import QtQuick.Window           2.2
19
import QtQml.Models             2.1
20

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

/// Flight Display View
33
Item {
34

Gus Grubba's avatar
Gus Grubba committed
35
    PlanMasterController {
Gus Grubba's avatar
Gus Grubba committed
36 37 38 39 40
        id: _planController
        Component.onCompleted: {
            start(true /* flyView */)
            mainWindow.planMasterControllerView = _planController
        }
Gus Grubba's avatar
Gus Grubba committed
41 42
    }

43 44
    property alias  guidedController:               guidedActionsController
    property bool   activeVehicleJoystickEnabled:   activeVehicle ? activeVehicle.joystickEnabled : false
45

Gus Grubba's avatar
Gus Grubba committed
46 47 48
    property var    _missionController:     _planController.missionController
    property var    _geoFenceController:    _planController.geoFenceController
    property var    _rallyPointController:  _planController.rallyPointController
49 50
    property bool   _mainIsMap:             QGroundControl.videoManager.hasVideo ? QGroundControl.loadBoolGlobalSetting(_mainIsMapKey,  true) : true
    property bool   _isPipVisible:          QGroundControl.videoManager.hasVideo ? QGroundControl.loadBoolGlobalSetting(_PIPVisibleKey, true) : false
51
    property bool   _useChecklist:          QGroundControl.settingsManager.appSettings.useChecklist.rawValue
52 53
    property real   _savedZoomLevel:        0
    property real   _margins:               ScreenTools.defaultFontPixelWidth / 2
54
    property real   _pipSize:               mainWindow.width * 0.2
55 56
    property alias  _guidedController:      guidedActionsController
    property alias  _altitudeSlider:        altitudeSlider
57

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

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

93 94 95
    function setPipVisibility(state) {
        _isPipVisible = state;
        QGroundControl.saveBoolGlobalSetting(_PIPVisibleKey, state)
96 97
    }

Gus Grubba's avatar
Gus Grubba committed
98 99 100 101 102 103 104 105 106 107 108 109 110 111
    function isInstrumentRight() {
        if(QGroundControl.corePlugin.options.instrumentWidget) {
            if(QGroundControl.corePlugin.options.instrumentWidget.source.toString().length) {
                switch(QGroundControl.corePlugin.options.instrumentWidget.widgetPosition) {
                case CustomInstrumentWidget.POS_TOP_LEFT:
                case CustomInstrumentWidget.POS_BOTTOM_LEFT:
                case CustomInstrumentWidget.POS_CENTER_LEFT:
                    return false;
                }
            }
        }
        return true;
    }

112
    BuiltInPreFlightCheckModel {
113
        id: preFlightCheckModel
114 115
    }

116
    Connections {
117 118
        target:                     _missionController
        onResumeMissionUploadFail:  guidedActionsController.confirmAction(guidedActionsController.actionResumeMissionUploadFail)
119 120
    }

121 122 123 124 125 126 127 128 129 130 131 132 133 134
    Connections {
        target:                 mainWindow
        onArmVehicle:           guidedController.confirmAction(guidedController.actionArm)
        onDisarmVehicle: {
            if (guidedController.showEmergenyStop) {
                guidedController.confirmAction(guidedController.actionEmergencyStop)
            } else {
                guidedController.confirmAction(guidedController.actionDisarm)
            }
        }
        onVtolTransitionToFwdFlight:    guidedController.confirmAction(guidedController.actionVtolTransitionToFwdFlight)
        onVtolTransitionToMRFlight:     guidedController.confirmAction(guidedController.actionVtolTransitionToMRFlight)
    }

135 136
    Component.onCompleted: {
        setStates()
137 138 139
        if(QGroundControl.corePlugin.options.flyViewOverlay.toString().length) {
            flyViewOverlay.source = QGroundControl.corePlugin.options.flyViewOverlay
        }
140
    }
dogmaphobic's avatar
dogmaphobic committed
141

142 143
    // The following code is used to track vehicle states such that we prompt to remove mission from vehicle when mission completes

Gus Grubba's avatar
Gus Grubba committed
144
    property bool vehicleArmed:                 activeVehicle ? activeVehicle.armed : true // true here prevents pop up from showing during shutdown
145
    property bool vehicleWasArmed:              false
Gus Grubba's avatar
Gus Grubba committed
146
    property bool vehicleInMissionFlightMode:   activeVehicle ? (activeVehicle.flightMode === activeVehicle.missionFlightMode) : false
147 148 149 150 151 152 153 154 155
    property bool promptForMissionRemove:       false

    onVehicleArmedChanged: {
        if (vehicleArmed) {
            if (!promptForMissionRemove) {
                promptForMissionRemove = vehicleInMissionFlightMode
                vehicleWasArmed = true
            }
        } else {
156
            if (promptForMissionRemove && (_missionController.containsItems || _geoFenceController.containsItems || _rallyPointController.containsItems)) {
157
                // ArduPilot has a strange bug which prevents mission clear from working at certain times, so we can't show this dialog
Gus Grubba's avatar
Gus Grubba committed
158
                if (!activeVehicle.apmFirmware) {
159
                    mainWindow.showDialog(missionCompleteDialogComponent, qsTr("Flight Plan complete"), mainWindow.showDialogDefaultWidth, StandardButton.Close)
160
                }
161 162 163 164 165 166 167 168 169 170 171 172
            }
            promptForMissionRemove = false
        }
    }

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

    Component {
173 174 175
        id: missionCompleteDialogComponent

        QGCViewDialog {
Gus Grubba's avatar
Gus Grubba committed
176
            property var activeVehicleCopy: activeVehicle
177 178 179 180 181
            onActiveVehicleCopyChanged:
                if (!activeVehicleCopy) {
                    hideDialog()
                }

182 183 184 185
            QGCFlickable {
                anchors.fill:   parent
                contentHeight:  column.height

186
                ColumnLayout {
187 188 189 190 191
                    id:                 column
                    anchors.margins:    _margins
                    anchors.left:       parent.left
                    anchors.right:      parent.right

192
                    ColumnLayout {
193
                        Layout.fillWidth:   true
194
                        spacing:            ScreenTools.defaultFontPixelHeight
Gus Grubba's avatar
Gus Grubba committed
195
                        visible:            !activeVehicle.connectionLost || !_guidedController.showResumeMission
196 197 198

                        QGCLabel {
                            Layout.fillWidth:       true
Gus Grubba's avatar
Gus Grubba committed
199
                            text:                   qsTr("%1 Images Taken").arg(activeVehicle.cameraTriggerPoints.count)
200
                            horizontalAlignment:    Text.AlignHCenter
Gus Grubba's avatar
Gus Grubba committed
201
                            visible:                activeVehicle.cameraTriggerPoints.count !== 0
202
                        }
203

204 205 206 207
                        QGCButton {
                            Layout.fillWidth:   true
                            text:               qsTr("Remove plan from vehicle")
                            onClicked: {
Gus Grubba's avatar
Gus Grubba committed
208
                                _planController.removeAllFromVehicle()
209 210 211
                                hideDialog()
                            }
                        }
Don Gagne's avatar
Don Gagne committed
212

213 214 215 216 217 218
                        QGCButton {
                            Layout.fillWidth:   true
                            Layout.alignment:   Qt.AlignHCenter
                            text:               qsTr("Leave plan on vehicle")
                            onClicked:          hideDialog()
                        }
Don Gagne's avatar
Don Gagne committed
219

220 221 222 223 224
                        Rectangle {
                            Layout.fillWidth:   true
                            color:              qgcPal.text
                            height:             1
                        }
Don Gagne's avatar
Don Gagne committed
225

226 227 228 229 230 231 232 233 234 235
                        QGCButton {
                            Layout.fillWidth:   true
                            Layout.alignment:   Qt.AlignHCenter
                            text:               qsTr("Resume Mission From Waypoint %1").arg(_guidedController._resumeMissionIndex)
                            visible:            _guidedController.showResumeMission

                            onClicked: {
                                guidedController.executeAction(_guidedController.actionResumeMission, null, null)
                                hideDialog()
                            }
Don Gagne's avatar
Don Gagne committed
236 237
                        }

238 239 240 241 242 243 244 245 246 247 248 249 250 251
                        QGCLabel {
                            Layout.fillWidth:   true
                            wrapMode:           Text.WordWrap
                            text:               qsTr("Resume Mission will rebuild the current mission from the last flown waypoint and upload it to the vehicle for the next flight.")
                            visible:            _guidedController.showResumeMission
                        }

                        QGCLabel {
                            Layout.fillWidth:   true
                            wrapMode:           Text.WordWrap
                            color:              qgcPal.warningText
                            text:               qsTr("If you are changing batteries for Resume Mission do not disconnect from the vehicle when communication is lost.")
                            visible:            _guidedController.showResumeMission
                        }
Don Gagne's avatar
Don Gagne committed
252 253
                    }

254
                    ColumnLayout {
Don Gagne's avatar
Don Gagne committed
255
                        Layout.fillWidth:   true
256
                        spacing:            ScreenTools.defaultFontPixelHeight
Gus Grubba's avatar
Gus Grubba committed
257
                        visible:            activeVehicle.connectionLost && _guidedController.showResumeMission
258 259 260 261 262 263 264

                        QGCLabel {
                            Layout.fillWidth:   true
                            wrapMode:           Text.WordWrap
                            color:              qgcPal.warningText
                            text:               qsTr("If you are changing batteries for Resume Mission do not disconnect from the vehicle.")
                        }
Don Gagne's avatar
Don Gagne committed
265
                    }
266
                }
267 268 269 270
            }
        }
    }

Patrick José Pereira's avatar
Patrick José Pereira committed
271 272
    Window {
        id:             videoWindow
273 274
        width:          !_mainIsMap ? _mapAndVideo.width  : _pipSize
        height:         !_mainIsMap ? _mapAndVideo.height : _pipSize * (9/16)
Patrick José Pereira's avatar
Patrick José Pereira committed
275 276 277 278 279 280 281 282 283 284 285
        visible:        false

        Item {
            id:             videoItem
            anchors.fill:   parent
        }

        onClosing: {
            _flightVideo.state = "unpopup"
            videoWindow.visible = false
        }
286
    }
Patrick José Pereira's avatar
Patrick José Pereira committed
287

288 289 290 291 292 293 294 295 296 297 298 299 300 301 302
    /* This timer will startVideo again after the popup window appears and is loaded.
     * Such approach was the only one to avoid a crash for windows users
     */
    Timer {
      id: videoPopUpTimer
      interval: 2000;
      running: false;
      repeat: false
      onTriggered: {
          // If state is popup, the next one will be popup-finished
          if (_flightVideo.state ==  "popup") {
            _flightVideo.state = "popup-finished"
          }
          QGroundControl.videoManager.startVideo()
      }
Patrick José Pereira's avatar
Patrick José Pereira committed
303 304
    }

305 306
    QGCMapPalette { id: mapPal; lightColors: _mainIsMap ? _flightMap.isSatelliteMap : true }

307
    Item {
308
        id:             _mapAndVideo
309 310 311 312 313
        anchors.fill:   parent

        //-- Map View
        Item {
            id: _flightMapContainer
314 315 316
            z:  _mainIsMap ? _mapAndVideo.z + 1 : _mapAndVideo.z + 2
            anchors.left:   _mapAndVideo.left
            anchors.bottom: _mapAndVideo.bottom
317
            visible:        _mainIsMap || _isPipVisible && !QGroundControl.videoManager.fullScreen
318 319
            width:          _mainIsMap ? _mapAndVideo.width  : _pipSize
            height:         _mainIsMap ? _mapAndVideo.height : _pipSize * (9/16)
320 321 322 323 324 325 326 327 328 329 330 331 332 333
            states: [
                State {
                    name:   "pipMode"
                    PropertyChanges {
                        target:             _flightMapContainer
                        anchors.margins:    ScreenTools.defaultFontPixelHeight
                    }
                },
                State {
                    name:   "fullMode"
                    PropertyChanges {
                        target:             _flightMapContainer
                        anchors.margins:    0
                    }
334
                }
335 336
            ]
            FlightDisplayViewMap {
337 338 339
                id:                         _flightMap
                anchors.fill:               parent
                guidedActionsController:    _guidedController
Gus Grubba's avatar
Gus Grubba committed
340
                missionController:          _planController
341 342
                flightWidgets:              flightDisplayViewWidgets
                rightPanelWidth:            ScreenTools.defaultFontPixelHeight * 9
343
                multiVehicleView:           !singleVehicleView.checked
344
                scaleState:                 (_mainIsMap && flyViewOverlay.item) ? (flyViewOverlay.item.scaleState ? flyViewOverlay.item.scaleState : "bottomMode") : "bottomMode"
345
            }
346
        }
347

348
        //-- Video View
349
        Item {
350
            id:             _flightVideo
351 352 353 354 355
            z:              _mainIsMap ? _mapAndVideo.z + 2 : _mapAndVideo.z + 1
            width:          !_mainIsMap ? _mapAndVideo.width  : _pipSize
            height:         !_mainIsMap ? _mapAndVideo.height : _pipSize * (9/16)
            anchors.left:   _mapAndVideo.left
            anchors.bottom: _mapAndVideo.bottom
356
            visible:        QGroundControl.videoManager.hasVideo && (!_mainIsMap || _isPipVisible)
357 358 359 360 361 362

            onParentChanged: {
                /* If video comes back from popup
                 * correct anchors.
                 * Such thing is not possible with ParentChange.
                 */
363
                if(parent == _mapAndVideo) {
364
                    // Do anchors again after popup
365 366
                    anchors.left =       _mapAndVideo.left
                    anchors.bottom =     _mapAndVideo.bottom
367 368 369 370
                    anchors.margins =    ScreenTools.defaultFontPixelHeight
                }
            }

371 372 373 374 375
            states: [
                State {
                    name:   "pipMode"
                    PropertyChanges {
                        target: _flightVideo
Patrick José Pereira's avatar
Patrick José Pereira committed
376 377 378 379 380
                        anchors.margins: ScreenTools.defaultFontPixelHeight
                    }
                    PropertyChanges {
                        target: _flightVideoPipControl
                        inPopup: false
381 382 383 384 385 386 387 388
                    }
                },
                State {
                    name:   "fullMode"
                    PropertyChanges {
                        target: _flightVideo
                        anchors.margins:    0
                    }
Patrick José Pereira's avatar
Patrick José Pereira committed
389 390 391 392 393 394 395 396
                    PropertyChanges {
                        target: _flightVideoPipControl
                        inPopup: false
                    }
                },
                State {
                    name: "popup"
                    StateChangeScript {
397 398 399 400 401 402
                        script: {
                            // Stop video, restart it again with Timer
                            // Avoiding crashs if ParentChange is not yet done
                            QGroundControl.videoManager.stopVideo()
                            videoPopUpTimer.running = true
                        }
Patrick José Pereira's avatar
Patrick José Pereira committed
403
                    }
404 405 406 407 408 409 410
                    PropertyChanges {
                        target: _flightVideoPipControl
                        inPopup: true
                    }
                },
                State {
                    name: "popup-finished"
Patrick José Pereira's avatar
Patrick José Pereira committed
411 412 413 414 415
                    ParentChange {
                        target: _flightVideo
                        parent: videoItem
                        x: 0
                        y: 0
416 417
                        width: videoItem.width
                        height: videoItem.height
Patrick José Pereira's avatar
Patrick José Pereira committed
418 419 420 421 422
                    }
                },
                State {
                    name: "unpopup"
                    StateChangeScript {
423 424 425 426
                        script: {
                            QGroundControl.videoManager.stopVideo()
                            videoPopUpTimer.running = true
                        }
Patrick José Pereira's avatar
Patrick José Pereira committed
427 428 429
                    }
                    ParentChange {
                        target: _flightVideo
430
                        parent: _mapAndVideo
Patrick José Pereira's avatar
Patrick José Pereira committed
431 432 433 434 435
                    }
                    PropertyChanges {
                        target: _flightVideoPipControl
                        inPopup: false
                    }
436
                }
437
            ]
438
            //-- Video Streaming
439
            FlightDisplayViewVideo {
Patrick José Pereira's avatar
Patrick José Pereira committed
440
                id:             videoStreaming
441 442 443 444
                anchors.fill:   parent
                visible:        QGroundControl.videoManager.isGStreamer
            }
            //-- UVC Video (USB Camera or Video Device)
445 446
            Loader {
                id:             cameraLoader
447 448
                anchors.fill:   parent
                visible:        !QGroundControl.videoManager.isGStreamer
449
                source:         QGroundControl.videoManager.uvcEnabled ? "qrc:/qml/FlightDisplayViewUVC.qml" : "qrc:/qml/FlightDisplayViewDummy.qml"
450
            }
dogmaphobic's avatar
dogmaphobic committed
451
        }
452 453 454 455

        QGCPipable {
            id:                 _flightVideoPipControl
            z:                  _flightVideo.z + 3
456 457
            width:              _pipSize
            height:             _pipSize * (9/16)
458 459
            anchors.left:       _mapAndVideo.left
            anchors.bottom:     _mapAndVideo.bottom
460
            anchors.margins:    ScreenTools.defaultFontPixelHeight
461
            visible:            QGroundControl.videoManager.hasVideo && !QGroundControl.videoManager.fullScreen && _flightVideo.state != "popup"
462 463
            isHidden:           !_isPipVisible
            isDark:             isBackgroundDark
464
            enablePopup:        _mainIsMap
465 466 467 468 469 470 471
            onActivated: {
                _mainIsMap = !_mainIsMap
                setStates()
            }
            onHideIt: {
                setPipVisibility(!state)
            }
Patrick José Pereira's avatar
Patrick José Pereira committed
472 473 474 475
            onPopup: {
                videoWindow.visible = true
                _flightVideo.state = "popup"
            }
476 477
            onNewWidth: {
                _pipSize = newWidth
Jacob Walser's avatar
Jacob Walser committed
478
            }
dogmaphobic's avatar
dogmaphobic committed
479
        }
Don Gagne's avatar
Don Gagne committed
480

481 482 483 484 485 486 487
        Row {
            id:                     singleMultiSelector
            anchors.topMargin:      ScreenTools.toolbarHeight + _margins
            anchors.rightMargin:    _margins
            anchors.right:          parent.right
            anchors.top:            parent.top
            spacing:                ScreenTools.defaultFontPixelWidth
488
            z:                      _mapAndVideo.z + 4
489 490 491 492 493 494 495 496 497
            visible:                QGroundControl.multiVehicleManager.vehicles.count > 1

            ExclusiveGroup { id: multiVehicleSelectorGroup }

            QGCRadioButton {
                id:             singleVehicleView
                exclusiveGroup: multiVehicleSelectorGroup
                text:           qsTr("Single")
                checked:        true
498
                textColor:      mapPal.text
499 500 501 502
            }

            QGCRadioButton {
                exclusiveGroup: multiVehicleSelectorGroup
503
                text:           qsTr("Multi-Vehicle")
504
                textColor:      mapPal.text
505 506 507
            }
        }

508
        FlightDisplayViewWidgets {
509
            id:                 flightDisplayViewWidgets
510 511
            z:                  _mapAndVideo.z + 4
            height:             availableHeight - (singleMultiSelector.visible ? singleMultiSelector.height + _margins : 0) - (ScreenTools.defaultFontPixelHeight * 0.5)
512
            anchors.left:       parent.left
513
            anchors.right:      altitudeSlider.visible ? altitudeSlider.left : parent.right
514
            anchors.bottom:     parent.bottom
515
            useLightColors:     isBackgroundDark
516
            missionController:  _missionController
517
            visible:            singleVehicleView.checked && !QGroundControl.videoManager.fullScreen
518 519
        }

520 521 522 523 524
        //-------------------------------------------------------------------------
        //-- Loader helper for plugins to overlay elements over the fly view
        Loader {
            id:                 flyViewOverlay
            z:                  flightDisplayViewWidgets.z + 1
525
            visible:            !QGroundControl.videoManager.fullScreen
526
            height:             mainWindow.height
527 528 529 530 531
            anchors.left:       parent.left
            anchors.right:      altitudeSlider.visible ? altitudeSlider.left : parent.right
            anchors.bottom:     parent.bottom
        }

532
        MultiVehicleList {
533 534 535 536 537 538
            anchors.margins:            _margins
            anchors.top:                singleMultiSelector.bottom
            anchors.right:              parent.right
            anchors.bottom:             parent.bottom
            width:                      ScreenTools.defaultFontPixelWidth * 30
            visible:                    !singleVehicleView.checked && !QGroundControl.videoManager.fullScreen
539
            z:                          _mapAndVideo.z + 4
540
            guidedActionsController:    _guidedController
541
        }
dogmaphobic's avatar
dogmaphobic committed
542

543
        //-- Virtual Joystick
544
        Loader {
545
            id:                         virtualJoystickMultiTouch
546
            z:                          _mapAndVideo.z + 5
547
            width:                      parent.width  - (_flightVideoPipControl.width / 2)
548
            height:                     Math.min(mainWindow.height * 0.25, ScreenTools.defaultFontPixelWidth * 16)
Gus Grubba's avatar
Gus Grubba committed
549
            visible:                    (_virtualJoystick ? _virtualJoystick.value : false) && !QGroundControl.videoManager.fullScreen && !(activeVehicle ? activeVehicle.highLatencyLink : false)
550 551
            anchors.bottom:             _flightVideoPipControl.top
            anchors.bottomMargin:       ScreenTools.defaultFontPixelHeight * 2
552
            anchors.horizontalCenter:   flightDisplayViewWidgets.horizontalCenter
553
            source:                     "qrc:/qml/VirtualJoystick.qml"
Gus Grubba's avatar
Gus Grubba committed
554
            active:                     (_virtualJoystick ? _virtualJoystick.value : false) && !(activeVehicle ? activeVehicle.highLatencyLink : false)
Don Gagne's avatar
Don Gagne committed
555

556
            property bool useLightColors: isBackgroundDark
557 558

            property Fact _virtualJoystick: QGroundControl.settingsManager.appSettings.virtualJoystick
Don Gagne's avatar
Don Gagne committed
559
        }
560 561

        ToolStrip {
Gus Grubba's avatar
Gus Grubba committed
562
            visible:            (activeVehicle ? activeVehicle.guidedModeSupported : true) && !QGroundControl.videoManager.fullScreen
563
            id:                 toolStrip
Gus Grubba's avatar
Gus Grubba committed
564
            anchors.leftMargin: isInstrumentRight() ? ScreenTools.defaultFontPixelWidth : undefined
565
            anchors.left:       isInstrumentRight() ? _mapAndVideo.left : undefined
Gus Grubba's avatar
Gus Grubba committed
566
            anchors.rightMargin:isInstrumentRight() ? undefined : ScreenTools.defaultFontPixelWidth
567
            anchors.right:      isInstrumentRight() ? undefined : _mapAndVideo.right
568
            anchors.topMargin:  ScreenTools.toolbarHeight + (_margins * 2)
569 570
            anchors.top:        _mapAndVideo.top
            z:                  _mapAndVideo.z + 4
571 572
            title:              qsTr("Fly")
            maxHeight:          (_flightVideo.visible ? _flightVideo.y : parent.height) - toolStrip.y
573 574
            buttonVisible:      [_useChecklist, _guidedController.showTakeoff || !_guidedController.showLand, _guidedController.showLand && !_guidedController.showTakeoff, true, true, true ]
            buttonEnabled:      [_useChecklist && activeVehicle, _guidedController.showTakeoff, _guidedController.showLand, _guidedController.showRTL, _guidedController.showPause, _anyActionAvailable ]
575

576
            property bool _anyActionAvailable: _guidedController.showStartMission || _guidedController.showResumeMission || _guidedController.showChangeAlt || _guidedController.showLandAbort
577 578
            property var _actionModel: [
                {
579 580 581 582
                    title:      _guidedController.startMissionTitle,
                    text:       _guidedController.startMissionMessage,
                    action:     _guidedController.actionStartMission,
                    visible:    _guidedController.showStartMission
583
                },
Don Gagne's avatar
Don Gagne committed
584 585 586 587 588 589
                {
                    title:      _guidedController.continueMissionTitle,
                    text:       _guidedController.continueMissionMessage,
                    action:     _guidedController.actionContinueMission,
                    visible:    _guidedController.showContinueMission
                },
590
                {
591 592 593 594
                    title:      _guidedController.resumeMissionTitle,
                    text:       _guidedController.resumeMissionMessage,
                    action:     _guidedController.actionResumeMission,
                    visible:    _guidedController.showResumeMission
595 596
                },
                {
597 598 599 600
                    title:      _guidedController.changeAltTitle,
                    text:       _guidedController.changeAltMessage,
                    action:     _guidedController.actionChangeAlt,
                    visible:    _guidedController.showChangeAlt
601 602
                },
                {
603 604 605 606
                    title:      _guidedController.landAbortTitle,
                    text:       _guidedController.landAbortMessage,
                    action:     _guidedController.actionLandAbort,
                    visible:    _guidedController.showLandAbort
607 608 609 610
                }
            ]

            model: [
611
                {
612 613
                    name:       "Checklist",
                    iconSource: "/qmlimages/check.svg",
614 615
                    dropPanelComponent: checklistDropPanel
                },
616
                {
617
                    name:       _guidedController.takeoffTitle,
618
                    iconSource: "/res/takeoff.svg",
619
                    action:     _guidedController.actionTakeoff
620 621
                },
                {
622
                    name:       _guidedController.landTitle,
623
                    iconSource: "/res/land.svg",
624
                    action:     _guidedController.actionLand
625 626
                },
                {
627
                    name:       _guidedController.rtlTitle,
628
                    iconSource: "/res/rtl.svg",
629
                    action:     _guidedController.actionRTL
630 631
                },
                {
632
                    name:       _guidedController.pauseTitle,
Gus Grubba's avatar
Gus Grubba committed
633
                    iconSource: "/res/pause-mission.svg",
634
                    action:     _guidedController.actionPause
635 636 637
                },
                {
                    name:       qsTr("Action"),
Gus Grubba's avatar
Gus Grubba committed
638
                    iconSource: "/res/action.svg",
639
                    action:     -1
DonLakeFlyer's avatar
DonLakeFlyer committed
640
                }
641 642 643
            ]

            onClicked: {
644
                guidedActionsController.closeAll()
645 646 647 648
                var action = model[index].action
                if (action === -1) {
                    guidedActionList.model   = _actionModel
                    guidedActionList.visible = true
649
                } else {
650
                    _guidedController.confirmAction(action)
651 652 653 654 655
                }
            }
        }

        GuidedActionsController {
656
            id:                 guidedActionsController
657
            missionController:  _missionController
658
            confirmDialog:      guidedActionConfirm
DonLakeFlyer's avatar
DonLakeFlyer committed
659
            actionList:         guidedActionList
Don Gagne's avatar
Don Gagne committed
660
            altitudeSlider:     _altitudeSlider
661 662
            z:                  _flightVideoPipControl.z + 1

663
            onShowStartMissionChanged: {
Don Gagne's avatar
Don Gagne committed
664
                if (showStartMission) {
665 666 667 668
                    confirmAction(actionStartMission)
                }
            }

669 670 671 672 673 674
            onShowContinueMissionChanged: {
                if (showContinueMission) {
                    confirmAction(actionContinueMission)
                }
            }

675 676 677 678 679
            onShowLandAbortChanged: {
                if (showLandAbort) {
                    confirmAction(actionLandAbort)
                }
            }
680 681 682 683 684 685 686 687

            /// Close all dialogs
            function closeAll() {
                rootLoader.sourceComponent  = null
                guidedActionConfirm.visible = false
                guidedActionList.visible    = false
                altitudeSlider.visible      = false
            }
688 689
        }

690
        GuidedActionConfirm {
691 692 693 694
            id:                         guidedActionConfirm
            anchors.margins:            _margins
            anchors.bottom:             parent.bottom
            anchors.horizontalCenter:   parent.horizontalCenter
695 696
            guidedController:           _guidedController
            altitudeSlider:             _altitudeSlider
697 698
        }

699
        GuidedActionList {
700 701 702 703
            id:                         guidedActionList
            anchors.margins:            _margins
            anchors.bottom:             parent.bottom
            anchors.horizontalCenter:   parent.horizontalCenter
704
            guidedController:           _guidedController
705 706 707
        }

        //-- Altitude slider
DonLakeFlyer's avatar
DonLakeFlyer committed
708
        GuidedAltitudeSlider {
709 710 711 712 713 714
            id:                 altitudeSlider
            anchors.margins:    _margins
            anchors.right:      parent.right
            anchors.topMargin:  ScreenTools.toolbarHeight + _margins
            anchors.top:        parent.top
            anchors.bottom:     parent.bottom
715
            z:                  _guidedController.z
716 717 718 719 720
            radius:             ScreenTools.defaultFontPixelWidth / 2
            width:              ScreenTools.defaultFontPixelWidth * 10
            color:              qgcPal.window
            visible:            false
        }
Don Gagne's avatar
Don Gagne committed
721
    }
722

723
    //-- Airspace Indicator
724
    Rectangle {
725 726 727
        id:             airspaceIndicator
        width:          airspaceRow.width + (ScreenTools.defaultFontPixelWidth * 3)
        height:         airspaceRow.height * 1.25
728
        color:          qgcPal.globalTheme === QGCPalette.Light ? Qt.rgba(1,1,1,0.95) : Qt.rgba(0,0,0,0.75)
729
        visible:        QGroundControl.airmapSupported && _mainIsMap && flightPermit && flightPermit !== AirspaceFlightPlanProvider.PermitNone && !messageArea.visible && !criticalMmessageArea.visible
730 731 732 733 734 735 736
        radius:         3
        border.width:   1
        border.color:   qgcPal.globalTheme === QGCPalette.Light ? Qt.rgba(0,0,0,0.35) : Qt.rgba(1,1,1,0.35)
        anchors.top:    parent.top
        anchors.topMargin: ScreenTools.toolbarHeight + (ScreenTools.defaultFontPixelHeight * 0.25)
        anchors.horizontalCenter: parent.horizontalCenter
        Row {
737
            id: airspaceRow
738 739
            spacing: ScreenTools.defaultFontPixelWidth
            anchors.centerIn: parent
740
            QGCLabel { text: airspaceIndicator.providerName+":"; anchors.verticalCenter: parent.verticalCenter; }
741 742
            QGCLabel {
                text: {
743
                    if(airspaceIndicator.flightPermit) {
Gus Grubba's avatar
Gus Grubba committed
744
                        if(airspaceIndicator.flightPermit === AirspaceFlightPlanProvider.PermitPending)
745
                            return qsTr("Approval Pending")
746
                        if(airspaceIndicator.flightPermit === AirspaceFlightPlanProvider.PermitAccepted || airspaceIndicator.flightPermit === AirspaceFlightPlanProvider.PermitNotRequired)
747
                            return qsTr("Flight Approved")
Gus Grubba's avatar
Gus Grubba committed
748
                        if(airspaceIndicator.flightPermit === AirspaceFlightPlanProvider.PermitRejected)
749
                            return qsTr("Flight Rejected")
750 751 752 753
                    }
                    return ""
                }
                color: {
754
                    if(airspaceIndicator.flightPermit) {
Gus Grubba's avatar
Gus Grubba committed
755
                        if(airspaceIndicator.flightPermit === AirspaceFlightPlanProvider.PermitPending)
756
                            return qgcPal.colorOrange
757
                        if(airspaceIndicator.flightPermit === AirspaceFlightPlanProvider.PermitAccepted || airspaceIndicator.flightPermit === AirspaceFlightPlanProvider.PermitNotRequired)
758 759 760 761 762 763 764
                            return qgcPal.colorGreen
                    }
                    return qgcPal.colorRed
                }
                anchors.verticalCenter: parent.verticalCenter;
            }
        }
Gus Grubba's avatar
Gus Grubba committed
765
        property var  flightPermit: QGroundControl.airmapSupported ? QGroundControl.airspaceManager.flightPlan.flightPermitStatus : null
766
        property string  providerName: QGroundControl.airspaceManager.providerName
767 768
    }

769
    //-- Checklist GUI
770 771
    Component {
        id: checklistDropPanel
772 773 774
        PreFlightCheckList {
            model: preFlightCheckModel
        }
775
    }
776
}