diff options
author | Albin Olsson <albin.olsson@cybercom.com> | 2013-08-16 11:04:49 +0200 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2013-08-16 13:26:02 +0200 |
commit | 29af7e577e34089f781322351043de39c025e01e (patch) | |
tree | 789c79159c721569b94494e03275bfe652e84aed /src | |
parent | 2b853429d8b333f8f75fd13f8ce34f6ccf11abb2 (diff) | |
download | qtlocation-29af7e577e34089f781322351043de39c025e01e.tar.gz |
Update to use filtering of child mouse and touch events.
Removing obsolete TOUCH_EVENT_WORKAROUND code and instead implement
use of of childMouseEventFilter inside QDeclarativeGeoMap. This allows
for MapMouseArea to be used together with MapGestureArea with minimal
problems.
Change-Id: I2eeaedc4881688fda4dede663f97fb0a482f14c3
Reviewed-by: Aaron McCarthy <mccarthy.aaron@gmail.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/imports/location/location.pro | 1 | ||||
-rw-r--r-- | src/imports/location/qdeclarativegeomap.cpp | 21 | ||||
-rw-r--r-- | src/imports/location/qdeclarativegeomap_p.h | 2 | ||||
-rw-r--r-- | src/imports/location/qdeclarativegeomapgesturearea.cpp | 51 | ||||
-rw-r--r-- | src/imports/location/qdeclarativegeomapgesturearea_p.h | 6 | ||||
-rw-r--r-- | src/imports/location/qdeclarativegeomapmousearea.cpp | 16 |
6 files changed, 60 insertions, 37 deletions
diff --git a/src/imports/location/location.pro b/src/imports/location/location.pro index d25cd9f4..4c110ddd 100644 --- a/src/imports/location/location.pro +++ b/src/imports/location/location.pro @@ -3,7 +3,6 @@ QT += quick-private network location-private qml-private 3d core-private gui-pri INCLUDEPATH += ../../location INCLUDEPATH += ../../location/maps INCLUDEPATH *= $$PWD -DEFINES += TOUCH_EVENT_WORKAROUND LIBS += -L../../3rdparty/poly2tri -lpoly2tri diff --git a/src/imports/location/qdeclarativegeomap.cpp b/src/imports/location/qdeclarativegeomap.cpp index e2e96179..ffc35933 100644 --- a/src/imports/location/qdeclarativegeomap.cpp +++ b/src/imports/location/qdeclarativegeomap.cpp @@ -204,6 +204,7 @@ QDeclarativeGeoMap::QDeclarativeGeoMap(QQuickItem *parent) setAcceptHoverEvents(false); setAcceptedMouseButtons(Qt::LeftButton | Qt::MidButton | Qt::RightButton); setFlags(QQuickItem::ItemHasContents | QQuickItem::ItemClipsChildrenToShape); + setFiltersChildMouseEvents(true); connect(this, SIGNAL(childrenChanged()), this, SLOT(onMapChildrenChanged()), Qt::QueuedConnection); @@ -888,6 +889,26 @@ void QDeclarativeGeoMap::wheelEvent(QWheelEvent *event) } /*! + \internal +*/ +bool QDeclarativeGeoMap::childMouseEventFilter(QQuickItem *item, QEvent *event) +{ + QLOC_TRACE0; + switch (event->type()) { + case QEvent::MouseButtonPress: + case QEvent::MouseButtonRelease: + case QEvent::MouseMove: + return gestureArea_->filterMapChildMouseEvent(static_cast<QMouseEvent *>(event)); + case QEvent::TouchBegin: + case QEvent::TouchUpdate: + case QEvent::TouchEnd: + return gestureArea_->filterMapChildTouchEvent(static_cast<QTouchEvent *>(event)); + default: + return false; + } +} + +/*! \qmlmethod QtLocation5::Map::addMapItem(MapItem item) Adds the given \a item to the Map (for example MapQuickItem, MapCircle). If the object diff --git a/src/imports/location/qdeclarativegeomap_p.h b/src/imports/location/qdeclarativegeomap_p.h index d939eda4..c69541a7 100644 --- a/src/imports/location/qdeclarativegeomap_p.h +++ b/src/imports/location/qdeclarativegeomap_p.h @@ -174,6 +174,8 @@ protected: void touchEvent(QTouchEvent *event); void wheelEvent(QWheelEvent *event); + bool childMouseEventFilter(QQuickItem *item, QEvent *event); + Q_SIGNALS: void wheelAngleChanged(QPoint angleDelta); void pluginChanged(QDeclarativeGeoServiceProvider *plugin); diff --git a/src/imports/location/qdeclarativegeomapgesturearea.cpp b/src/imports/location/qdeclarativegeomapgesturearea.cpp index e3f76fbd..9ac10aee 100644 --- a/src/imports/location/qdeclarativegeomapgesturearea.cpp +++ b/src/imports/location/qdeclarativegeomapgesturearea.cpp @@ -345,9 +345,6 @@ QDeclarativeGeoMapGestureArea::QDeclarativeGeoMapGestureArea(QDeclarativeGeoMap pan_.maxVelocity_ = QML_MAP_FLICK_DEFAULTMAXVELOCITY; pan_.deceleration_ = QML_MAP_FLICK_DEFAULTDECELERATION; pan_.animation_ = 0; -#if defined(TOUCH_EVENT_WORKAROUND) - mouseBeingUsed_ = true; -#endif touchPointState_ = touchPoints0; pinchState_ = pinchInactive; panState_ = panInactive; @@ -569,10 +566,6 @@ QTouchEvent::TouchPoint makeTouchPointFromMouseEvent(QMouseEvent *event, Qt::Tou */ bool QDeclarativeGeoMapGestureArea::mousePressEvent(QMouseEvent *event) { -#if defined(TOUCH_EVENT_WORKAROUND) - if (!mouseBeingUsed_) - return true; -#endif touchPoints_.clear(); touchPoints_ << makeTouchPointFromMouseEvent(event, Qt::TouchPointPressed); @@ -585,10 +578,6 @@ bool QDeclarativeGeoMapGestureArea::mousePressEvent(QMouseEvent *event) */ bool QDeclarativeGeoMapGestureArea::mouseMoveEvent(QMouseEvent *event) { -#if defined(TOUCH_EVENT_WORKAROUND) - if (!mouseBeingUsed_) - return true; -#endif touchPoints_.clear(); touchPoints_ << makeTouchPointFromMouseEvent(event, Qt::TouchPointMoved); @@ -596,16 +585,11 @@ bool QDeclarativeGeoMapGestureArea::mouseMoveEvent(QMouseEvent *event) return true; } - /*! \internal */ bool QDeclarativeGeoMapGestureArea::mouseReleaseEvent(QMouseEvent *) { -#if defined(TOUCH_EVENT_WORKAROUND) - if (!mouseBeingUsed_) - return true; -#endif touchPoints_.clear(); update(); return true; @@ -616,9 +600,6 @@ bool QDeclarativeGeoMapGestureArea::mouseReleaseEvent(QMouseEvent *) */ void QDeclarativeGeoMapGestureArea::touchEvent(QTouchEvent *event) { -#if defined(TOUCH_EVENT_WORKAROUND) - mouseBeingUsed_ = false; -#endif switch (event->type()) { case QEvent::TouchBegin: case QEvent::TouchUpdate: @@ -643,6 +624,38 @@ void QDeclarativeGeoMapGestureArea::touchEvent(QTouchEvent *event) /*! \internal */ +bool QDeclarativeGeoMapGestureArea::filterMapChildMouseEvent(QMouseEvent *event) +{ + bool used = false; + switch (event->type()) { + case QEvent::MouseButtonPress: + used = mousePressEvent(event); + break; + case QEvent::MouseButtonRelease: + used = mouseReleaseEvent(event); + break; + case QEvent::MouseMove: + used = mouseMoveEvent(event); + break; + default: + used = false; + break; + } + return used && (isPanActive() || isPinchActive()); +} + +/*! + \internal +*/ +bool QDeclarativeGeoMapGestureArea::filterMapChildTouchEvent(QTouchEvent *event) +{ + touchEvent(event); + return isPanActive() || isPinchActive(); +} + +/*! + \internal +*/ void QDeclarativeGeoMapGestureArea::clearTouchData() { velocityX_ = 0; diff --git a/src/imports/location/qdeclarativegeomapgesturearea_p.h b/src/imports/location/qdeclarativegeomapgesturearea_p.h index c8b07da1..6dac15d8 100644 --- a/src/imports/location/qdeclarativegeomapgesturearea_p.h +++ b/src/imports/location/qdeclarativegeomapgesturearea_p.h @@ -166,6 +166,9 @@ public: bool mouseMoveEvent(QMouseEvent *event); bool mouseReleaseEvent(QMouseEvent *event); + bool filterMapChildMouseEvent(QMouseEvent *event); + bool filterMapChildTouchEvent(QTouchEvent *event); + void zoomLevelLimits(qreal min, qreal max); void setMap(QGeoMap *map); @@ -295,9 +298,6 @@ private: qreal distanceBetweenTouchPoints_; QPointF sceneCenter_; -#if defined(TOUCH_EVENT_WORKAROUND) // will be removed when review change 21896 goes into QML core - bool mouseBeingUsed_; -#endif // prototype state machine... enum TouchPointState { diff --git a/src/imports/location/qdeclarativegeomapmousearea.cpp b/src/imports/location/qdeclarativegeomapmousearea.cpp index 6370bd47..51ccaf4d 100644 --- a/src/imports/location/qdeclarativegeomapmousearea.cpp +++ b/src/imports/location/qdeclarativegeomapmousearea.cpp @@ -199,12 +199,8 @@ void QDeclarativeGeoMapMouseArea::componentComplete() */ void QDeclarativeGeoMapMouseArea::mousePressEvent(QMouseEvent *event) { - // map object's flickable may use the event - QQuickItem *pmi = parentMapItem(); - if (pmi && qobject_cast<QDeclarativeGeoMap *>(pmi)) - qobject_cast<QDeclarativeGeoMap *>(pmi)->mouseEvent(event); - // ignore event if it misses non-rectangular geometry (e.g. circle, route) + QQuickItem *pmi = parentMapItem(); bool contains = true; if (pmi && qobject_cast<QDeclarativeGeoMapItemBase *>(pmi)) contains = pmi->contains(event->pos()); @@ -220,12 +216,9 @@ void QDeclarativeGeoMapMouseArea::mousePressEvent(QMouseEvent *event) */ void QDeclarativeGeoMapMouseArea::mouseReleaseEvent(QMouseEvent *event) { - // map object's flickable may use the event QQuickItem *pmi = parentMapItem(); - if (pmi && qobject_cast<QDeclarativeGeoMap *>(pmi)) { - qobject_cast<QDeclarativeGeoMap *>(pmi)->mouseEvent(event); - } else if (dragActive_ && pmi && qobject_cast<QDeclarativeGeoMapItemBase *>(pmi)) { + 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(); @@ -248,11 +241,6 @@ void QDeclarativeGeoMapMouseArea::mouseDoubleClickEvent(QMouseEvent *event) */ void QDeclarativeGeoMapMouseArea::mouseMoveEvent(QMouseEvent *event) { - // map object's flickable may use the event - QQuickItem *pmi = parentMapItem(); - if (pmi && qobject_cast<QDeclarativeGeoMap *>(pmi)) - qobject_cast<QDeclarativeGeoMap *>(pmi)->mouseEvent(event); - QQuickMouseArea::mouseMoveEvent(event); } |