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 QtGui 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 QEVENT_P_H
41#define QEVENT_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 for the convenience
48// of other Qt classes. 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 <QtGui/private/qtguiglobal_p.h>
55#include <QtCore/qurl.h>
56#include <QtGui/qevent.h>
57#include <QtGui/qwindow.h>
58
59QT_BEGIN_NAMESPACE
60
61class QPointingDevice;
62
63struct QEventPointPrivate {
64 QEventPointPrivate(int id, const QPointingDevice *device)
65 : device(device), pointId(id) { }
66
67 QEventPointPrivate(int pointId, QEventPoint::State state, const QPointF &scenePosition, const QPointF &globalPosition)
68 : scenePos(scenePosition), globalPos(globalPosition), pointId(pointId), state(state)
69 {
70 if (state == QEventPoint::State::Released)
71 pressure = 0;
72 }
73 inline bool operator==(const QEventPointPrivate &other) const
74 {
75 return device == other.device
76 && window == other.window
77 && target == other.target
78 && pos == other.pos
79 && scenePos == other.scenePos
80 && globalPos == other.globalPos
81 && globalPressPos == other.globalPressPos
82 && globalGrabPos == other.globalGrabPos
83 && globalLastPos == other.globalLastPos
84 && pressure == other.pressure
85 && rotation == other.rotation
86 && ellipseDiameters == other.ellipseDiameters
87 && velocity == other.velocity
88 && timestamp == other.timestamp
89 && lastTimestamp == other.lastTimestamp
90 && pressTimestamp == other.pressTimestamp
91 && uniqueId == other.uniqueId
92 && pointId == other.pointId
93 && state == other.state;
94 }
95
96 const QPointingDevice *device = nullptr;
97 QPointer<QWindow> window;
98 QPointer<QObject> target;
99 QPointF pos, scenePos, globalPos,
100 globalPressPos, globalGrabPos, globalLastPos;
101 qreal pressure = 1;
102 qreal rotation = 0;
103 QSizeF ellipseDiameters = QSizeF(0, 0);
104 QVector2D velocity;
105 ulong timestamp = 0;
106 ulong lastTimestamp = 0;
107 ulong pressTimestamp = 0;
108 QPointingDeviceUniqueId uniqueId;
109 int refCount = 1;
110 int pointId = -1;
111 QEventPoint::State state = QEventPoint::State::Unknown;
112 bool accept = false;
113};
114
115// Private subclasses to allow accessing and modifying protected variables.
116// These should NOT hold any extra state.
117
118class Q_GUI_EXPORT QMutableEventPoint : public QEventPoint
119{
120public:
121 QMutableEventPoint(int pointId = -1, State state = QEventPoint::State::Stationary,
122 const QPointF &scenePosition = QPointF(), const QPointF &globalPosition = QPointF()) :
123 QEventPoint(pointId, state, scenePosition, globalPosition) {}
124
125 QMutableEventPoint(ulong timestamp, int pointId, State state,
126 const QPointF &position, const QPointF &scenePosition, const QPointF &globalPosition) :
127 QEventPoint(pointId, state, scenePosition, globalPosition)
128 {
129 d->timestamp = timestamp;
130 d->pos = position;
131 }
132
133 void updateFrom(const QEventPoint &other);
134
135 static QMutableEventPoint *from(QEventPoint *me) { return static_cast<QMutableEventPoint *>(me); }
136
137 static QMutableEventPoint &from(QEventPoint &me) { return static_cast<QMutableEventPoint &>(me); }
138
139 static const QMutableEventPoint &constFrom(const QEventPoint &me) { return static_cast<const QMutableEventPoint &>(me); }
140
141 void detach();
142
143 void setId(int pointId) { d->pointId = pointId; }
144
145 void setDevice(const QPointingDevice *device) { d->device = device; }
146
147 void setTimestamp(const ulong t);
148
149 void setPressTimestamp(const ulong t) { d->pressTimestamp = t; }
150
151 void setState(QEventPoint::State state) { d->state = state; }
152
153 void setUniqueId(const QPointingDeviceUniqueId &uid) { d->uniqueId = uid; }
154
155 void setPosition(const QPointF &pos) { d->pos = pos; }
156
157 void setScenePosition(const QPointF &pos) { d->scenePos = pos; }
158
159 void setGlobalPosition(const QPointF &pos) { d->globalPos = pos; }
160
161#if QT_DEPRECATED_SINCE(6, 0)
162 // temporary replacements for QTouchEvent::TouchPoint setters, mainly to make porting easier
163 QT_DEPRECATED_VERSION_X_6_0("Use setPosition()")
164 void setPos(const QPointF &pos) { d->pos = pos; }
165 QT_DEPRECATED_VERSION_X_6_0("Use setScenePosition()")
166 void setScenePos(const QPointF &pos) { d->scenePos = pos; }
167 QT_DEPRECATED_VERSION_X_6_0("Use setGlobalPosition()")
168 void setScreenPos(const QPointF &pos) { d->globalPos = pos; }
169#endif
170
171 void setGlobalPressPosition(const QPointF &pos) { d->globalPressPos = pos; }
172
173 void setGlobalGrabPosition(const QPointF &pos) { d->globalGrabPos = pos; }
174
175 void setGlobalLastPosition(const QPointF &pos) { d->globalLastPos = pos; }
176
177 void setEllipseDiameters(const QSizeF &diams) { d->ellipseDiameters = diams; }
178
179 void setPressure(qreal v) { d->pressure = v; }
180
181 void setRotation(qreal v) { d->rotation = v; }
182
183 void setVelocity(const QVector2D &v) { d->velocity = v; }
184
185 QWindow *window() const { return d->window.data(); }
186
187 void setWindow(const QPointer<QWindow> &w) { d->window = w; }
188
189 QObject *target() const { return d->target.data(); }
190
191 void setTarget(const QPointer<QObject> &t) { d->target = t; }
192};
193
194static_assert(sizeof(QMutableEventPoint) == sizeof(QEventPoint));
195
196class Q_GUI_EXPORT QMutableTouchEvent : public QTouchEvent
197{
198public:
199 QMutableTouchEvent(QEvent::Type eventType = QEvent::TouchBegin,
200 const QPointingDevice *device = nullptr,
201 Qt::KeyboardModifiers modifiers = Qt::NoModifier,
202 const QList<QEventPoint> &touchPoints = QList<QEventPoint>()) :
203 QTouchEvent(eventType, device, modifiers, touchPoints) { }
204
205 static QMutableTouchEvent *from(QTouchEvent *e) { return static_cast<QMutableTouchEvent *>(e); }
206
207 static QMutableTouchEvent &from(QTouchEvent &e) { return static_cast<QMutableTouchEvent &>(e); }
208
209 void setTarget(QObject *target) { m_target = target; }
210
211 void addPoint(const QEventPoint &point);
212};
213
214static_assert(sizeof(QMutableTouchEvent) == sizeof(QTouchEvent));
215
216class Q_GUI_EXPORT QMutableSinglePointEvent : public QSinglePointEvent
217{
218public:
219 QMutableSinglePointEvent(Type type, const QPointingDevice *device, const QEventPoint &point,
220 Qt::MouseButton button = Qt::NoButton, Qt::MouseButtons buttons = Qt::NoButton,
221 Qt::KeyboardModifiers modifiers = Qt::NoModifier,
222 Qt::MouseEventSource source = Qt::MouseEventSynthesizedByQt) :
223 QSinglePointEvent(type, device, point, button, buttons, modifiers, source) { }
224
225 static QMutableSinglePointEvent *from(QSinglePointEvent *e) { return static_cast<QMutableSinglePointEvent *>(e); }
226
227 static QMutableSinglePointEvent &from(QSinglePointEvent &e) { return static_cast<QMutableSinglePointEvent &>(e); }
228
229 QMutableEventPoint &mutablePoint() { return QMutableEventPoint::from(point(0)); }
230
231 void setSource(Qt::MouseEventSource s) { m_source = s; }
232
233 bool isDoubleClick() { return m_doubleClick; }
234
235 void setDoubleClick(bool d = true) { m_doubleClick = d; }
236};
237
238static_assert(sizeof(QMutableSinglePointEvent) == sizeof(QSinglePointEvent));
239
240QT_END_NAMESPACE
241
242#endif // QEVENT_P_H
243