FlightDisplayView.qml 33.5 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 34 35
QGCView {
    id:             root
    viewPanel:      _panel
36

37
    QGCPalette { id: qgcPal; colorGroupEnabled: enabled }
38

Don Gagne's avatar
Don Gagne committed
39 40
    property alias  guidedController:   guidedActionsController

41 42
    property bool activeVehicleJoystickEnabled: _activeVehicle ? _activeVehicle.joystickEnabled : false

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
50
    property bool   _useChecklist:          QGroundControl.settingsManager.appSettings.useChecklist.rawValue
51 52
    property real   _savedZoomLevel:        0
    property real   _margins:               ScreenTools.defaultFontPixelWidth / 2
53
    property real   _pipSize:               flightView.width * 0.2
54 55
    property alias  _guidedController:      guidedActionsController
    property alias  _altitudeSlider:        altitudeSlider
56

57 58
    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
59 60 61 62 63 64 65 66 67 68 69 70
    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"

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

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

Gus Grubba's avatar
Gus Grubba committed
97 98 99 100 101 102 103 104 105 106 107 108 109 110
    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;
    }

111
    PlanMasterController {
112
        id:                     masterController
113
        Component.onCompleted:  start(true /* flyView */)
114 115
    }

116
    BuiltInPreFlightCheckModel {
117
        id: preFlightCheckModel
118 119
    }

120
    Connections {
121 122
        target:                     _missionController
        onResumeMissionUploadFail:  guidedActionsController.confirmAction(guidedActionsController.actionResumeMissionUploadFail)
123 124
    }

125 126
    Component.onCompleted: {
        setStates()
127 128 129
        if(QGroundControl.corePlugin.options.flyViewOverlay.toString().length) {
            flyViewOverlay.source = QGroundControl.corePlugin.options.flyViewOverlay
        }
130
    }
dogmaphobic's avatar
dogmaphobic committed
131

132 133 134 135 136 137 138 139 140 141 142 143 144 145
    // 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 {
146
            if (promptForMissionRemove && (_missionController.containsItems || _geoFenceController.containsItems || _rallyPointController.containsItems)) {
147 148 149 150
                // 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)
                }
151 152 153 154 155 156 157 158 159 160 161 162
            }
            promptForMissionRemove = false
        }
    }

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

    Component {
163 164 165
        id: missionCompleteDialogComponent

        QGCViewDialog {
166 167 168 169 170 171
            property var activeVehicleCopy: _activeVehicle
            onActiveVehicleCopyChanged:
                if (!activeVehicleCopy) {
                    hideDialog()
                }

172 173 174 175
            QGCFlickable {
                anchors.fill:   parent
                contentHeight:  column.height

176
                ColumnLayout {
177 178 179 180 181
                    id:                 column
                    anchors.margins:    _margins
                    anchors.left:       parent.left
                    anchors.right:      parent.right

182
                    ColumnLayout {
183
                        Layout.fillWidth:   true
184 185 186 187 188 189 190 191
                        spacing:            ScreenTools.defaultFontPixelHeight
                        visible:            !_activeVehicle.connectionLost || !_guidedController.showResumeMission

                        QGCLabel {
                            Layout.fillWidth:       true
                            text:                   qsTr("%1 Images Taken").arg(_activeVehicle.cameraTriggerPoints.count)
                            horizontalAlignment:    Text.AlignHCenter
                            visible:                _activeVehicle.cameraTriggerPoints.count != 0
192
                        }
193

194 195 196 197 198 199 200 201
                        QGCButton {
                            Layout.fillWidth:   true
                            text:               qsTr("Remove plan from vehicle")
                            onClicked: {
                                _planMasterController.removeAllFromVehicle()
                                hideDialog()
                            }
                        }
Don Gagne's avatar
Don Gagne committed
202

203 204 205 206 207 208
                        QGCButton {
                            Layout.fillWidth:   true
                            Layout.alignment:   Qt.AlignHCenter
                            text:               qsTr("Leave plan on vehicle")
                            onClicked:          hideDialog()
                        }
Don Gagne's avatar
Don Gagne committed
209

210 211 212 213 214
                        Rectangle {
                            Layout.fillWidth:   true
                            color:              qgcPal.text
                            height:             1
                        }
Don Gagne's avatar
Don Gagne committed
215

216 217 218 219 220 221 222 223 224 225
                        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
226 227
                        }

228 229 230 231 232 233 234 235 236 237 238 239 240 241
                        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
242 243
                    }

244
                    ColumnLayout {
Don Gagne's avatar
Don Gagne committed
245
                        Layout.fillWidth:   true
246 247 248 249 250 251 252 253 254
                        spacing:            ScreenTools.defaultFontPixelHeight
                        visible:            _activeVehicle.connectionLost && _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.")
                        }
Don Gagne's avatar
Don Gagne committed
255
                    }
256
                }
257 258 259 260
            }
        }
    }

Patrick José Pereira's avatar
Patrick José Pereira committed
261 262 263 264 265 266 267 268 269 270 271 272 273 274 275
    Window {
        id:             videoWindow
        width:          !_mainIsMap ? _panel.width  : _pipSize
        height:         !_mainIsMap ? _panel.height : _pipSize * (9/16)
        visible:        false

        Item {
            id:             videoItem
            anchors.fill:   parent
        }

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

278 279 280 281 282 283 284 285 286 287 288 289 290 291 292
    /* 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
293 294
    }

295 296
    QGCMapPalette { id: mapPal; lightColors: _mainIsMap ? _flightMap.isSatelliteMap : true }

297 298 299 300 301 302 303 304 305 306 307 308
    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
309
            visible:        _mainIsMap || _isPipVisible && !QGroundControl.videoManager.fullScreen
310 311
            width:          _mainIsMap ? _panel.width  : _pipSize
            height:         _mainIsMap ? _panel.height : _pipSize * (9/16)
312 313 314 315 316 317 318 319 320 321 322 323 324 325
            states: [
                State {
                    name:   "pipMode"
                    PropertyChanges {
                        target:             _flightMapContainer
                        anchors.margins:    ScreenTools.defaultFontPixelHeight
                    }
                },
                State {
                    name:   "fullMode"
                    PropertyChanges {
                        target:             _flightMapContainer
                        anchors.margins:    0
                    }
326
                }
327 328
            ]
            FlightDisplayViewMap {
329 330
                id:                         _flightMap
                anchors.fill:               parent
331
                planMasterController:       masterController
332 333 334 335
                guidedActionsController:    _guidedController
                flightWidgets:              flightDisplayViewWidgets
                rightPanelWidth:            ScreenTools.defaultFontPixelHeight * 9
                qgcView:                    root
336
                multiVehicleView:           !singleVehicleView.checked
337
                scaleState:                 (_mainIsMap && flyViewOverlay.item) ? (flyViewOverlay.item.scaleState ? flyViewOverlay.item.scaleState : "bottomMode") : "bottomMode"
338
            }
339
        }
340

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

            onParentChanged: {
                /* If video comes back from popup
                 * correct anchors.
                 * Such thing is not possible with ParentChange.
                 */
                if(parent == _panel) {
                    // Do anchors again after popup
                    anchors.left =       _panel.left
                    anchors.bottom =     _panel.bottom
                    anchors.margins =    ScreenTools.defaultFontPixelHeight
                }
            }

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

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

474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490
        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
491
                textColor:      mapPal.text
492 493 494 495
            }

            QGCRadioButton {
                exclusiveGroup: multiVehicleSelectorGroup
496
                text:           qsTr("Multi-Vehicle")
497
                textColor:      mapPal.text
498 499 500
            }
        }

501
        FlightDisplayViewWidgets {
502 503
            id:                 flightDisplayViewWidgets
            z:                  _panel.z + 4
504
            height:             ScreenTools.availableHeight - (singleMultiSelector.visible ? singleMultiSelector.height + _margins : 0)
505
            anchors.left:       parent.left
506
            anchors.right:      altitudeSlider.visible ? altitudeSlider.left : parent.right
507 508
            anchors.bottom:     parent.bottom
            qgcView:            root
509
            useLightColors:     isBackgroundDark
510
            missionController:  _missionController
511
            visible:            singleVehicleView.checked && !QGroundControl.videoManager.fullScreen
512 513
        }

514 515 516 517 518
        //-------------------------------------------------------------------------
        //-- Loader helper for plugins to overlay elements over the fly view
        Loader {
            id:                 flyViewOverlay
            z:                  flightDisplayViewWidgets.z + 1
519
            visible:            !QGroundControl.videoManager.fullScreen
520 521 522 523
            height:             ScreenTools.availableHeight
            anchors.left:       parent.left
            anchors.right:      altitudeSlider.visible ? altitudeSlider.left : parent.right
            anchors.bottom:     parent.bottom
524 525

            property var qgcView: root
526 527
        }

528
        MultiVehicleList {
529 530 531 532 533 534 535 536
            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
            z:                          _panel.z + 4
            guidedActionsController:    _guidedController
537
        }
dogmaphobic's avatar
dogmaphobic committed
538

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

552
            property bool useLightColors: isBackgroundDark
553 554

            property Fact _virtualJoystick: QGroundControl.settingsManager.appSettings.virtualJoystick
Don Gagne's avatar
Don Gagne committed
555
        }
556 557

        ToolStrip {
558
            visible:            (_activeVehicle ? _activeVehicle.guidedModeSupported : true) && !QGroundControl.videoManager.fullScreen
559
            id:                 toolStrip
Gus Grubba's avatar
Gus Grubba committed
560 561 562 563
            anchors.leftMargin: isInstrumentRight() ? ScreenTools.defaultFontPixelWidth : undefined
            anchors.left:       isInstrumentRight() ? _panel.left : undefined
            anchors.rightMargin:isInstrumentRight() ? undefined : ScreenTools.defaultFontPixelWidth
            anchors.right:      isInstrumentRight() ? undefined : _panel.right
564
            anchors.topMargin:  ScreenTools.toolbarHeight + (_margins * 2)
565 566 567 568
            anchors.top:        _panel.top
            z:                  _panel.z + 4
            title:              qsTr("Fly")
            maxHeight:          (_flightVideo.visible ? _flightVideo.y : parent.height) - toolStrip.y
DonLakeFlyer's avatar
DonLakeFlyer committed
569 570
            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 ]
571

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

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

            onClicked: {
640
                guidedActionsController.closeAll()
641 642
                var action = model[index].action
                if (action === -1) {
DonLakeFlyer's avatar
DonLakeFlyer committed
643 644
                    guidedActionList.model   = _actionModel
                    guidedActionList.visible = true
645
                } else {
646
                    _guidedController.confirmAction(action)
647 648 649 650 651
                }
            }
        }

        GuidedActionsController {
652
            id:                 guidedActionsController
653
            missionController:  _missionController
654
            confirmDialog:      guidedActionConfirm
DonLakeFlyer's avatar
DonLakeFlyer committed
655
            actionList:         guidedActionList
Don Gagne's avatar
Don Gagne committed
656
            altitudeSlider:     _altitudeSlider
657 658
            z:                  _flightVideoPipControl.z + 1

659
            onShowStartMissionChanged: {
Don Gagne's avatar
Don Gagne committed
660
                if (showStartMission) {
661 662 663 664
                    confirmAction(actionStartMission)
                }
            }

665 666 667 668 669 670
            onShowContinueMissionChanged: {
                if (showContinueMission) {
                    confirmAction(actionContinueMission)
                }
            }

671 672 673 674 675
            onShowLandAbortChanged: {
                if (showLandAbort) {
                    confirmAction(actionLandAbort)
                }
            }
676 677 678

            /// Close all dialogs
            function closeAll() {
679
                mainWindow.enableToolbar()
680 681 682 683 684
                rootLoader.sourceComponent  = null
                guidedActionConfirm.visible = false
                guidedActionList.visible    = false
                altitudeSlider.visible      = false
            }
685 686
        }

687
        GuidedActionConfirm {
688 689 690 691
            id:                         guidedActionConfirm
            anchors.margins:            _margins
            anchors.bottom:             parent.bottom
            anchors.horizontalCenter:   parent.horizontalCenter
692 693
            guidedController:           _guidedController
            altitudeSlider:             _altitudeSlider
694 695
        }

696
        GuidedActionList {
697 698 699 700
            id:                         guidedActionList
            anchors.margins:            _margins
            anchors.bottom:             parent.bottom
            anchors.horizontalCenter:   parent.horizontalCenter
701
            guidedController:           _guidedController
702 703 704
        }

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

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

766
    //-- Checklist GUI
767 768
    Component {
        id: checklistDropPanel
769 770 771
        PreFlightCheckList {
            model: preFlightCheckModel
        }
772
    }
773
}