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#ifndef QT_NO_GESTURES
25
26#include <functional>
27
28QT_BEGIN_NAMESPACE
29
30class QBasicTimer;
31class QGraphicsObject;
32class QGestureManager : public QObject
33{
34 Q_OBJECT
35public:
36 QGestureManager(QObject *parent);
37 ~QGestureManager();
38
39 Qt::GestureType registerGestureRecognizer(QGestureRecognizer *recognizer);
40 void unregisterGestureRecognizer(Qt::GestureType type);
41
42 bool filterEvent(QWidget *receiver, QEvent *event);
43 bool filterEvent(QObject *receiver, QEvent *event);
44#if QT_CONFIG(graphicsview)
45 bool filterEvent(QGraphicsObject *receiver, QEvent *event);
46#endif // QT_CONFIG(graphicsview)
47
48 enum InstanceCreation { ForceCreation, DontForceCreation };
49
50 static QGestureManager *instance(InstanceCreation ic = ForceCreation); // declared in qapplication.cpp
51 static bool gesturePending(QObject *o);
52
53 void cleanupCachedGestures(QObject *target, Qt::GestureType type);
54
55 void recycle(QGesture *gesture);
56
57protected:
58 bool filterEventThroughContexts(const QMultiMap<QObject *, Qt::GestureType> &contexts,
59 QEvent *event);
60
61private:
62 QMultiMap<Qt::GestureType, QGestureRecognizer *> m_recognizers;
63
64 QSet<QGesture *> m_activeGestures;
65 QSet<QGesture *> m_maybeGestures;
66
67 struct ObjectGesture
68 {
69 QObject* object;
70 Qt::GestureType gesture;
71
72 ObjectGesture(QObject *o, const Qt::GestureType &g) : object(o), gesture(g) { }
73 inline bool operator<(const ObjectGesture &rhs) const
74 {
75 if (std::less<QObject *>{}(object, rhs.object))
76 return true;
77 if (object == rhs.object)
78 return gesture < rhs.gesture;
79 return false;
80 }
81 };
82
83 QMap<ObjectGesture, QList<QGesture *> > m_objectGestures;
84 QHash<QGesture *, QGestureRecognizer *> m_gestureToRecognizer;
85 QHash<QGesture *, QObject *> m_gestureOwners;
86
87 QHash<QGesture *, QPointer<QWidget> > m_gestureTargets;
88
89 int m_lastCustomGestureId;
90
91 QHash<QGestureRecognizer *, QSet<QGesture *> > m_obsoleteGestures;
92 QHash<QGesture *, QGestureRecognizer *> m_deletedRecognizers;
93 QSet<QGesture *> m_gesturesToDelete;
94 void cleanupGesturesForRemovedRecognizer(QGesture *gesture);
95
96 QGesture *getState(QObject *widget, QGestureRecognizer *recognizer,
97 Qt::GestureType gesture);
98 void deliverEvents(const QSet<QGesture *> &gestures,
99 QSet<QGesture *> *undeliveredGestures);
100 void getGestureTargets(const QSet<QGesture*> &gestures,
101 QHash<QWidget *, QList<QGesture *> > *conflicts,
102 QHash<QWidget *, QList<QGesture *> > *normal);
103
104 void cancelGesturesForChildren(QGesture *originatingGesture);
105};
106
107QT_END_NAMESPACE
108
109#endif // QT_NO_GESTURES
110
111#endif // QGESTUREMANAGER_P_H
112

source code of qtbase/src/widgets/kernel/qgesturemanager_p.h