diff options
Diffstat (limited to 'src/Runtime/ogl-runtime/src/api/studio3dqml')
-rw-r--r-- | src/Runtime/ogl-runtime/src/api/studio3dqml/q3dsstudio3d.cpp | 108 | ||||
-rw-r--r-- | src/Runtime/ogl-runtime/src/api/studio3dqml/q3dsstudio3d_p.h | 23 |
2 files changed, 85 insertions, 46 deletions
diff --git a/src/Runtime/ogl-runtime/src/api/studio3dqml/q3dsstudio3d.cpp b/src/Runtime/ogl-runtime/src/api/studio3dqml/q3dsstudio3d.cpp index 59f92b01..3d48babc 100644 --- a/src/Runtime/ogl-runtime/src/api/studio3dqml/q3dsstudio3d.cpp +++ b/src/Runtime/ogl-runtime/src/api/studio3dqml/q3dsstudio3d.cpp @@ -143,16 +143,14 @@ Q3DSStudio3D::Q3DSStudio3D() , m_presentation(nullptr) , m_emitRunningChange(false) , m_isRunning(false) - , m_ignoreMouseEvents(false) - , m_ignoreWheelEvents(false) - , m_ignoreKeyboardEvents(false) + , m_eventIgnoreFlags(EnableAllEvents) , m_pixelRatio(1.0) { setMirrorVertically(true); connect(this, &Q3DSStudio3D::windowChanged, this, &Q3DSStudio3D::handleWindowChanged); connect(this, &Q3DSStudio3D::visibleChanged, this, &Q3DSStudio3D::handleVisibleChanged); - setIgnoreEvents(false, false, false); + updateEventMasks(); } Q3DSStudio3D::~Q3DSStudio3D() @@ -207,20 +205,39 @@ void Q3DSStudio3D::setError(const QString &error) } /*! + \qmlproperty EventIgnoreFlags Studio3D::ignoredEvents + + This property can be used to ignore mouse/wheel/keyboard events. + By default all events are enabled. +*/ + +Q3DSStudio3D::EventIgnoreFlags Q3DSStudio3D::ignoredEvents() const +{ + return m_eventIgnoreFlags; +} + +void Q3DSStudio3D::setIgnoredEvents(EventIgnoreFlags flags) +{ + if (m_eventIgnoreFlags == flags) + return; + + m_eventIgnoreFlags = flags; + updateEventMasks(); + Q_EMIT ignoredEventsChanged(); +} + +/*! \internal - It might be beneficial to have these as properties so they could be accessed from QML? */ -void Q3DSStudio3D::setIgnoreEvents(bool mouse, bool wheel, bool keyboard) +void Q3DSStudio3D::updateEventMasks() { - m_ignoreMouseEvents = mouse; - m_ignoreWheelEvents = wheel; - m_ignoreKeyboardEvents = keyboard; - - if (mouse) + if (m_eventIgnoreFlags.testFlag(IgnoreMouseEvents)) { setAcceptedMouseButtons(Qt::NoButton); - else - setAcceptedMouseButtons(Qt::LeftButton | Qt::RightButton | Qt::MiddleButton); - setAcceptHoverEvents(!mouse); + setAcceptHoverEvents(false); + } else { + setAcceptedMouseButtons(Qt::MouseButtonMask); + setAcceptHoverEvents(true); + } } /*! @@ -435,14 +452,15 @@ void Q3DSStudio3D::getCommands(bool emitInitialize, CommandQueue &renderQueue) */ void Q3DSStudio3D::mousePressEvent(QMouseEvent *event) { - if (!m_ignoreMouseEvents) { - if (m_pixelRatio != 1.0) { - QMouseEvent scaledEvent(event->type(), event->pos() * m_pixelRatio, - event->button(), event->buttons(), event->modifiers()); - m_presentation->mousePressEvent(&scaledEvent); - } else { - m_presentation->mousePressEvent(event); - } + if (m_eventIgnoreFlags.testFlag(IgnoreMouseEvents)) + return; + + if (m_pixelRatio != 1.0) { + QMouseEvent scaledEvent(event->type(), event->pos() * m_pixelRatio, + event->button(), event->buttons(), event->modifiers()); + m_presentation->mousePressEvent(&scaledEvent); + } else { + m_presentation->mousePressEvent(event); } } @@ -451,14 +469,15 @@ void Q3DSStudio3D::mousePressEvent(QMouseEvent *event) */ void Q3DSStudio3D::mouseReleaseEvent(QMouseEvent *event) { - if (!m_ignoreMouseEvents) { - if (m_pixelRatio != 1.0) { - QMouseEvent scaledEvent(event->type(), event->pos() * m_pixelRatio, - event->button(), event->buttons(), event->modifiers()); - m_presentation->mouseReleaseEvent(&scaledEvent); - } else { - m_presentation->mouseReleaseEvent(event); - } + if (m_eventIgnoreFlags.testFlag(IgnoreMouseEvents)) + return; + + if (m_pixelRatio != 1.0) { + QMouseEvent scaledEvent(event->type(), event->pos() * m_pixelRatio, + event->button(), event->buttons(), event->modifiers()); + m_presentation->mouseReleaseEvent(&scaledEvent); + } else { + m_presentation->mouseReleaseEvent(event); } } @@ -467,14 +486,15 @@ void Q3DSStudio3D::mouseReleaseEvent(QMouseEvent *event) */ void Q3DSStudio3D::mouseMoveEvent(QMouseEvent *event) { - if (!m_ignoreMouseEvents) { - if (m_pixelRatio != 1.0) { - QMouseEvent scaledEvent(event->type(), event->pos() * m_pixelRatio, - event->button(), event->buttons(), event->modifiers()); - m_presentation->mouseMoveEvent(&scaledEvent); - } else { - m_presentation->mouseMoveEvent(event); - } + if (m_eventIgnoreFlags.testFlag(IgnoreMouseEvents)) + return; + + if (m_pixelRatio != 1.0) { + QMouseEvent scaledEvent(event->type(), event->pos() * m_pixelRatio, + event->button(), event->buttons(), event->modifiers()); + m_presentation->mouseMoveEvent(&scaledEvent); + } else { + m_presentation->mouseMoveEvent(event); } } @@ -483,8 +503,10 @@ void Q3DSStudio3D::mouseMoveEvent(QMouseEvent *event) */ void Q3DSStudio3D::wheelEvent(QWheelEvent *event) { - if (!m_ignoreWheelEvents) - m_presentation->wheelEvent(event); + if (m_eventIgnoreFlags.testFlag(IgnoreWheelEvents)) + return; + + m_presentation->wheelEvent(event); } /*! @@ -492,8 +514,9 @@ void Q3DSStudio3D::wheelEvent(QWheelEvent *event) */ void Q3DSStudio3D::keyPressEvent(QKeyEvent *event) { - if (m_ignoreKeyboardEvents) + if (m_eventIgnoreFlags.testFlag(IgnoreKeyboardEvents)) return; + m_presentation->keyPressEvent(event); } @@ -502,8 +525,9 @@ void Q3DSStudio3D::keyPressEvent(QKeyEvent *event) */ void Q3DSStudio3D::keyReleaseEvent(QKeyEvent *event) { - if (m_ignoreKeyboardEvents) + if (m_eventIgnoreFlags.testFlag(IgnoreKeyboardEvents)) return; + if (!event->isAutoRepeat()) m_presentation->keyReleaseEvent(event); } diff --git a/src/Runtime/ogl-runtime/src/api/studio3dqml/q3dsstudio3d_p.h b/src/Runtime/ogl-runtime/src/api/studio3dqml/q3dsstudio3d_p.h index 0fd3b9d0..eed8459a 100644 --- a/src/Runtime/ogl-runtime/src/api/studio3dqml/q3dsstudio3d_p.h +++ b/src/Runtime/ogl-runtime/src/api/studio3dqml/q3dsstudio3d_p.h @@ -59,8 +59,19 @@ class Q3DSStudio3D : public QQuickFramebufferObject Q_PROPERTY(Q3DSPresentationItem *presentation READ presentation CONSTANT) Q_PROPERTY(Q3DSViewerSettings *viewerSettings READ viewerSettings CONSTANT) Q_PROPERTY(QString error READ error NOTIFY errorChanged) + Q_PROPERTY(EventIgnoreFlags ignoredEvents READ ignoredEvents WRITE setIgnoredEvents NOTIFY ignoredEventsChanged) public: + enum EventIgnoreFlag { + EnableAllEvents = 0, + IgnoreMouseEvents = 0x01, + IgnoreWheelEvents = 0x02, + IgnoreKeyboardEvents = 0x04, + IgnoreAllInputEvents = IgnoreMouseEvents | IgnoreWheelEvents | IgnoreKeyboardEvents + }; + Q_DECLARE_FLAGS(EventIgnoreFlags, EventIgnoreFlag) + Q_FLAG(EventIgnoreFlags) + Q3DSStudio3D(); ~Q3DSStudio3D() override; @@ -81,7 +92,8 @@ public: void keyPressEvent(QKeyEvent *event) override; void keyReleaseEvent(QKeyEvent *event) override; - void setIgnoreEvents(bool mouse, bool wheel, bool keyboard); + EventIgnoreFlags ignoredEvents() const; + void setIgnoredEvents(EventIgnoreFlags flags); void componentComplete() override; @@ -89,6 +101,7 @@ Q_SIGNALS: void frameUpdate(); void runningChanged(bool initialized); void errorChanged(const QString &error); + void ignoredEventsChanged(); void presentationReady(); void presentationLoaded(); @@ -101,6 +114,8 @@ protected Q_SLOTS: void tick(); void requestResponseHandler(const QString &elementPath, CommandType commandType, void *requestData); +private: + void updateEventMasks(); protected: Q3DSViewerSettings *m_viewerSettings; @@ -108,15 +123,15 @@ protected: bool m_emitRunningChange; bool m_isRunning; - bool m_ignoreMouseEvents; - bool m_ignoreWheelEvents; - bool m_ignoreKeyboardEvents; + EventIgnoreFlags m_eventIgnoreFlags; CommandQueue m_pendingCommands; qreal m_pixelRatio; QString m_error; }; +Q_DECLARE_OPERATORS_FOR_FLAGS(Q3DSStudio3D::EventIgnoreFlags) + QT_END_NAMESPACE #endif // Q3DS_STUDIO3D_H |