diff options
author | Juha Vuolle <juha.vuolle@nokia.com> | 2011-12-21 13:39:42 +0200 |
---|---|---|
committer | Qt by Nokia <qt-info@nokia.com> | 2011-12-22 04:02:51 +0100 |
commit | 436c2ebcc6520c1797fa0f6632418615002b23be (patch) | |
tree | 9a98d57bcca67dfe9c1c4112e25147f7bf271ac5 /src/imports/location/qdeclarativegeomapmousearea.cpp | |
parent | 1b1c6adf03d199bf7a2639c16232601c66600f7e (diff) | |
download | qtlocation-436c2ebcc6520c1797fa0f6632418615002b23be.tar.gz |
Finetune map item drag, works now also with mapviewer.
Change-Id: Ifd7612bca979a74ab09caaa6ec542cc9ee16cb96
Reviewed-by: Natalia Shubina <natalia.shubina@nokia.com>
Reviewed-by: David Laing <david.laing@nokia.com>
Diffstat (limited to 'src/imports/location/qdeclarativegeomapmousearea.cpp')
-rw-r--r-- | src/imports/location/qdeclarativegeomapmousearea.cpp | 39 |
1 files changed, 24 insertions, 15 deletions
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<QDeclarativeGeoMap*>(pmi); + map = qobject_cast<QDeclarativeGeoMap*>(pmi); if (!map) { QDeclarativeGeoMapItemBase* item = qobject_cast<QDeclarativeGeoMapItemBase*>(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<QDeclarativeGeoMapItemBase*>(pmi)) { - if (drag() && drag()->property("active").toBool()) - qobject_cast<QDeclarativeGeoMapItemBase*>(pmi)->dragStarted(); - else - qobject_cast<QDeclarativeGeoMapItemBase*>(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<QDeclarativeGeoMap*>(pmi)) + if (pmi && qobject_cast<QDeclarativeGeoMap*>(pmi)) { qobject_cast<QDeclarativeGeoMap*>(pmi)->mouseEvent(event); + } else if (dragActive_ && pmi && qobject_cast<QDeclarativeGeoMapItemBase*>(pmi)) { + // position of the item may have changed by the time the activeChanged + // is received, hence update already on mouse release + qobject_cast<QDeclarativeGeoMapItemBase*>(pmi)->dragEnded(); + dragActive_ = false; + } QQuickMouseArea::mouseReleaseEvent(event); } |