Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qquickpointerhandler_p.h
Go to the documentation of this file.
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// Qt-Security score:significant reason:default
4
5#ifndef QQUICKPOINTERHANDLER_H
6#define QQUICKPOINTERHANDLER_H
7
8//
9// W A R N I N G
10// -------------
11//
12// This file is not part of the Qt API. It exists purely as an
13// implementation detail. This header file may change from version to
14// version without notice, or even be removed.
15//
16// We mean it.
17//
18
19#include <QtCore/QObject>
20#include <QtCore/qloggingcategory.h>
21#include <QtCore/qtconfigmacros.h>
22#include <QtGui/qeventpoint.h>
23#include <QtGui/qpointingdevice.h>
24#include <QtQml/QQmlParserStatus>
25#include <QtQml/qqmlregistration.h>
26#include <QtQuick/qtquickglobal.h>
27#include <QtQuick/qtquickexports.h>
28
30
31Q_DECLARE_LOGGING_CATEGORY(lcPointerHandlerDispatch)
32
33class QQuickItem;
34class QQuickPointerHandlerPrivate;
35class QPointerEvent;
36
37class Q_QUICK_EXPORT QQuickPointerHandler : public QObject, public QQmlParserStatus
38{
39 Q_OBJECT
40 Q_INTERFACES(QQmlParserStatus)
41
42 Q_PROPERTY(bool enabled READ enabled WRITE setEnabled NOTIFY enabledChanged)
43 Q_PROPERTY(bool active READ active NOTIFY activeChanged)
44 Q_PROPERTY(QQuickItem * target READ target WRITE setTarget NOTIFY targetChanged)
45 Q_PROPERTY(QQuickItem * parent READ parentItem WRITE setParentItem NOTIFY parentChanged)
46 Q_PROPERTY(GrabPermissions grabPermissions READ grabPermissions WRITE setGrabPermissions NOTIFY grabPermissionChanged)
47 Q_PROPERTY(qreal margin READ margin WRITE setMargin NOTIFY marginChanged)
48 Q_PROPERTY(int dragThreshold READ dragThreshold WRITE setDragThreshold RESET resetDragThreshold NOTIFY dragThresholdChanged REVISION(2, 15))
49#if QT_CONFIG(cursor)
50 Q_PROPERTY(Qt::CursorShape cursorShape READ cursorShape WRITE setCursorShape RESET resetCursorShape NOTIFY cursorShapeChanged REVISION(2, 15))
51#endif
52
53 Q_CLASSINFO("ParentProperty", "parent")
54 QML_NAMED_ELEMENT(PointerHandler)
55 QML_UNCREATABLE("PointerHandler is an abstract base class.")
56 QML_ADDED_IN_VERSION(2, 12)
57
58public:
59 explicit QQuickPointerHandler(QQuickItem *parent = nullptr);
60 ~QQuickPointerHandler();
61
62 enum GrabPermission {
63 TakeOverForbidden = 0x0,
64 CanTakeOverFromHandlersOfSameType = 0x01,
65 CanTakeOverFromHandlersOfDifferentType= 0x02,
66 CanTakeOverFromItems = 0x04,
67 CanTakeOverFromAnything = 0x0F,
68 ApprovesTakeOverByHandlersOfSameType = 0x10,
69 ApprovesTakeOverByHandlersOfDifferentType= 0x20,
70 ApprovesTakeOverByItems = 0x40,
71 ApprovesCancellation = 0x80,
72 ApprovesTakeOverByAnything = 0xF0
73 };
74 Q_DECLARE_FLAGS(GrabPermissions, GrabPermission)
75 Q_FLAG(GrabPermissions)
76
77public:
78 bool enabled() const;
79 void setEnabled(bool enabled);
80
81 bool active() const;
82
83 QQuickItem *target() const;
84 void setTarget(QQuickItem *target);
85
86 QQuickItem * parentItem() const;
87 void setParentItem(QQuickItem *p);
88
89 void handlePointerEvent(QPointerEvent *event);
90
91 GrabPermissions grabPermissions() const;
92 void setGrabPermissions(GrabPermissions grabPermissions);
93
94 qreal margin() const;
95 void setMargin(qreal pointDistanceThreshold);
96
97 int dragThreshold() const;
98 void setDragThreshold(int t);
99 void resetDragThreshold();
100
101#if QT_CONFIG(cursor)
102 Qt::CursorShape cursorShape() const;
103 void setCursorShape(Qt::CursorShape shape);
104 void resetCursorShape();
105 bool isCursorShapeExplicitlySet() const;
106#endif
107
108Q_SIGNALS:
109 void enabledChanged();
110 void activeChanged();
111 void targetChanged();
112 void marginChanged();
113 Q_REVISION(2, 15) void dragThresholdChanged();
114 void grabChanged(QPointingDevice::GrabTransition transition, QEventPoint point);
115 void grabPermissionChanged();
116 void canceled(QEventPoint point);
117#if QT_CONFIG(cursor)
118 Q_REVISION(2, 15) void cursorShapeChanged();
119#endif
120 Q_REVISION(6, 3) void parentChanged();
121
122protected:
123 QQuickPointerHandler(QQuickPointerHandlerPrivate &dd, QQuickItem *parent);
124
125 void classBegin() override;
126 void componentComplete() override;
127 bool event(QEvent *) override;
128
129 QPointerEvent *currentEvent();
130 virtual bool wantsPointerEvent(QPointerEvent *event);
131 virtual bool wantsEventPoint(const QPointerEvent *event, const QEventPoint &point);
132 virtual void handlePointerEventImpl(QPointerEvent *event);
133 void setActive(bool active);
134 virtual void onTargetChanged(QQuickItem *oldTarget) { Q_UNUSED(oldTarget); }
135 virtual void onActiveChanged() { }
136 virtual void onGrabChanged(QQuickPointerHandler *grabber, QPointingDevice::GrabTransition transition,
137 QPointerEvent *event, QEventPoint &point);
138 virtual bool canGrab(QPointerEvent *event, const QEventPoint &point);
139 virtual bool approveGrabTransition(QPointerEvent *event, const QEventPoint &point, QObject *proposedGrabber);
140 void setPassiveGrab(QPointerEvent *event, const QEventPoint &point, bool grab = true);
141 bool setExclusiveGrab(QPointerEvent *ev, const QEventPoint &point, bool grab = true);
142 void cancelAllGrabs(QPointerEvent *event, QEventPoint &point);
143 QPointF eventPos(const QEventPoint &point) const;
144 bool parentContains(const QEventPoint &point) const;
145 bool parentContains(const QPointF &scenePosition) const;
146
147 friend class QQuickDeliveryAgentPrivate;
148 friend class QQuickItemPrivate;
149 friend class QQuickMenuPrivate;
150 friend class QQuickWindowPrivate;
151
152 Q_DECLARE_PRIVATE(QQuickPointerHandler)
153};
154
155Q_DECLARE_OPERATORS_FOR_FLAGS(QQuickPointerHandler::GrabPermissions)
156
157QT_END_NAMESPACE
158
159#endif // QQUICKPOINTERHANDLER_H
Q_STATIC_LOGGING_CATEGORY(lcAccessibilityCore, "qt.accessibility.core")