diff options
Diffstat (limited to 'src/gui')
-rw-r--r-- | src/gui/graphicsview/qgraphicsitem.cpp | 6 | ||||
-rw-r--r-- | src/gui/graphicsview/qgraphicsitem.h | 2 | ||||
-rw-r--r-- | src/gui/graphicsview/qgraphicsitem_p.h | 2 | ||||
-rw-r--r-- | src/gui/graphicsview/qgraphicsscene.cpp | 16 | ||||
-rw-r--r-- | src/gui/kernel/qapplication.cpp | 54 | ||||
-rw-r--r-- | src/gui/kernel/qapplication.h | 4 | ||||
-rw-r--r-- | src/gui/kernel/qapplication_p.h | 2 | ||||
-rw-r--r-- | src/gui/kernel/qevent.cpp | 22 | ||||
-rw-r--r-- | src/gui/kernel/qevent.h | 4 | ||||
-rw-r--r-- | src/gui/kernel/qgesture.cpp | 89 | ||||
-rw-r--r-- | src/gui/kernel/qgesture.h | 21 | ||||
-rw-r--r-- | src/gui/kernel/qgesture_p.h | 10 | ||||
-rw-r--r-- | src/gui/kernel/qgesturemanager.cpp | 44 | ||||
-rw-r--r-- | src/gui/kernel/qgesturemanager_p.h | 3 | ||||
-rw-r--r-- | src/gui/kernel/qgesturerecognizer.cpp | 86 | ||||
-rw-r--r-- | src/gui/kernel/qgesturerecognizer.h | 25 | ||||
-rw-r--r-- | src/gui/kernel/qstandardgestures.cpp | 63 | ||||
-rw-r--r-- | src/gui/kernel/qstandardgestures_p.h | 9 | ||||
-rw-r--r-- | src/gui/kernel/qwidget.cpp | 8 | ||||
-rw-r--r-- | src/gui/kernel/qwidget.h | 2 | ||||
-rw-r--r-- | src/gui/kernel/qwidget_p.h | 2 | ||||
-rw-r--r-- | src/gui/widgets/qplaintextedit.cpp | 8 |
22 files changed, 252 insertions, 230 deletions
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); } |