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