| 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 | |
| 57 | QT_BEGIN_NAMESPACE |
| 58 | |
| 59 | Q_DECLARE_LOGGING_CATEGORY(lcPointerHandlerDispatch) |
| 60 | |
| 61 | class QQuickPointerHandlerPrivate; |
| 62 | |
| 63 | class 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 | Q_PROPERTY(int dragThreshold READ dragThreshold WRITE setDragThreshold RESET resetDragThreshold NOTIFY dragThresholdChanged REVISION 15) |
| 75 | #if QT_CONFIG(cursor) |
| 76 | Q_PROPERTY(Qt::CursorShape cursorShape READ cursorShape WRITE setCursorShape RESET resetCursorShape NOTIFY cursorShapeChanged REVISION 15) |
| 77 | #endif |
| 78 | |
| 79 | QML_NAMED_ELEMENT(PointerHandler) |
| 80 | QML_UNCREATABLE("PointerHandler is an abstract base class." ) |
| 81 | QML_ADDED_IN_MINOR_VERSION(12) |
| 82 | |
| 83 | public: |
| 84 | explicit QQuickPointerHandler(QQuickItem *parent = nullptr); |
| 85 | ~QQuickPointerHandler(); |
| 86 | |
| 87 | enum GrabPermission { |
| 88 | TakeOverForbidden = 0x0, |
| 89 | CanTakeOverFromHandlersOfSameType = 0x01, |
| 90 | CanTakeOverFromHandlersOfDifferentType= 0x02, |
| 91 | CanTakeOverFromItems = 0x04, |
| 92 | CanTakeOverFromAnything = 0x0F, |
| 93 | ApprovesTakeOverByHandlersOfSameType = 0x10, |
| 94 | ApprovesTakeOverByHandlersOfDifferentType= 0x20, |
| 95 | ApprovesTakeOverByItems = 0x40, |
| 96 | ApprovesCancellation = 0x80, |
| 97 | ApprovesTakeOverByAnything = 0xF0 |
| 98 | }; |
| 99 | Q_DECLARE_FLAGS(GrabPermissions, GrabPermission) |
| 100 | Q_FLAG(GrabPermissions) |
| 101 | |
| 102 | public: |
| 103 | bool enabled() const; |
| 104 | void setEnabled(bool enabled); |
| 105 | |
| 106 | bool active() const; |
| 107 | |
| 108 | QQuickItem *target() const; |
| 109 | void setTarget(QQuickItem *target); |
| 110 | |
| 111 | QQuickItem * parentItem() const; |
| 112 | |
| 113 | void handlePointerEvent(QQuickPointerEvent *event); |
| 114 | |
| 115 | GrabPermissions grabPermissions() const; |
| 116 | void setGrabPermissions(GrabPermissions grabPermissions); |
| 117 | |
| 118 | qreal margin() const; |
| 119 | void setMargin(qreal pointDistanceThreshold); |
| 120 | |
| 121 | int dragThreshold() const; |
| 122 | void setDragThreshold(int t); |
| 123 | void resetDragThreshold(); |
| 124 | |
| 125 | #if QT_CONFIG(cursor) |
| 126 | Qt::CursorShape cursorShape() const; |
| 127 | void setCursorShape(Qt::CursorShape shape); |
| 128 | void resetCursorShape(); |
| 129 | bool isCursorShapeExplicitlySet() const; |
| 130 | #endif |
| 131 | |
| 132 | Q_SIGNALS: |
| 133 | void enabledChanged(); |
| 134 | void activeChanged(); |
| 135 | void targetChanged(); |
| 136 | void marginChanged(); |
| 137 | Q_REVISION(15) void dragThresholdChanged(); |
| 138 | void grabChanged(QQuickEventPoint::GrabTransition transition, QQuickEventPoint *point); |
| 139 | void grabPermissionChanged(); |
| 140 | void canceled(QQuickEventPoint *point); |
| 141 | #if QT_CONFIG(cursor) |
| 142 | Q_REVISION(15) void cursorShapeChanged(); |
| 143 | #endif |
| 144 | |
| 145 | protected: |
| 146 | QQuickPointerHandler(QQuickPointerHandlerPrivate &dd, QQuickItem *parent); |
| 147 | |
| 148 | void classBegin() override; |
| 149 | void componentComplete() override; |
| 150 | |
| 151 | QQuickPointerEvent *currentEvent(); |
| 152 | virtual bool wantsPointerEvent(QQuickPointerEvent *event); |
| 153 | virtual bool wantsEventPoint(QQuickEventPoint *point); |
| 154 | virtual void handlePointerEventImpl(QQuickPointerEvent *event); |
| 155 | void setActive(bool active); |
| 156 | virtual void onTargetChanged(QQuickItem *oldTarget) { Q_UNUSED(oldTarget); } |
| 157 | virtual void onActiveChanged() { } |
| 158 | virtual void onGrabChanged(QQuickPointerHandler *grabber, QQuickEventPoint::GrabTransition transition, QQuickEventPoint *point); |
| 159 | virtual bool canGrab(QQuickEventPoint *point); |
| 160 | virtual bool approveGrabTransition(QQuickEventPoint *point, QObject *proposedGrabber); |
| 161 | void setPassiveGrab(QQuickEventPoint *point, bool grab = true); |
| 162 | bool setExclusiveGrab(QQuickEventPoint *point, bool grab = true); |
| 163 | void cancelAllGrabs(QQuickEventPoint *point); |
| 164 | QPointF eventPos(const QQuickEventPoint *point) const; |
| 165 | bool parentContains(const QQuickEventPoint *point) const; |
| 166 | |
| 167 | friend class QQuickEventPoint; |
| 168 | friend class QQuickItemPrivate; |
| 169 | friend class QQuickWindowPrivate; |
| 170 | |
| 171 | Q_DECLARE_PRIVATE(QQuickPointerHandler) |
| 172 | }; |
| 173 | |
| 174 | Q_DECLARE_OPERATORS_FOR_FLAGS(QQuickPointerHandler::GrabPermissions) |
| 175 | |
| 176 | QT_END_NAMESPACE |
| 177 | |
| 178 | QML_DECLARE_TYPE(QQuickPointerHandler) |
| 179 | |
| 180 | #endif // QQUICKPOINTERHANDLER_H |
| 181 | |