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 QQUICKEVENTS_P_P_H
5#define QQUICKEVENTS_P_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 purely as an
12// implementation detail. 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 <private/qtquickglobal_p.h>
19#include <qqml.h>
20
21#include <QtCore/qobject.h>
22#include <QtCore/qpointer.h>
23#include <QtGui/qevent.h>
24#include <QtGui/qpointingdevice.h>
25#include <QtGui/qvector2d.h>
26#include <QtQuick/qquickitem.h>
27
28#if QT_CONFIG(shortcut)
29# include <QtGui/qkeysequence.h>
30#endif
31
32QT_BEGIN_NAMESPACE
33
34class QPointingDevice;
35class QPointerEvent;
36class QMouseEvent;
37class QQuickPointerHandler;
38
39class Q_QUICK_PRIVATE_EXPORT QQuickKeyEvent : public QObject
40{
41 Q_OBJECT
42 Q_PROPERTY(int key READ key CONSTANT FINAL)
43 Q_PROPERTY(QString text READ text CONSTANT FINAL)
44 Q_PROPERTY(int modifiers READ modifiers CONSTANT FINAL)
45 Q_PROPERTY(bool isAutoRepeat READ isAutoRepeat CONSTANT FINAL)
46 Q_PROPERTY(int count READ count CONSTANT FINAL)
47 Q_PROPERTY(quint32 nativeScanCode READ nativeScanCode CONSTANT FINAL)
48 Q_PROPERTY(bool accepted READ isAccepted WRITE setAccepted FINAL)
49 QML_ANONYMOUS
50 QML_ADDED_IN_VERSION(2, 0)
51
52public:
53 QQuickKeyEvent()
54 {}
55
56 void reset(QEvent::Type type, int key, Qt::KeyboardModifiers modifiers,
57 const QString &text = QString(), bool autorep = false, ushort count = 1)
58 {
59 m_type = type;
60 m_key = key;
61 m_modifiers = modifiers;
62 m_text = text;
63 m_autoRepeat = autorep;
64 m_count = count;
65 setAccepted(false);
66 }
67
68 void reset(const QKeyEvent &ke)
69 {
70 m_type = ke.type();
71 m_key = ke.key();
72 m_modifiers = ke.modifiers();
73 m_text = ke.text();
74 m_autoRepeat = ke.isAutoRepeat();
75 m_count = ke.count();
76 m_nativeScanCode = ke.nativeScanCode();
77 setAccepted(false);
78 }
79
80 int key() const { return m_key; }
81 QString text() const { return m_text; }
82 int modifiers() const { return m_modifiers; }
83 bool isAutoRepeat() const { return m_autoRepeat; }
84 int count() const { return m_count; }
85 quint32 nativeScanCode() const { return m_nativeScanCode; }
86
87 bool isAccepted() { return m_accepted; }
88 void setAccepted(bool accepted) { m_accepted = accepted; }
89
90#if QT_CONFIG(shortcut)
91 Q_REVISION(2, 2) Q_INVOKABLE bool matches(QKeySequence::StandardKey key) const;
92#endif
93
94private:
95 QString m_text;
96 quint32 m_nativeScanCode = 0;
97 QEvent::Type m_type = QEvent::None;
98 int m_key = 0;
99 int m_modifiers = 0;
100 int m_count = 0;
101 bool m_accepted = false;
102 bool m_autoRepeat = false;
103};
104
105class Q_QUICK_PRIVATE_EXPORT QQuickMouseEvent : public QObject
106{
107 Q_OBJECT
108 Q_PROPERTY(qreal x READ x CONSTANT FINAL)
109 Q_PROPERTY(qreal y READ y CONSTANT FINAL)
110 Q_PROPERTY(int button READ button CONSTANT FINAL)
111 Q_PROPERTY(int buttons READ buttons CONSTANT FINAL)
112 Q_PROPERTY(int modifiers READ modifiers CONSTANT FINAL)
113#if QT_DEPRECATED_SINCE(6, 6)
114 Q_PROPERTY(int source READ source CONSTANT REVISION(2, 7) FINAL)
115#endif
116 Q_PROPERTY(bool wasHeld READ wasHeld CONSTANT FINAL)
117 Q_PROPERTY(bool isClick READ isClick CONSTANT FINAL)
118 Q_PROPERTY(bool accepted READ isAccepted WRITE setAccepted FINAL)
119 Q_PROPERTY(int flags READ flags CONSTANT REVISION(2, 11) FINAL)
120 QML_ANONYMOUS
121 QML_ADDED_IN_VERSION(2, 0)
122
123public:
124 QQuickMouseEvent()
125 : _wasHeld(false), _isClick(false), _accepted(false)
126 {}
127
128 void reset(qreal x, qreal y, Qt::MouseButton button, Qt::MouseButtons buttons,
129 Qt::KeyboardModifiers modifiers, bool isClick = false, bool wasHeld = false,
130 Qt::MouseEventFlags flags = { })
131 {
132 _x = x;
133 _y = y;
134 _button = button;
135 _buttons = buttons;
136 _modifiers = modifiers;
137 _source = Qt::MouseEventNotSynthesized;
138 _wasHeld = wasHeld;
139 _isClick = isClick;
140 _accepted = true;
141 _flags = flags;
142 }
143
144 qreal x() const { return _x; }
145 qreal y() const { return _y; }
146 int button() const { return _button; }
147 int buttons() const { return _buttons; }
148 int modifiers() const { return _modifiers; }
149#if QT_DEPRECATED_SINCE(6, 6)
150 int source() const { return _source; }
151#endif
152 bool wasHeld() const { return _wasHeld; }
153 bool isClick() const { return _isClick; }
154
155 // only for internal usage
156 void setX(qreal x) { _x = x; }
157 void setY(qreal y) { _y = y; }
158 void setPosition(const QPointF &point) { _x = point.x(); _y = point.y(); }
159#if QT_DEPRECATED_SINCE(6, 6)
160 void setSource(Qt::MouseEventSource s) { _source = s; }
161#endif
162
163 bool isAccepted() { return _accepted; }
164 void setAccepted(bool accepted) { _accepted = accepted; }
165 int flags() const { return _flags; }
166private:
167 qreal _x = 0;
168 qreal _y = 0;
169 Qt::MouseButton _button = Qt::NoButton;
170 Qt::MouseButtons _buttons = Qt::NoButton;
171 Qt::KeyboardModifiers _modifiers = Qt::NoModifier;
172 Qt::MouseEventSource _source = Qt::MouseEventNotSynthesized;
173 bool _wasHeld : 1;
174 bool _isClick : 1;
175 bool _accepted : 1;
176 Qt::MouseEventFlags _flags = Qt::NoMouseEventFlag;
177};
178
179#if QT_CONFIG(wheelevent)
180class Q_QUICK_PRIVATE_EXPORT QQuickWheelEvent : public QObject
181{
182 Q_OBJECT
183 Q_PROPERTY(const QPointingDevice *device READ pointingDevice CONSTANT FINAL)
184 Q_PROPERTY(qreal x READ x CONSTANT FINAL)
185 Q_PROPERTY(qreal y READ y CONSTANT FINAL)
186 Q_PROPERTY(QPoint angleDelta READ angleDelta CONSTANT FINAL)
187 Q_PROPERTY(QPoint pixelDelta READ pixelDelta CONSTANT FINAL)
188 Q_PROPERTY(Qt::ScrollPhase phase READ phase CONSTANT FINAL)
189 Q_PROPERTY(int buttons READ buttons CONSTANT FINAL)
190 Q_PROPERTY(int modifiers READ modifiers CONSTANT FINAL)
191 Q_PROPERTY(bool inverted READ inverted CONSTANT FINAL)
192 Q_PROPERTY(bool accepted READ isAccepted WRITE setAccepted FINAL)
193 QML_ANONYMOUS
194 QML_ADDED_IN_VERSION(2, 0)
195
196public:
197 QQuickWheelEvent() = default;
198
199 void reset(const QWheelEvent *event)
200 {
201 _device = event->pointingDevice();
202 _x = event->position().x();
203 _y = event->position().y();
204 _angleDelta = event->angleDelta();
205 _pixelDelta = event->pixelDelta();
206 _buttons = event->buttons();
207 _modifiers = event->modifiers();
208 _accepted = true;
209 _inverted = event->inverted();
210 _phase = event->phase();
211 }
212
213 const QPointingDevice *pointingDevice() const { return _device; }
214 qreal x() const { return _x; }
215 qreal y() const { return _y; }
216 QPoint angleDelta() const { return _angleDelta; }
217 QPoint pixelDelta() const { return _pixelDelta; }
218 int buttons() const { return _buttons; }
219 int modifiers() const { return _modifiers; }
220 Qt::ScrollPhase phase() const { return _phase; }
221 bool inverted() const { return _inverted; }
222 bool isAccepted() { return _accepted; }
223 void setAccepted(bool accepted) { _accepted = accepted; }
224
225private:
226 const QPointingDevice *_device = nullptr;
227 qreal _x = 0;
228 qreal _y = 0;
229 QPoint _angleDelta;
230 QPoint _pixelDelta;
231 Qt::MouseButtons _buttons = Qt::NoButton;
232 Qt::KeyboardModifiers _modifiers = Qt::NoModifier;
233 Qt::ScrollPhase _phase = Qt::NoScrollPhase;
234 bool _inverted = false;
235 bool _accepted = false;
236};
237#endif
238
239class Q_QUICK_PRIVATE_EXPORT QQuickCloseEvent : public QObject
240{
241 Q_OBJECT
242 Q_PROPERTY(bool accepted READ isAccepted WRITE setAccepted FINAL)
243 QML_ANONYMOUS
244 QML_ADDED_IN_VERSION(2, 0)
245
246public:
247 QQuickCloseEvent() {}
248
249 bool isAccepted() { return _accepted; }
250 void setAccepted(bool accepted) { _accepted = accepted; }
251
252private:
253 bool _accepted = true;
254};
255
256QT_END_NAMESPACE
257
258QML_DECLARE_TYPE(QQuickKeyEvent)
259QML_DECLARE_TYPE(QQuickMouseEvent)
260#if QT_CONFIG(wheelevent)
261QML_DECLARE_TYPE(QQuickWheelEvent)
262#endif
263QML_DECLARE_TYPE(QQuickCloseEvent)
264QML_DECLARE_TYPE(QPointingDevice)
265QML_DECLARE_TYPE(QPointingDeviceUniqueId)
266QML_DECLARE_TYPE(QPointerEvent)
267
268#endif // QQUICKEVENTS_P_P_H
269

source code of qtdeclarative/src/quick/items/qquickevents_p_p.h