summaryrefslogtreecommitdiffstats
path: root/src/input/frontend/qmouseevent.cpp
blob: 2b06c824d4269e37a20263838b8e292a30245a27 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
/****************************************************************************
**
** Copyright (C) 2015 Klaralvdalens Datakonsult AB (KDAB).
** Contact: https://www.qt.io/licensing/
**
** This file is part of the Qt3D module of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:LGPL$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 3 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL3 included in the
** packaging of this file. Please review the following information to
** ensure the GNU Lesser General Public License version 3 requirements
** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 2.0 or (at your option) the GNU General
** Public license version 3 or any later version approved by the KDE Free
** Qt Foundation. The licenses are as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
** included in the packaging of this file. Please review the following
** information to ensure the GNU General Public License requirements will
** be met: https://www.gnu.org/licenses/gpl-2.0.html and
** https://www.gnu.org/licenses/gpl-3.0.html.
**
** $QT_END_LICENSE$
**
****************************************************************************/

#include "qmouseevent.h"

QT_BEGIN_NAMESPACE

namespace Qt3DInput {

namespace {

template<typename EventClass, typename QtEventClass>
typename EventClass::Modifiers modifiersForEvent(const QtEventClass &event)
{
    const Qt::KeyboardModifiers eventModifiers = event.modifiers();
    int modifiers = EventClass::NoModifier;

    if (eventModifiers & Qt::ShiftModifier)
        modifiers |= EventClass::ShiftModifier;

    if (eventModifiers & Qt::ControlModifier)
        modifiers |= EventClass::ControlModifier;

    if (eventModifiers & Qt::AltModifier)
        modifiers |= EventClass::AltModifier;

    if (eventModifiers & Qt::MetaModifier)
        modifiers |= EventClass::MetaModifier;

    if (eventModifiers & Qt::KeypadModifier)
        modifiers |= EventClass::KeypadModifier;

    // Abuse the int used to store an enum to store multiple
    // modifiers into one
    return static_cast<typename EventClass::Modifiers>(modifiers);
}

} // anonymous

// Notes:
// Maybe we should provide the world pos of the intersection
// The distance t along the segment line at which the intersection occurs
// Screen Pos / Mouse Pos / Viewport Pos
// The intersection Ray
// These can always be added in follow up commits once the input API takes shape

/*!
 * \qmltype MouseEvent
 * \instantiates Qt3DInput::QMouseEvent
 * \inqmlmodule Qt3D.Input
 * \since 5.5
 * \brief Provides parameters that describe a mouse event.
 *
 * Mouse events occur when a mouse button is pressed and the ray
 * traversing the view, originating from the mouse position intersects with one
 * or more elements of the scene.
 *
 * \sa KeyEvent, WheelEvent, MouseHandler
 */

/*!
 * \qmlproperty int Qt3D.Input::MouseEvent::x
 * Specifies The X coordinate of the mouse event
 * \readonly
 */

/*!
 * \qmlproperty int Qt3D.Input::MouseEvent::y
 * Specifies The Y coordinate of the mouse event
 * \readonly
 */

/*!
 * \qmlproperty bool Qt3D.Input::MouseEvent::wasHeld
 * Specifies if a mouse button was held down during the mouse event
 * \readonly
 */

/*!
 * \qmlproperty Buttons Qt3D.Input::MouseEvent::button
 * Specifies the button triggering the mouse event
 * \readonly
 */

/*!
 * \qmlproperty int Qt3D.Input::MouseEvent::buttons
 * Specifies the button triggering the mouse event
 * \readonly
 */

/*!
 * \qmlproperty Modifiers Qt3D.Input::MouseEvent::modifiers
 * Specifies if any modifiers were applied to the mouse event
 * \readonly
 */

/*!
 * \qmlproperty bool Qt3D.Input::MouseEvent::accepted
 * Specifies if the mouse event has been accepted
 */

/*!
 * \class Qt3DInput::QMouseEvent
 * \inheaderfile Qt3DInput/QMouseEvent
 * \inmodule Qt3DInput
 *
 * \brief The Qt3DCore::QMouseEvent contains parameters that describe a mouse event.
 *
 * Mouse events occur when a mouse button is pressed and the ray
 * traversing the view, originating from the mouse position intersects with one
 * or more elements of the scene.
 *
 * \since 5.5
 *
 * \sa QKeyEvent, QWheelEvent, QMouseHandler
 *
 */

/*!
 * \property QMouseEvent::x
 * Specifies The X coordinate of the mouse event
 * \readonly
 */

/*!
 * \property QMouseEvent::y
 * Specifies The y coordinate of the mouse event
 * \readonly
 */

/*!
 * \property QMouseEvent::wasHeld
 * Specifies if a mouse button was held down during the mouse event
 * \readonly
 */

/*!
 * \property QMouseEvent::button
 * Specifies the button triggering the mouse event
 * \readonly
 */

/*!
 * \property QMouseEvent::buttons
 * Specifies the button triggering the mouse event
 * \readonly
 */

/*!
 * \property QMouseEvent::modifiers
 * Specifies if any modifiers were applied to the mouse event
 * \readonly
 */

/*!
 * \property QMouseEvent::accepted
 * Specifies if the mouse event has been accepted
 */

/*!
 * \enum Qt3DInput::QMouseEvent::Buttons
 *
 * \value LeftButton
 * \value RightButton
 * \value MiddleButton
 * \value BackButton
 * \value NoButton
 */

/*!
 * \enum Qt3DInput::QMouseEvent::Modifiers
 *
 * \value NoModifier
 * \value ShiftModifier
 * \value ControlModifier
 * \value AltModifier
 * \value MetaModifier
 * \value KeypadModifier
 */

/*!
 * \typedef Qt3DInput::QMouseEventPtr
 * \relates Qt3DInput::QMouseEvent
 *
 * A shared pointer for QMouseEvent.
 */

/*!
 * \fn int Qt3DInput::QMouseEvent::x() const
 *
 *  Returns the x position of the mouse event.
 */

/*!
 * \fn int Qt3DInput::QMouseEvent::y() const
 *
 *  Returns the y position of the mouse event.
 */

/*!
 * \fn bool Qt3DInput::QMouseEvent::isAccepted() const
 *
 *  Returns whether the event was accepted.
 */

/*!
 * \fn void Qt3DInput::QMouseEvent::setAccepted(bool accepted)
 *
 *  Sets the event as accepted if \a accepted is true.
 *
 * \note When an event is accepted, it will prevent further propagation to other
 * listeners.
 */

/*!
 * \fn QEvent::Type Qt3DInput::QMouseEvent::type() const
 *
 *  Returns the QEvent::Type of the event.
 */

/*!
 * Constructs a new QMouseEvent instance for the QMouseEvent \a e.
 */
QMouseEvent::QMouseEvent(const QT_PREPEND_NAMESPACE(QMouseEvent) &e)
    : QObject()
    , m_event(e)
{
}

QMouseEvent::~QMouseEvent()
{
}

/*!
 * Returns the mouse button of the mouse event.
 */
QMouseEvent::Buttons QMouseEvent::button() const
{
    switch (m_event.button()) {
    case Qt::LeftButton:
        return QMouseEvent::LeftButton;
    case Qt::RightButton:
        return QMouseEvent::RightButton;
    case Qt::MiddleButton:
        return QMouseEvent::MiddleButton;
    case Qt::BackButton:
        return QMouseEvent::BackButton;
    default:
        return QMouseEvent::NoButton;
    }
}

/*!
 * Returns a bitfield to be used to check for mouse buttons that may be
 * accompanying the mouse event.
 */
int QMouseEvent::buttons() const
{
   return m_event.buttons();
}

/*!
 * Returns the keyboard modifiers that may be accompanying the mouse event.
 */
QMouseEvent::Modifiers QMouseEvent::modifiers() const
{
    return modifiersForEvent<QMouseEvent, decltype(m_event)>(m_event);
}

/*!
 * \qmltype WheelEvent
 * \instantiates Qt3DInput::QWheelEvent
 * \inqmlmodule Qt3D.Input
 * \since 5.5
 * \brief Contains parameters that describe a mouse wheel event.
 *
 * Mouse wheel events occur when the mouse wheel is rotated.
 *
 * \sa KeyEvent, MouseEvent, MouseHandler
 *
 */

/*!
 * \qmlproperty int Qt3D.Input::WheelEvent::x
 * Specifies The X coordinate of the mouse wheel event
 * \readonly
 */

/*!
 * \qmlproperty int Qt3D.Input::WheelEvent::y
 * Specifies The Y coordinate of the mouse wheel event
 * \readonly
 */

/*!
 * \qmlproperty Point Qt3D.Input::WheelEvent::angleDelta
 * Specifies The change wheel angle of the mouse wheel event
 * \readonly
 */

/*!
 * \qmlproperty int Qt3D.Input::WheelEvent::buttons
 * Specifies the button if present in the mouse wheel event
 * \readonly
 */

/*!
 * \qmlproperty Modifiers Qt3D.Input::WheelEvent::modifiers
 * Specifies if any modifiers were applied to the mouse wheel event
 * \readonly
 */

/*!
 * \qmlproperty bool Qt3D.Input::WheelEvent::accepted
 * Specifies if the mouse wheel event has been accepted
 */

/*!
 * \class Qt3DInput::QWheelEvent
 * \inheaderfile Qt3DInput/QWheelEvent
 * \inmodule Qt3DInput
 *
 * \brief The QWheelEvent class contains parameters that describe a mouse wheel event.
 *
 * Mouse wheel events occur when the mouse is rotated.
 *
 * \since 5.5
 *
 * \sa QKeyEvent, QMouseEvent, QMouseHandler
 *
 */

/*!
 * \property QWheelEvent::x
 * Specifies The X coordinate of the mouse wheel event
 * \readonly
 */

/*!
 * \property QWheelEvent::y
 * Specifies The Y coordinate of the mouse wheel event
 * \readonly
 */

/*!
 * \property QWheelEvent::angleDelta
 * Specifies The change wheel angle of the mouse wheel event
 * \readonly
 */

/*!
 * \property QWheelEvent::buttons
 * Specifies the button if present in the mouse wheel event
 * \readonly
 */

/*!
 * \property  QWheelEvent::modifiers
 * Specifies if any modifiers were applied to the mouse wheel event
 * \readonly
 */

/*!
 * \property QWheelEvent::accepted
 * Specifies if the mouse wheel event has been accepted
 */

/*!
 * \enum Qt3DInput::QWheelEvent::Buttons
 *
 * \value LeftButton
 * \value RightButton
 * \value MiddleButton
 * \value BackButton
 * \value NoButton
 */

/*!
 * \enum Qt3DInput::QWheelEvent::Modifiers
 *
 * \value NoModifier
 * \value ShiftModifier
 * \value ControlModifier
 * \value AltModifier
 * \value MetaModifier
 * \value KeypadModifier
 */


/*!
 * \typedef Qt3DInput::QWheelEventPtr
 * \relates Qt3DInput::QWheelEvent
 *
 * A shared pointer for QWheelEvent.
 */

/*!
 * \fn int Qt3DInput::QWheelEvent::x() const
 *
 *  Returns the x position of the mouse event.
 */

/*!
 * \fn int Qt3DInput::QWheelEvent::y() const
 *
 *  Returns the x position of the mouse event.
 */

/*!
 * \fn QPoint Qt3DInput::QWheelEvent::angleDelta() const
 *
 * Returns the distance that the wheel is rotated, in eighths of a degree. A
 * positive value indicates that the wheel was rotated forward (away from the
 * user), a negative value indicates the wheel was rotated backward (toward the
 * user).
 */

/*!
 * \fn bool Qt3DInput::QWheelEvent::isAccepted() const
 *
 *  Returns whether the event was accepted.
 */

/*!
 * \fn void Qt3DInput::QWheelEvent::setAccepted(bool accepted)
 *
 *  Sets the event as accepted if \a accepted is true.
 *
 * \note When an event is accepted, it will prevent further propagation to other
 * listeners.
 */

/*!
 * \fn QEvent::Type Qt3DInput::QWheelEvent::type() const
 *
 *  Returns the QEvent::Type of the event.
 */

#if QT_CONFIG(wheelevent)
/*!
 * Constructs a new QWheelEvent instance from the QWheelEvent \a e.
 */
QWheelEvent::QWheelEvent(const QT_PREPEND_NAMESPACE(QWheelEvent) &e)
    : QObject()
    , m_event(e)
{
}

QWheelEvent::~QWheelEvent()
{
}

/*!
 * Returns a bitfield to be used to check for mouse buttons that may be
 * accompanying the wheel event.
 */
int QWheelEvent::buttons() const
{
    return m_event.buttons();
}

/*!
 * Returns the keyboard modifiers that may be accompanying the wheel event.
 */
QWheelEvent::Modifiers QWheelEvent::modifiers() const
{
    return modifiersForEvent<QWheelEvent, decltype(m_event)>(m_event);
}
#endif // QT_CONFIG(wheelevent)

} // namespace Qt3DInput

QT_END_NAMESPACE