1 | // Copyright (C) 2018 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 QQUICKPOINTERHANDLER_H |
5 | #define QQUICKPOINTERHANDLER_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 purely as an |
12 | // implementation detail. 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 <QtCore/QObject> |
19 | #include <QtCore/qloggingcategory.h> |
20 | #include <QtCore/qtconfigmacros.h> |
21 | #include <QtGui/qeventpoint.h> |
22 | #include <QtGui/qpointingdevice.h> |
23 | #include <QtQml/QQmlParserStatus> |
24 | #include <QtQml/qqmlregistration.h> |
25 | #include <QtQuick/qtquickglobal.h> |
26 | #include <QtQuick/private/qtquickexports_p.h> |
27 | |
28 | QT_BEGIN_NAMESPACE |
29 | |
30 | Q_DECLARE_LOGGING_CATEGORY(lcPointerHandlerDispatch) |
31 | |
32 | class QQuickItem; |
33 | class QQuickPointerHandlerPrivate; |
34 | class QPointerEvent; |
35 | |
36 | class Q_QUICK_PRIVATE_EXPORT QQuickPointerHandler : public QObject, public QQmlParserStatus |
37 | { |
38 | Q_OBJECT |
39 | Q_INTERFACES(QQmlParserStatus) |
40 | |
41 | Q_PROPERTY(bool enabled READ enabled WRITE setEnabled NOTIFY enabledChanged FINAL) |
42 | Q_PROPERTY(bool active READ active NOTIFY activeChanged FINAL) |
43 | Q_PROPERTY(QQuickItem * target READ target WRITE setTarget NOTIFY targetChanged FINAL) |
44 | Q_PROPERTY(QQuickItem * parent READ parentItem WRITE setParentItem NOTIFY parentChanged FINAL) |
45 | Q_PROPERTY(GrabPermissions grabPermissions READ grabPermissions WRITE setGrabPermissions NOTIFY grabPermissionChanged FINAL) |
46 | Q_PROPERTY(qreal margin READ margin WRITE setMargin NOTIFY marginChanged FINAL) |
47 | Q_PROPERTY(int dragThreshold READ dragThreshold WRITE setDragThreshold RESET resetDragThreshold NOTIFY dragThresholdChanged REVISION(2, 15) FINAL) |
48 | #if QT_CONFIG(cursor) |
49 | Q_PROPERTY(Qt::CursorShape cursorShape READ cursorShape WRITE setCursorShape RESET resetCursorShape NOTIFY cursorShapeChanged REVISION(2, 15) FINAL) |
50 | #endif |
51 | |
52 | Q_CLASSINFO("ParentProperty" , "parent" ) |
53 | QML_NAMED_ELEMENT(PointerHandler) |
54 | QML_UNCREATABLE("PointerHandler is an abstract base class." ) |
55 | QML_ADDED_IN_VERSION(2, 12) |
56 | |
57 | public: |
58 | explicit QQuickPointerHandler(QQuickItem *parent = nullptr); |
59 | ~QQuickPointerHandler(); |
60 | |
61 | enum GrabPermission { |
62 | TakeOverForbidden = 0x0, |
63 | CanTakeOverFromHandlersOfSameType = 0x01, |
64 | CanTakeOverFromHandlersOfDifferentType= 0x02, |
65 | CanTakeOverFromItems = 0x04, |
66 | CanTakeOverFromAnything = 0x0F, |
67 | ApprovesTakeOverByHandlersOfSameType = 0x10, |
68 | ApprovesTakeOverByHandlersOfDifferentType= 0x20, |
69 | ApprovesTakeOverByItems = 0x40, |
70 | ApprovesCancellation = 0x80, |
71 | ApprovesTakeOverByAnything = 0xF0 |
72 | }; |
73 | Q_DECLARE_FLAGS(GrabPermissions, GrabPermission) |
74 | Q_FLAG(GrabPermissions) |
75 | |
76 | public: |
77 | bool enabled() const; |
78 | void setEnabled(bool enabled); |
79 | |
80 | bool active() const; |
81 | |
82 | QQuickItem *target() const; |
83 | void setTarget(QQuickItem *target); |
84 | |
85 | QQuickItem * parentItem() const; |
86 | void setParentItem(QQuickItem *p); |
87 | |
88 | void handlePointerEvent(QPointerEvent *event); |
89 | |
90 | GrabPermissions grabPermissions() const; |
91 | void setGrabPermissions(GrabPermissions grabPermissions); |
92 | |
93 | qreal margin() const; |
94 | void setMargin(qreal pointDistanceThreshold); |
95 | |
96 | int dragThreshold() const; |
97 | void setDragThreshold(int t); |
98 | void resetDragThreshold(); |
99 | |
100 | #if QT_CONFIG(cursor) |
101 | Qt::CursorShape cursorShape() const; |
102 | void setCursorShape(Qt::CursorShape shape); |
103 | void resetCursorShape(); |
104 | bool isCursorShapeExplicitlySet() const; |
105 | #endif |
106 | |
107 | Q_SIGNALS: |
108 | void enabledChanged(); |
109 | void activeChanged(); |
110 | void targetChanged(); |
111 | void marginChanged(); |
112 | Q_REVISION(2, 15) void dragThresholdChanged(); |
113 | void grabChanged(QPointingDevice::GrabTransition transition, QEventPoint point); |
114 | void grabPermissionChanged(); |
115 | void canceled(QEventPoint point); |
116 | #if QT_CONFIG(cursor) |
117 | Q_REVISION(2, 15) void cursorShapeChanged(); |
118 | #endif |
119 | Q_REVISION(6, 3) void parentChanged(); |
120 | |
121 | protected: |
122 | QQuickPointerHandler(QQuickPointerHandlerPrivate &dd, QQuickItem *parent); |
123 | |
124 | void classBegin() override; |
125 | void componentComplete() override; |
126 | bool event(QEvent *) override; |
127 | |
128 | QPointerEvent *currentEvent(); |
129 | virtual bool wantsPointerEvent(QPointerEvent *event); |
130 | virtual bool wantsEventPoint(const QPointerEvent *event, const QEventPoint &point); |
131 | virtual void handlePointerEventImpl(QPointerEvent *event); |
132 | void setActive(bool active); |
133 | virtual void onTargetChanged(QQuickItem *oldTarget) { Q_UNUSED(oldTarget); } |
134 | virtual void onActiveChanged() { } |
135 | virtual void onGrabChanged(QQuickPointerHandler *grabber, QPointingDevice::GrabTransition transition, |
136 | QPointerEvent *event, QEventPoint &point); |
137 | virtual bool canGrab(QPointerEvent *event, const QEventPoint &point); |
138 | virtual bool approveGrabTransition(QPointerEvent *event, const QEventPoint &point, QObject *proposedGrabber); |
139 | void setPassiveGrab(QPointerEvent *event, const QEventPoint &point, bool grab = true); |
140 | bool setExclusiveGrab(QPointerEvent *ev, const QEventPoint &point, bool grab = true); |
141 | void cancelAllGrabs(QPointerEvent *event, QEventPoint &point); |
142 | QPointF eventPos(const QEventPoint &point) const; |
143 | bool parentContains(const QEventPoint &point) const; |
144 | bool parentContains(const QPointF &scenePosition) const; |
145 | |
146 | friend class QQuickDeliveryAgentPrivate; |
147 | friend class QQuickItemPrivate; |
148 | friend class QQuickWindowPrivate; |
149 | |
150 | Q_DECLARE_PRIVATE(QQuickPointerHandler) |
151 | }; |
152 | |
153 | Q_DECLARE_OPERATORS_FOR_FLAGS(QQuickPointerHandler::GrabPermissions) |
154 | |
155 | QT_END_NAMESPACE |
156 | |
157 | #endif // QQUICKPOINTERHANDLER_H |
158 | |