summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaolo Angelelli <paolo.angelelli@qt.io>2017-06-06 14:39:32 +0200
committerPaolo Angelelli <paolo.angelelli@qt.io>2017-07-17 15:51:35 +0000
commit73a51e3df7a3b1b8413c985b17f4ba9cc246e0fd (patch)
tree686e2f82ce54cabc32c07e004a87f0aeda698f37
parent73bf828559ab343a180a67db5d632bbd702a921e (diff)
downloadqtlocation-73a51e3df7a3b1b8413c985b17f4ba9cc246e0fd.tar.gz
Allow to tilt/rotate the map using the scroll wheel
This patch allows to rotate the map by using the scroll wheel in combination with the Shift key, and to tilt the map in combination with the Control key. [ChangeLog][QtLocation][MapGestureArea] Added rotation and tilt scrollwheel actions. Change-Id: I1cfdad7615258e75506802ac4f4e71413b71b8ce Reviewed-by: Alex Blasche <alexander.blasche@qt.io>
-rw-r--r--src/location/declarativemaps/qquickgeomapgesturearea.cpp31
1 files changed, 22 insertions, 9 deletions
diff --git a/src/location/declarativemaps/qquickgeomapgesturearea.cpp b/src/location/declarativemaps/qquickgeomapgesturearea.cpp
index 6931c774..39fd2397 100644
--- a/src/location/declarativemaps/qquickgeomapgesturearea.cpp
+++ b/src/location/declarativemaps/qquickgeomapgesturearea.cpp
@@ -243,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
@@ -939,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(m_map->geoProjection().anchorCoordinateToPoint(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