aboutsummaryrefslogtreecommitdiffstats
path: root/share/qtcreator
diff options
context:
space:
mode:
authorMiikka Heikkinen <miikka.heikkinen@qt.io>2020-09-10 16:02:31 +0300
committerMiikka Heikkinen <miikka.heikkinen@qt.io>2020-09-16 07:00:06 +0000
commit90d9cb36f3ae756fe08ddfbf74756ada62df6918 (patch)
tree9b277ed53e957412923756eadb3c7530a44b23f9 /share/qtcreator
parentf849bd110552571f985ae691677d7c44b8affd82 (diff)
QmlDesigner: Add navigator preview tooltip for materials
Request 3D preview image for material instances from puppet to show on tooltip. Support for effect previews is also done, but handler for it is not registered, as effects cannot be shared between windows due to issue QTBUG-86616. Also refactored the preview image support out of navigator to make it more accessible by other components. Change-Id: Ie08ba218f929660c2e43d39578997a5a1a883efd Reviewed-by: Thomas Hartmann <thomas.hartmann@qt.io>
Diffstat (limited to 'share/qtcreator')
-rw-r--r--share/qtcreator/qml/qmlpuppet/commands/commands.pri6
-rw-r--r--share/qtcreator/qml/qmlpuppet/commands/puppettocreatorcommand.h2
-rw-r--r--share/qtcreator/qml/qmlpuppet/commands/requestmodelnodepreviewimagecommand.cpp73
-rw-r--r--share/qtcreator/qml/qmlpuppet/commands/requestmodelnodepreviewimagecommand.h60
-rw-r--r--share/qtcreator/qml/qmlpuppet/instances/nodeinstanceclientproxy.cpp9
-rw-r--r--share/qtcreator/qml/qmlpuppet/instances/nodeinstanceclientproxy.h2
-rw-r--r--share/qtcreator/qml/qmlpuppet/interfaces/nodeinstanceserverinterface.cpp4
-rw-r--r--share/qtcreator/qml/qmlpuppet/interfaces/nodeinstanceserverinterface.h2
-rw-r--r--share/qtcreator/qml/qmlpuppet/mockfiles/EffectNodeView.qml65
-rw-r--r--share/qtcreator/qml/qmlpuppet/mockfiles/MaterialNodeView.qml59
-rw-r--r--share/qtcreator/qml/qmlpuppet/mockfiles/ModelNode3DImageView.qml96
-rw-r--r--share/qtcreator/qml/qmlpuppet/qml2puppet/instances/nodeinstanceserver.cpp6
-rw-r--r--share/qtcreator/qml/qmlpuppet/qml2puppet/instances/nodeinstanceserver.h1
-rw-r--r--share/qtcreator/qml/qmlpuppet/qml2puppet/instances/nodeinstanceserverdispatcher.cpp6
-rw-r--r--share/qtcreator/qml/qmlpuppet/qml2puppet/instances/nodeinstanceserverdispatcher.h1
-rw-r--r--share/qtcreator/qml/qmlpuppet/qml2puppet/instances/qt5informationnodeinstanceserver.cpp128
-rw-r--r--share/qtcreator/qml/qmlpuppet/qml2puppet/instances/qt5informationnodeinstanceserver.h16
-rw-r--r--share/qtcreator/qml/qmlpuppet/qmlpuppet.qrc3
18 files changed, 511 insertions, 28 deletions
diff --git a/share/qtcreator/qml/qmlpuppet/commands/commands.pri b/share/qtcreator/qml/qmlpuppet/commands/commands.pri
index 680abb2744..270c326a33 100644
--- a/share/qtcreator/qml/qmlpuppet/commands/commands.pri
+++ b/share/qtcreator/qml/qmlpuppet/commands/commands.pri
@@ -34,7 +34,8 @@ HEADERS += $$PWD/synchronizecommand.h \ \
$$PWD/update3dviewstatecommand.h \
$$PWD/puppettocreatorcommand.h \
$$PWD/inputeventcommand.h \
- $$PWD/view3dactioncommand.h
+ $$PWD/view3dactioncommand.h \
+ $$PWD/requestmodelnodepreviewimagecommand.h
SOURCES += $$PWD/synchronizecommand.cpp \
$$PWD/changepreviewimagesizecommand.cpp \
@@ -68,4 +69,5 @@ SOURCES += $$PWD/synchronizecommand.cpp \
$$PWD/update3dviewstatecommand.cpp \
$$PWD/puppettocreatorcommand.cpp \
$$PWD/inputeventcommand.cpp \
- $$PWD/view3dactioncommand.cpp
+ $$PWD/view3dactioncommand.cpp \
+ $$PWD/requestmodelnodepreviewimagecommand.cpp
diff --git a/share/qtcreator/qml/qmlpuppet/commands/puppettocreatorcommand.h b/share/qtcreator/qml/qmlpuppet/commands/puppettocreatorcommand.h
index a713656bde..dc125d4ead 100644
--- a/share/qtcreator/qml/qmlpuppet/commands/puppettocreatorcommand.h
+++ b/share/qtcreator/qml/qmlpuppet/commands/puppettocreatorcommand.h
@@ -34,7 +34,7 @@ namespace QmlDesigner {
class PuppetToCreatorCommand
{
public:
- enum Type { Edit3DToolState, Render3DView, ActiveSceneChanged, None };
+ enum Type { Edit3DToolState, Render3DView, ActiveSceneChanged, RenderModelNodePreviewImage, None };
PuppetToCreatorCommand(Type type, const QVariant &data);
PuppetToCreatorCommand() = default;
diff --git a/share/qtcreator/qml/qmlpuppet/commands/requestmodelnodepreviewimagecommand.cpp b/share/qtcreator/qml/qmlpuppet/commands/requestmodelnodepreviewimagecommand.cpp
new file mode 100644
index 0000000000..c29ec216c8
--- /dev/null
+++ b/share/qtcreator/qml/qmlpuppet/commands/requestmodelnodepreviewimagecommand.cpp
@@ -0,0 +1,73 @@
+/****************************************************************************
+**
+** Copyright (C) 2020 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of Qt Creator.
+**
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3 as published by the Free Software
+** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-3.0.html.
+**
+****************************************************************************/
+
+#include "requestmodelnodepreviewimagecommand.h"
+
+#include <QDataStream>
+#include <QDebug>
+
+namespace QmlDesigner {
+
+RequestModelNodePreviewImageCommand::RequestModelNodePreviewImageCommand() = default;
+
+RequestModelNodePreviewImageCommand::RequestModelNodePreviewImageCommand(qint32 id, const QSize &size)
+ : m_instanceId(id)
+ , m_size(size)
+{
+}
+
+qint32 RequestModelNodePreviewImageCommand::instanceId() const
+{
+ return m_instanceId;
+}
+
+QSize QmlDesigner::RequestModelNodePreviewImageCommand::size() const
+{
+ return m_size;
+}
+
+QDataStream &operator<<(QDataStream &out, const RequestModelNodePreviewImageCommand &command)
+{
+ out << int(command.instanceId());
+ out << command.size();
+
+ return out;
+}
+
+QDataStream &operator>>(QDataStream &in, RequestModelNodePreviewImageCommand &command)
+{
+ in >> command.m_instanceId;
+ in >> command.m_size;
+ return in;
+}
+
+QDebug operator <<(QDebug debug, const RequestModelNodePreviewImageCommand &command)
+{
+ return debug.nospace() << "RequestModelNodePreviewImageCommand("
+ << "instanceId: " << command.instanceId() << ", "
+ << "size: " << command.size() << ")";
+}
+
+} // namespace QmlDesigner
diff --git a/share/qtcreator/qml/qmlpuppet/commands/requestmodelnodepreviewimagecommand.h b/share/qtcreator/qml/qmlpuppet/commands/requestmodelnodepreviewimagecommand.h
new file mode 100644
index 0000000000..f18055695b
--- /dev/null
+++ b/share/qtcreator/qml/qmlpuppet/commands/requestmodelnodepreviewimagecommand.h
@@ -0,0 +1,60 @@
+/****************************************************************************
+**
+** Copyright (C) 2020 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of Qt Creator.
+**
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3 as published by the Free Software
+** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-3.0.html.
+**
+****************************************************************************/
+
+#pragma once
+
+#include <QtCore/qmetatype.h>
+#include <QtCore/qdatastream.h>
+#include <QtGui/qevent.h>
+
+#include "instancecontainer.h"
+
+namespace QmlDesigner {
+
+class RequestModelNodePreviewImageCommand
+{
+ friend QDataStream &operator>>(QDataStream &in, RequestModelNodePreviewImageCommand &command);
+ friend QDebug operator <<(QDebug debug, const RequestModelNodePreviewImageCommand &command);
+
+public:
+ RequestModelNodePreviewImageCommand();
+ explicit RequestModelNodePreviewImageCommand(qint32 id, const QSize &size);
+
+ qint32 instanceId() const;
+ QSize size() const;
+
+private:
+ qint32 m_instanceId;
+ QSize m_size;
+};
+
+QDataStream &operator<<(QDataStream &out, const RequestModelNodePreviewImageCommand &command);
+QDataStream &operator>>(QDataStream &in, RequestModelNodePreviewImageCommand &command);
+
+QDebug operator <<(QDebug debug, const RequestModelNodePreviewImageCommand &command);
+
+} // namespace QmlDesigner
+
+Q_DECLARE_METATYPE(QmlDesigner::RequestModelNodePreviewImageCommand)
diff --git a/share/qtcreator/qml/qmlpuppet/instances/nodeinstanceclientproxy.cpp b/share/qtcreator/qml/qmlpuppet/instances/nodeinstanceclientproxy.cpp
index 0c0f4fec78..ded21b71cf 100644
--- a/share/qtcreator/qml/qmlpuppet/instances/nodeinstanceclientproxy.cpp
+++ b/share/qtcreator/qml/qmlpuppet/instances/nodeinstanceclientproxy.cpp
@@ -75,6 +75,7 @@
#include "update3dviewstatecommand.h"
#include "valueschangedcommand.h"
#include "view3dactioncommand.h"
+#include "requestmodelnodepreviewimagecommand.h"
namespace QmlDesigner {
@@ -339,6 +340,11 @@ void NodeInstanceClientProxy::view3DAction(const View3DActionCommand &command)
nodeInstanceServer()->view3DAction(command);
}
+void NodeInstanceClientProxy::requestModelNodePreviewImage(const RequestModelNodePreviewImageCommand &command)
+{
+ nodeInstanceServer()->requestModelNodePreviewImage(command);
+}
+
void NodeInstanceClientProxy::changeLanguage(const ChangeLanguageCommand &command)
{
nodeInstanceServer()->changeLanguage(command);
@@ -516,6 +522,7 @@ void NodeInstanceClientProxy::dispatchCommand(const QVariant &command)
static const int changeSelectionCommandType = QMetaType::type("ChangeSelectionCommand");
static const int inputEventCommandType = QMetaType::type("InputEventCommand");
static const int view3DActionCommandType = QMetaType::type("View3DActionCommand");
+ static const int requestModelNodePreviewImageCommandType = QMetaType::type("RequestModelNodePreviewImageCommand");
static const int changeLanguageCommand = QMetaType::type("ChangeLanguageCommand");
static const int changePreviewImageSizeCommand = QMetaType::type(
"ChangePreviewImageSizeCommand");
@@ -562,6 +569,8 @@ void NodeInstanceClientProxy::dispatchCommand(const QVariant &command)
redirectToken(command.value<EndPuppetCommand>());
else if (commandType == view3DActionCommandType)
view3DAction(command.value<View3DActionCommand>());
+ else if (commandType == requestModelNodePreviewImageCommandType)
+ requestModelNodePreviewImage(command.value<RequestModelNodePreviewImageCommand>());
else if (commandType == synchronizeCommandType) {
SynchronizeCommand synchronizeCommand = command.value<SynchronizeCommand>();
m_synchronizeId = synchronizeCommand.synchronizeId();
diff --git a/share/qtcreator/qml/qmlpuppet/instances/nodeinstanceclientproxy.h b/share/qtcreator/qml/qmlpuppet/instances/nodeinstanceclientproxy.h
index 11658c5dd5..f4471b3470 100644
--- a/share/qtcreator/qml/qmlpuppet/instances/nodeinstanceclientproxy.h
+++ b/share/qtcreator/qml/qmlpuppet/instances/nodeinstanceclientproxy.h
@@ -63,6 +63,7 @@ class ChangeSelectionCommand;
class PuppetToCreatorCommand;
class InputEventCommand;
class View3DActionCommand;
+class RequestModelNodePreviewImageCommand;
class ChangeLanguageCommand;
class ChangePreviewImageSizeCommand;
@@ -123,6 +124,7 @@ protected:
static QVariant readCommandFromIOStream(QIODevice *ioDevice, quint32 *readCommandCounter, quint32 *blockSize);
void inputEvent(const InputEventCommand &command);
void view3DAction(const View3DActionCommand &command);
+ void requestModelNodePreviewImage(const RequestModelNodePreviewImageCommand &command);
void changeLanguage(const ChangeLanguageCommand &command);
void changePreviewImageSize(const ChangePreviewImageSizeCommand &command);
diff --git a/share/qtcreator/qml/qmlpuppet/interfaces/nodeinstanceserverinterface.cpp b/share/qtcreator/qml/qmlpuppet/interfaces/nodeinstanceserverinterface.cpp
index 638308af11..3e3351e507 100644
--- a/share/qtcreator/qml/qmlpuppet/interfaces/nodeinstanceserverinterface.cpp
+++ b/share/qtcreator/qml/qmlpuppet/interfaces/nodeinstanceserverinterface.cpp
@@ -67,6 +67,7 @@
#include "update3dviewstatecommand.h"
#include "valueschangedcommand.h"
#include "view3dactioncommand.h"
+#include "requestmodelnodepreviewimagecommand.h"
#include <enumeration.h>
@@ -213,6 +214,9 @@ void NodeInstanceServerInterface::registerCommands()
qRegisterMetaType<View3DActionCommand>("View3DActionCommand");
qRegisterMetaTypeStreamOperators<View3DActionCommand>("View3DActionCommand");
+ qRegisterMetaType<RequestModelNodePreviewImageCommand>("RequestModelNodePreviewImageCommand");
+ qRegisterMetaTypeStreamOperators<RequestModelNodePreviewImageCommand>("RequestModelNodePreviewImageCommand");
+
qRegisterMetaType<QPair<int, int>>("QPairIntInt");
qRegisterMetaTypeStreamOperators<QPair<int, int>>("QPairIntInt");
diff --git a/share/qtcreator/qml/qmlpuppet/interfaces/nodeinstanceserverinterface.h b/share/qtcreator/qml/qmlpuppet/interfaces/nodeinstanceserverinterface.h
index 39eb2618d6..841cd8561e 100644
--- a/share/qtcreator/qml/qmlpuppet/interfaces/nodeinstanceserverinterface.h
+++ b/share/qtcreator/qml/qmlpuppet/interfaces/nodeinstanceserverinterface.h
@@ -53,6 +53,7 @@ class RemoveSharedMemoryCommand;
class ChangeSelectionCommand;
class InputEventCommand;
class View3DActionCommand;
+class RequestModelNodePreviewImageCommand;
class ChangeLanguageCommand;
class ChangePreviewImageSizeCommand;
@@ -82,6 +83,7 @@ public:
virtual void changeSelection(const ChangeSelectionCommand &command) = 0;
virtual void inputEvent(const InputEventCommand &command) = 0;
virtual void view3DAction(const View3DActionCommand &command) = 0;
+ virtual void requestModelNodePreviewImage(const RequestModelNodePreviewImageCommand &command) = 0;
virtual void changeLanguage(const ChangeLanguageCommand &command) = 0;
virtual void changePreviewImageSize(const ChangePreviewImageSizeCommand &command) = 0;
diff --git a/share/qtcreator/qml/qmlpuppet/mockfiles/EffectNodeView.qml b/share/qtcreator/qml/qmlpuppet/mockfiles/EffectNodeView.qml
new file mode 100644
index 0000000000..9259e0d08f
--- /dev/null
+++ b/share/qtcreator/qml/qmlpuppet/mockfiles/EffectNodeView.qml
@@ -0,0 +1,65 @@
+/****************************************************************************
+**
+** Copyright (C) 2020 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of Qt Creator.
+**
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3 as published by the Free Software
+** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-3.0.html.
+**
+****************************************************************************/
+
+import QtQuick3D 1.15
+import QtQuick3D.Effects 1.15
+
+View3D {
+ id: root
+ anchors.fill: parent
+ environment: sceneEnv
+
+ property Effect previewEffect
+
+ SceneEnvironment {
+ id: sceneEnv
+ antialiasingMode: SceneEnvironment.MSAA
+ antialiasingQuality: SceneEnvironment.High
+ effects: previewEffect
+ }
+
+ Node {
+ DirectionalLight {
+ eulerRotation.x: -30
+ eulerRotation.y: -30
+ }
+
+ PerspectiveCamera {
+ z: 120
+ clipFar: 1000
+ clipNear: 1
+ }
+
+ Model {
+ id: model
+ source: "#Sphere"
+ materials: [
+ DefaultMaterial {
+ diffuseColor: "green"
+ }
+ ]
+ }
+ }
+}
diff --git a/share/qtcreator/qml/qmlpuppet/mockfiles/MaterialNodeView.qml b/share/qtcreator/qml/qmlpuppet/mockfiles/MaterialNodeView.qml
new file mode 100644
index 0000000000..f52bcf4bee
--- /dev/null
+++ b/share/qtcreator/qml/qmlpuppet/mockfiles/MaterialNodeView.qml
@@ -0,0 +1,59 @@
+/****************************************************************************
+**
+** Copyright (C) 2020 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of Qt Creator.
+**
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3 as published by the Free Software
+** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-3.0.html.
+**
+****************************************************************************/
+
+import QtQuick3D 1.15
+
+View3D {
+ id: root
+ anchors.fill: parent
+ environment: sceneEnv
+
+ property Material previewMaterial
+
+ SceneEnvironment {
+ id: sceneEnv
+ antialiasingMode: SceneEnvironment.MSAA
+ antialiasingQuality: SceneEnvironment.High
+ }
+
+ Node {
+ DirectionalLight {
+ eulerRotation.x: -30
+ eulerRotation.y: -30
+ }
+
+ PerspectiveCamera {
+ z: 120
+ clipFar: 1000
+ clipNear: 1
+ }
+
+ Model {
+ id: model
+ source: "#Sphere"
+ materials: previewMaterial
+ }
+ }
+}
diff --git a/share/qtcreator/qml/qmlpuppet/mockfiles/ModelNode3DImageView.qml b/share/qtcreator/qml/qmlpuppet/mockfiles/ModelNode3DImageView.qml
new file mode 100644
index 0000000000..b0ed2114ea
--- /dev/null
+++ b/share/qtcreator/qml/qmlpuppet/mockfiles/ModelNode3DImageView.qml
@@ -0,0 +1,96 @@
+/****************************************************************************
+**
+** Copyright (C) 2020 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of Qt Creator.
+**
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3 as published by the Free Software
+** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-3.0.html.
+**
+****************************************************************************/
+
+import QtQuick 2.15
+import QtQuick3D 1.15
+import QtQuick3D.Effects 1.15
+
+Item {
+ id: root
+ width: 150
+ height: 150
+ visible: true
+
+ property View3D view: null
+ property alias contentItem: contentItem
+
+ property var materialViewComponent
+ property var effectViewComponent
+
+ function destroyView()
+ {
+ if (view) {
+ // Destroy is async, so make sure we don't get any more updates for the old view
+ _generalHelper.enableItemUpdate(view, false);
+ view.destroy();
+ }
+ }
+
+ function createViewForObject(obj, w, h)
+ {
+ width = w;
+ height = h;
+
+ if (obj instanceof Material)
+ createViewForMaterial(obj);
+ else if (obj instanceof Effect)
+ createViewForEffect(obj);
+ }
+
+ function createViewForMaterial(material)
+ {
+ if (!materialViewComponent)
+ materialViewComponent = Qt.createComponent("MaterialNodeView.qml");
+
+ // Always recreate the view to ensure material is up to date
+ if (materialViewComponent.status === Component.Ready)
+ view = materialViewComponent.createObject(viewRect, {"previewMaterial": material});
+ }
+
+ function createViewForEffect(effect)
+ {
+ if (!effectViewComponent)
+ effectViewComponent = Qt.createComponent("EffectNodeView.qml");
+
+ // Always recreate the view to ensure effect is up to date
+ if (effectViewComponent.status === Component.Ready)
+ view = effectViewComponent.createObject(viewRect, {"previewEffect": effect});
+ }
+
+ Item {
+ id: contentItem
+ anchors.fill: parent
+
+ Rectangle {
+ id: viewRect
+ anchors.fill: parent
+
+ gradient: Gradient {
+ GradientStop { position: 1.0; color: "#222222" }
+ GradientStop { position: 0.0; color: "#999999" }
+ }
+ }
+ }
+}
diff --git a/share/qtcreator/qml/qmlpuppet/qml2puppet/instances/nodeinstanceserver.cpp b/share/qtcreator/qml/qmlpuppet/qml2puppet/instances/nodeinstanceserver.cpp
index 6bbaebe086..45d5fce845 100644
--- a/share/qtcreator/qml/qmlpuppet/qml2puppet/instances/nodeinstanceserver.cpp
+++ b/share/qtcreator/qml/qmlpuppet/qml2puppet/instances/nodeinstanceserver.cpp
@@ -69,6 +69,7 @@
#include <changeselectioncommand.h>
#include <inputeventcommand.h>
#include <view3dactioncommand.h>
+#include <requestmodelnodepreviewimagecommand.h>
#include <changelanguagecommand.h>
#include <QDebug>
@@ -1417,6 +1418,11 @@ void NodeInstanceServer::view3DAction(const View3DActionCommand &command)
Q_UNUSED(command)
}
+void NodeInstanceServer::requestModelNodePreviewImage(const RequestModelNodePreviewImageCommand &command)
+{
+ Q_UNUSED(command)
+}
+
void NodeInstanceServer::changeLanguage(const ChangeLanguageCommand &command)
{
setTranslationLanguage(command.language);
diff --git a/share/qtcreator/qml/qmlpuppet/qml2puppet/instances/nodeinstanceserver.h b/share/qtcreator/qml/qmlpuppet/qml2puppet/instances/nodeinstanceserver.h
index 0c5810b3ec..bd6349d29a 100644
--- a/share/qtcreator/qml/qmlpuppet/qml2puppet/instances/nodeinstanceserver.h
+++ b/share/qtcreator/qml/qmlpuppet/qml2puppet/instances/nodeinstanceserver.h
@@ -152,6 +152,7 @@ public:
void changeSelection(const ChangeSelectionCommand &command) override;
void inputEvent(const InputEventCommand &command) override;
void view3DAction(const View3DActionCommand &command) override;
+ void requestModelNodePreviewImage(const RequestModelNodePreviewImageCommand &command) override;
void changeLanguage(const ChangeLanguageCommand &command) override;
void changePreviewImageSize(const ChangePreviewImageSizeCommand &command) override;
diff --git a/share/qtcreator/qml/qmlpuppet/qml2puppet/instances/nodeinstanceserverdispatcher.cpp b/share/qtcreator/qml/qmlpuppet/qml2puppet/instances/nodeinstanceserverdispatcher.cpp
index a06a156e15..dd9c42c5bd 100644
--- a/share/qtcreator/qml/qmlpuppet/qml2puppet/instances/nodeinstanceserverdispatcher.cpp
+++ b/share/qtcreator/qml/qmlpuppet/qml2puppet/instances/nodeinstanceserverdispatcher.cpp
@@ -158,6 +158,12 @@ void NodeInstanceServerDispatcher::view3DAction(const View3DActionCommand &comma
server->view3DAction(command);
}
+void NodeInstanceServerDispatcher::requestModelNodePreviewImage(const RequestModelNodePreviewImageCommand &command)
+{
+ for (std::unique_ptr<NodeInstanceServer> &server : m_servers)
+ server->requestModelNodePreviewImage(command);
+}
+
void NodeInstanceServerDispatcher::changeLanguage(const ChangeLanguageCommand &command)
{
for (std::unique_ptr<NodeInstanceServer> &server : m_servers)
diff --git a/share/qtcreator/qml/qmlpuppet/qml2puppet/instances/nodeinstanceserverdispatcher.h b/share/qtcreator/qml/qmlpuppet/qml2puppet/instances/nodeinstanceserverdispatcher.h
index c09c629573..03323a511d 100644
--- a/share/qtcreator/qml/qmlpuppet/qml2puppet/instances/nodeinstanceserverdispatcher.h
+++ b/share/qtcreator/qml/qmlpuppet/qml2puppet/instances/nodeinstanceserverdispatcher.h
@@ -58,6 +58,7 @@ public:
void changeSelection(const ChangeSelectionCommand &command);
void inputEvent(const InputEventCommand &command);
void view3DAction(const View3DActionCommand &command);
+ void requestModelNodePreviewImage(const RequestModelNodePreviewImageCommand &command);
void changeLanguage(const ChangeLanguageCommand &command);
void changePreviewImageSize(const ChangePreviewImageSizeCommand &command);
diff --git a/share/qtcreator/qml/qmlpuppet/qml2puppet/instances/qt5informationnodeinstanceserver.cpp b/share/qtcreator/qml/qmlpuppet/qml2puppet/instances/qt5informationnodeinstanceserver.cpp
index 6b6cbefa5e..54e36f7420 100644
--- a/share/qtcreator/qml/qmlpuppet/qml2puppet/instances/qt5informationnodeinstanceserver.cpp
+++ b/share/qtcreator/qml/qmlpuppet/qml2puppet/instances/qt5informationnodeinstanceserver.cpp
@@ -62,6 +62,7 @@
#include "puppettocreatorcommand.h"
#include "inputeventcommand.h"
#include "view3dactioncommand.h"
+#include "requestmodelnodepreviewimagecommand.h"
#include "dummycontextobject.h"
#include "../editor3d/generalhelper.h"
@@ -145,13 +146,35 @@ void Qt5InformationNodeInstanceServer::createEditView3D()
this, &Qt5InformationNodeInstanceServer::handleObjectPropertyChangeTimeout);
QObject::connect(&m_selectionChangeTimer, &QTimer::timeout,
this, &Qt5InformationNodeInstanceServer::handleSelectionChangeTimeout);
- QObject::connect(&m_renderTimer, &QTimer::timeout,
+ QObject::connect(&m_render3DEditViewTimer, &QTimer::timeout,
this, &Qt5InformationNodeInstanceServer::doRender3DEditView);
+ QObject::connect(&m_renderModelNode3DImageViewTimer, &QTimer::timeout,
+ this, &Qt5InformationNodeInstanceServer::doRenderModelNode3DImageView);
helper->setParent(m_editView3DRootItem);
#endif
}
+void Qt5InformationNodeInstanceServer::create3DPreviewView()
+{
+#ifdef QUICK3D_MODULE
+ // This function assumes createEditView3D() has been called previously
+ m_ModelNode3DImageView = new QQuickView(quickView()->engine(), quickView());
+ m_ModelNode3DImageView->setFormat(quickView()->format());
+ DesignerSupport::createOpenGLContext(m_ModelNode3DImageView.data());
+ QQmlComponent component(engine());
+ component.loadUrl(QUrl("qrc:/qtquickplugin/mockfiles/ModelNode3DImageView.qml"));
+ m_ModelNode3DImageViewRootItem = qobject_cast<QQuickItem *>(component.create());
+
+ if (!m_ModelNode3DImageViewRootItem) {
+ qWarning() << "Could not create ModelNode preview image 3D view: " << component.errors();
+ return;
+ }
+
+ DesignerSupport::setRootItem(m_ModelNode3DImageView, m_ModelNode3DImageViewRootItem);
+#endif
+}
+
// The selection has changed in the edit view 3D. Empty list indicates selection is cleared.
void Qt5InformationNodeInstanceServer::handleSelectionChanged(const QVariant &objs)
{
@@ -440,31 +463,37 @@ ServerNodeInstance Qt5InformationNodeInstanceServer::active3DSceneInstance() con
return sceneInstance;
}
+void Qt5InformationNodeInstanceServer::updateNodesRecursive(QQuickItem *item)
+{
+ for (QQuickItem *childItem : item->childItems())
+ updateNodesRecursive(childItem);
+ DesignerSupport::updateDirtyNode(item);
+}
+
+QQuickItem *Qt5InformationNodeInstanceServer::getContentItemForRendering(QQuickItem *rootItem)
+{
+ QQuickItem *contentItem = QQmlProperty::read(rootItem, "contentItem").value<QQuickItem *>();
+ if (contentItem) {
+ designerSupport()->refFromEffectItem(contentItem, false);
+ QmlDesigner::Internal::QmlPrivateGate::disableNativeTextRendering(contentItem);
+ }
+ return contentItem;
+}
+
void Qt5InformationNodeInstanceServer::render3DEditView(int count)
{
- m_needRender = qMax(count, m_needRender);
- if (!m_renderTimer.isActive())
- m_renderTimer.start(0);
+ m_need3DEditViewRender = qMax(count, m_need3DEditViewRender);
+ if (!m_render3DEditViewTimer.isActive())
+ m_render3DEditViewTimer.start(0);
}
// render the 3D edit view and send the result to creator process
void Qt5InformationNodeInstanceServer::doRender3DEditView()
{
if (m_editView3DRootItem) {
- if (!m_editView3DContentItem) {
- m_editView3DContentItem = QQmlProperty::read(m_editView3DRootItem, "contentItem").value<QQuickItem *>();
- if (m_editView3DContentItem) {
- designerSupport()->refFromEffectItem(m_editView3DContentItem, false);
- QmlDesigner::Internal::QmlPrivateGate::disableNativeTextRendering(m_editView3DContentItem);
- }
- }
+ if (!m_editView3DContentItem)
+ m_editView3DContentItem = getContentItemForRendering(m_editView3DRootItem);
- std::function<void (QQuickItem *)> updateNodesRecursive;
- updateNodesRecursive = [&updateNodesRecursive](QQuickItem *item) {
- for (QQuickItem *childItem : item->childItems())
- updateNodesRecursive(childItem);
- DesignerSupport::updateDirtyNode(item);
- };
updateNodesRecursive(m_editView3DContentItem);
// Fake render loop signaling to update things like QML items as 3D textures
@@ -480,26 +509,69 @@ void Qt5InformationNodeInstanceServer::doRender3DEditView()
// There's no instance related to image, so instance id is -1.
// Key number is selected so that it is unlikely to conflict other ImageContainer use.
- const qint32 edit3DKey = 2100000000;
- auto imgContainer = ImageContainer(-1, renderImage, edit3DKey);
+ auto imgContainer = ImageContainer(-1, renderImage, 2100000000);
// send the rendered image to creator process
nodeInstanceClient()->handlePuppetToCreatorCommand({PuppetToCreatorCommand::Render3DView,
QVariant::fromValue(imgContainer)});
- if (m_needRender > 0) {
- m_renderTimer.start(0);
- --m_needRender;
+ if (m_need3DEditViewRender > 0) {
+ m_render3DEditViewTimer.start(0);
+ --m_need3DEditViewRender;
}
}
}
+void Qt5InformationNodeInstanceServer::renderModelNode3DImageView()
+{
+ if (!m_renderModelNode3DImageViewTimer.isActive())
+ m_renderModelNode3DImageViewTimer.start(0);
+}
+
+void Qt5InformationNodeInstanceServer::doRenderModelNode3DImageView()
+{
+ if (m_ModelNode3DImageViewRootItem) {
+ if (!m_ModelNode3DImageViewContentItem)
+ m_ModelNode3DImageViewContentItem = getContentItemForRendering(m_ModelNode3DImageViewRootItem);
+
+ ServerNodeInstance instance = instanceForId(m_modelNodelPreviewImageCommand.instanceId());
+ QObject *instanceObj = instance.internalObject();
+ QSize renderSize = m_modelNodelPreviewImageCommand.size() * 2;
+ QMetaObject::invokeMethod(m_ModelNode3DImageViewRootItem, "createViewForObject",
+ Q_ARG(QVariant, objectToVariant(instanceObj)),
+ Q_ARG(QVariant, QVariant::fromValue(renderSize.width())),
+ Q_ARG(QVariant, QVariant::fromValue(renderSize.height())));
+
+ updateNodesRecursive(m_ModelNode3DImageViewContentItem);
+
+ // Fake render loop signaling to update things like QML items as 3D textures
+ m_editView3D->beforeSynchronizing();
+ m_editView3D->beforeRendering();
+
+ QSizeF size = qobject_cast<QQuickItem *>(m_ModelNode3DImageViewContentItem)->size();
+ QRectF renderRect(QPointF(0., 0.), size);
+ QImage renderImage = designerSupport()->renderImageForItem(m_ModelNode3DImageViewContentItem,
+ renderRect, size.toSize());
+ m_editView3D->afterRendering();
+
+ QMetaObject::invokeMethod(m_ModelNode3DImageViewRootItem, "destroyView");
+
+ // Key number is selected so that it is unlikely to conflict other ImageContainer use.
+ auto imgContainer = ImageContainer(m_modelNodelPreviewImageCommand.instanceId(), renderImage, 2100000001);
+
+ // send the rendered image to creator process
+ nodeInstanceClient()->handlePuppetToCreatorCommand({PuppetToCreatorCommand::RenderModelNodePreviewImage,
+ QVariant::fromValue(imgContainer)});
+ }
+}
+
Qt5InformationNodeInstanceServer::Qt5InformationNodeInstanceServer(NodeInstanceClientInterface *nodeInstanceClient) :
Qt5NodeInstanceServer(nodeInstanceClient)
{
m_propertyChangeTimer.setInterval(100);
m_propertyChangeTimer.setSingleShot(true);
m_selectionChangeTimer.setSingleShot(true);
- m_renderTimer.setSingleShot(true);
+ m_render3DEditViewTimer.setSingleShot(true);
+ m_renderModelNode3DImageViewTimer.setSingleShot(true);
}
void Qt5InformationNodeInstanceServer::sendTokenBack()
@@ -815,6 +887,7 @@ void Qt5InformationNodeInstanceServer::setup3DEditView(const QList<ServerNodeIns
add3DScenes(instanceList);
createEditView3D();
+ create3DPreviewView();
QString lastSceneId;
auto helper = qobject_cast<QmlDesigner::Internal::GeneralHelper *>(m_3dHelper);
@@ -1237,6 +1310,15 @@ void Qt5InformationNodeInstanceServer::view3DAction(const View3DActionCommand &c
render3DEditView(renderCount);
}
+void Qt5InformationNodeInstanceServer::requestModelNodePreviewImage(const RequestModelNodePreviewImageCommand &command)
+{
+ m_modelNodelPreviewImageCommand = command;
+
+ ServerNodeInstance instance = instanceForId(m_modelNodelPreviewImageCommand.instanceId());
+ if (instance.isSubclassOf("QQuick3DObject"))
+ renderModelNode3DImageView();
+}
+
void Qt5InformationNodeInstanceServer::changeAuxiliaryValues(const ChangeAuxiliaryCommand &command)
{
Qt5NodeInstanceServer::changeAuxiliaryValues(command);
diff --git a/share/qtcreator/qml/qmlpuppet/qml2puppet/instances/qt5informationnodeinstanceserver.h b/share/qtcreator/qml/qmlpuppet/qml2puppet/instances/qt5informationnodeinstanceserver.h
index 40668da55d..f85d974e0f 100644
--- a/share/qtcreator/qml/qmlpuppet/qml2puppet/instances/qt5informationnodeinstanceserver.h
+++ b/share/qtcreator/qml/qmlpuppet/qml2puppet/instances/qt5informationnodeinstanceserver.h
@@ -29,6 +29,7 @@
#include "tokencommand.h"
#include "valueschangedcommand.h"
#include "changeselectioncommand.h"
+#include "requestmodelnodepreviewimagecommand.h"
#include <QTimer>
#include <QVariant>
@@ -59,6 +60,7 @@ public:
void removeInstances(const RemoveInstancesCommand &command) override;
void inputEvent(const InputEventCommand &command) override;
void view3DAction(const View3DActionCommand &command) override;
+ void requestModelNodePreviewImage(const RequestModelNodePreviewImageCommand &command) override;
void changeAuxiliaryValues(const ChangeAuxiliaryCommand &command) override;
void changePropertyBindings(const ChangeBindingsCommand &command) override;
void changeIds(const ChangeIdsCommand &command) override;
@@ -89,6 +91,7 @@ private:
void handleObjectPropertyChangeTimeout();
void handleSelectionChangeTimeout();
void createEditView3D();
+ void create3DPreviewView();
void setup3DEditView(const QList<ServerNodeInstance> &instanceList,
const QHash<QString, QVariantMap> &toolStates);
void createCameraAndLightGizmos(const QList<ServerNodeInstance> &instanceList) const;
@@ -110,12 +113,20 @@ private:
void removeNode3D(QObject *node);
void resolveSceneRoots();
ServerNodeInstance active3DSceneInstance() const;
+ void updateNodesRecursive(QQuickItem *item);
+ QQuickItem *getContentItemForRendering(QQuickItem *rootItem);
void render3DEditView(int count = 1);
void doRender3DEditView();
+ void renderModelNode3DImageView();
+ void doRenderModelNode3DImageView();
QPointer<QQuickView> m_editView3D;
QQuickItem *m_editView3DRootItem = nullptr;
QQuickItem *m_editView3DContentItem = nullptr;
+ QPointer<QQuickView> m_ModelNode3DImageView;
+ QQuickItem *m_ModelNode3DImageViewRootItem = nullptr;
+ QQuickItem *m_ModelNode3DImageViewContentItem = nullptr;
+ RequestModelNodePreviewImageCommand m_modelNodelPreviewImageCommand;
QSet<QObject *> m_view3Ds;
QMultiHash<QObject *, QObject *> m_3DSceneMap; // key: scene root, value: node
QObject *m_active3DView = nullptr;
@@ -126,12 +137,13 @@ private:
QList<TokenCommand> m_tokenList;
QTimer m_propertyChangeTimer;
QTimer m_selectionChangeTimer;
- QTimer m_renderTimer;
+ QTimer m_render3DEditViewTimer;
+ QTimer m_renderModelNode3DImageViewTimer;
QVariant m_changedNode;
PropertyName m_changedProperty;
ChangeSelectionCommand m_lastSelectionChangeCommand;
QObject *m_3dHelper = nullptr;
- int m_needRender = 0;
+ int m_need3DEditViewRender = 0;
};
} // namespace QmlDesigner
diff --git a/share/qtcreator/qml/qmlpuppet/qmlpuppet.qrc b/share/qtcreator/qml/qmlpuppet/qmlpuppet.qrc
index f1af244e38..02878b81b6 100644
--- a/share/qtcreator/qml/qmlpuppet/qmlpuppet.qrc
+++ b/share/qtcreator/qml/qmlpuppet/qmlpuppet.qrc
@@ -40,6 +40,9 @@
<file>mockfiles/AxisHelper.qml</file>
<file>mockfiles/AxisHelperArm.qml</file>
<file>mockfiles/Line3D.qml</file>
+ <file>mockfiles/ModelNode3DImageView.qml</file>
+ <file>mockfiles/MaterialNodeView.qml</file>
+ <file>mockfiles/EffectNodeView.qml</file>
<file>mockfiles/meshes/arrow.mesh</file>
<file>mockfiles/meshes/scalerod.mesh</file>
<file>mockfiles/meshes/ring.mesh</file>