| 1 | // Copyright (C) 2020 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 QEVENTPOINT_P_H |
| 5 | #define QEVENTPOINT_P_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 for the convenience |
| 12 | // of other Qt classes. 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 <QtGui/private/qtguiglobal_p.h> |
| 19 | #include <QtGui/qevent.h> |
| 20 | |
| 21 | #include <QtCore/qloggingcategory.h> |
| 22 | #include <QtCore/qpointer.h> |
| 23 | |
| 24 | QT_BEGIN_NAMESPACE |
| 25 | |
| 26 | Q_DECLARE_LOGGING_CATEGORY(lcPointerVel); |
| 27 | Q_DECLARE_LOGGING_CATEGORY(lcEPDetach); |
| 28 | |
| 29 | class QPointingDevice; |
| 30 | |
| 31 | class QEventPointPrivate : public QSharedData |
| 32 | { |
| 33 | public: |
| 34 | QEventPointPrivate(int id, const QPointingDevice *device) |
| 35 | : device(device), pointId(id) { } |
| 36 | |
| 37 | QEventPointPrivate(int pointId, QEventPoint::State state, const QPointF &scenePosition, const QPointF &globalPosition) |
| 38 | : scenePos(scenePosition), globalPos(globalPosition), pointId(pointId), state(state) |
| 39 | { |
| 40 | if (state == QEventPoint::State::Released) |
| 41 | pressure = 0; |
| 42 | } |
| 43 | inline bool operator==(const QEventPointPrivate &other) const |
| 44 | { |
| 45 | return device == other.device |
| 46 | && window == other.window |
| 47 | && target == other.target |
| 48 | && pos == other.pos |
| 49 | && scenePos == other.scenePos |
| 50 | && globalPos == other.globalPos |
| 51 | && globalPressPos == other.globalPressPos |
| 52 | && globalGrabPos == other.globalGrabPos |
| 53 | && globalLastPos == other.globalLastPos |
| 54 | && pressure == other.pressure |
| 55 | && rotation == other.rotation |
| 56 | && ellipseDiameters == other.ellipseDiameters |
| 57 | && velocity == other.velocity |
| 58 | && timestamp == other.timestamp |
| 59 | && lastTimestamp == other.lastTimestamp |
| 60 | && pressTimestamp == other.pressTimestamp |
| 61 | && uniqueId == other.uniqueId |
| 62 | && pointId == other.pointId |
| 63 | && state == other.state; |
| 64 | } |
| 65 | |
| 66 | const QPointingDevice *device = nullptr; |
| 67 | QPointer<QWindow> window; |
| 68 | QPointer<QObject> target; |
| 69 | QPointF pos, scenePos, globalPos, |
| 70 | globalPressPos, globalGrabPos, globalLastPos; |
| 71 | qreal pressure = 1; |
| 72 | qreal rotation = 0; |
| 73 | QSizeF ellipseDiameters = QSizeF(0, 0); |
| 74 | QVector2D velocity; |
| 75 | ulong timestamp = 0; |
| 76 | ulong lastTimestamp = 0; |
| 77 | ulong pressTimestamp = 0; |
| 78 | QPointingDeviceUniqueId uniqueId; |
| 79 | int pointId = -1; |
| 80 | QEventPoint::State state = QEventPoint::State::Unknown; |
| 81 | bool accept = false; |
| 82 | }; |
| 83 | |
| 84 | // Private subclasses to allow accessing and modifying protected variables. |
| 85 | // These should NOT hold any extra state. |
| 86 | |
| 87 | class QMutableEventPoint |
| 88 | { |
| 89 | public: |
| 90 | static QEventPoint withTimeStamp(ulong timestamp, int pointId, QEventPoint::State state, |
| 91 | QPointF position, QPointF scenePosition, QPointF globalPosition) |
| 92 | { |
| 93 | QEventPoint p(pointId, state, scenePosition, globalPosition); |
| 94 | p.d->timestamp = timestamp; |
| 95 | p.d->pos = position; |
| 96 | return p; |
| 97 | } |
| 98 | |
| 99 | static Q_GUI_EXPORT void update(const QEventPoint &from, QEventPoint &to); |
| 100 | |
| 101 | static Q_GUI_EXPORT void detach(QEventPoint &p); |
| 102 | |
| 103 | #define TRIVIAL_SETTER(type, field, Field) \ |
| 104 | static void set##Field (QEventPoint &p, type arg) { p.d->field = std::move(arg); } \ |
| 105 | /* end */ |
| 106 | |
| 107 | TRIVIAL_SETTER(int, pointId, Id) |
| 108 | TRIVIAL_SETTER(const QPointingDevice *, device, Device) |
| 109 | |
| 110 | // not trivial: |
| 111 | static Q_GUI_EXPORT void setTimestamp(QEventPoint &p, ulong t); |
| 112 | |
| 113 | TRIVIAL_SETTER(ulong, pressTimestamp, PressTimestamp) |
| 114 | TRIVIAL_SETTER(QEventPoint::State, state, State) |
| 115 | TRIVIAL_SETTER(QPointingDeviceUniqueId, uniqueId, UniqueId) |
| 116 | TRIVIAL_SETTER(QPointF, pos, Position) |
| 117 | TRIVIAL_SETTER(QPointF, scenePos, ScenePosition) |
| 118 | TRIVIAL_SETTER(QPointF, globalPos, GlobalPosition) |
| 119 | |
| 120 | TRIVIAL_SETTER(QPointF, globalPressPos, GlobalPressPosition) |
| 121 | TRIVIAL_SETTER(QPointF, globalGrabPos, GlobalGrabPosition) |
| 122 | TRIVIAL_SETTER(QPointF, globalLastPos, GlobalLastPosition) |
| 123 | TRIVIAL_SETTER(QSizeF, ellipseDiameters, EllipseDiameters) |
| 124 | TRIVIAL_SETTER(qreal, pressure, Pressure) |
| 125 | TRIVIAL_SETTER(qreal, rotation, Rotation) |
| 126 | TRIVIAL_SETTER(QVector2D, velocity, Velocity) |
| 127 | |
| 128 | static QWindow *window(const QEventPoint &p) { return p.d->window.data(); } |
| 129 | |
| 130 | TRIVIAL_SETTER(QWindow *, window, Window) |
| 131 | |
| 132 | static QObject *target(const QEventPoint &p) { return p.d->target.data(); } |
| 133 | |
| 134 | TRIVIAL_SETTER(QObject *, target, Target) |
| 135 | |
| 136 | #undef TRIVIAL_SETTER |
| 137 | }; |
| 138 | |
| 139 | QT_END_NAMESPACE |
| 140 | |
| 141 | #endif // QEVENTPOINT_P_H |
| 142 | |