Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
qwasmevent.h
Go to the documentation of this file.
1// Copyright (C) 2022 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
3
4#ifndef QWASMEVENT_H
5#define QWASMEVENT_H
6
7#include "qwasmplatform.h"
8#include "qwasmdom.h"
9
10#include <QtCore/qglobal.h>
11#include <QtCore/qnamespace.h>
12#include <QtGui/qevent.h>
13#include <private/qstdweb_p.h>
14#include <QPoint>
15
16#include <emscripten/html5.h>
17#include <emscripten/val.h>
18
20
22class QWindow;
23
24enum class EventType {
25 DragEnd,
28 Drop,
29 KeyDown,
30 KeyUp,
37 Wheel,
38};
39
40enum class PointerType {
41 Mouse,
42 Touch,
43 Pen,
44 Other,
45};
46
47enum class WindowArea {
49 Client,
50};
51
52enum class DeltaMode { Pixel, Line, Page };
53
54namespace KeyboardModifier {
55namespace internal
56{
57 // Check for the existence of shiftKey, ctrlKey, altKey and metaKey in a type.
58 // Based on that, we can safely assume we are dealing with an emscripten event type.
59 template<typename T>
61 {
62 template<typename U, EM_BOOL U::*, EM_BOOL U::*, EM_BOOL U::*, EM_BOOL U::*>
63 struct SFINAE {};
64 template<typename U> static char Test(
65 SFINAE<U, &U::shiftKey, &U::ctrlKey, &U::altKey, &U::metaKey>*);
66 template<typename U> static int Test(...);
67 static const bool value = sizeof(Test<T>(0)) == sizeof(char);
68 };
69
70 template<class T, typename Enable = void>
71 struct Helper;
72
73 template<class T>
74 struct Helper<T, std::enable_if_t<IsEmscriptenEvent<T>::value>>
75 {
76 static QFlags<Qt::KeyboardModifier> getModifierForEvent(const T& event) {
77 QFlags<Qt::KeyboardModifier> keyModifier = Qt::NoModifier;
78 if (event.shiftKey)
79 keyModifier |= Qt::ShiftModifier;
80 if (event.ctrlKey)
82 if (event.altKey)
83 keyModifier |= Qt::AltModifier;
84 if (event.metaKey)
86
87 return keyModifier;
88 }
89 };
90
91 template<>
93 {
94 static QFlags<Qt::KeyboardModifier> getModifierForEvent(const emscripten::val& event) {
95 QFlags<Qt::KeyboardModifier> keyModifier = Qt::NoModifier;
96 if (event["shiftKey"].as<bool>())
97 keyModifier |= Qt::ShiftModifier;
98 if (event["ctrlKey"].as<bool>())
100 if (event["altKey"].as<bool>())
101 keyModifier |= Qt::AltModifier;
102 if (event["metaKey"].as<bool>())
104 if (event["constructor"]["name"].as<std::string>() == "KeyboardEvent" &&
105 event["location"].as<unsigned int>() == DOM_KEY_LOCATION_NUMPAD) {
106 keyModifier |= Qt::KeypadModifier;
107 }
108
109 return keyModifier;
110 }
111 };
112} // namespace internal
113
114template <typename Event>
115QFlags<Qt::KeyboardModifier> getForEvent(const Event& event)
116{
118}
119
120template <>
121QFlags<Qt::KeyboardModifier> getForEvent<EmscriptenKeyboardEvent>(
122 const EmscriptenKeyboardEvent& event);
123
124} // namespace KeyboardModifier
125
126struct Event
127{
128 Event(EventType type, emscripten::val webEvent);
134
135 emscripten::val webEvent;
137 emscripten::val target() const { return webEvent["target"]; }
138};
139
140struct KeyEvent : public Event
141{
142 static std::optional<KeyEvent>
143 fromWebWithDeadKeyTranslation(emscripten::val webEvent, QWasmDeadKeySupport *deadKeySupport);
144
145 KeyEvent(EventType type, emscripten::val webEvent);
151
153 QFlags<Qt::KeyboardModifier> modifiers;
156};
157
158struct MouseEvent : public Event
159{
160 MouseEvent(EventType type, emscripten::val webEvent);
166
167 static constexpr Qt::MouseButton buttonFromWeb(int webButton) {
168 switch (webButton) {
169 case 0:
170 return Qt::LeftButton;
171 case 1:
172 return Qt::MiddleButton;
173 case 2:
174 return Qt::RightButton;
175 default:
176 return Qt::NoButton;
177 }
178 }
179
180 static constexpr Qt::MouseButtons buttonsFromWeb(unsigned short webButtons) {
181 // Coincidentally, Qt and web bitfields match.
182 return Qt::MouseButtons::fromInt(webButtons);
183 }
184
186 EventType eventType, WindowArea windowArea) {
187 switch (eventType) {
189 return windowArea == WindowArea::Client ?
192 return windowArea == WindowArea::Client ?
195 return windowArea == WindowArea::Client ?
197 default:
198 return QEvent::None;
199 }
200 }
201
206 Qt::MouseButtons mouseButtons;
207 QFlags<Qt::KeyboardModifier> modifiers;
208};
209
232
233struct DragEvent : public MouseEvent
234{
235 static std::optional<DragEvent> fromWeb(emscripten::val webEvent, QWindow *targetQWindow);
236
237 DragEvent(EventType type, emscripten::val webEvent, QWindow *targetQWindow);
243
244 void cancelDragStart();
245 void acceptDragOver();
246 void acceptDrop();
247
251};
252
268
270
271#endif // QWASMEVENT_H
Type
This enum type defines the valid event types in Qt.
Definition qcoreevent.h:51
@ MouseMove
Definition qcoreevent.h:63
@ MouseButtonPress
Definition qcoreevent.h:60
@ NonClientAreaMouseMove
Definition qcoreevent.h:212
@ NonClientAreaMouseButtonRelease
Definition qcoreevent.h:214
@ NonClientAreaMouseButtonPress
Definition qcoreevent.h:213
@ MouseButtonRelease
Definition qcoreevent.h:61
\inmodule QtCore\reentrant
Definition qpoint.h:217
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:129
\inmodule QtGui
Definition qwindow.h:63
QFlags< Qt::KeyboardModifier > getForEvent< EmscriptenKeyboardEvent >(const EmscriptenKeyboardEvent &event)
QFlags< Qt::KeyboardModifier > getForEvent(const Event &event)
Definition qwasmevent.h:115
Combined button and popup list for selecting options.
MouseButton
Definition qnamespace.h:56
@ LeftButton
Definition qnamespace.h:58
@ RightButton
Definition qnamespace.h:59
@ MiddleButton
Definition qnamespace.h:60
@ NoButton
Definition qnamespace.h:57
@ ShiftModifier
@ ControlModifier
@ MetaModifier
@ KeypadModifier
@ NoModifier
@ AltModifier
DropAction
EGLOutputLayerEXT EGLint EGLAttrib value
[5]
GLenum type
struct _cl_event * event
GLuint GLfloat * val
double qreal
Definition qtypes.h:187
DeltaMode
Definition qwasmevent.h:52
PointerType
Definition qwasmevent.h:40
EventType
Definition qwasmevent.h:24
WindowArea
Definition qwasmevent.h:47
QT_BEGIN_NAMESPACE Platform platform()
QSharedPointer< T > other(t)
[5]
DragEvent & operator=(const DragEvent &other)
DragEvent(EventType type, emscripten::val webEvent, QWindow *targetQWindow)
void acceptDrop()
void acceptDragOver()
void cancelDragStart()
DragEvent(const DragEvent &other)
QWindow * targetWindow
Definition qwasmevent.h:250
DragEvent(DragEvent &&other)
static std::optional< DragEvent > fromWeb(emscripten::val webEvent, QWindow *targetQWindow)
dom::DataTransfer dataTransfer
Definition qwasmevent.h:249
Qt::DropAction dropAction
Definition qwasmevent.h:248
DragEvent & operator=(DragEvent &&other)
emscripten::val webEvent
Definition qwasmevent.h:135
Event & operator=(const Event &other)
Event & operator=(Event &&other)
Event(const Event &other)
emscripten::val target() const
Definition qwasmevent.h:137
EventType type
Definition qwasmevent.h:136
Event(Event &&other)
KeyEvent(KeyEvent &&other)
KeyEvent & operator=(const KeyEvent &other)
bool deadKey
Definition qwasmevent.h:154
QString text
Definition qwasmevent.h:155
static std::optional< KeyEvent > fromWebWithDeadKeyTranslation(emscripten::val webEvent, QWasmDeadKeySupport *deadKeySupport)
Qt::Key key
Definition qwasmevent.h:152
KeyEvent(EventType type, emscripten::val webEvent)
KeyEvent & operator=(KeyEvent &&other)
KeyEvent(const KeyEvent &other)
QFlags< Qt::KeyboardModifier > modifiers
Definition qwasmevent.h:153
static QFlags< Qt::KeyboardModifier > getModifierForEvent(const T &event)
Definition qwasmevent.h:76
static QFlags< Qt::KeyboardModifier > getModifierForEvent(const emscripten::val &event)
Definition qwasmevent.h:94
static char Test(SFINAE< U, &U::shiftKey, &U::ctrlKey, &U::altKey, &U::metaKey > *)
static constexpr Qt::MouseButton buttonFromWeb(int webButton)
Definition qwasmevent.h:167
MouseEvent(MouseEvent &&other)
QPointF localPoint
Definition qwasmevent.h:202
static constexpr QEvent::Type mouseEventTypeFromEventType(EventType eventType, WindowArea windowArea)
Definition qwasmevent.h:185
QFlags< Qt::KeyboardModifier > modifiers
Definition qwasmevent.h:207
MouseEvent(const MouseEvent &other)
QPointF pointInViewport
Definition qwasmevent.h:204
Qt::MouseButton mouseButton
Definition qwasmevent.h:205
static constexpr Qt::MouseButtons buttonsFromWeb(unsigned short webButtons)
Definition qwasmevent.h:180
Qt::MouseButtons mouseButtons
Definition qwasmevent.h:206
QPointF pointInPage
Definition qwasmevent.h:203
MouseEvent(EventType type, emscripten::val webEvent)
MouseEvent & operator=(MouseEvent &&other)
MouseEvent & operator=(const MouseEvent &other)
PointerType pointerType
Definition qwasmevent.h:221
PointerEvent(const PointerEvent &other)
PointerEvent(PointerEvent &&other)
PointerEvent(EventType type, emscripten::val webEvent)
static std::optional< PointerEvent > fromWeb(emscripten::val webEvent)
PointerEvent & operator=(PointerEvent &&other)
qreal tangentialPressure
Definition qwasmevent.h:226
PointerEvent & operator=(const PointerEvent &other)
WheelEvent & operator=(WheelEvent &&other)
WheelEvent(const WheelEvent &other)
static std::optional< WheelEvent > fromWeb(emscripten::val webEvent)
DeltaMode deltaMode
Definition qwasmevent.h:264
WheelEvent(WheelEvent &&other)
WheelEvent(EventType type, emscripten::val webEvent)
bool webkitDirectionInvertedFromDevice
Definition qwasmevent.h:265
WheelEvent & operator=(const WheelEvent &other)
QPointF delta
Definition qwasmevent.h:266