summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorHarald Meyer <dev@meh.at>2015-07-09 17:29:56 +0200
committerHarald Meyer <dev@meh.at>2015-07-13 06:52:31 +0000
commit6b40fb48fe5f5f094232535199cfccc753f62b17 (patch)
treea761835d0f0c1ea07d26ccbe83f53a7a5422150c /src
parent43bea1bbadec470202cb27d9db5cc202b9514f91 (diff)
downloadqtlocation-6b40fb48fe5f5f094232535199cfccc753f62b17.tar.gz
Improved zooming and map movement behavior.
Improved: Double tapping/mouse wheel based zooming keeps the map at the current geo location. Added: Left/Right/Up/Down keys can be used to move the map. Task-number: QTBUG-47020 Task-number: QTBUG-47019 Change-Id: I63859319b282e7738a173b0d3917433860fc8969 Reviewed-by: Michal Klocek <michal.klocek@theqtcompany.com> Reviewed-by: Alex Blasche <alexander.blasche@theqtcompany.com>
Diffstat (limited to 'src')
-rw-r--r--src/imports/location/qdeclarativegeomap.cpp18
-rw-r--r--src/imports/location/qdeclarativegeomap_p.h4
-rw-r--r--src/imports/location/qdeclarativegeomapgesturearea.cpp16
3 files changed, 28 insertions, 10 deletions
diff --git a/src/imports/location/qdeclarativegeomap.cpp b/src/imports/location/qdeclarativegeomap.cpp
index f948b0c3..1de22a50 100644
--- a/src/imports/location/qdeclarativegeomap.cpp
+++ b/src/imports/location/qdeclarativegeomap.cpp
@@ -821,31 +821,33 @@ QQmlListProperty<QDeclarativeGeoMapType> QDeclarativeGeoMap::supportedMapTypes()
}
/*!
- \qmlmethod coordinate QtLocation::Map::toCoordinate(QPointF position)
+ \qmlmethod coordinate QtLocation::Map::toCoordinate(QPointF position, bool clipToViewPort)
Returns the coordinate which corresponds to the \a position relative to the map item.
- Returns an invalid coordinate if \a position is not within the current viewport.
+ If \a cliptoViewPort is \c true, or not supplied then returns an invalid coordinate if
+ \a position is not within the current viewport.
*/
-QGeoCoordinate QDeclarativeGeoMap::toCoordinate(const QPointF &position) const
+QGeoCoordinate QDeclarativeGeoMap::toCoordinate(const QPointF &position, bool clipToViewPort) const
{
if (m_map)
- return m_map->itemPositionToCoordinate(QDoubleVector2D(position));
+ return m_map->itemPositionToCoordinate(QDoubleVector2D(position), clipToViewPort);
else
return QGeoCoordinate();
}
/*!
- \qmlmethod point QtLocation::Map::fromCoordinate(coordinate coordinate)
+ \qmlmethod point QtLocation::Map::fromCoordinate(coordinate coordinate, bool clipToViewPort)
Returns the position relative to the map item which corresponds to the \a coordinate.
- Returns an invalid QPointF if \a coordinate is not within the current viewport.
+ If \a cliptoViewPort is \c true, or not supplied then returns an invalid QPointF if
+ \a coordinate is not within the current viewport.
*/
-QPointF QDeclarativeGeoMap::fromCoordinate(const QGeoCoordinate &coordinate) const
+QPointF QDeclarativeGeoMap::fromCoordinate(const QGeoCoordinate &coordinate, bool clipToViewPort) const
{
if (m_map)
- return m_map->coordinateToItemPosition(coordinate).toPointF();
+ return m_map->coordinateToItemPosition(coordinate, clipToViewPort).toPointF();
else
return QPointF(qQNaN(), qQNaN());
}
diff --git a/src/imports/location/qdeclarativegeomap_p.h b/src/imports/location/qdeclarativegeomap_p.h
index 58c07b1b..ddbb8018 100644
--- a/src/imports/location/qdeclarativegeomap_p.h
+++ b/src/imports/location/qdeclarativegeomap_p.h
@@ -103,8 +103,8 @@ public:
Q_INVOKABLE void clearMapItems();
QList<QObject *> mapItems();
- Q_INVOKABLE QGeoCoordinate toCoordinate(const QPointF &position) const;
- Q_INVOKABLE QPointF fromCoordinate(const QGeoCoordinate &coordinate) const;
+ Q_INVOKABLE QGeoCoordinate toCoordinate(const QPointF &position, bool clipToViewPort = true) const;
+ Q_INVOKABLE QPointF fromCoordinate(const QGeoCoordinate &coordinate, bool clipToViewPort = true) const;
#if QT_DEPRECATED_SINCE(5,5)
QT_DEPRECATED Q_INVOKABLE QPointF toScreenPosition(const QGeoCoordinate &coordinate) const;
diff --git a/src/imports/location/qdeclarativegeomapgesturearea.cpp b/src/imports/location/qdeclarativegeomapgesturearea.cpp
index 5a74d231..7d34b729 100644
--- a/src/imports/location/qdeclarativegeomapgesturearea.cpp
+++ b/src/imports/location/qdeclarativegeomapgesturearea.cpp
@@ -658,7 +658,23 @@ void QDeclarativeGeoMapGestureArea::handleTouchEvent(QTouchEvent *event)
void QDeclarativeGeoMapGestureArea::handleWheelEvent(QWheelEvent *event)
{
+ QGeoCoordinate wheelGeoPos = map_->itemPositionToCoordinate(QDoubleVector2D(event->posF()), false);
+ QPointF preZoomPoint = map_->coordinateToItemPosition(wheelGeoPos, false).toPointF();
+
declarativeMap_->setZoomLevel(qBound(minimumZoomLevel(), declarativeMap_->zoomLevel() + event->angleDelta().y() * qreal(0.001), maximumZoomLevel()));
+
+ QPointF postZoomPoint = map_->coordinateToItemPosition(wheelGeoPos, false).toPointF();
+
+ if (preZoomPoint != postZoomPoint)
+ {
+ qreal dx = postZoomPoint.x() - preZoomPoint.x();
+ qreal dy = postZoomPoint.y() - preZoomPoint.y();
+ QPointF mapCenterPoint(map_->width() / 2.0 + dx, map_->height() / 2.0 + dy);
+
+ QGeoCoordinate mapCenterCoordinate = map_->itemPositionToCoordinate(QDoubleVector2D(mapCenterPoint), false);
+ map_->mapController()->setCenter(mapCenterCoordinate);
+ }
+
event->accept();
}