1/****************************************************************************
2**
3** Copyright (C) 2018 The Qt Company Ltd.
4** Contact: https://www.qt.io/licensing/
5**
6** This file is part of the QtQuick module of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:LGPL$
9** Commercial License Usage
10** Licensees holding valid commercial Qt licenses may use this file in
11** accordance with the commercial license agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and The Qt Company. For licensing terms
14** and conditions see https://www.qt.io/terms-conditions. For further
15** information use the contact form at https://www.qt.io/contact-us.
16**
17** GNU Lesser General Public License Usage
18** Alternatively, this file may be used under the terms of the GNU Lesser
19** General Public License version 3 as published by the Free Software
20** Foundation and appearing in the file LICENSE.LGPL3 included in the
21** packaging of this file. Please review the following information to
22** ensure the GNU Lesser General Public License version 3 requirements
23** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
24**
25** GNU General Public License Usage
26** Alternatively, this file may be used under the terms of the GNU
27** General Public License version 2.0 or (at your option) the GNU General
28** Public license version 3 or any later version approved by the KDE Free
29** Qt Foundation. The licenses are as published by the Free Software
30** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
31** included in the packaging of this file. Please review the following
32** information to ensure the GNU General Public License requirements will
33** be met: https://www.gnu.org/licenses/gpl-2.0.html and
34** https://www.gnu.org/licenses/gpl-3.0.html.
35**
36** $QT_END_LICENSE$
37**
38****************************************************************************/
39
40#ifndef QQUICKPOINTERHANDLER_H
41#define QQUICKPOINTERHANDLER_H
42
43//
44// W A R N I N G
45// -------------
46//
47// This file is not part of the Qt API. It exists purely as an
48// implementation detail. This header file may change from version to
49// version without notice, or even be removed.
50//
51// We mean it.
52//
53
54#include <QtQuick/private/qquickevents_p_p.h>
55#include <QtQuick/private/qquickitem_p.h>
56
57QT_BEGIN_NAMESPACE
58
59Q_DECLARE_LOGGING_CATEGORY(lcPointerHandlerDispatch)
60
61class QQuickPointerHandlerPrivate;
62
63class Q_QUICK_PRIVATE_EXPORT QQuickPointerHandler : public QObject, public QQmlParserStatus
64{
65 Q_OBJECT
66 Q_INTERFACES(QQmlParserStatus)
67
68 Q_PROPERTY(bool enabled READ enabled WRITE setEnabled NOTIFY enabledChanged)
69 Q_PROPERTY(bool active READ active NOTIFY activeChanged)
70 Q_PROPERTY(QQuickItem * target READ target WRITE setTarget NOTIFY targetChanged)
71 Q_PROPERTY(QQuickItem * parent READ parentItem CONSTANT)
72 Q_PROPERTY(GrabPermissions grabPermissions READ grabPermissions WRITE setGrabPermissions NOTIFY grabPermissionChanged)
73 Q_PROPERTY(qreal margin READ margin WRITE setMargin NOTIFY marginChanged)
74
75public:
76 explicit QQuickPointerHandler(QQuickItem *parent = nullptr);
77 ~QQuickPointerHandler();
78
79 enum GrabPermission {
80 TakeOverForbidden = 0x0,
81 CanTakeOverFromHandlersOfSameType = 0x01,
82 CanTakeOverFromHandlersOfDifferentType= 0x02,
83 CanTakeOverFromItems = 0x04,
84 CanTakeOverFromAnything = 0x0F,
85 ApprovesTakeOverByHandlersOfSameType = 0x10,
86 ApprovesTakeOverByHandlersOfDifferentType= 0x20,
87 ApprovesTakeOverByItems = 0x40,
88 ApprovesCancellation = 0x80,
89 ApprovesTakeOverByAnything = 0xF0
90 };
91 Q_DECLARE_FLAGS(GrabPermissions, GrabPermission)
92 Q_FLAG(GrabPermissions)
93
94public:
95 bool enabled() const;
96 void setEnabled(bool enabled);
97
98 bool active() const;
99
100 QQuickItem *target() const;
101 void setTarget(QQuickItem *target);
102
103 QQuickItem * parentItem() const;
104
105 void handlePointerEvent(QQuickPointerEvent *event);
106
107 GrabPermissions grabPermissions() const;
108 void setGrabPermissions(GrabPermissions grabPermissions);
109
110 qreal margin() const;
111 void setMargin(qreal pointDistanceThreshold);
112
113Q_SIGNALS:
114 void enabledChanged();
115 void activeChanged();
116 void targetChanged();
117 void marginChanged();
118 void grabChanged(QQuickEventPoint::GrabTransition transition, QQuickEventPoint *point);
119 void grabPermissionChanged();
120 void canceled(QQuickEventPoint *point);
121
122protected:
123 QQuickPointerHandler(QQuickPointerHandlerPrivate &dd, QQuickItem *parent);
124
125 void classBegin() override;
126 void componentComplete() override;
127
128 QQuickPointerEvent *currentEvent();
129 virtual bool wantsPointerEvent(QQuickPointerEvent *event);
130 virtual bool wantsEventPoint(QQuickEventPoint *point);
131 virtual void handlePointerEventImpl(QQuickPointerEvent *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, QQuickEventPoint::GrabTransition transition, QQuickEventPoint *point);
136 virtual bool canGrab(QQuickEventPoint *point);
137 virtual bool approveGrabTransition(QQuickEventPoint *point, QObject *proposedGrabber);
138 void setPassiveGrab(QQuickEventPoint *point, bool grab = true);
139 bool setExclusiveGrab(QQuickEventPoint *point, bool grab = true);
140 void cancelAllGrabs(QQuickEventPoint *point);
141 QPointF eventPos(const QQuickEventPoint *point) const;
142 bool parentContains(const QQuickEventPoint *point) const;
143
144 friend class QQuickEventPoint;
145 friend class QQuickItemPrivate;
146 friend class QQuickWindowPrivate;
147
148 Q_DECLARE_PRIVATE(QQuickPointerHandler)
149};
150
151Q_DECLARE_OPERATORS_FOR_FLAGS(QQuickPointerHandler::GrabPermissions)
152
153QT_END_NAMESPACE
154
155QML_DECLARE_TYPE(QQuickPointerHandler)
156
157#endif // QQUICKPOINTERHANDLER_H
158