1// Copyright (C) 2015 Klaralvdalens Datakonsult AB (KDAB).
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4#include "qmouseevent.h"
5
6QT_BEGIN_NAMESPACE
7
8namespace Qt3DInput {
9
10namespace {
11
12template<typename EventClass, typename QtEventClass>
13typename EventClass::Modifiers modifiersForEvent(const QtEventClass *event)
14{
15 const Qt::KeyboardModifiers eventModifiers = event->modifiers();
16 int modifiers = EventClass::NoModifier;
17
18 if (eventModifiers & Qt::ShiftModifier)
19 modifiers |= EventClass::ShiftModifier;
20
21 if (eventModifiers & Qt::ControlModifier)
22 modifiers |= EventClass::ControlModifier;
23
24 if (eventModifiers & Qt::AltModifier)
25 modifiers |= EventClass::AltModifier;
26
27 if (eventModifiers & Qt::MetaModifier)
28 modifiers |= EventClass::MetaModifier;
29
30 if (eventModifiers & Qt::KeypadModifier)
31 modifiers |= EventClass::KeypadModifier;
32
33 // Abuse the int used to store an enum to store multiple
34 // modifiers into one
35 return static_cast<typename EventClass::Modifiers>(modifiers);
36}
37
38} // anonymous
39
40// Notes:
41// Maybe we should provide the world pos of the intersection
42// The distance t along the segment line at which the intersection occurs
43// Screen Pos / Mouse Pos / Viewport Pos
44// The intersection Ray
45// These can always be added in follow up commits once the input API takes shape
46
47/*!
48 * \qmltype MouseEvent
49 * \instantiates Qt3DInput::QMouseEvent
50 * \inqmlmodule Qt3D.Input
51 * \since 5.5
52 * \brief Provides parameters that describe a mouse event.
53 *
54 * Mouse events occur when a mouse button is pressed and the ray
55 * traversing the view, originating from the mouse position intersects with one
56 * or more elements of the scene.
57 *
58 * \sa KeyEvent, WheelEvent, MouseHandler
59 */
60
61/*!
62 * \qmlproperty int Qt3D.Input::MouseEvent::x
63 * Specifies The X coordinate of the mouse event
64 * \readonly
65 */
66
67/*!
68 * \qmlproperty int Qt3D.Input::MouseEvent::y
69 * Specifies The Y coordinate of the mouse event
70 * \readonly
71 */
72
73/*!
74 * \qmlproperty bool Qt3D.Input::MouseEvent::wasHeld
75 * Specifies if a mouse button was held down during the mouse event
76 * \readonly
77 */
78
79/*!
80 * \qmlproperty Buttons Qt3D.Input::MouseEvent::button
81 * Specifies the button triggering the mouse event
82 * \readonly
83 */
84
85/*!
86 * \qmlproperty int Qt3D.Input::MouseEvent::buttons
87 * Specifies the button triggering the mouse event
88 * \readonly
89 */
90
91/*!
92 * \qmlproperty Modifiers Qt3D.Input::MouseEvent::modifiers
93 * Specifies if any modifiers were applied to the mouse event
94 * \readonly
95 */
96
97/*!
98 * \qmlproperty bool Qt3D.Input::MouseEvent::accepted
99 * Specifies if the mouse event has been accepted
100 */
101
102/*!
103 * \class Qt3DInput::QMouseEvent
104 * \inheaderfile Qt3DInput/QMouseEvent
105 * \inmodule Qt3DInput
106 *
107 * \brief The Qt3DCore::QMouseEvent contains parameters that describe a mouse event.
108 *
109 * Mouse events occur when a mouse button is pressed and the ray
110 * traversing the view, originating from the mouse position intersects with one
111 * or more elements of the scene.
112 *
113 * \since 5.5
114 *
115 * \sa QKeyEvent, QWheelEvent, QMouseHandler
116 *
117 */
118
119/*!
120 * \property QMouseEvent::x
121 * Specifies The X coordinate of the mouse event
122 * \readonly
123 */
124
125/*!
126 * \property QMouseEvent::y
127 * Specifies The y coordinate of the mouse event
128 * \readonly
129 */
130
131/*!
132 * \property QMouseEvent::wasHeld
133 * Specifies if a mouse button was held down during the mouse event
134 * \readonly
135 */
136
137/*!
138 * \property QMouseEvent::button
139 * Specifies the button triggering the mouse event
140 * \readonly
141 */
142
143/*!
144 * \property QMouseEvent::buttons
145 * Specifies the button triggering the mouse event
146 * \readonly
147 */
148
149/*!
150 * \property QMouseEvent::modifiers
151 * Specifies if any modifiers were applied to the mouse event
152 * \readonly
153 */
154
155/*!
156 * \property QMouseEvent::accepted
157 * Specifies if the mouse event has been accepted
158 */
159
160/*!
161 * \enum Qt3DInput::QMouseEvent::Buttons
162 *
163 * \value LeftButton
164 * \value RightButton
165 * \value MiddleButton
166 * \value BackButton
167 * \value NoButton
168 */
169
170/*!
171 * \enum Qt3DInput::QMouseEvent::Modifiers
172 *
173 * \value NoModifier
174 * \value ShiftModifier
175 * \value ControlModifier
176 * \value AltModifier
177 * \value MetaModifier
178 * \value KeypadModifier
179 */
180
181/*!
182 * \typedef Qt3DInput::QMouseEventPtr
183 * \relates Qt3DInput::QMouseEvent
184 *
185 * A shared pointer for QMouseEvent.
186 */
187
188/*!
189 * \fn int Qt3DInput::QMouseEvent::x() const
190 *
191 * Returns the x position of the mouse event.
192 */
193
194/*!
195 * \fn int Qt3DInput::QMouseEvent::y() const
196 *
197 * Returns the y position of the mouse event.
198 */
199
200/*!
201 * \fn bool Qt3DInput::QMouseEvent::isAccepted() const
202 *
203 * Returns whether the event was accepted.
204 */
205
206/*!
207 * \fn void Qt3DInput::QMouseEvent::setAccepted(bool accepted)
208 *
209 * Sets the event as accepted if \a accepted is true.
210 *
211 * \note When an event is accepted, it will prevent further propagation to other
212 * listeners.
213 */
214
215/*!
216 * \fn QEvent::Type Qt3DInput::QMouseEvent::type() const
217 *
218 * Returns the QEvent::Type of the event.
219 */
220
221/*!
222 * Constructs a new QMouseEvent instance for the QMouseEvent \a e.
223 */
224QMouseEvent::QMouseEvent(const QT_PREPEND_NAMESPACE(QMouseEvent) &e)
225 : QObject()
226 , m_event(static_cast<QT_PREPEND_NAMESPACE(QMouseEvent)*>(e.clone()))
227{
228}
229
230QMouseEvent::~QMouseEvent()
231{
232}
233
234/*!
235 * Returns the mouse button of the mouse event.
236 */
237QMouseEvent::Buttons QMouseEvent::button() const
238{
239 switch (m_event->button()) {
240 case Qt::LeftButton:
241 return QMouseEvent::LeftButton;
242 case Qt::RightButton:
243 return QMouseEvent::RightButton;
244 case Qt::MiddleButton:
245 return QMouseEvent::MiddleButton;
246 case Qt::BackButton:
247 return QMouseEvent::BackButton;
248 default:
249 return QMouseEvent::NoButton;
250 }
251}
252
253/*!
254 * Returns a bitfield to be used to check for mouse buttons that may be
255 * accompanying the mouse event.
256 */
257int QMouseEvent::buttons() const
258{
259 return m_event->buttons();
260}
261
262/*!
263 * Returns the keyboard modifiers that may be accompanying the mouse event.
264 */
265QMouseEvent::Modifiers QMouseEvent::modifiers() const
266{
267 return modifiersForEvent<QMouseEvent, QT_PREPEND_NAMESPACE(QMouseEvent)>(event: m_event.get());
268}
269
270/*!
271 * \qmltype WheelEvent
272 * \instantiates Qt3DInput::QWheelEvent
273 * \inqmlmodule Qt3D.Input
274 * \since 5.5
275 * \brief Contains parameters that describe a mouse wheel event.
276 *
277 * Mouse wheel events occur when the mouse wheel is rotated.
278 *
279 * \sa KeyEvent, MouseEvent, MouseHandler
280 *
281 */
282
283/*!
284 * \qmlproperty int Qt3D.Input::WheelEvent::x
285 * Specifies The X coordinate of the mouse wheel event
286 * \readonly
287 */
288
289/*!
290 * \qmlproperty int Qt3D.Input::WheelEvent::y
291 * Specifies The Y coordinate of the mouse wheel event
292 * \readonly
293 */
294
295/*!
296 * \qmlproperty Point Qt3D.Input::WheelEvent::angleDelta
297 * Specifies The change wheel angle of the mouse wheel event
298 * \readonly
299 */
300
301/*!
302 * \qmlproperty int Qt3D.Input::WheelEvent::buttons
303 * Specifies the button if present in the mouse wheel event
304 * \readonly
305 */
306
307/*!
308 * \qmlproperty Modifiers Qt3D.Input::WheelEvent::modifiers
309 * Specifies if any modifiers were applied to the mouse wheel event
310 * \readonly
311 */
312
313/*!
314 * \qmlproperty bool Qt3D.Input::WheelEvent::accepted
315 * Specifies if the mouse wheel event has been accepted
316 */
317
318/*!
319 * \class Qt3DInput::QWheelEvent
320 * \inheaderfile Qt3DInput/QWheelEvent
321 * \inmodule Qt3DInput
322 *
323 * \brief The QWheelEvent class contains parameters that describe a mouse wheel event.
324 *
325 * Mouse wheel events occur when the mouse is rotated.
326 *
327 * \since 5.5
328 *
329 * \sa QKeyEvent, QMouseEvent, QMouseHandler
330 *
331 */
332
333/*!
334 * \property QWheelEvent::x
335 * Specifies The X coordinate of the mouse wheel event
336 * \readonly
337 */
338
339/*!
340 * \property QWheelEvent::y
341 * Specifies The Y coordinate of the mouse wheel event
342 * \readonly
343 */
344
345/*!
346 * \property QWheelEvent::angleDelta
347 * Specifies The change wheel angle of the mouse wheel event
348 * \readonly
349 */
350
351/*!
352 * \property QWheelEvent::buttons
353 * Specifies the button if present in the mouse wheel event
354 * \readonly
355 */
356
357/*!
358 * \property QWheelEvent::modifiers
359 * Specifies if any modifiers were applied to the mouse wheel event
360 * \readonly
361 */
362
363/*!
364 * \property QWheelEvent::accepted
365 * Specifies if the mouse wheel event has been accepted
366 */
367
368/*!
369 * \enum Qt3DInput::QWheelEvent::Buttons
370 *
371 * \value LeftButton
372 * \value RightButton
373 * \value MiddleButton
374 * \value BackButton
375 * \value NoButton
376 */
377
378/*!
379 * \enum Qt3DInput::QWheelEvent::Modifiers
380 *
381 * \value NoModifier
382 * \value ShiftModifier
383 * \value ControlModifier
384 * \value AltModifier
385 * \value MetaModifier
386 * \value KeypadModifier
387 */
388
389
390/*!
391 * \typedef Qt3DInput::QWheelEventPtr
392 * \relates Qt3DInput::QWheelEvent
393 *
394 * A shared pointer for QWheelEvent.
395 */
396
397/*!
398 * \fn int Qt3DInput::QWheelEvent::x() const
399 *
400 * Returns the x position of the mouse event.
401 */
402
403/*!
404 * \fn int Qt3DInput::QWheelEvent::y() const
405 *
406 * Returns the x position of the mouse event.
407 */
408
409/*!
410 * \fn QPoint Qt3DInput::QWheelEvent::angleDelta() const
411 *
412 * Returns the distance that the wheel is rotated, in eighths of a degree. A
413 * positive value indicates that the wheel was rotated forward (away from the
414 * user), a negative value indicates the wheel was rotated backward (toward the
415 * user).
416 */
417
418/*!
419 * \fn bool Qt3DInput::QWheelEvent::isAccepted() const
420 *
421 * Returns whether the event was accepted.
422 */
423
424/*!
425 * \fn void Qt3DInput::QWheelEvent::setAccepted(bool accepted)
426 *
427 * Sets the event as accepted if \a accepted is true.
428 *
429 * \note When an event is accepted, it will prevent further propagation to other
430 * listeners.
431 */
432
433/*!
434 * \fn QEvent::Type Qt3DInput::QWheelEvent::type() const
435 *
436 * Returns the QEvent::Type of the event.
437 */
438
439#if QT_CONFIG(wheelevent)
440/*!
441 * Constructs a new QWheelEvent instance from the QWheelEvent \a e.
442 */
443QWheelEvent::QWheelEvent(const QT_PREPEND_NAMESPACE(QWheelEvent) &e)
444 : QObject()
445 , m_event(static_cast<QT_PREPEND_NAMESPACE(QWheelEvent)*>(e.clone()))
446{
447}
448
449QWheelEvent::~QWheelEvent()
450{
451}
452
453/*!
454 * Returns a bitfield to be used to check for mouse buttons that may be
455 * accompanying the wheel event.
456 */
457int QWheelEvent::buttons() const
458{
459 return m_event->buttons();
460}
461
462/*!
463 * Returns the keyboard modifiers that may be accompanying the wheel event.
464 */
465QWheelEvent::Modifiers QWheelEvent::modifiers() const
466{
467 return modifiersForEvent<QWheelEvent, QT_PREPEND_NAMESPACE(QWheelEvent)>(event: m_event.get());
468}
469#endif // QT_CONFIG(wheelevent)
470
471} // namespace Qt3DInput
472
473QT_END_NAMESPACE
474
475#include "moc_qmouseevent.cpp"
476

source code of qt3d/src/input/frontend/qmouseevent.cpp