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