OfflineMap.qml 42 KB
Newer Older
dogmaphobic's avatar
dogmaphobic committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 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 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270
/*=====================================================================

 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/>.

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

import QtQuick                  2.5
import QtQuick.Controls         1.2
import QtQuick.Controls.Styles  1.2
import QtQuick.Dialogs          1.1
import QtQuick.Layouts          1.2
import QtLocation               5.3
import QtPositioning            5.3

import QGroundControl                       1.0
import QGroundControl.Controls              1.0
import QGroundControl.ScreenTools           1.0
import QGroundControl.Palette               1.0

Rectangle {
    id:                 _offlineMapRoot
    color:              __qgcPal.window
    anchors.fill:       parent
    anchors.margins:    ScreenTools.defaultFontPixelWidth

    property var    _currentSelection: null

    property string mapKey:        "lastMapType"

    property string mapType:        QGroundControl.mapEngineManager.loadSetting(mapKey, "Google Street Map")
    property int    mapMargin:      (ScreenTools.defaultFontPixelHeight * 0.2).toFixed(0)
    property real   infoWidth:      Math.max(Math.max(nameLabel.width, descLabel.width), (ScreenTools.defaultFontPixelWidth * 40))
    property bool   isDefaultSet:   _offlineMapRoot._currentSelection && _offlineMapRoot._currentSelection.defaultSet

    property real oldlon0:      0
    property real oldlon1:      0
    property real oldlat0:      0
    property real oldlat1:      0
    property int  oldz0:        0
    property int  oldz1:        0

    Component.onCompleted: {
        QGroundControl.mapEngineManager.loadTileSets()
        updateMap()
    }

    Connections {
        target: QGroundControl.mapEngineManager
        onTileSetsChanged: {
            setName.text = QGroundControl.mapEngineManager.getUniqueName()
        }
        onErrorMessageChanged: {
            errorDialog.visible = true
        }
    }

    ExclusiveGroup { id: setGroup }

    function handleChanges() {
        var xl = mapMargin
        var yl = mapMargin
        var xr = _map.width.toFixed(0)  - mapMargin
        var yr = _map.height.toFixed(0) - mapMargin
        var c0 = _map.toCoordinate(Qt.point(xl, yl))
        var c1 = _map.toCoordinate(Qt.point(xr, yr))
        if(oldlon0 !== c0.longitude || oldlat0 !== c0.latitude || oldlon1 !== c1.longitude || oldlat1 !== c1.latitude || oldz0 !== _slider0.value || oldz1 !== _slider1.value) {
            QGroundControl.mapEngineManager.updateForCurrentView(c0.longitude, c0.latitude, c1.longitude, c1.latitude, _slider0.value, _slider1.value, mapType)
        }
    }

    function checkSanity() {
        if(QGroundControl.mapEngineManager.crazySize) {
            _slider1.value = _slider1.value - 1
            handleChanges()
        }
    }

    function updateMap() {
        for (var i = 0; i < _map.supportedMapTypes.length; i++) {
            if (mapType === _map.supportedMapTypes[i].name) {
                _map.activeMapType = _map.supportedMapTypes[i]
                handleChanges()
                return
            }
        }
    }

    function showOptions() {
        _tileSetList.visible = false
        _infoView.visible = false
        _mapView.visible = false
        _optionsView.visible = true
    }

    function showMap() {
        _tileSetList.visible = false
        _infoView.visible = false
        _mapView.visible = true
        _optionsView.visible = false
    }

    function showList() {
        _tileSetList.visible = true
        _infoView.visible = false
        _mapView.visible = false
        _optionsView.visible = false
    }

    function showInfo() {
        if(_currentSelection && !_offlineMapRoot._currentSelection.deleting) {
            _tileSetList.visible = false
            _mapView.visible = false
            _infoView.visible = true
            _optionsView.visible = false
        } else
            showList()
    }

    ExclusiveGroup {
        id: _dropButtonsExclusiveGroup
    }

    onMapTypeChanged: {
        updateMap()
        QGroundControl.mapEngineManager.saveSetting(mapKey, mapType)
    }

    MessageDialog {
        id:         errorDialog
        visible:    false
        text:       QGroundControl.mapEngineManager.errorMessage
        icon:       StandardIcon.Critical
        standardButtons: StandardButton.Ok
        title:      "Errror Message"
        onYes: {
            errorDialog.visible = false
        }
    }
    Rectangle {
        id:         _offlineMapTopRect
        width:      parent.width
        height:     labelTitle.height + ScreenTools.defaultFontPixelHeight
        color:      __qgcPal.window
        anchors.top: parent.top
        Row {
            spacing: ScreenTools.defaultFontPixelHeight * 2
            anchors.verticalCenter: parent.verticalCenter
            QGCLabel {
                id:         labelTitle
                text:       "Offline Maps"
                font.pixelSize: ScreenTools.mediumFontPixelSize
                anchors.verticalCenter: parent.verticalCenter
            }
            QGCCheckBox {
                id:         showTilePreview
                text:       "Show tile min/max zoom level preview"
                checked:    false
                visible:    _mapView.visible
                anchors.verticalCenter: parent.verticalCenter
            }
        }
    }
    QGCFlickable {
        id:                 _tileSetList
        clip:               true
        anchors.top:        _offlineMapTopRect.bottom
        width:              parent.width
        height:             parent.height - _offlineMapTopRect.height
        contentHeight:      _cacheList.height
        contentWidth:       parent.width
        flickableDirection: Flickable.VerticalFlick
        Column {
            id:                 _cacheList
            width:              _offlineMapRoot.width
            anchors.margins:    ScreenTools.defaultFontPixelWidth
            spacing:            (ScreenTools.defaultFontPixelHeight * 0.5).toFixed(0)
            OfflineMapButton {
                text:   "Add new set"
                width:  (ScreenTools.defaultFontPixelWidth  * 50).toFixed(0)
                height: (ScreenTools.defaultFontPixelHeight * 2).toFixed(0)
                anchors.horizontalCenter: parent.horizontalCenter
                onClicked: {
                    _offlineMapRoot._currentSelection = null
                    showMap()
                }
            }
            Repeater {
                model: QGroundControl.mapEngineManager.tileSets
                delegate: OfflineMapButton {
                    text:   object.name
                    size:   object.downloadStatus
                    complete: object.complete
                    width:  (ScreenTools.defaultFontPixelWidth  * 50).toFixed(0)
                    height: (ScreenTools.defaultFontPixelHeight * 2).toFixed(0)
                    anchors.horizontalCenter: parent.horizontalCenter
                    onClicked: {
                        _offlineMapRoot._currentSelection = object
                        showInfo()
                    }
                }
            }
        }
    }
    QGCButton {
        id:              _optionsButton
        text:            "Options"
        width:           ScreenTools.defaultFontPixelWidth * 10
        visible:         _tileSetList.visible
        anchors.bottom:  parent.bottom
        anchors.right:   parent.right
        anchors.margins: ScreenTools.defaultFontPixelWidth
        onClicked:       showOptions()
    }
    //-- Offline Map Definition
    Rectangle {
        id:                 _mapView
        color:              __qgcPal.window
        width:              parent.width
        anchors.top:        _offlineMapTopRect.bottom
        anchors.bottom:     parent.bottom
        anchors.margins:    ScreenTools.defaultFontPixelWidth
        visible:            false

        Rectangle {
            width:          parent.width
            anchors.top:    parent.top
            anchors.bottom: bottomRect.top
            color:          (__qgcPal.globalTheme === QGCPalette.Light) ? "black" : "#98aca4"
            Map {
                id:                 _map
                anchors.fill:       parent
                anchors.margins:    ScreenTools.defaultFontPixelHeight * 0.15
                zoomLevel:          10
                center:             QGroundControl.defaultMapPosition
                gesture.flickDeceleration:  3000
                gesture.activeGestures:     MapGestureArea.ZoomGesture | MapGestureArea.PanGesture | MapGestureArea.FlickGesture
                plugin: Plugin { name: "QGroundControl" }
                onCenterChanged: {
                    handleChanges()
                    checkSanity()
                }
                onZoomLevelChanged: {
                    handleChanges()
                    checkSanity()
                }
                onWidthChanged: {
                    handleChanges()
                    checkSanity()
                }
                onHeightChanged: {
                    handleChanges()
                    checkSanity()
                }
271 272 273 274
                // Used to make pinch zoom work
                MouseArea {
                    anchors.fill: parent
                }
dogmaphobic's avatar
dogmaphobic committed
275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323
            }
            Rectangle {
                width:              ScreenTools.defaultFontPixelHeight * 16
                height:             ScreenTools.defaultFontPixelHeight * 9
                anchors.top:        parent.top
                anchors.left:       parent.left
                anchors.margins:    ScreenTools.defaultFontPixelHeight
                color:              "black"
                visible:            showTilePreview.checked
                Map {
                    id:                 _mapMin
                    anchors.fill:       parent
                    anchors.margins:    2
                    zoomLevel:          _slider0.value
                    center:             _map.center
                    gesture.enabled:    false
                    activeMapType:      _map.activeMapType
                    plugin: Plugin { name: "QGroundControl" }
                }
            }
            Rectangle {
                width:              ScreenTools.defaultFontPixelHeight * 16
                height:             ScreenTools.defaultFontPixelHeight * 9
                anchors.top:        parent.top
                anchors.right:      parent.right
                anchors.margins:    ScreenTools.defaultFontPixelHeight
                color:              "black"
                visible:            showTilePreview.checked
                Map {
                    id:                 _mapMax
                    anchors.fill:       parent
                    anchors.margins:    2
                    zoomLevel:          _slider1.value
                    center:             _map.center
                    gesture.enabled:    false
                    activeMapType:      _map.activeMapType
                    plugin: Plugin { name: "QGroundControl" }
                }
            }
        }
        Rectangle {
            id:     bottomRect
            width:  parent.width
            height: _controlRow.height + (ScreenTools.defaultFontPixelHeight * 2)
            color:  __qgcPal.window
            anchors.bottom: parent.bottom
            Row {
                id: _controlRow
                anchors.centerIn: parent
324
                spacing: ScreenTools.defaultFontPixelWidth * 0.5
dogmaphobic's avatar
dogmaphobic committed
325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 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
                Rectangle {
                    height:     _zoomRow.height + ScreenTools.defaultFontPixelHeight * 1.5
                    width:      _zoomRow.width  + ScreenTools.defaultFontPixelWidth
                    color:      "#98aca4"
                    border.color: "black"
                    border.width: 2
                    radius:     ScreenTools.defaultFontPixelWidth * 0.5
                    anchors.verticalCenter: parent.verticalCenter
                    Row {
                        id: _zoomRow
                        anchors.centerIn:   parent
                        Column {
                            spacing:            ScreenTools.defaultFontPixelHeight * 0.5
                            anchors.verticalCenter: parent.verticalCenter
                            Row {
                                spacing:        ScreenTools.defaultFontPixelWidth * 0.5
                                Column {
                                    anchors.verticalCenter: parent.verticalCenter
                                    Label {
                                        text:   "Min"
                                        color:  "black"
                                        width:  ScreenTools.defaultFontPixelWidth * 5
                                        font.pixelSize: ScreenTools.smallFontPixelSize
                                        horizontalAlignment: Text.AlignHCenter
                                    }
                                    Label {
                                        text:   "Zoom"
                                        color:  "black"
                                        width:  ScreenTools.defaultFontPixelWidth * 5
                                        font.pixelSize: ScreenTools.smallFontPixelSize
                                        horizontalAlignment: Text.AlignHCenter
                                    }
                                }
                                Slider {
                                    id:                 _slider0
                                    minimumValue:       3
                                    maximumValue:       18
                                    stepSize:           1
                                    tickmarksEnabled:   false
                                    orientation:        Qt.Horizontal
                                    updateValueWhileDragging: true
                                    anchors.verticalCenter: parent.verticalCenter
                                    style: SliderStyle {
                                        groove: Rectangle {
369
                                            implicitWidth:  ScreenTools.defaultFontPixelWidth * 12
dogmaphobic's avatar
dogmaphobic committed
370 371 372 373 374 375 376 377 378
                                            implicitHeight: 4
                                            color:          "gray"
                                            radius:         4
                                        }
                                        handle: Rectangle {
                                            anchors.centerIn: parent
                                            color: control.pressed ? "white" : "lightgray"
                                            border.color: "gray"
                                            border.width:   2
379 380
                                            implicitWidth:  ScreenTools.isAndroid ? 60 : 30
                                            implicitHeight: ScreenTools.isAndroid ? 60 : 30
dogmaphobic's avatar
dogmaphobic committed
381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432
                                            radius:         10
                                            Label {
                                                text:  _slider0.value
                                                anchors.centerIn: parent
                                            }
                                        }
                                    }
                                    Component.onCompleted: {
                                        _slider0.value = _map.zoomLevel - 2
                                    }
                                    onValueChanged: {
                                        if(_slider1) {
                                            if(_slider0.value > _slider1.value)
                                                _slider1.value = _slider0.value
                                            else {
                                                handleChanges()
                                                checkSanity()
                                            }
                                        }
                                    }
                                }
                            }
                            Row {
                                spacing:        ScreenTools.defaultFontPixelWidth * 0.5
                                Column {
                                    anchors.verticalCenter: parent.verticalCenter
                                    Label {
                                        text:   "Max"
                                        color:  "black"
                                        width:  ScreenTools.defaultFontPixelWidth * 5
                                        font.pixelSize: ScreenTools.smallFontPixelSize
                                        horizontalAlignment: Text.AlignHCenter
                                    }
                                    Label {
                                        text:   "Zoom"
                                        color:  "black"
                                        width:  ScreenTools.defaultFontPixelWidth * 5
                                        font.pixelSize: ScreenTools.smallFontPixelSize
                                        horizontalAlignment: Text.AlignHCenter
                                    }
                                }
                                Slider {
                                    id:                 _slider1
                                    minimumValue:       3
                                    maximumValue:       18
                                    stepSize:           1
                                    tickmarksEnabled:   false
                                    orientation:        Qt.Horizontal
                                    updateValueWhileDragging: true
                                    anchors.verticalCenter: parent.verticalCenter
                                    style: SliderStyle {
                                        groove: Rectangle {
433
                                            implicitWidth:  ScreenTools.defaultFontPixelWidth * 12
dogmaphobic's avatar
dogmaphobic committed
434 435 436 437 438 439 440 441 442
                                            implicitHeight: 4
                                            color:          "gray"
                                            radius:         4
                                        }
                                        handle: Rectangle {
                                            anchors.centerIn: parent
                                            color: control.pressed ? "white" : "lightgray"
                                            border.color: "gray"
                                            border.width:   2
443 444
                                            implicitWidth:  ScreenTools.isAndroid ? 60 : 30
                                            implicitHeight: ScreenTools.isAndroid ? 60 : 30
dogmaphobic's avatar
dogmaphobic committed
445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510
                                            radius:         10
                                            Label {
                                                text:  _slider1.value
                                                anchors.centerIn: parent
                                            }
                                        }
                                    }
                                    Component.onCompleted: {
                                        _slider1.value = _map.zoomLevel + 2
                                    }
                                    onValueChanged: {
                                        if(_slider1.value < _slider0.value)
                                            _slider0.value = _slider1.value
                                        else {
                                            handleChanges()
                                            checkSanity()
                                        }
                                    }
                                }
                            }
                        }
                        Column {
                            spacing:            ScreenTools.defaultFontPixelHeight * 0.5
                            anchors.verticalCenter: parent.verticalCenter
                            Label {
                                text:   "Tile Count"
                                color:  "black"
                                width:  ScreenTools.defaultFontPixelWidth * 12
                                font.pixelSize: ScreenTools.smallFontPixelSize
                                horizontalAlignment: Text.AlignHCenter
                            }
                            Label {
                                text:  QGroundControl.mapEngineManager.tileCountStr
                                color: "black"
                                width: ScreenTools.defaultFontPixelWidth * 12
                                horizontalAlignment: Text.AlignHCenter
                            }
                            Label {
                                text:   "Set Size (Est)"
                                color:  "black"
                                width:  ScreenTools.defaultFontPixelWidth * 12
                                font.pixelSize: ScreenTools.smallFontPixelSize
                                horizontalAlignment: Text.AlignHCenter
                            }
                            Label {
                                text:  QGroundControl.mapEngineManager.tileSizeStr
                                color: "black"
                                width: ScreenTools.defaultFontPixelWidth * 12
                                horizontalAlignment: Text.AlignHCenter
                            }
                        }
                    }
                }
                Column {
                    anchors.verticalCenter: parent.verticalCenter
                    spacing:            ScreenTools.defaultFontPixelHeight * 0.5
                    Row {
                        spacing:        ScreenTools.defaultFontPixelWidth * 2
                        QGCLabel {
                            text:   "Name:"
                            width:  ScreenTools.defaultFontPixelWidth * 10
                            anchors.verticalCenter: parent.verticalCenter
                            horizontalAlignment: Text.AlignRight
                        }
                        QGCTextField {
                            id:     setName
511
                            width:  ScreenTools.defaultFontPixelWidth * 24
dogmaphobic's avatar
dogmaphobic committed
512 513 514 515 516 517 518 519 520 521 522 523 524 525
                            anchors.verticalCenter: parent.verticalCenter
                        }
                    }
                    Row {
                        spacing: ScreenTools.defaultFontPixelWidth * 2
                        QGCLabel {
                            text:  "Description:"
                            width:  ScreenTools.defaultFontPixelWidth * 10
                            anchors.verticalCenter: parent.verticalCenter
                            horizontalAlignment: Text.AlignRight
                        }
                        QGCTextField {
                            id:     setDescription
                            text:   "Description"
526
                            width:  ScreenTools.defaultFontPixelWidth * 24
dogmaphobic's avatar
dogmaphobic committed
527 528 529 530 531 532 533 534 535 536 537 538 539
                            anchors.verticalCenter: parent.verticalCenter
                        }
                    }
                    Row {
                        spacing: ScreenTools.defaultFontPixelWidth * 2
                        QGCLabel {
                            text:  "Map Type:"
                            width:  ScreenTools.defaultFontPixelWidth * 10
                            anchors.verticalCenter: parent.verticalCenter
                            horizontalAlignment: Text.AlignRight
                        }
                        QGCComboBox {
                            id:         mapCombo
540
                            width:      ScreenTools.defaultFontPixelWidth * 24
dogmaphobic's avatar
dogmaphobic committed
541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560
                            model:      QGroundControl.mapEngineManager.mapList
                            onActivated: {
                                mapType = textAt(index)
                                if(_dropButtonsExclusiveGroup.current)
                                    _dropButtonsExclusiveGroup.current.checked = false
                                _dropButtonsExclusiveGroup.current = null
                            }
                            Component.onCompleted: {
                                var index = mapCombo.find(mapType)
                                if (index === -1) {
                                    console.warn("Active map name not in combo", mapType)
                                } else {
                                    mapCombo.currentIndex = index
                                }
                            }
                        }
                    }
                }
                Item {
                    height: 1
561
                    width:  ScreenTools.defaultFontPixelWidth * 1.5
dogmaphobic's avatar
dogmaphobic committed
562 563 564 565 566 567 568 569 570 571 572 573
                }
                Column {
                    anchors.verticalCenter: parent.verticalCenter
                    spacing: ScreenTools.defaultFontPixelHeight * 0.5
                    QGCButton {
                        text:  "Download"
                        enabled: setName.text.length > 0
                        width: ScreenTools.defaultFontPixelWidth * 10
                        onClicked: {
                            if(QGroundControl.mapEngineManager.findName(setName.text)) {
                                duplicateName.visible = true
                            } else {
574
                                /* This does not work if hosted by QQuickWidget. Waiting until we're 100% QtQuick
dogmaphobic's avatar
dogmaphobic committed
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
                                var mapImage
                                _map.grabToImage(function(result) { mapImage = result; })
                                QGroundControl.mapEngineManager.startDownload(setName.text, setDescription.text, mapType, mapImage);
                                */
                                QGroundControl.mapEngineManager.startDownload(setName.text, setDescription.text, mapType);
                                showList()
                            }
                        }
                    }
                    QGCButton {
                        text:  "Cancel"
                        width: ScreenTools.defaultFontPixelWidth * 10
                        onClicked: {
                            showList()
                        }
                    }
                    MessageDialog {
                        id:         duplicateName
                        visible:    false
                        icon:       StandardIcon.Warning
                        standardButtons: StandardButton.Ok
                        title:      "Tile Set Already Exists"
                        text:       "Tile Set \"" + setName.text + "\" already exists.\nPlease select a different name."
                        onYes: {
                            duplicateName.visible = false
                        }
                    }
                }
            }
        }
    }
    Rectangle {
        id:                 _infoView
        color:              __qgcPal.windowShade
        width:              parent.width
        anchors.top:        _offlineMapTopRect.bottom
        anchors.bottom:     parent.bottom
        anchors.margins:    ScreenTools.defaultFontPixelWidth
        visible:            false

        Column {
            width:          parent.width
            spacing:        ScreenTools.defaultFontPixelHeight
            Item {
619
                height:     ScreenTools.defaultFontPixelHeight * 0.5
dogmaphobic's avatar
dogmaphobic committed
620 621 622 623 624 625 626 627 628 629 630
                width:      1
            }
            Rectangle {
                width:      infoWidth
                height:     nameLabel.height + (ScreenTools.defaultFontPixelHeight * 2)
                color:      __qgcPal.window
                radius:     ScreenTools.defaultFontPixelHeight * 0.5
                anchors.horizontalCenter: parent.horizontalCenter
                QGCLabel {
                    id:     nameLabel
                    text:   _offlineMapRoot._currentSelection ? _offlineMapRoot._currentSelection.name : ""
631
                    font.pixelSize:   ScreenTools.isAndroid ? ScreenTools.mediumFontPixelSize : ScreenTools.largeFontPixelSize
dogmaphobic's avatar
dogmaphobic committed
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
                    anchors.centerIn: parent
                }
            }
            QGCLabel {
                id:     descLabel
                text:   _offlineMapRoot._currentSelection ? _offlineMapRoot._currentSelection.description : ""
                anchors.horizontalCenter: parent.horizontalCenter
            }
            Rectangle {
                id:         infoRect
                width:      infoWidth
                height:     infoGrid.height + (ScreenTools.defaultFontPixelHeight * 4)
                color:      __qgcPal.window
                radius:     ScreenTools.defaultFontPixelHeight * 0.5
                anchors.horizontalCenter: parent.horizontalCenter
                GridLayout {
                    id:                 infoGrid
                    columns:            2
                    anchors.centerIn:   parent
                    anchors.margins:    ScreenTools.defaultFontPixelWidth  * 2
                    rowSpacing:         ScreenTools.defaultFontPixelWidth
                    columnSpacing:      ScreenTools.defaultFontPixelHeight * 2
                    QGCLabel {
                        text:       "Map Type:"
                        visible:    !isDefaultSet
                    }
                    QGCLabel {
                        text:       _offlineMapRoot._currentSelection ? _offlineMapRoot._currentSelection.mapTypeStr : ""
                        visible:    !isDefaultSet
                    }
                    QGCLabel {
                        text:       "Min Zoom:"
                        visible:    !isDefaultSet
                    }
                    QGCLabel {
                        text:       _offlineMapRoot._currentSelection ? _offlineMapRoot._currentSelection.minZoom : ""
                        visible:    !isDefaultSet
                    }
                    QGCLabel {
                        text:       "Max Zoom:"
                        visible:    !isDefaultSet
                    }
                    QGCLabel {
                        text:       _offlineMapRoot._currentSelection ? _offlineMapRoot._currentSelection.maxZoom : ""
                        visible:    !isDefaultSet
                    }
                    QGCLabel {
                        text:       isDefaultSet ? "Default Set Size:" : "Total Size:"
                    }
                    QGCLabel {
                        text:       _offlineMapRoot._currentSelection ? _offlineMapRoot._currentSelection.tilesSizeStr : ""
                    }
                    QGCLabel {
                        text:       isDefaultSet ? "Default Set Tile Count:" : "Total Tile Count:"
                    }
                    QGCLabel {
                        text:       _offlineMapRoot._currentSelection ? _offlineMapRoot._currentSelection.numTilesStr : ""
                    }
                    QGCLabel {
691
                        text:       isDefaultSet ? "Total Size (All Sets):" : "Downloaded Size:"
dogmaphobic's avatar
dogmaphobic committed
692 693 694 695 696
                    }
                    QGCLabel {
                        text:       _offlineMapRoot._currentSelection ? _offlineMapRoot._currentSelection.savedSizeStr : ""
                    }
                    QGCLabel {
697
                        text:       isDefaultSet ? "Total Count (All Sets):" : "Downloaded Count:"
dogmaphobic's avatar
dogmaphobic committed
698 699 700 701 702 703 704 705 706 707 708 709 710 711 712
                    }
                    QGCLabel {
                        text:       _offlineMapRoot._currentSelection ? _offlineMapRoot._currentSelection.savedTilesStr : ""
                    }
                    QGCLabel {
                        text:       "Error Count:"
                        visible:    !isDefaultSet && _offlineMapRoot._currentSelection && !_offlineMapRoot._currentSelection.complete
                    }
                    QGCLabel {
                        text:       _offlineMapRoot._currentSelection ? _offlineMapRoot._currentSelection.errorCountStr : ""
                        visible:    !isDefaultSet && _offlineMapRoot._currentSelection && !_offlineMapRoot._currentSelection.complete
                    }
                }
            }
            Item {
713
                height:     ScreenTools.defaultFontPixelHeight * 0.5
dogmaphobic's avatar
dogmaphobic committed
714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773
                width:      1
            }
            Row {
                anchors.horizontalCenter: parent.horizontalCenter
                spacing: ScreenTools.defaultFontPixelWidth
                QGCButton {
                    width:      ScreenTools.defaultFontPixelWidth * 18
                    text:       "Delete"
                    enabled:    _offlineMapRoot._currentSelection && (!_offlineMapRoot._currentSelection.deleting)
                    onClicked: {
                        if(_offlineMapRoot._currentSelection)
                            deleteDialog.visible = true
                    }
                    MessageDialog {
                        id:         deleteDialog
                        visible:    false
                        icon:       StandardIcon.Warning
                        standardButtons: StandardButton.Yes | StandardButton.No
                        title:      "Delete Tile Set"
                        text:       {
                            if(_offlineMapRoot._currentSelection) {
                                var blurb = "Delete " + _offlineMapRoot._currentSelection.name + " and all its tiles.\nIs this really what you want?"
                                if(_offlineMapRoot._currentSelection.defaultSet)
                                    return blurb + "\nNote that deleteting the Default Set deletes all tiles from all sets."
                                else
                                    return blurb
                            }
                            return ""
                        }
                        onYes: {
                            if(_offlineMapRoot._currentSelection)
                                QGroundControl.mapEngineManager.deleteTileSet(_offlineMapRoot._currentSelection)
                            deleteDialog.visible = false
                            showList()
                        }
                        onNo: {
                            deleteDialog.visible = false
                        }
                    }
                }
                QGCButton {
                    text:       "Resume Download"
                    width:      ScreenTools.defaultFontPixelWidth * 18
                    enabled:    _offlineMapRoot._currentSelection && (!_offlineMapRoot._currentSelection.deleting && !_offlineMapRoot._currentSelection.downloading)
                    visible:    !isDefaultSet && _offlineMapRoot._currentSelection && (!_offlineMapRoot._currentSelection.complete && !_offlineMapRoot._currentSelection.downloading)
                    onClicked: {
                        if(_offlineMapRoot._currentSelection)
                            _offlineMapRoot._currentSelection.resumeDownloadTask()
                    }
                }
                QGCButton {
                    text:       "Cancel Download"
                    width:      ScreenTools.defaultFontPixelWidth * 18
                    enabled:    _offlineMapRoot._currentSelection && (!_offlineMapRoot._currentSelection.deleting && _offlineMapRoot._currentSelection.downloading)
                    visible:    !isDefaultSet && _offlineMapRoot._currentSelection && (!_offlineMapRoot._currentSelection.complete && _offlineMapRoot._currentSelection.downloading)
                    onClicked: {
                        if(_offlineMapRoot._currentSelection)
                            _offlineMapRoot._currentSelection.cancelDownloadTask()
                    }
                }
774 775 776 777 778
                QGCButton {
                    text:       "Back"
                    width:      ScreenTools.defaultFontPixelWidth * 18
                    onClicked:  showList()
                }
dogmaphobic's avatar
dogmaphobic committed
779 780 781 782 783 784 785 786 787 788 789 790 791 792 793
            }
        }
    }
    Rectangle {
        id:                 _optionsView
        color:              __qgcPal.windowShade
        width:              parent.width
        anchors.top:        _offlineMapTopRect.bottom
        anchors.bottom:     parent.bottom
        anchors.margins:    ScreenTools.defaultFontPixelWidth
        visible:            false
        onVisibleChanged: {
            if(_optionsView.visible) {
                mapBoxToken.text     = QGroundControl.mapEngineManager.mapboxToken
                maxCacheSize.text    = QGroundControl.mapEngineManager.maxDiskCache
794
                maxCacheMemSize.text = QGroundControl.mapEngineManager.maxMemCache
dogmaphobic's avatar
dogmaphobic committed
795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812
            }
        }
        Column {
            width:          parent.width
            spacing:        ScreenTools.defaultFontPixelHeight
            Item {
                height:     ScreenTools.defaultFontPixelHeight
                width:      1
            }
            Rectangle {
                width:      infoWidth
                height:     optionsLabel.height + (ScreenTools.defaultFontPixelHeight * 2)
                color:      __qgcPal.window
                radius:     ScreenTools.defaultFontPixelHeight * 0.5
                anchors.horizontalCenter: parent.horizontalCenter
                QGCLabel {
                    id:     optionsLabel
                    text:   "Offline Map Options"
813 814
                    font.pixelSize:     ScreenTools.isAndroid ? ScreenTools.mediumFontPixelSize : ScreenTools.largeFontPixelSize
                    anchors.centerIn:   parent
dogmaphobic's avatar
dogmaphobic committed
815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835
                }
            }
            Rectangle {
                id:         optionsRect
                width:      optionsGrid.width  + (ScreenTools.defaultFontPixelWidth * 4)
                height:     optionsGrid.height + (ScreenTools.defaultFontPixelHeight * 4)
                color:      __qgcPal.window
                radius:     ScreenTools.defaultFontPixelHeight * 0.5
                anchors.horizontalCenter: parent.horizontalCenter
                GridLayout {
                    id:                 optionsGrid
                    columns:            2
                    anchors.centerIn:   parent
                    anchors.margins:    ScreenTools.defaultFontPixelWidth  * 2
                    rowSpacing:         ScreenTools.defaultFontPixelWidth  * 1.5
                    columnSpacing:      ScreenTools.defaultFontPixelHeight * 2
                    QGCLabel {
                        text:       "Max Cache Disk Size (MB):"
                    }
                    QGCTextField {
                        id:             maxCacheSize
836
                        maximumLength:  6
dogmaphobic's avatar
dogmaphobic committed
837 838 839 840 841 842 843 844
                        inputMethodHints: Qt.ImhDigitsOnly
                        validator: IntValidator {bottom: 1; top: 262144;}
                    }
                    QGCLabel {
                        text:       "Max Cache Memory Size (MB):"
                    }
                    QGCTextField {
                        id:             maxCacheMemSize
845
                        maximumLength:  4
dogmaphobic's avatar
dogmaphobic committed
846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871
                        inputMethodHints: Qt.ImhDigitsOnly
                        validator: IntValidator {bottom: 1; top: 4096;}
                    }
                    Item {
                        Layout.columnSpan:  2
                        Layout.fillWidth:   true
                        implicitHeight:     ScreenTools.defaultFontPixelHeight * 1.5
                        QGCLabel {
                            anchors.centerIn: parent
                            text: "Memory cache changes require a restart to take effect."
                            font.pixelSize: ScreenTools.defaultFontPixelSize * 0.85
                        }
                    }
                    Rectangle {
                        Layout.columnSpan:  2
                        Layout.fillWidth:   true
                        implicitHeight:     1
                        color:              __qgcPal.text
                    }
                    QGCLabel {
                        text: "MapBox Access Token"
                    }
                    QGCTextField {
                        id:                 mapBoxToken
                        Layout.fillWidth:   true
                        maximumLength:      256
872
                        implicitWidth :     ScreenTools.defaultFontPixelWidth * 30
dogmaphobic's avatar
dogmaphobic committed
873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892
                    }
                    Item {
                        Layout.columnSpan:  2
                        Layout.fillWidth:   true
                        implicitHeight:     ScreenTools.defaultFontPixelHeight * 1.5
                        QGCLabel {
                            anchors.centerIn: parent
                            text: "With an access token, you can use MapBox Maps."
                            font.pixelSize: ScreenTools.defaultFontPixelSize * 0.85
                        }
                    }
                }
            }
            Row {
                anchors.horizontalCenter: parent.horizontalCenter
                spacing: ScreenTools.defaultFontPixelWidth
                QGCButton {
                    text:       "Save"
                    width:      ScreenTools.defaultFontPixelWidth * 18
                    onClicked:  {
893 894 895
                        QGroundControl.mapEngineManager.mapboxToken  = mapBoxToken.text
                        QGroundControl.mapEngineManager.maxDiskCache = parseInt(maxCacheSize.text)
                        QGroundControl.mapEngineManager.maxMemCache  = parseInt(maxCacheMemSize.text)
dogmaphobic's avatar
dogmaphobic committed
896 897 898 899 900 901 902 903 904 905 906 907 908 909
                        showList()
                    }
                }
                QGCButton {
                    text:       "Cancel"
                    width:      ScreenTools.defaultFontPixelWidth * 18
                    onClicked:  {
                        showList()
                    }
                }
            }
        }
    }
}