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


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

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

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

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

37 38
    property alias guidedController: guidedActionsController

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

41
    property var _activeVehicle:        QGroundControl.multiVehicleManager.activeVehicle
42 43
    property bool _mainIsMap:           QGroundControl.videoManager.hasVideo ? QGroundControl.loadBoolGlobalSetting(_mainIsMapKey,  true) : true
    property bool _isPipVisible:        QGroundControl.videoManager.hasVideo ? QGroundControl.loadBoolGlobalSetting(_PIPVisibleKey, true) : false
44 45 46
    property real _savedZoomLevel:      0
    property real _margins:             ScreenTools.defaultFontPixelWidth / 2
    property real _pipSize:             mainWindow.width * 0.2
47

Don Gagne's avatar
Don Gagne committed
48 49 50 51 52 53 54 55 56 57 58 59
    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"

60
    function setStates() {
61
        QGroundControl.saveBoolGlobalSetting(_mainIsMapKey, _mainIsMap)
62
        if(_mainIsMap) {
63 64 65 66 67 68 69 70
            //-- Adjust Margins
            _flightMapContainer.state   = "fullMode"
            _flightVideo.state          = "pipMode"
            //-- Save/Restore Map Zoom Level
            if(_savedZoomLevel != 0)
                _flightMap.zoomLevel = _savedZoomLevel
            else
                _savedZoomLevel = _flightMap.zoomLevel
71
        } else {
72 73 74 75 76 77
            //-- Adjust Margins
            _flightMapContainer.state   = "pipMode"
            _flightVideo.state          = "fullMode"
            //-- Set Map Zoom Level
            _savedZoomLevel = _flightMap.zoomLevel
            _flightMap.zoomLevel = _savedZoomLevel - 3
78
        }
Don Gagne's avatar
Don Gagne committed
79 80
    }

81 82 83
    function setPipVisibility(state) {
        _isPipVisible = state;
        QGroundControl.saveBoolGlobalSetting(_PIPVisibleKey, state)
84 85
    }

86
    function px4JoystickCheck() {
87
        if ( _activeVehicle && !_activeVehicle.supportsManualControl && (QGroundControl.settingsManager.appSettings.virtualJoystick.value || _activeVehicle.joystickEnabled)) {
88 89 90 91
            px4JoystickSupport.open()
        }
    }

92 93 94 95 96
    MissionController {
        id: flyMissionController
        Component.onCompleted: start(false /* editMode */)
    }

97 98
    MessageDialog {
        id:     px4JoystickSupport
99 100 101
        text:   qsTr("Joystick support requires MAVLink MANUAL_CONTROL support. ") +
                qsTr("The firmware you are running does not normally support this. ") +
                qsTr("It will only work if you have modified the firmware to add MANUAL_CONTROL support.")
102 103 104
    }

    Connections {
105
        target: QGroundControl.multiVehicleManager
106 107 108 109
        onActiveVehicleChanged: px4JoystickCheck()
    }

    Connections {
110 111
        target:         QGroundControl.settingsManager.appSettings.virtualJoystick
        onValueChanged: px4JoystickCheck()
112 113 114 115
    }

    onActiveVehicleJoystickEnabledChanged: px4JoystickCheck()

116 117
    Component.onCompleted: {
        setStates()
118
        px4JoystickCheck()
119 120 121
        if(QGroundControl.corePlugin.options.flyViewOverlay.toString().length) {
            flyViewOverlay.source = QGroundControl.corePlugin.options.flyViewOverlay
        }
122
    }
dogmaphobic's avatar
dogmaphobic committed
123

124 125
    QGCMapPalette { id: mapPal; lightColors: _mainIsMap ? _flightMap.isSatelliteMap : true }

126 127 128 129 130 131 132 133 134 135 136 137 138
    QGCViewPanel {
        id:             _panel
        anchors.fill:   parent

        //-- Map View
        //   For whatever reason, if FlightDisplayViewMap is the _panel item, changing
        //   width/height has no effect.
        Item {
            id: _flightMapContainer
            z:  _mainIsMap ? _panel.z + 1 : _panel.z + 2
            anchors.left:   _panel.left
            anchors.bottom: _panel.bottom
            visible:        _mainIsMap || _isPipVisible
139 140
            width:          _mainIsMap ? _panel.width  : _pipSize
            height:         _mainIsMap ? _panel.height : _pipSize * (9/16)
141 142 143 144 145 146 147 148 149 150 151 152 153 154
            states: [
                State {
                    name:   "pipMode"
                    PropertyChanges {
                        target:             _flightMapContainer
                        anchors.margins:    ScreenTools.defaultFontPixelHeight
                    }
                },
                State {
                    name:   "fullMode"
                    PropertyChanges {
                        target:             _flightMapContainer
                        anchors.margins:    0
                    }
155
                }
156 157
            ]
            FlightDisplayViewMap {
158 159 160 161 162 163 164
                id:                     _flightMap
                anchors.fill:           parent
                missionController:      flyMissionController
                guidedActionsController: guidedController
                flightWidgets:          flightDisplayViewWidgets
                rightPanelWidth:        ScreenTools.defaultFontPixelHeight * 9
                qgcView:                root
165
                scaleState:             (_mainIsMap && flyViewOverlay.item) ? (flyViewOverlay.item.scaleState ? flyViewOverlay.item.scaleState : "bottomMode") : "bottomMode"
166
            }
167
        }
168

169
        //-- Video View
170
        Item {
171 172
            id:             _flightVideo
            z:              _mainIsMap ? _panel.z + 2 : _panel.z + 1
173 174
            width:          !_mainIsMap ? _panel.width  : _pipSize
            height:         !_mainIsMap ? _panel.height : _pipSize * (9/16)
175 176
            anchors.left:   _panel.left
            anchors.bottom: _panel.bottom
177
            visible:        QGroundControl.videoManager.hasVideo && (!_mainIsMap || _isPipVisible)
178 179 180 181 182 183 184 185 186 187 188 189 190 191
            states: [
                State {
                    name:   "pipMode"
                    PropertyChanges {
                        target: _flightVideo
                        anchors.margins:    ScreenTools.defaultFontPixelHeight
                    }
                },
                State {
                    name:   "fullMode"
                    PropertyChanges {
                        target: _flightVideo
                        anchors.margins:    0
                    }
192
                }
193
            ]
194
            //-- Video Streaming
195 196 197 198 199
            FlightDisplayViewVideo {
                anchors.fill:   parent
                visible:        QGroundControl.videoManager.isGStreamer
            }
            //-- UVC Video (USB Camera or Video Device)
200 201
            Loader {
                id:             cameraLoader
202 203
                anchors.fill:   parent
                visible:        !QGroundControl.videoManager.isGStreamer
204
                source:         QGroundControl.videoManager.uvcEnabled ? "qrc:/qml/FlightDisplayViewUVC.qml" : "qrc:/qml/FlightDisplayViewDummy.qml"
205
            }
dogmaphobic's avatar
dogmaphobic committed
206
        }
207 208 209 210

        QGCPipable {
            id:                 _flightVideoPipControl
            z:                  _flightVideo.z + 3
211 212
            width:              _pipSize
            height:             _pipSize * (9/16)
213 214 215
            anchors.left:       _panel.left
            anchors.bottom:     _panel.bottom
            anchors.margins:    ScreenTools.defaultFontPixelHeight
216
            visible:            QGroundControl.videoManager.hasVideo
217 218 219 220 221 222 223 224 225
            isHidden:           !_isPipVisible
            isDark:             isBackgroundDark
            onActivated: {
                _mainIsMap = !_mainIsMap
                setStates()
            }
            onHideIt: {
                setPipVisibility(!state)
            }
dogmaphobic's avatar
dogmaphobic committed
226
        }
Don Gagne's avatar
Don Gagne committed
227

228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254
        Row {
            id:                     singleMultiSelector
            anchors.topMargin:      ScreenTools.toolbarHeight + _margins
            anchors.rightMargin:    _margins
            anchors.right:          parent.right
            anchors.top:            parent.top
            spacing:                ScreenTools.defaultFontPixelWidth
            z:                      _panel.z + 4
            visible:                QGroundControl.multiVehicleManager.vehicles.count > 1

            ExclusiveGroup { id: multiVehicleSelectorGroup }

            QGCRadioButton {
                id:             singleVehicleView
                exclusiveGroup: multiVehicleSelectorGroup
                text:           qsTr("Single")
                checked:        true
                color:          mapPal.text
            }

            QGCRadioButton {
                exclusiveGroup: multiVehicleSelectorGroup
                text:           qsTr("Multi-Vehicle (WIP)")
                color:          mapPal.text
            }
        }

255
        FlightDisplayViewWidgets {
256 257 258 259
            id:                 flightDisplayViewWidgets
            z:                  _panel.z + 4
            height:             ScreenTools.availableHeight
            anchors.left:       parent.left
260
            anchors.right:      altitudeSlider.visible ? altitudeSlider.left : parent.right
261 262
            anchors.bottom:     parent.bottom
            qgcView:            root
263
            useLightColors:     isBackgroundDark
264
            missionController:  _flightMap.missionController
265 266 267
            visible:            singleVehicleView.checked
        }

268 269 270 271 272 273 274 275 276 277 278
        //-------------------------------------------------------------------------
        //-- Loader helper for plugins to overlay elements over the fly view
        Loader {
            id:                 flyViewOverlay
            z:                  flightDisplayViewWidgets.z + 1
            height:             ScreenTools.availableHeight
            anchors.left:       parent.left
            anchors.right:      altitudeSlider.visible ? altitudeSlider.left : parent.right
            anchors.bottom:     parent.bottom
        }

279 280 281 282 283 284 285 286
        // Button to start/stop video recording
        Item {
            z:                  _flightVideoPipControl.z + 1
            anchors.margins:    ScreenTools.defaultFontPixelHeight / 2
            anchors.bottom:     _flightVideo.bottom
            anchors.right:      _flightVideo.right
            height:             ScreenTools.defaultFontPixelHeight * 2
            width:              height
287
            visible:            QGroundControl.videoManager.videoRunning && QGroundControl.videoManager.recordingEnabled
288 289 290 291 292 293
            opacity:            0.75

            Rectangle {
                anchors.top:        parent.top
                anchors.bottom:     parent.bottom
                width:              height
294
                radius:             QGroundControl.videoManager && QGroundControl.videoManager.videoReceiver && QGroundControl.videoManager.videoReceiver.recording ? 0 : height
295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310
                color:              "red"
            }

            QGCColoredImage {
                anchors.top:                parent.top
                anchors.bottom:             parent.bottom
                anchors.horizontalCenter:   parent.horizontalCenter
                width:                      height * 0.625
                sourceSize.width:           width
                source:                     "/qmlimages/CameraIcon.svg"
                fillMode:                   Image.PreserveAspectFit
                color:                      "white"
            }

            MouseArea {
                anchors.fill:   parent
311
                onClicked:      QGroundControl.videoManager.videoReceiver && QGroundControl.videoManager.videoReceiver.recording ? QGroundControl.videoManager.videoReceiver.stopRecording() : QGroundControl.videoManager.videoReceiver.startRecording()
312 313 314
            }
        }

315 316 317 318 319 320 321 322
        MultiVehicleList {
            anchors.margins:    _margins
            anchors.top:        singleMultiSelector.bottom
            anchors.right:      parent.right
            anchors.bottom:     parent.bottom
            width:              ScreenTools.defaultFontPixelWidth * 30
            visible:            !singleVehicleView.checked
            z:                  _panel.z + 4
323
        }
dogmaphobic's avatar
dogmaphobic committed
324

325

326
        //-- Virtual Joystick
327
        Loader {
328
            id:                         virtualJoystickMultiTouch
329 330
            z:                          _panel.z + 5
            width:                      parent.width  - (_flightVideoPipControl.width / 2)
331
            height:                     Math.min(ScreenTools.availableHeight * 0.25, ScreenTools.defaultFontPixelWidth * 16)
332
            visible:                    _virtualJoystick ? _virtualJoystick.value : false
333 334
            anchors.bottom:             _flightVideoPipControl.top
            anchors.bottomMargin:       ScreenTools.defaultFontPixelHeight * 2
335
            anchors.horizontalCenter:   flightDisplayViewWidgets.horizontalCenter
336
            source:                     "qrc:/qml/VirtualJoystick.qml"
337
            active:                     _virtualJoystick ? _virtualJoystick.value : false
Don Gagne's avatar
Don Gagne committed
338

339
            property bool useLightColors: isBackgroundDark
340 341

            property Fact _virtualJoystick: QGroundControl.settingsManager.appSettings.virtualJoystick
Don Gagne's avatar
Don Gagne committed
342
        }
343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395

        ToolStrip {
            id:                 toolStrip
            anchors.leftMargin: ScreenTools.defaultFontPixelWidth
            anchors.left:       _panel.left
            anchors.topMargin:  ScreenTools.toolbarHeight + _margins
            anchors.top:        _panel.top
            z:                  _panel.z + 4
            title:              qsTr("Fly")
            maxHeight:          (_flightVideo.visible ? _flightVideo.y : parent.height) - toolStrip.y
            buttonVisible:      [ guidedController.showTakeoff || !guidedController.showLand, guidedController.showLand, true, true, true, guidedController.smartShotsAvailable ]
            buttonEnabled:      [ guidedController.showTakeoff, guidedController.showLand, guidedController.showRTL, guidedController.showPause, _anyActionAvailable, _anySmartShotAvailable ]

            property bool _anyActionAvailable: guidedController.showEmergenyStop || guidedController.showStartMission || guidedController.showResumeMission || guidedController.showChangeAlt || guidedController.showLandAbort
            property bool _anySmartShotAvailable: guidedController.showOrbit
            property var _actionModel: [
                {
                    title:      guidedController.startMissionTitle,
                    text:       guidedController.startMissionMessage,
                    action:     guidedController.actionStartMission,
                    visible:    guidedController.showStartMission
                },
                {
                    title:      guidedController.resumeMissionTitle,
                    text:       guidedController.resumeMissionMessage,
                    action:     guidedController.actionResumeMission,
                    visible:    guidedController.showResumeMission
                },
                {
                    title:      guidedController.changeAltTitle,
                    text:       guidedController.changeAltMessage,
                    action:     guidedController.actionChangeAlt,
                    visible:    guidedController.showChangeAlt
                },
                {
                    title:      guidedController.landAbortTitle,
                    text:       guidedController.landAbortMessage,
                    action:     guidedController.actionLandAbort,
                    visible:    guidedController.showLandAbort
                }
            ]
            property var _smartShotModel: [
                {
                    title:      guidedController.orbitTitle,
                    text:       guidedController.orbitMessage,
                    action:     guidedController.actionOrbit,
                    visible:    guidedController.showOrbit
                }
            ]

            model: [
                {
                    name:       guidedController.takeoffTitle,
396
                    iconSource: "/res/takeoff.svg",
397 398 399 400
                    action:     guidedController.actionTakeoff
                },
                {
                    name:       guidedController.landTitle,
401
                    iconSource: "/res/land.svg",
402 403 404 405
                    action:     guidedController.actionLand
                },
                {
                    name:       guidedController.rtlTitle,
406
                    iconSource: "/res/rtl.svg",
407 408 409 410
                    action:     guidedController.actionRTL
                },
                {
                    name:       guidedController.pauseTitle,
411
                    iconSource: "/res/Pause.svg",
412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448
                    action:     guidedController.actionPause
                },
                {
                    name:       qsTr("Action"),
                    iconSource: "/qmlimages/MapCenter.svg",
                    action:     -1
                },
                /*
                  No firmware support any smart shots yet
                {
                    name:       qsTr("Smart"),
                    iconSource: "/qmlimages/MapCenter.svg",
                    action:     -1
                },
                */
            ]

            onClicked: {
                guidedActionConfirm.visible = false
                guidedActionList.visible = false
                altitudeSlider.visible = false
                var action = model[index].action
                if (action === -1) {
                    if (index == 4) {
                        guidedActionList.model = _actionModel
                        guidedActionList.visible = true
                    } else if (index == 5) {
                        guidedActionList.model = _smartShotModel
                        guidedActionList.visible = true
                    }
                } else {
                    guidedController.confirmAction(action)
                }
            }
        }

        GuidedActionsController {
449
            id:                 guidedActionsController
450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465
            missionController:  flyMissionController
            z:                  _flightVideoPipControl.z + 1

            onShowConfirmAction: {
                guidedActionConfirm.title =         title
                guidedActionConfirm.message =       message
                guidedActionConfirm.action =        action
                guidedActionConfirm.actionData =    actionData
                guidedActionConfirm.visible =       true
            }
        }

        Rectangle {
            id:                         guidedActionConfirm
            anchors.margins:            _margins
            anchors.bottom:             parent.bottom
466
            anchors.bottomMargin:       ScreenTools.defaultFontPixelHeight * 4
467
            anchors.horizontalCenter:   parent.horizontalCenter
468 469 470 471
            border.color:               qgcPal.alertBorder
            border.width:               1
            width:                      confirmColumn.width  + (_margins * 4)
            height:                     confirmColumn.height + (_margins * 4)
472
            radius:                     ScreenTools.defaultFontPixelHeight / 2
473
            color:                      qgcPal.alertBackground
474 475 476 477 478 479 480 481 482 483 484 485 486 487
            opacity:                    0.9
            z:                          guidedController.z
            visible:                    false

            property alias  title:      titleText.text
            property alias  message:    messageText.text
            property int    action
            property var    actionData

            property real _margins: ScreenTools.defaultFontPixelWidth

            Column {
                id:                 confirmColumn
                anchors.margins:    _margins
488
                anchors.centerIn:   parent
489 490 491 492
                spacing:            _margins

                QGCLabel {
                    id:                     titleText
493
                    color:                  qgcPal.alertText
494 495 496 497 498 499 500
                    anchors.left:           slider.left
                    anchors.right:          slider.right
                    horizontalAlignment:    Text.AlignHCenter
                }

                QGCLabel {
                    id:                     messageText
501
                    color:                  qgcPal.alertText
502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538
                    anchors.left:           slider.left
                    anchors.right:          slider.right
                    horizontalAlignment:    Text.AlignHCenter
                    wrapMode:               Text.WordWrap
                }

                // Action confirmation control
                SliderSwitch {
                    id:             slider
                    confirmText:    qsTr("Slide to confirm")
                    width:          Math.max(implicitWidth, ScreenTools.defaultFontPixelWidth * 30)

                    onAccept: {
                        guidedActionConfirm.visible = false
                        if (altitudeSlider.visible) {
                            guidedActionConfirm.actionData = altitudeSlider.getValue()
                            altitudeSlider.visible = false
                        }
                        guidedController.executeAction(guidedActionConfirm.action, guidedActionConfirm.actionData)
                    }

                    onReject: {
                        altitudeSlider.visible = false
                        guidedActionConfirm.visible = false
                    }
                }
            }

            QGCColoredImage {
                anchors.margins:    _margins
                anchors.top:        parent.top
                anchors.right:      parent.right
                width:              ScreenTools.defaultFontPixelHeight
                height:             width
                sourceSize.height:  width
                source:             "/res/XDelete.svg"
                fillMode:           Image.PreserveAspectFit
539
                color:              qgcPal.alertText
540 541 542 543 544 545 546 547 548 549 550 551 552 553
                QGCMouseArea {
                    fillItem:   parent
                    onClicked: {
                        altitudeSlider.visible = false
                        guidedActionConfirm.visible = false
                    }
                }
            }
        }

        Rectangle {
            id:                         guidedActionList
            anchors.margins:            _margins
            anchors.bottom:             parent.bottom
554
            anchors.bottomMargin:       ScreenTools.defaultFontPixelHeight * 4
555
            anchors.horizontalCenter:   parent.horizontalCenter
556 557
            width:                      actionColumn.width  + (_margins * 4)
            height:                     actionColumn.height + (_margins * 4)
558 559 560 561 562 563 564 565 566 567 568 569 570
            radius:                     _margins / 2
            color:                      qgcPal.window
            opacity:                    0.9
            z:                          guidedController.z
            visible:                    false

            property alias model: actionRepeater.model

            property real _margins: Math.round(ScreenTools.defaultFontPixelHeight * 0.66)

            ColumnLayout {
                id:                 actionColumn
                anchors.margins:    guidedActionList._margins
571
                anchors.centerIn:   parent
572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711
                spacing:            _margins

                QGCLabel {
                    text:               qsTr("Select Action")
                    Layout.alignment:   Qt.AlignHCenter
                }

                QGCFlickable {
                    contentWidth:           actionRow.width
                    contentHeight:          actionRow.height
                    Layout.minimumHeight:   actionRow.height
                    Layout.maximumHeight:   actionRow.height
                    Layout.minimumWidth:    _width
                    Layout.maximumWidth:    _width

                    property real _width: Math.min(root.width * 0.8, actionRow.width)

                    RowLayout {
                        id:         actionRow
                        spacing:    ScreenTools.defaultFontPixelHeight * 2

                        Repeater {
                            id: actionRepeater

                            ColumnLayout {
                                spacing:            ScreenTools.defaultFontPixelHeight / 2
                                visible:            modelData.visible
                                Layout.fillHeight:  true

                                QGCLabel {
                                    id:                     actionMessage
                                    text:                   modelData.text
                                    horizontalAlignment:    Text.AlignHCenter
                                    wrapMode:               Text.WordWrap
                                    Layout.minimumWidth:    _width
                                    Layout.maximumWidth:    _width
                                    Layout.fillHeight:      true

                                    property real _width: ScreenTools.defaultFontPixelWidth * 25
                                }

                                QGCButton {
                                    id:                         actionButton
                                    anchors.horizontalCenter:   parent.horizontalCenter
                                    text:                       modelData.title

                                    onClicked: {
                                        if (modelData.action === guidedController.actionChangeAlt) {
                                            altitudeSlider.visible = true
                                        }
                                        guidedActionList.visible = false
                                        guidedController.confirmAction(modelData.action)
                                    }
                                }
                            }
                        }
                    }
                }
            }

            QGCColoredImage {
                anchors.margins:    _margins
                anchors.top:        parent.top
                anchors.right:      parent.right
                width:              ScreenTools.defaultFontPixelHeight
                height:             width
                sourceSize.height:  width
                source:             "/res/XDelete.svg"
                fillMode:           Image.PreserveAspectFit
                color:              qgcPal.text

                QGCMouseArea {
                    fillItem:   parent
                    onClicked:  guidedActionList.visible = false
                }
            }
        }

        //-- Altitude slider
        Rectangle {
            id:                 altitudeSlider
            anchors.margins:    _margins
            anchors.right:      parent.right
            anchors.topMargin:  ScreenTools.toolbarHeight + _margins
            anchors.top:        parent.top
            anchors.bottom:     parent.bottom
            z:                  guidedController.z
            radius:             ScreenTools.defaultFontPixelWidth / 2
            width:              ScreenTools.defaultFontPixelWidth * 10
            color:              qgcPal.window
            visible:            false

            function setValue(value) {
                altSlider.value = value
            }

            function getValue() {
                return altSlider.value
            }

            Column {
                id:                 headerColumn
                anchors.margins:    _margins
                anchors.top:        parent.top
                anchors.left:       parent.left
                anchors.right:      parent.right

                QGCLabel {
                    anchors.horizontalCenter:   parent.horizontalCenter
                    text:                       altSlider.value >=0 ? qsTr("Up") : qsTr("Down")
                }

                QGCLabel {
                    id:                         altField
                    anchors.horizontalCenter:   parent.horizontalCenter
                    text:                       Math.abs(altSlider.value.toFixed(1)) + " " + QGroundControl.appSettingsDistanceUnitsString
                }
            }

            QGCSlider {
                id:                 altSlider
                anchors.margins:    _margins
                anchors.top:        headerColumn.bottom
                anchors.bottom:     parent.bottom
                anchors.left:       parent.left
                anchors.right:      parent.right
                orientation:        Qt.Vertical
                minimumValue:       QGroundControl.metersToAppSettingsDistanceUnits(-10)
                maximumValue:       QGroundControl.metersToAppSettingsDistanceUnits(10)
                indicatorCentered:  true
                rotation:           180

                // We want slide up to be positive values
                transform: Rotation {
                    origin.x:   altSlider.width / 2
                    origin.y:   altSlider.height / 2
                    angle:      180
                }
            }
        }
Don Gagne's avatar
Don Gagne committed
712
    }
713
}