| 
									
										
										
										
											2017-07-17 02:04:05 +03:00
										 |  |  | // SPDX-License-Identifier: GPL-2.0
 | 
					
						
							| 
									
										
										
										
											2017-12-24 20:06:43 +01:00
										 |  |  | import QtQuick 2.5 | 
					
						
							| 
									
										
										
										
											2017-07-14 17:53:08 +03:00
										 |  |  | import QtLocation 5.3 | 
					
						
							|  |  |  | import QtPositioning 5.3 | 
					
						
							| 
									
										
										
										
											2017-07-16 03:01:54 +03:00
										 |  |  | import org.subsurfacedivelog.mobile 1.0 | 
					
						
							| 
									
										
										
										
											2017-07-14 17:53:08 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-07-15 00:55:29 +03:00
										 |  |  | Item { | 
					
						
							| 
									
										
										
										
											2017-08-12 03:58:26 +03:00
										 |  |  | 	id: rootItem | 
					
						
							| 
									
										
										
										
											2018-03-08 21:59:34 +02:00
										 |  |  | 	property alias mapHelper: mapHelper | 
					
						
							|  |  |  | 	property alias map: map | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	signal selectedDivesChanged(var list) | 
					
						
							| 
									
										
										
										
											2017-07-24 22:50:18 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-07-16 03:01:54 +03:00
										 |  |  | 	MapWidgetHelper { | 
					
						
							|  |  |  | 		id: mapHelper | 
					
						
							| 
									
										
										
										
											2017-07-16 23:59:09 +03:00
										 |  |  | 		map: map | 
					
						
							| 
									
										
										
										
											2017-07-28 00:09:25 +03:00
										 |  |  | 		editMode: false | 
					
						
							| 
									
										
										
										
											2018-03-08 21:59:34 +02:00
										 |  |  | 		onSelectedDivesChanged: rootItem.selectedDivesChanged(list) | 
					
						
							| 
									
										
										
										
											2017-07-28 00:09:25 +03:00
										 |  |  | 		onEditModeChanged: editMessage.isVisible = editMode === true ? 1 : 0 | 
					
						
							| 
									
										
										
										
											2017-07-28 00:36:06 +03:00
										 |  |  | 		onCoordinatesChanged: {} | 
					
						
							| 
									
										
										
										
											2017-08-12 03:58:26 +03:00
										 |  |  | 		Component.onCompleted: { | 
					
						
							|  |  |  | 			map.plugin = Qt.createQmlObject(pluginObject, rootItem) | 
					
						
							|  |  |  | 			map.mapType = { "STREET": map.supportedMapTypes[0], "SATELLITE": map.supportedMapTypes[1] } | 
					
						
							|  |  |  | 			map.activeMapType = map.mapType.SATELLITE | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2017-07-16 03:01:54 +03:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-07-14 17:53:08 +03:00
										 |  |  | 	Map { | 
					
						
							| 
									
										
										
										
											2017-07-16 00:56:54 +03:00
										 |  |  | 		id: map | 
					
						
							| 
									
										
										
										
											2017-07-14 17:53:08 +03:00
										 |  |  | 		anchors.fill: parent | 
					
						
							| 
									
										
										
										
											2017-10-27 12:39:03 +02:00
										 |  |  | 		zoomLevel: defaultZoomIn | 
					
						
							| 
									
										
										
										
											2017-07-16 00:56:54 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-08-12 03:58:26 +03:00
										 |  |  | 		property var mapType | 
					
						
							| 
									
										
										
										
											2017-07-20 00:09:53 +03:00
										 |  |  | 		readonly property var defaultCenter: QtPositioning.coordinate(0, 0) | 
					
						
							| 
									
										
										
										
											2017-07-28 00:25:48 +03:00
										 |  |  | 		readonly property real defaultZoomIn: 12.0 | 
					
						
							| 
									
										
										
										
											2017-07-25 18:38:15 +03:00
										 |  |  | 		readonly property real defaultZoomOut: 1.0 | 
					
						
							| 
									
										
										
										
											2017-07-31 12:50:04 -07:00
										 |  |  | 		readonly property real textVisibleZoom: 11.0 | 
					
						
							| 
									
										
										
										
											2017-07-25 18:38:15 +03:00
										 |  |  | 		readonly property real zoomStep: 2.0 | 
					
						
							| 
									
										
										
										
											2017-07-20 00:09:53 +03:00
										 |  |  | 		property var newCenter: defaultCenter | 
					
						
							| 
									
										
										
										
											2017-07-25 18:38:15 +03:00
										 |  |  | 		property real newZoom: 1.0 | 
					
						
							| 
									
										
										
										
											2017-07-28 00:25:48 +03:00
										 |  |  | 		property real newZoomOut: 1.0 | 
					
						
							| 
									
										
										
										
											2017-07-25 18:38:15 +03:00
										 |  |  | 		property var clickCoord: QtPositioning.coordinate(0, 0) | 
					
						
							| 
									
										
										
										
											2017-10-28 13:56:09 +03:00
										 |  |  | 		property bool isReady: false | 
					
						
							| 
									
										
										
										
											2017-07-17 01:16:27 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-28 13:56:09 +03:00
										 |  |  | 		Component.onCompleted: isReady = true | 
					
						
							|  |  |  | 		onZoomLevelChanged: { | 
					
						
							|  |  |  | 			if (isReady) | 
					
						
							|  |  |  | 				mapHelper.calculateSmallCircleRadius(map.center) | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2017-07-24 16:17:37 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-07-17 22:24:30 +03:00
										 |  |  | 		MapItemView { | 
					
						
							|  |  |  | 			id: mapItemView | 
					
						
							|  |  |  | 			model: mapHelper.model | 
					
						
							|  |  |  | 			delegate: MapQuickItem { | 
					
						
							| 
									
										
										
										
											2017-07-28 00:25:48 +03:00
										 |  |  | 				id: mapItem | 
					
						
							| 
									
										
										
										
											2017-07-17 22:24:30 +03:00
										 |  |  | 				anchorPoint.x: 0 | 
					
						
							|  |  |  | 				anchorPoint.y: mapItemImage.height | 
					
						
							| 
									
										
										
										
											2017-07-17 22:36:55 +03:00
										 |  |  | 				coordinate:  model.coordinate | 
					
						
							| 
									
										
										
										
											2019-08-30 18:09:37 +02:00
										 |  |  | 				z: model.z | 
					
						
							| 
									
										
										
										
											2017-10-15 21:19:29 +03:00
										 |  |  | 				sourceItem: Image { | 
					
						
							|  |  |  | 					id: mapItemImage | 
					
						
							| 
									
										
										
										
											2019-08-30 15:25:59 +02:00
										 |  |  | 					source: model.pixmap | 
					
						
							| 
									
										
										
										
											2017-10-15 21:19:29 +03:00
										 |  |  | 					SequentialAnimation { | 
					
						
							|  |  |  | 						id: mapItemImageAnimation | 
					
						
							|  |  |  | 						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 } | 
					
						
							|  |  |  | 					} | 
					
						
							|  |  |  | 					MouseArea { | 
					
						
							| 
									
										
										
										
											2019-08-31 23:24:21 +02:00
										 |  |  | 						drag.target: (mapHelper.editMode && model.isSelected) ? mapItem : undefined | 
					
						
							| 
									
										
										
										
											2017-10-15 21:19:29 +03:00
										 |  |  | 						anchors.fill: parent | 
					
						
							|  |  |  | 						onClicked: { | 
					
						
							| 
									
										
										
										
											2019-08-30 17:38:54 +02:00
										 |  |  | 							if (!mapHelper.editMode && model.divesite) | 
					
						
							| 
									
										
										
										
											2019-08-30 12:38:25 +02:00
										 |  |  | 								mapHelper.selectedLocationChanged(model.divesite) | 
					
						
							| 
									
										
										
										
											2017-07-20 00:06:08 +03:00
										 |  |  | 						} | 
					
						
							| 
									
										
										
										
											2017-10-15 21:19:29 +03:00
										 |  |  | 						onDoubleClicked: map.doubleClickHandler(mapItem.coordinate) | 
					
						
							|  |  |  | 						onReleased: { | 
					
						
							| 
									
										
										
										
											2019-08-31 23:24:21 +02:00
										 |  |  | 							if (mapHelper.editMode && model.isSelected) { | 
					
						
							| 
									
										
										
										
											2019-05-02 00:09:59 +02:00
										 |  |  | 								mapHelper.updateCurrentDiveSiteCoordinatesFromMap(model.divesite, mapItem.coordinate) | 
					
						
							| 
									
										
										
										
											2017-07-28 00:25:48 +03:00
										 |  |  | 							} | 
					
						
							| 
									
										
										
										
											2017-07-25 23:43:18 +03:00
										 |  |  | 						} | 
					
						
							|  |  |  | 					} | 
					
						
							|  |  |  | 					Item { | 
					
						
							|  |  |  | 						// Text with a duplicate for shadow. DropShadow as layer effect is kind of slow here.
 | 
					
						
							|  |  |  | 						y: mapItemImage.y + mapItemImage.height | 
					
						
							| 
									
										
										
										
											2017-07-28 00:25:48 +03:00
										 |  |  | 						visible: map.zoomLevel >= map.textVisibleZoom | 
					
						
							| 
									
										
										
										
											2017-07-25 23:43:18 +03: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 | 
					
						
							| 
									
										
										
										
											2019-08-31 23:24:21 +02:00
										 |  |  | 							color: model.isSelected ? "white" : "lightgrey" | 
					
						
							| 
									
										
										
										
											2017-07-20 00:06:08 +03:00
										 |  |  | 						} | 
					
						
							|  |  |  | 					} | 
					
						
							| 
									
										
										
										
											2017-07-19 02:36:59 +03:00
										 |  |  | 				} | 
					
						
							| 
									
										
										
										
											2017-07-17 22:24:30 +03:00
										 |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-07-28 00:25:48 +03:00
										 |  |  | 		SequentialAnimation { | 
					
						
							| 
									
										
										
										
											2017-07-20 01:33:15 +03:00
										 |  |  | 			id: mapAnimationZoomIn | 
					
						
							| 
									
										
										
										
											2017-07-17 01:16:27 +03:00
										 |  |  | 			NumberAnimation { | 
					
						
							| 
									
										
										
										
											2017-07-28 00:25:48 +03:00
										 |  |  | 				target: map; property: "zoomLevel"; to: map.newZoomOut; duration: Math.abs(map.newZoomOut - map.zoomLevel) * 200 | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 			ParallelAnimation { | 
					
						
							| 
									
										
										
										
											2017-11-27 16:09:49 +02:00
										 |  |  | 				CoordinateAnimation { target: map; property: "center"; to: map.newCenter; duration: 2000; easing.type: Easing.OutCubic } | 
					
						
							| 
									
										
										
										
											2017-07-28 00:25:48 +03:00
										 |  |  | 				NumberAnimation { | 
					
						
							| 
									
										
										
										
											2017-11-27 16:09:49 +02:00
										 |  |  | 					target: map; property: "zoomLevel"; to: map.newZoom; duration: 2000 | 
					
						
							| 
									
										
										
										
											2017-07-28 00:25:48 +03:00
										 |  |  | 				} | 
					
						
							| 
									
										
										
										
											2017-07-17 01:16:27 +03:00
										 |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-07-25 18:34:24 +03:00
										 |  |  | 		ParallelAnimation { | 
					
						
							|  |  |  | 			id: mapAnimationClick | 
					
						
							| 
									
										
										
										
											2017-07-28 16:40:28 +03:00
										 |  |  | 			CoordinateAnimation { target: map; property: "center"; to: map.newCenter; duration: 500	} | 
					
						
							|  |  |  | 			NumberAnimation { target: map; property: "zoomLevel"; to: map.newZoom; duration: 500 } | 
					
						
							| 
									
										
										
										
											2017-07-25 18:34:24 +03:00
										 |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		MouseArea { | 
					
						
							|  |  |  | 			anchors.fill: parent | 
					
						
							| 
									
										
										
										
											2017-11-26 00:10:08 +02:00
										 |  |  | 			onPressed: { map.stopZoomAnimations(); mouse.accepted = false } | 
					
						
							|  |  |  | 			onWheel: { map.stopZoomAnimations(); wheel.accepted = false } | 
					
						
							| 
									
										
										
										
											2017-07-25 18:34:24 +03:00
										 |  |  | 			onDoubleClicked: map.doubleClickHandler(map.toCoordinate(Qt.point(mouseX, mouseY))) | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		function doubleClickHandler(coord) { | 
					
						
							|  |  |  | 			newCenter = coord | 
					
						
							|  |  |  | 			newZoom = zoomLevel + zoomStep | 
					
						
							| 
									
										
										
										
											2017-07-25 18:55:36 +03:00
										 |  |  | 			if (newZoom > maximumZoomLevel) | 
					
						
							|  |  |  | 				newZoom = maximumZoomLevel | 
					
						
							| 
									
										
										
										
											2017-07-25 18:34:24 +03:00
										 |  |  | 			mapAnimationClick.restart() | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-08-07 02:13:25 +03:00
										 |  |  | 		function pointIsVisible(pt) { | 
					
						
							|  |  |  | 			return !isNaN(pt.x) | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-27 17:05:43 +02:00
										 |  |  | 		function coordIsValid(coord) { | 
					
						
							|  |  |  | 			if (coord == null || isNaN(coord.latitude) || isNaN(coord.longitude) || | 
					
						
							|  |  |  | 			    (coord.latitude === 0.0 && coord.longitude === 0.0)) | 
					
						
							|  |  |  | 				return false; | 
					
						
							|  |  |  | 			return true; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-08-07 02:13:25 +03:00
										 |  |  | 		function stopZoomAnimations() { | 
					
						
							|  |  |  | 			mapAnimationZoomIn.stop() | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-07-27 23:46:54 +03:00
										 |  |  | 		function centerOnCoordinate(coord) { | 
					
						
							| 
									
										
										
										
											2017-08-07 02:13:25 +03:00
										 |  |  | 			stopZoomAnimations() | 
					
						
							| 
									
										
										
										
											2017-11-27 17:05:43 +02:00
										 |  |  | 			if (!coordIsValid(coord)) { | 
					
						
							|  |  |  | 				console.warn("MapWidget.qml: centerOnCoordinate(): !coordIsValid()") | 
					
						
							| 
									
										
										
										
											2017-11-27 17:13:57 +02:00
										 |  |  | 				return | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 			var newZoomOutFound = false | 
					
						
							|  |  |  | 			var zoomStored = zoomLevel | 
					
						
							|  |  |  | 			var centerStored = QtPositioning.coordinate(center.latitude, center.longitude) | 
					
						
							|  |  |  | 			newZoomOut = zoomLevel | 
					
						
							|  |  |  | 			newCenter = coord | 
					
						
							|  |  |  | 			zoomLevel = Math.floor(zoomLevel) | 
					
						
							|  |  |  | 			while (zoomLevel > minimumZoomLevel) { | 
					
						
							|  |  |  | 				var pt = fromCoordinate(coord) | 
					
						
							|  |  |  | 				if (pointIsVisible(pt)) { | 
					
						
							|  |  |  | 					newZoomOut = zoomLevel | 
					
						
							|  |  |  | 					newZoomOutFound = true | 
					
						
							|  |  |  | 					break | 
					
						
							| 
									
										
										
										
											2017-07-28 00:25:48 +03:00
										 |  |  | 				} | 
					
						
							| 
									
										
										
										
											2017-11-27 17:13:57 +02:00
										 |  |  | 				zoomLevel -= 1.0 | 
					
						
							| 
									
										
										
										
											2017-07-28 00:25:48 +03:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2017-11-27 17:13:57 +02:00
										 |  |  | 			if (!newZoomOutFound) | 
					
						
							|  |  |  | 				newZoomOut = defaultZoomOut | 
					
						
							|  |  |  | 			zoomLevel = zoomStored | 
					
						
							|  |  |  | 			center = centerStored | 
					
						
							|  |  |  | 			newZoom = zoomStored | 
					
						
							|  |  |  | 			mapAnimationZoomIn.restart() | 
					
						
							| 
									
										
										
										
											2017-07-17 00:25:19 +03:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2017-07-20 00:29:42 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-08-07 02:18:09 +03:00
										 |  |  | 		function centerOnRectangle(topLeft, bottomRight, centerRect) { | 
					
						
							|  |  |  | 			stopZoomAnimations() | 
					
						
							|  |  |  | 			if (newCenter.latitude === 0.0 && newCenter.longitude === 0.0) { | 
					
						
							| 
									
										
										
										
											2017-10-23 10:04:33 -04:00
										 |  |  | 				// Do nothing
 | 
					
						
							| 
									
										
										
										
											2017-11-27 17:13:57 +02:00
										 |  |  | 				return | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 			var centerStored = QtPositioning.coordinate(center.latitude, center.longitude) | 
					
						
							|  |  |  | 			var zoomStored = zoomLevel | 
					
						
							|  |  |  | 			var newZoomOutFound = false | 
					
						
							|  |  |  | 			newCenter = centerRect | 
					
						
							|  |  |  | 			// calculate zoom out
 | 
					
						
							|  |  |  | 			newZoomOut = zoomLevel | 
					
						
							|  |  |  | 			while (zoomLevel > minimumZoomLevel) { | 
					
						
							|  |  |  | 				var ptCenter = fromCoordinate(centerStored) | 
					
						
							|  |  |  | 				var ptCenterRect = fromCoordinate(centerRect) | 
					
						
							|  |  |  | 				if (pointIsVisible(ptCenter) && pointIsVisible(ptCenterRect)) { | 
					
						
							|  |  |  | 					newZoomOut = zoomLevel | 
					
						
							|  |  |  | 					newZoomOutFound = true | 
					
						
							|  |  |  | 					break | 
					
						
							| 
									
										
										
										
											2017-08-07 02:18:09 +03:00
										 |  |  | 				} | 
					
						
							| 
									
										
										
										
											2017-11-27 17:13:57 +02:00
										 |  |  | 				zoomLevel -= 1.0 | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 			if (!newZoomOutFound) | 
					
						
							|  |  |  | 				newZoomOut = defaultZoomOut | 
					
						
							|  |  |  | 			// calculate zoom in
 | 
					
						
							|  |  |  | 			center = newCenter | 
					
						
							|  |  |  | 			zoomLevel = Math.floor(maximumZoomLevel) | 
					
						
							|  |  |  | 			var diagonalRect = topLeft.distanceTo(bottomRight) | 
					
						
							|  |  |  | 			while (zoomLevel > minimumZoomLevel) { | 
					
						
							|  |  |  | 				var c0 = toCoordinate(Qt.point(0.0, 0.0)) | 
					
						
							|  |  |  | 				var c1 = toCoordinate(Qt.point(width, height)) | 
					
						
							|  |  |  | 				if (c0.distanceTo(c1) > diagonalRect) { | 
					
						
							|  |  |  | 					newZoom = zoomLevel - 2.0 | 
					
						
							|  |  |  | 					break | 
					
						
							| 
									
										
										
										
											2017-08-07 02:18:09 +03:00
										 |  |  | 				} | 
					
						
							| 
									
										
										
										
											2017-11-27 17:13:57 +02:00
										 |  |  | 				zoomLevel -= 1.0 | 
					
						
							| 
									
										
										
										
											2017-08-07 02:18:09 +03:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2017-11-27 17:13:57 +02:00
										 |  |  | 			if (newZoom > defaultZoomIn) | 
					
						
							|  |  |  | 				newZoom = defaultZoomIn | 
					
						
							|  |  |  | 			zoomLevel = zoomStored | 
					
						
							|  |  |  | 			center = centerStored | 
					
						
							|  |  |  | 			mapAnimationZoomIn.restart() | 
					
						
							| 
									
										
										
										
											2017-08-07 02:04:23 +03:00
										 |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-07-20 00:29:42 +03:00
										 |  |  | 		function deselectMapLocation() { | 
					
						
							| 
									
										
										
										
											2017-10-23 10:04:33 -04:00
										 |  |  | 			stopZoomAnimations() | 
					
						
							| 
									
										
										
										
											2017-07-20 00:29:42 +03:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2017-07-20 05:24:18 +03:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2017-07-20 03:07:47 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-07-28 00:09:25 +03: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 16:40:28 +03:00
										 |  |  | 		transitions: Transition { NumberAnimation { properties: "opacity"; easing.type: Easing.InOutQuad }} | 
					
						
							| 
									
										
										
										
											2017-07-28 00:09:25 +03: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 05:24:18 +03:00
										 |  |  | 	Image { | 
					
						
							|  |  |  | 		id: toggleImage | 
					
						
							|  |  |  | 		x: 10; y: x | 
					
						
							| 
									
										
										
										
											2017-07-31 21:43:19 +02:00
										 |  |  | 		width: 40 | 
					
						
							|  |  |  | 		height: 40 | 
					
						
							| 
									
										
										
										
											2017-11-29 10:57:08 +01:00
										 |  |  | 		source: "qrc:///map-style-" + (map.activeMapType === map.mapType.SATELLITE ? "map" : "photo") + "-icon" | 
					
						
							| 
									
										
										
										
											2017-07-20 05:24:18 +03:00
										 |  |  | 		SequentialAnimation { | 
					
						
							|  |  |  | 			id: toggleImageAnimation | 
					
						
							| 
									
										
										
										
											2017-07-28 16:40:28 +03: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 05:24:18 +03:00
										 |  |  | 		} | 
					
						
							|  |  |  | 		MouseArea { | 
					
						
							|  |  |  | 			anchors.fill: parent | 
					
						
							|  |  |  | 			onClicked: { | 
					
						
							|  |  |  | 				map.activeMapType = map.activeMapType === map.mapType.SATELLITE ? map.mapType.STREET : map.mapType.SATELLITE | 
					
						
							|  |  |  | 				toggleImageAnimation.restart() | 
					
						
							| 
									
										
										
										
											2017-07-20 03:07:47 +03:00
										 |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2017-07-14 17:53:08 +03:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2017-07-20 16:58:21 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-07-25 18:55:36 +03:00
										 |  |  | 	Image { | 
					
						
							|  |  |  | 		id: imageZoomIn | 
					
						
							|  |  |  | 		x: 10 + (toggleImage.width - imageZoomIn.width) * 0.5; y: toggleImage.y + toggleImage.height + 10 | 
					
						
							| 
									
										
										
										
											2017-07-31 21:43:19 +02:00
										 |  |  | 		width: 20 | 
					
						
							|  |  |  | 		height: 20 | 
					
						
							| 
									
										
										
										
											2017-11-29 10:57:08 +01:00
										 |  |  | 		source: "qrc:///zoom-in-icon" | 
					
						
							| 
									
										
										
										
											2017-07-25 18:55:36 +03:00
										 |  |  | 		SequentialAnimation { | 
					
						
							|  |  |  | 			id: imageZoomInAnimation | 
					
						
							| 
									
										
										
										
											2017-07-28 16:40:28 +03: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 18:55:36 +03:00
										 |  |  | 		} | 
					
						
							|  |  |  | 		MouseArea { | 
					
						
							|  |  |  | 			anchors.fill: parent | 
					
						
							|  |  |  | 			onClicked: { | 
					
						
							| 
									
										
										
										
											2017-11-26 00:10:08 +02:00
										 |  |  | 				map.stopZoomAnimations() | 
					
						
							| 
									
										
										
										
											2017-07-25 18:55:36 +03:00
										 |  |  | 				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 | 
					
						
							| 
									
										
										
										
											2017-11-29 10:57:08 +01:00
										 |  |  | 		source: "qrc:///zoom-out-icon" | 
					
						
							| 
									
										
										
										
											2017-07-31 21:43:19 +02:00
										 |  |  | 		width: 20 | 
					
						
							|  |  |  | 		height: 20 | 
					
						
							| 
									
										
										
										
											2017-07-25 18:55:36 +03:00
										 |  |  | 		SequentialAnimation { | 
					
						
							|  |  |  | 			id: imageZoomOutAnimation | 
					
						
							| 
									
										
										
										
											2017-07-28 16:40:28 +03: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 18:55:36 +03:00
										 |  |  | 		} | 
					
						
							|  |  |  | 		MouseArea { | 
					
						
							|  |  |  | 			anchors.fill: parent | 
					
						
							|  |  |  | 			onClicked: { | 
					
						
							| 
									
										
										
										
											2017-11-26 00:10:08 +02:00
										 |  |  | 				map.stopZoomAnimations() | 
					
						
							| 
									
										
										
										
											2017-07-25 18:55:36 +03:00
										 |  |  | 				map.newCenter = map.center | 
					
						
							|  |  |  | 				map.newZoom = map.zoomLevel - map.zoomStep | 
					
						
							|  |  |  | 				mapAnimationClick.restart() | 
					
						
							|  |  |  | 				imageZoomOutAnimation.restart() | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-14 20:06:13 +02:00
										 |  |  | 	/* | 
					
						
							|  |  |  | 	 * open coordinates in google maps while attempting to roughly preserve | 
					
						
							|  |  |  | 	 * the zoom level. the mapping between the QML map zoom level and the | 
					
						
							|  |  |  | 	 * Google Maps zoom level is done via exponential regression: | 
					
						
							|  |  |  | 	 *     y = a * exp(b * x) | 
					
						
							|  |  |  | 	 * | 
					
						
							|  |  |  | 	 * data set: | 
					
						
							|  |  |  | 	 *     qml (x)            gmaps (y in meters) | 
					
						
							|  |  |  | 	 *     21                 257 | 
					
						
							|  |  |  | 	 *     15.313216749178913 3260 | 
					
						
							|  |  |  | 	 *     12.553216749178931 20436 | 
					
						
							|  |  |  | 	 *     11.11321674917894  52883 | 
					
						
							|  |  |  | 	 *     9.313216749178952  202114 | 
					
						
							|  |  |  | 	 *     7.51321674917896   737136 | 
					
						
							|  |  |  | 	 *     5.593216749178958  2495529 | 
					
						
							|  |  |  | 	 *     4.153216749178957  3895765 | 
					
						
							|  |  |  | 	 *     1.753216749178955  18999949 | 
					
						
							|  |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2017-07-21 16:26:33 +03:00
										 |  |  | 	function openLocationInGoogleMaps(latitude, longitude) { | 
					
						
							| 
									
										
										
										
											2018-03-14 18:57:06 +02:00
										 |  |  | 		var loc = latitude + "," + longitude | 
					
						
							| 
									
										
										
										
											2018-03-14 20:06:13 +02:00
										 |  |  | 		var x = map.zoomLevel | 
					
						
							|  |  |  | 		var a = 53864950.831693 | 
					
						
							|  |  |  | 		var b = -0.60455861606547030630 | 
					
						
							|  |  |  | 		var zoom = Math.floor(a * Math.exp(b * x)) | 
					
						
							|  |  |  | 		var url = "https://www.google.com/maps/place/@" + loc + "," + zoom + "m/data=!3m1!1e3!4m2!3m1!1s0x0:0x0" | 
					
						
							| 
									
										
										
										
											2017-07-21 16:26:33 +03:00
										 |  |  | 		Qt.openUrlExternally(url) | 
					
						
							| 
									
										
										
										
											2018-03-14 20:06:13 +02:00
										 |  |  | 		console.log("openLocationInGoogleMaps() map.zoomLevel: " + x + ", url: " + url) | 
					
						
							| 
									
										
										
										
											2017-07-21 16:26:33 +03:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-07-20 16:58:21 +03:00
										 |  |  | 	MapWidgetContextMenu { | 
					
						
							|  |  |  | 		id: contextMenu | 
					
						
							| 
									
										
										
										
											2017-07-20 19:25:59 +03:00
										 |  |  | 		y: 10; x: map.width - y | 
					
						
							| 
									
										
										
										
											2017-07-21 01:28:58 +03:00
										 |  |  | 		onActionSelected: { | 
					
						
							|  |  |  | 			switch (action) { | 
					
						
							|  |  |  | 			case contextMenu.actions.OPEN_LOCATION_IN_GOOGLE_MAPS: | 
					
						
							| 
									
										
										
										
											2017-07-21 16:26:33 +03:00
										 |  |  | 				openLocationInGoogleMaps(map.center.latitude, map.center.longitude) | 
					
						
							| 
									
										
										
										
											2017-07-28 16:40:28 +03:00
										 |  |  | 				break | 
					
						
							| 
									
										
										
										
											2017-07-21 01:28:58 +03:00
										 |  |  | 			case contextMenu.actions.COPY_LOCATION_DECIMAL: | 
					
						
							| 
									
										
										
										
											2017-07-25 18:38:15 +03:00
										 |  |  | 				mapHelper.copyToClipboardCoordinates(map.center, false) | 
					
						
							| 
									
										
										
										
											2017-07-28 16:40:28 +03:00
										 |  |  | 				break | 
					
						
							| 
									
										
										
										
											2017-07-21 01:28:58 +03:00
										 |  |  | 			case contextMenu.actions.COPY_LOCATION_SEXAGESIMAL: | 
					
						
							| 
									
										
										
										
											2017-07-25 18:38:15 +03:00
										 |  |  | 				mapHelper.copyToClipboardCoordinates(map.center, true) | 
					
						
							| 
									
										
										
										
											2017-07-28 16:40:28 +03:00
										 |  |  | 				break | 
					
						
							| 
									
										
										
										
											2017-08-07 03:02:16 +03:00
										 |  |  | 			case contextMenu.actions.SELECT_VISIBLE_LOCATIONS: | 
					
						
							|  |  |  | 				mapHelper.selectVisibleLocations() | 
					
						
							|  |  |  | 				break | 
					
						
							| 
									
										
										
										
											2017-07-21 01:28:58 +03:00
										 |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2017-07-20 16:58:21 +03:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2017-07-14 17:53:08 +03:00
										 |  |  | } |