Serial-Studio/assets/qml/Widgets/MapDelegate.qml

170 lines
4.6 KiB
QML
Raw Normal View History

2020-10-18 06:50:26 -05:00
/*
* Copyright (c) 2018 Kaan-Sat <https://kaansat.com.mx/>
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
import QtQuick 2.0
import QtLocation 5.11
import QtPositioning 5.11
import QtQuick.Layouts 1.0
import QtQuick.Controls 2.0
import QtQuick.Controls.Universal 2.0
import Qt.labs.settings 1.0
2020-12-27 17:21:19 -06:00
import Group 1.0
import Dataset 1.0
import "."
Window {
id: root
2020-10-18 06:50:26 -05:00
//
2020-12-27 17:21:19 -06:00
// Window properties
2020-10-18 06:50:26 -05:00
//
2020-12-27 17:21:19 -06:00
spacing: -1
2020-12-30 16:11:51 -06:00
gradient: true
2020-12-27 17:21:19 -06:00
implicitWidth: 260
visible: opacity > 0
opacity: enabled ? 1 : 0
2021-01-22 12:46:11 -05:00
backgroundColor: "#09090c"
2020-12-27 17:21:19 -06:00
implicitHeight: implicitWidth + 96
icon.source: "qrc:/icons/location-on.svg"
2020-10-18 06:50:26 -05:00
//
2020-12-27 17:21:19 -06:00
// Custom properties
2020-10-18 06:50:26 -05:00
//
2020-12-27 17:21:19 -06:00
property real latitude: 0
property real longitude: 0
property int groupIndex: 0
readonly property var gpsCoordinates: QtPositioning.coordinate(latitude, longitude)
2020-10-18 06:50:26 -05:00
//
2020-12-27 17:21:19 -06:00
// Connections with widget manager
2020-10-18 06:50:26 -05:00
//
2020-12-27 17:21:19 -06:00
Connections {
2021-01-22 12:46:11 -05:00
target: CppWidgetProvider
2020-12-27 17:21:19 -06:00
function onDataChanged() {
root.updateValues()
2020-12-27 17:21:19 -06:00
}
}
2020-10-18 06:50:26 -05:00
//
2020-12-27 17:21:19 -06:00
// Updates the internal values of the map widget
2020-10-18 06:50:26 -05:00
//
2020-12-27 17:21:19 -06:00
function updateValues() {
2021-01-22 12:46:11 -05:00
if (CppWidgetProvider.mapGroupCount() > root.groupIndex) {
root.latitude = CppWidgetProvider.mapLatitude(root.groupIndex)
root.longitude = CppWidgetProvider.mapLongitude(root.groupIndex)
root.title = CppWidgetProvider.mapGroupAt(root.groupIndex).title
root.centerMap()
2020-12-27 17:21:19 -06:00
}
else {
root.title = ""
root.latitude = 0
root.longitude = 0
2020-12-27 17:21:19 -06:00
}
}
2020-10-18 06:50:26 -05:00
//
2020-12-27 17:21:19 -06:00
// Animations
2020-10-18 06:50:26 -05:00
//
2020-12-27 17:21:19 -06:00
Behavior on latitude {NumberAnimation{}}
Behavior on longitude {NumberAnimation{}}
2020-10-18 06:50:26 -05:00
//
2020-12-27 17:21:19 -06:00
// Centers the map to the current coordinates
2020-10-18 06:50:26 -05:00
//
function centerMap() {
2020-12-27 17:21:19 -06:00
map.center = gpsCoordinates
2020-10-18 06:50:26 -05:00
}
//
// Save settings between runs
//
Settings {
property alias mapType: mapTypeSelector.currentIndex
}
//
2020-12-27 17:21:19 -06:00
// UI controls
2020-10-18 06:50:26 -05:00
//
2020-12-27 17:21:19 -06:00
ColumnLayout {
2020-10-18 06:50:26 -05:00
spacing: app.spacing
2020-12-27 17:21:19 -06:00
anchors.fill: parent
anchors.margins: app.spacing
//
// Map type selector
2020-12-27 17:21:19 -06:00
//
ComboBox {
id: mapTypeSelector
textRole: "description"
2020-10-18 06:50:26 -05:00
Layout.fillWidth: true
model: map.supportedMapTypes
onCurrentIndexChanged: map.activeMapType = map.supportedMapTypes[currentIndex]
2020-10-18 06:50:26 -05:00
}
2020-12-27 17:21:19 -06:00
//
// Map
//
Rectangle {
Layout.fillWidth: true
Layout.fillHeight: true
2020-10-18 06:50:26 -05:00
2020-12-27 17:21:19 -06:00
border {
width: 2
color: "#646464"
}
2020-10-18 06:50:26 -05:00
2020-12-27 17:21:19 -06:00
Map {
id: map
anchors.fill: parent
copyrightsVisible: false
color: Universal.background
anchors.margins: parent.border.width
zoomLevel: (map.minimumZoomLevel + map.maximumZoomLevel) * 0.8
MapQuickItem {
coordinate: gpsCoordinates
anchorPoint: Qt.point(sourceItem.width / 2, sourceItem.height/ 2)
sourceItem: Rectangle {
id: dot
width: 20
height: 20
opacity: 0.8
color: "#f00"
border.width: 2
radius: width / 2
border.color: "#fff"
2020-10-18 06:50:26 -05:00
}
}
2020-12-27 17:21:19 -06:00
plugin: Plugin {
2021-02-01 19:54:55 -05:00
preferred: ["mapboxgl", "mapbox", "osm"]
2020-12-27 17:21:19 -06:00
}
2020-10-18 06:50:26 -05:00
}
}
}
}