Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qquickevents_p_p.h
Go to the documentation of this file.
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// Qt-Security score:significant reason:default
4
5#ifndef QQUICKEVENTS_P_P_H
6#define QQUICKEVENTS_P_P_H
7
8//
9// W A R N I N G
10// -------------
11//
12// This file is not part of the Qt API. It exists purely as an
13// implementation detail. This header file may change from version to
14// version without notice, or even be removed.
15//
16// We mean it.
17//
18
19#include <private/qtquickglobal_p.h>
20#include <qqml.h>
21
22#include <QtCore/qobject.h>
23#include <QtCore/qpointer.h>
24#include <QtGui/qevent.h>
25#include <QtGui/qpointingdevice.h>
26#include <QtGui/qvector2d.h>
27#include <QtQuick/qquickitem.h>
28
29#if QT_CONFIG(shortcut)
30# include <QtGui/qkeysequence.h>
31#endif
32
34
35class QPointingDevice;
36class QPointerEvent;
37class QMouseEvent;
38class QQuickPointerHandler;
39
40class Q_QUICK_EXPORT QQuickKeyEvent : public QObject
41{
42 Q_OBJECT
43 Q_PROPERTY(int key READ key CONSTANT FINAL)
44 Q_PROPERTY(QString text READ text CONSTANT FINAL)
45 Q_PROPERTY(int modifiers READ modifiers CONSTANT FINAL)
46 Q_PROPERTY(bool isAutoRepeat READ isAutoRepeat CONSTANT FINAL)
47 Q_PROPERTY(int count READ count CONSTANT FINAL)
48 Q_PROPERTY(quint32 nativeScanCode READ nativeScanCode CONSTANT FINAL)
49 Q_PROPERTY(bool accepted READ isAccepted WRITE setAccepted FINAL)
50 QML_NAMED_ELEMENT(KeyEvent)
51 QML_UNCREATABLE("Should only be used by signal handlers in the Keys attached property")
52 QML_ADDED_IN_VERSION(2, 0)
53
54public:
55 QQuickKeyEvent()
56 {}
57
58 void reset(QEvent::Type type, int key, Qt::KeyboardModifiers modifiers,
59 const QString &text = QString(), bool autorep = false, ushort count = 1)
60 {
61 m_type = type;
62 m_key = key;
63 m_modifiers = modifiers;
64 m_text = text;
65 m_autoRepeat = autorep;
66 m_count = count;
67 setAccepted(false);
68 }
69
70 void reset(const QKeyEvent &ke)
71 {
72 m_type = ke.type();
73 m_key = ke.key();
74 m_modifiers = ke.modifiers();
75 m_text = ke.text();
76 m_autoRepeat = ke.isAutoRepeat();
77 m_count = ke.count();
78 m_nativeScanCode = ke.nativeScanCode();
79 setAccepted(false);
80 }
81
82 int key() const { return m_key; }
83 QString text() const { return m_text; }
84 int modifiers() const { return m_modifiers; }
85 bool isAutoRepeat() const { return m_autoRepeat; }
86 int count() const { return m_count; }
87 quint32 nativeScanCode() const { return m_nativeScanCode; }
88
89 bool isAccepted() { return m_accepted; }
90 void setAccepted(bool accepted) { m_accepted = accepted; }
91
92#if QT_CONFIG(shortcut)
93 Q_REVISION(2, 2) Q_INVOKABLE bool matches(QKeySequence::StandardKey key) const;
94#endif
95
96private:
97 QString m_text;
98 quint32 m_nativeScanCode = 0;
99 QEvent::Type m_type = QEvent::None;
100 int m_key = 0;
101 int m_modifiers = 0;
102 int m_count = 0;
103 bool m_accepted = false;
104 bool m_autoRepeat = false;
105};
106
107class Q_QUICK_EXPORT QQuickMouseEvent : public QObject
108{
109 Q_OBJECT
110 Q_PROPERTY(qreal x READ x CONSTANT FINAL)
111 Q_PROPERTY(qreal y READ y CONSTANT FINAL)
112 Q_PROPERTY(int button READ button CONSTANT FINAL)
113 Q_PROPERTY(int buttons READ buttons CONSTANT FINAL)
114 Q_PROPERTY(int modifiers READ modifiers CONSTANT FINAL)
115#if QT_DEPRECATED_SINCE(6, 6)
116 Q_PROPERTY(int source READ source CONSTANT REVISION(2, 7) FINAL)
117#endif
118 Q_PROPERTY(bool isClick READ isClick CONSTANT FINAL)
119 Q_PROPERTY(bool wasHeld READ wasHeld CONSTANT FINAL)
120 Q_PROPERTY(bool accepted READ isAccepted WRITE setAccepted FINAL)
121 Q_PROPERTY(int flags READ flags CONSTANT REVISION(2, 11) FINAL)
122 QML_NAMED_ELEMENT(MouseEvent)
123 QML_UNCREATABLE("Should only be used by mouse event signal handlers, for example in MouseArea")
124 QML_ADDED_IN_VERSION(2, 0)
125
126public:
127 QQuickMouseEvent()
128 : _wasHeld(false), _isClick(false), _accepted(false)
129 {}
130
131 void reset(qreal x, qreal y, Qt::MouseButton button, Qt::MouseButtons buttons,
132 Qt::KeyboardModifiers modifiers, bool isClick = false, bool wasHeld = false,
133 Qt::MouseEventFlags flags = { })
134 {
135 _x = x;
136 _y = y;
137 _button = button;
138 _buttons = buttons;
139 _modifiers = modifiers;
140 _source = Qt::MouseEventNotSynthesized;
141 _wasHeld = wasHeld;
142 _isClick = isClick;
143 _accepted = true;
144 _flags = flags;
145 }
146
147 qreal x() const { return _x; }
148 qreal y() const { return _y; }
149 int button() const { return _button; }
150 int buttons() const { return _buttons; }
151 int modifiers() const { return _modifiers; }
152#if QT_DEPRECATED_SINCE(6, 6)
153 int source() const { return _source; }
154#endif
155 bool wasHeld() const { return _wasHeld; }
156 bool isClick() const { return _isClick; }
157
158 // only for internal usage
159 void setX(qreal x) { _x = x; }
160 void setY(qreal y) { _y = y; }
161 void setPosition(const QPointF &point) { _x = point.x(); _y = point.y(); }
162#if QT_DEPRECATED_SINCE(6, 6)
163 void setSource(Qt::MouseEventSource s) { _source = s; }
164#endif
165
166 bool isAccepted() { return _accepted; }
167 void setAccepted(bool accepted) { _accepted = accepted; }
168 int flags() const { return _flags; }
169private:
170 qreal _x = 0;
171 qreal _y = 0;
172 Qt::MouseButton _button = Qt::NoButton;
173 Qt::MouseButtons _buttons = Qt::NoButton;
174 Qt::KeyboardModifiers _modifiers = Qt::NoModifier;
175 Qt::MouseEventSource _source = Qt::MouseEventNotSynthesized;
176 bool _wasHeld : 1;
177 bool _isClick : 1;
178 bool _accepted : 1;
179 Qt::MouseEventFlags _flags = Qt::NoMouseEventFlag;
180};
181
182#if QT_CONFIG(wheelevent)
183class Q_QUICK_EXPORT QQuickWheelEvent : public QObject
184{
185 Q_OBJECT
186 Q_PROPERTY(const QPointingDevice *device READ pointingDevice CONSTANT FINAL)
187 Q_PROPERTY(qreal x READ x CONSTANT FINAL)
188 Q_PROPERTY(qreal y READ y CONSTANT FINAL)
189 Q_PROPERTY(QPoint angleDelta READ angleDelta CONSTANT FINAL)
190 Q_PROPERTY(QPoint pixelDelta READ pixelDelta CONSTANT FINAL)
191 Q_PROPERTY(Qt::ScrollPhase phase READ phase CONSTANT FINAL)
192 Q_PROPERTY(int buttons READ buttons CONSTANT FINAL)
193 Q_PROPERTY(int modifiers READ modifiers CONSTANT FINAL)
194 Q_PROPERTY(bool inverted READ inverted CONSTANT FINAL)
195 Q_PROPERTY(bool accepted READ isAccepted WRITE setAccepted FINAL)
196 QML_NAMED_ELEMENT(WheelEvent)
197 QML_UNCREATABLE("Should only be used by wheel event signal handlers, for example in MouseArea")
198 QML_ADDED_IN_VERSION(2, 0)
199
200public:
201 QQuickWheelEvent() = default;
202
203 void reset(const QWheelEvent *event)
204 {
205 _device = event->pointingDevice();
206 _x = event->position().x();
207 _y = event->position().y();
208 _angleDelta = event->angleDelta();
209 _pixelDelta = event->pixelDelta();
210 _buttons = event->buttons();
211 _modifiers = event->modifiers();
212 _accepted = true;
213 _inverted = event->inverted();
214 _phase = event->phase();
215 }
216
217 const QPointingDevice *pointingDevice() const { return _device; }
218 qreal x() const { return _x; }
219 qreal y() const { return _y; }
220 QPoint angleDelta() const { return _angleDelta; }
221 QPoint pixelDelta() const { return _pixelDelta; }
222 int buttons() const { return _buttons; }
223 int modifiers() const { return _modifiers; }
224 Qt::ScrollPhase phase() const { return _phase; }
225 bool inverted() const { return _inverted; }
226 bool isAccepted() { return _accepted; }
227 void setAccepted(bool accepted) { _accepted = accepted; }
228
229private:
230 const QPointingDevice *_device = nullptr;
231 qreal _x = 0;
232 qreal _y = 0;
233 QPoint _angleDelta;
234 QPoint _pixelDelta;
235 Qt::MouseButtons _buttons = Qt::NoButton;
236 Qt::KeyboardModifiers _modifiers = Qt::NoModifier;
237 Qt::ScrollPhase _phase = Qt::NoScrollPhase;
238 bool _inverted = false;
239 bool _accepted = false;
240};
241#endif
242
243class Q_QUICK_EXPORT QQuickCloseEvent : public QObject
244{
245 Q_OBJECT
246 Q_PROPERTY(bool accepted READ isAccepted WRITE setAccepted FINAL)
247 QML_NAMED_ELEMENT(CloseEvent)
248 QML_UNCREATABLE("Should only be used by Window's closing signal")
249 QML_ADDED_IN_VERSION(2, 0)
250
251public:
252 QQuickCloseEvent() {}
253
254 bool isAccepted() { return _accepted; }
255 void setAccepted(bool accepted) { _accepted = accepted; }
256
257private:
258 bool _accepted = true;
259};
260
261QT_END_NAMESPACE
262
263#endif // QQUICKEVENTS_P_P_H
\qmlsignal QtQuick::Window::sceneGraphError(SceneGraphError error, QString message)
\qmlproperty int QtQuick::KeyEvent::key