diff options
Diffstat (limited to 'src/location/declarativemaps/qquickgeomapgesturearea.cpp')
-rw-r--r-- | src/location/declarativemaps/qquickgeomapgesturearea.cpp | 45 |
1 files changed, 23 insertions, 22 deletions
diff --git a/src/location/declarativemaps/qquickgeomapgesturearea.cpp b/src/location/declarativemaps/qquickgeomapgesturearea.cpp index 4f949ad0..d62ae8cf 100644 --- a/src/location/declarativemaps/qquickgeomapgesturearea.cpp +++ b/src/location/declarativemaps/qquickgeomapgesturearea.cpp @@ -84,18 +84,6 @@ static qreal distanceBetweenTouchPoints(const QPointF &p1, const QPointF &p2) return QLineF(p1, p2).length(); } -// Returns the new map center after anchoring coordinate to anchorPoint on the screen -// Approach: find the displacement in (wrapped) mercator space, and apply that to the center -static QGeoCoordinate anchorCoordinateToPoint(QGeoMap &map, const QGeoCoordinate &coordinate, const QPointF &anchorPoint) -{ - QDoubleVector2D centerProj = map.geoProjection().geoToWrappedMapProjection(map.cameraData().center()); - QDoubleVector2D coordProj = map.geoProjection().geoToWrappedMapProjection(coordinate); - - QDoubleVector2D anchorProj = map.geoProjection().itemPositionToWrappedMapProjection(QDoubleVector2D(anchorPoint)); - // Y-clamping done in mercatorToCoord - return map.geoProjection().wrappedMapProjectionToGeo(centerProj + coordProj - anchorProj); -} - static qreal angleFromPoints(const QPointF &p1, const QPointF &p2) { return QLineF(p1, p2).angle(); @@ -255,6 +243,8 @@ QT_BEGIN_NAMESPACE MapGestureArea objects are used as part of a Map, to provide for panning, flicking and pinch-to-zoom gesture used on touch displays, as well as two finger rotation and two finger parallel vertical sliding to tilt the map. + On platforms supporting \l QWheelEvent, using the scroll wheel alone, or in combination with + key modifiers Shift or Control will also zoom, rotate or tilt the map, respectively. A MapGestureArea is automatically created with a new Map and available with the \l{Map::gesture}{gesture} property. This is the only way @@ -951,15 +941,26 @@ void QQuickGeoMapGestureArea::handleWheelEvent(QWheelEvent *event) const QGeoCoordinate &wheelGeoPos = m_map->geoProjection().itemPositionToCoordinate(QDoubleVector2D(event->posF()), false); const QPointF &preZoomPoint = event->posF(); - const double zoomLevelDelta = event->angleDelta().y() * qreal(0.001); - // Gesture area should always honor maxZL, but Map might not. - m_declarativeMap->setZoomLevel(qMin<qreal>(m_declarativeMap->zoomLevel() + zoomLevelDelta, maximumZoomLevel()), - false); - const QPointF &postZoomPoint = m_map->geoProjection().coordinateToItemPosition(wheelGeoPos, false).toPointF(); - - if (preZoomPoint != postZoomPoint) // need to re-anchor the wheel geoPos to the event position - m_declarativeMap->setCenter(anchorCoordinateToPoint(*m_map, wheelGeoPos, preZoomPoint)); - + // Not using AltModifier as, for some reason, it causes angleDelta to be 0 + if (event->modifiers() & Qt::ShiftModifier && rotationEnabled()) { + // First set bearing + const double bearingDelta = event->angleDelta().y() * qreal(0.05); + m_declarativeMap->setBearing(m_declarativeMap->bearing() + bearingDelta); + // then reanchor + m_declarativeMap->setCenter(m_map->geoProjection().anchorCoordinateToPoint(wheelGeoPos, preZoomPoint)); + } else if (event->modifiers() & Qt::ControlModifier && tiltEnabled()) { + const double tiltDelta = event->angleDelta().y() * qreal(0.05); + m_declarativeMap->setTilt(m_declarativeMap->tilt() + tiltDelta); + } else if (pinchEnabled()) { + const double zoomLevelDelta = event->angleDelta().y() * qreal(0.001); + // Gesture area should always honor maxZL, but Map might not. + m_declarativeMap->setZoomLevel(qMin<qreal>(m_declarativeMap->zoomLevel() + zoomLevelDelta, maximumZoomLevel()), + false); + const QPointF &postZoomPoint = m_map->geoProjection().coordinateToItemPosition(wheelGeoPos, false).toPointF(); + + if (preZoomPoint != postZoomPoint) // need to re-anchor the wheel geoPos to the event position + m_declarativeMap->setCenter(m_map->geoProjection().anchorCoordinateToPoint(wheelGeoPos, preZoomPoint)); + } event->accept(); } #endif @@ -1705,7 +1706,7 @@ bool QQuickGeoMapGestureArea::canStartPan() */ void QQuickGeoMapGestureArea::updatePan() { - QGeoCoordinate animationStartCoordinate = anchorCoordinateToPoint(*m_map, m_startCoord, m_touchPointsCentroid); + QGeoCoordinate animationStartCoordinate = m_map->geoProjection().anchorCoordinateToPoint(m_startCoord, m_touchPointsCentroid); m_declarativeMap->setCenter(animationStartCoordinate); } |