From 436c2ebcc6520c1797fa0f6632418615002b23be Mon Sep 17 00:00:00 2001 From: Juha Vuolle Date: Wed, 21 Dec 2011 13:39:42 +0200 Subject: Finetune map item drag, works now also with mapviewer. Change-Id: Ifd7612bca979a74ab09caaa6ec542cc9ee16cb96 Reviewed-by: Natalia Shubina Reviewed-by: David Laing --- .../location/qdeclarativegeomapmousearea.cpp | 39 +++++++++++++--------- 1 file changed, 24 insertions(+), 15 deletions(-) (limited to 'src/imports/location/qdeclarativegeomapmousearea.cpp') diff --git a/src/imports/location/qdeclarativegeomapmousearea.cpp b/src/imports/location/qdeclarativegeomapmousearea.cpp index 479f496a..94268cb8 100644 --- a/src/imports/location/qdeclarativegeomapmousearea.cpp +++ b/src/imports/location/qdeclarativegeomapmousearea.cpp @@ -96,8 +96,8 @@ QT_BEGIN_NAMESPACE QDeclarativeGeoMapMouseArea::QDeclarativeGeoMapMouseArea(QQuickItem *parent) : QQuickMouseArea(parent), - map_(0), - componentCompleted_(false) + componentCompleted_(false), + dragActive_(false) { } @@ -107,30 +107,33 @@ QDeclarativeGeoMapMouseArea::~QDeclarativeGeoMapMouseArea() QDeclarativeCoordinate* QDeclarativeGeoMapMouseArea::mouseToCoordinate(QQuickMouseEvent* event) { - // figure out the map association for this mouse area and use it to resolve geocoordinate. + // figure out the map association for this mouse area and use it to resolve geocoordinate + QDeclarativeGeoMap* quickmap = map(); + if (quickmap) + return quickmap->toCoordinate(quickmap->mapFromItem(this, QPointF(event->x(), event->y()))); + return new QDeclarativeCoordinate; // return invalid coordinate +} + +// TODO: cache the map association and hook up to parent change -signals +QDeclarativeGeoMap* QDeclarativeGeoMapMouseArea::map() +{ QQuickItem* pmi = parentMapItem(); + QDeclarativeGeoMap* map = 0; if (pmi) { - QDeclarativeGeoMap* map = qobject_cast(pmi); + map = qobject_cast(pmi); if (!map) { QDeclarativeGeoMapItemBase* item = qobject_cast(pmi); if (item) map = item->quickMap(); } - if (map) - return map->toCoordinate(map->mapFromItem(this, QPointF(event->x(), event->y()))); } - return new QDeclarativeCoordinate; // return invalid coordinate + return map; } void QDeclarativeGeoMapMouseArea::dragActiveChanged() { - QQuickItem* pmi = parentMapItem(); - if (pmi && qobject_cast(pmi)) { - if (drag() && drag()->property("active").toBool()) - qobject_cast(pmi)->dragStarted(); - else - qobject_cast(pmi)->dragEnded(); - } + if (drag() && drag()->property("active").toBool()) + dragActive_ = true; } void QDeclarativeGeoMapMouseArea::componentComplete() @@ -160,8 +163,14 @@ void QDeclarativeGeoMapMouseArea::mouseReleaseEvent(QMouseEvent *event) { // map element's flickable may use the event QQuickItem* pmi = parentMapItem(); - if (pmi && qobject_cast(pmi)) + if (pmi && qobject_cast(pmi)) { qobject_cast(pmi)->mouseEvent(event); + } else if (dragActive_ && pmi && qobject_cast(pmi)) { + // position of the item may have changed by the time the activeChanged + // is received, hence update already on mouse release + qobject_cast(pmi)->dragEnded(); + dragActive_ = false; + } QQuickMouseArea::mouseReleaseEvent(event); } -- cgit v1.2.1