MissionEditor.qml 35.9 KB
Newer Older
Don Gagne's avatar
Don Gagne committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
/*=====================================================================

QGroundControl Open Source Ground Control Station

(c) 2009, 2015 QGROUNDCONTROL PROJECT <http://www.qgroundcontrol.org>

This file is part of the QGROUNDCONTROL project

    QGROUNDCONTROL is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    QGROUNDCONTROL is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with QGROUNDCONTROL. If not, see <http://www.gnu.org/licenses/>.

======================================================================*/

Don Gagne's avatar
Don Gagne committed
24 25 26 27 28
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
29
import QtQuick.Layouts  1.2
Don Gagne's avatar
Don Gagne committed
30

31
import QGroundControl               1.0
Don Gagne's avatar
Don Gagne committed
32 33 34 35
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
36
import QGroundControl.Mavlink       1.0
37
import QGroundControl.Controllers   1.0
Don Gagne's avatar
Don Gagne committed
38 39

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

Don Gagne's avatar
Don Gagne committed
41
QGCView {
42 43
    id:         _root

44
    property bool syncNeeded: controller.visualItems.dirty // Unsaved changes, visible to parent container
45

46
    viewPanel:          panel
Don Gagne's avatar
Don Gagne committed
47

48
    // zOrder comes from the Loader in MainWindow.qml
Gus Grubba's avatar
Gus Grubba committed
49
    z: QGroundControl.zOrderTopMost
50

51
    readonly property int       _decimalPlaces:     8
52
    readonly property real      _horizontalMargin:  ScreenTools.defaultFontPixelWidth  / 2
dogmaphobic's avatar
dogmaphobic committed
53
    readonly property real      _margin:            ScreenTools.defaultFontPixelHeight * 0.5
54
    readonly property var       _activeVehicle:     QGroundControl.multiVehicleManager.activeVehicle
55
    readonly property real      _editFieldWidth:    ScreenTools.defaultFontPixelWidth * 16
Don Gagne's avatar
Don Gagne committed
56
    readonly property real      _rightPanelWidth:   Math.min(parent.width / 3, ScreenTools.defaultFontPixelWidth * 30)
57 58 59 60
    readonly property real      _rightPanelOpacity: 0.8
    readonly property int       _toolButtonCount:   6
    readonly property string    _autoSyncKey:       "AutoSync"
    readonly property int       _addMissionItemsButtonAutoOffTimeout:   10000
61
    readonly property var       _defaultVehicleCoordinate:   QtPositioning.coordinate(37.803784, -122.462276)
62

63
    property var    _visualItems:          controller.visualItems
Don Gagne's avatar
Don Gagne committed
64
    property var    _currentMissionItem
65 66
    property bool   _firstVehiclePosition:  true
    property var    activeVehiclePosition:  _activeVehicle ? _activeVehicle.coordinate : QtPositioning.coordinate()
67
    property bool   _lightWidgetBorders:    editorMap.isSatelliteMap
68

69
    onActiveVehiclePositionChanged: updateMapToVehiclePosition()
70

71
    Connections {
72
        target: QGroundControl.multiVehicleManager
73 74 75 76 77 78

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

    function updateMapToVehiclePosition() {
82
        if (_activeVehicle && _activeVehicle.coordinateValid && _activeVehicle.coordinate.isValid && _firstVehiclePosition) {
83 84
            _firstVehiclePosition = false
            editorMap.center = _activeVehicle.coordinate
85 86 87
        }
    }

88 89 90 91 92
    function loadFromVehicle() {
        controller.getMissionItems()
    }

    function loadFromFile() {
93
        if (ScreenTools.isMobile) {
94
            _root.showDialog(mobileFilePicker, qsTr("Select Mission File"), _root.showDialogDefaultWidth, StandardButton.Yes | StandardButton.Cancel)
95
        } else {
Don Gagne's avatar
Don Gagne committed
96
            controller.loadMissionFromFilePicker()
97 98 99 100 101 102
            fitViewportToMissionItems()
        }
    }

    function saveToFile() {
        if (ScreenTools.isMobile) {
103
            _root.showDialog(mobileFileSaver, qsTr("Save Mission File"), _root.showDialogDefaultWidth, StandardButton.Save | StandardButton.Cancel)
104
        } else {
Don Gagne's avatar
Don Gagne committed
105
            controller.saveMissionToFilePicker()
106
        }
107 108 109 110 111 112 113 114 115 116 117 118
    }

    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
    }

119
    /// Fix the map viewport to the current mission items.
120
    function fitViewportToMissionItems() {
121 122
        if (_visualItems.count == 1) {
            editorMap.center = _visualItems.get(0).coordinate
123
        } else {
124
            var missionItem = _visualItems.get(0)
125 126 127 128 129
            var north = normalizeLat(missionItem.coordinate.latitude)
            var south = north
            var east = normalizeLon(missionItem.coordinate.longitude)
            var west = east

130 131
            for (var i=1; i<_visualItems.count; i++) {
                missionItem = _visualItems.get(i)
132

133
                if (missionItem.specifiesCoordinate && !missionItem.isStandaloneCoordinate) {
134 135 136 137 138 139 140 141
                    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)
                }
142
            }
143
            editorMap.visibleRegion = QtPositioning.rectangle(QtPositioning.coordinate(north - 90.0, west - 180.0), QtPositioning.coordinate(south - 90.0, east - 180.0))
144 145 146
        }
    }

147
    MissionController {
148
        id:         controller
149

150 151
        Component.onCompleted: {
            start(true /* editMode */)
152
            setCurrentItem(0)
153 154
        }

Don Gagne's avatar
Don Gagne committed
155
        /*
156 157
        FIXME: autoSync is temporarily disconnected since it's still buggy

158 159 160
        autoSync:   QGroundControl.flightMapSettings.loadMapSetting(editorMap.mapName, _autoSyncKey, true)

        onAutoSyncChanged:      QGroundControl.flightMapSettings.saveMapSetting(editorMap.mapName, _autoSyncKey, autoSync)
161
*/
162

163
        onVisualItemsChanged: itemDragger.clearItem()
164
        onNewItemsFromVehicle: fitViewportToMissionItems()
165
    }
166

167
    QGCPalette { id: qgcPal; colorGroupEnabled: enabled }
Don Gagne's avatar
Don Gagne committed
168

169 170 171 172 173 174
    ExclusiveGroup {
        id: _mapTypeButtonsExclusiveGroup
    }

    ExclusiveGroup {
        id: _dropButtonsExclusiveGroup
175 176
    }

177
    function setCurrentItem(sequenceNumber) {
Don Gagne's avatar
Don Gagne committed
178
        _currentMissionItem = undefined
179
        for (var i=0; i<_visualItems.count; i++) {
180 181 182
            var visualItem = _visualItems.get(i)
            if (visualItem.sequenceNumber == sequenceNumber) {
                _currentMissionItem = visualItem
Don Gagne's avatar
Don Gagne committed
183 184
                _currentMissionItem.isCurrentItem = true
            } else {
185
                visualItem.isCurrentItem = false
Don Gagne's avatar
Don Gagne committed
186
            }
187 188 189
        }
    }

190 191
    property int _moveDialogMissionItemIndex

192 193 194
    Component {
        id: mobileFilePicker

Don Gagne's avatar
Don Gagne committed
195 196 197 198 199 200 201
        QGCMobileFileDialog {
            openDialog:     true
            fileExtension:  QGroundControl.missionFileExtension

            onFilenameReturned: {
                controller.loadMissionFromFile(filename)
                fitViewportToMissionItems()
202 203 204 205 206 207 208
            }
        }
    }

    Component {
        id: mobileFileSaver

Don Gagne's avatar
Don Gagne committed
209 210 211
        QGCMobileFileDialog {
            openDialog:     false
            fileExtension:  QGroundControl.missionFileExtension
212

Don Gagne's avatar
Don Gagne committed
213 214
            onFilenameReturned: {
                controller.saveMissionToFile(filename)
215 216 217 218
            }
        }
    }

219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241
    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
242
                    text:           qsTr("Move the selected mission item to the be after following mission item:")
243 244 245 246
                }

                QGCComboBox {
                    id:             toCombo
247
                    model:          _visualItems.count
248 249 250 251 252 253
                    currentIndex:   _moveDialogMissionItemIndex
                }
            }
        }
    }

Don Gagne's avatar
Don Gagne committed
254 255
    QGCViewPanel {
        id:             panel
256 257 258 259
        height:         ScreenTools.availableHeight
        anchors.bottom: parent.bottom
        anchors.left:   parent.left
        anchors.right:  parent.right
Don Gagne's avatar
Don Gagne committed
260

Don Gagne's avatar
Don Gagne committed
261
        Item {
Don Gagne's avatar
Don Gagne committed
262 263
            anchors.fill: parent

Don Gagne's avatar
Don Gagne committed
264 265
            FlightMap {
                id:             editorMap
266 267 268 269
                height:         _root.height
                anchors.bottom: parent.bottom
                anchors.left:   parent.left
                anchors.right:  parent.right
Don Gagne's avatar
Don Gagne committed
270
                mapName:        "MissionEditor"
271

272 273
                signal mapClicked(var coordinate)

274 275
                readonly property real animationDuration: 500

276 277 278
                // Initial map position duplicates Fly view position
                Component.onCompleted: editorMap.center = QGroundControl.flightMapPosition

279 280 281 282 283 284 285
                Behavior on zoomLevel {
                    NumberAnimation {
                        duration:       editorMap.animationDuration
                        easing.type:    Easing.InOutQuad
                    }
                }

Don Gagne's avatar
Don Gagne committed
286
                MouseArea {
287 288
                    //-- 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
289 290
                    anchors.fill: parent
                    onClicked: {
291 292 293 294 295 296 297 298 299 300 301 302 303 304
                        //-- 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)
                                editorListView.positionViewAtIndex(editorListView.count - 1, ListView.Contain)
                            } else {
                                editorMap.mapClicked(coordinate)
                            }
305
                        }
Don Gagne's avatar
Don Gagne committed
306
                    }
Don Gagne's avatar
Don Gagne committed
307
                }
Don Gagne's avatar
Don Gagne committed
308

309
                // We use this item to support dragging since dragging a MapQuickItem just doesn't seem to work
Don Gagne's avatar
Don Gagne committed
310 311 312 313
                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
314 315
                    width:          ScreenTools.defaultFontPixelHeight * 2
                    height:         ScreenTools.defaultFontPixelHeight * 2
Don Gagne's avatar
Don Gagne committed
316 317 318
                    color:          "transparent"
                    visible:        false
                    z:              QGroundControl.zOrderMapItems + 1    // Above item icons
319 320 321

                    property var    missionItem
                    property var    missionItemIndicator
322 323 324 325 326 327 328 329 330 331 332 333 334 335 336
                    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
337

338
                    function clearItem() {
Don Gagne's avatar
Don Gagne committed
339 340 341 342 343
                        itemDragger.visible = false
                        itemDragger.missionItem = undefined
                        itemDragger.missionItemIndicator = undefined
                    }

344 345 346 347 348 349 350 351
                    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
352 353 354 355
                        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
356
                    }
357
                }
358

359
                // Add the complex mission item polygon to the map
360
                MapItemView {
Don Gagne's avatar
Don Gagne committed
361 362
                    model: controller.complexVisualItems
                    delegate: MapPolygon {
363 364 365 366 367 368
                        color:      'green'
                        path:       object.polygonPath
                        opacity:    0.5
                    }
                }

369 370 371 372 373 374 375 376 377 378
                // Add the complex mission item grid to the map
                MapItemView {
                    model: controller.complexVisualItems

                    delegate: MapPolyline {
                        line.color: "white"
                        path:       object.gridPoints
                    }
                }

379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394
                // 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
395 396
                }

397 398 399 400 401 402
                // Add the simple mission items to the map
                MapItemView {
                    model:      controller.visualItems
                    delegate:   missionItemComponent
                }

Don Gagne's avatar
Don Gagne committed
403
                Component {
404
                    id: missionItemComponent
Don Gagne's avatar
Don Gagne committed
405 406 407 408

                    MissionItemIndicator {
                        id:             itemIndicator
                        coordinate:     object.coordinate
409
                        visible:        object.specifiesCoordinate
Don Gagne's avatar
Don Gagne committed
410
                        z:              QGroundControl.zOrderMapItems
411
                        missionItem:    object
412
                        sequenceNumber: object.sequenceNumber
Don Gagne's avatar
Don Gagne committed
413

414 415 416
                        //-- 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
417 418
                        onClicked: setCurrentItem(object.sequenceNumber)

419 420
                        function updateItemIndicator() {
                            if (object.isCurrentItem && itemIndicator.visible && object.specifiesCoordinate && object.isSimpleItem) {
421 422 423 424
                                // 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
425 426 427
                            }
                        }

428 429 430
                        Connections {
                            target: object

431 432
                            onIsCurrentItemChanged:         updateItemIndicator()
                            onSpecifiesCoordinateChanged:   updateItemIndicator()
433 434
                        }

Don Gagne's avatar
Don Gagne committed
435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452
                        // 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 {
                                    label:          object.sequenceNumber
                                    isCurrentItem:  object.isCurrentItem
                                    z:              2

                                    onClicked: setCurrentItem(object.sequenceNumber)
                                }
                            }
                        }
                    }
453 454 455
                }

                // Add lines between waypoints
456 457
                MissionLineView {
                    model:          controller.waypointLines
Don Gagne's avatar
Don Gagne committed
458 459
                }

Don Gagne's avatar
Don Gagne committed
460 461
                // Add the vehicles to the map
                MapItemView {
462
                    model: QGroundControl.multiVehicleManager.vehicles
Don Gagne's avatar
Don Gagne committed
463 464 465 466 467 468 469 470 471 472
                    delegate:
                        VehicleMapItem {
                                vehicle:        object
                                coordinate:     object.coordinate
                                isSatellite:    editorMap.isSatelliteMap
                                size:           ScreenTools.defaultFontPixelHeight * 5
                                z:              QGroundControl.zOrderMapItems - 1
                        }
                }

473
                // Mission Item Editor
Don Gagne's avatar
Don Gagne committed
474
                Item {
475
                    id:             missionItemEditor
476
                    height:         ScreenTools.availableHeight
477 478 479 480
                    anchors.bottom: parent.bottom
                    anchors.right:  parent.right
                    width:          _rightPanelWidth
                    opacity:        _rightPanelOpacity
Gus Grubba's avatar
Gus Grubba committed
481
                    z:              QGroundControl.zOrderTopMost
482

Don Gagne's avatar
Don Gagne committed
483 484 485 486 487 488 489
                    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
                     }

490
                    ListView {
491 492 493 494
                        id:             editorListView
                        anchors.left:   parent.left
                        anchors.right:  parent.right
                        anchors.top:    parent.top
495
                        height:         parent.height
496 497
                        spacing:        _margin / 2
                        orientation:    ListView.Vertical
498
                        model:          controller.visualItems
499
                        cacheBuffer:    height * 2
500
                        clip:           true
501

502
                        delegate: MissionItemEditor {
503 504
                            missionItem:    object
                            width:          parent.width
Don Gagne's avatar
Don Gagne committed
505
                            qgcView:        _root
506
                            readOnly:       false
507 508 509 510

                            onClicked:  setCurrentItem(object.sequenceNumber)

                            onRemove: {
511
                                itemDragger.clearItem()
haigithub's avatar
haigithub committed
512
                                controller.removeMissionItem(index)
513 514
                            }

515
                            onInsert: {
516 517
                                var sequenceNumber = controller.insertSimpleMissionItem(editorMap.center, i)
                                setCurrentItem(sequenceNumber)
518
                            }
519

520
                            onMoveHomeToMapCenter: controller.visualItems.get(0).coordinate = editorMap.center
Don Gagne's avatar
Don Gagne committed
521 522 523 524 525 526 527 528 529 530

                            Connections {
                                target: object

                                onIsCurrentItemChanged: {
                                    if (object.isCurrentItem) {
                                        editorListView.positionViewAtIndex(index, ListView.Contain)
                                    }
                                }
                            }
531
                        }
532 533 534
                    } // ListView
                } // Item - Mission Item editor

535 536 537 538 539 540 541 542 543 544 545 546 547
                //-- Dismiss Drop Down (if any)
                MouseArea {
                    anchors.fill:   parent
                    enabled:        _dropButtonsExclusiveGroup.current != null
                    onClicked: {
                        if(_dropButtonsExclusiveGroup.current)
                            _dropButtonsExclusiveGroup.current.checked = false
                        _dropButtonsExclusiveGroup.current = null
                    }
                }

                //-- Vertical Tool Buttons
                Column {
548
                    id:                 toolColumn
549
                    anchors.topMargin:  parent.height - ScreenTools.availableHeight + ScreenTools.defaultFontPixelHeight
550 551 552 553
                    anchors.margins:    ScreenTools.defaultFontPixelHeight
                    anchors.left:       parent.left
                    anchors.top:        parent.top
                    spacing:            ScreenTools.defaultFontPixelHeight
554 555

                    RoundButton {
556 557 558 559
                        id:             addMissionItemsButton
                        buttonImage:    "/qmlimages/MapAddMission.svg"
                        z:              QGroundControl.zOrderWidgets
                        lightBorders:   _lightWidgetBorders
560 561
                    }

562
                    RoundButton {
563 564 565 566 567
                        id:             addShapeButton
                        buttonImage:    "/qmlimages/MapDrawShape.svg"
                        z:              QGroundControl.zOrderWidgets
                        visible:        QGroundControl.experimentalSurvey
                        lightBorders:   _lightWidgetBorders
568 569 570 571 572 573

                        onClicked: {
                            var coordinate = editorMap.center
                            coordinate.latitude = coordinate.latitude.toFixed(_decimalPlaces)
                            coordinate.longitude = coordinate.longitude.toFixed(_decimalPlaces)
                            coordinate.altitude = coordinate.altitude.toFixed(_decimalPlaces)
574 575
                            var sequenceNumber = controller.insertComplexMissionItem(coordinate, controller.visualItems.count)
                            setCurrentItem(sequenceNumber)
576
                            checked = false
577
                            addMissionItemsButton.checked = false
578 579 580
                        }
                    }

581 582 583
                    DropButton {
                        id:                 syncButton
                        dropDirection:      dropRight
584
                        buttonImage:        syncNeeded ? "/qmlimages/MapSyncChanged.svg" : "/qmlimages/MapSync.svg"
585 586 587 588
                        viewportMargins:    ScreenTools.defaultFontPixelWidth / 2
                        exclusiveGroup:     _dropButtonsExclusiveGroup
                        z:                  QGroundControl.zOrderWidgets
                        dropDownComponent:  syncDropDownComponent
589 590
                        enabled:            !controller.syncInProgress
                        rotateImage:        controller.syncInProgress
591
                        lightBorders:       _lightWidgetBorders
592 593
                    }

594 595 596 597 598 599 600
                    DropButton {
                        id:                 centerMapButton
                        dropDirection:      dropRight
                        buttonImage:        "/qmlimages/MapCenter.svg"
                        viewportMargins:    ScreenTools.defaultFontPixelWidth / 2
                        exclusiveGroup:     _dropButtonsExclusiveGroup
                        z:                  QGroundControl.zOrderWidgets
601
                        lightBorders:       _lightWidgetBorders
602

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

640 641 642 643 644 645 646
                    DropButton {
                        id:                 mapTypeButton
                        dropDirection:      dropRight
                        buttonImage:        "/qmlimages/MapType.svg"
                        viewportMargins:    ScreenTools.defaultFontPixelWidth / 2
                        exclusiveGroup:     _dropButtonsExclusiveGroup
                        z:                  QGroundControl.zOrderWidgets
647
                        lightBorders:       _lightWidgetBorders
648 649 650

                        dropDownComponent: Component {
                            Column {
dogmaphobic's avatar
dogmaphobic committed
651
                                spacing: _margin
652
                                QGCLabel { text: qsTr("Map type:") }
653 654 655 656 657 658
                                Row {
                                    spacing: ScreenTools.defaultFontPixelWidth
                                    Repeater {
                                        model: QGroundControl.flightMapSettings.mapTypes
                                        QGCButton {
                                            checkable:      true
dogmaphobic's avatar
dogmaphobic committed
659
                                            checked:        editorMap.mapType === text
660 661 662 663 664 665 666
                                            text:           modelData
                                            exclusiveGroup: _mapTypeButtonsExclusiveGroup
                                            onClicked: {
                                                editorMap.mapType = text
                                                checked = true
                                                mapTypeButton.hideDropDown()
                                            }
667 668 669 670 671 672 673
                                        }
                                    }
                                }
                            }
                        }
                    }

674 675
                    //-- Zoom Map In
                    RoundButton {
676 677 678 679 680 681
                        id:             mapZoomPlus
                        visible:        !ScreenTools.isTinyScreen && !ScreenTools.isShortScreen
                        buttonImage:    "/qmlimages/ZoomPlus.svg"
                        z:              QGroundControl.zOrderWidgets
                        lightBorders:   _lightWidgetBorders

682 683 684 685 686 687 688 689 690
                        onClicked: {
                            if(editorMap)
                                editorMap.zoomLevel += 0.5
                            checked = false
                        }
                    }

                    //-- Zoom Map Out
                    RoundButton {
691 692 693 694 695
                        id:             mapZoomMinus
                        visible:        !ScreenTools.isTinyScreen && !ScreenTools.isShortScreen
                        buttonImage:    "/qmlimages/ZoomMinus.svg"
                        z:              QGroundControl.zOrderWidgets
                        lightBorders:   _lightWidgetBorders
696 697 698 699 700 701
                        onClicked: {
                            if(editorMap)
                                editorMap.zoomLevel -= 0.5
                            checked = false
                        }
                    }
702
                }
703

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

719 720 721 722
    Component {
        id: syncLoadFromVehicleOverwrite
        QGCViewMessage {
            id:         syncLoadFromVehicleCheck
723
            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?")
724 725
            function accept() {
                hideDialog()
726
                loadFromVehicle()
727 728 729 730 731 732 733 734
            }
        }
    }

    Component {
        id: syncLoadFromFileOverwrite
        QGCViewMessage {
            id:         syncLoadFromVehicleCheck
735
            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?")
736 737
            function accept() {
                hideDialog()
738
                loadFromFile()
739 740 741 742
            }
        }
    }

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

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

dogmaphobic's avatar
dogmaphobic committed
828

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

            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
            }
846
*/
847 848
        }
    }
Don Gagne's avatar
Don Gagne committed
849
} // QGCVIew