| 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 | #ifndef QT3DINPUT_QMOUSEEVENT_H |
| 5 | #define QT3DINPUT_QMOUSEEVENT_H |
| 6 | |
| 7 | #include <Qt3DInput/qt3dinput_global.h> |
| 8 | #include <QtCore/QtGlobal> |
| 9 | #include <QtCore/QObject> |
| 10 | #include <QtGui/QMouseEvent> |
| 11 | |
| 12 | #include <memory> |
| 13 | |
| 14 | QT_BEGIN_NAMESPACE |
| 15 | |
| 16 | namespace Qt3DInput { |
| 17 | |
| 18 | class Q_3DINPUTSHARED_EXPORT QMouseEvent : public QObject |
| 19 | { |
| 20 | Q_OBJECT |
| 21 | Q_PROPERTY(int x READ x CONSTANT) |
| 22 | Q_PROPERTY(int y READ y CONSTANT) |
| 23 | Q_PROPERTY(bool wasHeld READ wasHeld CONSTANT) |
| 24 | Q_PROPERTY(Qt3DInput::QMouseEvent::Buttons button READ button CONSTANT) |
| 25 | Q_PROPERTY(int buttons READ buttons CONSTANT) |
| 26 | Q_PROPERTY(Qt3DInput::QMouseEvent::Modifiers modifiers READ modifiers CONSTANT) |
| 27 | Q_PROPERTY(bool accepted READ isAccepted WRITE setAccepted) |
| 28 | public: |
| 29 | enum Buttons { |
| 30 | LeftButton = Qt::LeftButton, |
| 31 | RightButton = Qt::RightButton, |
| 32 | MiddleButton = Qt::MiddleButton, |
| 33 | BackButton = Qt::BackButton, |
| 34 | NoButton = Qt::NoButton |
| 35 | }; |
| 36 | Q_ENUM(Buttons) // LCOV_EXCL_LINE |
| 37 | |
| 38 | enum Modifiers { |
| 39 | NoModifier = Qt::NoModifier, |
| 40 | ShiftModifier = Qt::ShiftModifier, |
| 41 | ControlModifier = Qt::ControlModifier, |
| 42 | AltModifier = Qt::AltModifier, |
| 43 | MetaModifier = Qt::MetaModifier, |
| 44 | KeypadModifier = Qt::KeypadModifier |
| 45 | }; |
| 46 | Q_ENUM(Modifiers) // LCOV_EXCL_LINE |
| 47 | // TO DO Qt6 Modifiers -> Modifier and add Q_FLAG(Modifiers) |
| 48 | |
| 49 | explicit QMouseEvent(const QT_PREPEND_NAMESPACE(QMouseEvent) &e); |
| 50 | ~QMouseEvent(); |
| 51 | |
| 52 | inline int x() const { return int(m_event->position().x()); } |
| 53 | inline int y() const { return int(m_event->position().y()); } |
| 54 | inline bool wasHeld() const { |
| 55 | #if QT_CONFIG(gestures) |
| 56 | return static_cast<Qt::GestureType>(m_event->type()) == Qt::TapAndHoldGesture; |
| 57 | #else |
| 58 | return false; |
| 59 | #endif |
| 60 | } |
| 61 | Buttons button() const; |
| 62 | int buttons() const; |
| 63 | Modifiers modifiers() const; |
| 64 | |
| 65 | inline bool isAccepted() const { return m_event->isAccepted(); } |
| 66 | inline void setAccepted(bool accepted) { m_event->setAccepted(accepted); } |
| 67 | inline QEvent::Type type() const { return m_event->type(); } |
| 68 | |
| 69 | private: |
| 70 | std::unique_ptr<QT_PREPEND_NAMESPACE(QMouseEvent)> m_event; |
| 71 | }; |
| 72 | |
| 73 | typedef QSharedPointer<QMouseEvent> QMouseEventPtr; |
| 74 | |
| 75 | #if QT_CONFIG(wheelevent) |
| 76 | class Q_3DINPUTSHARED_EXPORT QWheelEvent : public QObject |
| 77 | { |
| 78 | Q_OBJECT |
| 79 | Q_PROPERTY(int x READ x CONSTANT) |
| 80 | Q_PROPERTY(int y READ y CONSTANT) |
| 81 | Q_PROPERTY(QPoint angleDelta READ angleDelta CONSTANT) |
| 82 | Q_PROPERTY(int buttons READ buttons CONSTANT) |
| 83 | Q_PROPERTY(Qt3DInput::QWheelEvent::Modifiers modifiers READ modifiers CONSTANT) |
| 84 | Q_PROPERTY(bool accepted READ isAccepted WRITE setAccepted) |
| 85 | |
| 86 | public: |
| 87 | enum Buttons { |
| 88 | LeftButton = Qt::LeftButton, |
| 89 | RightButton = Qt::RightButton, |
| 90 | MiddleButton = Qt::MiddleButton, |
| 91 | BackButton = Qt::BackButton, |
| 92 | NoButton = Qt::NoButton |
| 93 | }; |
| 94 | Q_ENUM(Buttons) // LCOV_EXCL_LINE |
| 95 | |
| 96 | enum Modifiers { |
| 97 | NoModifier = Qt::NoModifier, |
| 98 | ShiftModifier = Qt::ShiftModifier, |
| 99 | ControlModifier = Qt::ControlModifier, |
| 100 | AltModifier = Qt::AltModifier, |
| 101 | MetaModifier = Qt::MetaModifier, |
| 102 | KeypadModifier = Qt::KeypadModifier |
| 103 | }; |
| 104 | Q_ENUM(Modifiers) // LCOV_EXCL_LINE |
| 105 | // TO DO Qt6 Modifiers -> Modifier and add Q_FLAG(Modifiers) |
| 106 | |
| 107 | explicit QWheelEvent(const QT_PREPEND_NAMESPACE(QWheelEvent) &e); |
| 108 | ~QWheelEvent(); |
| 109 | |
| 110 | inline int x() const { return int(m_event->position().x()); } |
| 111 | inline int y() const { return int(m_event->position().y()); } |
| 112 | inline QPoint angleDelta() const { return m_event->angleDelta(); } |
| 113 | int buttons() const; |
| 114 | Modifiers modifiers() const; |
| 115 | |
| 116 | inline bool isAccepted() const { return m_event->isAccepted(); } |
| 117 | inline void setAccepted(bool accepted) { m_event->setAccepted(accepted); } |
| 118 | inline QEvent::Type type() const { return m_event->type(); } |
| 119 | |
| 120 | private: |
| 121 | std::unique_ptr<QT_PREPEND_NAMESPACE(QWheelEvent)> m_event; |
| 122 | }; |
| 123 | |
| 124 | typedef QSharedPointer<QWheelEvent> QWheelEventPtr; |
| 125 | #endif |
| 126 | |
| 127 | } // namespace Qt3DInput |
| 128 | |
| 129 | QT_END_NAMESPACE |
| 130 | |
| 131 | Q_DECLARE_METATYPE(Qt3DInput::QMouseEvent*) // LCOV_EXCL_LINE |
| 132 | |
| 133 | #if QT_CONFIG(wheelevent) |
| 134 | Q_DECLARE_METATYPE(Qt3DInput::QWheelEvent*) // LCOV_EXCL_LINE |
| 135 | #endif |
| 136 | |
| 137 | #endif // QT3DINPUT_QMOUSEEVENT_H |
| 138 | |