| 1 | /**************************************************************************** |
| 2 | ** |
| 3 | ** Copyright (C) 2020 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 QQUICKEVENTS_P_P_H |
| 41 | #define QQUICKEVENTS_P_P_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 <private/qtquickglobal_p.h> |
| 55 | #include <qqml.h> |
| 56 | |
| 57 | #include <QtCore/qobject.h> |
| 58 | #include <QtCore/qpointer.h> |
| 59 | #include <QtGui/qvector2d.h> |
| 60 | #include <QtGui/qevent.h> |
| 61 | #if QT_CONFIG(shortcut) |
| 62 | # include <QtGui/qkeysequence.h> |
| 63 | #endif |
| 64 | #include <QtQuick/qquickitem.h> |
| 65 | |
| 66 | QT_BEGIN_NAMESPACE |
| 67 | |
| 68 | class QQuickPointerDevice; |
| 69 | class QQuickPointerEvent; |
| 70 | class QQuickPointerMouseEvent; |
| 71 | #if QT_CONFIG(gestures) |
| 72 | class QQuickPointerNativeGestureEvent; |
| 73 | #endif |
| 74 | class QQuickPointerScrollEvent; |
| 75 | class QQuickPointerTabletEvent; |
| 76 | class QQuickPointerTouchEvent; |
| 77 | class QQuickPointerHandler; |
| 78 | |
| 79 | class QQuickKeyEvent : public QObject |
| 80 | { |
| 81 | Q_OBJECT |
| 82 | Q_PROPERTY(int key READ key CONSTANT) |
| 83 | Q_PROPERTY(QString text READ text CONSTANT) |
| 84 | Q_PROPERTY(int modifiers READ modifiers CONSTANT) |
| 85 | Q_PROPERTY(bool isAutoRepeat READ isAutoRepeat CONSTANT) |
| 86 | Q_PROPERTY(int count READ count CONSTANT) |
| 87 | Q_PROPERTY(quint32 nativeScanCode READ nativeScanCode CONSTANT) |
| 88 | Q_PROPERTY(bool accepted READ isAccepted WRITE setAccepted) |
| 89 | QML_ANONYMOUS |
| 90 | |
| 91 | public: |
| 92 | QQuickKeyEvent() |
| 93 | : event(QEvent::None, 0, { }) |
| 94 | {} |
| 95 | |
| 96 | void reset(QEvent::Type type, int key, Qt::KeyboardModifiers modifiers, |
| 97 | const QString &text = QString(), bool autorep = false, ushort count = 1) |
| 98 | { |
| 99 | event = QKeyEvent(type, key, modifiers, text, autorep, count); |
| 100 | event.setAccepted(false); |
| 101 | } |
| 102 | |
| 103 | void reset(const QKeyEvent &ke) |
| 104 | { |
| 105 | event = ke; |
| 106 | event.setAccepted(false); |
| 107 | } |
| 108 | |
| 109 | int key() const { return event.key(); } |
| 110 | QString text() const { return event.text(); } |
| 111 | int modifiers() const { return event.modifiers(); } |
| 112 | bool isAutoRepeat() const { return event.isAutoRepeat(); } |
| 113 | int count() const { return event.count(); } |
| 114 | quint32 nativeScanCode() const { return event.nativeScanCode(); } |
| 115 | |
| 116 | bool isAccepted() { return event.isAccepted(); } |
| 117 | void setAccepted(bool accepted) { event.setAccepted(accepted); } |
| 118 | |
| 119 | #if QT_CONFIG(shortcut) |
| 120 | Q_REVISION(2) Q_INVOKABLE bool matches(QKeySequence::StandardKey key) const { return event.matches(key); } |
| 121 | #endif |
| 122 | |
| 123 | private: |
| 124 | QKeyEvent event; |
| 125 | }; |
| 126 | |
| 127 | // used in Qt Location |
| 128 | class Q_QUICK_PRIVATE_EXPORT QQuickMouseEvent : public QObject |
| 129 | { |
| 130 | Q_OBJECT |
| 131 | Q_PROPERTY(qreal x READ x CONSTANT) |
| 132 | Q_PROPERTY(qreal y READ y CONSTANT) |
| 133 | Q_PROPERTY(int button READ button CONSTANT) |
| 134 | Q_PROPERTY(int buttons READ buttons CONSTANT) |
| 135 | Q_PROPERTY(int modifiers READ modifiers CONSTANT) |
| 136 | Q_PROPERTY(int source READ source CONSTANT REVISION 7) |
| 137 | Q_PROPERTY(bool wasHeld READ wasHeld CONSTANT) |
| 138 | Q_PROPERTY(bool isClick READ isClick CONSTANT) |
| 139 | Q_PROPERTY(bool accepted READ isAccepted WRITE setAccepted) |
| 140 | Q_PROPERTY(int flags READ flags CONSTANT REVISION 11) |
| 141 | QML_ANONYMOUS |
| 142 | |
| 143 | public: |
| 144 | QQuickMouseEvent() |
| 145 | : _buttons(Qt::NoButton), _modifiers(Qt::NoModifier) |
| 146 | , _wasHeld(false), _isClick(false), _accepted(false) |
| 147 | {} |
| 148 | |
| 149 | void reset(qreal x, qreal y, Qt::MouseButton button, Qt::MouseButtons buttons, |
| 150 | Qt::KeyboardModifiers modifiers, bool isClick = false, bool wasHeld = false, |
| 151 | Qt::MouseEventFlags flags = { }) |
| 152 | { |
| 153 | _x = x; |
| 154 | _y = y; |
| 155 | _button = button; |
| 156 | _buttons = buttons; |
| 157 | _modifiers = modifiers; |
| 158 | _source = Qt::MouseEventNotSynthesized; |
| 159 | _wasHeld = wasHeld; |
| 160 | _isClick = isClick; |
| 161 | _accepted = true; |
| 162 | _flags = flags; |
| 163 | } |
| 164 | |
| 165 | qreal x() const { return _x; } |
| 166 | qreal y() const { return _y; } |
| 167 | int button() const { return _button; } |
| 168 | int buttons() const { return _buttons; } |
| 169 | int modifiers() const { return _modifiers; } |
| 170 | int source() const { return _source; } |
| 171 | bool wasHeld() const { return _wasHeld; } |
| 172 | bool isClick() const { return _isClick; } |
| 173 | |
| 174 | // only for internal usage |
| 175 | void setX(qreal x) { _x = x; } |
| 176 | void setY(qreal y) { _y = y; } |
| 177 | void setPosition(const QPointF &point) { _x = point.x(); _y = point.y(); } |
| 178 | void setSource(Qt::MouseEventSource s) { _source = s; } |
| 179 | |
| 180 | bool isAccepted() { return _accepted; } |
| 181 | void setAccepted(bool accepted) { _accepted = accepted; } |
| 182 | int flags() const { return _flags; } |
| 183 | private: |
| 184 | qreal _x = 0; |
| 185 | qreal _y = 0; |
| 186 | Qt::MouseButton _button = Qt::NoButton; |
| 187 | Qt::MouseButtons _buttons; |
| 188 | Qt::KeyboardModifiers _modifiers; |
| 189 | Qt::MouseEventSource _source = Qt::MouseEventNotSynthesized; |
| 190 | bool _wasHeld : 1; |
| 191 | bool _isClick : 1; |
| 192 | bool _accepted : 1; |
| 193 | Qt::MouseEventFlags _flags; |
| 194 | }; |
| 195 | |
| 196 | class QQuickWheelEvent : public QObject |
| 197 | { |
| 198 | Q_OBJECT |
| 199 | Q_PROPERTY(qreal x READ x CONSTANT) |
| 200 | Q_PROPERTY(qreal y READ y CONSTANT) |
| 201 | Q_PROPERTY(QPoint angleDelta READ angleDelta CONSTANT) |
| 202 | Q_PROPERTY(QPoint pixelDelta READ pixelDelta CONSTANT) |
| 203 | Q_PROPERTY(int buttons READ buttons CONSTANT) |
| 204 | Q_PROPERTY(int modifiers READ modifiers CONSTANT) |
| 205 | Q_PROPERTY(bool inverted READ inverted CONSTANT) |
| 206 | Q_PROPERTY(bool accepted READ isAccepted WRITE setAccepted) |
| 207 | QML_ANONYMOUS |
| 208 | |
| 209 | public: |
| 210 | QQuickWheelEvent() |
| 211 | : _buttons(Qt::NoButton), _modifiers(Qt::NoModifier) |
| 212 | {} |
| 213 | |
| 214 | void reset(qreal x, qreal y, const QPoint &angleDelta, const QPoint &pixelDelta, |
| 215 | Qt::MouseButtons buttons, Qt::KeyboardModifiers modifiers, bool inverted) |
| 216 | { |
| 217 | _x = x; |
| 218 | _y = y; |
| 219 | _angleDelta = angleDelta; |
| 220 | _pixelDelta = pixelDelta; |
| 221 | _buttons = buttons; |
| 222 | _modifiers = modifiers; |
| 223 | _accepted = true; |
| 224 | _inverted = inverted; |
| 225 | } |
| 226 | |
| 227 | qreal x() const { return _x; } |
| 228 | qreal y() const { return _y; } |
| 229 | QPoint angleDelta() const { return _angleDelta; } |
| 230 | QPoint pixelDelta() const { return _pixelDelta; } |
| 231 | int buttons() const { return _buttons; } |
| 232 | int modifiers() const { return _modifiers; } |
| 233 | bool inverted() const { return _inverted; } |
| 234 | bool isAccepted() { return _accepted; } |
| 235 | void setAccepted(bool accepted) { _accepted = accepted; } |
| 236 | |
| 237 | private: |
| 238 | qreal _x = 0; |
| 239 | qreal _y = 0; |
| 240 | QPoint _angleDelta; |
| 241 | QPoint _pixelDelta; |
| 242 | Qt::MouseButtons _buttons; |
| 243 | Qt::KeyboardModifiers _modifiers; |
| 244 | bool _inverted = false; |
| 245 | bool _accepted = false; |
| 246 | }; |
| 247 | |
| 248 | class Q_QUICK_PRIVATE_EXPORT QQuickCloseEvent : public QObject |
| 249 | { |
| 250 | Q_OBJECT |
| 251 | Q_PROPERTY(bool accepted READ isAccepted WRITE setAccepted) |
| 252 | QML_ANONYMOUS |
| 253 | |
| 254 | public: |
| 255 | QQuickCloseEvent() {} |
| 256 | |
| 257 | bool isAccepted() { return _accepted; } |
| 258 | void setAccepted(bool accepted) { _accepted = accepted; } |
| 259 | |
| 260 | private: |
| 261 | bool _accepted = true; |
| 262 | }; |
| 263 | |
| 264 | class Q_QUICK_PRIVATE_EXPORT QQuickEventPoint : public QObject |
| 265 | { |
| 266 | Q_OBJECT |
| 267 | Q_PROPERTY(QQuickPointerEvent *event READ pointerEvent CONSTANT) |
| 268 | Q_PROPERTY(QPointF position READ position CONSTANT) |
| 269 | Q_PROPERTY(QPointF scenePosition READ scenePosition CONSTANT) |
| 270 | Q_PROPERTY(QPointF scenePressPosition READ scenePressPosition CONSTANT) |
| 271 | Q_PROPERTY(QPointF sceneGrabPosition READ sceneGrabPosition CONSTANT) |
| 272 | Q_PROPERTY(State state READ state CONSTANT) |
| 273 | Q_PROPERTY(int pointId READ pointId CONSTANT) |
| 274 | Q_PROPERTY(qreal timeHeld READ timeHeld CONSTANT) |
| 275 | Q_PROPERTY(QVector2D velocity READ velocity CONSTANT) |
| 276 | Q_PROPERTY(bool accepted READ isAccepted WRITE setAccepted) |
| 277 | Q_PROPERTY(QObject *exclusiveGrabber READ exclusiveGrabber WRITE setExclusiveGrabber) |
| 278 | |
| 279 | QML_NAMED_ELEMENT(EventPoint) |
| 280 | QML_UNCREATABLE("EventPoint is only available as a member of PointerEvent." ) |
| 281 | QML_ADDED_IN_MINOR_VERSION(12) |
| 282 | |
| 283 | public: |
| 284 | enum State { |
| 285 | Pressed = Qt::TouchPointPressed, |
| 286 | Updated = Qt::TouchPointMoved, |
| 287 | Stationary = Qt::TouchPointStationary, |
| 288 | Released = Qt::TouchPointReleased |
| 289 | }; |
| 290 | Q_DECLARE_FLAGS(States, State) |
| 291 | Q_FLAG(States) |
| 292 | |
| 293 | enum GrabTransition { |
| 294 | GrabPassive = 0x01, |
| 295 | UngrabPassive = 0x02, |
| 296 | CancelGrabPassive = 0x03, |
| 297 | OverrideGrabPassive = 0x04, |
| 298 | GrabExclusive = 0x10, |
| 299 | UngrabExclusive = 0x20, |
| 300 | CancelGrabExclusive = 0x30, |
| 301 | }; |
| 302 | Q_ENUM(GrabTransition) |
| 303 | |
| 304 | QQuickEventPoint(QQuickPointerEvent *parent); |
| 305 | |
| 306 | void reset(Qt::TouchPointState state, const QPointF &scenePosition, int pointId, ulong timestamp, const QVector2D &velocity = QVector2D()); |
| 307 | void localizePosition(QQuickItem *target); |
| 308 | |
| 309 | QQuickPointerEvent *pointerEvent() const; |
| 310 | QPointF position() const { return m_pos; } |
| 311 | QPointF scenePosition() const { return m_scenePos; } |
| 312 | QPointF scenePressPosition() const { return m_scenePressPos; } |
| 313 | QPointF sceneGrabPosition() const { return m_sceneGrabPos; } |
| 314 | QVector2D velocity() const { return m_velocity; } |
| 315 | State state() const { return m_state; } |
| 316 | int pointId() const { return m_pointId; } |
| 317 | qreal timeHeld() const { return (m_timestamp - m_pressTimestamp) / 1000.0; } |
| 318 | bool isAccepted() const { return m_accept; } |
| 319 | void setAccepted(bool accepted = true); |
| 320 | QObject *exclusiveGrabber() const; |
| 321 | void setExclusiveGrabber(QObject *exclusiveGrabber); |
| 322 | |
| 323 | QQuickItem *grabberItem() const; |
| 324 | void setGrabberItem(QQuickItem *exclusiveGrabber); |
| 325 | |
| 326 | QQuickPointerHandler *grabberPointerHandler() const; |
| 327 | void setGrabberPointerHandler(QQuickPointerHandler *exclusiveGrabber, bool exclusive = false); |
| 328 | |
| 329 | void cancelExclusiveGrab(); |
| 330 | void cancelPassiveGrab(QQuickPointerHandler *handler); |
| 331 | bool removePassiveGrabber(QQuickPointerHandler *handler); |
| 332 | void cancelAllGrabs(QQuickPointerHandler *handler); |
| 333 | |
| 334 | QVector<QPointer <QQuickPointerHandler> > passiveGrabbers() const { return m_passiveGrabbers; } |
| 335 | void setPassiveGrabbers(const QVector<QPointer <QQuickPointerHandler> > &grabbers) { m_passiveGrabbers = grabbers; } |
| 336 | void clearPassiveGrabbers() { m_passiveGrabbers.clear(); } |
| 337 | |
| 338 | protected: |
| 339 | void cancelExclusiveGrabImpl(QTouchEvent *cancelEvent = nullptr); |
| 340 | |
| 341 | private: |
| 342 | QVector2D estimatedVelocity() const; |
| 343 | |
| 344 | protected: |
| 345 | QPointF m_pos; |
| 346 | QPointF m_scenePos; |
| 347 | QPointF m_scenePressPos; |
| 348 | QPointF m_sceneGrabPos; |
| 349 | QVector2D m_velocity; |
| 350 | int m_pointId; |
| 351 | QPointer<QObject> m_exclusiveGrabber; |
| 352 | QVector<QPointer <QQuickPointerHandler> > m_passiveGrabbers; |
| 353 | ulong m_timestamp; |
| 354 | ulong m_pressTimestamp; |
| 355 | State m_state; |
| 356 | bool m_accept : 1; |
| 357 | bool m_grabberIsHandler : 1; |
| 358 | int m_reserved : 29; |
| 359 | |
| 360 | friend class QQuickPointerTouchEvent; |
| 361 | friend class QQuickWindowPrivate; |
| 362 | |
| 363 | Q_DISABLE_COPY(QQuickEventPoint) |
| 364 | }; |
| 365 | |
| 366 | class Q_QUICK_PRIVATE_EXPORT QQuickEventTouchPoint : public QQuickEventPoint |
| 367 | { |
| 368 | Q_OBJECT |
| 369 | Q_PROPERTY(qreal rotation READ rotation) |
| 370 | Q_PROPERTY(qreal pressure READ pressure) |
| 371 | Q_PROPERTY(QSizeF ellipseDiameters READ ellipseDiameters) |
| 372 | Q_PROPERTY(QPointingDeviceUniqueId uniqueId READ uniqueId) |
| 373 | |
| 374 | QML_NAMED_ELEMENT(EventTouchPoint) |
| 375 | QML_UNCREATABLE("EventTouchPoint is only available as a member of PointerEvent." ) |
| 376 | QML_ADDED_IN_MINOR_VERSION(12) |
| 377 | |
| 378 | public: |
| 379 | QQuickEventTouchPoint(QQuickPointerTouchEvent *parent); |
| 380 | |
| 381 | void reset(const QTouchEvent::TouchPoint &tp, ulong timestamp); |
| 382 | |
| 383 | qreal rotation() const { return m_rotation; } |
| 384 | qreal pressure() const { return m_pressure; } |
| 385 | QSizeF ellipseDiameters() const { return m_ellipseDiameters; } |
| 386 | QPointingDeviceUniqueId uniqueId() const { return m_uniqueId; } |
| 387 | |
| 388 | private: |
| 389 | qreal m_rotation; |
| 390 | qreal m_pressure; |
| 391 | QSizeF m_ellipseDiameters; |
| 392 | QPointingDeviceUniqueId m_uniqueId; |
| 393 | |
| 394 | friend class QQuickPointerTouchEvent; |
| 395 | |
| 396 | Q_DISABLE_COPY(QQuickEventTouchPoint) |
| 397 | }; |
| 398 | |
| 399 | class Q_QUICK_PRIVATE_EXPORT QQuickPointerEvent : public QObject |
| 400 | { |
| 401 | Q_OBJECT |
| 402 | Q_PROPERTY(QQuickPointerDevice *device READ device CONSTANT) |
| 403 | Q_PROPERTY(Qt::KeyboardModifiers modifiers READ modifiers CONSTANT) |
| 404 | Q_PROPERTY(Qt::MouseButtons button READ button CONSTANT) |
| 405 | Q_PROPERTY(Qt::MouseButtons buttons READ buttons CONSTANT) |
| 406 | |
| 407 | QML_NAMED_ELEMENT(PointerEvent) |
| 408 | QML_UNCREATABLE("PointerEvent is only available as a parameter of several signals in PointerHandler" ) |
| 409 | QML_ADDED_IN_MINOR_VERSION(12) |
| 410 | |
| 411 | public: |
| 412 | QQuickPointerEvent(QObject *parent = nullptr, QQuickPointerDevice *device = nullptr) |
| 413 | : QObject(parent) |
| 414 | , m_device(device) |
| 415 | , m_pressedButtons(Qt::NoButton) |
| 416 | {} |
| 417 | |
| 418 | ~QQuickPointerEvent() override; |
| 419 | |
| 420 | public: // property accessors |
| 421 | QQuickPointerDevice *device() const { return m_device; } |
| 422 | Qt::KeyboardModifiers modifiers() const { return m_event ? m_event->modifiers() : Qt::NoModifier; } |
| 423 | Qt::MouseButton button() const { return m_button; } |
| 424 | Qt::MouseButtons buttons() const { return m_pressedButtons; } |
| 425 | |
| 426 | public: // helpers for C++ only (during event delivery) |
| 427 | virtual QQuickPointerEvent *reset(QEvent *ev) = 0; |
| 428 | virtual void localize(QQuickItem *target) = 0; |
| 429 | |
| 430 | virtual bool isPressEvent() const = 0; |
| 431 | virtual bool isDoubleClickEvent() const { return false; } |
| 432 | virtual bool isUpdateEvent() const = 0; |
| 433 | virtual bool isReleaseEvent() const = 0; |
| 434 | virtual QQuickPointerMouseEvent *asPointerMouseEvent() { return nullptr; } |
| 435 | virtual QQuickPointerTouchEvent *asPointerTouchEvent() { return nullptr; } |
| 436 | virtual QQuickPointerTabletEvent *asPointerTabletEvent() { return nullptr; } |
| 437 | #if QT_CONFIG(gestures) |
| 438 | virtual QQuickPointerNativeGestureEvent *asPointerNativeGestureEvent() { return nullptr; } |
| 439 | #endif |
| 440 | virtual QQuickPointerScrollEvent *asPointerScrollEvent() { return nullptr; } |
| 441 | virtual const QQuickPointerMouseEvent *asPointerMouseEvent() const { return nullptr; } |
| 442 | virtual const QQuickPointerTouchEvent *asPointerTouchEvent() const { return nullptr; } |
| 443 | virtual const QQuickPointerTabletEvent *asPointerTabletEvent() const { return nullptr; } |
| 444 | #if QT_CONFIG(gestures) |
| 445 | virtual const QQuickPointerNativeGestureEvent *asPointerNativeGestureEvent() const { return nullptr; } |
| 446 | #endif |
| 447 | virtual const QQuickPointerScrollEvent *asPointerScrollEvent() const { return nullptr; } |
| 448 | virtual bool allPointsAccepted() const = 0; |
| 449 | virtual bool allUpdatedPointsAccepted() const = 0; |
| 450 | virtual bool allPointsGrabbed() const = 0; |
| 451 | bool isAccepted() { return m_event ? m_event->isAccepted() : false; } |
| 452 | void setAccepted(bool accepted) { if (m_event) m_event->setAccepted(accepted); } |
| 453 | QVector<QPointF> unacceptedPressedPointScenePositions() const; |
| 454 | |
| 455 | virtual int pointCount() const = 0; |
| 456 | virtual QQuickEventPoint *point(int i) const = 0; |
| 457 | virtual QQuickEventPoint *pointById(int pointId) const = 0; |
| 458 | virtual QVector<QObject *> exclusiveGrabbers() const = 0; |
| 459 | virtual void clearGrabbers() const = 0; |
| 460 | virtual bool hasExclusiveGrabber(const QQuickPointerHandler *handler) const = 0; |
| 461 | |
| 462 | ulong timestamp() const { return m_event ? m_event->timestamp() : 0; } |
| 463 | |
| 464 | protected: |
| 465 | QQuickPointerDevice *m_device; |
| 466 | QInputEvent *m_event = nullptr; // original event as received by QQuickWindow |
| 467 | Qt::MouseButton m_button = Qt::NoButton; |
| 468 | Qt::MouseButtons m_pressedButtons; |
| 469 | |
| 470 | friend class QQuickWindowPrivate; |
| 471 | |
| 472 | Q_DISABLE_COPY(QQuickPointerEvent) |
| 473 | }; |
| 474 | |
| 475 | class Q_QUICK_PRIVATE_EXPORT QQuickSinglePointEvent : public QQuickPointerEvent |
| 476 | { |
| 477 | Q_OBJECT |
| 478 | public: |
| 479 | QQuickSinglePointEvent(QObject *parent, QQuickPointerDevice *device) |
| 480 | : QQuickPointerEvent(parent, device) { } |
| 481 | |
| 482 | void localize(QQuickItem *target) override; |
| 483 | int pointCount() const override { return 1; } |
| 484 | QQuickEventPoint *point(int i) const override; |
| 485 | QQuickEventPoint *pointById(int pointId) const override; |
| 486 | bool allPointsAccepted() const override; |
| 487 | bool allUpdatedPointsAccepted() const override; |
| 488 | bool allPointsGrabbed() const override; |
| 489 | QVector<QObject *> exclusiveGrabbers() const override; |
| 490 | void clearGrabbers() const override; |
| 491 | bool hasExclusiveGrabber(const QQuickPointerHandler *handler) const override; |
| 492 | |
| 493 | protected: |
| 494 | QQuickEventPoint *m_point = nullptr; |
| 495 | |
| 496 | Q_DISABLE_COPY(QQuickSinglePointEvent) |
| 497 | }; |
| 498 | |
| 499 | class Q_QUICK_PRIVATE_EXPORT QQuickPointerMouseEvent : public QQuickSinglePointEvent |
| 500 | { |
| 501 | Q_OBJECT |
| 502 | |
| 503 | QML_NAMED_ELEMENT(PointerMouseEvent) |
| 504 | QML_UNCREATABLE("PointerMouseEvent is only available as a parameter of several signals in PointerHandler" ) |
| 505 | QML_ADDED_IN_MINOR_VERSION(12) |
| 506 | |
| 507 | public: |
| 508 | QQuickPointerMouseEvent(QObject *parent, QQuickPointerDevice *device); |
| 509 | |
| 510 | QQuickPointerEvent *reset(QEvent *) override; |
| 511 | bool isPressEvent() const override; |
| 512 | bool isDoubleClickEvent() const override; |
| 513 | bool isUpdateEvent() const override; |
| 514 | bool isReleaseEvent() const override; |
| 515 | QQuickPointerMouseEvent *asPointerMouseEvent() override { return this; } |
| 516 | const QQuickPointerMouseEvent *asPointerMouseEvent() const override { return this; } |
| 517 | |
| 518 | QMouseEvent *asMouseEvent(const QPointF& localPos) const; |
| 519 | |
| 520 | Q_DISABLE_COPY(QQuickPointerMouseEvent) |
| 521 | }; |
| 522 | |
| 523 | class Q_QUICK_PRIVATE_EXPORT QQuickPointerTouchEvent : public QQuickPointerEvent |
| 524 | { |
| 525 | Q_OBJECT |
| 526 | |
| 527 | QML_NAMED_ELEMENT(PointerTouchEvent) |
| 528 | QML_UNCREATABLE("PointerTouchEvent is only available as a parameter of several signals in PointerHandler" ) |
| 529 | QML_ADDED_IN_MINOR_VERSION(12) |
| 530 | |
| 531 | public: |
| 532 | QQuickPointerTouchEvent(QObject *parent = nullptr, QQuickPointerDevice *device = nullptr) |
| 533 | : QQuickPointerEvent(parent, device) |
| 534 | , m_synthMouseEvent(QEvent::MouseMove, QPointF(), Qt::NoButton, Qt::NoButton, Qt::NoModifier) |
| 535 | {} |
| 536 | |
| 537 | QQuickPointerEvent *reset(QEvent *) override; |
| 538 | void localize(QQuickItem *target) override; |
| 539 | bool isPressEvent() const override; |
| 540 | bool isUpdateEvent() const override; |
| 541 | bool isReleaseEvent() const override; |
| 542 | QQuickPointerTouchEvent *asPointerTouchEvent() override { return this; } |
| 543 | const QQuickPointerTouchEvent *asPointerTouchEvent() const override { return this; } |
| 544 | int pointCount() const override { return m_pointCount; } |
| 545 | QQuickEventPoint *point(int i) const override; |
| 546 | QQuickEventPoint *pointById(int pointId) const override; |
| 547 | const QTouchEvent::TouchPoint *touchPointById(int pointId) const; |
| 548 | bool allPointsAccepted() const override; |
| 549 | bool allUpdatedPointsAccepted() const override; |
| 550 | bool allPointsGrabbed() const override; |
| 551 | QVector<QObject *> exclusiveGrabbers() const override; |
| 552 | void clearGrabbers() const override; |
| 553 | bool hasExclusiveGrabber(const QQuickPointerHandler *handler) const override; |
| 554 | |
| 555 | QMouseEvent *syntheticMouseEvent(int pointID, QQuickItem *relativeTo) const; |
| 556 | QTouchEvent *touchEventForItem(QQuickItem *item, bool isFiltering = false) const; |
| 557 | |
| 558 | QTouchEvent *asTouchEvent() const; |
| 559 | |
| 560 | private: |
| 561 | Qt::TouchPointStates touchPointStates() const; |
| 562 | |
| 563 | int m_pointCount = 0; |
| 564 | QVector<QQuickEventTouchPoint *> m_touchPoints; |
| 565 | mutable QMouseEvent m_synthMouseEvent; |
| 566 | |
| 567 | Q_DISABLE_COPY(QQuickPointerTouchEvent) |
| 568 | }; |
| 569 | |
| 570 | #if QT_CONFIG(tabletevent) |
| 571 | class Q_QUICK_PRIVATE_EXPORT QQuickEventTabletPoint : public QQuickEventPoint |
| 572 | { |
| 573 | Q_OBJECT |
| 574 | Q_PROPERTY(qreal rotation READ rotation) |
| 575 | Q_PROPERTY(qreal pressure READ pressure) |
| 576 | Q_PROPERTY(qreal tangentialPressure READ tangentialPressure) |
| 577 | Q_PROPERTY(QVector2D tilt READ tilt) |
| 578 | |
| 579 | QML_NAMED_ELEMENT(EventTabletPoint) |
| 580 | QML_UNCREATABLE("EventTouchPoint is only available as a member of PointerEvent." ) |
| 581 | QML_ADDED_IN_MINOR_VERSION(15) |
| 582 | |
| 583 | public: |
| 584 | QQuickEventTabletPoint(QQuickPointerTabletEvent *parent); |
| 585 | |
| 586 | void reset(const QTabletEvent *e); |
| 587 | |
| 588 | qreal rotation() const { return m_rotation; } |
| 589 | qreal pressure() const { return m_pressure; } |
| 590 | qreal tangentialPressure() const { return m_tangentialPressure; } |
| 591 | QVector2D tilt() const { return m_tilt; } |
| 592 | |
| 593 | private: |
| 594 | qreal m_rotation; |
| 595 | qreal m_pressure; |
| 596 | qreal m_tangentialPressure; |
| 597 | QVector2D m_tilt; |
| 598 | |
| 599 | friend class QQuickPointerTouchEvent; |
| 600 | |
| 601 | Q_DISABLE_COPY(QQuickEventTabletPoint) |
| 602 | }; |
| 603 | |
| 604 | class Q_QUICK_PRIVATE_EXPORT QQuickPointerTabletEvent : public QQuickSinglePointEvent |
| 605 | { |
| 606 | Q_OBJECT |
| 607 | public: |
| 608 | QQuickPointerTabletEvent(QObject *parent, QQuickPointerDevice *device); |
| 609 | |
| 610 | QQuickPointerEvent *reset(QEvent *) override; |
| 611 | bool isPressEvent() const override; |
| 612 | bool isUpdateEvent() const override; |
| 613 | bool isReleaseEvent() const override; |
| 614 | QQuickPointerTabletEvent *asPointerTabletEvent() override { return this; } |
| 615 | const QQuickPointerTabletEvent *asPointerTabletEvent() const override { return this; } |
| 616 | const QQuickEventTabletPoint *tabletPoint() const { return static_cast<QQuickEventTabletPoint *>(m_point); } |
| 617 | |
| 618 | QTabletEvent *asTabletEvent() const; |
| 619 | |
| 620 | Q_DISABLE_COPY(QQuickPointerTabletEvent) |
| 621 | }; |
| 622 | #endif // QT_CONFIG(tabletevent) |
| 623 | |
| 624 | #if QT_CONFIG(gestures) |
| 625 | class Q_QUICK_PRIVATE_EXPORT QQuickPointerNativeGestureEvent : public QQuickSinglePointEvent |
| 626 | { |
| 627 | Q_OBJECT |
| 628 | Q_PROPERTY(Qt::NativeGestureType type READ type CONSTANT) |
| 629 | Q_PROPERTY(qreal value READ value CONSTANT) |
| 630 | |
| 631 | public: |
| 632 | QQuickPointerNativeGestureEvent(QObject *parent, QQuickPointerDevice *device); |
| 633 | |
| 634 | QQuickPointerEvent *reset(QEvent *) override; |
| 635 | bool isPressEvent() const override; |
| 636 | bool isUpdateEvent() const override; |
| 637 | bool isReleaseEvent() const override; |
| 638 | QQuickPointerNativeGestureEvent *asPointerNativeGestureEvent() override { return this; } |
| 639 | const QQuickPointerNativeGestureEvent *asPointerNativeGestureEvent() const override { return this; } |
| 640 | Qt::NativeGestureType type() const; |
| 641 | qreal value() const; |
| 642 | |
| 643 | Q_DISABLE_COPY(QQuickPointerNativeGestureEvent) |
| 644 | }; |
| 645 | #endif // QT_CONFIG(gestures) |
| 646 | |
| 647 | class Q_QUICK_PRIVATE_EXPORT QQuickPointerScrollEvent : public QQuickSinglePointEvent |
| 648 | { |
| 649 | Q_OBJECT |
| 650 | Q_PROPERTY(QVector2D angleDelta READ angleDelta CONSTANT) |
| 651 | Q_PROPERTY(QVector2D pixelDelta READ pixelDelta CONSTANT) |
| 652 | Q_PROPERTY(bool hasAngleDelta READ hasAngleDelta CONSTANT) |
| 653 | Q_PROPERTY(bool hasPixelDelta READ hasPixelDelta CONSTANT) |
| 654 | Q_PROPERTY(bool inverted READ isInverted CONSTANT) |
| 655 | |
| 656 | QML_NAMED_ELEMENT(PointerScrollEvent) |
| 657 | QML_UNCREATABLE("PointerScrollEvent is only available via the WheelHandler::wheel signal." ) |
| 658 | QML_ADDED_IN_MINOR_VERSION(14) |
| 659 | |
| 660 | public: |
| 661 | QQuickPointerScrollEvent(QObject *parent, QQuickPointerDevice *device); |
| 662 | |
| 663 | QQuickPointerEvent *reset(QEvent *) override; |
| 664 | void localize(QQuickItem *target) override; |
| 665 | bool isPressEvent() const override; |
| 666 | bool isUpdateEvent() const override; |
| 667 | bool isReleaseEvent() const override; |
| 668 | QQuickPointerScrollEvent *asPointerScrollEvent() override { return this; } |
| 669 | const QQuickPointerScrollEvent *asPointerScrollEvent() const override { return this; } |
| 670 | QVector2D angleDelta() const { return m_angleDelta; } |
| 671 | QVector2D pixelDelta() const { return m_pixelDelta; } |
| 672 | bool hasAngleDelta() const { return !angleDelta().isNull(); } |
| 673 | bool hasPixelDelta() const { return !pixelDelta().isNull(); } |
| 674 | bool isInverted() const { return m_inverted; } |
| 675 | Qt::ScrollPhase phase() const { return m_phase; } |
| 676 | |
| 677 | private: |
| 678 | // TODO add QQuickPointerDevice source() whenever QInputEvent is extended to have a source device |
| 679 | // then maybe Qt::MouseEventSource synthSource() will be obsolete... that's why it's not public now |
| 680 | Qt::MouseEventSource synthSource() const { return m_synthSource; } |
| 681 | |
| 682 | private: |
| 683 | QVector2D m_angleDelta; |
| 684 | QVector2D m_pixelDelta; |
| 685 | Qt::ScrollPhase m_phase = Qt::NoScrollPhase; |
| 686 | Qt::MouseEventSource m_synthSource = Qt::MouseEventNotSynthesized; |
| 687 | bool m_inverted = false; |
| 688 | |
| 689 | friend class QQuickWindowPrivate; |
| 690 | friend class QQuickWheelHandler; |
| 691 | |
| 692 | Q_DISABLE_COPY(QQuickPointerScrollEvent) |
| 693 | }; |
| 694 | |
| 695 | |
| 696 | // ### Qt 6: move this to qtbase, replace QTouchDevice and the enums in QTabletEvent |
| 697 | class Q_QUICK_PRIVATE_EXPORT QQuickPointerDevice : public QObject |
| 698 | { |
| 699 | Q_OBJECT |
| 700 | Q_PROPERTY(DeviceType type READ type CONSTANT) |
| 701 | Q_PROPERTY(PointerType pointerType READ pointerType CONSTANT) |
| 702 | Q_PROPERTY(Capabilities capabilities READ capabilities CONSTANT) |
| 703 | Q_PROPERTY(int maximumTouchPoints READ maximumTouchPoints CONSTANT) |
| 704 | Q_PROPERTY(int buttonCount READ buttonCount CONSTANT) |
| 705 | Q_PROPERTY(QString name READ name CONSTANT) |
| 706 | Q_PROPERTY(QPointingDeviceUniqueId uniqueId READ uniqueId CONSTANT) |
| 707 | |
| 708 | QML_NAMED_ELEMENT(PointerDevice) |
| 709 | QML_UNCREATABLE("PointerDevice is only available as a property of PointerEvent." ) |
| 710 | QML_ADDED_IN_MINOR_VERSION(12) |
| 711 | |
| 712 | public: |
| 713 | enum DeviceType : qint16 { |
| 714 | UnknownDevice = 0x0000, |
| 715 | Mouse = 0x0001, |
| 716 | TouchScreen = 0x0002, |
| 717 | TouchPad = 0x0004, |
| 718 | Puck = 0x0008, |
| 719 | Stylus = 0x0010, |
| 720 | Airbrush = 0x0020, |
| 721 | AllDevices = 0x7FFF |
| 722 | }; |
| 723 | Q_DECLARE_FLAGS(DeviceTypes, DeviceType) |
| 724 | Q_FLAG(DeviceTypes) |
| 725 | |
| 726 | enum PointerType : qint16 { |
| 727 | GenericPointer = 0x0001, |
| 728 | Finger = 0x0002, |
| 729 | Pen = 0x0004, |
| 730 | Eraser = 0x0008, |
| 731 | Cursor = 0x0010, |
| 732 | AllPointerTypes = 0x7FFF |
| 733 | }; |
| 734 | Q_DECLARE_FLAGS(PointerTypes, PointerType) |
| 735 | Q_FLAG(PointerTypes) |
| 736 | |
| 737 | enum CapabilityFlag : qint16 { |
| 738 | Position = QTouchDevice::Position, |
| 739 | Area = QTouchDevice::Area, |
| 740 | Pressure = QTouchDevice::Pressure, |
| 741 | Velocity = QTouchDevice::Velocity, |
| 742 | MouseEmulation = QTouchDevice::MouseEmulation, |
| 743 | // some bits reserved in case we need more of QTouchDevice::Capabilities |
| 744 | Scroll = 0x0100, // mouse has a wheel, or there is OS-level scroll gesture recognition (dubious?) |
| 745 | Hover = 0x0200, |
| 746 | Rotation = 0x0400, |
| 747 | XTilt = 0x0800, |
| 748 | YTilt = 0x1000 |
| 749 | }; |
| 750 | Q_DECLARE_FLAGS(Capabilities, CapabilityFlag) |
| 751 | Q_FLAG(Capabilities) |
| 752 | |
| 753 | DeviceType type() const { return m_deviceType; } |
| 754 | PointerType pointerType() const { return m_pointerType; } |
| 755 | Capabilities capabilities() const { return static_cast<Capabilities>(m_capabilities); } |
| 756 | bool hasCapability(CapabilityFlag cap) { return m_capabilities & cap; } |
| 757 | int maximumTouchPoints() const { return m_maximumTouchPoints; } |
| 758 | int buttonCount() const { return m_buttonCount; } |
| 759 | QString name() const { return m_name; } |
| 760 | QPointingDeviceUniqueId uniqueId() const { return m_uniqueId; } |
| 761 | const QTouchDevice *qTouchDevice() const; |
| 762 | |
| 763 | static QQuickPointerDevice *touchDevice(const QTouchDevice *d); |
| 764 | static QList<QQuickPointerDevice *> touchDevices(); |
| 765 | static QQuickPointerDevice *genericMouseDevice(); |
| 766 | #if QT_CONFIG(tabletevent) |
| 767 | static QQuickPointerDevice *tabletDevice(const QTabletEvent *event); |
| 768 | #endif |
| 769 | |
| 770 | QVector<QQuickPointerHandler *> &eventDeliveryTargets() { return m_eventDeliveryTargets; } |
| 771 | |
| 772 | private: |
| 773 | QQuickPointerDevice(DeviceType devType, PointerType pType, Capabilities caps, int maxPoints, int buttonCount, const QString &name, qint64 uniqueId = 0) |
| 774 | : m_deviceType(devType), m_pointerType(pType), m_capabilities(static_cast<qint16>(caps)) |
| 775 | , m_maximumTouchPoints(static_cast<qint8>(maxPoints)), m_buttonCount(static_cast<qint8>(buttonCount)), m_name(name) |
| 776 | , m_uniqueId(QPointingDeviceUniqueId::fromNumericId(id: uniqueId)) |
| 777 | { |
| 778 | } |
| 779 | ~QQuickPointerDevice() override { } |
| 780 | |
| 781 | private: |
| 782 | // begin 64-bit field |
| 783 | DeviceType m_deviceType; |
| 784 | PointerType m_pointerType; |
| 785 | qint16 m_capabilities; |
| 786 | qint8 m_maximumTouchPoints; |
| 787 | qint8 m_buttonCount; |
| 788 | // end 64-bit field |
| 789 | QString m_name; |
| 790 | QPointingDeviceUniqueId m_uniqueId; |
| 791 | QVector<QQuickPointerHandler *> m_eventDeliveryTargets; // during delivery, handlers which have already seen the event |
| 792 | |
| 793 | Q_DISABLE_COPY(QQuickPointerDevice) |
| 794 | friend struct ConstructableQQuickPointerDevice; |
| 795 | }; |
| 796 | |
| 797 | Q_DECLARE_OPERATORS_FOR_FLAGS(QQuickPointerDevice::DeviceTypes) |
| 798 | Q_DECLARE_OPERATORS_FOR_FLAGS(QQuickPointerDevice::PointerTypes) |
| 799 | Q_DECLARE_OPERATORS_FOR_FLAGS(QQuickPointerDevice::Capabilities) |
| 800 | |
| 801 | Q_QUICK_PRIVATE_EXPORT QDebug operator<<(QDebug, const QQuickPointerDevice *); |
| 802 | Q_QUICK_PRIVATE_EXPORT QDebug operator<<(QDebug, const QQuickPointerEvent *); |
| 803 | Q_QUICK_PRIVATE_EXPORT QDebug operator<<(QDebug, const QQuickEventPoint *); |
| 804 | //Q_QUICK_PRIVATE_EXPORT QDebug operator<<(QDebug, const QQuickEventTouchPoint *); TODO maybe |
| 805 | |
| 806 | QT_END_NAMESPACE |
| 807 | |
| 808 | QML_DECLARE_TYPE(QQuickKeyEvent) |
| 809 | QML_DECLARE_TYPE(QQuickMouseEvent) |
| 810 | QML_DECLARE_TYPE(QQuickWheelEvent) |
| 811 | QML_DECLARE_TYPE(QQuickCloseEvent) |
| 812 | QML_DECLARE_TYPE(QQuickPointerDevice) |
| 813 | QML_DECLARE_TYPE(QPointingDeviceUniqueId) |
| 814 | QML_DECLARE_TYPE(QQuickPointerEvent) |
| 815 | Q_DECLARE_METATYPE(QQuickEventPoint::GrabTransition) |
| 816 | |
| 817 | #endif // QQUICKEVENTS_P_P_H |
| 818 | |