summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLaszlo Agocs <laszlo.agocs@qt.io>2018-03-26 13:29:51 +0200
committerLaszlo Agocs <laszlo.agocs@qt.io>2018-03-26 14:41:18 +0000
commit6ade5518e91bcbeb76fdd89e32a8cec812aef35e (patch)
tree08f197b4382ccd0c1b631f17a71459576ee67818
parent90846a54c9646905fd120813479606f8efa55566 (diff)
Add API for toggling profile UI and disable the implicit toggles
In the viewer profiling is enabled by default and the built-in toggles (F10, backtick, double double click) or the menu item (when using widgets) can be used to bring up the UI. For applications none of these is ideal. Instead, provide a Q3DSPresentation property that can be used to toggle the UI. Therefore, an application will typically do profilingEnabled: true on its Presentation and then set profileUiVisible to true when it wants to. This way we are not tied to the sometimes not ideal keyboard and mouse shortcuts in real applications. Rename Q3DSEngine::profileUiEnabled to autoToggleProfileUi because that's what it really is. It merely enables or disables the built-in keyboard and mouse shortcuts for toggling, nothing more. Change-Id: If49ed7bc2575b7e81c2f6101dba307a639c3c011 Reviewed-by: Andy Nichols <andy.nichols@qt.io>
-rw-r--r--examples/3dstudioruntime2/simpleqml/main.cpp2
-rw-r--r--examples/3dstudioruntime2/simpleqml/main.qml23
-rw-r--r--src/imports/studio3d/q3dsstudio3ditem.cpp7
-rw-r--r--src/runtime/api/q3dspresentation.cpp39
-rw-r--r--src/runtime/api/q3dspresentation.h14
-rw-r--r--src/runtime/api/q3dspresentation_p.h3
-rw-r--r--src/runtime/api/q3dspresentationcontroller.cpp8
-rw-r--r--src/runtime/api/q3dssurfaceviewer.cpp7
-rw-r--r--src/runtime/api/q3dswidget.cpp8
-rw-r--r--src/runtime/profileui/q3dsprofileui.cpp6
-rw-r--r--src/runtime/profileui/q3dsprofileui_p.h2
-rw-r--r--src/runtime/q3dsengine.cpp16
-rw-r--r--src/runtime/q3dsengine_p.h6
-rw-r--r--src/runtime/q3dsscenemanager.cpp8
-rw-r--r--src/runtime/q3dsscenemanager_p.h2
15 files changed, 118 insertions, 33 deletions
diff --git a/examples/3dstudioruntime2/simpleqml/main.cpp b/examples/3dstudioruntime2/simpleqml/main.cpp
index 44ac32b..897b59a 100644
--- a/examples/3dstudioruntime2/simpleqml/main.cpp
+++ b/examples/3dstudioruntime2/simpleqml/main.cpp
@@ -63,7 +63,7 @@ int main(int argc, char *argv[])
viewer.setTitle(QStringLiteral("Qt 3D Studio Example"));
viewer.setResizeMode(QQuickView::SizeRootObjectToView);
- viewer.resize(1024, 768);
+ viewer.resize(1280, 720);
viewer.show();
return app.exec();
diff --git a/examples/3dstudioruntime2/simpleqml/main.qml b/examples/3dstudioruntime2/simpleqml/main.qml
index 67e043d..bb2782f 100644
--- a/examples/3dstudioruntime2/simpleqml/main.qml
+++ b/examples/3dstudioruntime2/simpleqml/main.qml
@@ -72,6 +72,7 @@ Rectangle {
id: s3dpres
source: "qrc:/presentation/barrel.uip"
profilingEnabled: true
+ profileUiScale: profUiScale.value / 100
onCustomSignalEmitted: customSignalName.text = Date.now() + ": " + name
onSlideEntered: slideEnter.text = "Entered slide " + name + "(index " + index + ") on " + elementPath
onSlideExited: slideExit.text = "Exited slide " + name + "(index " + index + ") on " + elementPath
@@ -155,9 +156,6 @@ Rectangle {
}
Button {
text: "Fire event"
- // Here we could open a Dialog to specify a target object and event
- // name but creating a working dialog with Quick Controls 2 is way
- // beyond my modest skills, apparently.
onClicked: s3dpres.fireEvent("Scene.Layer.Camera", "customCameraEvent") // in actionevent.uip this will change the sphere's color
focusPolicy: Qt.NoFocus
}
@@ -211,6 +209,25 @@ Rectangle {
focusPolicy: Qt.NoFocus
}
+ Button {
+ id: profTogBtn
+ text: "Toggle profile UI"
+ anchors.right: parent.right
+ anchors.bottom: parent.bottom
+ focusPolicy: Qt.NoFocus
+ onClicked: s3dpres.profileUiVisible = !s3dpres.profileUiVisible
+ }
+ Slider {
+ id: profUiScale
+ width: profTogBtn.width
+ anchors.right: profTogBtn.left
+ anchors.bottom: parent.bottom
+ from: 50
+ to: 400
+ value: 100
+ focusPolicy: Qt.NoFocus
+ }
+
FileDialog {
id: openDialog
fileMode: FileDialog.OpenFile
diff --git a/src/imports/studio3d/q3dsstudio3ditem.cpp b/src/imports/studio3d/q3dsstudio3ditem.cpp
index 1005580..d964b4a 100644
--- a/src/imports/studio3d/q3dsstudio3ditem.cpp
+++ b/src/imports/studio3d/q3dsstudio3ditem.cpp
@@ -176,14 +176,11 @@ void Q3DSStudio3DItem::createEngine()
// Rendering will be driven manually from the Quick render thread via the QRenderAspect.
// We create the render aspect ourselves on the Quick render thread.
Q3DSEngine::Flags flags = Q3DSEngine::WithoutRenderAspect;
- if (m_sourceFlags.testFlag(Q3DSPresentationController::Profiling)) {
+ if (m_sourceFlags.testFlag(Q3DSPresentationController::Profiling))
flags |= Q3DSEngine::EnableProfiling;
- m_engine->setProfileUiEnabled(true);
- } else {
- m_engine->setProfileUiEnabled(false);
- }
m_engine->setFlags(flags);
+ m_engine->setAutoToggleProfileUi(false); // up to the app to control this via the API instead
// Use our QQmlEngine for QML subpresentations and behavior scripts.
QQmlEngine *qmlEngine = QQmlEngine::contextForObject(this)->engine();
diff --git a/src/runtime/api/q3dspresentation.cpp b/src/runtime/api/q3dspresentation.cpp
index dd0e5b8..fc8009f 100644
--- a/src/runtime/api/q3dspresentation.cpp
+++ b/src/runtime/api/q3dspresentation.cpp
@@ -88,7 +88,44 @@ void Q3DSPresentation::setProfilingEnabled(bool enable)
// must be set up front). Defaults to disabled.
Q_D(Q3DSPresentation);
- d->profiling = enable; // no effect until next setSource()
+ if (d->profiling != enable) {
+ d->profiling = enable; // no effect until next setSource()
+ emit profilingEnabledChanged();
+ }
+}
+
+bool Q3DSPresentation::isProfileUiVisible() const
+{
+ Q_D(const Q3DSPresentation);
+ return d->profiling ? d->profileUiVisible : false;
+}
+
+void Q3DSPresentation::setProfileUiVisible(bool visible)
+{
+ Q_D(Q3DSPresentation);
+ if (d->profiling && d->profileUiVisible != visible) {
+ d->profileUiVisible = visible;
+ if (d->controller)
+ d->controller->handleSetProfileUiVisible(d->profileUiVisible, d->profileUiScale);
+ emit profileUiVisibleChanged();
+ }
+}
+
+float Q3DSPresentation::profileUiScale() const
+{
+ Q_D(const Q3DSPresentation);
+ return d->profileUiScale;
+}
+
+void Q3DSPresentation::setProfileUiScale(float scale)
+{
+ Q_D(Q3DSPresentation);
+ if (d->profileUiScale != scale) {
+ d->profileUiScale = scale;
+ if (d->controller)
+ d->controller->handleSetProfileUiVisible(d->profileUiVisible, d->profileUiScale);
+ emit profileUiScaleChanged();
+ }
}
void Q3DSPresentation::reload()
diff --git a/src/runtime/api/q3dspresentation.h b/src/runtime/api/q3dspresentation.h
index d79f92a..e3a45a0 100644
--- a/src/runtime/api/q3dspresentation.h
+++ b/src/runtime/api/q3dspresentation.h
@@ -47,6 +47,8 @@ class Q3DSV_EXPORT Q3DSPresentation : public QObject
Q_OBJECT
Q_PROPERTY(QUrl source READ source WRITE setSource NOTIFY sourceChanged)
Q_PROPERTY(bool profilingEnabled READ isProfilingEnabled WRITE setProfilingEnabled NOTIFY profilingEnabledChanged)
+ Q_PROPERTY(bool profileUiVisible READ isProfileUiVisible WRITE setProfileUiVisible NOTIFY profileUiVisibleChanged)
+ Q_PROPERTY(float profileUiScale READ profileUiScale WRITE setProfileUiScale NOTIFY profileUiScaleChanged)
public:
explicit Q3DSPresentation(QObject *parent = nullptr);
@@ -58,13 +60,23 @@ public:
bool isProfilingEnabled() const;
void setProfilingEnabled(bool enable);
+ bool isProfileUiVisible() const;
+ void setProfileUiVisible(bool visible);
+
+ float profileUiScale() const;
+ void setProfileUiScale(float scale);
+
Q_INVOKABLE void reload();
+
Q_INVOKABLE void setDataInputValue(const QString &name, const QVariant &value);
+
Q_INVOKABLE void fireEvent(const QString &elementPath, const QString &eventName);
+
Q_INVOKABLE void goToTime(const QString &elementPath, float timeSeconds);
Q_INVOKABLE void goToSlide(const QString &elementPath, const QString &name);
Q_INVOKABLE void goToSlide(const QString &elementPath, int index);
Q_INVOKABLE void goToSlide(const QString &elementPath, bool next, bool wrap);
+
Q_INVOKABLE QVariant getAttribute(const QString &elementPath, const QString &attributeName);
Q_INVOKABLE void setAttribute(const QString &elementPath, const QString &attributeName, const QVariant &value);
@@ -81,6 +93,8 @@ public:
Q_SIGNALS:
void sourceChanged();
void profilingEnabledChanged();
+ void profileUiVisibleChanged();
+ void profileUiScaleChanged();
void customSignalEmitted(const QString &elementPath, const QString &name);
void slideEntered(const QString &elementPath, int index, const QString &name);
void slideExited(const QString &elementPath, int index, const QString &name);
diff --git a/src/runtime/api/q3dspresentation_p.h b/src/runtime/api/q3dspresentation_p.h
index f0fec93..b4d6c57 100644
--- a/src/runtime/api/q3dspresentation_p.h
+++ b/src/runtime/api/q3dspresentation_p.h
@@ -83,6 +83,7 @@ public:
virtual void handleGoToSlideByDirection(const QString &elementPath, bool next, bool wrap);
virtual QVariant handleGetAttribute(const QString &elementPath, const QString &attribute);
virtual void handleSetAttribute(const QString &elementPath, const QString &attributeName, const QVariant &value);
+ virtual void handleSetProfileUiVisible(bool visible, float scale = 1.0f);
protected:
Q3DSEngine *m_pcEngine = nullptr; // don't want clashes with commonly used m_engine members
@@ -103,6 +104,8 @@ public:
QUrl source;
Q3DSPresentationController *controller = nullptr;
bool profiling = false; // unlike the viewer, the public API defaults to profile off
+ bool profileUiVisible = false;
+ float profileUiScale = 1.0f;
};
QT_END_NAMESPACE
diff --git a/src/runtime/api/q3dspresentationcontroller.cpp b/src/runtime/api/q3dspresentationcontroller.cpp
index 850ae4b..edaef22 100644
--- a/src/runtime/api/q3dspresentationcontroller.cpp
+++ b/src/runtime/api/q3dspresentationcontroller.cpp
@@ -193,4 +193,12 @@ void Q3DSPresentationController::handleSetAttribute(const QString &elementPath,
obj->notifyPropertyChanges(cl);
}
+void Q3DSPresentationController::handleSetProfileUiVisible(bool visible, float scale)
+{
+ if (m_pcEngine) {
+ m_pcEngine->setProfileUiVisible(visible);
+ m_pcEngine->configureProfileUi(scale);
+ }
+}
+
QT_END_NAMESPACE
diff --git a/src/runtime/api/q3dssurfaceviewer.cpp b/src/runtime/api/q3dssurfaceviewer.cpp
index 2361d16..8f9f8b2 100644
--- a/src/runtime/api/q3dssurfaceviewer.cpp
+++ b/src/runtime/api/q3dssurfaceviewer.cpp
@@ -307,14 +307,11 @@ bool Q3DSSurfaceViewerPrivate::createEngine()
engine = new Q3DSEngine;
Q3DSEngine::Flags flags = Q3DSEngine::WithoutRenderAspect;
- if (sourceFlags.testFlag(Q3DSPresentationController::Profiling)) {
+ if (sourceFlags.testFlag(Q3DSPresentationController::Profiling))
flags |= Q3DSEngine::EnableProfiling;
- engine->setProfileUiEnabled(true);
- } else {
- engine->setProfileUiEnabled(false);
- }
engine->setFlags(flags);
+ engine->setAutoToggleProfileUi(false); // up to the app to control this via the API instead
switch (surface->surfaceClass()) {
case QSurface::Window:
diff --git a/src/runtime/api/q3dswidget.cpp b/src/runtime/api/q3dswidget.cpp
index c8c0e1c..d174b73 100644
--- a/src/runtime/api/q3dswidget.cpp
+++ b/src/runtime/api/q3dswidget.cpp
@@ -223,14 +223,12 @@ void Q3DSWidgetPrivate::createEngine()
engine = new Q3DSEngine;
Q3DSEngine::Flags flags = Q3DSEngine::WithoutRenderAspect;
- if (sourceFlags.testFlag(Q3DSPresentationController::Profiling)) {
+ if (sourceFlags.testFlag(Q3DSPresentationController::Profiling))
flags |= Q3DSEngine::EnableProfiling;
- engine->setProfileUiEnabled(true);
- } else {
- engine->setProfileUiEnabled(false);
- }
engine->setFlags(flags);
+ engine->setAutoToggleProfileUi(false); // up to the app to control this via the API instead
+
engine->setSurface(q_ptr->window()->windowHandle());
qCDebug(lc3DSWidget, "Created engine %p", engine);
diff --git a/src/runtime/profileui/q3dsprofileui.cpp b/src/runtime/profileui/q3dsprofileui.cpp
index 66f630b..f7c909b 100644
--- a/src/runtime/profileui/q3dsprofileui.cpp
+++ b/src/runtime/profileui/q3dsprofileui.cpp
@@ -67,7 +67,7 @@ public:
void frame();
- void openLog() { m_logWindowOpen = m_consoleWindowOpen = true; }
+ void openLogAndConsole() { m_logWindowOpen = m_consoleWindowOpen = true; }
private:
void addQt3DObjectsWindow();
@@ -1001,9 +1001,9 @@ void Q3DSProfileUi::setVisible(bool visible)
m_guiMgr->setEnabled(m_visible);
}
-void Q3DSProfileUi::openLog()
+void Q3DSProfileUi::openLogAndConsole()
{
- m_view->openLog();
+ m_view->openLogAndConsole();
}
QT_END_NAMESPACE
diff --git a/src/runtime/profileui/q3dsprofileui_p.h b/src/runtime/profileui/q3dsprofileui_p.h
index 8ba9551..234e9e2 100644
--- a/src/runtime/profileui/q3dsprofileui_p.h
+++ b/src/runtime/profileui/q3dsprofileui_p.h
@@ -65,7 +65,7 @@ public:
bool visible() const { return m_visible; }
void setVisible(bool visible);
- void openLog();
+ void openLogAndConsole();
private:
Q3DSGuiData *m_data;
diff --git a/src/runtime/q3dsengine.cpp b/src/runtime/q3dsengine.cpp
index 63d6135..77cfd93 100644
--- a/src/runtime/q3dsengine.cpp
+++ b/src/runtime/q3dsengine.cpp
@@ -1087,7 +1087,7 @@ void Q3DSEngine::handleKeyPressEvent(QKeyEvent *e)
{
bool forwardEvent = isProfileUiVisible();
- if (m_profileUiEnabled) {
+ if (m_autoToggleProfileUi) {
Q3DSSceneManager *sm = !m_uipPresentations.isEmpty() ? m_uipPresentations[0].sceneManager : nullptr;
// not ideal since the window needs focus which it often won't have. also no keyboard on embedded/mobile.
@@ -1177,7 +1177,7 @@ void Q3DSEngine::handleMouseDoubleClickEvent(QMouseEvent *e)
if (isProfileUiVisible())
QCoreApplication::sendEvent(&m_profileUiEventSource, e);
- if (!m_profileUiEnabled)
+ if (!m_autoToggleProfileUi)
return;
// Toggle with short double-clicks. This should work both with
@@ -1219,6 +1219,18 @@ void Q3DSEngine::requestGrab()
}
}
+void Q3DSEngine::setProfileUiVisible(bool visible)
+{
+ if (!m_uipPresentations.isEmpty() && m_uipPresentations[0].sceneManager)
+ m_uipPresentations[0].sceneManager->setProfileUiVisible(visible);
+}
+
+void Q3DSEngine::configureProfileUi(float scale)
+{
+ if (!m_uipPresentations.isEmpty() && m_uipPresentations[0].sceneManager)
+ m_uipPresentations[0].sceneManager->configureProfileUi(scale);
+}
+
void Q3DSEngine::setDataInputValue(const QString &name, const QVariant &value)
{
for (const UipPresentation &pres : qAsConst(m_uipPresentations)) {
diff --git a/src/runtime/q3dsengine_p.h b/src/runtime/q3dsengine_p.h
index 63cb1b6..7c24b6d 100644
--- a/src/runtime/q3dsengine_p.h
+++ b/src/runtime/q3dsengine_p.h
@@ -159,7 +159,9 @@ public:
void handleWheelEvent(QWheelEvent *e);
#endif
- void setProfileUiEnabled(bool enabled) { m_profileUiEnabled = enabled; }
+ void setAutoToggleProfileUi(bool enabled) { m_autoToggleProfileUi = enabled; }
+ void setProfileUiVisible(bool visible);
+ void configureProfileUi(float scale);
typedef QHash<Q3DSBehaviorInstance *, Q3DSBehaviorHandle> BehaviorMap;
@@ -259,7 +261,7 @@ private:
QObject m_profileUiEventSource;
bool m_autoStart = true;
float m_profileUiScale = 1;
- bool m_profileUiEnabled = true;
+ bool m_autoToggleProfileUi = true;
QQmlEngine *m_behaviorQmlEngine = nullptr;
bool m_ownsBehaviorQmlEngine = false;
diff --git a/src/runtime/q3dsscenemanager.cpp b/src/runtime/q3dsscenemanager.cpp
index 7a1aca0..fcd360c 100644
--- a/src/runtime/q3dsscenemanager.cpp
+++ b/src/runtime/q3dsscenemanager.cpp
@@ -6347,17 +6347,17 @@ void Q3DSFrameUpdater::frameAction(float dt)
++m_frameCounter;
}
-void Q3DSSceneManager::setProfileUiVisible(bool visible, bool openLog)
+void Q3DSSceneManager::setProfileUiVisible(bool visible, bool openLogAndConsole)
{
#if QT_CONFIG(q3ds_profileui)
if (m_profileUi) {
m_profileUi->setVisible(visible);
- if (visible && openLog)
- m_profileUi->openLog();
+ if (visible && openLogAndConsole)
+ m_profileUi->openLogAndConsole();
}
#else
Q_UNUSED(visible);
- Q_UNUSED(openLog);
+ Q_UNUSED(openLogAndConsole);
#endif
}
diff --git a/src/runtime/q3dsscenemanager_p.h b/src/runtime/q3dsscenemanager_p.h
index ff789ce..a030d75 100644
--- a/src/runtime/q3dsscenemanager_p.h
+++ b/src/runtime/q3dsscenemanager_p.h
@@ -620,7 +620,7 @@ public:
Q3DSProfiler *profiler() { return m_profiler; }
- void setProfileUiVisible(bool visible, bool openLog = false);
+ void setProfileUiVisible(bool visible, bool openLogAndConsole = false);
bool isProfileUiVisible() const;
void setProfileUiInputEventSource(QObject *obj);
void configureProfileUi(float scale);