summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--doc/src/frameworks-technologies/gestures.qdoc14
-rw-r--r--examples/gestures/imagegestures/imagewidget.cpp6
-rw-r--r--src/corelib/global/qnamespace.h17
-rw-r--r--src/corelib/global/qnamespace.qdoc36
-rw-r--r--src/gui/graphicsview/qgraphicsitem.cpp6
-rw-r--r--src/gui/graphicsview/qgraphicsitem.h2
-rw-r--r--src/gui/graphicsview/qgraphicsitem_p.h2
-rw-r--r--src/gui/graphicsview/qgraphicsscene.cpp16
-rw-r--r--src/gui/kernel/qapplication.cpp54
-rw-r--r--src/gui/kernel/qapplication.h4
-rw-r--r--src/gui/kernel/qapplication_p.h2
-rw-r--r--src/gui/kernel/qevent.cpp22
-rw-r--r--src/gui/kernel/qevent.h4
-rw-r--r--src/gui/kernel/qgesture.cpp89
-rw-r--r--src/gui/kernel/qgesture.h21
-rw-r--r--src/gui/kernel/qgesture_p.h10
-rw-r--r--src/gui/kernel/qgesturemanager.cpp44
-rw-r--r--src/gui/kernel/qgesturemanager_p.h3
-rw-r--r--src/gui/kernel/qgesturerecognizer.cpp86
-rw-r--r--src/gui/kernel/qgesturerecognizer.h25
-rw-r--r--src/gui/kernel/qstandardgestures.cpp63
-rw-r--r--src/gui/kernel/qstandardgestures_p.h9
-rw-r--r--src/gui/kernel/qwidget.cpp8
-rw-r--r--src/gui/kernel/qwidget.h2
-rw-r--r--src/gui/kernel/qwidget_p.h2
-rw-r--r--src/gui/widgets/qplaintextedit.cpp8
-rw-r--r--tests/auto/gestures/tst_gestures.cpp212
-rw-r--r--tests/manual/gestures/graphicsview/gestures.cpp24
-rw-r--r--tests/manual/gestures/graphicsview/gestures.h8
-rw-r--r--tests/manual/gestures/graphicsview/main.cpp10
-rw-r--r--tests/manual/gestures/graphicsview/mousepangesturerecognizer.cpp25
-rw-r--r--tests/manual/gestures/graphicsview/mousepangesturerecognizer.h4
-rw-r--r--tests/manual/gestures/scrollarea/main.cpp20
-rw-r--r--tests/manual/gestures/scrollarea/mousepangesturerecognizer.cpp25
-rw-r--r--tests/manual/gestures/scrollarea/mousepangesturerecognizer.h4
35 files changed, 441 insertions, 446 deletions
diff --git a/doc/src/frameworks-technologies/gestures.qdoc b/doc/src/frameworks-technologies/gestures.qdoc
index f64e301..2fa8dab 100644
--- a/doc/src/frameworks-technologies/gestures.qdoc
+++ b/doc/src/frameworks-technologies/gestures.qdoc
@@ -122,7 +122,7 @@
\section2 Filtering Input Events
- The \l{QGestureRecognizer::}{filterEvent()} function must be reimplemented.
+ The \l{QGestureRecognizer::}{recognize()} function must be reimplemented.
This function handles and filters the incoming input events for the target objects
and determines whether or not they correspond to the gesture the recognizer is
looking for.
@@ -132,15 +132,15 @@
persistent information about the state of the recognition process in the QGesture
object supplied.
- Your \l{QGestureRecognizer::}{filterEvent()} function must return a value of
- Qt::GestureState that indicates the state of recognition for a given gesture and
+ Your \l{QGestureRecognizer::}{recognize()} function must return a value of
+ QGestureRecognizer::Result that indicates the state of recognition for a given gesture and
target object. This determines whether or not a gesture event will be delivered
to a target object.
\section2 Custom Gestures
If you choose to represent a gesture by a custom QGesture subclass, you will need to
- reimplement the \l{QGestureRecognizer::}{createGesture()} function to construct
+ reimplement the \l{QGestureRecognizer::}{create()} function to construct
instances of your gesture class instead of standard QGesture instances. Alternatively,
you may want to use standard QGesture instances, but add additional dynamic properties
to them to express specific details of the gesture you want to handle.
@@ -152,7 +152,7 @@
\l{QGestureRecognizer::}{reset()} function to perform these special tasks.
Note that QGesture objects are only created once for each combination of target object
- and gesture type, and they are reused every time the user attempts to perform the
+ and gesture type, and they might be reused every time the user attempts to perform the
same gesture type on the target object. As a result, it can be useful to reimplement
the \l{QGestureRecognizer::}{reset()} function to clean up after each previous attempt
at recognizing a gesture.
@@ -162,8 +162,8 @@
To use a gesture recognizer, construct an instance of your QGestureRecognizer
subclass, and register it with the application with
- QApplication::registerGestureRecognizer(). A recognizer for a given type of
- gesture can be removed with QApplication::unregisterGestureRecognizer().
+ QGestureRecognizer::registerRecognizer(). A recognizer for a given type of
+ gesture can be removed with QGestureRecognizer::unregisterRecognizer().
\section1 Further Reading
diff --git a/examples/gestures/imagegestures/imagewidget.cpp b/examples/gestures/imagegestures/imagewidget.cpp
index c798fcc..da9daae 100644
--- a/examples/gestures/imagegestures/imagewidget.cpp
+++ b/examples/gestures/imagegestures/imagewidget.cpp
@@ -132,13 +132,13 @@ void ImageWidget::panTriggered(QPanGesture *gesture)
void ImageWidget::pinchTriggered(QPinchGesture *gesture)
{
- QPinchGesture::WhatChanged whatChanged = gesture->whatChanged();
- if (whatChanged & QPinchGesture::RotationAngleChanged) {
+ QPinchGesture::ChangeFlags changeFlags = gesture->changeFlags();
+ if (changeFlags & QPinchGesture::RotationAngleChanged) {
qreal value = gesture->property("rotationAngle").toReal();
qreal lastValue = gesture->property("lastRotationAngle").toReal();
rotationAngle += value - lastValue;
}
- if (whatChanged & QPinchGesture::ScaleFactorChanged) {
+ if (changeFlags & QPinchGesture::ScaleFactorChanged) {
qreal value = gesture->property("scaleFactor").toReal();
qreal lastValue = gesture->property("lastScaleFactor").toReal();
scaleFactor += value - lastValue;
diff --git a/src/corelib/global/qnamespace.h b/src/corelib/global/qnamespace.h
index 561ffc1..efa6cc7 100644
--- a/src/corelib/global/qnamespace.h
+++ b/src/corelib/global/qnamespace.h
@@ -1715,19 +1715,12 @@ public:
LastGestureType = ~0u
};
- enum GestureContextFlag
+ enum GestureFlag
{
- WidgetGesture = 0,
- WidgetWithChildrenGesture = 3,
-
- ItemGesture = WidgetGesture,
- ItemWithChildrenGesture = WidgetWithChildrenGesture,
-
- GestureContext_Mask = 0x00ff,
- AcceptPartialGesturesHint = 0x0100,
- GestureContextHint_Mask = 0xff00
+ DontStartGestureOnChildren = 0x01,
+ ReceivePartialGestures = 0x02
};
- Q_DECLARE_FLAGS(GestureContext, GestureContextFlag)
+ Q_DECLARE_FLAGS(GestureFlags, GestureFlag)
enum NavigationMode
{
@@ -1762,7 +1755,7 @@ Q_DECLARE_OPERATORS_FOR_FLAGS(Qt::MatchFlags)
Q_DECLARE_OPERATORS_FOR_FLAGS(Qt::TextInteractionFlags)
Q_DECLARE_OPERATORS_FOR_FLAGS(Qt::InputMethodHints)
Q_DECLARE_OPERATORS_FOR_FLAGS(Qt::TouchPointStates)
-Q_DECLARE_OPERATORS_FOR_FLAGS(Qt::GestureContext)
+Q_DECLARE_OPERATORS_FOR_FLAGS(Qt::GestureFlags)
typedef bool (*qInternalCallback)(void **);
diff --git a/src/corelib/global/qnamespace.qdoc b/src/corelib/global/qnamespace.qdoc
index f2a8882..a00a72b 100644
--- a/src/corelib/global/qnamespace.qdoc
+++ b/src/corelib/global/qnamespace.qdoc
@@ -2910,45 +2910,35 @@
\value PanGesture A Pan gesture.
\value PinchGesture A Pinch gesture.
\value SwipeGesture A Swipe gesture.
- \value CustomGesture User-defined gesture ID.
- \value LastGestureType Last user gesture ID.
+ \value CustomGesture A flag that can be used to test if the gesture is a
+ user-defined gesture ID.
+ \omitvalue LastGestureType
User-defined gestures are registered with the
- QApplication::registerGestureRecognizer() function which generates a custom gesture ID
- in the range of values from CustomGesture to LastGestureType.
+ QGestureRecognizer::registerRecognizer() function which generates a custom
+ gesture ID with the Qt::CustomGesture flag set.
\sa QGesture, QWidget::grabGesture(), QGraphicsObject::grabGesture()
*/
/*!
- \enum Qt::GestureContextFlag
+ \enum Qt::GestureFlag
\since 4.6
- This enum type describes the context of a gesture.
+ This enum type describes additional flags that can be used when subscribing
+ to a gesture.
- For a QGesture to trigger, the gesture recognizer should filter events for
- a widget tree. This enum describes for which widget the gesture recognizer
- should filter events:
+ \value DontStartGestureOnChildren By default gestures can start on the
+ widget or over any of its children. Use this flag to disable this and allow
+ a gesture to start on the widget only.
- \value WidgetGesture Gestures can only start over the widget itself.
- \value WidgetWithChildrenGesture Gestures can start on the widget or over
- any of its children.
- \value ItemGesture Gestures can only start over the item itself.
- \value ItemWithChildrenGesture Gestures can start on the item or over
- any of its children.
-
- \value AcceptPartialGesturesHint Allows any ignored gesture events to be
+ \value ReceivePartialGestures Allows any ignored gesture events to be
propagated to parent widgets which have specified this hint. By default
only gestures that are in the Qt::GestureStarted state are propagated and
- the widget only gets the full gesture sequence starting with a gesture in
+ the widget always gets the full gesture sequence starting with a gesture in
the Qt::GestureStarted state and ending with a gesture in the
Qt::GestureFinished or Qt::GestureCanceled states.
- \value GestureContext_Mask A mask for extracting the context type of the
- context flags.
- \value GestureContextHint_Mask A mask for extracting additional hints for
- the context.
-
\sa QWidget::grabGesture(), QGraphicsObject::grabGesture()
*/
diff --git a/src/gui/graphicsview/qgraphicsitem.cpp b/src/gui/graphicsview/qgraphicsitem.cpp
index 58d7e7d..72f08d5 100644
--- a/src/gui/graphicsview/qgraphicsitem.cpp
+++ b/src/gui/graphicsview/qgraphicsitem.cpp
@@ -7320,14 +7320,14 @@ QGraphicsObject::QGraphicsObject(QGraphicsItemPrivate &dd, QGraphicsItem *parent
}
/*!
- Subscribes the graphics object to the given \a gesture for the specified \a context.
+ Subscribes the graphics object to the given \a gesture with specific \a flags.
\sa ungrabGesture(), QGestureEvent
*/
-void QGraphicsObject::grabGesture(Qt::GestureType gesture, Qt::GestureContext context)
+void QGraphicsObject::grabGesture(Qt::GestureType gesture, Qt::GestureFlags flags)
{
QGraphicsItemPrivate * const d = QGraphicsItem::d_func();
- d->gestureContext.insert(gesture, context);
+ d->gestureContext.insert(gesture, flags);
(void)QGestureManager::instance(); // create a gesture manager
}
diff --git a/src/gui/graphicsview/qgraphicsitem.h b/src/gui/graphicsview/qgraphicsitem.h
index fc180f3..f091e34 100644
--- a/src/gui/graphicsview/qgraphicsitem.h
+++ b/src/gui/graphicsview/qgraphicsitem.h
@@ -555,7 +555,7 @@ public:
using QObject::children;
#endif
- void grabGesture(Qt::GestureType type, Qt::GestureContext context = Qt::ItemWithChildrenGesture);
+ void grabGesture(Qt::GestureType type, Qt::GestureFlags flags = Qt::GestureFlags());
void ungrabGesture(Qt::GestureType type);
Q_SIGNALS:
diff --git a/src/gui/graphicsview/qgraphicsitem_p.h b/src/gui/graphicsview/qgraphicsitem_p.h
index 183e95b..90e4631 100644
--- a/src/gui/graphicsview/qgraphicsitem_p.h
+++ b/src/gui/graphicsview/qgraphicsitem_p.h
@@ -453,7 +453,7 @@ public:
QGraphicsItem *focusScopeItem;
Qt::InputMethodHints imHints;
QGraphicsItem::PanelModality panelModality;
- QMap<Qt::GestureType, Qt::GestureContext> gestureContext;
+ QMap<Qt::GestureType, Qt::GestureFlags> gestureContext;
// Packed 32 bits
quint32 acceptedMouseButtons : 5;
diff --git a/src/gui/graphicsview/qgraphicsscene.cpp b/src/gui/graphicsview/qgraphicsscene.cpp
index f5bb408..aed2837 100644
--- a/src/gui/graphicsview/qgraphicsscene.cpp
+++ b/src/gui/graphicsview/qgraphicsscene.cpp
@@ -1060,9 +1060,8 @@ bool QGraphicsScenePrivate::filterEvent(QGraphicsItem *item, QEvent *event)
bool QGraphicsScenePrivate::sendEvent(QGraphicsItem *item, QEvent *event)
{
if (QGraphicsObject *object = item->toGraphicsObject()) {
- QApplicationPrivate *qAppPriv = QApplicationPrivate::instance();
- if (qAppPriv->gestureManager) {
- if (qAppPriv->gestureManager->filterEvent(object, event))
+ if (qt_gestureManager) {
+ if (qt_gestureManager->filterEvent(object, event))
return true;
}
}
@@ -5761,7 +5760,7 @@ void QGraphicsScenePrivate::gestureEventHandler(QGestureEvent *event)
QWidget *viewport = event->widget();
if (!viewport)
return;
- QList<QGesture *> allGestures = event->allGestures();
+ QList<QGesture *> allGestures = event->gestures();
DEBUG() << "QGraphicsScenePrivate::gestureEventHandler:"
<< "Delivering gestures:" << allGestures;
@@ -5900,11 +5899,11 @@ void QGraphicsScenePrivate::gestureEventHandler(QGestureEvent *event)
QGraphicsItemPrivate *gid = item->QGraphicsItem::d_func();
foreach(QGesture *g, alreadyIgnoredGestures) {
- QMap<Qt::GestureType, Qt::GestureContext>::iterator contextit =
+ QMap<Qt::GestureType, Qt::GestureFlags>::iterator contextit =
gid->gestureContext.find(g->gestureType());
bool deliver = contextit != gid->gestureContext.end() &&
(g->state() == Qt::GestureStarted ||
- (contextit.value() & Qt::GestureContextHint_Mask) & Qt::AcceptPartialGesturesHint);
+ (contextit.value() & Qt::ReceivePartialGestures));
if (deliver)
gestures += g;
}
@@ -6046,10 +6045,9 @@ void QGraphicsScenePrivate::cancelGesturesForChildren(QGesture *original, QWidge
}
}
- QGestureManager *gm = QApplicationPrivate::instance()->gestureManager;
- Q_ASSERT(gm); // it would be very odd if we got called without a manager.
+ Q_ASSERT(qt_gestureManager); // it would be very odd if we got called without a manager.
for (setIter = canceledGestures.begin(); setIter != canceledGestures.end(); ++setIter) {
- gm->recycle(*setIter);
+ qt_gestureManager->recycle(*setIter);
gestureTargets.remove(*setIter);
}
}
diff --git a/src/gui/kernel/qapplication.cpp b/src/gui/kernel/qapplication.cpp
index b9e7d52..60ab05a 100644
--- a/src/gui/kernel/qapplication.cpp
+++ b/src/gui/kernel/qapplication.cpp
@@ -154,14 +154,6 @@ bool QApplicationPrivate::autoSipEnabled = false;
bool QApplicationPrivate::autoSipEnabled = true;
#endif
-QGestureManager* QGestureManager::instance()
-{
- QApplicationPrivate *d = qApp->d_func();
- if (!d->gestureManager)
- d->gestureManager = new QGestureManager(qApp);
- return d->gestureManager;
-}
-
QApplicationPrivate::QApplicationPrivate(int &argc, char **argv, QApplication::Type type)
: QCoreApplicationPrivate(argc, argv)
{
@@ -185,7 +177,6 @@ QApplicationPrivate::QApplicationPrivate(int &argc, char **argv, QApplication::T
directPainters = 0;
#endif
- gestureManager = 0;
gestureWidget = 0;
if (!self)
@@ -3632,12 +3623,12 @@ bool QApplication::notify(QObject *receiver, QEvent *e)
}
// walk through parents and check for gestures
- if (d->gestureManager) {
+ if (qt_gestureManager) {
if (receiver->isWidgetType()) {
- if (d->gestureManager->filterEvent(static_cast<QWidget *>(receiver), e))
+ if (qt_gestureManager->filterEvent(static_cast<QWidget *>(receiver), e))
return true;
} else if (QGesture *gesture = qobject_cast<QGesture *>(receiver)) {
- if (d->gestureManager->filterEvent(gesture, e))
+ if (qt_gestureManager->filterEvent(gesture, e))
return true;
}
}
@@ -4150,7 +4141,7 @@ bool QApplication::notify(QObject *receiver, QEvent *e)
if (receiver->isWidgetType()) {
QWidget *w = static_cast<QWidget *>(receiver);
QGestureEvent *gestureEvent = static_cast<QGestureEvent *>(e);
- QList<QGesture *> allGestures = gestureEvent->allGestures();
+ QList<QGesture *> allGestures = gestureEvent->gestures();
bool eventAccepted = gestureEvent->isAccepted();
bool wasAccepted = eventAccepted;
@@ -4161,11 +4152,11 @@ bool QApplication::notify(QObject *receiver, QEvent *e)
for (int i = 0; i < allGestures.size();) {
QGesture *g = allGestures.at(i);
Qt::GestureType type = g->gestureType();
- QMap<Qt::GestureType, Qt::GestureContext>::iterator contextit =
+ QMap<Qt::GestureType, Qt::GestureFlags>::iterator contextit =
wd->gestureContext.find(type);
bool deliver = contextit != wd->gestureContext.end() &&
(g->state() == Qt::GestureStarted || w == receiver ||
- (contextit.value() & Qt::GestureContextHint_Mask) & Qt::AcceptPartialGesturesHint);
+ (contextit.value() & Qt::ReceivePartialGestures));
if (deliver) {
allGestures.removeAt(i);
gestures.append(g);
@@ -5616,39 +5607,6 @@ Q_GUI_EXPORT void qt_translateRawTouchEvent(QWidget *window,
QApplicationPrivate::translateRawTouchEvent(window, deviceType, touchPoints);
}
-/*!
- \since 4.6
-
- Registers the given \a recognizer in the gesture framework and returns a gesture ID
- for it.
-
- The application takes ownership of the \a recognizer and returns the gesture type
- ID associated with it. For gesture recognizers which handle custom QGesture
- objects (i.e., those which return Qt::CustomGesture in a QGesture::gestureType()
- function) the return value is a gesture ID between Qt::CustomGesture and
- Qt::LastGestureType, inclusive.
-
- \sa unregisterGestureRecognizer(), QGestureRecognizer::createGesture(), QGesture
-*/
-Qt::GestureType QApplication::registerGestureRecognizer(QGestureRecognizer *recognizer)
-{
- return QGestureManager::instance()->registerGestureRecognizer(recognizer);
-}
-
-/*!
- \since 4.6
-
- Unregisters all gesture recognizers of the specified \a type.
-
- \sa registerGestureRecognizer()
-*/
-void QApplication::unregisterGestureRecognizer(Qt::GestureType type)
-{
- QApplicationPrivate *d = qApp->d_func();
- if (d->gestureManager)
- d->gestureManager->unregisterGestureRecognizer(type);
-}
-
QT_END_NAMESPACE
#include "moc_qapplication.cpp"
diff --git a/src/gui/kernel/qapplication.h b/src/gui/kernel/qapplication.h
index 5877ba4..e8c1281 100644
--- a/src/gui/kernel/qapplication.h
+++ b/src/gui/kernel/qapplication.h
@@ -86,7 +86,6 @@ class QSymbianEvent;
class QApplication;
class QApplicationPrivate;
-class QGestureRecognizer;
#if defined(qApp)
#undef qApp
#endif
@@ -288,9 +287,6 @@ public:
static Qt::NavigationMode navigationMode();
#endif
- static Qt::GestureType registerGestureRecognizer(QGestureRecognizer *recognizer);
- static void unregisterGestureRecognizer(Qt::GestureType type);
-
Q_SIGNALS:
void lastWindowClosed();
void focusChanged(QWidget *old, QWidget *now);
diff --git a/src/gui/kernel/qapplication_p.h b/src/gui/kernel/qapplication_p.h
index 2c57238..8df4d08 100644
--- a/src/gui/kernel/qapplication_p.h
+++ b/src/gui/kernel/qapplication_p.h
@@ -84,7 +84,6 @@ class QInputContext;
class QObject;
class QWidget;
class QSocketNotifier;
-class QGestureManager;
extern bool qt_is_gui_used;
#ifndef QT_NO_CLIPBOARD
@@ -510,7 +509,6 @@ public:
void sendSyntheticEnterLeave(QWidget *widget);
#endif
- QGestureManager *gestureManager;
QWidget *gestureWidget;
QMap<int, QWidget *> widgetForTouchPointId;
diff --git a/src/gui/kernel/qevent.cpp b/src/gui/kernel/qevent.cpp
index 6757fa2..763b681 100644
--- a/src/gui/kernel/qevent.cpp
+++ b/src/gui/kernel/qevent.cpp
@@ -4202,7 +4202,7 @@ QTouchEvent::TouchPoint &QTouchEvent::TouchPoint::operator=(const QTouchEvent::T
\brief The QGestureEvent class provides the description of triggered gestures.
The QGestureEvent class contains a list of gestures, which can be obtained using the
- allGestures() function.
+ gestures() function.
The gestures are either active or canceled. A list of those that are currently being
executed can be obtained using the activeGestures() function. A list of those which
@@ -4211,10 +4211,11 @@ QTouchEvent::TouchPoint &QTouchEvent::TouchPoint::operator=(const QTouchEvent::T
focus, for example, or because of a timeout, or for other reasons.
If the event handler does not accept the event by calling the generic
- QEvent::accept() function, all individual QGesture object that were not accepted
- will be propagated up the parent widget chain until a widget accepts them
- individually, by calling QGestureEvent::accept() for each of them, or an event
- filter consumes the event.
+ QEvent::accept() function, all individual QGesture object that were not
+ accepted and in the Qt::GestureStarted state will be propagated up the
+ parent widget chain until a widget accepts them individually, by calling
+ QGestureEvent::accept() for each of them, or an event filter consumes the
+ event.
\sa QGesture, QGestureRecognizer,
QWidget::grabGesture(), QGraphicsObject::grabGesture()
@@ -4240,7 +4241,7 @@ QGestureEvent::~QGestureEvent()
/*!
Returns all gestures that are delivered in the event.
*/
-QList<QGesture *> QGestureEvent::allGestures() const
+QList<QGesture *> QGestureEvent::gestures() const
{
return d_func()->gestures;
}
@@ -4417,11 +4418,16 @@ QWidget *QGestureEvent::widget() const
}
/*!
- Returns the scene-local coordinates if the \a gesturePoint is inside a graphics view.
+ Returns the scene-local coordinates if the \a gesturePoint is inside a
+ graphics view.
+
+ This functional might be useful when the gesture event is delivered to a
+ QGraphicsObject to translate a point in screen coordinates to scene-local
+ coordinates.
\sa QPointF::isNull().
*/
-QPointF QGestureEvent::mapToScene(const QPointF &gesturePoint) const
+QPointF QGestureEvent::mapToGraphicsScene(const QPointF &gesturePoint) const
{
QWidget *w = widget();
if (w) // we get the viewport as widget, not the graphics view
diff --git a/src/gui/kernel/qevent.h b/src/gui/kernel/qevent.h
index fb245c0..dfd0f33 100644
--- a/src/gui/kernel/qevent.h
+++ b/src/gui/kernel/qevent.h
@@ -827,7 +827,7 @@ public:
QGestureEvent(const QList<QGesture *> &gestures);
~QGestureEvent();
- QList<QGesture *> allGestures() const;
+ QList<QGesture *> gestures() const;
QGesture *gesture(Qt::GestureType type) const;
QList<QGesture *> activeGestures() const;
@@ -859,7 +859,7 @@ public:
void setWidget(QWidget *widget);
QWidget *widget() const;
- QPointF mapToScene(const QPointF &gesturePoint) const;
+ QPointF mapToGraphicsScene(const QPointF &gesturePoint) const;
private:
QGestureEventPrivate *d_func();
diff --git a/src/gui/kernel/qgesture.cpp b/src/gui/kernel/qgesture.cpp
index df99746..e322af2 100644
--- a/src/gui/kernel/qgesture.cpp
+++ b/src/gui/kernel/qgesture.cpp
@@ -54,7 +54,7 @@ QT_BEGIN_NAMESPACE
Gesture objects are not constructed directly by developers. They are created by
the QGestureRecognizer object that is registered with the application; see
- QApplication::registerGestureRecognizer().
+ QGestureRecognizer::registerRecognizer().
\section1 Gesture Properties
@@ -74,7 +74,7 @@ QT_BEGIN_NAMESPACE
destroy particular instances of them and create new ones to replace them.
The registered gesture recognizer monitors the input events for the target
- object via its \l{QGestureRecognizer::}{filterEvent()} function, updating the
+ object via its \l{QGestureRecognizer::}{recognize()} function, updating the
properties of the gesture object as required.
The gesture object may be delivered to the target object in a QGestureEvent if
@@ -90,7 +90,7 @@ QT_BEGIN_NAMESPACE
Constructs a new gesture object with the given \a parent.
QGesture objects are created by gesture recognizers in the
- QGestureRecognizer::createGesture() function.
+ QGestureRecognizer::create() function.
*/
QGesture::QGesture(QObject *parent)
: QObject(*new QGesturePrivate, parent)
@@ -129,7 +129,7 @@ QGesture::~QGesture()
\brief The point that is used to find the receiver for the gesture event.
The hot-spot is a point in the global coordinate system, use
- QWidget::mapFromGlobal() or QGestureEvent::mapToScene() to get a
+ QWidget::mapFromGlobal() or QGestureEvent::mapToGraphicsScene() to get a
local hot-spot.
The hot-spot should be set by the gesture recognizer to allow gesture event
@@ -180,8 +180,10 @@ void QGesture::unsetHotSpot()
automatically.
\value CancelNone On accepting this gesture no other gestures will be affected.
- \value CancelAllInContext On accepting this gesture all gestures that are active
- in the context (Qt::GestureContext) will be cancelled.
+
+ \value CancelAllInContext On accepting this gesture all gestures that are
+ active in the context (respecting the Qt::GestureFlag that were specified
+ when subscribed to the gesture) will be cancelled.
*/
void QGesture::setGestureCancelPolicy(GestureCancelPolicy policy)
@@ -208,15 +210,6 @@ QGesture::GestureCancelPolicy QGesture::gestureCancelPolicy() const
*/
/*!
- \property QPanGesture::totalOffset
- \brief the total offset from the first input position to the current input
- position
-
- The total offset measures the total change in position of the user's input
- covered by the gesture on the input device.
-*/
-
-/*!
\property QGesture::gestureCancelPolicy
\brief the policy for deciding what happens on accepting a gesture
@@ -241,11 +234,19 @@ QGesture::GestureCancelPolicy QGesture::gestureCancelPolicy() const
/*!
\property QPanGesture::offset
- \brief the offset from the previous input position to the current input
+ \brief the total offset from the first input position to the current input
position
- The offset measures the change in position of the user's input on the
- input device.
+ The offset measures the total change in position of the user's input
+ covered by the gesture on the input device.
+*/
+
+/*!
+ \property QPanGesture::delta
+ \brief the offset from the previous input position to the current input
+
+ This is essentially the same as the difference between offset() and
+ lastOffset().
*/
/*!
@@ -261,10 +262,6 @@ QPanGesture::QPanGesture(QObject *parent)
d_func()->gestureType = Qt::PanGesture;
}
-QPointF QPanGesture::totalOffset() const
-{
- return d_func()->totalOffset;
-}
QPointF QPanGesture::lastOffset() const
{
@@ -276,15 +273,15 @@ QPointF QPanGesture::offset() const
return d_func()->offset;
}
-qreal QPanGesture::acceleration() const
+QPointF QPanGesture::delta() const
{
- return d_func()->acceleration;
+ Q_D(const QPanGesture);
+ return d->offset - d->lastOffset;
}
-
-void QPanGesture::setTotalOffset(const QPointF &value)
+qreal QPanGesture::acceleration() const
{
- d_func()->totalOffset = value;
+ return d_func()->acceleration;
}
void QPanGesture::setLastOffset(const QPointF &value)
@@ -326,7 +323,7 @@ void QPanGesture::setAcceleration(qreal value)
*/
/*!
- \enum QPinchGesture::WhatChange
+ \enum QPinchGesture::ChangeFlag
This enum describes the changes that can occur to the properties of
the gesture object.
@@ -335,19 +332,30 @@ void QPanGesture::setAcceleration(qreal value)
\value RotationAngleChanged The rotation angle held by rotationAngle changed.
\value CenterPointChanged The center point held by centerPoint changed.
- \sa whatChanged
+ \sa changeFlags, totalChangeFlags
+*/
+
+/*!
+ \property QPinchGesture::totalChangeFlags
+ \brief the property of the gesture that has change
+
+ This property indicates which of the other properties has changed since the
+ gesture has started. You can use this information to determine which aspect
+ of your user interface needs to be updated.
+
+ \sa changeFlags, scaleFactor, rotationAngle, centerPoint
*/
/*!
- \property QPinchGesture::whatChanged
- \brief the property of the gesture that has changed
+ \property QPinchGesture::changeFlags
+ \brief the property of the gesture that has changed in the current step
This property indicates which of the other properties has changed since
the previous gesture event included information about this gesture. You
can use this information to determine which aspect of your user interface
needs to be updated.
- \sa scaleFactor, rotationAngle, centerPoint
+ \sa totalChangeFlags, scaleFactor, rotationAngle, centerPoint
*/
/*!
@@ -441,16 +449,25 @@ QPinchGesture::QPinchGesture(QObject *parent)
d_func()->gestureType = Qt::PinchGesture;
}
-QPinchGesture::WhatChanged QPinchGesture::whatChanged() const
+QPinchGesture::ChangeFlags QPinchGesture::totalChangeFlags() const
+{
+ return d_func()->totalChangeFlags;
+}
+
+void QPinchGesture::setTotalChangeFlags(QPinchGesture::ChangeFlags value)
{
- return d_func()->whatChanged;
+ d_func()->totalChangeFlags = value;
}
-void QPinchGesture::setWhatChanged(QPinchGesture::WhatChanged value)
+QPinchGesture::ChangeFlags QPinchGesture::changeFlags() const
{
- d_func()->whatChanged = value;
+ return d_func()->changeFlags;
}
+void QPinchGesture::setChangeFlags(QPinchGesture::ChangeFlags value)
+{
+ d_func()->changeFlags = value;
+}
QPointF QPinchGesture::startCenterPoint() const
{
diff --git a/src/gui/kernel/qgesture.h b/src/gui/kernel/qgesture.h
index 8614ecb..dd322ad 100644
--- a/src/gui/kernel/qgesture.h
+++ b/src/gui/kernel/qgesture.h
@@ -106,20 +106,19 @@ class Q_GUI_EXPORT QPanGesture : public QGesture
Q_OBJECT
Q_DECLARE_PRIVATE(QPanGesture)
- Q_PROPERTY(QPointF totalOffset READ totalOffset WRITE setTotalOffset)
Q_PROPERTY(QPointF lastOffset READ lastOffset WRITE setLastOffset)
Q_PROPERTY(QPointF offset READ offset WRITE setOffset)
+ Q_PROPERTY(QPointF delta READ delta STORED false)
Q_PROPERTY(qreal acceleration READ acceleration WRITE setAcceleration)
public:
QPanGesture(QObject *parent = 0);
- QPointF totalOffset() const;
QPointF lastOffset() const;
QPointF offset() const;
+ QPointF delta() const;
qreal acceleration() const;
- void setTotalOffset(const QPointF &value);
void setLastOffset(const QPointF &value);
void setOffset(const QPointF &value);
void setAcceleration(qreal value);
@@ -135,14 +134,15 @@ class Q_GUI_EXPORT QPinchGesture : public QGesture
Q_DECLARE_PRIVATE(QPinchGesture)
public:
- enum WhatChange {
+ enum ChangeFlag {
ScaleFactorChanged = 0x1,
RotationAngleChanged = 0x2,
CenterPointChanged = 0x4
};
- Q_DECLARE_FLAGS(WhatChanged, WhatChange)
+ Q_DECLARE_FLAGS(ChangeFlags, ChangeFlag)
- Q_PROPERTY(WhatChanged whatChanged READ whatChanged WRITE setWhatChanged)
+ Q_PROPERTY(ChangeFlags totalChangeFlags READ totalChangeFlags WRITE setTotalChangeFlags)
+ Q_PROPERTY(ChangeFlags changeFlags READ changeFlags WRITE setChangeFlags)
Q_PROPERTY(qreal totalScaleFactor READ totalScaleFactor WRITE setTotalScaleFactor)
Q_PROPERTY(qreal lastScaleFactor READ lastScaleFactor WRITE setLastScaleFactor)
@@ -159,8 +159,11 @@ public:
public:
QPinchGesture(QObject *parent = 0);
- WhatChanged whatChanged() const;
- void setWhatChanged(WhatChanged value);
+ ChangeFlags totalChangeFlags() const;
+ void setTotalChangeFlags(ChangeFlags value);
+
+ ChangeFlags changeFlags() const;
+ void setChangeFlags(ChangeFlags value);
QPointF startCenterPoint() const;
QPointF lastCenterPoint() const;
@@ -188,7 +191,7 @@ public:
QT_END_NAMESPACE
-Q_DECLARE_METATYPE(QPinchGesture::WhatChanged)
+Q_DECLARE_METATYPE(QPinchGesture::ChangeFlags)
QT_BEGIN_NAMESPACE
diff --git a/src/gui/kernel/qgesture_p.h b/src/gui/kernel/qgesture_p.h
index 73a6bcf..96fd64d 100644
--- a/src/gui/kernel/qgesture_p.h
+++ b/src/gui/kernel/qgesture_p.h
@@ -90,7 +90,6 @@ public:
{
}
- QPointF totalOffset;
QPointF lastOffset;
QPointF offset;
QPoint lastPosition;
@@ -103,12 +102,15 @@ class QPinchGesturePrivate : public QGesturePrivate
public:
QPinchGesturePrivate()
- : whatChanged(0), totalScaleFactor(0), lastScaleFactor(0), scaleFactor(0),
- totalRotationAngle(0), lastRotationAngle(0), rotationAngle(0)
+ : totalChangeFlags(0), changeFlags(0),
+ totalScaleFactor(0), lastScaleFactor(0), scaleFactor(0),
+ totalRotationAngle(0), lastRotationAngle(0), rotationAngle(0),
+ isNewSequence(true)
{
}
- QPinchGesture::WhatChanged whatChanged;
+ QPinchGesture::ChangeFlags totalChangeFlags;
+ QPinchGesture::ChangeFlags changeFlags;
QPointF startCenterPoint;
QPointF lastCenterPoint;
diff --git a/src/gui/kernel/qgesturemanager.cpp b/src/gui/kernel/qgesturemanager.cpp
index e4a1eb4..d2939f0 100644
--- a/src/gui/kernel/qgesturemanager.cpp
+++ b/src/gui/kernel/qgesturemanager.cpp
@@ -67,6 +67,15 @@
QT_BEGIN_NAMESPACE
+QGestureManager *qt_gestureManager = 0;
+
+QGestureManager* QGestureManager::instance()
+{
+ if (!qt_gestureManager)
+ qt_gestureManager = new QGestureManager(qApp);
+ return qt_gestureManager;
+}
+
QGestureManager::QGestureManager(QObject *parent)
: QObject(parent), state(NotGesture), m_lastCustomGestureId(0)
{
@@ -99,7 +108,7 @@ QGestureManager::~QGestureManager()
Qt::GestureType QGestureManager::registerGestureRecognizer(QGestureRecognizer *recognizer)
{
- QGesture *dummy = recognizer->createGesture(0);
+ QGesture *dummy = recognizer->create(0);
if (!dummy) {
qWarning("QGestureManager::registerGestureRecognizer: "
"the recognizer fails to create a gesture object, skipping registration.");
@@ -179,7 +188,7 @@ QGesture *QGestureManager::getState(QObject *object, QGestureRecognizer *recogni
}
Q_ASSERT(recognizer);
- QGesture *state = recognizer->createGesture(object);
+ QGesture *state = recognizer->create(object);
if (!state)
return 0;
state->setParent(this);
@@ -226,18 +235,19 @@ bool QGestureManager::filterEventThroughContexts(const QMultiHash<QObject *,
QGesture *state = getState(target, recognizer, gestureType);
if (!state)
continue;
- QGestureRecognizer::Result result = recognizer->filterEvent(state, target, event);
+ QGestureRecognizer::Result result = recognizer->recognize(state, target, event);
QGestureRecognizer::Result type = result & QGestureRecognizer::ResultState_Mask;
- if (type == QGestureRecognizer::GestureTriggered) {
+ result &= QGestureRecognizer::ResultHint_Mask;
+ if (type == QGestureRecognizer::TriggerGesture) {
DEBUG() << "QGestureManager:Recognizer: gesture triggered: " << state;
triggeredGestures << state;
- } else if (type == QGestureRecognizer::GestureFinished) {
+ } else if (type == QGestureRecognizer::FinishGesture) {
DEBUG() << "QGestureManager:Recognizer: gesture finished: " << state;
finishedGestures << state;
- } else if (type == QGestureRecognizer::MaybeGesture) {
+ } else if (type == QGestureRecognizer::MayBeGesture) {
DEBUG() << "QGestureManager:Recognizer: maybe gesture: " << state;
newMaybeGestures << state;
- } else if (type == QGestureRecognizer::NotGesture) {
+ } else if (type == QGestureRecognizer::CancelGesture) {
DEBUG() << "QGestureManager:Recognizer: not gesture: " << state;
notGestures << state;
} else if (type == QGestureRecognizer::Ignore) {
@@ -434,7 +444,7 @@ bool QGestureManager::filterEvent(QWidget *receiver, QEvent *event)
QSet<Qt::GestureType> types;
QMultiHash<QObject *, Qt::GestureType> contexts;
QWidget *w = receiver;
- typedef QMap<Qt::GestureType, Qt::GestureContext>::const_iterator ContextIterator;
+ typedef QMap<Qt::GestureType, Qt::GestureFlags>::const_iterator ContextIterator;
if (!w->d_func()->gestureContext.isEmpty()) {
for(ContextIterator it = w->d_func()->gestureContext.begin(),
e = w->d_func()->gestureContext.end(); it != e; ++it) {
@@ -448,7 +458,7 @@ bool QGestureManager::filterEvent(QWidget *receiver, QEvent *event)
{
for (ContextIterator it = w->d_func()->gestureContext.begin(),
e = w->d_func()->gestureContext.end(); it != e; ++it) {
- if ((it.value() & Qt::GestureContext_Mask) == Qt::WidgetWithChildrenGesture) {
+ if (!(it.value() & Qt::DontStartGestureOnChildren)) {
if (!types.contains(it.key())) {
types.insert(it.key());
contexts.insertMulti(w, it.key());
@@ -468,7 +478,7 @@ bool QGestureManager::filterEvent(QGraphicsObject *receiver, QEvent *event)
QMultiHash<QObject *, Qt::GestureType> contexts;
QGraphicsObject *item = receiver;
if (!item->QGraphicsItem::d_func()->gestureContext.isEmpty()) {
- typedef QMap<Qt::GestureType, Qt::GestureContext>::const_iterator ContextIterator;
+ typedef QMap<Qt::GestureType, Qt::GestureFlags>::const_iterator ContextIterator;
for(ContextIterator it = item->QGraphicsItem::d_func()->gestureContext.begin(),
e = item->QGraphicsItem::d_func()->gestureContext.end(); it != e; ++it) {
types.insert(it.key());
@@ -479,10 +489,10 @@ bool QGestureManager::filterEvent(QGraphicsObject *receiver, QEvent *event)
item = item->parentObject();
while (item)
{
- typedef QMap<Qt::GestureType, Qt::GestureContext>::const_iterator ContextIterator;
+ typedef QMap<Qt::GestureType, Qt::GestureFlags>::const_iterator ContextIterator;
for (ContextIterator it = item->QGraphicsItem::d_func()->gestureContext.begin(),
e = item->QGraphicsItem::d_func()->gestureContext.end(); it != e; ++it) {
- if ((it.value() & Qt::GestureContext_Mask) == Qt::ItemWithChildrenGesture) {
+ if (!(it.value() & Qt::DontStartGestureOnChildren)) {
if (!types.contains(it.key())) {
types.insert(it.key());
contexts.insertMulti(item, it.key());
@@ -521,12 +531,12 @@ void QGestureManager::getGestureTargets(const QSet<QGesture*> &gestures,
foreach (QWidget *widget, gestures.keys()) {
QWidget *w = widget->parentWidget();
while (w) {
- QMap<Qt::GestureType, Qt::GestureContext>::const_iterator it
+ QMap<Qt::GestureType, Qt::GestureFlags>::const_iterator it
= w->d_func()->gestureContext.find(type);
if (it != w->d_func()->gestureContext.end()) {
// i.e. 'w' listens to gesture 'type'
- Qt::GestureContext context = it.value() & Qt::GestureContext_Mask;
- if (context == Qt::WidgetWithChildrenGesture && w != widget) {
+ Qt::GestureFlags flags = it.value();
+ if (!(it.value() & Qt::DontStartGestureOnChildren) && w != widget) {
// conflicting gesture!
(*conflicts)[widget].append(gestures[widget]);
break;
@@ -620,7 +630,7 @@ void QGestureManager::deliverEvents(const QSet<QGesture *> &gestures,
QApplication::sendEvent(receiver, &event);
bool eventAccepted = event.isAccepted();
- foreach(QGesture *gesture, event.allGestures()) {
+ foreach(QGesture *gesture, event.gestures()) {
if (eventAccepted || event.isAccepted(gesture)) {
QWidget *w = event.d_func()->targetWidgets.value(gesture->gestureType(), 0);
Q_ASSERT(w);
@@ -646,7 +656,7 @@ void QGestureManager::deliverEvents(const QSet<QGesture *> &gestures,
QGestureEvent event(it.value());
QApplication::sendEvent(it.key(), &event);
bool eventAccepted = event.isAccepted();
- foreach (QGesture *gesture, event.allGestures()) {
+ foreach (QGesture *gesture, event.gestures()) {
if (gesture->state() == Qt::GestureStarted &&
(eventAccepted || event.isAccepted(gesture))) {
QWidget *w = event.d_func()->targetWidgets.value(gesture->gestureType(), 0);
diff --git a/src/gui/kernel/qgesturemanager_p.h b/src/gui/kernel/qgesturemanager_p.h
index d60aedc..27cc8fc 100644
--- a/src/gui/kernel/qgesturemanager_p.h
+++ b/src/gui/kernel/qgesturemanager_p.h
@@ -76,7 +76,6 @@ public:
bool filterEvent(QGesture *receiver, QEvent *event);
bool filterEvent(QGraphicsObject *receiver, QEvent *event);
- // declared in qapplication.cpp
static QGestureManager* instance();
void cleanupCachedGestures(QObject *target, Qt::GestureType type);
@@ -141,6 +140,8 @@ private:
void cancelGesturesForChildren(QGesture *originatingGesture);
};
+extern QGestureManager *qt_gestureManager;
+
QT_END_NAMESPACE
#endif // QGESTUREMANAGER_P_H
diff --git a/src/gui/kernel/qgesturerecognizer.cpp b/src/gui/kernel/qgesturerecognizer.cpp
index 2673be3..ed0bdcc 100644
--- a/src/gui/kernel/qgesturerecognizer.cpp
+++ b/src/gui/kernel/qgesturerecognizer.cpp
@@ -42,6 +42,7 @@
#include "qgesturerecognizer.h"
#include "private/qgesture_p.h"
+#include "private/qgesturemanager_p.h"
QT_BEGIN_NAMESPACE
@@ -65,12 +66,12 @@ QT_BEGIN_NAMESPACE
objects, and modifying the associated QGesture objects to include relevant information
about the user's input.
- Gestures are created when the framework calls createGesture() to handle user input
+ Gestures are created when the framework calls create() to handle user input
for a particular instance of a QWidget or QGraphicsObject subclass. A QGesture object
is created for each widget or item that is configured to use gestures.
Once a QGesture has been created for a target object, the gesture recognizer will
- receive events for it in its filterEvent() handler function.
+ receive events for it in its recognize() handler function.
When a gesture is canceled, the reset() function is called, giving the recognizer the
chance to update the appropriate properties in the corresponding QGesture object.
@@ -79,20 +80,22 @@ QT_BEGIN_NAMESPACE
To add support for new gestures, you need to derive from QGestureRecognizer to create
a custom recognizer class, construct an instance of this class, and register it with
- the application by calling QApplication::registerGestureRecognizer(). You can also
+ the application by calling QGestureRecognizer::registerRecognizer(). You can also
subclass QGesture to create a custom gesture class, or rely on dynamic properties
to express specific details of the gesture you want to handle.
- Your custom QGestureRecognizer subclass needs to reimplement the filterEvent() function
- to handle and filter the incoming input events for QWidget and QGraphicsObject subclasses.
- Although the logic for gesture recognition is implemented in this function, you can
- store persistent information about the state of the recognition process in the QGesture
- object supplied. The filterEvent() function must return a value of Qt::GestureState that
- indicates the state of recognition for a given gesture and target object. This determines
- whether or not a gesture event will be delivered to a target object.
+ Your custom QGestureRecognizer subclass needs to reimplement the recognize()
+ function to handle and filter the incoming input events for QWidget and
+ QGraphicsObject subclasses. Although the logic for gesture recognition is
+ implemented in this function, you can store persistent information about the
+ state of the recognition process in the QGesture object supplied. The
+ recognize() function must return a value of QGestureRecognizer::Result that
+ indicates the state of recognition for a given gesture and target object.
+ This determines whether or not a gesture event will be delivered to a target
+ object.
If you choose to represent a gesture by a custom QGesture subclass, you will need to
- reimplement the createGesture() function to construct instances of your gesture class.
+ reimplement the create() function to construct instances of your gesture class.
Similarly, you may need to reimplement the reset() function if your custom gesture
objects need to be specially handled when a gesture is canceled.
@@ -105,37 +108,37 @@ QT_BEGIN_NAMESPACE
This enum describes the result of the current event filtering step in
a gesture recognizer state machine.
- The result consists of a state value (one of Ignore, NotGesture,
- MaybeGesture, GestureTriggered, GestureFinished) and an optional hint
+ The result consists of a state value (one of Ignore, MayBeGesture,
+ TriggerGesture, FinishGesture, CancelGesture) and an optional hint
(ConsumeEventHint).
\value Ignore The event does not change the state of the recognizer.
- \value NotGesture The event made it clear that it is not a gesture. If the
- gesture recognizer was in GestureTriggered state before, then the gesture
- is canceled and the appropriate QGesture object will be delivered to the
- target as a part of a QGestureEvent.
-
- \value MaybeGesture The event changed the internal state of the recognizer,
+ \value MayBeGesture The event changed the internal state of the recognizer,
but it isn't clear yet if it is a gesture or not. The recognizer needs to
- filter more events to decide. Gesture recognizers in the MaybeGesture state
+ filter more events to decide. Gesture recognizers in the MayBeGesture state
may be reset automatically if they take too long to recognize gestures.
- \value GestureTriggered The gesture has been triggered and the appropriate
+ \value TriggerGesture The gesture has been triggered and the appropriate
QGesture object will be delivered to the target as a part of a
QGestureEvent.
- \value GestureFinished The gesture has been finished successfully and the
+ \value FinishGesture The gesture has been finished successfully and the
appropriate QGesture object will be delivered to the target as a part of a
QGestureEvent.
- \value ConsumeEventHint This hint specifies that the gesture framework should
- consume the filtered event and not deliver it to the receiver.
+ \value CancelGesture The event made it clear that it is not a gesture. If
+ the gesture recognizer was in GestureTriggered state before, then the
+ gesture is canceled and the appropriate QGesture object will be delivered
+ to the target as a part of a QGestureEvent.
+
+ \value ConsumeEventHint This hint specifies that the gesture framework
+ should consume the filtered event and not deliver it to the receiver.
\omitvalue ResultState_Mask
\omitvalue ResultHint_Mask
- \sa QGestureRecognizer::filterEvent()
+ \sa QGestureRecognizer::recognize()
*/
/*!
@@ -159,7 +162,7 @@ QGestureRecognizer::~QGestureRecognizer()
Reimplement this function to create a custom QGesture-derived gesture
object if necessary.
*/
-QGesture *QGestureRecognizer::createGesture(QObject *target)
+QGesture *QGestureRecognizer::create(QObject *target)
{
Q_UNUSED(target);
return new QGesture;
@@ -183,7 +186,7 @@ void QGestureRecognizer::reset(QGesture *gesture)
}
/*!
- \fn QGestureRecognizer::filterEvent(QGesture *gesture, QObject *watched, QEvent *event)
+ \fn QGestureRecognizer::recognize(QGesture *gesture, QObject *watched, QEvent *event)
Handles the given \a event for the \a watched object, updating the state of the \a gesture
object as required, and returns a suitable result for the current recognition step.
@@ -194,7 +197,34 @@ void QGestureRecognizer::reset(QGesture *gesture)
The result reflects how much of the gesture has been recognized. The state of the
\a gesture object is set depending on the result.
- \sa Qt::GestureState
+ \sa QGestureRecognizer::Result
+*/
+
+/*!
+ Registers the given \a recognizer in the gesture framework and returns a gesture ID
+ for it.
+
+ The application takes ownership of the \a recognizer and returns the gesture type
+ ID associated with it. For gesture recognizers which handle custom QGesture
+ objects (i.e., those which return Qt::CustomGesture in a QGesture::gestureType()
+ function) the return value is a generated gesture ID with the Qt::CustomGesture
+ flag set.
+
+ \sa unregisterRecognizer(), QGestureRecognizer::create(), QGesture
*/
+Qt::GestureType QGestureRecognizer::registerRecognizer(QGestureRecognizer *recognizer)
+{
+ return QGestureManager::instance()->registerGestureRecognizer(recognizer);
+}
+
+/*!
+ Unregisters all gesture recognizers of the specified \a type.
+
+ \sa registerRecognizer()
+*/
+void QGestureRecognizer::unregisterRecognizer(Qt::GestureType type)
+{
+ QGestureManager::instance()->unregisterGestureRecognizer(type);
+}
QT_END_NAMESPACE
diff --git a/src/gui/kernel/qgesturerecognizer.h b/src/gui/kernel/qgesturerecognizer.h
index a3c990d..4eebf7c 100644
--- a/src/gui/kernel/qgesturerecognizer.h
+++ b/src/gui/kernel/qgesturerecognizer.h
@@ -43,6 +43,7 @@
#define QGESTURERECOGNIZER_H
#include <QtCore/qglobal.h>
+#include <QtCore/qnamespace.h>
QT_BEGIN_HEADER
@@ -58,30 +59,34 @@ class Q_GUI_EXPORT QGestureRecognizer
public:
enum ResultFlag
{
- Ignore = 0x0001,
- NotGesture = 0x0002,
- MaybeGesture = 0x0004,
- GestureTriggered = 0x0008, // Gesture started or updated
- GestureFinished = 0x0010,
+ Ignore = 0x0001,
- ResultState_Mask = 0x00ff,
+ MayBeGesture = 0x0002,
+ TriggerGesture = 0x0004,
+ FinishGesture = 0x0008,
+ CancelGesture = 0x0010,
+
+ ResultState_Mask = 0x00ff,
ConsumeEventHint = 0x0100,
// StoreEventHint = 0x0200,
// ReplayStoredEventsHint = 0x0400,
// DiscardStoredEventsHint = 0x0800,
- ResultHint_Mask = 0xff00
+ ResultHint_Mask = 0xff00
};
Q_DECLARE_FLAGS(Result, ResultFlag)
QGestureRecognizer();
virtual ~QGestureRecognizer();
- virtual QGesture *createGesture(QObject *target);
- virtual QGestureRecognizer::Result filterEvent(QGesture *state, QObject *watched, QEvent *event) = 0;
-
+ virtual QGesture *create(QObject *target);
+ virtual Result recognize(QGesture *state, QObject *watched,
+ QEvent *event) = 0;
virtual void reset(QGesture *state);
+
+ static Qt::GestureType registerRecognizer(QGestureRecognizer *recognizer);
+ static void unregisterRecognizer(Qt::GestureType type);
};
Q_DECLARE_OPERATORS_FOR_FLAGS(QGestureRecognizer::Result)
diff --git a/src/gui/kernel/qstandardgestures.cpp b/src/gui/kernel/qstandardgestures.cpp
index 57cf12d..ba00a90 100644
--- a/src/gui/kernel/qstandardgestures.cpp
+++ b/src/gui/kernel/qstandardgestures.cpp
@@ -52,7 +52,7 @@ QPanGestureRecognizer::QPanGestureRecognizer()
{
}
-QGesture *QPanGestureRecognizer::createGesture(QObject *target)
+QGesture *QPanGestureRecognizer::create(QObject *target)
{
if (target && target->isWidgetType()) {
#if defined(Q_OS_WIN)
@@ -66,21 +66,21 @@ QGesture *QPanGestureRecognizer::createGesture(QObject *target)
return new QPanGesture;
}
-QGestureRecognizer::Result QPanGestureRecognizer::filterEvent(QGesture *state, QObject *, QEvent *event)
+QGestureRecognizer::Result QPanGestureRecognizer::recognize(QGesture *state, QObject *, QEvent *event)
{
- QPanGesture *q = static_cast<QPanGesture*>(state);
+ QPanGesture *q = static_cast<QPanGesture *>(state);
QPanGesturePrivate *d = q->d_func();
- const QTouchEvent *ev = static_cast<const QTouchEvent*>(event);
+ const QTouchEvent *ev = static_cast<const QTouchEvent *>(event);
QGestureRecognizer::Result result;
switch (event->type()) {
case QEvent::TouchBegin: {
- result = QGestureRecognizer::MaybeGesture;
+ result = QGestureRecognizer::MayBeGesture;
QTouchEvent::TouchPoint p = ev->touchPoints().at(0);
d->lastPosition = p.pos().toPoint();
- d->lastOffset = d->totalOffset = d->offset = QPointF();
+ d->lastOffset = d->offset = QPointF();
break;
}
case QEvent::TouchEnd: {
@@ -90,13 +90,12 @@ QGestureRecognizer::Result QPanGestureRecognizer::filterEvent(QGesture *state, Q
QTouchEvent::TouchPoint p2 = ev->touchPoints().at(1);
d->lastOffset = d->offset;
d->offset =
- QPointF(p1.pos().x() - p1.lastPos().x() + p2.pos().x() - p2.lastPos().x(),
- p1.pos().y() - p1.lastPos().y() + p2.pos().y() - p2.lastPos().y()) / 2;
- d->totalOffset += d->offset;
+ QPointF(p1.pos().x() - p1.startPos().x() + p2.pos().x() - p2.startPos().x(),
+ p1.pos().y() - p1.startPos().y() + p2.pos().y() - p2.startPos().y()) / 2;
}
- result = QGestureRecognizer::GestureFinished;
+ result = QGestureRecognizer::FinishGesture;
} else {
- result = QGestureRecognizer::NotGesture;
+ result = QGestureRecognizer::CancelGesture;
}
break;
}
@@ -106,14 +105,13 @@ QGestureRecognizer::Result QPanGestureRecognizer::filterEvent(QGesture *state, Q
QTouchEvent::TouchPoint p2 = ev->touchPoints().at(1);
d->lastOffset = d->offset;
d->offset =
- QPointF(p1.pos().x() - p1.lastPos().x() + p2.pos().x() - p2.lastPos().x(),
- p1.pos().y() - p1.lastPos().y() + p2.pos().y() - p2.lastPos().y()) / 2;
- d->totalOffset += d->offset;
- if (d->totalOffset.x() > 10 || d->totalOffset.y() > 10 ||
- d->totalOffset.x() < -10 || d->totalOffset.y() < -10) {
- result = QGestureRecognizer::GestureTriggered;
+ QPointF(p1.pos().x() - p1.startPos().x() + p2.pos().x() - p2.startPos().x(),
+ p1.pos().y() - p1.startPos().y() + p2.pos().y() - p2.startPos().y()) / 2;
+ if (d->offset.x() > 10 || d->offset.y() > 10 ||
+ d->offset.x() < -10 || d->offset.y() < -10) {
+ result = QGestureRecognizer::TriggerGesture;
} else {
- result = QGestureRecognizer::MaybeGesture;
+ result = QGestureRecognizer::MayBeGesture;
}
}
break;
@@ -135,7 +133,7 @@ void QPanGestureRecognizer::reset(QGesture *state)
QPanGesture *pan = static_cast<QPanGesture*>(state);
QPanGesturePrivate *d = pan->d_func();
- d->totalOffset = d->lastOffset = d->offset = QPointF();
+ d->lastOffset = d->offset = QPointF();
d->lastPosition = QPoint();
d->acceleration = 0;
@@ -151,7 +149,7 @@ QPinchGestureRecognizer::QPinchGestureRecognizer()
{
}
-QGesture *QPinchGestureRecognizer::createGesture(QObject *target)
+QGesture *QPinchGestureRecognizer::create(QObject *target)
{
if (target && target->isWidgetType()) {
static_cast<QWidget *>(target)->setAttribute(Qt::WA_AcceptTouchEvents);
@@ -159,7 +157,7 @@ QGesture *QPinchGestureRecognizer::createGesture(QObject *target)
return new QPinchGesture;
}
-QGestureRecognizer::Result QPinchGestureRecognizer::filterEvent(QGesture *state, QObject *, QEvent *event)
+QGestureRecognizer::Result QPinchGestureRecognizer::recognize(QGesture *state, QObject *, QEvent *event)
{
QPinchGesture *q = static_cast<QPinchGesture *>(state);
QPinchGesturePrivate *d = q->d_func();
@@ -170,19 +168,19 @@ QGestureRecognizer::Result QPinchGestureRecognizer::filterEvent(QGesture *state,
switch (event->type()) {
case QEvent::TouchBegin: {
- result = QGestureRecognizer::MaybeGesture;
+ result = QGestureRecognizer::MayBeGesture;
break;
}
case QEvent::TouchEnd: {
if (q->state() != Qt::NoGesture) {
- result = QGestureRecognizer::GestureFinished;
+ result = QGestureRecognizer::FinishGesture;
} else {
- result = QGestureRecognizer::NotGesture;
+ result = QGestureRecognizer::CancelGesture;
}
break;
}
case QEvent::TouchUpdate: {
- d->whatChanged = 0;
+ d->changeFlags = 0;
if (ev->touchPoints().size() == 2) {
QTouchEvent::TouchPoint p1 = ev->touchPoints().at(0);
QTouchEvent::TouchPoint p2 = ev->touchPoints().at(1);
@@ -201,7 +199,7 @@ QGestureRecognizer::Result QPinchGestureRecognizer::filterEvent(QGesture *state,
d->lastCenterPoint = d->centerPoint;
d->centerPoint = centerPoint;
- d->whatChanged |= QPinchGesture::CenterPointChanged;
+ d->changeFlags |= QPinchGesture::CenterPointChanged;
const qreal scaleFactor = QLineF(p1.pos(), p2.pos()).length()
/ QLineF(d->startPosition[0], d->startPosition[1]).length();
@@ -212,7 +210,7 @@ QGestureRecognizer::Result QPinchGestureRecognizer::filterEvent(QGesture *state,
}
d->scaleFactor = scaleFactor;
d->totalScaleFactor += d->scaleFactor - d->lastScaleFactor;
- d->whatChanged |= QPinchGesture::ScaleFactorChanged;
+ d->changeFlags |= QPinchGesture::ScaleFactorChanged;
const qreal rotationAngle = -line.angle();
if (d->isNewSequence)
@@ -221,13 +219,14 @@ QGestureRecognizer::Result QPinchGestureRecognizer::filterEvent(QGesture *state,
d->lastRotationAngle = d->rotationAngle;
d->rotationAngle = rotationAngle;
d->totalRotationAngle += d->rotationAngle - d->lastRotationAngle;
- d->whatChanged |= QPinchGesture::RotationAngleChanged;
+ d->changeFlags |= QPinchGesture::RotationAngleChanged;
+ d->totalChangeFlags |= d->changeFlags;
d->isNewSequence = false;
- result = QGestureRecognizer::GestureTriggered;
+ result = QGestureRecognizer::TriggerGesture;
} else {
d->isNewSequence = true;
- result = QGestureRecognizer::MaybeGesture;
+ result = QGestureRecognizer::MayBeGesture;
}
break;
}
@@ -245,10 +244,10 @@ QGestureRecognizer::Result QPinchGestureRecognizer::filterEvent(QGesture *state,
void QPinchGestureRecognizer::reset(QGesture *state)
{
- QPinchGesture *pinch = static_cast<QPinchGesture*>(state);
+ QPinchGesture *pinch = static_cast<QPinchGesture *>(state);
QPinchGesturePrivate *d = pinch->d_func();
- d->whatChanged = 0;
+ d->totalChangeFlags = d->changeFlags = 0;
d->startCenterPoint = d->lastCenterPoint = d->centerPoint = QPointF();
d->totalScaleFactor = d->lastScaleFactor = d->scaleFactor = 0;
diff --git a/src/gui/kernel/qstandardgestures_p.h b/src/gui/kernel/qstandardgestures_p.h
index 827b2a2..e6f346c 100644
--- a/src/gui/kernel/qstandardgestures_p.h
+++ b/src/gui/kernel/qstandardgestures_p.h
@@ -63,9 +63,8 @@ class QPanGestureRecognizer : public QGestureRecognizer
public:
QPanGestureRecognizer();
- QGesture *createGesture(QObject *target);
-
- QGestureRecognizer::Result filterEvent(QGesture *state, QObject *watched, QEvent *event);
+ QGesture *create(QObject *target);
+ QGestureRecognizer::Result recognize(QGesture *state, QObject *watched, QEvent *event);
void reset(QGesture *state);
};
@@ -74,9 +73,9 @@ class QPinchGestureRecognizer : public QGestureRecognizer
public:
QPinchGestureRecognizer();
- QGesture *createGesture(QObject *target);
+ QGesture *create(QObject *target);
- QGestureRecognizer::Result filterEvent(QGesture *state, QObject *watched, QEvent *event);
+ QGestureRecognizer::Result recognize(QGesture *state, QObject *watched, QEvent *event);
void reset(QGesture *state);
};
diff --git a/src/gui/kernel/qwidget.cpp b/src/gui/kernel/qwidget.cpp
index 00d9a99..25284e4 100644
--- a/src/gui/kernel/qwidget.cpp
+++ b/src/gui/kernel/qwidget.cpp
@@ -11711,20 +11711,20 @@ QGraphicsProxyWidget *QWidget::graphicsProxyWidget() const
*/
/*!
- Subscribes the widget to a given \a gesture with a \a context.
+ Subscribes the widget to a given \a gesture with specific \a flags.
\sa ungrabGesture(), QGestureEvent
\since 4.6
*/
-void QWidget::grabGesture(Qt::GestureType gesture, Qt::GestureContext context)
+void QWidget::grabGesture(Qt::GestureType gesture, Qt::GestureFlags flags)
{
Q_D(QWidget);
- d->gestureContext.insert(gesture, context);
+ d->gestureContext.insert(gesture, flags);
(void)QGestureManager::instance(); // create a gesture manager
}
/*!
- Unsubscribes the widget to a given \a gesture type
+ Unsubscribes the widget from a given \a gesture type
\sa grabGesture(), QGestureEvent
\since 4.6
diff --git a/src/gui/kernel/qwidget.h b/src/gui/kernel/qwidget.h
index fce3f09..05f0069 100644
--- a/src/gui/kernel/qwidget.h
+++ b/src/gui/kernel/qwidget.h
@@ -354,7 +354,7 @@ public:
QGraphicsEffect *graphicsEffect() const;
void setGraphicsEffect(QGraphicsEffect *effect);
- void grabGesture(Qt::GestureType type, Qt::GestureContext context = Qt::WidgetWithChildrenGesture);
+ void grabGesture(Qt::GestureType type, Qt::GestureFlags flags = Qt::GestureFlags());
void ungrabGesture(Qt::GestureType type);
public Q_SLOTS:
diff --git a/src/gui/kernel/qwidget_p.h b/src/gui/kernel/qwidget_p.h
index 616a972..dd859a7 100644
--- a/src/gui/kernel/qwidget_p.h
+++ b/src/gui/kernel/qwidget_p.h
@@ -631,7 +631,7 @@ public:
#ifndef QT_NO_ACTION
QList<QAction*> actions;
#endif
- QMap<Qt::GestureType, Qt::GestureContext> gestureContext;
+ QMap<Qt::GestureType, Qt::GestureFlags> gestureContext;
// Bit fields.
uint high_attributes[3]; // the low ones are in QWidget::widget_attributes
diff --git a/src/gui/widgets/qplaintextedit.cpp b/src/gui/widgets/qplaintextedit.cpp
index 0e5ee46..44feaaf 100644
--- a/src/gui/widgets/qplaintextedit.cpp
+++ b/src/gui/widgets/qplaintextedit.cpp
@@ -1458,15 +1458,15 @@ bool QPlainTextEdit::event(QEvent *e)
QScrollBar *vBar = verticalScrollBar();
if (g->state() == Qt::GestureStarted)
d->originalOffsetY = vBar->value();
- QPointF totalOffset = g->totalOffset();
- if (!totalOffset.isNull()) {
+ QPointF offset = g->offset();
+ if (!offset.isNull()) {
if (QApplication::isRightToLeft())
- totalOffset.rx() *= -1;
+ offset.rx() *= -1;
// QPlainTextEdit scrolls by lines only in vertical direction
QFontMetrics fm(document()->defaultFont());
int lineHeight = fm.height();
int newX = hBar->value() - g->lastOffset().x();
- int newY = d->originalOffsetY - totalOffset.y()/lineHeight;
+ int newY = d->originalOffsetY - offset.y()/lineHeight;
hBar->setValue(newX);
vBar->setValue(newY);
}
diff --git a/tests/auto/gestures/tst_gestures.cpp b/tests/auto/gestures/tst_gestures.cpp
index 9b2bc57..20b53f2 100644
--- a/tests/auto/gestures/tst_gestures.cpp
+++ b/tests/auto/gestures/tst_gestures.cpp
@@ -111,12 +111,12 @@ public:
CustomEvent::EventType = QEvent::registerEventType();
}
- QGesture* createGesture(QObject *)
+ QGesture* create(QObject *)
{
return new CustomGesture;
}
- QGestureRecognizer::Result filterEvent(QGesture *state, QObject*o , QEvent *event)
+ QGestureRecognizer::Result recognize(QGesture *state, QObject*, QEvent *event)
{
if (event->type() == CustomEvent::EventType) {
QGestureRecognizer::Result result = 0;
@@ -128,13 +128,13 @@ public:
if (e->hasHotSpot)
g->setHotSpot(e->hotSpot);
if (g->serial >= CustomGesture::SerialFinishedThreshold)
- result |= QGestureRecognizer::GestureFinished;
+ result |= QGestureRecognizer::FinishGesture;
else if (g->serial >= CustomGesture::SerialStartedThreshold)
- result |= QGestureRecognizer::GestureTriggered;
+ result |= QGestureRecognizer::TriggerGesture;
else if (g->serial >= CustomGesture::SerialMaybeThreshold)
- result |= QGestureRecognizer::MaybeGesture;
+ result |= QGestureRecognizer::MayBeGesture;
else
- result = QGestureRecognizer::NotGesture;
+ result = QGestureRecognizer::CancelGesture;
return result;
}
return QGestureRecognizer::Ignore;
@@ -142,7 +142,7 @@ public:
void reset(QGesture *state)
{
- CustomGesture *g = static_cast<CustomGesture*>(state);
+ CustomGesture *g = static_cast<CustomGesture *>(state);
g->serial = 0;
QGestureRecognizer::reset(state);
}
@@ -159,26 +159,26 @@ public:
CustomEvent::EventType = QEvent::registerEventType();
}
- QGesture* createGesture(QObject *)
+ QGesture* create(QObject *)
{
return new CustomGesture;
}
- QGestureRecognizer::Result filterEvent(QGesture *state, QObject*, QEvent *event)
+ QGestureRecognizer::Result recognize(QGesture *state, QObject*, QEvent *event)
{
if (event->type() == CustomEvent::EventType) {
QGestureRecognizer::Result result = QGestureRecognizer::ConsumeEventHint;
- CustomGesture *g = static_cast<CustomGesture*>(state);
- CustomEvent *e = static_cast<CustomEvent*>(event);
+ CustomGesture *g = static_cast<CustomGesture *>(state);
+ CustomEvent *e = static_cast<CustomEvent *>(event);
g->serial = e->serial;
if (e->hasHotSpot)
g->setHotSpot(e->hotSpot);
if (g->serial >= CustomGesture::SerialFinishedThreshold)
- result |= QGestureRecognizer::GestureFinished;
+ result |= QGestureRecognizer::FinishGesture;
else if (g->serial >= CustomGesture::SerialMaybeThreshold)
- result |= QGestureRecognizer::GestureTriggered;
+ result |= QGestureRecognizer::TriggerGesture;
else
- result = QGestureRecognizer::NotGesture;
+ result = QGestureRecognizer::CancelGesture;
return result;
}
return QGestureRecognizer::Ignore;
@@ -186,7 +186,7 @@ public:
void reset(QGesture *state)
{
- CustomGesture *g = static_cast<CustomGesture*>(state);
+ CustomGesture *g = static_cast<CustomGesture *>(state);
g->serial = 0;
QGestureRecognizer::reset(state);
}
@@ -256,7 +256,7 @@ protected:
}
if (eventsPtr) {
QGestureEvent *e = static_cast<QGestureEvent*>(event);
- QList<QGesture*> gestures = e->allGestures();
+ QList<QGesture*> gestures = e->gestures();
foreach(QGesture *g, gestures) {
eventsPtr->all << g->gestureType();
switch(g->state()) {
@@ -345,14 +345,14 @@ tst_Gestures::~tst_Gestures()
void tst_Gestures::initTestCase()
{
- CustomGesture::GestureType = QApplication::registerGestureRecognizer(new CustomGestureRecognizer);
+ CustomGesture::GestureType = QGestureRecognizer::registerRecognizer(new CustomGestureRecognizer);
QVERIFY(CustomGesture::GestureType != Qt::GestureType(0));
QVERIFY(CustomGesture::GestureType != Qt::CustomGesture);
}
void tst_Gestures::cleanupTestCase()
{
- QApplication::unregisterGestureRecognizer(CustomGesture::GestureType);
+ QGestureRecognizer::unregisterRecognizer(CustomGesture::GestureType);
}
void tst_Gestures::init()
@@ -366,7 +366,7 @@ void tst_Gestures::cleanup()
void tst_Gestures::customGesture()
{
GestureWidget widget;
- widget.grabGesture(CustomGesture::GestureType, Qt::WidgetGesture);
+ widget.grabGesture(CustomGesture::GestureType, Qt::DontStartGestureOnChildren);
CustomEvent event;
sendCustomGesture(&event, &widget);
@@ -387,7 +387,7 @@ void tst_Gestures::customGesture()
void tst_Gestures::consumeEventHint()
{
GestureWidget widget;
- widget.grabGesture(CustomGesture::GestureType, Qt::WidgetGesture);
+ widget.grabGesture(CustomGesture::GestureType, Qt::DontStartGestureOnChildren);
CustomGestureRecognizer::ConsumeEvents = true;
CustomEvent event;
@@ -400,7 +400,7 @@ void tst_Gestures::consumeEventHint()
void tst_Gestures::autoCancelingGestures()
{
GestureWidget widget;
- widget.grabGesture(CustomGesture::GestureType, Qt::WidgetGesture);
+ widget.grabGesture(CustomGesture::GestureType, Qt::DontStartGestureOnChildren);
// send partial gesture. The gesture will be in the "maybe" state, but will
// never get enough events to fire, so Qt will have to kill it.
CustomEvent ev;
@@ -424,7 +424,7 @@ void tst_Gestures::gestureOverChild()
GestureWidget *child = new GestureWidget("child");
l->addWidget(child);
- widget.grabGesture(CustomGesture::GestureType, Qt::WidgetGesture);
+ widget.grabGesture(CustomGesture::GestureType, Qt::DontStartGestureOnChildren);
CustomEvent event;
sendCustomGesture(&event, child);
@@ -440,7 +440,7 @@ void tst_Gestures::gestureOverChild()
QCOMPARE(widget.gestureOverrideEventsReceived, 0);
// enable gestures over the children
- widget.grabGesture(CustomGesture::GestureType, Qt::WidgetWithChildrenGesture);
+ widget.grabGesture(CustomGesture::GestureType);
widget.reset();
child->reset();
@@ -469,8 +469,8 @@ void tst_Gestures::multipleWidgetOnlyGestureInTree()
GestureWidget *child = new GestureWidget("child");
l->addWidget(child);
- parent.grabGesture(CustomGesture::GestureType, Qt::WidgetGesture);
- child->grabGesture(CustomGesture::GestureType, Qt::WidgetGesture);
+ parent.grabGesture(CustomGesture::GestureType, Qt::DontStartGestureOnChildren);
+ child->grabGesture(CustomGesture::GestureType, Qt::DontStartGestureOnChildren);
static const int TotalGestureEventsCount = CustomGesture::SerialFinishedThreshold - CustomGesture::SerialStartedThreshold + 1;
static const int TotalCustomEventsCount = CustomGesture::SerialFinishedThreshold - CustomGesture::SerialMaybeThreshold + 1;
@@ -507,8 +507,8 @@ void tst_Gestures::conflictingGestures()
GestureWidget *child = new GestureWidget("child");
l->addWidget(child);
- parent.grabGesture(CustomGesture::GestureType, Qt::WidgetWithChildrenGesture);
- child->grabGesture(CustomGesture::GestureType, Qt::WidgetWithChildrenGesture);
+ parent.grabGesture(CustomGesture::GestureType);
+ child->grabGesture(CustomGesture::GestureType);
static const int TotalGestureEventsCount = CustomGesture::SerialFinishedThreshold - CustomGesture::SerialStartedThreshold + 1;
@@ -579,7 +579,7 @@ void tst_Gestures::conflictingGestures()
child->reset();
// we set an attribute to make sure all gesture events are propagated
- parent.grabGesture(CustomGesture::GestureType, Qt::WidgetWithChildrenGesture | Qt::AcceptPartialGesturesHint);
+ parent.grabGesture(CustomGesture::GestureType, Qt::ReceivePartialGestures);
parent.acceptGestureOverride = false;
child->acceptGestureOverride = false;
parent.ignoredGestures << CustomGesture::GestureType;
@@ -596,7 +596,7 @@ void tst_Gestures::conflictingGestures()
parent.reset();
child->reset();
- Qt::GestureType ContinuousGesture = QApplication::registerGestureRecognizer(new CustomContinuousGestureRecognizer);
+ Qt::GestureType ContinuousGesture = QGestureRecognizer::registerRecognizer(new CustomContinuousGestureRecognizer);
static const int ContinuousGestureEventsCount = CustomGesture::SerialFinishedThreshold - CustomGesture::SerialMaybeThreshold + 1;
child->grabGesture(ContinuousGesture);
// child accepts override. And it also receives another custom gesture.
@@ -610,13 +610,13 @@ void tst_Gestures::conflictingGestures()
QCOMPARE(parent.gestureOverrideEventsReceived, 0);
QCOMPARE(parent.gestureEventsReceived, 0);
- QApplication::unregisterGestureRecognizer(ContinuousGesture);
+ QGestureRecognizer::unregisterRecognizer(ContinuousGesture);
}
void tst_Gestures::finishedWithoutStarted()
{
GestureWidget widget;
- widget.grabGesture(CustomGesture::GestureType, Qt::WidgetGesture);
+ widget.grabGesture(CustomGesture::GestureType, Qt::DontStartGestureOnChildren);
// the gesture will claim it finished, but it was never started.
CustomEvent ev;
@@ -636,9 +636,9 @@ void tst_Gestures::finishedWithoutStarted()
void tst_Gestures::unknownGesture()
{
GestureWidget widget;
- widget.grabGesture(CustomGesture::GestureType, Qt::WidgetGesture);
- widget.grabGesture(Qt::CustomGesture, Qt::WidgetGesture);
- widget.grabGesture(Qt::GestureType(Qt::PanGesture+512), Qt::WidgetGesture);
+ widget.grabGesture(CustomGesture::GestureType, Qt::DontStartGestureOnChildren);
+ widget.grabGesture(Qt::CustomGesture, Qt::DontStartGestureOnChildren);
+ widget.grabGesture(Qt::GestureType(Qt::PanGesture+512), Qt::DontStartGestureOnChildren);
CustomEvent event;
sendCustomGesture(&event, &widget);
@@ -740,7 +740,7 @@ protected:
}
if (eventsPtr) {
QGestureEvent *e = static_cast<QGestureEvent*>(event);
- QList<QGesture*> gestures = e->allGestures();
+ QList<QGesture*> gestures = e->gestures();
foreach(QGesture *g, gestures) {
eventsPtr->all << g->gestureType();
switch(g->state()) {
@@ -784,7 +784,7 @@ void tst_Gestures::graphicsItemGesture()
QTest::qWaitForWindowShown(&view);
view.ensureVisible(scene.sceneRect());
- view.viewport()->grabGesture(CustomGesture::GestureType, Qt::WidgetGesture);
+ view.viewport()->grabGesture(CustomGesture::GestureType, Qt::DontStartGestureOnChildren);
item->grabGesture(CustomGesture::GestureType);
static const int TotalGestureEventsCount = CustomGesture::SerialFinishedThreshold - CustomGesture::SerialStartedThreshold + 1;
@@ -858,7 +858,7 @@ void tst_Gestures::graphicsItemTreeGesture()
QTest::qWaitForWindowShown(&view);
view.ensureVisible(scene.sceneRect());
- view.viewport()->grabGesture(CustomGesture::GestureType, Qt::WidgetGesture);
+ view.viewport()->grabGesture(CustomGesture::GestureType, Qt::DontStartGestureOnChildren);
item1->grabGesture(CustomGesture::GestureType);
static const int TotalGestureEventsCount = CustomGesture::SerialFinishedThreshold - CustomGesture::SerialStartedThreshold + 1;
@@ -916,10 +916,10 @@ void tst_Gestures::explicitGraphicsObjectTarget()
QTest::qWaitForWindowShown(&view);
view.ensureVisible(scene.sceneRect());
- view.viewport()->grabGesture(CustomGesture::GestureType, Qt::WidgetGesture);
- item1->grabGesture(CustomGesture::GestureType, Qt::ItemGesture);
- item2->grabGesture(CustomGesture::GestureType, Qt::ItemGesture);
- item2_child1->grabGesture(CustomGesture::GestureType, Qt::ItemGesture);
+ view.viewport()->grabGesture(CustomGesture::GestureType, Qt::DontStartGestureOnChildren);
+ item1->grabGesture(CustomGesture::GestureType, Qt::DontStartGestureOnChildren);
+ item2->grabGesture(CustomGesture::GestureType, Qt::DontStartGestureOnChildren);
+ item2_child1->grabGesture(CustomGesture::GestureType, Qt::DontStartGestureOnChildren);
static const int TotalGestureEventsCount = CustomGesture::SerialFinishedThreshold - CustomGesture::SerialStartedThreshold + 1;
@@ -976,7 +976,7 @@ void tst_Gestures::gestureOverChildGraphicsItem()
QTest::qWaitForWindowShown(&view);
view.ensureVisible(scene.sceneRect());
- view.viewport()->grabGesture(CustomGesture::GestureType, Qt::WidgetGesture);
+ view.viewport()->grabGesture(CustomGesture::GestureType, Qt::DontStartGestureOnChildren);
item1->grabGesture(CustomGesture::GestureType);
static const int TotalGestureEventsCount = CustomGesture::SerialFinishedThreshold - CustomGesture::SerialStartedThreshold + 1;
@@ -1030,7 +1030,7 @@ void tst_Gestures::gestureOverChildGraphicsItem()
item2->grabGesture(CustomGesture::GestureType);
item2->ignoredGestures << CustomGesture::GestureType;
item1->ignoredGestures << CustomGesture::GestureType;
- item1->grabGesture(CustomGesture::GestureType, Qt::WidgetWithChildrenGesture | Qt::AcceptPartialGesturesHint);
+ item1->grabGesture(CustomGesture::GestureType, Qt::ReceivePartialGestures);
event.hotSpot = mapToGlobal(QPointF(10, 10), item2_child1, &view);
event.hasHotSpot = true;
@@ -1051,10 +1051,10 @@ void tst_Gestures::twoGesturesOnDifferentLevel()
GestureWidget *child = new GestureWidget("child");
l->addWidget(child);
- Qt::GestureType SecondGesture = QApplication::registerGestureRecognizer(new CustomGestureRecognizer);
+ Qt::GestureType SecondGesture = QGestureRecognizer::registerRecognizer(new CustomGestureRecognizer);
- parent.grabGesture(CustomGesture::GestureType, Qt::WidgetWithChildrenGesture);
- child->grabGesture(SecondGesture, Qt::WidgetWithChildrenGesture);
+ parent.grabGesture(CustomGesture::GestureType);
+ child->grabGesture(SecondGesture);
CustomEvent event;
// sending events that form a gesture to one widget, but they will be
@@ -1079,7 +1079,7 @@ void tst_Gestures::twoGesturesOnDifferentLevel()
for(int i = 0; i < child->events.all.size(); ++i)
QCOMPARE(parent.events.all.at(i), CustomGesture::GestureType);
- QApplication::unregisterGestureRecognizer(SecondGesture);
+ QGestureRecognizer::unregisterRecognizer(SecondGesture);
}
void tst_Gestures::multipleGesturesInTree()
@@ -1091,19 +1091,19 @@ void tst_Gestures::multipleGesturesInTree()
GestureWidget *D = new GestureWidget("D", C);
Qt::GestureType FirstGesture = CustomGesture::GestureType;
- Qt::GestureType SecondGesture = QApplication::registerGestureRecognizer(new CustomGestureRecognizer);
- Qt::GestureType ThirdGesture = QApplication::registerGestureRecognizer(new CustomGestureRecognizer);
-
- Qt::GestureContext context = Qt::WidgetWithChildrenGesture | Qt::AcceptPartialGesturesHint;
- A->grabGesture(FirstGesture, context); // A [1 3]
- A->grabGesture(ThirdGesture, context); // |
- B->grabGesture(SecondGesture, context); // B [ 2 3]
- B->grabGesture(ThirdGesture, context); // |
- C->grabGesture(FirstGesture, context); // C [1 2 3]
- C->grabGesture(SecondGesture, context); // |
- C->grabGesture(ThirdGesture, context); // D [1 3]
- D->grabGesture(FirstGesture, context);
- D->grabGesture(ThirdGesture, context);
+ Qt::GestureType SecondGesture = QGestureRecognizer::registerRecognizer(new CustomGestureRecognizer);
+ Qt::GestureType ThirdGesture = QGestureRecognizer::registerRecognizer(new CustomGestureRecognizer);
+
+ Qt::GestureFlags flags = Qt::ReceivePartialGestures;
+ A->grabGesture(FirstGesture, flags); // A [1 3]
+ A->grabGesture(ThirdGesture, flags); // |
+ B->grabGesture(SecondGesture, flags); // B [ 2 3]
+ B->grabGesture(ThirdGesture, flags); // |
+ C->grabGesture(FirstGesture, flags); // C [1 2 3]
+ C->grabGesture(SecondGesture, flags); // |
+ C->grabGesture(ThirdGesture, flags); // D [1 3]
+ D->grabGesture(FirstGesture, flags);
+ D->grabGesture(ThirdGesture, flags);
// make sure all widgets ignore events, so they get propagated.
A->ignoredGestures << FirstGesture << ThirdGesture;
@@ -1150,8 +1150,8 @@ void tst_Gestures::multipleGesturesInTree()
QCOMPARE(A->events.all.count(SecondGesture), 0);
QCOMPARE(A->events.all.count(ThirdGesture), TotalGestureEventsCount);
- QApplication::unregisterGestureRecognizer(SecondGesture);
- QApplication::unregisterGestureRecognizer(ThirdGesture);
+ QGestureRecognizer::unregisterRecognizer(SecondGesture);
+ QGestureRecognizer::unregisterRecognizer(ThirdGesture);
}
void tst_Gestures::multipleGesturesInComplexTree()
@@ -1163,27 +1163,27 @@ void tst_Gestures::multipleGesturesInComplexTree()
GestureWidget *D = new GestureWidget("D", C);
Qt::GestureType FirstGesture = CustomGesture::GestureType;
- Qt::GestureType SecondGesture = QApplication::registerGestureRecognizer(new CustomGestureRecognizer);
- Qt::GestureType ThirdGesture = QApplication::registerGestureRecognizer(new CustomGestureRecognizer);
- Qt::GestureType FourthGesture = QApplication::registerGestureRecognizer(new CustomGestureRecognizer);
- Qt::GestureType FifthGesture = QApplication::registerGestureRecognizer(new CustomGestureRecognizer);
- Qt::GestureType SixthGesture = QApplication::registerGestureRecognizer(new CustomGestureRecognizer);
- Qt::GestureType SeventhGesture = QApplication::registerGestureRecognizer(new CustomGestureRecognizer);
-
- Qt::GestureContext context = Qt::WidgetWithChildrenGesture | Qt::AcceptPartialGesturesHint;
- A->grabGesture(FirstGesture, context); // A [1,3,4]
- A->grabGesture(ThirdGesture, context); // |
- A->grabGesture(FourthGesture, context); // B [2,3,5]
- B->grabGesture(SecondGesture, context); // |
- B->grabGesture(ThirdGesture, context); // C [1,2,3,6]
- B->grabGesture(FifthGesture, context); // |
- C->grabGesture(FirstGesture, context); // D [1,3,7]
- C->grabGesture(SecondGesture, context);
- C->grabGesture(ThirdGesture, context);
- C->grabGesture(SixthGesture, context);
- D->grabGesture(FirstGesture, context);
- D->grabGesture(ThirdGesture, context);
- D->grabGesture(SeventhGesture, context);
+ Qt::GestureType SecondGesture = QGestureRecognizer::registerRecognizer(new CustomGestureRecognizer);
+ Qt::GestureType ThirdGesture = QGestureRecognizer::registerRecognizer(new CustomGestureRecognizer);
+ Qt::GestureType FourthGesture = QGestureRecognizer::registerRecognizer(new CustomGestureRecognizer);
+ Qt::GestureType FifthGesture = QGestureRecognizer::registerRecognizer(new CustomGestureRecognizer);
+ Qt::GestureType SixthGesture = QGestureRecognizer::registerRecognizer(new CustomGestureRecognizer);
+ Qt::GestureType SeventhGesture = QGestureRecognizer::registerRecognizer(new CustomGestureRecognizer);
+
+ Qt::GestureFlags flags = Qt::ReceivePartialGestures;
+ A->grabGesture(FirstGesture, flags); // A [1,3,4]
+ A->grabGesture(ThirdGesture, flags); // |
+ A->grabGesture(FourthGesture, flags); // B [2,3,5]
+ B->grabGesture(SecondGesture, flags); // |
+ B->grabGesture(ThirdGesture, flags); // C [1,2,3,6]
+ B->grabGesture(FifthGesture, flags); // |
+ C->grabGesture(FirstGesture, flags); // D [1,3,7]
+ C->grabGesture(SecondGesture, flags);
+ C->grabGesture(ThirdGesture, flags);
+ C->grabGesture(SixthGesture, flags);
+ D->grabGesture(FirstGesture, flags);
+ D->grabGesture(ThirdGesture, flags);
+ D->grabGesture(SeventhGesture, flags);
// make sure all widgets ignore events, so they get propagated.
QSet<Qt::GestureType> allGestureTypes;
@@ -1247,12 +1247,12 @@ void tst_Gestures::multipleGesturesInComplexTree()
QCOMPARE(A->events.all.count(SixthGesture), 0);
QCOMPARE(A->events.all.count(SeventhGesture), 0);
- QApplication::unregisterGestureRecognizer(SecondGesture);
- QApplication::unregisterGestureRecognizer(ThirdGesture);
- QApplication::unregisterGestureRecognizer(FourthGesture);
- QApplication::unregisterGestureRecognizer(FifthGesture);
- QApplication::unregisterGestureRecognizer(SixthGesture);
- QApplication::unregisterGestureRecognizer(SeventhGesture);
+ QGestureRecognizer::unregisterRecognizer(SecondGesture);
+ QGestureRecognizer::unregisterRecognizer(ThirdGesture);
+ QGestureRecognizer::unregisterRecognizer(FourthGesture);
+ QGestureRecognizer::unregisterRecognizer(FifthGesture);
+ QGestureRecognizer::unregisterRecognizer(SixthGesture);
+ QGestureRecognizer::unregisterRecognizer(SeventhGesture);
}
void tst_Gestures::testMapToScene()
@@ -1261,7 +1261,7 @@ void tst_Gestures::testMapToScene()
QList<QGesture*> list;
list << &gesture;
QGestureEvent event(list);
- QCOMPARE(event.mapToScene(gesture.hotSpot()), QPointF()); // not set, can't do much
+ QCOMPARE(event.mapToGraphicsScene(gesture.hotSpot()), QPointF()); // not set, can't do much
QGraphicsScene scene;
QGraphicsView view(&scene);
@@ -1278,7 +1278,7 @@ void tst_Gestures::testMapToScene()
QPoint origin = view.mapToGlobal(QPoint());
event.setWidget(view.viewport());
- QCOMPARE(event.mapToScene(origin + QPoint(100, 200)), view.mapToScene(QPoint(100, 200)));
+ QCOMPARE(event.mapToGraphicsScene(origin + QPoint(100, 200)), view.mapToScene(QPoint(100, 200)));
}
void tst_Gestures::ungrabGesture() // a method on QWidget
@@ -1296,7 +1296,7 @@ void tst_Gestures::ungrabGesture() // a method on QWidget
if (event->type() == QEvent::Gesture) {
QGestureEvent *gestureEvent = static_cast<QGestureEvent*>(event);
if (gestureEvent)
- foreach (QGesture *g, gestureEvent->allGestures())
+ foreach (QGesture *g, gestureEvent->gestures())
gestures.insert(g);
}
return GestureWidget::event(event);
@@ -1307,8 +1307,8 @@ void tst_Gestures::ungrabGesture() // a method on QWidget
MockGestureWidget *a = &parent;
MockGestureWidget *b = new MockGestureWidget("B", a);
- a->grabGesture(CustomGesture::GestureType, Qt::WidgetGesture);
- b->grabGesture(CustomGesture::GestureType, Qt::WidgetWithChildrenGesture);
+ a->grabGesture(CustomGesture::GestureType, Qt::DontStartGestureOnChildren);
+ b->grabGesture(CustomGesture::GestureType);
b->ignoredGestures << CustomGesture::GestureType;
CustomEvent event;
@@ -1375,14 +1375,14 @@ void tst_Gestures::autoCancelGestures()
{
if (event->type() == QEvent::Gesture) {
QGestureEvent *ge = static_cast<QGestureEvent*>(event);
- Q_ASSERT(ge->allGestures().count() == 1); // can't use QCOMPARE here...
- ge->allGestures().first()->setGestureCancelPolicy(QGesture::CancelAllInContext);
+ Q_ASSERT(ge->gestures().count() == 1); // can't use QCOMPARE here...
+ ge->gestures().first()->setGestureCancelPolicy(QGesture::CancelAllInContext);
}
return GestureWidget::event(event);
}
};
- const Qt::GestureType secondGesture = QApplication::registerGestureRecognizer(new CustomGestureRecognizer);
+ const Qt::GestureType secondGesture = QGestureRecognizer::registerRecognizer(new CustomGestureRecognizer);
MockWidget parent("parent"); // this one sets the cancel policy to CancelAllInContext
parent.resize(300, 100);
@@ -1390,8 +1390,8 @@ void tst_Gestures::autoCancelGestures()
GestureWidget *child = new GestureWidget("child", &parent);
child->setGeometry(10, 10, 100, 80);
- parent.grabGesture(CustomGesture::GestureType, Qt::WidgetWithChildrenGesture);
- child->grabGesture(secondGesture, Qt::WidgetWithChildrenGesture);
+ parent.grabGesture(CustomGesture::GestureType);
+ child->grabGesture(secondGesture);
parent.show();
QTest::qWaitForWindowShown(&parent);
@@ -1425,14 +1425,14 @@ void tst_Gestures::autoCancelGestures2()
bool event(QEvent *event) {
if (event->type() == QEvent::Gesture) {
QGestureEvent *ge = static_cast<QGestureEvent*>(event);
- Q_ASSERT(ge->allGestures().count() == 1); // can't use QCOMPARE here...
- ge->allGestures().first()->setGestureCancelPolicy(QGesture::CancelAllInContext);
+ Q_ASSERT(ge->gestures().count() == 1); // can't use QCOMPARE here...
+ ge->gestures().first()->setGestureCancelPolicy(QGesture::CancelAllInContext);
}
return GestureItem::event(event);
}
};
- const Qt::GestureType secondGesture = QApplication::registerGestureRecognizer(new CustomGestureRecognizer);
+ const Qt::GestureType secondGesture = QGestureRecognizer ::registerRecognizer(new CustomGestureRecognizer);
QGraphicsScene scene;
QGraphicsView view(&scene);
@@ -1444,10 +1444,10 @@ void tst_Gestures::autoCancelGestures2()
parent->setPos(0, 0);
child->setPos(10, 10);
scene.addItem(parent);
- view.viewport()->grabGesture(CustomGesture::GestureType, Qt::WidgetGesture);
- view.viewport()->grabGesture(secondGesture, Qt::WidgetGesture);
- parent->grabGesture(CustomGesture::GestureType, Qt::WidgetWithChildrenGesture);
- child->grabGesture(secondGesture, Qt::WidgetWithChildrenGesture);
+ view.viewport()->grabGesture(CustomGesture::GestureType, Qt::DontStartGestureOnChildren);
+ view.viewport()->grabGesture(secondGesture, Qt::DontStartGestureOnChildren);
+ parent->grabGesture(CustomGesture::GestureType);
+ child->grabGesture(secondGesture);
view.show();
QTest::qWaitForWindowShown(&view);
diff --git a/tests/manual/gestures/graphicsview/gestures.cpp b/tests/manual/gestures/graphicsview/gestures.cpp
index 5416457..4c21712 100644
--- a/tests/manual/gestures/graphicsview/gestures.cpp
+++ b/tests/manual/gestures/graphicsview/gestures.cpp
@@ -45,41 +45,41 @@
Qt::GestureType ThreeFingerSlideGesture::Type = Qt::CustomGesture;
-QGesture *ThreeFingerSlideGestureRecognizer::createGesture(QObject *)
+QGesture *ThreeFingerSlideGestureRecognizer::create(QObject *)
{
return new ThreeFingerSlideGesture;
}
-QGestureRecognizer::Result ThreeFingerSlideGestureRecognizer::filterEvent(QGesture *state, QObject *, QEvent *event)
+QGestureRecognizer::Result ThreeFingerSlideGestureRecognizer::recognize(QGesture *state, QObject *, QEvent *event)
{
ThreeFingerSlideGesture *d = static_cast<ThreeFingerSlideGesture *>(state);
QGestureRecognizer::Result result;
switch (event->type()) {
case QEvent::TouchBegin:
- result = QGestureRecognizer::MaybeGesture;
+ result = QGestureRecognizer::MayBeGesture;
case QEvent::TouchEnd:
if (d->gestureFired)
- result = QGestureRecognizer::GestureFinished;
+ result = QGestureRecognizer::FinishGesture;
else
- result = QGestureRecognizer::NotGesture;
+ result = QGestureRecognizer::CancelGesture;
case QEvent::TouchUpdate:
if (d->state() != Qt::NoGesture) {
QTouchEvent *ev = static_cast<QTouchEvent*>(event);
if (ev->touchPoints().size() == 3) {
d->gestureFired = true;
- result = QGestureRecognizer::GestureTriggered;
+ result = QGestureRecognizer::TriggerGesture;
} else {
- result = QGestureRecognizer::MaybeGesture;
+ result = QGestureRecognizer::MayBeGesture;
for (int i = 0; i < ev->touchPoints().size(); ++i) {
const QTouchEvent::TouchPoint &pt = ev->touchPoints().at(i);
const int distance = (pt.pos().toPoint() - pt.startPos().toPoint()).manhattanLength();
if (distance > 20) {
- result = QGestureRecognizer::NotGesture;
+ result = QGestureRecognizer::CancelGesture;
}
}
}
} else {
- result = QGestureRecognizer::NotGesture;
+ result = QGestureRecognizer::CancelGesture;
}
break;
@@ -89,7 +89,7 @@ QGestureRecognizer::Result ThreeFingerSlideGestureRecognizer::filterEvent(QGestu
if (d->state() != Qt::NoGesture)
result = QGestureRecognizer::Ignore;
else
- result = QGestureRecognizer::NotGesture;
+ result = QGestureRecognizer::CancelGesture;
break;
default:
result = QGestureRecognizer::Ignore;
@@ -105,12 +105,12 @@ void ThreeFingerSlideGestureRecognizer::reset(QGesture *state)
}
-QGesture *RotateGestureRecognizer::createGesture(QObject *)
+QGesture *RotateGestureRecognizer::create(QObject *)
{
return new QGesture;
}
-QGestureRecognizer::Result RotateGestureRecognizer::filterEvent(QGesture *, QObject *, QEvent *event)
+QGestureRecognizer::Result RotateGestureRecognizer::recognize(QGesture *, QObject *, QEvent *event)
{
switch (event->type()) {
case QEvent::TouchBegin:
diff --git a/tests/manual/gestures/graphicsview/gestures.h b/tests/manual/gestures/graphicsview/gestures.h
index 6140b12..8a31b71 100644
--- a/tests/manual/gestures/graphicsview/gestures.h
+++ b/tests/manual/gestures/graphicsview/gestures.h
@@ -59,8 +59,8 @@ public:
class ThreeFingerSlideGestureRecognizer : public QGestureRecognizer
{
private:
- QGesture* createGesture(QObject *target);
- QGestureRecognizer::Result filterEvent(QGesture *state, QObject *watched, QEvent *event);
+ QGesture *create(QObject *target);
+ QGestureRecognizer::Result recognize(QGesture *state, QObject *watched, QEvent *event);
void reset(QGesture *state);
};
@@ -70,8 +70,8 @@ public:
RotateGestureRecognizer();
private:
- QGesture* createGesture(QObject *target);
- QGestureRecognizer::Result filterEvent(QGesture *state, QObject *watched, QEvent *event);
+ QGesture *create(QObject *target);
+ QGestureRecognizer::Result recognize(QGesture *state, QObject *watched, QEvent *event);
void reset(QGesture *state);
};
diff --git a/tests/manual/gestures/graphicsview/main.cpp b/tests/manual/gestures/graphicsview/main.cpp
index de92afe..f8433b5 100644
--- a/tests/manual/gestures/graphicsview/main.cpp
+++ b/tests/manual/gestures/graphicsview/main.cpp
@@ -66,11 +66,11 @@ protected:
default: qDebug("view: Pan: <unknown state>"); break;
}
- const QPointF offset = pan->offset();
+ const QPointF delta = pan->delta();
QScrollBar *vbar = verticalScrollBar();
QScrollBar *hbar = horizontalScrollBar();
- vbar->setValue(vbar->value() - offset.y());
- hbar->setValue(hbar->value() - offset.x());
+ vbar->setValue(vbar->value() - delta.y());
+ hbar->setValue(hbar->value() - delta.x());
ge->accept(pan);
return true;
}
@@ -152,8 +152,8 @@ private:
MainWindow::MainWindow()
{
- (void)QApplication::registerGestureRecognizer(new MousePanGestureRecognizer);
- ThreeFingerSlideGesture::Type = QApplication::registerGestureRecognizer(new ThreeFingerSlideGestureRecognizer);
+ (void)QGestureRecognizer::registerRecognizer(new MousePanGestureRecognizer);
+ ThreeFingerSlideGesture::Type = QGestureRecognizer::registerRecognizer(new ThreeFingerSlideGestureRecognizer);
tabWidget = new QTabWidget;
diff --git a/tests/manual/gestures/graphicsview/mousepangesturerecognizer.cpp b/tests/manual/gestures/graphicsview/mousepangesturerecognizer.cpp
index 6cdbe12..82adfbd 100644
--- a/tests/manual/gestures/graphicsview/mousepangesturerecognizer.cpp
+++ b/tests/manual/gestures/graphicsview/mousepangesturerecognizer.cpp
@@ -51,12 +51,12 @@ MousePanGestureRecognizer::MousePanGestureRecognizer()
{
}
-QGesture* MousePanGestureRecognizer::createGesture(QObject *)
+QGesture* MousePanGestureRecognizer::create(QObject *)
{
return new QPanGesture;
}
-QGestureRecognizer::Result MousePanGestureRecognizer::filterEvent(QGesture *state, QObject *, QEvent *event)
+QGestureRecognizer::Result MousePanGestureRecognizer::recognize(QGesture *state, QObject *, QEvent *event)
{
QPanGesture *g = static_cast<QPanGesture *>(state);
QPoint globalPos;
@@ -78,23 +78,19 @@ QGestureRecognizer::Result MousePanGestureRecognizer::filterEvent(QGesture *stat
if (event->type() == QEvent::MouseButtonPress || event->type() == QEvent::MouseButtonDblClick
|| event->type() == QEvent::GraphicsSceneMousePress || event->type() == QEvent::GraphicsSceneMouseDoubleClick) {
g->setHotSpot(globalPos);
- g->setProperty("lastPos", globalPos);
+ g->setProperty("startPos", globalPos);
g->setProperty("pressed", QVariant::fromValue<bool>(true));
- return QGestureRecognizer::GestureTriggered | QGestureRecognizer::ConsumeEventHint;
+ return QGestureRecognizer::TriggerGesture | QGestureRecognizer::ConsumeEventHint;
} else if (event->type() == QEvent::MouseMove || event->type() == QEvent::GraphicsSceneMouseMove) {
if (g->property("pressed").toBool()) {
- QPoint pos = globalPos;
- QPoint lastPos = g->property("lastPos").toPoint();
+ QPoint offset = globalPos - g->property("startPos").toPoint();
g->setLastOffset(g->offset());
- lastPos = pos - lastPos;
- g->setOffset(QPointF(lastPos.x(), lastPos.y()));
- g->setTotalOffset(g->totalOffset() + QPointF(lastPos.x(), lastPos.y()));
- g->setProperty("lastPos", pos);
- return QGestureRecognizer::GestureTriggered | QGestureRecognizer::ConsumeEventHint;
+ g->setOffset(QPointF(offset.x(), offset.y()));
+ return QGestureRecognizer::TriggerGesture | QGestureRecognizer::ConsumeEventHint;
}
- return QGestureRecognizer::NotGesture;
+ return QGestureRecognizer::CancelGesture;
} else if (event->type() == QEvent::MouseButtonRelease || event->type() == QEvent::GraphicsSceneMouseRelease) {
- return QGestureRecognizer::GestureFinished | QGestureRecognizer::ConsumeEventHint;
+ return QGestureRecognizer::FinishGesture | QGestureRecognizer::ConsumeEventHint;
}
return QGestureRecognizer::Ignore;
}
@@ -102,11 +98,10 @@ QGestureRecognizer::Result MousePanGestureRecognizer::filterEvent(QGesture *stat
void MousePanGestureRecognizer::reset(QGesture *state)
{
QPanGesture *g = static_cast<QPanGesture *>(state);
- g->setTotalOffset(QPointF());
g->setLastOffset(QPointF());
g->setOffset(QPointF());
g->setAcceleration(0);
- g->setProperty("lastPos", QVariant());
+ g->setProperty("startPos", QVariant());
g->setProperty("pressed", QVariant::fromValue<bool>(false));
QGestureRecognizer::reset(state);
}
diff --git a/tests/manual/gestures/graphicsview/mousepangesturerecognizer.h b/tests/manual/gestures/graphicsview/mousepangesturerecognizer.h
index b062fd0..6e04621 100644
--- a/tests/manual/gestures/graphicsview/mousepangesturerecognizer.h
+++ b/tests/manual/gestures/graphicsview/mousepangesturerecognizer.h
@@ -49,8 +49,8 @@ class MousePanGestureRecognizer : public QGestureRecognizer
public:
MousePanGestureRecognizer();
- QGesture* createGesture(QObject *target);
- QGestureRecognizer::Result filterEvent(QGesture *state, QObject *watched, QEvent *event);
+ QGesture* create(QObject *target);
+ QGestureRecognizer::Result recognize(QGesture *state, QObject *watched, QEvent *event);
void reset(QGesture *state);
};
diff --git a/tests/manual/gestures/scrollarea/main.cpp b/tests/manual/gestures/scrollarea/main.cpp
index 9a5eb02..4f33b28 100644
--- a/tests/manual/gestures/scrollarea/main.cpp
+++ b/tests/manual/gestures/scrollarea/main.cpp
@@ -50,7 +50,7 @@ public:
ScrollArea(QWidget *parent = 0)
: QScrollArea(parent), outside(false)
{
- viewport()->grabGesture(Qt::PanGesture);
+ viewport()->grabGesture(Qt::PanGesture, Qt::ReceivePartialGestures);
}
protected:
@@ -87,8 +87,8 @@ protected:
if (outside)
return;
- const QPointF offset = pan->offset();
- const QPointF totalOffset = pan->totalOffset();
+ const QPointF delta = pan->delta();
+ const QPointF totalOffset = pan->offset();
QScrollBar *vbar = verticalScrollBar();
QScrollBar *hbar = horizontalScrollBar();
@@ -102,8 +102,8 @@ protected:
outside = true;
return;
}
- vbar->setValue(vbar->value() - offset.y());
- hbar->setValue(hbar->value() - offset.x());
+ vbar->setValue(vbar->value() - delta.y());
+ hbar->setValue(hbar->value() - delta.x());
event->accept(pan);
}
}
@@ -147,8 +147,8 @@ protected:
event->ignore(pan);
if (outside)
return;
- const QPointF offset = pan->offset();
- const QPointF totalOffset = pan->totalOffset();
+ const QPointF delta = pan->delta();
+ const QPointF totalOffset = pan->offset();
if (orientation() == Qt::Horizontal) {
if ((value() == minimum() && totalOffset.x() < -10) ||
(value() == maximum() && totalOffset.x() > 10)) {
@@ -156,7 +156,7 @@ protected:
return;
}
if (totalOffset.y() < 40 && totalOffset.y() > -40) {
- setValue(value() + offset.x());
+ setValue(value() + delta.x());
event->accept(pan);
} else {
outside = true;
@@ -168,7 +168,7 @@ protected:
return;
}
if (totalOffset.x() < 40 && totalOffset.x() > -40) {
- setValue(value() - offset.y());
+ setValue(value() - delta.y());
event->accept(pan);
} else {
outside = true;
@@ -232,7 +232,7 @@ private:
int main(int argc, char **argv)
{
QApplication app(argc, argv);
- app.registerGestureRecognizer(new MousePanGestureRecognizer);
+ QGestureRecognizer::registerRecognizer(new MousePanGestureRecognizer);
MainWindow w;
w.show();
return app.exec();
diff --git a/tests/manual/gestures/scrollarea/mousepangesturerecognizer.cpp b/tests/manual/gestures/scrollarea/mousepangesturerecognizer.cpp
index ce5ef57..66fcf18 100644
--- a/tests/manual/gestures/scrollarea/mousepangesturerecognizer.cpp
+++ b/tests/manual/gestures/scrollarea/mousepangesturerecognizer.cpp
@@ -49,12 +49,12 @@ MousePanGestureRecognizer::MousePanGestureRecognizer()
{
}
-QGesture* MousePanGestureRecognizer::createGesture(QObject *)
+QGesture *MousePanGestureRecognizer::create(QObject *)
{
return new QPanGesture;
}
-QGestureRecognizer::Result MousePanGestureRecognizer::filterEvent(QGesture *state, QObject *, QEvent *event)
+QGestureRecognizer::Result MousePanGestureRecognizer::recognize(QGesture *state, QObject *, QEvent *event)
{
QPanGesture *g = static_cast<QPanGesture *>(state);
if (event->type() == QEvent::TouchBegin) {
@@ -68,24 +68,20 @@ QGestureRecognizer::Result MousePanGestureRecognizer::filterEvent(QGesture *stat
if (g->property("ignoreMousePress").toBool())
return QGestureRecognizer::Ignore;
g->setHotSpot(me->globalPos());
- g->setProperty("lastPos", me->globalPos());
+ g->setProperty("startPos", me->globalPos());
g->setProperty("pressed", QVariant::fromValue<bool>(true));
- return QGestureRecognizer::GestureTriggered | QGestureRecognizer::ConsumeEventHint;
+ return QGestureRecognizer::TriggerGesture | QGestureRecognizer::ConsumeEventHint;
} else if (event->type() == QEvent::MouseMove) {
if (g->property("pressed").toBool()) {
- QPoint pos = me->globalPos();
- QPoint lastPos = g->property("lastPos").toPoint();
+ QPoint offset = me->globalPos() - g->property("startPos").toPoint();
g->setLastOffset(g->offset());
- lastPos = pos - lastPos;
- g->setOffset(QPointF(lastPos.x(), lastPos.y()));
- g->setTotalOffset(g->totalOffset() + QPointF(lastPos.x(), lastPos.y()));
- g->setProperty("lastPos", pos);
- return QGestureRecognizer::GestureTriggered | QGestureRecognizer::ConsumeEventHint;
+ g->setOffset(QPointF(offset.x(), offset.y()));
+ return QGestureRecognizer::TriggerGesture | QGestureRecognizer::ConsumeEventHint;
}
- return QGestureRecognizer::NotGesture;
+ return QGestureRecognizer::CancelGesture;
} else if (event->type() == QEvent::MouseButtonRelease) {
if (g->property("pressed").toBool())
- return QGestureRecognizer::GestureFinished | QGestureRecognizer::ConsumeEventHint;
+ return QGestureRecognizer::FinishGesture | QGestureRecognizer::ConsumeEventHint;
}
return QGestureRecognizer::Ignore;
}
@@ -93,11 +89,10 @@ QGestureRecognizer::Result MousePanGestureRecognizer::filterEvent(QGesture *stat
void MousePanGestureRecognizer::reset(QGesture *state)
{
QPanGesture *g = static_cast<QPanGesture *>(state);
- g->setTotalOffset(QPointF());
g->setLastOffset(QPointF());
g->setOffset(QPointF());
g->setAcceleration(0);
- g->setProperty("lastPos", QVariant());
+ g->setProperty("startPos", QVariant());
g->setProperty("pressed", QVariant::fromValue<bool>(false));
g->setProperty("ignoreMousePress", QVariant::fromValue<bool>(false));
QGestureRecognizer::reset(state);
diff --git a/tests/manual/gestures/scrollarea/mousepangesturerecognizer.h b/tests/manual/gestures/scrollarea/mousepangesturerecognizer.h
index b062fd0..6e04621 100644
--- a/tests/manual/gestures/scrollarea/mousepangesturerecognizer.h
+++ b/tests/manual/gestures/scrollarea/mousepangesturerecognizer.h
@@ -49,8 +49,8 @@ class MousePanGestureRecognizer : public QGestureRecognizer
public:
MousePanGestureRecognizer();
- QGesture* createGesture(QObject *target);
- QGestureRecognizer::Result filterEvent(QGesture *state, QObject *watched, QEvent *event);
+ QGesture* create(QObject *target);
+ QGestureRecognizer::Result recognize(QGesture *state, QObject *watched, QEvent *event);
void reset(QGesture *state);
};