OfflineMap.qml 52.9 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.
 *
 ****************************************************************************/
dogmaphobic's avatar
dogmaphobic committed
9 10 11 12 13 14 15


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
16 17
import QtLocation               5.5
import QtPositioning            5.5
dogmaphobic's avatar
dogmaphobic committed
18 19 20 21 22 23 24 25

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

Rectangle {
    id:                 _offlineMapRoot
26
    color:              qgcPal.window
dogmaphobic's avatar
dogmaphobic committed
27 28 29
    anchors.fill:       parent
    anchors.margins:    ScreenTools.defaultFontPixelWidth

dogmaphobic's avatar
dogmaphobic committed
30
    property var    _currentSelection:  null
dogmaphobic's avatar
dogmaphobic committed
31

dogmaphobic's avatar
dogmaphobic committed
32
    property string mapKey:             "lastMapType"
dogmaphobic's avatar
dogmaphobic committed
33

34 35 36 37 38 39 40 41
    property string mapType:            QGroundControl.mapEngineManager.loadSetting(mapKey, "Google Street Map")
    property int    mapMargin:          (ScreenTools.defaultFontPixelHeight * 0.2).toFixed(0)
    property real   infoWidth:          Math.max(infoCol.width, (ScreenTools.defaultFontPixelWidth * 40))
    property bool   isDefaultSet:       _offlineMapRoot._currentSelection && _offlineMapRoot._currentSelection.defaultSet
    property bool   isMapInteractive:   true
    property var    savedCenter:        undefined
    property real   savedZoom:          3
    property string savedMapType:       ""
dogmaphobic's avatar
dogmaphobic committed
42

dogmaphobic's avatar
dogmaphobic committed
43
    property real   _newSetMiddleLabel: ScreenTools.isTinyScreen ? ScreenTools.defaultFontPixelWidth * 10 : ScreenTools.defaultFontPixelWidth * 12
44
    property real   _newSetMiddleField: ScreenTools.isTinyScreen ? ScreenTools.defaultFontPixelWidth * 16 : ScreenTools.defaultFontPixelWidth * 20
dogmaphobic's avatar
dogmaphobic committed
45
    property real   _netSetSliderWidth: ScreenTools.isTinyScreen ? ScreenTools.defaultFontPixelWidth *  8 : ScreenTools.defaultFontPixelWidth * 16
46

dogmaphobic's avatar
dogmaphobic committed
47 48 49 50 51 52 53
    property real oldlon0:      0
    property real oldlon1:      0
    property real oldlat0:      0
    property real oldlat1:      0
    property int  oldz0:        0
    property int  oldz1:        0

Don Gagne's avatar
Don Gagne committed
54 55 56
    readonly property real minZoomLevel: 3
    readonly property real maxZoomLevel: 20

57 58
    QGCPalette { id: qgcpal }

dogmaphobic's avatar
dogmaphobic committed
59 60 61
    Component.onCompleted: {
        QGroundControl.mapEngineManager.loadTileSets()
        updateMap()
62
        savedCenter = _map.toCoordinate(Qt.point(_map.width / 2, _map.height / 2))
dogmaphobic's avatar
dogmaphobic committed
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77
    }

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

    ExclusiveGroup { id: setGroup }

    function handleChanges() {
78 79 80 81 82 83 84 85 86 87
        if(isMapInteractive) {
            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)
            }
dogmaphobic's avatar
dogmaphobic committed
88 89 90 91
        }
    }

    function checkSanity() {
92
        if(isMapInteractive && QGroundControl.mapEngineManager.crazySize) {
dogmaphobic's avatar
dogmaphobic committed
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108
            _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() {
109
        _map.visible = false
dogmaphobic's avatar
dogmaphobic committed
110 111
        _tileSetList.visible = false
        _infoView.visible = false
112
        _defaultInfoView.visible = false
dogmaphobic's avatar
dogmaphobic committed
113 114 115 116 117
        _mapView.visible = false
        _optionsView.visible = true
    }

    function showMap() {
118
        _map.visible = true
dogmaphobic's avatar
dogmaphobic committed
119 120
        _tileSetList.visible = false
        _infoView.visible = false
121
        _defaultInfoView.visible = false
dogmaphobic's avatar
dogmaphobic committed
122 123 124 125 126
        _mapView.visible = true
        _optionsView.visible = false
    }

    function showList() {
127
        _map.visible = false
dogmaphobic's avatar
dogmaphobic committed
128 129
        _tileSetList.visible = true
        _infoView.visible = false
130
        _defaultInfoView.visible = false
dogmaphobic's avatar
dogmaphobic committed
131 132 133 134 135 136
        _mapView.visible = false
        _optionsView.visible = false
    }

    function showInfo() {
        if(_currentSelection && !_offlineMapRoot._currentSelection.deleting) {
137
            enterInfoView()
dogmaphobic's avatar
dogmaphobic committed
138 139 140 141
        } else
            showList()
    }

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
    function toRadian(deg) {
        return deg * Math.PI / 180
    }

    function toDegree(rad) {
        return rad * 180 / Math.PI
    }

    function midPoint(lat1, lat2, lon1, lon2) {
        var dLon = toRadian(lon2 - lon1);
        lat1 = toRadian(lat1);
        lat2 = toRadian(lat2);
        lon1 = toRadian(lon1);
        var Bx = Math.cos(lat2) * Math.cos(dLon);
        var By = Math.cos(lat2) * Math.sin(dLon);
        var lat3 = Math.atan2(Math.sin(lat1) + Math.sin(lat2), Math.sqrt((Math.cos(lat1) + Bx) * (Math.cos(lat1) + Bx) + By * By));
        var lon3 = lon1 + Math.atan2(By, Math.cos(lat1) + Bx);
        return QtPositioning.coordinate(toDegree(lat3), toDegree(lon3))
    }

    function enterInfoView() {
        if(!isDefaultSet) {
            isMapInteractive = false
            savedCenter = _map.toCoordinate(Qt.point(_map.width / 2, _map.height / 2))
            savedZoom = _map.zoomLevel
            savedMapType = mapType
            _map.visible = true
            mapType = _offlineMapRoot._currentSelection.mapTypeStr
            _map.center = midPoint(_offlineMapRoot._currentSelection.topleftLat, _offlineMapRoot._currentSelection.bottomRightLat, _offlineMapRoot._currentSelection.topleftLon, _offlineMapRoot._currentSelection.bottomRightLon)
171 172 173 174 175 176 177 178 179
            //-- Delineate Set Region
            var x0 = _offlineMapRoot._currentSelection.topleftLon
            var x1 = _offlineMapRoot._currentSelection.bottomRightLon
            var y0 = _offlineMapRoot._currentSelection.topleftLat
            var y1 = _offlineMapRoot._currentSelection.bottomRightLat
            mapBoundary.topLeft     = QtPositioning.coordinate(y0, x0)
            mapBoundary.bottomRight = QtPositioning.coordinate(y1, x1)
            mapBoundary.visible = true
            _map.fitViewportToMapItems()
180 181
        }
        _tileSetList.visible = false
182
        _mapView.visible     = false
183 184
        _optionsView.visible = false
        if(isDefaultSet) {
185
            _defaultInfoView.visible = true
186
        } else {
187
            _infoView.visible= true
188 189 190 191
        }
    }

    function leaveInfoView() {
192
        mapBoundary.visible = false
193 194 195 196 197 198
        _map.center = savedCenter
        _map.zoomLevel = savedZoom
        mapType = savedMapType
        isMapInteractive = true
    }

dogmaphobic's avatar
dogmaphobic committed
199 200 201 202 203 204
    ExclusiveGroup {
        id: _dropButtonsExclusiveGroup
    }

    onMapTypeChanged: {
        updateMap()
205 206 207
        if(isMapInteractive) {
            QGroundControl.mapEngineManager.saveSetting(mapKey, mapType)
        }
dogmaphobic's avatar
dogmaphobic committed
208 209 210 211 212 213 214 215
    }

    MessageDialog {
        id:         errorDialog
        visible:    false
        text:       QGroundControl.mapEngineManager.errorMessage
        icon:       StandardIcon.Critical
        standardButtons: StandardButton.Ok
216
        title:      qsTr("Errror Message")
dogmaphobic's avatar
dogmaphobic committed
217 218 219 220
        onYes: {
            errorDialog.visible = false
        }
    }
Don Gagne's avatar
Don Gagne committed
221

dogmaphobic's avatar
dogmaphobic committed
222 223 224 225
    Rectangle {
        id:         _offlineMapTopRect
        width:      parent.width
        height:     labelTitle.height + ScreenTools.defaultFontPixelHeight
226
        color:      qgcPal.window
dogmaphobic's avatar
dogmaphobic committed
227 228 229 230 231 232
        anchors.top: parent.top
        Row {
            spacing: ScreenTools.defaultFontPixelHeight * 2
            anchors.verticalCenter: parent.verticalCenter
            QGCLabel {
                id:         labelTitle
233
                text:       qsTr("Offline Maps")
234
                font.pointSize: ScreenTools.mediumFontPointSize
dogmaphobic's avatar
dogmaphobic committed
235 236 237 238
                anchors.verticalCenter: parent.verticalCenter
            }
            QGCCheckBox {
                id:         showTilePreview
239
                text:       qsTr("Show tile min/max zoom level preview")
dogmaphobic's avatar
dogmaphobic committed
240
                checked:    false
241
                visible:    _mapView.visible && !ScreenTools.isTinyScreen
dogmaphobic's avatar
dogmaphobic committed
242 243 244 245
                anchors.verticalCenter: parent.verticalCenter
            }
        }
    }
Don Gagne's avatar
Don Gagne committed
246

247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265
    Map {
        id:                 _map
        anchors.top:        _offlineMapTopRect.bottom
        anchors.left:       parent.left
        anchors.bottom:     parent.bottom
        anchors.margins:    mapMargin
        width:              parent.width - ScreenTools.defaultFontPixelWidth
        center:             QGroundControl.defaultMapPosition
        visible:            false
        gesture.flickDeceleration:  3000
        plugin: Plugin { name: "QGroundControl" }

        Rectangle {
            color: Qt.rgba(0,0,0,0)
            border.color: "black"
            border.width: 1
            anchors.fill: parent
        }

266 267 268 269 270 271 272 273 274
        MapRectangle {
            id:             mapBoundary
            border.width:   2
            border.color:   "red"
            color:          Qt.rgba(1,0,0,0.05)
            smooth:         true
            antialiasing:   true
        }

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
        Component.onCompleted: {
            center = QGroundControl.flightMapPosition
            zoomLevel = QGroundControl.flightMapZoom
        }

        onCenterChanged: {
            handleChanges()
            checkSanity()
        }
        onZoomLevelChanged: {
            handleChanges()
            checkSanity()
        }
        onWidthChanged: {
            handleChanges()
            checkSanity()
        }
        onHeightChanged: {
            handleChanges()
            checkSanity()
        }
        // Used to make pinch zoom work
        MouseArea {
            anchors.fill: parent
        }
    }

dogmaphobic's avatar
dogmaphobic committed
302 303 304 305
    QGCFlickable {
        id:                 _tileSetList
        clip:               true
        anchors.top:        _offlineMapTopRect.bottom
Don Gagne's avatar
Don Gagne committed
306 307 308
        anchors.left:       parent.left
        anchors.right:      parent.right
        anchors.bottom:     _optionsButton.top
dogmaphobic's avatar
dogmaphobic committed
309 310
        contentHeight:      _cacheList.height
        flickableDirection: Flickable.VerticalFlick
Don Gagne's avatar
Don Gagne committed
311

dogmaphobic's avatar
dogmaphobic committed
312 313
        Column {
            id:                 _cacheList
Don Gagne's avatar
Don Gagne committed
314
            width:              Math.min(parent.width, (ScreenTools.defaultFontPixelWidth  * 50).toFixed(0))
dogmaphobic's avatar
dogmaphobic committed
315
            anchors.margins:    ScreenTools.defaultFontPixelWidth
316
            spacing:            ScreenTools.defaultFontPixelHeight * 0.5
Don Gagne's avatar
Don Gagne committed
317 318
            anchors.horizontalCenter: parent.horizontalCenter

dogmaphobic's avatar
dogmaphobic committed
319
            OfflineMapButton {
320
                text:           qsTr("Add new set")
Don Gagne's avatar
Don Gagne committed
321 322
                anchors.left:   parent.left
                anchors.right:  parent.right
323
                height:         ScreenTools.defaultFontPixelHeight * 2
dogmaphobic's avatar
dogmaphobic committed
324 325 326 327 328 329 330 331
                onClicked: {
                    _offlineMapRoot._currentSelection = null
                    showMap()
                }
            }
            Repeater {
                model: QGroundControl.mapEngineManager.tileSets
                delegate: OfflineMapButton {
Don Gagne's avatar
Don Gagne committed
332 333 334 335 336
                    text:           object.name
                    size:           object.downloadStatus
                    complete:       object.complete
                    anchors.left:   parent.left
                    anchors.right:  parent.right
337
                    height:         ScreenTools.defaultFontPixelHeight * 2
dogmaphobic's avatar
dogmaphobic committed
338 339 340 341 342 343 344 345
                    onClicked: {
                        _offlineMapRoot._currentSelection = object
                        showInfo()
                    }
                }
            }
        }
    }
Don Gagne's avatar
Don Gagne committed
346

dogmaphobic's avatar
dogmaphobic committed
347 348
    QGCButton {
        id:              _optionsButton
349
        text:            qsTr("Options")
dogmaphobic's avatar
dogmaphobic committed
350 351 352 353 354 355
        visible:         _tileSetList.visible
        anchors.bottom:  parent.bottom
        anchors.right:   parent.right
        anchors.margins: ScreenTools.defaultFontPixelWidth
        onClicked:       showOptions()
    }
Don Gagne's avatar
Don Gagne committed
356

dogmaphobic's avatar
dogmaphobic committed
357
    //-- Offline Map Definition
358
    Item {
dogmaphobic's avatar
dogmaphobic committed
359 360 361 362 363 364 365
        id:                 _mapView
        width:              parent.width
        anchors.top:        _offlineMapTopRect.bottom
        anchors.bottom:     parent.bottom
        anchors.margins:    ScreenTools.defaultFontPixelWidth
        visible:            false

366 367
        //-- Zoom Preview Maps
        Item {
dogmaphobic's avatar
dogmaphobic committed
368 369
            width:          parent.width
            anchors.top:    parent.top
370
            visible:        showTilePreview.checked
dogmaphobic's avatar
dogmaphobic committed
371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407
            Rectangle {
                width:              ScreenTools.defaultFontPixelHeight * 16
                height:             ScreenTools.defaultFontPixelHeight * 9
                anchors.top:        parent.top
                anchors.left:       parent.left
                anchors.margins:    ScreenTools.defaultFontPixelHeight
                color:              "black"
                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"
                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" }
                }
            }
        }
408
        //-- Tile set settings
dogmaphobic's avatar
dogmaphobic committed
409 410
        Rectangle {
            id:     bottomRect
411
            width:  _controlRow.width  + (ScreenTools.defaultFontPixelWidth  * 2)
dogmaphobic's avatar
dogmaphobic committed
412
            height: _controlRow.height + (ScreenTools.defaultFontPixelHeight * 2)
413
            color:  qgcPal.window
414 415 416 417 418
            radius: ScreenTools.defaultFontPixelWidth * 0.5
            anchors.horizontalCenter: parent.horizontalCenter
            Component.onCompleted: {
                color = Qt.rgba(color.r, color.g, color.b, 0.85)
            }
dogmaphobic's avatar
dogmaphobic committed
419 420 421 422
            anchors.bottom: parent.bottom
            Row {
                id: _controlRow
                anchors.centerIn: parent
423
                spacing: ScreenTools.defaultFontPixelWidth * 0.5
dogmaphobic's avatar
dogmaphobic committed
424
                Rectangle {
425 426 427 428 429
                    height:         _zoomRow.height + ScreenTools.defaultFontPixelHeight * 1.5
                    width:          _zoomRow.width  + ScreenTools.defaultFontPixelWidth
                    color:          "#98aca4"
                    border.color:   "black"
                    border.width:   2
dogmaphobic's avatar
dogmaphobic committed
430 431 432
                    radius:     ScreenTools.defaultFontPixelWidth * 0.5
                    anchors.verticalCenter: parent.verticalCenter
                    Row {
433
                        id:                 _zoomRow
dogmaphobic's avatar
dogmaphobic committed
434 435
                        anchors.centerIn:   parent
                        Column {
436
                            spacing:        ScreenTools.defaultFontPixelHeight * 0.5
dogmaphobic's avatar
dogmaphobic committed
437 438
                            anchors.verticalCenter: parent.verticalCenter
                            Row {
439
                                spacing:    ScreenTools.defaultFontPixelWidth * 0.5
dogmaphobic's avatar
dogmaphobic committed
440 441 442
                                Column {
                                    anchors.verticalCenter: parent.verticalCenter
                                    Label {
443 444
                                        text:                   qsTr("Min")
                                        color:                  "black"
445 446
                                        width:                  ScreenTools.defaultFontPixelWidth * 4
                                        font.pointSize:         ScreenTools.smallFontPointSize
447 448
                                        horizontalAlignment:    Text.AlignHCenter
                                        font.family:            ScreenTools.normalFontFamily
dogmaphobic's avatar
dogmaphobic committed
449 450
                                    }
                                    Label {
451 452
                                        text:                   qsTr("Zoom")
                                        color:                  "black"
453
                                        width:                  ScreenTools.defaultFontPixelWidth * 4
454
                                        font.family:            ScreenTools.normalFontFamily
455
                                        font.pointSize:         ScreenTools.smallFontPointSize
456
                                        horizontalAlignment:    Text.AlignHCenter
dogmaphobic's avatar
dogmaphobic committed
457 458 459 460
                                    }
                                }
                                Slider {
                                    id:                 _slider0
Don Gagne's avatar
Don Gagne committed
461 462
                                    minimumValue:       minZoomLevel
                                    maximumValue:       maxZoomLevel
dogmaphobic's avatar
dogmaphobic committed
463 464 465 466 467 468 469
                                    stepSize:           1
                                    tickmarksEnabled:   false
                                    orientation:        Qt.Horizontal
                                    updateValueWhileDragging: true
                                    anchors.verticalCenter: parent.verticalCenter
                                    style: SliderStyle {
                                        groove: Rectangle {
470
                                            implicitWidth:  _netSetSliderWidth
dogmaphobic's avatar
dogmaphobic committed
471 472 473 474 475 476 477 478 479
                                            implicitHeight: 4
                                            color:          "gray"
                                            radius:         4
                                        }
                                        handle: Rectangle {
                                            anchors.centerIn: parent
                                            color: control.pressed ? "white" : "lightgray"
                                            border.color: "gray"
                                            border.width:   2
480 481
                                            implicitWidth:  ScreenTools.defaultFontPixelWidth * 3
                                            implicitHeight: ScreenTools.defaultFontPixelWidth * 3
dogmaphobic's avatar
dogmaphobic committed
482 483
                                            radius:         10
                                            Label {
484 485 486
                                                text:               _slider0.value
                                                anchors.centerIn:   parent
                                                font.family:        ScreenTools.normalFontFamily
487
                                                font.pointSize:     ScreenTools.smallFontPointSize
dogmaphobic's avatar
dogmaphobic committed
488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510
                                            }
                                        }
                                    }
                                    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 {
511 512
                                        text:           qsTr("Max")
                                        color:          "black"
513 514
                                        width:          ScreenTools.defaultFontPixelWidth * 4
                                        font.pointSize: ScreenTools.smallFontPointSize
515
                                        font.family:    ScreenTools.normalFontFamily
dogmaphobic's avatar
dogmaphobic committed
516 517 518
                                        horizontalAlignment: Text.AlignHCenter
                                    }
                                    Label {
519 520
                                        text:           qsTr("Zoom")
                                        color:          "black"
521 522
                                        width:          ScreenTools.defaultFontPixelWidth * 4
                                        font.pointSize: ScreenTools.smallFontPointSize
523
                                        font.family:    ScreenTools.normalFontFamily
dogmaphobic's avatar
dogmaphobic committed
524 525 526 527 528
                                        horizontalAlignment: Text.AlignHCenter
                                    }
                                }
                                Slider {
                                    id:                 _slider1
Don Gagne's avatar
Don Gagne committed
529 530
                                    minimumValue:       minZoomLevel
                                    maximumValue:       maxZoomLevel
dogmaphobic's avatar
dogmaphobic committed
531 532 533 534 535 536 537
                                    stepSize:           1
                                    tickmarksEnabled:   false
                                    orientation:        Qt.Horizontal
                                    updateValueWhileDragging: true
                                    anchors.verticalCenter: parent.verticalCenter
                                    style: SliderStyle {
                                        groove: Rectangle {
538
                                            implicitWidth:  _netSetSliderWidth
dogmaphobic's avatar
dogmaphobic committed
539 540 541 542 543 544 545 546 547
                                            implicitHeight: 4
                                            color:          "gray"
                                            radius:         4
                                        }
                                        handle: Rectangle {
                                            anchors.centerIn: parent
                                            color: control.pressed ? "white" : "lightgray"
                                            border.color: "gray"
                                            border.width:   2
548 549
                                            implicitWidth:  ScreenTools.defaultFontPixelWidth * 3
                                            implicitHeight: ScreenTools.defaultFontPixelWidth * 3
dogmaphobic's avatar
dogmaphobic committed
550 551
                                            radius:         10
                                            Label {
552 553
                                                text:               _slider1.value
                                                anchors.centerIn:   parent
554 555
                                                font.family:        ScreenTools.normalFontFamily
                                                font.pointSize:     ScreenTools.smallFontPointSize
dogmaphobic's avatar
dogmaphobic committed
556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576
                                            }
                                        }
                                    }
                                    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 {
577 578 579
                                text:           qsTr("Tile Count")
                                color:          "black"
                                width:          ScreenTools.defaultFontPixelWidth * 12
580
                                font.pointSize: ScreenTools.smallFontPointSize
581
                                font.family:    ScreenTools.normalFontFamily
dogmaphobic's avatar
dogmaphobic committed
582 583 584
                                horizontalAlignment: Text.AlignHCenter
                            }
                            Label {
585 586 587 588
                                text:           QGroundControl.mapEngineManager.tileCountStr
                                color:          "black"
                                width:          ScreenTools.defaultFontPixelWidth * 12
                                font.family:    ScreenTools.normalFontFamily
589
                                font.pointSize: ScreenTools.defaultFontPointSize
dogmaphobic's avatar
dogmaphobic committed
590 591 592
                                horizontalAlignment: Text.AlignHCenter
                            }
                            Label {
593 594 595
                                text:           qsTr("Set Size (Est)")
                                color:          "black"
                                width:          ScreenTools.defaultFontPixelWidth * 12
596
                                font.pointSize: ScreenTools.smallFontPointSize
597
                                font.family:    ScreenTools.normalFontFamily
dogmaphobic's avatar
dogmaphobic committed
598 599 600
                                horizontalAlignment: Text.AlignHCenter
                            }
                            Label {
601 602 603 604
                                text:           QGroundControl.mapEngineManager.tileSizeStr
                                color:          "black"
                                width:          ScreenTools.defaultFontPixelWidth * 12
                                font.family:    ScreenTools.normalFontFamily
605
                                font.pointSize: ScreenTools.defaultFontPointSize
dogmaphobic's avatar
dogmaphobic committed
606 607 608 609 610 611 612 613 614
                                horizontalAlignment: Text.AlignHCenter
                            }
                        }
                    }
                }
                Column {
                    anchors.verticalCenter: parent.verticalCenter
                    spacing:            ScreenTools.defaultFontPixelHeight * 0.5
                    Row {
615
                        spacing:        ScreenTools.defaultFontPixelWidth
dogmaphobic's avatar
dogmaphobic committed
616
                        QGCLabel {
617
                            text:   qsTr("Name:")
618
                            width:  _newSetMiddleLabel
dogmaphobic's avatar
dogmaphobic committed
619 620 621 622 623
                            anchors.verticalCenter: parent.verticalCenter
                            horizontalAlignment: Text.AlignRight
                        }
                        QGCTextField {
                            id:     setName
624
                            width:  _newSetMiddleField
dogmaphobic's avatar
dogmaphobic committed
625 626 627 628
                            anchors.verticalCenter: parent.verticalCenter
                        }
                    }
                    Row {
629
                        spacing: ScreenTools.defaultFontPixelWidth
dogmaphobic's avatar
dogmaphobic committed
630
                        QGCLabel {
631 632
                            text:   qsTr("Description:")
                            width:  _newSetMiddleLabel
dogmaphobic's avatar
dogmaphobic committed
633 634 635 636 637
                            anchors.verticalCenter: parent.verticalCenter
                            horizontalAlignment: Text.AlignRight
                        }
                        QGCTextField {
                            id:     setDescription
638
                            text:   qsTr("Description")
639
                            width:  _newSetMiddleField
dogmaphobic's avatar
dogmaphobic committed
640 641 642 643
                            anchors.verticalCenter: parent.verticalCenter
                        }
                    }
                    Row {
644
                        spacing: ScreenTools.defaultFontPixelWidth
dogmaphobic's avatar
dogmaphobic committed
645
                        QGCLabel {
646 647
                            text:   qsTr("Map Type:")
                            width:  _newSetMiddleLabel
dogmaphobic's avatar
dogmaphobic committed
648 649 650 651 652
                            anchors.verticalCenter: parent.verticalCenter
                            horizontalAlignment: Text.AlignRight
                        }
                        QGCComboBox {
                            id:         mapCombo
653
                            width:      _newSetMiddleField
dogmaphobic's avatar
dogmaphobic committed
654 655 656 657 658 659 660 661 662 663
                            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) {
664
                                    console.warn(qsTr("Active map name not in combo"), mapType)
dogmaphobic's avatar
dogmaphobic committed
665 666 667 668 669 670 671 672 673
                                } else {
                                    mapCombo.currentIndex = index
                                }
                            }
                        }
                    }
                }
                Item {
                    height: 1
dogmaphobic's avatar
dogmaphobic committed
674
                    width:  ScreenTools.defaultFontPixelWidth
dogmaphobic's avatar
dogmaphobic committed
675 676 677 678 679
                }
                Column {
                    anchors.verticalCenter: parent.verticalCenter
                    spacing: ScreenTools.defaultFontPixelHeight * 0.5
                    QGCButton {
680
                        text:  qsTr("Download")
dogmaphobic's avatar
dogmaphobic committed
681
                        enabled: setName.text.length > 0
682
                        width: ScreenTools.defaultFontPixelWidth * 10
dogmaphobic's avatar
dogmaphobic committed
683 684 685 686
                        onClicked: {
                            if(QGroundControl.mapEngineManager.findName(setName.text)) {
                                duplicateName.visible = true
                            } else {
687
                                /* This does not work if hosted by QQuickWidget. Waiting until we're 100% QtQuick
dogmaphobic's avatar
dogmaphobic committed
688 689 690 691 692 693 694 695 696 697
                                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 {
698
                        text:  qsTr("Cancel")
699
                        width: ScreenTools.defaultFontPixelWidth * 10
dogmaphobic's avatar
dogmaphobic committed
700 701 702 703 704 705 706 707 708
                        onClicked: {
                            showList()
                        }
                    }
                    MessageDialog {
                        id:         duplicateName
                        visible:    false
                        icon:       StandardIcon.Warning
                        standardButtons: StandardButton.Ok
709 710
                        title:      qsTr("Tile Set Already Exists")
                        text:       qsTr("Tile Set \"%1\" already exists.\nPlease select a different name.").arg(setName.text)
dogmaphobic's avatar
dogmaphobic committed
711 712 713 714 715 716 717 718
                        onYes: {
                            duplicateName.visible = false
                        }
                    }
                }
            }
        }
    }
719 720 721

    //-- Show Set Info
    Item {
dogmaphobic's avatar
dogmaphobic committed
722
        id:                 _infoView
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
        width:              parent.width
        anchors.bottom:     parent.bottom
        anchors.margins:    ScreenTools.defaultFontPixelWidth
        visible:            false

        //-- Tile set settings
        Rectangle {
            id:     bottomInfoRect
            width:  _controlInfoRow.width  + (ScreenTools.defaultFontPixelWidth  * 2)
            height: _controlInfoRow.height + (ScreenTools.defaultFontPixelHeight * 2)
            color:  qgcPal.window
            radius: ScreenTools.defaultFontPixelWidth * 0.5
            anchors.margins: ScreenTools.defaultFontPixelWidth
            anchors.horizontalCenter: parent.horizontalCenter
            Component.onCompleted: {
                color = Qt.rgba(color.r, color.g, color.b, 0.85)
            }
            anchors.bottom: parent.bottom
            Row {
                id: _controlInfoRow
                anchors.centerIn: parent
                spacing: ScreenTools.defaultFontPixelWidth * 4
                Column {
                    anchors.rightMargin:    ScreenTools.defaultFontPixelWidth
                    anchors.leftMargin:     ScreenTools.defaultFontPixelWidth
                    anchors.verticalCenter: parent.verticalCenter
                    spacing:                ScreenTools.defaultFontPixelHeight * 0.5
                    QGCLabel {
                        text:   _offlineMapRoot._currentSelection ? _offlineMapRoot._currentSelection.name : ""
752
                        font.pointSize:   ScreenTools.isAndroid ? ScreenTools.mediumFontPointSize : ScreenTools.largeFontPointSize
753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 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 872 873 874 875
                        anchors.horizontalCenter: parent.horizontalCenter
                    }
                    QGCLabel {
                        text:    _offlineMapRoot._currentSelection ? _offlineMapRoot._currentSelection.description : ""
                        visible: text !== qsTr("Description")
                        anchors.horizontalCenter: parent.horizontalCenter
                    }
                    QGCLabel {
                        text:   _offlineMapRoot._currentSelection ? "(" + _offlineMapRoot._currentSelection.mapTypeStr + ")" : ""
                    }
                }
                GridLayout {
                    columns:            2
                    anchors.margins:    ScreenTools.defaultFontPixelWidth
                    rowSpacing:         ScreenTools.defaultFontPixelWidth
                    columnSpacing:      ScreenTools.defaultFontPixelHeight
                    QGCLabel {
                        text:       qsTr("Min Zoom:")
                    }
                    QGCLabel {
                        text:       _offlineMapRoot._currentSelection ? _offlineMapRoot._currentSelection.minZoom : ""
                    }
                    QGCLabel {
                        text:       qsTr("Max Zoom:")
                    }
                    QGCLabel {
                        text:       _offlineMapRoot._currentSelection ? _offlineMapRoot._currentSelection.maxZoom : ""
                    }
                    QGCLabel {
                        text:       qsTr("Total:")
                    }
                    QGCLabel {
                        text:       (_offlineMapRoot._currentSelection ? _offlineMapRoot._currentSelection.numTilesStr : "") + " (" + (_offlineMapRoot._currentSelection ? _offlineMapRoot._currentSelection.tilesSizeStr : "") + ")"
                    }
                    QGCLabel {
                        text:       qsTr("Downloaded:")
                        visible:    _offlineMapRoot._currentSelection && !_offlineMapRoot._currentSelection.complete
                    }
                    QGCLabel {
                        text:        (_offlineMapRoot._currentSelection ? _offlineMapRoot._currentSelection.savedTilesStr : "") + " (" + (_offlineMapRoot._currentSelection ? _offlineMapRoot._currentSelection.savedSizeStr : "") + ")"
                        visible:    _offlineMapRoot._currentSelection && !_offlineMapRoot._currentSelection.complete
                    }
                    QGCLabel {
                        text:       qsTr("Error Count:")
                        visible:    _offlineMapRoot._currentSelection && !_offlineMapRoot._currentSelection.complete
                    }
                    QGCLabel {
                        text:       _offlineMapRoot._currentSelection ? _offlineMapRoot._currentSelection.errorCountStr : ""
                        visible:    _offlineMapRoot._currentSelection && !_offlineMapRoot._currentSelection.complete
                    }
                }
                Column {
                    anchors.verticalCenter: parent.verticalCenter
                    spacing:  ScreenTools.defaultFontPixelHeight * 0.5
                    QGCButton {
                        width:      ScreenTools.defaultFontPixelWidth * 18
                        text:       qsTr("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:      qsTr("Delete Tile Set")
                            text:       {
                                if(_offlineMapRoot._currentSelection) {
                                    var blurb = qsTr("Delete %1 and all its tiles.\nIs this really what you want?").arg(_offlineMapRoot._currentSelection.name)
                                    return blurb
                                }
                                return ""
                            }
                            onYes: {
                                leaveInfoView()
                                if(_offlineMapRoot._currentSelection)
                                    QGroundControl.mapEngineManager.deleteTileSet(_offlineMapRoot._currentSelection)
                                deleteDialog.visible = false
                                showList()
                            }
                            onNo: {
                                deleteDialog.visible = false
                            }
                        }
                    }
                    QGCButton {
                        text:       qsTr("Resume Download")
                        width:      ScreenTools.defaultFontPixelWidth * 18
                        enabled:    _offlineMapRoot._currentSelection && (!_offlineMapRoot._currentSelection.deleting && !_offlineMapRoot._currentSelection.downloading)
                        visible:    _offlineMapRoot._currentSelection && (!_offlineMapRoot._currentSelection.complete && !_offlineMapRoot._currentSelection.downloading)
                        onClicked: {
                            if(_offlineMapRoot._currentSelection)
                                _offlineMapRoot._currentSelection.resumeDownloadTask()
                        }
                    }
                    QGCButton {
                        text:       qsTr("Cancel Download")
                        width:      ScreenTools.defaultFontPixelWidth * 18
                        enabled:    _offlineMapRoot._currentSelection && (!_offlineMapRoot._currentSelection.deleting && _offlineMapRoot._currentSelection.downloading)
                        visible:    _offlineMapRoot._currentSelection && (!_offlineMapRoot._currentSelection.complete && _offlineMapRoot._currentSelection.downloading)
                        onClicked: {
                            if(_offlineMapRoot._currentSelection)
                                _offlineMapRoot._currentSelection.cancelDownloadTask()
                        }
                    }
                    QGCButton {
                        text:       qsTr("Back")
                        width:      ScreenTools.defaultFontPixelWidth * 18
                        onClicked: {
                            leaveInfoView()
                            showList()
                        }
                    }
                }
            }
        }
    }

    //-- Show info on default tile set
    Rectangle {
        id:                 _defaultInfoView
876
        color:              qgcPal.windowShade
dogmaphobic's avatar
dogmaphobic committed
877 878 879 880 881
        width:              parent.width
        anchors.top:        _offlineMapTopRect.bottom
        anchors.bottom:     parent.bottom
        anchors.margins:    ScreenTools.defaultFontPixelWidth
        visible:            false
dogmaphobic's avatar
dogmaphobic committed
882 883 884 885 886 887 888 889 890 891 892 893 894
        QGCFlickable {
            id:                 infoScroll
            anchors.fill:       parent
            contentHeight:      infoColumn.height
            flickableDirection: Flickable.VerticalFlick
            clip:               true
            Column {
                id:             infoColumn
                width:          parent.width
                spacing:        ScreenTools.defaultFontPixelHeight
                Item {
                    height:     ScreenTools.defaultFontPixelHeight * 0.5
                    width:      1
dogmaphobic's avatar
dogmaphobic committed
895
                }
dogmaphobic's avatar
dogmaphobic committed
896
                Rectangle {
897
                    id:         _infoNameRect
dogmaphobic's avatar
dogmaphobic committed
898
                    width:      infoWidth
899
                    height:     infoCol.height + (ScreenTools.defaultFontPixelHeight * 2)
900
                    color:      qgcPal.window
dogmaphobic's avatar
dogmaphobic committed
901 902
                    radius:     ScreenTools.defaultFontPixelHeight * 0.5
                    anchors.horizontalCenter: parent.horizontalCenter
903 904 905
                    Column {
                        id:         infoCol
                        spacing:    ScreenTools.defaultFontPixelHeight
dogmaphobic's avatar
dogmaphobic committed
906
                        anchors.centerIn: parent
907 908 909
                        QGCLabel {
                            id:     nameLabel
                            text:   _offlineMapRoot._currentSelection ? _offlineMapRoot._currentSelection.name : ""
910
                            font.pointSize:   ScreenTools.isAndroid ? ScreenTools.mediumFontPointSize : ScreenTools.largeFontPointSize
911 912 913 914 915 916 917
                            anchors.horizontalCenter: parent.horizontalCenter
                        }
                        QGCLabel {
                            id:     descLabel
                            text:   _offlineMapRoot._currentSelection ? _offlineMapRoot._currentSelection.description : ""
                            anchors.horizontalCenter: parent.horizontalCenter
                        }
dogmaphobic's avatar
dogmaphobic committed
918 919
                    }
                }
dogmaphobic's avatar
dogmaphobic committed
920
                Rectangle {
921
                    id:         _infoRect
dogmaphobic's avatar
dogmaphobic committed
922 923
                    width:      infoWidth
                    height:     infoGrid.height + (ScreenTools.defaultFontPixelHeight * 4)
924
                    color:      qgcPal.window
dogmaphobic's avatar
dogmaphobic committed
925 926 927 928 929 930 931 932 933 934
                    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 {
935
                            text:       qsTr("Default Set Size:")
dogmaphobic's avatar
dogmaphobic committed
936 937 938 939 940
                        }
                        QGCLabel {
                            text:       _offlineMapRoot._currentSelection ? _offlineMapRoot._currentSelection.tilesSizeStr : ""
                        }
                        QGCLabel {
941
                            text:       qsTr("Default Set Tile Count:")
dogmaphobic's avatar
dogmaphobic committed
942 943 944 945 946
                        }
                        QGCLabel {
                            text:       _offlineMapRoot._currentSelection ? _offlineMapRoot._currentSelection.numTilesStr : ""
                        }
                        QGCLabel {
947
                            text:       qsTr("Total Size (All Sets):")
dogmaphobic's avatar
dogmaphobic committed
948 949 950 951 952
                        }
                        QGCLabel {
                            text:       _offlineMapRoot._currentSelection ? _offlineMapRoot._currentSelection.savedSizeStr : ""
                        }
                        QGCLabel {
953
                            text:       qsTr("Total Count (All Sets):")
dogmaphobic's avatar
dogmaphobic committed
954 955 956 957
                        }
                        QGCLabel {
                            text:       _offlineMapRoot._currentSelection ? _offlineMapRoot._currentSelection.savedTilesStr : ""
                        }
dogmaphobic's avatar
dogmaphobic committed
958
                    }
dogmaphobic's avatar
dogmaphobic committed
959 960 961 962 963 964
                }
                Row {
                    anchors.horizontalCenter: parent.horizontalCenter
                    spacing: ScreenTools.defaultFontPixelWidth
                    QGCButton {
                        width:      ScreenTools.defaultFontPixelWidth * 18
965
                        text:       qsTr("Delete")
dogmaphobic's avatar
dogmaphobic committed
966 967 968
                        enabled:    _offlineMapRoot._currentSelection && (!_offlineMapRoot._currentSelection.deleting)
                        onClicked: {
                            if(_offlineMapRoot._currentSelection)
969
                                deleteDefaultDialog.visible = true
dogmaphobic's avatar
dogmaphobic committed
970 971
                        }
                        MessageDialog {
972
                            id:         deleteDefaultDialog
dogmaphobic's avatar
dogmaphobic committed
973 974 975
                            visible:    false
                            icon:       StandardIcon.Warning
                            standardButtons: StandardButton.Yes | StandardButton.No
976 977
                            title:      qsTr("Delete All Tiles")
                            text:       qsTr("Delete all cached tiles.\nIs this really what you want?")
dogmaphobic's avatar
dogmaphobic committed
978 979 980
                            onYes: {
                                if(_offlineMapRoot._currentSelection)
                                    QGroundControl.mapEngineManager.deleteTileSet(_offlineMapRoot._currentSelection)
981
                                deleteDefaultDialog.visible = false
dogmaphobic's avatar
dogmaphobic committed
982 983 984
                                showList()
                            }
                            onNo: {
985
                                deleteDefaultDialog.visible = false
dogmaphobic's avatar
dogmaphobic committed
986 987
                            }
                        }
dogmaphobic's avatar
dogmaphobic committed
988 989
                    }
                    QGCButton {
990
                        text:       qsTr("Back")
dogmaphobic's avatar
dogmaphobic committed
991
                        width:      ScreenTools.defaultFontPixelWidth * 18
992 993 994
                        onClicked: {
                            showList()
                        }
dogmaphobic's avatar
dogmaphobic committed
995 996 997 998 999
                    }
                }
            }
        }
    }
1000

dogmaphobic's avatar
dogmaphobic committed
1001 1002
    Rectangle {
        id:                 _optionsView
1003
        color:              qgcPal.windowShade
dogmaphobic's avatar
dogmaphobic committed
1004 1005 1006 1007 1008 1009 1010 1011 1012
        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
1013
                maxCacheMemSize.text = QGroundControl.mapEngineManager.maxMemCache
dogmaphobic's avatar
dogmaphobic committed
1014 1015
            }
        }
dogmaphobic's avatar
dogmaphobic committed
1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028
        QGCFlickable {
            id:                 optionsScroll
            anchors.fill:       parent
            contentHeight:      optionsColumn.height
            flickableDirection: Flickable.VerticalFlick
            clip:               true
            Column {
                id:             optionsColumn
                width:          parent.width
                spacing:        ScreenTools.defaultFontPixelHeight
                Item {
                    height:     ScreenTools.defaultFontPixelHeight
                    width:      1
dogmaphobic's avatar
dogmaphobic committed
1029
                }
dogmaphobic's avatar
dogmaphobic committed
1030 1031 1032
                Rectangle {
                    width:      infoWidth
                    height:     optionsLabel.height + (ScreenTools.defaultFontPixelHeight * 2)
1033
                    color:      qgcPal.window
dogmaphobic's avatar
dogmaphobic committed
1034 1035
                    radius:     ScreenTools.defaultFontPixelHeight * 0.5
                    anchors.horizontalCenter: parent.horizontalCenter
dogmaphobic's avatar
dogmaphobic committed
1036
                    QGCLabel {
dogmaphobic's avatar
dogmaphobic committed
1037
                        id:     optionsLabel
Tomaz Canabrava's avatar
Tomaz Canabrava committed
1038
                        text:   qsTr("Offline Map Options")
1039
                        font.pointSize:     ScreenTools.largeFontPointSize
dogmaphobic's avatar
dogmaphobic committed
1040
                        anchors.centerIn:   parent
dogmaphobic's avatar
dogmaphobic committed
1041
                    }
dogmaphobic's avatar
dogmaphobic committed
1042 1043 1044
                }
                Rectangle {
                    id:         optionsRect
dogmaphobic's avatar
dogmaphobic committed
1045
                    width:      optionsGrid.width  + (ScreenTools.defaultFontPixelWidth  * 4)
dogmaphobic's avatar
dogmaphobic committed
1046
                    height:     optionsGrid.height + (ScreenTools.defaultFontPixelHeight * 4)
1047
                    color:      qgcPal.window
dogmaphobic's avatar
dogmaphobic committed
1048 1049 1050 1051 1052 1053 1054 1055 1056
                    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
dogmaphobic's avatar
dogmaphobic committed
1057
                        QGCLabel {
1058
                            text:       qsTr("Max Cache Disk Size (MB):")
dogmaphobic's avatar
dogmaphobic committed
1059 1060 1061 1062 1063 1064 1065 1066
                        }
                        QGCTextField {
                            id:             maxCacheSize
                            maximumLength:  6
                            inputMethodHints: Qt.ImhDigitsOnly
                            validator: IntValidator {bottom: 1; top: 262144;}
                        }
                        QGCLabel {
1067
                            text:       qsTr("Max Cache Memory Size (MB):")
dogmaphobic's avatar
dogmaphobic committed
1068 1069 1070 1071 1072 1073 1074 1075 1076 1077
                        }
                        QGCTextField {
                            id:             maxCacheMemSize
                            maximumLength:  4
                            inputMethodHints: Qt.ImhDigitsOnly
                            validator: IntValidator {bottom: 1; top: 4096;}
                        }
                        Item {
                            Layout.columnSpan:  2
                            Layout.fillWidth:   true
dogmaphobic's avatar
dogmaphobic committed
1078
                            height:             ScreenTools.defaultFontPixelHeight * 1.5
dogmaphobic's avatar
dogmaphobic committed
1079 1080
                            QGCLabel {
                                anchors.centerIn: parent
1081
                                text: qsTr("Memory cache changes require a restart to take effect.")
dogmaphobic's avatar
dogmaphobic committed
1082
                                font.pointSize: ScreenTools.smallFontPointSize
dogmaphobic's avatar
dogmaphobic committed
1083 1084 1085 1086 1087
                            }
                        }
                        Rectangle {
                            Layout.columnSpan:  2
                            Layout.fillWidth:   true
dogmaphobic's avatar
dogmaphobic committed
1088
                            height:             1
1089
                            color:              qgcPal.text
dogmaphobic's avatar
dogmaphobic committed
1090 1091
                        }
                        QGCLabel {
1092
                            text: qsTr("MapBox Access Token")
dogmaphobic's avatar
dogmaphobic committed
1093 1094 1095 1096
                        }
                        QGCTextField {
                            id:                 mapBoxToken
                            maximumLength:      256
dogmaphobic's avatar
dogmaphobic committed
1097
                            width:              ScreenTools.defaultFontPixelWidth * 30
dogmaphobic's avatar
dogmaphobic committed
1098 1099 1100 1101
                        }
                        Item {
                            Layout.columnSpan:  2
                            Layout.fillWidth:   true
dogmaphobic's avatar
dogmaphobic committed
1102
                            height:             ScreenTools.defaultFontPixelHeight * 1.5
dogmaphobic's avatar
dogmaphobic committed
1103 1104
                            QGCLabel {
                                anchors.centerIn: parent
1105
                                text: qsTr("With an access token, you can use MapBox Maps.")
dogmaphobic's avatar
dogmaphobic committed
1106
                                font.pointSize: ScreenTools.smallFontPointSize
dogmaphobic's avatar
dogmaphobic committed
1107
                            }
dogmaphobic's avatar
dogmaphobic committed
1108 1109 1110
                        }
                    }
                }
dogmaphobic's avatar
dogmaphobic committed
1111 1112 1113 1114
                Row {
                    anchors.horizontalCenter: parent.horizontalCenter
                    spacing: ScreenTools.defaultFontPixelWidth
                    QGCButton {
1115
                        text:       qsTr("Save")
dogmaphobic's avatar
dogmaphobic committed
1116 1117 1118 1119 1120 1121 1122
                        width:      ScreenTools.defaultFontPixelWidth * 18
                        onClicked:  {
                            QGroundControl.mapEngineManager.mapboxToken  = mapBoxToken.text
                            QGroundControl.mapEngineManager.maxDiskCache = parseInt(maxCacheSize.text)
                            QGroundControl.mapEngineManager.maxMemCache  = parseInt(maxCacheMemSize.text)
                            showList()
                        }
dogmaphobic's avatar
dogmaphobic committed
1123
                    }
dogmaphobic's avatar
dogmaphobic committed
1124
                    QGCButton {
1125
                        text:       qsTr("Cancel")
dogmaphobic's avatar
dogmaphobic committed
1126 1127 1128 1129
                        width:      ScreenTools.defaultFontPixelWidth * 18
                        onClicked:  {
                            showList()
                        }
dogmaphobic's avatar
dogmaphobic committed
1130 1131 1132 1133 1134 1135
                    }
                }
            }
        }
    }
}