42 #include "private/qgesturemanager_p.h" 43 #include "private/qstandardgestures_p.h" 44 #include "private/qwidget_p.h" 45 #include "private/qgesture_p.h" 46 #include "private/qgraphicsitem_p.h" 47 #include "private/qevent_p.h" 48 #include "private/qapplication_p.h" 56 #if defined(Q_OS_WIN) && !defined(QT_NO_NATIVE_GESTURES) 64 # define DEBUG if (0) qDebug 69 #ifndef QT_NO_GESTURES 76 qRegisterMetaType<Qt::GestureState>();
81 #if defined(QT_MAC_USE_COCOA) 91 #if !defined(QT_NO_NATIVE_GESTURES) 114 qWarning(
"QGestureManager::registerGestureRecognizer: " 115 "the recognizer fails to create a gesture object, skipping registration.");
148 if (objectGesture.
gesture == type) {
165 if (objectGesture.
gesture == type && target == objectGesture.
object) {
169 it.value() -= gestures;
195 if (static_cast<QWidget *>(
object)->d_func()->data.in_destructor)
197 }
else if (
QGesture *g = qobject_cast<QGesture *>(
object)) {
199 #ifndef QT_NO_GRAPHICSVIEW 201 Q_ASSERT(qobject_cast<QGraphicsObject *>(
object));
203 if (graphicsObject->QGraphicsItem::d_func()->inDestructor)
223 #if defined(GESTURE_DEBUG) 246 bool consumeEventHint =
false;
250 ContextIterator contextEnd = contexts.end();
251 for (ContextIterator context = contexts.begin(); context != contextEnd; ++context) {
256 for (; typeToRecognizerIterator != typeToRecognizerEnd; ++typeToRecognizerIterator) {
258 QObject *target = context.key();
262 QGestureRecognizer::Result recognizerResult = recognizer->
recognize(state, target, event);
266 DEBUG() <<
"QGestureManager:Recognizer: gesture triggered: " <<
state;
267 triggeredGestures <<
state;
269 DEBUG() <<
"QGestureManager:Recognizer: gesture finished: " <<
state;
270 finishedGestures <<
state;
272 DEBUG() <<
"QGestureManager:Recognizer: maybe gesture: " <<
state;
273 newMaybeGestures <<
state;
275 DEBUG() <<
"QGestureManager:Recognizer: not gesture: " <<
state;
276 notGestures <<
state;
278 DEBUG() <<
"QGestureManager:Recognizer: ignored the event: " <<
state;
280 DEBUG() <<
"QGestureManager:Recognizer: hm, lets assume the recognizer" 281 <<
"ignored the event: " <<
state;
284 DEBUG() <<
"QGestureManager: we were asked to consume the event: " 286 consumeEventHint =
true;
296 QSet<QGesture *> activeToMaybeGestures = m_activeGestures & newMaybeGestures;
310 | finishedGestures | canceledGestures
325 foreach (
QGesture *gesture, notStarted)
329 finishedGestures -= undeliveredGestures;
332 m_activeGestures += startedGestures;
334 Q_ASSERT((m_activeGestures & triggeredGestures).size() == triggeredGestures.size());
335 m_activeGestures -= finishedGestures;
336 m_activeGestures -= activeToMaybeGestures;
337 m_activeGestures -= canceledGestures;
340 foreach (
QGesture *gesture, startedGestures)
342 foreach (
QGesture *gesture, triggeredGestures)
344 foreach (
QGesture *gesture, finishedGestures)
346 foreach (
QGesture *gesture, canceledGestures)
348 foreach (
QGesture *gesture, activeToMaybeGestures)
352 !startedGestures.
isEmpty() || !triggeredGestures.isEmpty() ||
353 !finishedGestures.isEmpty() || !canceledGestures.isEmpty()) {
354 DEBUG() <<
"QGestureManager::filterEventThroughContexts:" 355 <<
"\n\tactiveGestures:" << m_activeGestures
357 <<
"\n\tstarted:" << startedGestures
358 <<
"\n\ttriggered:" << triggeredGestures
359 <<
"\n\tfinished:" << finishedGestures
360 <<
"\n\tcanceled:" << canceledGestures
361 <<
"\n\tmaybe-canceled:" << maybeToCanceledGestures;
365 deliverEvents(startedGestures+triggeredGestures+finishedGestures+canceledGestures,
366 &undeliveredGestures);
368 foreach (
QGesture *g, startedGestures) {
369 if (undeliveredGestures.
contains(g))
372 DEBUG() <<
"lets try to cancel some";
378 m_activeGestures -= undeliveredGestures;
382 finishedGestures + canceledGestures + undeliveredGestures + maybeToCanceledGestures;
383 foreach (
QGesture *gesture, endedGestures) {
392 return consumeEventHint;
411 if (widget != originatingWidget && originatingWidget->
isAncestorOf(widget)) {
412 DEBUG() <<
" found a gesture to cancel" << (*iter);
414 cancelledGestures << *iter;
425 while (!almostCanceledGestures.
isEmpty()) {
428 iter = almostCanceledGestures.
begin();
430 while (iter != almostCanceledGestures.
end()) {
434 if (target == widget) {
436 iter = almostCanceledGestures.
erase(iter);
447 for (iter = cancelledGestures.
begin(); iter != cancelledGestures.
end(); ++iter)
472 if (!w->d_func()->gestureContext.isEmpty()) {
473 for(ContextIterator
it = w->d_func()->gestureContext.begin(),
474 e = w->d_func()->gestureContext.end();
it != e; ++
it) {
483 for (ContextIterator
it = w->d_func()->gestureContext.begin(),
484 e = w->d_func()->gestureContext.end();
it != e; ++
it) {
499 #ifndef QT_NO_GRAPHICSVIEW 505 if (!item->QGraphicsItem::d_func()->gestureContext.isEmpty()) {
507 for(ContextIterator
it = item->QGraphicsItem::d_func()->gestureContext.begin(),
508 e = item->QGraphicsItem::d_func()->gestureContext.end();
it != e; ++
it) {
518 for (ContextIterator
it = item->QGraphicsItem::d_func()->gestureContext.begin(),
519 e = item->QGraphicsItem::d_func()->gestureContext.end();
it != e; ++
it) {
548 GestureByTypes gestureByTypes;
551 foreach (
QGesture *gesture, gestures) {
554 gestureByTypes[gesture->
gestureType()].insert(receiver, gesture);
564 = w->d_func()->gestureContext.
find(type);
565 if (it != w->d_func()->gestureContext.end()) {
569 (*conflicts)[
widget].append(gestures[widget]);
580 (*normal)[
widget].append(gestures[widget]);
592 GesturesPerWidget conflictedGestures;
593 GesturesPerWidget normalStartedGestures;
598 e = gestures.
end();
it != e; ++
it) {
609 target = child ? child : topLevel;
615 target = static_cast<QWidget *>(context);
627 startedGestures.
insert(gesture);
629 normalStartedGestures[target].append(gesture);
632 DEBUG() <<
"QGestureManager::deliverEvent: could not find the target for gesture" 634 qWarning(
"QGestureManager::deliverEvent: could not find the target for gesture");
635 undeliveredGestures->
insert(gesture);
640 DEBUG() <<
"QGestureManager::deliverEvents:" 641 <<
"\nstarted: " << startedGestures
642 <<
"\nconflicted: " << conflictedGestures
643 <<
"\nnormal: " << normalStartedGestures
647 for (GesturesPerWidget::const_iterator
it = conflictedGestures.begin(),
648 e = conflictedGestures.end();
it != e; ++
it) {
651 DEBUG() <<
"QGestureManager::deliverEvents: sending GestureOverride to" 653 <<
"gestures:" << gestures;
659 event.setAccepted(g,
false);
662 bool eventAccepted =
event.isAccepted();
664 if (eventAccepted || event.
isAccepted(gesture)) {
667 DEBUG() <<
"override event: gesture was accepted:" << gesture << w;
673 DEBUG() <<
"override event: gesture wasn't accepted. putting back:" << gesture;
681 for (GesturesPerWidget::const_iterator
it = normalStartedGestures.begin(),
682 e = normalStartedGestures.end();
it != e; ++
it) {
683 if (!
it.value().isEmpty()) {
684 DEBUG() <<
"QGestureManager::deliverEvents: sending to" <<
it.key()
685 <<
"gestures:" <<
it.value();
688 bool eventAccepted =
event.isAccepted();
691 (eventAccepted ||
event.isAccepted(gesture))) {
694 DEBUG() <<
"started gesture was delivered and accepted by" << w;
707 recognizer->
reset(gesture);
716 #endif // QT_NO_GESTURES 718 #include "moc_qgesturemanager_p.cpp" static QString number(int, int base=10)
This is an overloaded member function, provided for convenience. It differs from the above function o...
The QMultiMap class is a convenience QMap subclass that provides multi-valued maps.
void recycle(QGesture *gesture)
#define QT_END_NAMESPACE
This macro expands to.
const Key key(const T &value) const
Returns the first key with value value.
QPointer< QWidget > widget
void clear()
Removes all items from the hash.
int remove(const Key &key)
Removes all the items that have the key from the hash.
#define it(className, varName)
QMap< ObjectGesture, QList< QGesture * > > m_objectGestures
QMap< Key, T >::iterator insert(const Key &key, const T &value)
Inserts a new item with the key key and a value of value.
bool remove(const T &value)
QList< T > values() const
Returns a list containing all the values in the map, in ascending order of their keys.
bool filterEvent(QWidget *receiver, QEvent *event)
QGesture::GestureCancelPolicy gestureCancelPolicy
the policy for deciding what happens on accepting a gesture
bool filterEventThroughContexts(const QMultiMap< QObject *, Qt::GestureType > &contexts, QEvent *event)
QHash< QGestureRecognizer *, QSet< QGesture * > > m_obsoleteGestures
QHash< QGesture *, QGestureRecognizer * > m_deletedRecognizers
QGestureManager(QObject *parent)
The QHash class is a template class that provides a hash-table-based dictionary.
The QObject class is the base class of all Qt objects.
void cleanupCachedGestures(QObject *target, Qt::GestureType type)
void cleanupGesturesForRemovedRecognizer(QGesture *gesture)
virtual bool event(QEvent *)
This virtual function receives events to an object and should return true if the event e was recogniz...
bool contains(const Key &key) const
Returns true if the hash contains an item with the key; otherwise returns false.
const T value(const Key &key) const
Returns the value associated with the key.
bool isEmpty() const
Returns true if the list contains no items; otherwise returns false.
iterator insert(const Key &key, const T &value)
Inserts a new item with the key and a value of value.
void setParent(QObject *)
Makes the object a child of parent.
void setObjectName(const QString &name)
iterator insertMulti(const Key &key, const T &value)
Inserts a new item with the key key and a value of value.
void deliverEvents(const QSet< QGesture *> &gestures, QSet< QGesture *> *undeliveredGestures)
void append(const T &t)
Inserts value at the end of the list.
#define QT_BEGIN_NAMESPACE
This macro expands to.
virtual void reset(QGesture *state)
This function is called by the framework to reset a given gesture.
The QGestureEvent class provides the description of triggered gestures.
QBool contains(const T &t) const
Returns true if the list contains an occurrence of value; otherwise returns false.
virtual Result recognize(QGesture *state, QObject *watched, QEvent *event)=0
Handles the given event for the watched object, updating the state of the gesture object as required...
void unregisterGestureRecognizer(Qt::GestureType type)
static bool isEmpty(const char *str)
bool contains(const T &value) const
QSet< QGesture * > m_gesturesToDelete
const T value(const Key &key) const
Returns the value associated with the key key.
QGraphicsObject * parentObject() const
Returns a pointer to the item's parent, cast to a QGraphicsObject.
Q_CORE_EXPORT void qWarning(const char *,...)
const_iterator insert(const T &value)
static bool HasTouchSupport
static bool sendEvent(QObject *receiver, QEvent *event)
Sends event event directly to receiver receiver, using the notify() function.
QList< QGesture * > gestures() const
Returns all gestures that are delivered in the event.
virtual QGesture * create(QObject *target)
This function is called by Qt to create a new QGesture object for the given target (QWidget or QGraph...
enum QGestureManager::State state
void getGestureTargets(const QSet< QGesture *> &gestures, QMap< QWidget *, QList< QGesture *> > *conflicts, QMap< QWidget *, QList< QGesture *> > *normal)
Qt::GestureType registerGestureRecognizer(QGestureRecognizer *recognizer)
QHash< QGesture *, QWidget * > m_gestureTargets
The QMap::const_iterator class provides an STL-style const iterator for QMap and QMultiMap.
QHash< QGesture *, QGestureRecognizer * > m_gestureToRecognizer
bool isWidgetType() const
Returns true if the object is a widget; otherwise returns false.
QHash< QGesture *, QObject * > m_gestureOwners
iterator end()
Returns an STL-style iterator pointing to the imaginary item after the last item in the hash...
The QGesture class represents a gesture, containing properties that describe the corresponding user i...
QPointF hotSpot
The point that is used to find the receiver for the gesture event.
Qt::GestureType gestureType
the type of the gesture
QPoint toPoint() const
Rounds the coordinates of this point to the nearest integer, and returns a QPoint object with the rou...
iterator insert(const Key &key, const T &value)
Inserts a new item with the key key and a value of value.
QGesture * getState(QObject *widget, QGestureRecognizer *recognizer, Qt::GestureType gesture)
QSet< QGesture * > m_activeGestures
The QPoint class defines a point in the plane using integer precision.
bool isEmpty() const
Returns true if the map contains no items; otherwise returns false.
The QGestureRecognizer class provides the infrastructure for gesture recognition. ...
iterator begin()
Returns an STL-style iterator pointing to the first item in the hash.
const T & value() const
Returns the current item's value.
bool contains(const Key &key) const
Returns true if the map contains an item with key key; otherwise returns false.
void setGestureCancelPolicy(GestureCancelPolicy policy)
bool isAccepted(QGesture *) const
Returns true if the gesture is accepted; otherwise returns false.
iterator upperBound(const Key &key)
Returns an iterator pointing to the item that immediately follows the last item with key key in the m...
Qt::GestureState state
the current state of the gesture
T take(const Key &key)
Removes the item with the key key from the map and returns the value associated with it...
iterator lowerBound(const Key &key)
Returns an iterator pointing to the first item with key key in the map.
QMultiMap< Qt::GestureType, QGestureRecognizer * > m_recognizers
int m_lastCustomGestureId
iterator erase(iterator i)
The QGraphicsObject class provides a base class for all graphics items that require signals...
The QEvent class is the base class of all event classes.
#define Q_UNUSED(x)
Indicates to the compiler that the parameter with the specified name is not used in the body of a fun...
Q_OUTOFLINE_TEMPLATE void qDeleteAll(ForwardIterator begin, ForwardIterator end)
void cancelGesturesForChildren(QGesture *originatingGesture)
bool hasHotSpot
whether the gesture has a hot-spot
QList< Key > keys() const
Returns a list containing all the keys in the hash, in an arbitrary order.
The QMap class is a template class that provides a skip-list-based dictionary.
QSet< QGesture * > m_maybeGestures
The QList class is a template class that provides lists.