From 089d283afb8cde5024e60c29eeeeefc5c3c80543 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kaj=20Gr=C3=B6nholm?= Date: Fri, 31 May 2019 16:27:12 +0300 Subject: Add ignoredEvents into OpenGL Runtime MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add ignoredEvents property into OpenGL runtime Studio3D item. Implementation and behavior matches to Qt3D runtime. Also adding test case for it. Task-number: QT3DS-3546 Change-Id: I2c1ab7e08b0eecdf16a62ee7a4bb87dc1fa4c702 Reviewed-by: Tomi Korpipää Reviewed-by: Antti Määttä Reviewed-by: Miikka Heikkinen --- .../src/api/studio3dqml/q3dsstudio3d.cpp | 108 +++++++++++++-------- .../src/api/studio3dqml/q3dsstudio3d_p.h | 23 ++++- tests/auto/runtime/runtime.pro | 2 +- tests/auto/viewer/tst_qt3dsviewer.cpp | 30 ++++++ tests/auto/viewer/tst_qt3dsviewer.h | 1 + tests/auto/viewer/viewer.pro | 2 +- .../presentations/simple_cube_animation.uip | 4 +- 7 files changed, 121 insertions(+), 49 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() @@ -206,21 +204,40 @@ 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 diff --git a/tests/auto/runtime/runtime.pro b/tests/auto/runtime/runtime.pro index 8f4451ed..534af9f8 100644 --- a/tests/auto/runtime/runtime.pro +++ b/tests/auto/runtime/runtime.pro @@ -1,6 +1,6 @@ TEMPLATE = app CONFIG += testcase -include($$PWD/../../../src/Runtime/commoninclude.pri) +include($$PWD/../../../src/Runtime/ogl-runtime/commoninclude.pri) TARGET = tst_qt3dsruntime QT += testlib gui diff --git a/tests/auto/viewer/tst_qt3dsviewer.cpp b/tests/auto/viewer/tst_qt3dsviewer.cpp index 97429039..9424612e 100644 --- a/tests/auto/viewer/tst_qt3dsviewer.cpp +++ b/tests/auto/viewer/tst_qt3dsviewer.cpp @@ -593,6 +593,36 @@ void tst_qt3dsviewer::testCreateMesh() QTest::qWait(200); // Extra wait to verify slide change visually } +void tst_qt3dsviewer::testMouseEvents() +{ + m_viewer->show(); + QTest::qWait(1000); + + QSignalSpy spyEvents(m_studio3DItem, + SIGNAL(ignoredEventsChanged())); + QSignalSpy spyExited(m_presentation, + SIGNAL(slideExited(const QString &, unsigned int, const QString &))); + + QCOMPARE(spyEvents.count(), 0); + QCOMPARE(spyExited.count(), 0); + + // Ignore mouse, so slide doesn't change + m_studio3DItem->setProperty("ignoredEvents", 1); + QTest::mousePress(m_viewer, Qt::LeftButton); + QTest::qWait(1000); + QTest::mouseRelease(m_viewer, Qt::LeftButton); + QCOMPARE(spyEvents.count(), 1); + QCOMPARE(spyExited.count(), 0); + + // Enable mouse, clicking switches slide + m_studio3DItem->setProperty("ignoredEvents", 0); + QTest::mousePress(m_viewer, Qt::LeftButton); + QTest::qWait(1000); + QTest::mouseRelease(m_viewer, Qt::LeftButton); + QCOMPARE(spyEvents.count(), 2); + QCOMPARE(spyExited.count(), 1); +} + void tst_qt3dsviewer::deleteCreated() { m_presentation->deleteElements(m_createdElements); diff --git a/tests/auto/viewer/tst_qt3dsviewer.h b/tests/auto/viewer/tst_qt3dsviewer.h index e6fae709..3d1f9473 100644 --- a/tests/auto/viewer/tst_qt3dsviewer.h +++ b/tests/auto/viewer/tst_qt3dsviewer.h @@ -58,6 +58,7 @@ private Q_SLOTS: void testCreateElement(); void testCreateMaterial(); void testCreateMesh(); + void testMouseEvents(); private: void deleteCreated(); diff --git a/tests/auto/viewer/viewer.pro b/tests/auto/viewer/viewer.pro index ad832e02..9e06c2ca 100644 --- a/tests/auto/viewer/viewer.pro +++ b/tests/auto/viewer/viewer.pro @@ -1,6 +1,6 @@ TEMPLATE = app CONFIG += testcase -include($$PWD/../../../src/Runtime/commoninclude.pri) +include($$PWD/../../../src/Runtime/ogl-runtime/commoninclude.pri) TARGET = tst_qt3dsviewer QT += testlib gui quick studio3d diff --git a/tests/scenes/simple_cube_animation/presentations/simple_cube_animation.uip b/tests/scenes/simple_cube_animation/presentations/simple_cube_animation.uip index fc273121..f8fae907 100644 --- a/tests/scenes/simple_cube_animation/presentations/simple_cube_animation.uip +++ b/tests/scenes/simple_cube_animation/presentations/simple_cube_animation.uip @@ -32,7 +32,9 @@ 0 0 100 100 5 0 100 100 - + + + -- cgit v1.2.3