FlightDisplayView.qml 35.3 KB
Newer Older
1 2
/****************************************************************************
 *
Gus Grubba's avatar
Gus Grubba committed
3
 * (c) 2009-2020 QGROUNDCONTROL PROJECT <http://www.qgroundcontrol.org>
4 5 6 7 8
 *
 * QGroundControl is licensed according to the terms in the file
 * COPYING.md in the root of the source code directory.
 *
 ****************************************************************************/
9

10 11 12 13
import QtQuick                  2.11
import QtQuick.Controls         2.4
import QtQuick.Dialogs          1.3
import QtQuick.Layouts          1.11
14

15 16
import QtLocation               5.3
import QtPositioning            5.3
Patrick José Pereira's avatar
Patrick José Pereira committed
17
import QtQuick.Window           2.2
18
import QtQml.Models             2.1
19

20
import QGroundControl               1.0
21 22 23 24
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
25
import QGroundControl.FlightDisplay 1.0
26 27
import QGroundControl.FlightMap     1.0
import QGroundControl.Palette       1.0
28
import QGroundControl.ScreenTools   1.0
29
import QGroundControl.Vehicle       1.0
30 31

/// Flight Display View
32
Item {
33

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

42 43 44 45 46 47 48 49 50
    property alias  guidedController:              guidedActionsController
    property bool   activeVehicleJoystickEnabled:  activeVehicle ? activeVehicle.joystickEnabled : false
    property bool   mainIsMap:                     QGroundControl.videoManager.hasVideo ? QGroundControl.loadBoolGlobalSetting(_mainIsMapKey,  true) : true
    property bool   isBackgroundDark:              mainIsMap ? (mainWindow.flightDisplayMap ? mainWindow.flightDisplayMap.isSatelliteMap : true) : true

    property var    _missionController:             _planController.missionController
    property var    _geoFenceController:            _planController.geoFenceController
    property var    _rallyPointController:          _planController.rallyPointController
    property bool   _isPipVisible:                  QGroundControl.videoManager.hasVideo ? QGroundControl.loadBoolGlobalSetting(_PIPVisibleKey, true) : false
51
    property bool   _useChecklist:                  QGroundControl.settingsManager.appSettings.useChecklist.rawValue && QGroundControl.corePlugin.options.preFlightChecklistUrl.toString().length
52 53
    property bool   _enforceChecklist:              _useChecklist && QGroundControl.settingsManager.appSettings.enforceChecklist.rawValue
    property bool   _canArm:                        activeVehicle ? (_useChecklist ? (_enforceChecklist ? activeVehicle.checkListState === Vehicle.CheckListPassed : true) : true) : false
54 55 56 57
    property real   _margins:                       ScreenTools.defaultFontPixelWidth / 2
    property real   _pipSize:                       mainWindow.width * 0.2
    property alias  _guidedController:              guidedActionsController
    property alias  _altitudeSlider:                altitudeSlider
58
    property real   _toolsMargin:                   ScreenTools.defaultFontPixelWidth * 0.75
59

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

73
    function setStates() {
74 75
        QGroundControl.saveBoolGlobalSetting(_mainIsMapKey, mainIsMap)
        if(mainIsMap) {
76 77 78
            //-- Adjust Margins
            _flightMapContainer.state   = "fullMode"
            _flightVideo.state          = "pipMode"
79
        } else {
80 81 82
            //-- Adjust Margins
            _flightMapContainer.state   = "pipMode"
            _flightVideo.state          = "fullMode"
83
        }
Don Gagne's avatar
Don Gagne committed
84 85
    }

86 87 88
    function setPipVisibility(state) {
        _isPipVisible = state;
        QGroundControl.saveBoolGlobalSetting(_PIPVisibleKey, state)
89 90
    }

Gus Grubba's avatar
Gus Grubba committed
91 92 93 94 95 96 97 98 99 100 101 102 103 104
    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;
    }

105
    Connections {
106 107
        target:                     _missionController
        onResumeMissionUploadFail:  guidedActionsController.confirmAction(guidedActionsController.actionResumeMissionUploadFail)
108 109
    }

110 111 112 113 114 115 116 117 118 119 120 121
    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)
122
        onFlightDisplayMapChanged:      setStates()
123 124
    }

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

134 135 136 137 138 139 140 141
    // The following code is used to track vehicle states for showing the mission complete dialog
    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 vehicleWasInMissionFlightMode:    false
    property bool showMissionCompleteDialog:        vehicleWasArmed && vehicleWasInMissionFlightMode &&
                                                        (_missionController.containsItems || _geoFenceController.containsItems || _rallyPointController.containsItems ||
                                                        (activeVehicle ? activeVehicle.cameraTriggerPoints.count !== 0 : false))
142 143 144

    onVehicleArmedChanged: {
        if (vehicleArmed) {
145 146
            vehicleWasArmed = true
            vehicleWasInMissionFlightMode = vehicleInMissionFlightMode
147
        } else {
148 149
            if (showMissionCompleteDialog) {
                mainWindow.showComponentDialog(missionCompleteDialogComponent, qsTr("Flight Plan complete"), mainWindow.showDialogDefaultWidth, StandardButton.Close)
150
            }
151 152
            vehicleWasArmed = false
            vehicleWasInMissionFlightMode = false
153 154 155 156
        }
    }

    onVehicleInMissionFlightModeChanged: {
157 158
        if (vehicleInMissionFlightMode && vehicleArmed) {
            vehicleWasInMissionFlightMode = true
159 160 161 162
        }
    }

    Component {
163 164 165
        id: missionCompleteDialogComponent

        QGCViewDialog {
Gus Grubba's avatar
Gus Grubba committed
166
            property var activeVehicleCopy: activeVehicle
167 168 169 170 171
            onActiveVehicleCopyChanged:
                if (!activeVehicleCopy) {
                    hideDialog()
                }

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

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

183 184 185 186 187 188
                    QGCLabel {
                        Layout.fillWidth:       true
                        text:                   qsTr("%1 Images Taken").arg(activeVehicle.cameraTriggerPoints.count)
                        horizontalAlignment:    Text.AlignHCenter
                        visible:                activeVehicle.cameraTriggerPoints.count !== 0
                    }
189

190 191 192 193 194 195 196
                    QGCButton {
                        Layout.fillWidth:   true
                        text:               qsTr("Remove plan from vehicle")
                        visible:            !activeVehicle.connectionLost// && !activeVehicle.apmFirmware  // ArduPilot has a bug somewhere with mission clear
                        onClicked: {
                            _planController.removeAllFromVehicle()
                            hideDialog()
197
                        }
198
                    }
199

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

207 208 209 210 211
                    Rectangle {
                        Layout.fillWidth:   true
                        color:              qgcPal.text
                        height:             1
                    }
Don Gagne's avatar
Don Gagne committed
212

213 214 215 216
                    ColumnLayout {
                        Layout.fillWidth:   true
                        spacing:            ScreenTools.defaultFontPixelHeight
                        visible:            !activeVehicle.connectionLost && _guidedController.showResumeMission
Don Gagne's avatar
Don Gagne committed
217

218 219 220 221 222 223 224 225 226
                        QGCButton {
                            Layout.fillWidth:   true
                            Layout.alignment:   Qt.AlignHCenter
                            text:               qsTr("Resume Mission From Waypoint %1").arg(_guidedController._resumeMissionIndex)

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

229 230 231 232 233
                        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.")
                        }
Don Gagne's avatar
Don Gagne committed
234 235
                    }

236
                    QGCLabel {
Don Gagne's avatar
Don Gagne committed
237
                        Layout.fillWidth:   true
238 239 240 241
                        wrapMode:           Text.WordWrap
                        color:              qgcPal.warningText
                        text:               qsTr("If you are changing batteries for Resume Mission do not disconnect from the vehicle.")
                        visible:            _guidedController.showResumeMission
Don Gagne's avatar
Don Gagne committed
242
                    }
243
                }
244 245 246 247
            }
        }
    }

Patrick José Pereira's avatar
Patrick José Pereira committed
248 249
    Window {
        id:             videoWindow
250 251
        width:          !mainIsMap ? _mapAndVideo.width  : _pipSize
        height:         !mainIsMap ? _mapAndVideo.height : _pipSize * (9/16)
Patrick José Pereira's avatar
Patrick José Pereira committed
252 253 254 255 256 257 258 259 260 261 262
        visible:        false

        Item {
            id:             videoItem
            anchors.fill:   parent
        }

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

265 266 267 268 269 270 271 272 273 274 275 276 277 278 279
    /* 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
280 281
    }

282
    QGCMapPalette { id: mapPal; lightColors: mainIsMap ? mainWindow.flightDisplayMap.isSatelliteMap : true }
283

284
    Item {
285
        id:             _mapAndVideo
286
        anchors.fill:   parent
287 288 289 290

        //-- Map View
        Item {
            id: _flightMapContainer
291
            z:  mainIsMap ? _mapAndVideo.z + 1 : _mapAndVideo.z + 2
292 293
            anchors.left:   _mapAndVideo.left
            anchors.bottom: _mapAndVideo.bottom
294 295 296
            visible:        mainIsMap || _isPipVisible && !QGroundControl.videoManager.fullScreen
            width:          mainIsMap ? _mapAndVideo.width  : _pipSize
            height:         mainIsMap ? _mapAndVideo.height : _pipSize * (9/16)
297 298 299 300 301 302 303 304 305 306 307 308 309 310
            states: [
                State {
                    name:   "pipMode"
                    PropertyChanges {
                        target:             _flightMapContainer
                        anchors.margins:    ScreenTools.defaultFontPixelHeight
                    }
                },
                State {
                    name:   "fullMode"
                    PropertyChanges {
                        target:             _flightMapContainer
                        anchors.margins:    0
                    }
311
                }
312 313
            ]
            FlightDisplayViewMap {
314
                id:                         _fMap
315 316
                anchors.fill:               parent
                guidedActionsController:    _guidedController
Gus Grubba's avatar
Gus Grubba committed
317
                missionController:          _planController
318 319
                flightWidgets:              flightDisplayViewWidgets
                rightPanelWidth:            ScreenTools.defaultFontPixelHeight * 9
320
                multiVehicleView:           !singleVehicleView.checked
321
                scaleState:                 (mainIsMap && flyViewOverlay.item) ? (flyViewOverlay.item.scaleState ? flyViewOverlay.item.scaleState : "bottomMode") : "bottomMode"
322 323
                Component.onCompleted: {
                    mainWindow.flightDisplayMap = _fMap
324
                    _fMap.adjustMapSize()
325
                }
326
            }
327
        }
328

329
        //-- Video View
330
        Item {
331
            id:             _flightVideo
332 333 334
            z:              mainIsMap ? _mapAndVideo.z + 2 : _mapAndVideo.z + 1
            width:          !mainIsMap ? _mapAndVideo.width  : _pipSize
            height:         !mainIsMap ? _mapAndVideo.height : _pipSize * (9/16)
335 336
            anchors.left:   _mapAndVideo.left
            anchors.bottom: _mapAndVideo.bottom
337
            visible:        QGroundControl.videoManager.hasVideo && (!mainIsMap || _isPipVisible)
338 339 340 341 342 343

            onParentChanged: {
                /* If video comes back from popup
                 * correct anchors.
                 * Such thing is not possible with ParentChange.
                 */
344
                if(parent == _mapAndVideo) {
345
                    // Do anchors again after popup
346 347
                    anchors.left =       _mapAndVideo.left
                    anchors.bottom =     _mapAndVideo.bottom
348
                    anchors.margins =    _toolsMargin
349 350 351
                }
            }

352 353 354 355
            states: [
                State {
                    name:   "pipMode"
                    PropertyChanges {
356
                        target:             _flightVideo
357
                        anchors.margins:    ScreenTools.defaultFontPixelHeight
Patrick José Pereira's avatar
Patrick José Pereira committed
358 359
                    }
                    PropertyChanges {
360 361
                        target:             _flightVideoPipControl
                        inPopup:            false
362 363 364 365 366
                    }
                },
                State {
                    name:   "fullMode"
                    PropertyChanges {
367
                        target:             _flightVideo
368 369
                        anchors.margins:    0
                    }
Patrick José Pereira's avatar
Patrick José Pereira committed
370
                    PropertyChanges {
371 372
                        target:             _flightVideoPipControl
                        inPopup:            false
Patrick José Pereira's avatar
Patrick José Pereira committed
373 374 375 376 377
                    }
                },
                State {
                    name: "popup"
                    StateChangeScript {
378 379
                        script: {
                            // Stop video, restart it again with Timer
Gus Grubba's avatar
Gus Grubba committed
380
                            // Avoiding crashes if ParentChange is not yet done
381 382 383
                            QGroundControl.videoManager.stopVideo()
                            videoPopUpTimer.running = true
                        }
Patrick José Pereira's avatar
Patrick José Pereira committed
384
                    }
385
                    PropertyChanges {
386 387
                        target:             _flightVideoPipControl
                        inPopup:            true
388 389 390 391
                    }
                },
                State {
                    name: "popup-finished"
Patrick José Pereira's avatar
Patrick José Pereira committed
392
                    ParentChange {
393 394 395 396 397 398
                        target:             _flightVideo
                        parent:             videoItem
                        x:                  0
                        y:                  0
                        width:              videoItem.width
                        height:             videoItem.height
Patrick José Pereira's avatar
Patrick José Pereira committed
399 400 401 402 403
                    }
                },
                State {
                    name: "unpopup"
                    StateChangeScript {
404 405 406 407
                        script: {
                            QGroundControl.videoManager.stopVideo()
                            videoPopUpTimer.running = true
                        }
Patrick José Pereira's avatar
Patrick José Pereira committed
408 409
                    }
                    ParentChange {
410 411
                        target:             _flightVideo
                        parent:             _mapAndVideo
Patrick José Pereira's avatar
Patrick José Pereira committed
412 413
                    }
                    PropertyChanges {
414 415
                        target:             _flightVideoPipControl
                        inPopup:             false
Patrick José Pereira's avatar
Patrick José Pereira committed
416
                    }
417
                }
418
            ]
419
            //-- Video Streaming
420
            FlightDisplayViewVideo {
Patrick José Pereira's avatar
Patrick José Pereira committed
421
                id:             videoStreaming
422 423 424 425
                anchors.fill:   parent
                visible:        QGroundControl.videoManager.isGStreamer
            }
            //-- UVC Video (USB Camera or Video Device)
426 427
            Loader {
                id:             cameraLoader
428 429
                anchors.fill:   parent
                visible:        !QGroundControl.videoManager.isGStreamer
430
                source:         visible ? (QGroundControl.videoManager.uvcEnabled ? "qrc:/qml/FlightDisplayViewUVC.qml" : "qrc:/qml/FlightDisplayViewDummy.qml") : ""
431
            }
dogmaphobic's avatar
dogmaphobic committed
432
        }
433 434 435 436

        QGCPipable {
            id:                 _flightVideoPipControl
            z:                  _flightVideo.z + 3
437 438
            width:              _pipSize
            height:             _pipSize * (9/16)
439 440
            anchors.left:       _mapAndVideo.left
            anchors.bottom:     _mapAndVideo.bottom
441
            anchors.margins:    ScreenTools.defaultFontPixelHeight
442
            visible:            QGroundControl.videoManager.hasVideo && !QGroundControl.videoManager.fullScreen && _flightVideo.state != "popup"
443 444
            isHidden:           !_isPipVisible
            isDark:             isBackgroundDark
445
            enablePopup:        mainIsMap
446
            onActivated: {
447
                mainIsMap = !mainIsMap
448
                setStates()
449
                _fMap.adjustMapSize()
450 451 452 453
            }
            onHideIt: {
                setPipVisibility(!state)
            }
Patrick José Pereira's avatar
Patrick José Pereira committed
454 455 456 457
            onPopup: {
                videoWindow.visible = true
                _flightVideo.state = "popup"
            }
458 459
            onNewWidth: {
                _pipSize = newWidth
Jacob Walser's avatar
Jacob Walser committed
460
            }
dogmaphobic's avatar
dogmaphobic committed
461
        }
Don Gagne's avatar
Don Gagne committed
462

463 464
        Row {
            id:                     singleMultiSelector
465 466
            anchors.topMargin:      ScreenTools.toolbarHeight + _toolsMargin
            anchors.rightMargin:    _toolsMargin
467 468
            anchors.right:          parent.right
            spacing:                ScreenTools.defaultFontPixelWidth
469
            z:                      _mapAndVideo.z + 4
470
            visible:                QGroundControl.multiVehicleManager.vehicles.count > 1 && QGroundControl.corePlugin.options.enableMultiVehicleList
471 472 473 474 475

            QGCRadioButton {
                id:             singleVehicleView
                text:           qsTr("Single")
                checked:        true
476
                textColor:      mapPal.text
477 478 479
            }

            QGCRadioButton {
480
                text:           qsTr("Multi-Vehicle")
481
                textColor:      mapPal.text
482 483 484
            }
        }

485
        FlightDisplayViewWidgets {
486
            id:                 flightDisplayViewWidgets
487
            z:                  _mapAndVideo.z + 4
488
            height:             availableHeight - (singleMultiSelector.visible ? singleMultiSelector.height + _toolsMargin : 0) - _toolsMargin
489
            anchors.left:       parent.left
490
            anchors.right:      altitudeSlider.visible ? altitudeSlider.left : parent.right
491
            anchors.bottom:     parent.bottom
492
            anchors.top:        singleMultiSelector.visible? singleMultiSelector.bottom : undefined
493
            useLightColors:     isBackgroundDark
494
            missionController:  _missionController
495
            visible:            singleVehicleView.checked && !QGroundControl.videoManager.fullScreen
496 497
        }

498 499 500 501 502
        //-------------------------------------------------------------------------
        //-- Loader helper for plugins to overlay elements over the fly view
        Loader {
            id:                 flyViewOverlay
            z:                  flightDisplayViewWidgets.z + 1
503
            visible:            !QGroundControl.videoManager.fullScreen
504
            height:             mainWindow.height - mainWindow.header.height
505 506 507 508 509
            anchors.left:       parent.left
            anchors.right:      altitudeSlider.visible ? altitudeSlider.left : parent.right
            anchors.bottom:     parent.bottom
        }

510
        MultiVehicleList {
511
            anchors.margins:            _toolsMargin
512 513 514 515
            anchors.top:                singleMultiSelector.bottom
            anchors.right:              parent.right
            anchors.bottom:             parent.bottom
            width:                      ScreenTools.defaultFontPixelWidth * 30
516
            visible:                    !singleVehicleView.checked && !QGroundControl.videoManager.fullScreen && QGroundControl.corePlugin.options.enableMultiVehicleList
517
            z:                          _mapAndVideo.z + 4
518
            guidedActionsController:    _guidedController
519
        }
dogmaphobic's avatar
dogmaphobic committed
520

521
        //-- Virtual Joystick
522
        Loader {
523
            id:                         virtualJoystickMultiTouch
524
            z:                          _mapAndVideo.z + 5
525
            width:                      parent.width  - (_flightVideoPipControl.width / 2)
526
            height:                     Math.min(mainWindow.height * 0.25, ScreenTools.defaultFontPixelWidth * 16)
Gus Grubba's avatar
Gus Grubba committed
527
            visible:                    (_virtualJoystick ? _virtualJoystick.value : false) && !QGroundControl.videoManager.fullScreen && !(activeVehicle ? activeVehicle.highLatencyLink : false)
528 529
            anchors.bottom:             _flightVideoPipControl.top
            anchors.bottomMargin:       ScreenTools.defaultFontPixelHeight * 2
530
            anchors.horizontalCenter:   flightDisplayViewWidgets.horizontalCenter
531
            source:                     "qrc:/qml/VirtualJoystick.qml"
Gus Grubba's avatar
Gus Grubba committed
532
            active:                     (_virtualJoystick ? _virtualJoystick.value : false) && !(activeVehicle ? activeVehicle.highLatencyLink : false)
Don Gagne's avatar
Don Gagne committed
533

534
            property bool useLightColors: isBackgroundDark
535 536
            // The default behaviour is not centralized throttle
            property bool centralizeThrottle: _virtualJoystickCentralized ? _virtualJoystickCentralized.value : false
537 538

            property Fact _virtualJoystick: QGroundControl.settingsManager.appSettings.virtualJoystick
539
            property Fact _virtualJoystickCentralized: QGroundControl.settingsManager.appSettings.virtualJoystickCentralized
Don Gagne's avatar
Don Gagne committed
540
        }
541 542

        ToolStrip {
Gus Grubba's avatar
Gus Grubba committed
543
            visible:            (activeVehicle ? activeVehicle.guidedModeSupported : true) && !QGroundControl.videoManager.fullScreen
544
            id:                 toolStrip
545

546
            anchors.leftMargin: isInstrumentRight() ? _toolsMargin : undefined
547
            anchors.left:       isInstrumentRight() ? _mapAndVideo.left : undefined
Gus Grubba's avatar
Gus Grubba committed
548
            anchors.rightMargin:isInstrumentRight() ? undefined : ScreenTools.defaultFontPixelWidth
549
            anchors.right:      isInstrumentRight() ? undefined : _mapAndVideo.right
550
            anchors.topMargin:  _toolsMargin
551
            anchors.top:        parent.top
552
            z:                  _mapAndVideo.z + 4
553
            maxHeight:          parent.height - toolStrip.y + (_flightVideo.visible ? (_flightVideo.y - parent.height) : 0)
554

555
            property bool _anyActionAvailable: _guidedController.showStartMission || _guidedController.showResumeMission || _guidedController.showChangeAlt || _guidedController.showLandAbort
556 557
            property var _actionModel: [
                {
558 559 560 561
                    title:      _guidedController.startMissionTitle,
                    text:       _guidedController.startMissionMessage,
                    action:     _guidedController.actionStartMission,
                    visible:    _guidedController.showStartMission
562
                },
Don Gagne's avatar
Don Gagne committed
563 564 565 566 567 568
                {
                    title:      _guidedController.continueMissionTitle,
                    text:       _guidedController.continueMissionMessage,
                    action:     _guidedController.actionContinueMission,
                    visible:    _guidedController.showContinueMission
                },
569
                {
570 571 572 573
                    title:      _guidedController.changeAltTitle,
                    text:       _guidedController.changeAltMessage,
                    action:     _guidedController.actionChangeAlt,
                    visible:    _guidedController.showChangeAlt
574 575
                },
                {
576 577 578 579
                    title:      _guidedController.landAbortTitle,
                    text:       _guidedController.landAbortMessage,
                    action:     _guidedController.actionLandAbort,
                    visible:    _guidedController.showLandAbort
580 581 582 583
                }
            ]

            model: [
584
                /*{
585 586
                    name:               "Plan",
                    iconSource:         "/qmlimages/Plan.svg",
Gus Grubba's avatar
Gus Grubba committed
587 588
                    buttonVisible:      true,
                    buttonEnabled:      true,
589
                },*/
590 591 592
                {
                    name:               "Checklist",
                    iconSource:         "/qmlimages/check.svg",
Gus Grubba's avatar
Gus Grubba committed
593 594
                    buttonVisible:      _useChecklist,
                    buttonEnabled:      _useChecklist && activeVehicle && !activeVehicle.armed,
595
                },
596
                {
Gus Grubba's avatar
Gus Grubba committed
597 598 599
                    name:               _guidedController.takeoffTitle,
                    iconSource:         "/res/takeoff.svg",
                    buttonVisible:      _guidedController.showTakeoff || !_guidedController.showLand,
600
                    buttonEnabled:      _guidedController.showTakeoff && _canArm,
Gus Grubba's avatar
Gus Grubba committed
601
                    action:             _guidedController.actionTakeoff
602 603
                },
                {
Gus Grubba's avatar
Gus Grubba committed
604 605 606 607 608
                    name:               _guidedController.landTitle,
                    iconSource:         "/res/land.svg",
                    buttonVisible:      _guidedController.showLand && !_guidedController.showTakeoff,
                    buttonEnabled:      _guidedController.showLand,
                    action:             _guidedController.actionLand
609 610
                },
                {
Gus Grubba's avatar
Gus Grubba committed
611 612 613 614 615
                    name:               _guidedController.rtlTitle,
                    iconSource:         "/res/rtl.svg",
                    buttonVisible:      true,
                    buttonEnabled:      _guidedController.showRTL,
                    action:             _guidedController.actionRTL
616 617
                },
                {
Gus Grubba's avatar
Gus Grubba committed
618 619 620 621 622
                    name:               _guidedController.pauseTitle,
                    iconSource:         "/res/pause-mission.svg",
                    buttonVisible:      _guidedController.showPause,
                    buttonEnabled:      _guidedController.showPause,
                    action:             _guidedController.actionPause
623 624
                },
                {
Gus Grubba's avatar
Gus Grubba committed
625 626 627
                    name:               qsTr("Action"),
                    iconSource:         "/res/action.svg",
                    buttonVisible:      !_guidedController.showPause,
628
                    buttonEnabled:      _anyActionAvailable && _canArm,
Gus Grubba's avatar
Gus Grubba committed
629
                    action:             -1
DonLakeFlyer's avatar
DonLakeFlyer committed
630
                }
631 632 633
            ]

            onClicked: {
634
                guidedActionsController.closeAll()
635
                /*if(index === 0) {
636
                    mainWindow.showPlanView()
637 638
                } else*/
                if(index === 0) {
639
                    checklistDropPanel.open()
640
                } else {
641 642 643 644 645 646 647
                    var action = model[index].action
                    if (action === -1) {
                        guidedActionList.model   = _actionModel
                        guidedActionList.visible = true
                    } else {
                        _guidedController.confirmAction(action)
                    }
648
                }
649

650 651 652 653
            }
        }

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

661
            onShowStartMissionChanged: {
662
                if (showStartMission && _canArm) {
663 664 665 666
                    confirmAction(actionStartMission)
                }
            }

667 668 669 670 671 672
            onShowContinueMissionChanged: {
                if (showContinueMission) {
                    confirmAction(actionContinueMission)
                }
            }

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

            /// Close all dialogs
            function closeAll() {
                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
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 769 770
    Popup {
        id:             checklistDropPanel
        x:              Math.round((mainWindow.width  - width)  * 0.5)
        y:              Math.round((mainWindow.height - height) * 0.5)
Gus Grubba's avatar
Gus Grubba committed
771 772
        height:         checkList.height
        width:          checkList.width
773 774 775 776
        modal:          true
        focus:          true
        closePolicy:    Popup.CloseOnEscape | Popup.CloseOnPressOutside
        background: Rectangle {
777 778 779
            anchors.fill:  parent
            color:      Qt.rgba(0,0,0,0)
            clip:       true
780
        }
781 782 783
        Loader {
            id:         checkList
            anchors.centerIn: parent
784
        }
785
    }
786

787
}