2017-07-16 23:04:05 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
2017-07-14 14:53:08 +00:00
|
|
|
import QtQuick 2.0
|
|
|
|
import QtLocation 5.3
|
|
|
|
import QtPositioning 5.3
|
2017-07-16 00:01:54 +00:00
|
|
|
import org.subsurfacedivelog.mobile 1.0
|
2017-07-14 14:53:08 +00:00
|
|
|
|
2017-07-14 21:55:29 +00:00
|
|
|
Item {
|
2017-07-24 19:50:18 +00:00
|
|
|
property int nSelectedDives: 0
|
|
|
|
|
2017-07-14 14:53:08 +00:00
|
|
|
Plugin {
|
|
|
|
id: mapPlugin
|
2017-08-01 21:51:09 +00:00
|
|
|
name: "googlemaps"
|
2017-08-06 13:53:09 +00:00
|
|
|
Component.onCompleted: {
|
|
|
|
if (availableServiceProviders.indexOf(name) === -1)
|
|
|
|
console.warn("MapWidget.qml: cannot find a plugin with the name '" + name + "'")
|
|
|
|
}
|
2017-07-14 14:53:08 +00:00
|
|
|
}
|
|
|
|
|
2017-07-16 00:01:54 +00:00
|
|
|
MapWidgetHelper {
|
|
|
|
id: mapHelper
|
2017-07-16 20:59:09 +00:00
|
|
|
map: map
|
2017-07-27 21:09:25 +00:00
|
|
|
editMode: false
|
2017-07-28 13:40:28 +00:00
|
|
|
onSelectedDivesChanged: nSelectedDives = list.length
|
2017-07-27 21:09:25 +00:00
|
|
|
onEditModeChanged: editMessage.isVisible = editMode === true ? 1 : 0
|
2017-07-27 21:36:06 +00:00
|
|
|
onCoordinatesChanged: {}
|
2017-07-16 00:01:54 +00:00
|
|
|
}
|
|
|
|
|
2017-07-14 14:53:08 +00:00
|
|
|
Map {
|
2017-07-15 21:56:54 +00:00
|
|
|
id: map
|
2017-07-14 14:53:08 +00:00
|
|
|
anchors.fill: parent
|
|
|
|
plugin: mapPlugin
|
|
|
|
zoomLevel: 1
|
2017-07-15 21:56:54 +00:00
|
|
|
|
2017-08-03 16:17:01 +00:00
|
|
|
readonly property var mapType: { "STREET": supportedMapTypes[0], "SATELLITE": supportedMapTypes[1] }
|
2017-07-19 21:09:53 +00:00
|
|
|
readonly property var defaultCenter: QtPositioning.coordinate(0, 0)
|
2017-07-27 21:25:48 +00:00
|
|
|
readonly property real defaultZoomIn: 12.0
|
2017-07-25 15:38:15 +00:00
|
|
|
readonly property real defaultZoomOut: 1.0
|
2017-07-31 19:50:04 +00:00
|
|
|
readonly property real textVisibleZoom: 11.0
|
2017-07-25 15:38:15 +00:00
|
|
|
readonly property real zoomStep: 2.0
|
2017-07-19 21:09:53 +00:00
|
|
|
property var newCenter: defaultCenter
|
2017-07-25 15:38:15 +00:00
|
|
|
property real newZoom: 1.0
|
2017-07-27 21:25:48 +00:00
|
|
|
property real newZoomOut: 1.0
|
2017-07-25 15:38:15 +00:00
|
|
|
property var clickCoord: QtPositioning.coordinate(0, 0)
|
2017-07-16 22:16:27 +00:00
|
|
|
|
2017-07-28 13:40:28 +00:00
|
|
|
Component.onCompleted: activeMapType = mapType.SATELLITE
|
2017-07-24 13:17:37 +00:00
|
|
|
onZoomLevelChanged: mapHelper.calculateSmallCircleRadius(map.center)
|
|
|
|
|
2017-07-17 19:24:30 +00:00
|
|
|
MapItemView {
|
|
|
|
id: mapItemView
|
|
|
|
model: mapHelper.model
|
|
|
|
delegate: MapQuickItem {
|
2017-07-27 21:25:48 +00:00
|
|
|
id: mapItem
|
2017-07-17 19:24:30 +00:00
|
|
|
anchorPoint.x: 0
|
|
|
|
anchorPoint.y: mapItemImage.height
|
2017-07-17 19:36:55 +00:00
|
|
|
coordinate: model.coordinate
|
2017-07-19 20:51:39 +00:00
|
|
|
z: mapHelper.model.selectedUuid === model.uuid ? mapHelper.model.count - 1 : 0
|
2017-07-25 20:43:18 +00:00
|
|
|
sourceItem: Item {
|
|
|
|
Image {
|
|
|
|
id: mapItemImage
|
|
|
|
source: "qrc:///mapwidget-marker" + (mapHelper.model.selectedUuid === model.uuid ? "-selected" : "")
|
|
|
|
SequentialAnimation {
|
|
|
|
id: mapItemImageAnimation
|
2017-07-28 13:40:28 +00:00
|
|
|
PropertyAnimation { target: mapItemImage; property: "scale"; from: 1.0; to: 0.7; duration: 120 }
|
|
|
|
PropertyAnimation { target: mapItemImage; property: "scale"; from: 0.7; to: 1.0; duration: 80 }
|
2017-07-19 21:06:08 +00:00
|
|
|
}
|
2017-07-25 20:43:18 +00:00
|
|
|
MouseArea {
|
2017-07-27 21:25:48 +00:00
|
|
|
drag.target: (mapHelper.editMode && mapHelper.model.selectedUuid === model.uuid) ? mapItem : undefined
|
2017-07-25 20:43:18 +00:00
|
|
|
anchors.fill: parent
|
2017-07-27 21:25:48 +00:00
|
|
|
onClicked: {
|
|
|
|
if (!mapHelper.editMode)
|
|
|
|
mapHelper.model.setSelectedUuid(model.uuid, true)
|
|
|
|
}
|
|
|
|
onDoubleClicked: map.doubleClickHandler(mapItem.coordinate)
|
|
|
|
onReleased: {
|
|
|
|
if (mapHelper.editMode && mapHelper.model.selectedUuid === model.uuid) {
|
|
|
|
mapHelper.updateCurrentDiveSiteCoordinates(mapHelper.model.selectedUuid, mapItem.coordinate)
|
|
|
|
}
|
|
|
|
}
|
2017-07-25 20:43:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
Item {
|
|
|
|
// Text with a duplicate for shadow. DropShadow as layer effect is kind of slow here.
|
|
|
|
y: mapItemImage.y + mapItemImage.height
|
2017-07-27 21:25:48 +00:00
|
|
|
visible: map.zoomLevel >= map.textVisibleZoom
|
2017-07-25 20:43:18 +00:00
|
|
|
Text {
|
|
|
|
id: mapItemTextShadow
|
|
|
|
x: mapItemText.x + 2; y: mapItemText.y + 2
|
|
|
|
text: mapItemText.text
|
|
|
|
font.pointSize: mapItemText.font.pointSize
|
|
|
|
color: "black"
|
|
|
|
}
|
|
|
|
Text {
|
|
|
|
id: mapItemText
|
|
|
|
text: model.name
|
|
|
|
font.pointSize: 11.0
|
2017-07-27 21:30:18 +00:00
|
|
|
color: mapHelper.model.selectedUuid === model.uuid ? "white" : "lightgrey"
|
2017-07-19 21:06:08 +00:00
|
|
|
}
|
|
|
|
}
|
2017-07-18 23:36:59 +00:00
|
|
|
}
|
2017-07-17 19:24:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-07-27 21:25:48 +00:00
|
|
|
SequentialAnimation {
|
2017-07-19 22:33:15 +00:00
|
|
|
id: mapAnimationZoomIn
|
2017-07-16 22:16:27 +00:00
|
|
|
NumberAnimation {
|
2017-07-27 21:25:48 +00:00
|
|
|
target: map; property: "zoomLevel"; to: map.newZoomOut; duration: Math.abs(map.newZoomOut - map.zoomLevel) * 200
|
|
|
|
}
|
|
|
|
ParallelAnimation {
|
2017-07-28 13:40:28 +00:00
|
|
|
CoordinateAnimation { target: map; property: "center"; to: map.newCenter; duration: 1000 }
|
2017-07-27 21:25:48 +00:00
|
|
|
NumberAnimation {
|
|
|
|
target: map; property: "zoomLevel"; to: map.newZoom ; duration: 2000; easing.type: Easing.InCubic
|
|
|
|
}
|
2017-07-16 22:16:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-07-19 22:33:15 +00:00
|
|
|
ParallelAnimation {
|
|
|
|
id: mapAnimationZoomOut
|
2017-07-28 13:40:28 +00:00
|
|
|
NumberAnimation { target: map; property: "zoomLevel"; from: map.zoomLevel; to: map.newZoom; duration: 3000 }
|
2017-07-19 22:33:15 +00:00
|
|
|
SequentialAnimation {
|
|
|
|
PauseAnimation { duration: 2000 }
|
2017-07-28 13:40:28 +00:00
|
|
|
CoordinateAnimation { target: map; property: "center"; to: map.newCenter; duration: 2000 }
|
2017-07-19 22:33:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-07-25 15:34:24 +00:00
|
|
|
ParallelAnimation {
|
|
|
|
id: mapAnimationClick
|
2017-07-28 13:40:28 +00:00
|
|
|
CoordinateAnimation { target: map; property: "center"; to: map.newCenter; duration: 500 }
|
|
|
|
NumberAnimation { target: map; property: "zoomLevel"; to: map.newZoom; duration: 500 }
|
2017-07-25 15:34:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
MouseArea {
|
|
|
|
anchors.fill: parent
|
|
|
|
onDoubleClicked: map.doubleClickHandler(map.toCoordinate(Qt.point(mouseX, mouseY)))
|
|
|
|
}
|
|
|
|
|
|
|
|
function doubleClickHandler(coord) {
|
|
|
|
newCenter = coord
|
|
|
|
newZoom = zoomLevel + zoomStep
|
2017-07-25 15:55:36 +00:00
|
|
|
if (newZoom > maximumZoomLevel)
|
|
|
|
newZoom = maximumZoomLevel
|
2017-07-25 15:34:24 +00:00
|
|
|
mapAnimationClick.restart()
|
|
|
|
}
|
|
|
|
|
2017-07-19 22:33:15 +00:00
|
|
|
function animateMapZoomOut() {
|
2017-07-25 15:38:15 +00:00
|
|
|
newCenter = defaultCenter
|
|
|
|
newZoom = defaultZoomOut
|
2017-07-19 22:33:15 +00:00
|
|
|
mapAnimationZoomIn.stop()
|
|
|
|
mapAnimationZoomOut.restart()
|
2017-07-19 21:22:52 +00:00
|
|
|
}
|
|
|
|
|
2017-07-27 20:46:54 +00:00
|
|
|
function centerOnCoordinate(coord) {
|
2017-07-27 21:25:48 +00:00
|
|
|
newCenter = coord
|
|
|
|
if (coord.latitude === 0.0 && coord.longitude === 0.0) {
|
|
|
|
newZoom = 2.6
|
|
|
|
newZoomOut = newZoom
|
|
|
|
} else {
|
|
|
|
var zoomStored = zoomLevel
|
|
|
|
newZoomOut = zoomLevel
|
|
|
|
while (zoomLevel > minimumZoomLevel) {
|
|
|
|
var pt = fromCoordinate(coord, false)
|
|
|
|
if (pt.x > 0 && pt.y > 0 && pt.x < width && pt.y < height) {
|
|
|
|
newZoomOut = zoomLevel
|
|
|
|
break
|
|
|
|
}
|
|
|
|
zoomLevel--
|
|
|
|
}
|
|
|
|
zoomLevel = zoomStored
|
|
|
|
newZoom = defaultZoomIn
|
|
|
|
}
|
|
|
|
mapAnimationZoomIn.restart()
|
|
|
|
mapAnimationZoomOut.stop()
|
2017-07-16 21:25:19 +00:00
|
|
|
}
|
2017-07-19 21:29:42 +00:00
|
|
|
|
2017-08-06 23:04:23 +00:00
|
|
|
function centerOnRectangle(topLeft, bottomRight, center) {
|
|
|
|
// TODO
|
|
|
|
}
|
|
|
|
|
2017-07-19 21:29:42 +00:00
|
|
|
function deselectMapLocation() {
|
2017-07-19 22:33:15 +00:00
|
|
|
animateMapZoomOut()
|
2017-07-19 21:29:42 +00:00
|
|
|
}
|
2017-07-20 02:24:18 +00:00
|
|
|
}
|
2017-07-20 00:07:47 +00:00
|
|
|
|
2017-07-27 21:09:25 +00:00
|
|
|
Rectangle {
|
|
|
|
id: editMessage
|
|
|
|
radius: padding
|
|
|
|
color: "#b08000"
|
|
|
|
border.color: "white"
|
|
|
|
x: (map.width - width) * 0.5; y: padding
|
|
|
|
width: editMessageText.width + padding * 2.0
|
|
|
|
height: editMessageText.height + padding * 2.0
|
|
|
|
visible: false
|
|
|
|
opacity: 0.0
|
|
|
|
property int isVisible: -1
|
|
|
|
property real padding: 10.0
|
|
|
|
onOpacityChanged: visible = opacity != 0.0
|
|
|
|
states: [
|
|
|
|
State { when: editMessage.isVisible === 1; PropertyChanges { target: editMessage; opacity: 1.0 }},
|
|
|
|
State { when: editMessage.isVisible === 0; PropertyChanges { target: editMessage; opacity: 0.0 }}
|
|
|
|
]
|
2017-07-28 13:40:28 +00:00
|
|
|
transitions: Transition { NumberAnimation { properties: "opacity"; easing.type: Easing.InOutQuad }}
|
2017-07-27 21:09:25 +00:00
|
|
|
Text {
|
|
|
|
id: editMessageText
|
|
|
|
y: editMessage.padding; x: editMessage.padding
|
|
|
|
verticalAlignment: Text.AlignVCenter
|
|
|
|
color: "white"
|
|
|
|
font.pointSize: 11.0
|
|
|
|
text: qsTr("Drag the selected dive location")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-07-20 02:24:18 +00:00
|
|
|
Image {
|
|
|
|
id: toggleImage
|
|
|
|
x: 10; y: x
|
2017-07-31 19:43:19 +00:00
|
|
|
width: 40
|
|
|
|
height: 40
|
2017-07-20 02:24:18 +00:00
|
|
|
source: "qrc:///mapwidget-toggle-" + (map.activeMapType === map.mapType.SATELLITE ? "street" : "satellite")
|
|
|
|
SequentialAnimation {
|
|
|
|
id: toggleImageAnimation
|
2017-07-28 13:40:28 +00:00
|
|
|
PropertyAnimation { target: toggleImage; property: "scale"; from: 1.0; to: 0.8; duration: 120 }
|
|
|
|
PropertyAnimation { target: toggleImage; property: "scale"; from: 0.8; to: 1.0; duration: 80 }
|
2017-07-20 02:24:18 +00:00
|
|
|
}
|
|
|
|
MouseArea {
|
|
|
|
anchors.fill: parent
|
|
|
|
onClicked: {
|
|
|
|
map.activeMapType = map.activeMapType === map.mapType.SATELLITE ? map.mapType.STREET : map.mapType.SATELLITE
|
|
|
|
toggleImageAnimation.restart()
|
2017-07-20 00:07:47 +00:00
|
|
|
}
|
|
|
|
}
|
2017-07-14 14:53:08 +00:00
|
|
|
}
|
2017-07-20 13:58:21 +00:00
|
|
|
|
2017-07-25 15:55:36 +00:00
|
|
|
Image {
|
|
|
|
id: imageZoomIn
|
|
|
|
x: 10 + (toggleImage.width - imageZoomIn.width) * 0.5; y: toggleImage.y + toggleImage.height + 10
|
2017-07-31 19:43:19 +00:00
|
|
|
width: 20
|
|
|
|
height: 20
|
2017-07-25 15:55:36 +00:00
|
|
|
source: "qrc:///mapwidget-zoom-in"
|
|
|
|
SequentialAnimation {
|
|
|
|
id: imageZoomInAnimation
|
2017-07-28 13:40:28 +00:00
|
|
|
PropertyAnimation { target: imageZoomIn; property: "scale"; from: 1.0; to: 0.8; duration: 120 }
|
|
|
|
PropertyAnimation { target: imageZoomIn; property: "scale"; from: 0.8; to: 1.0; duration: 80 }
|
2017-07-25 15:55:36 +00:00
|
|
|
}
|
|
|
|
MouseArea {
|
|
|
|
anchors.fill: parent
|
|
|
|
onClicked: {
|
|
|
|
map.newCenter = map.center
|
|
|
|
map.newZoom = map.zoomLevel + map.zoomStep
|
|
|
|
if (map.newZoom > map.maximumZoomLevel)
|
|
|
|
map.newZoom = map.maximumZoomLevel
|
|
|
|
mapAnimationClick.restart()
|
|
|
|
imageZoomInAnimation.restart()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Image {
|
|
|
|
id: imageZoomOut
|
|
|
|
x: imageZoomIn.x; y: imageZoomIn.y + imageZoomIn.height + 10
|
|
|
|
source: "qrc:///mapwidget-zoom-out"
|
2017-07-31 19:43:19 +00:00
|
|
|
width: 20
|
|
|
|
height: 20
|
2017-07-25 15:55:36 +00:00
|
|
|
SequentialAnimation {
|
|
|
|
id: imageZoomOutAnimation
|
2017-07-28 13:40:28 +00:00
|
|
|
PropertyAnimation { target: imageZoomOut; property: "scale"; from: 1.0; to: 0.8; duration: 120 }
|
|
|
|
PropertyAnimation { target: imageZoomOut; property: "scale"; from: 0.8; to: 1.0; duration: 80 }
|
2017-07-25 15:55:36 +00:00
|
|
|
}
|
|
|
|
MouseArea {
|
|
|
|
anchors.fill: parent
|
|
|
|
onClicked: {
|
|
|
|
map.newCenter = map.center
|
|
|
|
map.newZoom = map.zoomLevel - map.zoomStep
|
|
|
|
mapAnimationClick.restart()
|
|
|
|
imageZoomOutAnimation.restart()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-07-21 13:26:33 +00:00
|
|
|
function openLocationInGoogleMaps(latitude, longitude) {
|
|
|
|
var loc = latitude + " " + longitude
|
|
|
|
var url = "https://www.google.com/maps/place/" + loc + "/@" + loc + ",5000m/data=!3m1!1e3!4m2!3m1!1s0x0:0x0"
|
|
|
|
Qt.openUrlExternally(url)
|
|
|
|
}
|
|
|
|
|
2017-07-20 13:58:21 +00:00
|
|
|
MapWidgetContextMenu {
|
|
|
|
id: contextMenu
|
2017-07-20 16:25:59 +00:00
|
|
|
y: 10; x: map.width - y
|
2017-07-20 22:28:58 +00:00
|
|
|
onActionSelected: {
|
|
|
|
switch (action) {
|
|
|
|
case contextMenu.actions.OPEN_LOCATION_IN_GOOGLE_MAPS:
|
2017-07-21 13:26:33 +00:00
|
|
|
openLocationInGoogleMaps(map.center.latitude, map.center.longitude)
|
2017-07-28 13:40:28 +00:00
|
|
|
break
|
2017-07-20 22:28:58 +00:00
|
|
|
case contextMenu.actions.COPY_LOCATION_DECIMAL:
|
2017-07-25 15:38:15 +00:00
|
|
|
mapHelper.copyToClipboardCoordinates(map.center, false)
|
2017-07-28 13:40:28 +00:00
|
|
|
break
|
2017-07-20 22:28:58 +00:00
|
|
|
case contextMenu.actions.COPY_LOCATION_SEXAGESIMAL:
|
2017-07-25 15:38:15 +00:00
|
|
|
mapHelper.copyToClipboardCoordinates(map.center, true)
|
2017-07-28 13:40:28 +00:00
|
|
|
break
|
2017-07-20 22:28:58 +00:00
|
|
|
}
|
|
|
|
}
|
2017-07-20 13:58:21 +00:00
|
|
|
}
|
2017-07-14 14:53:08 +00:00
|
|
|
}
|