| 1 | // Copyright (C) 2016 The Qt Company Ltd. |
| 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only |
| 3 | |
| 4 | #ifndef QGESTUREMANAGER_P_H |
| 5 | #define QGESTUREMANAGER_P_H |
| 6 | |
| 7 | // |
| 8 | // W A R N I N G |
| 9 | // ------------- |
| 10 | // |
| 11 | // This file is not part of the Qt API. It exists for the convenience |
| 12 | // of other Qt classes. This header file may change from version to |
| 13 | // version without notice, or even be removed. |
| 14 | // |
| 15 | // We mean it. |
| 16 | // |
| 17 | |
| 18 | #include <QtWidgets/private/qtwidgetsglobal_p.h> |
| 19 | #include "qobject.h" |
| 20 | #include "qbasictimer.h" |
| 21 | #include "private/qwidget_p.h" |
| 22 | #include "qgesturerecognizer.h" |
| 23 | |
| 24 | #include <QtCore/qpointer.h> |
| 25 | |
| 26 | #ifndef QT_NO_GESTURES |
| 27 | |
| 28 | #include <functional> |
| 29 | |
| 30 | QT_BEGIN_NAMESPACE |
| 31 | |
| 32 | class QBasicTimer; |
| 33 | class QGraphicsObject; |
| 34 | class QGestureManager : public QObject |
| 35 | { |
| 36 | Q_OBJECT |
| 37 | public: |
| 38 | QGestureManager(QObject *parent); |
| 39 | ~QGestureManager(); |
| 40 | |
| 41 | Qt::GestureType registerGestureRecognizer(QGestureRecognizer *recognizer); |
| 42 | void unregisterGestureRecognizer(Qt::GestureType type); |
| 43 | |
| 44 | bool filterEvent(QWidget *receiver, QEvent *event); |
| 45 | bool filterEvent(QObject *receiver, QEvent *event); |
| 46 | #if QT_CONFIG(graphicsview) |
| 47 | bool filterEvent(QGraphicsObject *receiver, QEvent *event); |
| 48 | #endif // QT_CONFIG(graphicsview) |
| 49 | |
| 50 | enum InstanceCreation { ForceCreation, DontForceCreation }; |
| 51 | |
| 52 | static QGestureManager *instance(InstanceCreation ic = ForceCreation); // declared in qapplication.cpp |
| 53 | static bool gesturePending(QObject *o); |
| 54 | |
| 55 | void cleanupCachedGestures(QObject *target, Qt::GestureType type); |
| 56 | |
| 57 | void recycle(QGesture *gesture); |
| 58 | |
| 59 | protected: |
| 60 | bool filterEventThroughContexts(const QMultiMap<QObject *, Qt::GestureType> &contexts, |
| 61 | QEvent *event); |
| 62 | |
| 63 | private: |
| 64 | QMultiMap<Qt::GestureType, QGestureRecognizer *> m_recognizers; |
| 65 | |
| 66 | QSet<QGesture *> m_activeGestures; |
| 67 | QSet<QGesture *> m_maybeGestures; |
| 68 | |
| 69 | struct ObjectGesture |
| 70 | { |
| 71 | QObject* object; |
| 72 | Qt::GestureType gesture; |
| 73 | |
| 74 | ObjectGesture(QObject *o, const Qt::GestureType &g) : object(o), gesture(g) { } |
| 75 | inline bool operator<(const ObjectGesture &rhs) const |
| 76 | { |
| 77 | if (std::less<QObject *>{}(object, rhs.object)) |
| 78 | return true; |
| 79 | if (object == rhs.object) |
| 80 | return gesture < rhs.gesture; |
| 81 | return false; |
| 82 | } |
| 83 | }; |
| 84 | |
| 85 | QMap<ObjectGesture, QList<QGesture *> > m_objectGestures; |
| 86 | QHash<QGesture *, QGestureRecognizer *> m_gestureToRecognizer; |
| 87 | QHash<QGesture *, QObject *> m_gestureOwners; |
| 88 | |
| 89 | QHash<QGesture *, QPointer<QWidget> > m_gestureTargets; |
| 90 | |
| 91 | int m_lastCustomGestureId; |
| 92 | |
| 93 | QHash<QGestureRecognizer *, QSet<QGesture *> > m_obsoleteGestures; |
| 94 | QHash<QGesture *, QGestureRecognizer *> m_deletedRecognizers; |
| 95 | QSet<QGesture *> m_gesturesToDelete; |
| 96 | void cleanupGesturesForRemovedRecognizer(QGesture *gesture); |
| 97 | |
| 98 | QGesture *getState(QObject *widget, QGestureRecognizer *recognizer, |
| 99 | Qt::GestureType gesture); |
| 100 | void deliverEvents(const QSet<QGesture *> &gestures, |
| 101 | QSet<QGesture *> *undeliveredGestures); |
| 102 | void getGestureTargets(const QSet<QGesture*> &gestures, |
| 103 | QHash<QWidget *, QList<QGesture *> > *conflicts, |
| 104 | QHash<QWidget *, QList<QGesture *> > *normal); |
| 105 | |
| 106 | void cancelGesturesForChildren(QGesture *originatingGesture); |
| 107 | }; |
| 108 | |
| 109 | QT_END_NAMESPACE |
| 110 | |
| 111 | #endif // QT_NO_GESTURES |
| 112 | |
| 113 | #endif // QGESTUREMANAGER_P_H |
| 114 | |