Fix TapAndHoldGesture (others) for QWidgets

After the migration to QPA, touch events usually have a QWindow as a receiver,
unlike Qt4 where receivers were QWidgets. This broke QGestureManager and
gestures such as the TapAndHoldGesture, because
QGestureManager::filterEvent(QWidget *, QEvent *) was never called. Since the
receivers are now of QWindow type, QGestureManager::filterEvent(QObject *,
QEvent *) gets called instead, always returning false. This has several side
effects, one of them was causing the TapAndHold gesture to time out, because
it never got a TouchEnd event (and thus it thought that the touch was still
going on, even though it was not). This patch ensures that if a gesture event is
meant to be delivered to a QWidget, the right event filter method is called.

Change-Id: I1df5f763fe6c4d8db0058adbd17d23d70b4988fe
Reviewed-by: Zeno Albisser <zeno.albisser@digia.com>
Reviewed-by: Andy Shaw <andy.shaw@digia.com>
Reviewed-by: Sean Harmer <sean.harmer@kdab.com>
Reviewed-by: Paul Olav Tvete <paul.tvete@digia.com>
Reviewed-by: Shawn Rutledge <shawn.rutledge@digia.com>
Reviewed-by: Denis Dzyubenko <denis@ddenis.info>
This commit is contained in:
Rafael Roquetto 2012-11-05 21:18:02 -02:00 committed by The Qt Project
parent d2e5c7787e
commit 602ea84f44

View File

@ -46,6 +46,7 @@
#include "private/qgraphicsitem_p.h"
#include "private/qevent_p.h"
#include "private/qapplication_p.h"
#include "private/qwidgetwindow_qpa_p.h"
#include "qgesture.h"
#include "qevent.h"
#include "qgraphicsitem.h"
@ -531,6 +532,13 @@ bool QGestureManager::filterEvent(QGraphicsObject *receiver, QEvent *event)
bool QGestureManager::filterEvent(QObject *receiver, QEvent *event)
{
// if the receiver is actually a widget, we need to call the correct event
// filter method.
QWidgetWindow *widgetWindow = qobject_cast<QWidgetWindow *>(receiver);
if (widgetWindow)
return filterEvent(widgetWindow->widget(), event);
if (!m_gestureToRecognizer.contains(static_cast<QGesture *>(receiver)))
return false;
QGesture *state = static_cast<QGesture *>(receiver);