diff options
author | Thomas Hartmann <thomas.hartmann@qt.io> | 2019-09-27 18:52:06 +0200 |
---|---|---|
committer | Thomas Hartmann <thomas.hartmann@qt.io> | 2019-10-09 10:07:11 +0000 |
commit | 1900276c1760cf26b80c95fd4364dc3433d9e492 (patch) | |
tree | c95ee39868d675cb0aa5980dfd243638290c8bbb /share/qtcreator/qml/qmlpuppet/qml2puppet/instances/qt5informationnodeinstanceserver.cpp | |
parent | 3451f4c0480b1e13a28063f1a2e35426768f428e (diff) | |
download | qt-creator-1900276c1760cf26b80c95fd4364dc3433d9e492.tar.gz |
QmlDesigner: Enable 3D Edit View in Qt Quick Designer
If we find a QQuick3DViewport or the root node is a QQuick3DNode,
we create an 3D Edit View QQuickView for 3D editing in the 'editmode'.
This requires to not use the DesignerWindowManager for the 'editmode'.
The current implementation for the 3D Edit View is done in EditView3D.qml,
but can be replaced by a custom EditView class later. At this point in time
there is no hard dependency on QtQuick3D. Once we start to implement
more advanceded editing features, EditView3D.qml has to be replaced by a
custom C++ class with a hard dependency on QtQuick3D.
Currently the scene can be rotated around the 'y' axis, it is possible
to move the camera on the 'z' axis and the custom light can be turned
on and off. This is simply a proof of concept that the 3D Edit View
already allows some user interaction.
Change-Id: I96400e72b0853dde7939c693d1d7300f9c2ab142
Reviewed-by: Mahmoud Badri <mahmoud.badri@qt.io>
Reviewed-by: Miikka Heikkinen <miikka.heikkinen@qt.io>
Reviewed-by: Alessandro Portale <alessandro.portale@qt.io>
Diffstat (limited to 'share/qtcreator/qml/qmlpuppet/qml2puppet/instances/qt5informationnodeinstanceserver.cpp')
-rw-r--r-- | share/qtcreator/qml/qmlpuppet/qml2puppet/instances/qt5informationnodeinstanceserver.cpp | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/share/qtcreator/qml/qmlpuppet/qml2puppet/instances/qt5informationnodeinstanceserver.cpp b/share/qtcreator/qml/qmlpuppet/qml2puppet/instances/qt5informationnodeinstanceserver.cpp index 055e9f9eba..f672a20831 100644 --- a/share/qtcreator/qml/qmlpuppet/qml2puppet/instances/qt5informationnodeinstanceserver.cpp +++ b/share/qtcreator/qml/qmlpuppet/qml2puppet/instances/qt5informationnodeinstanceserver.cpp @@ -60,8 +60,23 @@ #include <designersupportdelegate.h> +#include <QQmlProperty> +#include <QOpenGLContext> +#include <QQuickView> + namespace QmlDesigner { +static QVariant objectToVariant(QObject *object) +{ + return QVariant::fromValue(object); +} + +static QObject *createEditView3D(QQmlEngine *engine) +{ + QQmlComponent component(engine, QUrl("qrc:/qtquickplugin/mockfiles/EditView3D.qml")); + return component.create(); +} + Qt5InformationNodeInstanceServer::Qt5InformationNodeInstanceServer(NodeInstanceClientInterface *nodeInstanceClient) : Qt5NodeInstanceServer(nodeInstanceClient) { @@ -122,6 +137,40 @@ bool Qt5InformationNodeInstanceServer::isDirtyRecursiveForParentInstances(QQuick return false; } +void Qt5InformationNodeInstanceServer::setup3DEditView(const QList<ServerNodeInstance> &instanceList) +{ + ServerNodeInstance root = rootNodeInstance(); + + QObject *node = nullptr; + bool showCustomLight = false; + + if (root.isSubclassOf("QQuick3DNode")) { + node = root.internalObject(); + showCustomLight = true; // Pure node scene we should add a custom light + } else { // Look for QQuick3DView + for (const ServerNodeInstance &instance : instanceList) { + if (instance.isSubclassOf("QQuick3DViewport")) { + for (const ServerNodeInstance &child : instanceList) { /* Look for scene node */ + if (child.isSubclassOf("QQuick3DNode") && child.parent() == instance) + node = child.internalObject(); + } + } + } + } + + if (node) { // If we found a scene we create the edit view + QObject *view = createEditView3D(engine()); + + QQmlProperty sceneProperty(view, "scene", context()); + node->setParent(view); + sceneProperty.write(objectToVariant(node)); + QQmlProperty parentProperty(node, "parent", context()); + parentProperty.write(objectToVariant(view)); + QQmlProperty completeSceneProperty(view, "showLight", context()); + completeSceneProperty.write(showCustomLight); + } +} + void Qt5InformationNodeInstanceServer::collectItemChangesAndSendChangeCommands() { static bool inFunction = false; @@ -232,6 +281,7 @@ void Qt5InformationNodeInstanceServer::createScene(const CreateSceneCommand &com sendChildrenChangedCommand(instanceList); nodeInstanceClient()->componentCompleted(createComponentCompletedCommand(instanceList)); + setup3DEditView(instanceList); } void Qt5InformationNodeInstanceServer::sendChildrenChangedCommand(const QList<ServerNodeInstance> &childList) |