summaryrefslogtreecommitdiffstats
path: root/src/imports/location/qdeclarativegeomapgesturearea.cpp
diff options
context:
space:
mode:
authorAlbin Olsson <albin.olsson@cybercom.com>2013-08-27 17:10:00 +0200
committerThe Qt Project <gerrit-noreply@qt-project.org>2013-08-29 15:40:05 +0200
commitb34bee26c932b9f7579e99d1dca632cb8c47d85f (patch)
tree57aa0765252b7257c22137590676fda528d520e2 /src/imports/location/qdeclarativegeomapgesturearea.cpp
parente09d297894a8b4ff9b06317169b5a9eb97aa7162 (diff)
Improve filtering of touch and mouse events.
When filtering touch events, two different touch points may be received in two different events. This could cause the map to flicker when it interpreted the events has having the same touch point. Solution is to check state and id of touch points in the event. When filtering events, either don't use the event, return true and receive the event again the normal way, or use the event but return false so the child can use it also. This should prevent using the same event twice. In order to support both mouse and touch (by internal touch synthesizing) we must record whether we receive touch events and only accept mouse events if we don't. Change-Id: I90e557b13e23db71d5179f52055965ee23067d36 Reviewed-by: Alex Blasche <alexander.blasche@digia.com>
Diffstat (limited to 'src/imports/location/qdeclarativegeomapgesturearea.cpp')
-rw-r--r--src/imports/location/qdeclarativegeomapgesturearea.cpp74
1 files changed, 59 insertions, 15 deletions
diff --git a/src/imports/location/qdeclarativegeomapgesturearea.cpp b/src/imports/location/qdeclarativegeomapgesturearea.cpp
index 9ac10aee..22eeba07 100644
--- a/src/imports/location/qdeclarativegeomapgesturearea.cpp
+++ b/src/imports/location/qdeclarativegeomapgesturearea.cpp
@@ -338,6 +338,7 @@ QDeclarativeGeoMapGestureArea::QDeclarativeGeoMapGestureArea(QDeclarativeGeoMap
: QObject(parent),
declarativeMap_(map),
enabled_(true),
+ usingTouch_(false),
activeGestures_(ZoomGesture | PanGesture | FlickGesture)
{
map_ = 0;
@@ -348,8 +349,8 @@ QDeclarativeGeoMapGestureArea::QDeclarativeGeoMapGestureArea(QDeclarativeGeoMap
touchPointState_ = touchPoints0;
pinchState_ = pinchInactive;
panState_ = panInactive;
-
}
+
/*!
\internal
*/
@@ -598,27 +599,51 @@ bool QDeclarativeGeoMapGestureArea::mouseReleaseEvent(QMouseEvent *)
/*!
\internal
*/
-void QDeclarativeGeoMapGestureArea::touchEvent(QTouchEvent *event)
+bool QDeclarativeGeoMapGestureArea::touchEvent(QTouchEvent *event)
{
+ usingTouch_ = true;
+
+ if (!(enabled_ && activeGestures_))
+ return false;
+
switch (event->type()) {
case QEvent::TouchBegin:
case QEvent::TouchUpdate:
- touchPoints_.clear();
- for (int i = 0; i < event->touchPoints().count(); ++i) {
- if (!(event->touchPoints().at(i).state() & Qt::TouchPointReleased)) {
- touchPoints_ << event->touchPoints().at(i);
+ foreach (const QTouchEvent::TouchPoint &p, event->touchPoints()) {
+ QList<QTouchEvent::TouchPoint>::iterator i;
+ for (i = touchPoints_.begin(); i != touchPoints_.end(); ++i) {
+ if (i->id() == p.id()) {
+ i = touchPoints_.erase(i);
+ break;
+ }
+ }
+ switch (p.state()) {
+ case Qt::TouchPointPressed:
+ case Qt::TouchPointMoved:
+ case Qt::TouchPointStationary:
+ touchPoints_.insert(i, p);
+ break;
+ case Qt::TouchPointReleased:
+ // already removed
+ break;
+ default:
+ break;
}
}
update();
break;
+
case QEvent::TouchEnd:
touchPoints_.clear();
update();
break;
+
default:
// no-op
break;
}
+
+ return true;
}
/*!
@@ -626,22 +651,31 @@ void QDeclarativeGeoMapGestureArea::touchEvent(QTouchEvent *event)
*/
bool QDeclarativeGeoMapGestureArea::filterMapChildMouseEvent(QMouseEvent *event)
{
- bool used = false;
+ if (usingTouch_)
+ return false;
+
+ if (!(enabled_ && activeGestures_))
+ return false;
+
+ if (isPanActive() || isPinchActive())
+ return true;
+
+ // Don't filter the event, but use it to see if we should start
+ // a gesture.
switch (event->type()) {
case QEvent::MouseButtonPress:
- used = mousePressEvent(event);
+ mousePressEvent(event);
break;
case QEvent::MouseButtonRelease:
- used = mouseReleaseEvent(event);
+ mouseReleaseEvent(event);
break;
case QEvent::MouseMove:
- used = mouseMoveEvent(event);
+ mouseMoveEvent(event);
break;
default:
- used = false;
break;
}
- return used && (isPanActive() || isPinchActive());
+ return false;
}
/*!
@@ -649,8 +683,18 @@ bool QDeclarativeGeoMapGestureArea::filterMapChildMouseEvent(QMouseEvent *event)
*/
bool QDeclarativeGeoMapGestureArea::filterMapChildTouchEvent(QTouchEvent *event)
{
+ usingTouch_ = true;
+
+ if (!(enabled_ && activeGestures_))
+ return false;
+
+ if (event->touchPoints().count() > 1 || isPanActive() || isPinchActive())
+ return true;
+
+ // Don't filter the event, but use it to see if we should start
+ // a gesture.
touchEvent(event);
- return isPanActive() || isPinchActive();
+ return false;
}
/*!
@@ -725,7 +769,7 @@ void QDeclarativeGeoMapGestureArea::touchPointStateMachine()
clearTouchData();
startOneTouchPoint();
touchPointState_ = touchPoints1;
- } else if (touchPoints_.count() == 2) {
+ } else if (touchPoints_.count() >= 2) {
clearTouchData();
startTwoTouchPoints();
touchPointState_ = touchPoints2;
@@ -734,7 +778,7 @@ void QDeclarativeGeoMapGestureArea::touchPointStateMachine()
case touchPoints1:
if (touchPoints_.count() == 0) {
touchPointState_ = touchPoints0;
- } else if (touchPoints_.count() == 2) {
+ } else if (touchPoints_.count() >= 2) {
touchCenterCoord_ = map_->screenPositionToCoordinate(sceneCenter_, false);
startTwoTouchPoints();
touchPointState_ = touchPoints2;