summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKaj Grönholm <kaj.gronholm@qt.io>2019-05-31 16:27:12 +0300
committerKaj Grönholm <kaj.gronholm@qt.io>2019-06-02 18:01:39 +0300
commit089d283afb8cde5024e60c29eeeeefc5c3c80543 (patch)
treec1b97499a81a4d1f7b362b1313f47a2fdd5a87ac
parent07e41a592a427988600ed721526a63bf1f5e9814 (diff)
Add ignoredEvents into OpenGL Runtime
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ää <tomi.korpipaa@qt.io> Reviewed-by: Antti Määttä <antti.maatta@qt.io> Reviewed-by: Miikka Heikkinen <miikka.heikkinen@qt.io>
-rw-r--r--src/Runtime/ogl-runtime/src/api/studio3dqml/q3dsstudio3d.cpp108
-rw-r--r--src/Runtime/ogl-runtime/src/api/studio3dqml/q3dsstudio3d_p.h23
-rw-r--r--tests/auto/runtime/runtime.pro2
-rw-r--r--tests/auto/viewer/tst_qt3dsviewer.cpp30
-rw-r--r--tests/auto/viewer/tst_qt3dsviewer.h1
-rw-r--r--tests/auto/viewer/viewer.pro2
-rw-r--r--tests/scenes/simple_cube_animation/presentations/simple_cube_animation.uip4
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()
@@ -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
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 @@
<AnimationTrack property="position.z" type="EaseInOut" >0 0 100 100 5 0 100 100</AnimationTrack>
</Add>
<State id="Scene-Slide1" name="Slide1" playmode="Play Through To..." >
- <Set ref="#Layer" endtime="5000" />
+ <Set ref="#Layer" endtime="5000" >
+ <Action id="Layer-Action" eyeball="True" triggerObject="#Scene" event="onPressureDown" targetObject="#Scene" handler="Next Slide" />
+ </Set>
<Set ref="#Camera" endtime="5000" />
<Set ref="#Light" endtime="5000" />
<Add ref="#Sphere" name="Sphere" endtime="5000" scale="0.1 0.1 0.1" sourcepath="#Sphere" />