MissionEditor.qml 36.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.
 *
 ****************************************************************************/
Don Gagne's avatar
Don Gagne committed
9 10


Don Gagne's avatar
Don Gagne committed
11 12 13 14 15
import QtQuick          2.4
import QtQuick.Controls 1.3
import QtQuick.Dialogs  1.2
import QtLocation       5.3
import QtPositioning    5.3
dogmaphobic's avatar
dogmaphobic committed
16
import QtQuick.Layouts  1.2
Don Gagne's avatar
Don Gagne committed
17

18
import QGroundControl               1.0
Don Gagne's avatar
Don Gagne committed
19 20 21 22
import QGroundControl.FlightMap     1.0
import QGroundControl.ScreenTools   1.0
import QGroundControl.Controls      1.0
import QGroundControl.Palette       1.0
Don Gagne's avatar
Don Gagne committed
23
import QGroundControl.Mavlink       1.0
24
import QGroundControl.Controllers   1.0
Don Gagne's avatar
Don Gagne committed
25 26

/// Mission Editor
Don Gagne's avatar
Don Gagne committed
27

Don Gagne's avatar
Don Gagne committed
28
QGCView {
29 30
    id:         _root

31
    viewPanel:          panel
Don Gagne's avatar
Don Gagne committed
32

33
    // zOrder comes from the Loader in MainWindow.qml
Gus Grubba's avatar
Gus Grubba committed
34
    z: QGroundControl.zOrderTopMost
35

36 37 38 39 40 41 42 43 44
    readonly property int       _decimalPlaces:         8
    readonly property real      _horizontalMargin:      ScreenTools.defaultFontPixelWidth  / 2
    readonly property real      _margin:                ScreenTools.defaultFontPixelHeight * 0.5
    readonly property var       _activeVehicle:         QGroundControl.multiVehicleManager.activeVehicle
    readonly property real      _rightPanelWidth:       Math.min(parent.width / 3, ScreenTools.defaultFontPixelWidth * 30)
    readonly property real      _rightPanelOpacity:     0.8
    readonly property int       _toolButtonCount:       6
    readonly property string    _autoSyncKey:           "AutoSync"
    readonly property real      _toolButtonTopMargin:   parent.height - ScreenTools.availableHeight + (ScreenTools.defaultFontPixelHeight / 2)
45
    readonly property int       _addMissionItemsButtonAutoOffTimeout:   10000
46
    readonly property var       _defaultVehicleCoordinate:   QtPositioning.coordinate(37.803784, -122.462276)
47

48

Don Gagne's avatar
Don Gagne committed
49
    property bool   _syncNeeded:            controller.visualItems.dirty // Unsaved changes, visible to parent container
50
    property var    _visualItems:           controller.visualItems
Don Gagne's avatar
Don Gagne committed
51
    property var    _currentMissionItem
52
    property int    _currentMissionIndex:   0
53 54
    property bool   _firstVehiclePosition:  true
    property var    activeVehiclePosition:  _activeVehicle ? _activeVehicle.coordinate : QtPositioning.coordinate()
55
    property bool   _lightWidgetBorders:    editorMap.isSatelliteMap
56

57
    onActiveVehiclePositionChanged: updateMapToVehiclePosition()
58

59
    Connections {
60
        target: QGroundControl.multiVehicleManager
61 62 63 64 65 66

        onActiveVehicleChanged: {
            // When the active vehicle changes we need to allow the first vehicle position to move the map again
            _firstVehiclePosition = true
            updateMapToVehiclePosition()
        }
67
    }
68 69

    function updateMapToVehiclePosition() {
70
        if (_activeVehicle && _activeVehicle.coordinateValid && _activeVehicle.coordinate.isValid && _firstVehiclePosition) {
71 72
            _firstVehiclePosition = false
            editorMap.center = _activeVehicle.coordinate
73 74 75
        }
    }

76 77 78 79 80
    function loadFromVehicle() {
        controller.getMissionItems()
    }

    function loadFromFile() {
81
        if (ScreenTools.isMobile) {
82
            _root.showDialog(mobileFilePicker, qsTr("Select Mission File"), _root.showDialogDefaultWidth, StandardButton.Yes | StandardButton.Cancel)
83
        } else {
Don Gagne's avatar
Don Gagne committed
84
            controller.loadMissionFromFilePicker()
85
            fitViewportToMissionItems()
86
            _currentMissionItem = _visualItems.get(0)
87 88 89 90 91
        }
    }

    function saveToFile() {
        if (ScreenTools.isMobile) {
92
            _root.showDialog(mobileFileSaver, qsTr("Save Mission File"), _root.showDialogDefaultWidth, StandardButton.Save | StandardButton.Cancel)
93
        } else {
Don Gagne's avatar
Don Gagne committed
94
            controller.saveMissionToFilePicker()
95
        }
96 97 98 99 100 101 102 103 104 105 106 107
    }

    function normalizeLat(lat) {
        // Normalize latitude to range: 0 to 180, S to N
        return lat + 90.0
    }

    function normalizeLon(lon) {
        // Normalize longitude to range: 0 to 360, W to E
        return lon  + 180.0
    }

108
    /// Fix the map viewport to the current mission items.
109
    function fitViewportToMissionItems() {
110 111
        if (_visualItems.count == 1) {
            editorMap.center = _visualItems.get(0).coordinate
112
        } else {
113
            var missionItem = _visualItems.get(0)
114 115 116 117 118
            var north = normalizeLat(missionItem.coordinate.latitude)
            var south = north
            var east = normalizeLon(missionItem.coordinate.longitude)
            var west = east

119 120
            for (var i=1; i<_visualItems.count; i++) {
                missionItem = _visualItems.get(i)
121

122
                if (missionItem.specifiesCoordinate && !missionItem.isStandaloneCoordinate) {
123 124 125 126 127 128 129 130
                    var lat = normalizeLat(missionItem.coordinate.latitude)
                    var lon = normalizeLon(missionItem.coordinate.longitude)

                    north = Math.max(north, lat)
                    south = Math.min(south, lat)
                    east = Math.max(east, lon)
                    west = Math.min(west, lon)
                }
131
            }
132
            editorMap.visibleRegion = QtPositioning.rectangle(QtPositioning.coordinate(north - 90.0, west - 180.0), QtPositioning.coordinate(south - 90.0, east - 180.0))
133 134 135
        }
    }

136
    MissionController {
137
        id:         controller
138

139 140
        Component.onCompleted: {
            start(true /* editMode */)
141
            setCurrentItem(0)
142 143
        }

Don Gagne's avatar
Don Gagne committed
144
        /*
145 146
        FIXME: autoSync is temporarily disconnected since it's still buggy

147 148 149
        autoSync:   QGroundControl.flightMapSettings.loadMapSetting(editorMap.mapName, _autoSyncKey, true)

        onAutoSyncChanged:      QGroundControl.flightMapSettings.saveMapSetting(editorMap.mapName, _autoSyncKey, autoSync)
150
*/
151

152
        onVisualItemsChanged: itemDragger.clearItem()
153
        onNewItemsFromVehicle: fitViewportToMissionItems()
154
    }
155

156
    QGCPalette { id: qgcPal; colorGroupEnabled: enabled }
Don Gagne's avatar
Don Gagne committed
157

158 159 160 161 162 163
    ExclusiveGroup {
        id: _mapTypeButtonsExclusiveGroup
    }

    ExclusiveGroup {
        id: _dropButtonsExclusiveGroup
164 165
    }

166
    function setCurrentItem(sequenceNumber) {
Don Gagne's avatar
Don Gagne committed
167
        _currentMissionItem = undefined
168
        for (var i=0; i<_visualItems.count; i++) {
169 170 171
            var visualItem = _visualItems.get(i)
            if (visualItem.sequenceNumber == sequenceNumber) {
                _currentMissionItem = visualItem
Don Gagne's avatar
Don Gagne committed
172
                _currentMissionItem.isCurrentItem = true
173
                _currentMissionIndex = i
Don Gagne's avatar
Don Gagne committed
174
            } else {
175
                visualItem.isCurrentItem = false
Don Gagne's avatar
Don Gagne committed
176
            }
177 178 179
        }
    }

180 181
    property int _moveDialogMissionItemIndex

182 183 184
    Component {
        id: mobileFilePicker

Don Gagne's avatar
Don Gagne committed
185 186 187 188 189 190 191
        QGCMobileFileDialog {
            openDialog:     true
            fileExtension:  QGroundControl.missionFileExtension

            onFilenameReturned: {
                controller.loadMissionFromFile(filename)
                fitViewportToMissionItems()
192
                _currentMissionItem = _visualItems.get(0)
193 194 195 196 197 198 199
            }
        }
    }

    Component {
        id: mobileFileSaver

Don Gagne's avatar
Don Gagne committed
200 201 202
        QGCMobileFileDialog {
            openDialog:     false
            fileExtension:  QGroundControl.missionFileExtension
203

Don Gagne's avatar
Don Gagne committed
204 205
            onFilenameReturned: {
                controller.saveMissionToFile(filename)
206 207 208 209
            }
        }
    }

210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232
    Component {
        id: moveDialog

        QGCViewDialog {
            function accept() {
                var toIndex = toCombo.currentIndex

                if (toIndex == 0) {
                    toIndex = 1
                }
                controller.moveMissionItem(_moveDialogMissionItemIndex, toIndex)
                hideDialog()
            }

            Column {
                anchors.left:   parent.left
                anchors.right:  parent.right
                spacing:        ScreenTools.defaultFontPixelHeight

                QGCLabel {
                    anchors.left:   parent.left
                    anchors.right:  parent.right
                    wrapMode:       Text.WordWrap
233
                    text:           qsTr("Move the selected mission item to the be after following mission item:")
234 235 236 237
                }

                QGCComboBox {
                    id:             toCombo
238
                    model:          _visualItems.count
239 240 241 242 243 244
                    currentIndex:   _moveDialogMissionItemIndex
                }
            }
        }
    }

Don Gagne's avatar
Don Gagne committed
245 246
    QGCViewPanel {
        id:             panel
247 248 249 250
        height:         ScreenTools.availableHeight
        anchors.bottom: parent.bottom
        anchors.left:   parent.left
        anchors.right:  parent.right
Don Gagne's avatar
Don Gagne committed
251

Don Gagne's avatar
Don Gagne committed
252
        Item {
Don Gagne's avatar
Don Gagne committed
253 254
            anchors.fill: parent

Don Gagne's avatar
Don Gagne committed
255 256
            FlightMap {
                id:             editorMap
257 258 259 260
                height:         _root.height
                anchors.bottom: parent.bottom
                anchors.left:   parent.left
                anchors.right:  parent.right
Don Gagne's avatar
Don Gagne committed
261
                mapName:        "MissionEditor"
262

263 264
                signal mapClicked(var coordinate)

265 266
                readonly property real animationDuration: 500

267 268 269
                // Initial map position duplicates Fly view position
                Component.onCompleted: editorMap.center = QGroundControl.flightMapPosition

270 271 272 273 274 275 276
                Behavior on zoomLevel {
                    NumberAnimation {
                        duration:       editorMap.animationDuration
                        easing.type:    Easing.InOutQuad
                    }
                }

277 278
                QGCMapPalette { id: mapPal; lightColors: editorMap.isSatelliteMap }

Don Gagne's avatar
Don Gagne committed
279
                MouseArea {
280 281
                    //-- It's a whole lot faster to just fill parent and deal with top offset below
                    //   than computing the coordinate offset.
Don Gagne's avatar
Don Gagne committed
282 283
                    anchors.fill: parent
                    onClicked: {
284 285 286 287 288 289 290 291 292 293 294 295 296
                        //-- Don't pay attention to items beneath the toolbar.
                        var topLimit = parent.height - ScreenTools.availableHeight
                        if(mouse.y >= topLimit) {
                            var coordinate = editorMap.toCoordinate(Qt.point(mouse.x, mouse.y))
                            coordinate.latitude = coordinate.latitude.toFixed(_decimalPlaces)
                            coordinate.longitude = coordinate.longitude.toFixed(_decimalPlaces)
                            coordinate.altitude = coordinate.altitude.toFixed(_decimalPlaces)
                            if (addMissionItemsButton.checked) {
                                var sequenceNumber = controller.insertSimpleMissionItem(coordinate, controller.visualItems.count)
                                setCurrentItem(sequenceNumber)
                            } else {
                                editorMap.mapClicked(coordinate)
                            }
297
                        }
Don Gagne's avatar
Don Gagne committed
298
                    }
Don Gagne's avatar
Don Gagne committed
299
                }
Don Gagne's avatar
Don Gagne committed
300

301
                // We use this item to support dragging since dragging a MapQuickItem just doesn't seem to work
Don Gagne's avatar
Don Gagne committed
302 303 304 305
                Rectangle {
                    id:             itemDragger
                    x:              missionItemIndicator ? (missionItemIndicator.x + missionItemIndicator.anchorPoint.x - (itemDragger.width / 2)) : 100
                    y:              missionItemIndicator ? (missionItemIndicator.y + missionItemIndicator.anchorPoint.y - (itemDragger.height / 2)) : 100
306 307
                    width:          ScreenTools.defaultFontPixelHeight * 2
                    height:         ScreenTools.defaultFontPixelHeight * 2
Don Gagne's avatar
Don Gagne committed
308 309 310
                    color:          "transparent"
                    visible:        false
                    z:              QGroundControl.zOrderMapItems + 1    // Above item icons
311 312 313

                    property var    missionItem
                    property var    missionItemIndicator
314 315 316 317 318 319 320 321 322 323 324 325 326 327 328
                    property bool   preventCoordinateBindingLoop: false

                    onXChanged: liveDrag()
                    onYChanged: liveDrag()

                    function liveDrag() {
                        if (!itemDragger.preventCoordinateBindingLoop && Drag.active) {
                            var point = Qt.point(itemDragger.x + (itemDragger.width  / 2), itemDragger.y + (itemDragger.height / 2))
                            var coordinate = editorMap.toCoordinate(point)
                            coordinate.altitude = itemDragger.missionItem.coordinate.altitude
                            itemDragger.preventCoordinateBindingLoop = true
                            itemDragger.missionItem.coordinate = coordinate
                            itemDragger.preventCoordinateBindingLoop = false
                        }
                    }
Don Gagne's avatar
Don Gagne committed
329

330
                    function clearItem() {
Don Gagne's avatar
Don Gagne committed
331 332 333 334 335
                        itemDragger.visible = false
                        itemDragger.missionItem = undefined
                        itemDragger.missionItemIndicator = undefined
                    }

336 337 338 339 340 341 342 343
                    Drag.active:    itemDrag.drag.active
                    Drag.hotSpot.x: width  / 2
                    Drag.hotSpot.y: height / 2

                    MouseArea {
                        id:             itemDrag
                        anchors.fill:   parent
                        drag.target:    parent
Don Gagne's avatar
Don Gagne committed
344 345 346 347
                        drag.minimumX:  0
                        drag.minimumY:  0
                        drag.maximumX:  itemDragger.parent.width - parent.width
                        drag.maximumY:  itemDragger.parent.height - parent.height
Don Gagne's avatar
Don Gagne committed
348
                    }
349
                }
350

351
                // Add the complex mission item polygon to the map
352
                MapItemView {
Don Gagne's avatar
Don Gagne committed
353 354
                    model: controller.complexVisualItems
                    delegate: MapPolygon {
355 356 357 358 359 360
                        color:      'green'
                        path:       object.polygonPath
                        opacity:    0.5
                    }
                }

361 362 363 364 365 366
                // Add the complex mission item grid to the map
                MapItemView {
                    model: controller.complexVisualItems

                    delegate: MapPolyline {
                        line.color: "white"
367
                        line.width: 2
368 369 370 371
                        path:       object.gridPoints
                    }
                }

372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387
                // Add the complex mission item exit coordinates
                MapItemView {
                    model:      controller.complexVisualItems
                    delegate:   exitCoordinateComponent
                }

                Component {
                    id: exitCoordinateComponent

                    MissionItemIndicator {
                        coordinate:     object.exitCoordinate
                        z:              QGroundControl.zOrderMapItems
                        missionItem:    object
                        sequenceNumber: object.lastSequenceNumber
                        visible:        object.specifiesCoordinate
                    }
Don Gagne's avatar
Don Gagne committed
388 389
                }

390 391 392 393 394 395
                // Add the simple mission items to the map
                MapItemView {
                    model:      controller.visualItems
                    delegate:   missionItemComponent
                }

Don Gagne's avatar
Don Gagne committed
396
                Component {
397
                    id: missionItemComponent
Don Gagne's avatar
Don Gagne committed
398 399 400 401

                    MissionItemIndicator {
                        id:             itemIndicator
                        coordinate:     object.coordinate
402
                        visible:        object.specifiesCoordinate
Don Gagne's avatar
Don Gagne committed
403
                        z:              QGroundControl.zOrderMapItems
404
                        missionItem:    object
405
                        sequenceNumber: object.sequenceNumber
Don Gagne's avatar
Don Gagne committed
406

407 408 409
                        //-- If you don't want to allow selecting items beneath the
                        //   toolbar, the code below has to check and see if mouse.y
                        //   is greater than (map.height - ScreenTools.availableHeight)
Don Gagne's avatar
Don Gagne committed
410 411
                        onClicked: setCurrentItem(object.sequenceNumber)

412 413
                        function updateItemIndicator() {
                            if (object.isCurrentItem && itemIndicator.visible && object.specifiesCoordinate && object.isSimpleItem) {
414 415 416 417
                                // Setup our drag item
                                itemDragger.visible = true
                                itemDragger.missionItem = Qt.binding(function() { return object })
                                itemDragger.missionItemIndicator = Qt.binding(function() { return itemIndicator })
Don Gagne's avatar
Don Gagne committed
418 419 420
                            }
                        }

421 422 423
                        Connections {
                            target: object

424 425
                            onIsCurrentItemChanged:         updateItemIndicator()
                            onSpecifiesCoordinateChanged:   updateItemIndicator()
426 427
                        }

Don Gagne's avatar
Don Gagne committed
428 429 430 431 432 433 434 435 436
                        // These are the non-coordinate child mission items attached to this item
                        Row {
                            anchors.top:    parent.top
                            anchors.left:   parent.right

                            Repeater {
                                model: object.childItems

                                delegate: MissionItemIndexLabel {
437
                                    label:          object.abbreviation
Don Gagne's avatar
Don Gagne committed
438 439 440 441 442 443 444 445
                                    isCurrentItem:  object.isCurrentItem
                                    z:              2

                                    onClicked: setCurrentItem(object.sequenceNumber)
                                }
                            }
                        }
                    }
446 447 448
                }

                // Add lines between waypoints
449 450
                MissionLineView {
                    model:          controller.waypointLines
Don Gagne's avatar
Don Gagne committed
451 452
                }

Don Gagne's avatar
Don Gagne committed
453 454
                // Add the vehicles to the map
                MapItemView {
455
                    model: QGroundControl.multiVehicleManager.vehicles
Don Gagne's avatar
Don Gagne committed
456 457 458 459 460 461 462 463 464 465
                    delegate:
                        VehicleMapItem {
                                vehicle:        object
                                coordinate:     object.coordinate
                                isSatellite:    editorMap.isSatelliteMap
                                size:           ScreenTools.defaultFontPixelHeight * 5
                                z:              QGroundControl.zOrderMapItems - 1
                        }
                }

466
                // Mission Item Editor
Don Gagne's avatar
Don Gagne committed
467
                Item {
468
                    id:             missionItemEditor
469
                    height:         ScreenTools.availableHeight
470 471 472 473
                    anchors.bottom: parent.bottom
                    anchors.right:  parent.right
                    width:          _rightPanelWidth
                    opacity:        _rightPanelOpacity
Gus Grubba's avatar
Gus Grubba committed
474
                    z:              QGroundControl.zOrderTopMost
475

Don Gagne's avatar
Don Gagne committed
476 477 478 479 480 481 482
                    MouseArea {
                         // This MouseArea prevents the Map below it from getting Mouse events. Without this
                         // things like mousewheel will scroll the Flickable and then scroll the map as well.
                         anchors.fill:       editorListView
                         onWheel:            wheel.accepted = true
                     }

483
                    ListView {
484 485 486 487
                        id:             editorListView
                        anchors.left:   parent.left
                        anchors.right:  parent.right
                        anchors.top:    parent.top
488
                        height:         parent.height
489 490
                        spacing:        _margin / 2
                        orientation:    ListView.Vertical
491
                        model:          controller.visualItems
492
                        cacheBuffer:    height * 2
493
                        clip:           true
494
                        currentIndex:   _currentMissionIndex
495 496
                        highlightMoveDuration: 250

497
                        delegate: MissionItemEditor {
498 499
                            missionItem:    object
                            width:          parent.width
Don Gagne's avatar
Don Gagne committed
500
                            qgcView:        _root
501
                            readOnly:       false
502 503 504 505

                            onClicked:  setCurrentItem(object.sequenceNumber)

                            onRemove: {
506
                                itemDragger.clearItem()
haigithub's avatar
haigithub committed
507
                                controller.removeMissionItem(index)
508 509
                            }

510
                            onInsert: {
511
                                var sequenceNumber = controller.insertSimpleMissionItem(editorMap.center, insertAfterIndex)
512 513 514
                                setCurrentItem(sequenceNumber)
                            }

515
                            onMoveHomeToMapCenter: controller.visualItems.get(0).coordinate = editorMap.center
516
                        }
517 518 519
                    } // ListView
                } // Item - Mission Item editor

520 521 522 523 524 525 526 527 528 529 530
                //-- Dismiss Drop Down (if any)
                MouseArea {
                    anchors.fill:   parent
                    enabled:        _dropButtonsExclusiveGroup.current != null
                    onClicked: {
                        if(_dropButtonsExclusiveGroup.current)
                            _dropButtonsExclusiveGroup.current.checked = false
                        _dropButtonsExclusiveGroup.current = null
                    }
                }

531 532 533 534 535 536 537 538 539 540
                QGCLabel {
                    id:         planLabel
                    text:       qsTr("Plan")
                    color:      mapPal.text
                    visible:    !ScreenTools.isShortScreen
                    anchors.topMargin:          _toolButtonTopMargin
                    anchors.horizontalCenter:   toolColumn.horizontalCenter
                    anchors.top:                parent.top
                }

541 542
                //-- Vertical Tool Buttons
                Column {
543
                    id:                 toolColumn
544 545
                    anchors.topMargin:  ScreenTools.isShortScreen ? _toolButtonTopMargin : ScreenTools.defaultFontPixelHeight / 2
                    anchors.leftMargin: ScreenTools.defaultFontPixelHeight
546
                    anchors.left:       parent.left
547
                    anchors.top:        ScreenTools.isShortScreen ? parent.top : planLabel.bottom
548
                    spacing:            ScreenTools.defaultFontPixelHeight
Don Gagne's avatar
Don Gagne committed
549
                    z:                  QGroundControl.zOrderWidgets
550 551

                    RoundButton {
552 553 554
                        id:             addMissionItemsButton
                        buttonImage:    "/qmlimages/MapAddMission.svg"
                        lightBorders:   _lightWidgetBorders
555 556
                    }

557
                    RoundButton {
558 559 560
                        id:             addShapeButton
                        buttonImage:    "/qmlimages/MapDrawShape.svg"
                        lightBorders:   _lightWidgetBorders
561 562 563 564 565 566

                        onClicked: {
                            var coordinate = editorMap.center
                            coordinate.latitude = coordinate.latitude.toFixed(_decimalPlaces)
                            coordinate.longitude = coordinate.longitude.toFixed(_decimalPlaces)
                            coordinate.altitude = coordinate.altitude.toFixed(_decimalPlaces)
567 568
                            var sequenceNumber = controller.insertComplexMissionItem(coordinate, controller.visualItems.count)
                            setCurrentItem(sequenceNumber)
569
                            checked = false
570
                            addMissionItemsButton.checked = false
571 572 573
                        }
                    }

574 575 576
                    DropButton {
                        id:                 syncButton
                        dropDirection:      dropRight
Don Gagne's avatar
Don Gagne committed
577
                        buttonImage:        _syncNeeded ? "/qmlimages/MapSyncChanged.svg" : "/qmlimages/MapSync.svg"
578 579 580
                        viewportMargins:    ScreenTools.defaultFontPixelWidth / 2
                        exclusiveGroup:     _dropButtonsExclusiveGroup
                        dropDownComponent:  syncDropDownComponent
581 582
                        enabled:            !controller.syncInProgress
                        rotateImage:        controller.syncInProgress
583
                        lightBorders:       _lightWidgetBorders
584 585
                    }

586 587 588 589 590 591
                    DropButton {
                        id:                 centerMapButton
                        dropDirection:      dropRight
                        buttonImage:        "/qmlimages/MapCenter.svg"
                        viewportMargins:    ScreenTools.defaultFontPixelWidth / 2
                        exclusiveGroup:     _dropButtonsExclusiveGroup
592
                        lightBorders:       _lightWidgetBorders
593

594 595
                        dropDownComponent: Component {
                            Column {
dogmaphobic's avatar
dogmaphobic committed
596
                                spacing: ScreenTools.defaultFontPixelWidth * 0.5
597
                                QGCLabel { text: qsTr("Center map:") }
598 599 600
                                Row {
                                    spacing: ScreenTools.defaultFontPixelWidth
                                    QGCButton {
601
                                        text: qsTr("Home")
dogmaphobic's avatar
dogmaphobic committed
602
                                        width:  ScreenTools.defaultFontPixelWidth * 10
603 604
                                        onClicked: {
                                            centerMapButton.hideDropDown()
605
                                            editorMap.center = controller.visualItems.get(0).coordinate
606
                                        }
607
                                    }
608
                                    QGCButton {
609
                                        text: qsTr("Mission")
dogmaphobic's avatar
dogmaphobic committed
610
                                        width:  ScreenTools.defaultFontPixelWidth * 10
611 612 613 614
                                        onClicked: {
                                            centerMapButton.hideDropDown()
                                            fitViewportToMissionItems()
                                        }
615
                                    }
616
                                    QGCButton {
617
                                        text:       qsTr("Vehicle")
dogmaphobic's avatar
dogmaphobic committed
618
                                        width:      ScreenTools.defaultFontPixelWidth * 10
619
                                        enabled:    activeVehicle && activeVehicle.latitude != 0 && activeVehicle.longitude != 0
620
                                        property var activeVehicle: _activeVehicle
621 622
                                        onClicked: {
                                            centerMapButton.hideDropDown()
623
                                            editorMap.center = activeVehicle.coordinate
624
                                        }
625 626 627 628 629 630
                                    }
                                }
                            }
                        }
                    }

631 632 633 634 635 636
                    DropButton {
                        id:                 mapTypeButton
                        dropDirection:      dropRight
                        buttonImage:        "/qmlimages/MapType.svg"
                        viewportMargins:    ScreenTools.defaultFontPixelWidth / 2
                        exclusiveGroup:     _dropButtonsExclusiveGroup
637
                        lightBorders:       _lightWidgetBorders
638 639 640

                        dropDownComponent: Component {
                            Column {
dogmaphobic's avatar
dogmaphobic committed
641
                                spacing: _margin
642
                                QGCLabel { text: qsTr("Map type:") }
643 644 645 646
                                Row {
                                    spacing: ScreenTools.defaultFontPixelWidth
                                    Repeater {
                                        model: QGroundControl.flightMapSettings.mapTypes
647

648 649
                                        QGCButton {
                                            checkable:      true
650
                                            checked:        QGroundControl.flightMapSettings.mapType === text
651 652 653
                                            text:           modelData
                                            exclusiveGroup: _mapTypeButtonsExclusiveGroup
                                            onClicked: {
654
                                                QGroundControl.flightMapSettings.mapType = text
655 656 657
                                                checked = true
                                                mapTypeButton.hideDropDown()
                                            }
658 659 660 661 662 663 664
                                        }
                                    }
                                }
                            }
                        }
                    }

665 666
                    //-- Zoom Map In
                    RoundButton {
667 668 669 670 671
                        id:             mapZoomPlus
                        visible:        !ScreenTools.isTinyScreen && !ScreenTools.isShortScreen
                        buttonImage:    "/qmlimages/ZoomPlus.svg"
                        lightBorders:   _lightWidgetBorders

672 673 674 675 676 677 678 679 680
                        onClicked: {
                            if(editorMap)
                                editorMap.zoomLevel += 0.5
                            checked = false
                        }
                    }

                    //-- Zoom Map Out
                    RoundButton {
681 682 683 684
                        id:             mapZoomMinus
                        visible:        !ScreenTools.isTinyScreen && !ScreenTools.isShortScreen
                        buttonImage:    "/qmlimages/ZoomMinus.svg"
                        lightBorders:   _lightWidgetBorders
685 686 687 688 689 690
                        onClicked: {
                            if(editorMap)
                                editorMap.zoomLevel -= 0.5
                            checked = false
                        }
                    }
691
                }
692

693 694 695 696 697 698 699 700 701
                MapScale {
                    anchors.margins:    ScreenTools.defaultFontPixelHeight * (0.66)
                    anchors.bottom:     waypointValuesDisplay.visible ? waypointValuesDisplay.top : parent.bottom
                    anchors.left:       parent.left
                    z:                  QGroundControl.zOrderWidgets
                    mapControl:         editorMap
                    visible:            !ScreenTools.isTinyScreen
                }

702
                MissionItemStatus {
703
                    id:                 waypointValuesDisplay
704
                    anchors.margins:    ScreenTools.defaultFontPixelWidth
705 706
                    anchors.left:       parent.left
                    anchors.bottom:     parent.bottom
707 708
                    z:                  QGroundControl.zOrderTopMost
                    currentMissionItem: _currentMissionItem
709
                    missionItems:       controller.visualItems
710
                    expandedWidth:      missionItemEditor.x - (ScreenTools.defaultFontPixelWidth * 2)
711 712 713 714
                    missionDistance:    controller.missionDistance
                    missionMaxTelemetry: controller.missionMaxTelemetry
                    cruiseDistance:    controller.cruiseDistance
                    hoverDistance:    controller.hoverDistance
Don Gagne's avatar
Don Gagne committed
715
                    visible:            !ScreenTools.isShortScreen
716
                }
717
            } // FlightMap
Don Gagne's avatar
Don Gagne committed
718 719
        } // Item - split view container
    } // QGCViewPanel
720

721 722 723 724
    Component {
        id: syncLoadFromVehicleOverwrite
        QGCViewMessage {
            id:         syncLoadFromVehicleCheck
725
            message:   qsTr("You have unsaved/unsent mission changes. Loading the mission from the Vehicle will lose these changes. Are you sure you want to load the mission from the Vehicle?")
726 727
            function accept() {
                hideDialog()
728
                loadFromVehicle()
729 730 731 732 733 734 735 736
            }
        }
    }

    Component {
        id: syncLoadFromFileOverwrite
        QGCViewMessage {
            id:         syncLoadFromVehicleCheck
737
            message:   qsTr("You have unsaved/unsent mission changes. Loading a mission from a file will lose these changes. Are you sure you want to load a mission from a file?")
738 739
            function accept() {
                hideDialog()
740
                loadFromFile()
741 742 743 744
            }
        }
    }

745 746 747
    Component {
        id: removeAllPromptDialog
        QGCViewMessage {
748
            message: qsTr("Are you sure you want to delete all mission items?")
749 750 751 752 753 754 755 756
            function accept() {
                itemDragger.clearItem()
                controller.removeAllMissionItems()
                hideDialog()
            }
        }
    }

757 758 759 760 761 762
    Component {
        id: syncDropDownComponent
        Column {
            id:         columnHolder
            spacing:    _margin
            QGCLabel {
dogmaphobic's avatar
dogmaphobic committed
763
                width:      sendSaveGrid.width
764
                wrapMode:   Text.WordWrap
Don Gagne's avatar
Don Gagne committed
765
                text:       _syncNeeded && !controller.autoSync ?
766
                                qsTr("You have unsaved changes to your mission. You should send to your vehicle, or save to a file:") :
767
                                qsTr("Sync:")
768
            }
dogmaphobic's avatar
dogmaphobic committed
769 770 771 772 773 774 775
            GridLayout {
                id:                 sendSaveGrid
                columns:            2
                anchors.margins:    _margin
                rowSpacing:         _margin
                columnSpacing:      ScreenTools.defaultFontPixelWidth
                visible:            true //autoSyncCheckBox.enabled && autoSyncCheckBox.checked
776
                QGCButton {
dogmaphobic's avatar
dogmaphobic committed
777 778 779
                    text:               qsTr("Send To Vehicle")
                    Layout.fillWidth:   true
                    enabled:            _activeVehicle && !controller.syncInProgress
780 781 782 783 784 785
                    onClicked: {
                        syncButton.hideDropDown()
                        controller.sendMissionItems()
                    }
                }
                QGCButton {
dogmaphobic's avatar
dogmaphobic committed
786 787 788
                    text:               qsTr("Load From Vehicle")
                    Layout.fillWidth:   true
                    enabled:            _activeVehicle && !controller.syncInProgress
789 790
                    onClicked: {
                        syncButton.hideDropDown()
Don Gagne's avatar
Don Gagne committed
791
                        if (_syncNeeded) {
792
                            _root.showDialog(syncLoadFromVehicleOverwrite, qsTr("Mission overwrite"), _root.showDialogDefaultWidth, StandardButton.Yes | StandardButton.Cancel)
793
                        } else {
794
                            loadFromVehicle()
795
                        }
796 797 798
                    }
                }
                QGCButton {
dogmaphobic's avatar
dogmaphobic committed
799 800 801
                    text:               qsTr("Save To File...")
                    Layout.fillWidth:   true
                    enabled:            !controller.syncInProgress
802 803
                    onClicked: {
                        syncButton.hideDropDown()
804
                        saveToFile()
805 806 807
                    }
                }
                QGCButton {
dogmaphobic's avatar
dogmaphobic committed
808 809 810
                    text:               qsTr("Load From File...")
                    Layout.fillWidth:   true
                    enabled:            !controller.syncInProgress
811 812
                    onClicked: {
                        syncButton.hideDropDown()
Don Gagne's avatar
Don Gagne committed
813
                        if (_syncNeeded) {
814
                            _root.showDialog(syncLoadFromFileOverwrite, qsTr("Mission overwrite"), _root.showDialogDefaultWidth, StandardButton.Yes | StandardButton.Cancel)
815
                        } else {
816
                            loadFromFile()
817
                        }
818 819
                    }
                }
dogmaphobic's avatar
dogmaphobic committed
820 821 822 823 824 825 826
                QGCButton {
                    text:               qsTr("Remove All")
                    Layout.fillWidth:   true
                    onClicked:  {
                        syncButton.hideDropDown()
                        _root.showDialog(removeAllPromptDialog, qsTr("Delete all"), _root.showDialogDefaultWidth, StandardButton.Yes | StandardButton.No)
                    }
827 828 829
                }
            }

dogmaphobic's avatar
dogmaphobic committed
830

831 832
/*
        FIXME: autoSync is temporarily disconnected since it's still buggy
833 834 835 836 837 838 839 840 841 842 843 844 845 846 847

            QGCLabel {
                id:         autoSyncDisallowedLabel
                visible:    _activeVehicle && _activeVehicle.armed
                text:       "AutoSync is not allowed whie vehicle is armed"
            }

            QGCCheckBox {
                id:         autoSyncCheckBox
                checked:    controller.autoSync
                text:       "Automatically sync changes with vehicle"
                enabled:    _activeVehicle ? !_activeVehicle.armed : false

                onClicked: controller.autoSync = checked
            }
848
*/
849 850
        }
    }
Don Gagne's avatar
Don Gagne committed
851
} // QGCVIew