mapwidget.qml: add new logic for zooming and editing support

The editing support is added via dragging. It is handled via the
MouseArea's drag.target of the MapQuickItem. The drag target changes
with the model selectedUuid.

"mapAnimationZoomIn" now also does an initial zoom-out before moving
to a new location.

centerOnCoordinate() now pefroms calculations to determine how much
the animation needs to zoom out. What it does is it reduces the Map
zoomLevel util both the current and the new target coordinates are visible.
It then restores the zoomLevel and performs animation based on newZoomOut.

animateMapZoomIn() is now obsolete.

The patch also includes the following smaller changes:
- remove the setSelectedUuid() call in deselectMapLocation()
This is now handled in C++
- sets "defaultZoomIn" to 12.0
- use ">=" when determining if a mapItem text should be visible

Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com>
This commit is contained in:
Lubomir I. Ivanov 2017-07-28 00:25:48 +03:00 committed by Dirk Hohndel
parent 3589e2e952
commit 5270688483

View file

@ -16,6 +16,7 @@ Item {
id: mapHelper id: mapHelper
map: map map: map
editMode: false editMode: false
onSelectedDivesChanged: { onSelectedDivesChanged: {
// 'list' contains a list of dive list indexes // 'list' contains a list of dive list indexes
nSelectedDives = list.length nSelectedDives = list.length
@ -31,12 +32,13 @@ Item {
readonly property var mapType: { "STREET": supportedMapTypes[0], "SATELLITE": supportedMapTypes[1] } readonly property var mapType: { "STREET": supportedMapTypes[0], "SATELLITE": supportedMapTypes[1] }
readonly property var defaultCenter: QtPositioning.coordinate(0, 0) readonly property var defaultCenter: QtPositioning.coordinate(0, 0)
readonly property real defaultZoomIn: 17.0 readonly property real defaultZoomIn: 12.0
readonly property real defaultZoomOut: 1.0 readonly property real defaultZoomOut: 1.0
readonly property real textVisibleZoom: 8.0 readonly property real textVisibleZoom: 8.0
readonly property real zoomStep: 2.0 readonly property real zoomStep: 2.0
property var newCenter: defaultCenter property var newCenter: defaultCenter
property real newZoom: 1.0 property real newZoom: 1.0
property real newZoomOut: 1.0
property var clickCoord: QtPositioning.coordinate(0, 0) property var clickCoord: QtPositioning.coordinate(0, 0)
Component.onCompleted: { Component.onCompleted: {
@ -49,6 +51,7 @@ Item {
id: mapItemView id: mapItemView
model: mapHelper.model model: mapHelper.model
delegate: MapQuickItem { delegate: MapQuickItem {
id: mapItem
anchorPoint.x: 0 anchorPoint.x: 0
anchorPoint.y: mapItemImage.height anchorPoint.y: mapItemImage.height
coordinate: model.coordinate coordinate: model.coordinate
@ -67,15 +70,24 @@ Item {
} }
} }
MouseArea { MouseArea {
drag.target: (mapHelper.editMode && mapHelper.model.selectedUuid === model.uuid) ? mapItem : undefined
anchors.fill: parent anchors.fill: parent
onClicked: mapHelper.model.setSelectedUuid(model.uuid, true) onClicked: {
onDoubleClicked: map.doubleClickHandler(model.coordinate) 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)
}
}
} }
} }
Item { Item {
// Text with a duplicate for shadow. DropShadow as layer effect is kind of slow here. // Text with a duplicate for shadow. DropShadow as layer effect is kind of slow here.
y: mapItemImage.y + mapItemImage.height y: mapItemImage.y + mapItemImage.height
visible: map.zoomLevel > map.textVisibleZoom visible: map.zoomLevel >= map.textVisibleZoom
Text { Text {
id: mapItemTextShadow id: mapItemTextShadow
x: mapItemText.x + 2; y: mapItemText.y + 2 x: mapItemText.x + 2; y: mapItemText.y + 2
@ -94,13 +106,18 @@ Item {
} }
} }
ParallelAnimation { SequentialAnimation {
id: mapAnimationZoomIn id: mapAnimationZoomIn
NumberAnimation {
target: map; property: "zoomLevel"; to: map.newZoomOut; duration: Math.abs(map.newZoomOut - map.zoomLevel) * 200
}
ParallelAnimation {
CoordinateAnimation { CoordinateAnimation {
target: map; property: "center"; to: map.newCenter; duration: 2000 target: map; property: "center"; to: map.newCenter; duration: 1000
} }
NumberAnimation { NumberAnimation {
target: map; property: "zoomLevel"; to: map.newZoom ; duration: 3000; easing.type: Easing.InCubic target: map; property: "zoomLevel"; to: map.newZoom ; duration: 2000; easing.type: Easing.InCubic
}
} }
} }
@ -140,14 +157,6 @@ Item {
mapAnimationClick.restart() mapAnimationClick.restart()
} }
function animateMapZoomIn(coord) {
zoomLevel = defaultZoomOut
newCenter = coord
newZoom = defaultZoomIn
mapAnimationZoomIn.restart()
mapAnimationZoomOut.stop()
}
function animateMapZoomOut() { function animateMapZoomOut() {
newCenter = defaultCenter newCenter = defaultCenter
newZoom = defaultZoomOut newZoom = defaultZoomOut
@ -156,11 +165,29 @@ Item {
} }
function centerOnCoordinate(coord) { function centerOnCoordinate(coord) {
animateMapZoomIn(coord) 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()
} }
function deselectMapLocation() { function deselectMapLocation() {
mapHelper.model.setSelectedUuid(0, false)
animateMapZoomOut() animateMapZoomOut()
} }
} }