From 86f93b89499c63af5b011c8d832f01e195764465 Mon Sep 17 00:00:00 2001 From: Samuel Ghinet Date: Mon, 20 Jun 2022 16:06:28 +0300 Subject: Sync color between environment map and 3D Editor background Task-number: QDS-7097 Change-Id: I5f2c83bc43bd589d0d1f32e01e7512ab20a03bcf Reviewed-by: Miikka Heikkinen Reviewed-by: Mahmoud Badri --- .../qml/qmlpuppet/commands/view3dactioncommand.h | 1 + .../qml/qmlpuppet/mockfiles/qt5/EditView3D.qml | 31 +++++++---- .../qml/qmlpuppet/mockfiles/qt6/EditView3D.qml | 13 +++++ .../qml2puppet/editor3d/generalhelper.cpp | 10 ++++ .../qmlpuppet/qml2puppet/editor3d/generalhelper.h | 4 ++ .../instances/qt5informationnodeinstanceserver.cpp | 60 +++++++++++++++++++++- .../instances/qt5informationnodeinstanceserver.h | 1 + .../qmldesigner/components/edit3d/edit3dview.cpp | 16 ++++++ .../qmldesigner/components/edit3d/edit3dview.h | 1 + src/plugins/qmldesigner/qmldesignerconstants.h | 1 + 10 files changed, 128 insertions(+), 10 deletions(-) diff --git a/share/qtcreator/qml/qmlpuppet/commands/view3dactioncommand.h b/share/qtcreator/qml/qmlpuppet/commands/view3dactioncommand.h index 13d39739437..4373a1c9ddd 100644 --- a/share/qtcreator/qml/qmlpuppet/commands/view3dactioncommand.h +++ b/share/qtcreator/qml/qmlpuppet/commands/view3dactioncommand.h @@ -59,6 +59,7 @@ public: SelectBackgroundColor, SelectGridColor, ResetBackgroundColor, + SyncBackgroundColor, GetModelAtPos }; diff --git a/share/qtcreator/qml/qmlpuppet/mockfiles/qt5/EditView3D.qml b/share/qtcreator/qml/qmlpuppet/mockfiles/qt5/EditView3D.qml index 09a4ebdc3f3..1376610984d 100644 --- a/share/qtcreator/qml/qmlpuppet/mockfiles/qt5/EditView3D.qml +++ b/share/qtcreator/qml/qmlpuppet/mockfiles/qt5/EditView3D.qml @@ -48,6 +48,7 @@ Item { property color backgroundGradientColorStart: "#222222" property color backgroundGradientColorEnd: "#999999" property color gridColor: "#aaaaaa" + property bool syncBackgroundColor: false enum SelectionMode { Item, Group } enum TransformMode { Move, Rotate, Scale } @@ -72,15 +73,16 @@ Item { signal changeObjectProperty(var objects, var propNames) signal notifyActiveSceneChange() - onUsePerspectiveChanged: _generalHelper.storeToolState(sceneId, "usePerspective", usePerspective) - onShowEditLightChanged: _generalHelper.storeToolState(sceneId, "showEditLight", showEditLight) - onGlobalOrientationChanged: _generalHelper.storeToolState(sceneId, "globalOrientation", globalOrientation) - onShowGridChanged: _generalHelper.storeToolState(sceneId, "showGrid", showGrid); - onShowSelectionBoxChanged: _generalHelper.storeToolState(sceneId, "showSelectionBox", showSelectionBox); - onShowIconGizmoChanged: _generalHelper.storeToolState(sceneId, "showIconGizmo", showIconGizmo); - onShowCameraFrustumChanged: _generalHelper.storeToolState(sceneId, "showCameraFrustum", showCameraFrustum); - onSelectionModeChanged: _generalHelper.storeToolState(sceneId, "selectionMode", selectionMode); - onTransformModeChanged: _generalHelper.storeToolState(sceneId, "transformMode", transformMode); + onUsePerspectiveChanged: _generalHelper.storeToolState(sceneId, "usePerspective", usePerspective) + onShowEditLightChanged: _generalHelper.storeToolState(sceneId, "showEditLight", showEditLight) + onGlobalOrientationChanged: _generalHelper.storeToolState(sceneId, "globalOrientation", globalOrientation) + onShowGridChanged: _generalHelper.storeToolState(sceneId, "showGrid", showGrid); + onSyncBackgroundColorChanged: _generalHelper.storeToolState(sceneId, "syncBackgroundColor", syncBackgroundColor); + onShowSelectionBoxChanged: _generalHelper.storeToolState(sceneId, "showSelectionBox", showSelectionBox); + onShowIconGizmoChanged: _generalHelper.storeToolState(sceneId, "showIconGizmo", showIconGizmo); + onShowCameraFrustumChanged: _generalHelper.storeToolState(sceneId, "showCameraFrustum", showCameraFrustum); + onSelectionModeChanged: _generalHelper.storeToolState(sceneId, "selectionMode", selectionMode); + onTransformModeChanged: _generalHelper.storeToolState(sceneId, "transformMode", transformMode); onActiveSceneChanged: updateActiveScene() @@ -249,6 +251,16 @@ Item { else if (resetToDefault) showGrid = true; + if ("syncBackgroundColor" in toolStates) { + syncBackgroundColor = toolStates.syncBackgroundColor; + if (syncBackgroundColor) { + var color = _generalHelper.sceneEnvironmentColor(sceneId); + updateViewStates({"selectBackgroundColor": color}) + } + } else if (resetToDefault) { + syncBackgroundColor = false; + } + if ("showSelectionBox" in toolStates) showSelectionBox = toolStates.showSelectionBox; else if (resetToDefault) @@ -294,6 +306,7 @@ Item { { _generalHelper.storeToolState(sceneId, "showEditLight", showEditLight) _generalHelper.storeToolState(sceneId, "showGrid", showGrid) + _generalHelper.storeToolState(sceneId, "syncBackgroundColor", syncBackgroundColor) _generalHelper.storeToolState(sceneId, "showSelectionBox", showSelectionBox) _generalHelper.storeToolState(sceneId, "showIconGizmo", showIconGizmo) _generalHelper.storeToolState(sceneId, "showCameraFrustum", showCameraFrustum) diff --git a/share/qtcreator/qml/qmlpuppet/mockfiles/qt6/EditView3D.qml b/share/qtcreator/qml/qmlpuppet/mockfiles/qt6/EditView3D.qml index a3f14e9d113..721e74ac303 100644 --- a/share/qtcreator/qml/qmlpuppet/mockfiles/qt6/EditView3D.qml +++ b/share/qtcreator/qml/qmlpuppet/mockfiles/qt6/EditView3D.qml @@ -49,6 +49,7 @@ Item { property color backgroundGradientColorStart: "#222222" property color backgroundGradientColorEnd: "#999999" property color gridColor: "#aaaaaa" + property bool syncBackgroundColor: false enum SelectionMode { Item, Group } enum TransformMode { Move, Rotate, Scale } @@ -79,6 +80,7 @@ Item { onShowEditLightChanged: _generalHelper.storeToolState(sceneId, "showEditLight", showEditLight) onGlobalOrientationChanged: _generalHelper.storeToolState(sceneId, "globalOrientation", globalOrientation) onShowGridChanged: _generalHelper.storeToolState(sceneId, "showGrid", showGrid); + onSyncBackgroundColorChanged: _generalHelper.storeToolState(sceneId, "syncBackgroundColor", syncBackgroundColor); onShowSelectionBoxChanged: _generalHelper.storeToolState(sceneId, "showSelectionBox", showSelectionBox); onShowIconGizmoChanged: _generalHelper.storeToolState(sceneId, "showIconGizmo", showIconGizmo); onShowCameraFrustumChanged: _generalHelper.storeToolState(sceneId, "showCameraFrustum", showCameraFrustum); @@ -243,6 +245,16 @@ Item { else if (resetToDefault) showGrid = true; + if ("syncBackgroundColor" in toolStates) { + syncBackgroundColor = toolStates.syncBackgroundColor; + if (syncBackgroundColor) { + var color = _generalHelper.sceneEnvironmentColor(sceneId); + updateViewStates({"selectBackgroundColor": color}) + } + } else if (resetToDefault) { + syncBackgroundColor = false; + } + if ("showSelectionBox" in toolStates) showSelectionBox = toolStates.showSelectionBox; else if (resetToDefault) @@ -293,6 +305,7 @@ Item { { _generalHelper.storeToolState(sceneId, "showEditLight", showEditLight) _generalHelper.storeToolState(sceneId, "showGrid", showGrid) + _generalHelper.storeToolState(sceneId, "syncBackgroundColor", syncBackgroundColor) _generalHelper.storeToolState(sceneId, "showSelectionBox", showSelectionBox) _generalHelper.storeToolState(sceneId, "showIconGizmo", showIconGizmo) _generalHelper.storeToolState(sceneId, "showCameraFrustum", showCameraFrustum) diff --git a/share/qtcreator/qml/qmlpuppet/qml2puppet/editor3d/generalhelper.cpp b/share/qtcreator/qml/qmlpuppet/qml2puppet/editor3d/generalhelper.cpp index 590785a30e3..f8ab464df23 100644 --- a/share/qtcreator/qml/qmlpuppet/qml2puppet/editor3d/generalhelper.cpp +++ b/share/qtcreator/qml/qmlpuppet/qml2puppet/editor3d/generalhelper.cpp @@ -547,6 +547,16 @@ void GeneralHelper::storeToolState(const QString &sceneId, const QString &tool, } } +void GeneralHelper::setSceneEnvironmentColor(const QString &sceneId, const QColor &color) +{ + m_sceneEnvironmentColor[sceneId] = color; +} + +QColor GeneralHelper::sceneEnvironmentColor(const QString &sceneId) const +{ + return m_sceneEnvironmentColor[sceneId]; +} + void GeneralHelper::initToolStates(const QString &sceneId, const QVariantMap &toolStates) { m_toolStates[sceneId] = toolStates; diff --git a/share/qtcreator/qml/qmlpuppet/qml2puppet/editor3d/generalhelper.h b/share/qtcreator/qml/qmlpuppet/qml2puppet/editor3d/generalhelper.h index 8014a711875..e3ae249755d 100644 --- a/share/qtcreator/qml/qmlpuppet/qml2puppet/editor3d/generalhelper.h +++ b/share/qtcreator/qml/qmlpuppet/qml2puppet/editor3d/generalhelper.h @@ -113,6 +113,9 @@ public: Q_INVOKABLE void scaleMultiSelection(bool commit); Q_INVOKABLE void rotateMultiSelection(bool commit); + void setSceneEnvironmentColor(const QString &sceneId, const QColor &color); + Q_INVOKABLE QColor sceneEnvironmentColor(const QString &sceneId) const; + bool isMacOS() const; void addRotationBlocks(const QSet &nodes); @@ -136,6 +139,7 @@ private: QTimer m_toolStateUpdateTimer; QHash m_toolStates; QHash m_toolStatesPending; + QHash m_sceneEnvironmentColor; QSet m_rotationBlockedNodes; struct MultiSelData { diff --git a/share/qtcreator/qml/qmlpuppet/qml2puppet/instances/qt5informationnodeinstanceserver.cpp b/share/qtcreator/qml/qmlpuppet/qml2puppet/instances/qt5informationnodeinstanceserver.cpp index 4448e2cee1f..c95a81641e0 100644 --- a/share/qtcreator/qml/qmlpuppet/qml2puppet/instances/qt5informationnodeinstanceserver.cpp +++ b/share/qtcreator/qml/qmlpuppet/qml2puppet/instances/qt5informationnodeinstanceserver.cpp @@ -867,8 +867,21 @@ void Qt5InformationNodeInstanceServer::updateActiveSceneToEditView3D(bool timerC updateView3DRect(m_active3DView); auto helper = qobject_cast(m_3dHelper); - if (helper) + if (helper) { helper->storeToolState(helper->globalStateId(), helper->lastSceneIdKey(), QVariant(sceneId), 0); + + QVariantMap toolStates = helper->getToolStates(sceneId); + if (toolStates.contains("syncBackgroundColor")) { + bool sync = toolStates["syncBackgroundColor"].toBool(); + if (sync) { + QColor color = helper->sceneEnvironmentColor(sceneId); + View3DActionCommand cmd(View3DActionCommand::SelectBackgroundColor, + QVariant::fromValue(color)); + view3DAction(cmd); + } + } + } + #else Q_UNUSED(timerCall) #endif @@ -2179,6 +2192,44 @@ void Qt5InformationNodeInstanceServer::changeSelection(const ChangeSelectionComm render3DEditView(2); } +void Qt5InformationNodeInstanceServer::setSceneEnvironmentColor(const PropertyValueContainer &container) +{ +#ifdef QUICK3D_MODULE + auto helper = qobject_cast(m_3dHelper); + if (!helper || !hasInstanceForId(container.instanceId()) || !m_active3DView) + return; + + ServerNodeInstance sceneEnvInstance = instanceForId(container.instanceId()); + if (!sceneEnvInstance.isSubclassOf("QQuick3DSceneEnvironment")) + return; + + auto activeView = qobject_cast(m_active3DView); + if (!activeView) + return; + + QQuick3DSceneEnvironment *activeEnv = activeView->environment(); + if (activeEnv != sceneEnvInstance.internalObject()) + return; + + ServerNodeInstance activeSceneInstance = active3DSceneInstance(); + const QString sceneId = activeSceneInstance.id(); + + QColor color = container.value().value(); + helper->setSceneEnvironmentColor(sceneId, color); + QVariantMap toolStates = helper->getToolStates(sceneId); + + if (toolStates.contains("syncBackgroundColor")) { + bool sync = toolStates["syncBackgroundColor"].toBool(); + if (sync) { + View3DActionCommand cmd(View3DActionCommand::SelectBackgroundColor, QVariant::fromValue(color)); + view3DAction(cmd); + } + } +#else + Q_UNUSED(container) +#endif +} + void Qt5InformationNodeInstanceServer::changePropertyValues(const ChangeValuesCommand &command) { bool hasDynamicProperties = false; @@ -2186,6 +2237,10 @@ void Qt5InformationNodeInstanceServer::changePropertyValues(const ChangeValuesCo for (const PropertyValueContainer &container : values) { if (!container.isReflected()) { hasDynamicProperties |= container.isDynamic(); + + if (container.name() == "clearColor") + setSceneEnvironmentColor(container); + setInstancePropertyVariant(container); } } @@ -2284,6 +2339,9 @@ void Qt5InformationNodeInstanceServer::view3DAction(const View3DActionCommand &c case View3DActionCommand::ShowCameraFrustum: updatedToolState.insert("showCameraFrustum", command.isEnabled()); break; + case View3DActionCommand::SyncBackgroundColor: + updatedToolState.insert("syncBackgroundColor", command.isEnabled()); + break; case View3DActionCommand::SelectBackgroundColor: updatedViewState.insert("selectBackgroundColor", command.value()); break; diff --git a/share/qtcreator/qml/qmlpuppet/qml2puppet/instances/qt5informationnodeinstanceserver.h b/share/qtcreator/qml/qmlpuppet/qml2puppet/instances/qt5informationnodeinstanceserver.h index c85a2730c46..f3448de4add 100644 --- a/share/qtcreator/qml/qmlpuppet/qml2puppet/instances/qt5informationnodeinstanceserver.h +++ b/share/qtcreator/qml/qmlpuppet/qml2puppet/instances/qt5informationnodeinstanceserver.h @@ -154,6 +154,7 @@ private: void resetParticleSystem(); void handleParticleSystemDeselected(); #endif + void setSceneEnvironmentColor(const PropertyValueContainer &container); RenderViewData m_editView3DData; RenderViewData m_modelNode3DImageViewData; diff --git a/src/plugins/qmldesigner/components/edit3d/edit3dview.cpp b/src/plugins/qmldesigner/components/edit3d/edit3dview.cpp index bcce905b4fa..f848b58b3f0 100644 --- a/src/plugins/qmldesigner/components/edit3d/edit3dview.cpp +++ b/src/plugins/qmldesigner/components/edit3d/edit3dview.cpp @@ -338,6 +338,21 @@ Edit3DAction *Edit3DView::createResetColorAction() tooltip); } +Edit3DAction *Edit3DView::createSyncBackgroundColorAction() +{ + QString description = QCoreApplication::translate("SyncEdit3DColorAction", + "Use Scene Environment Color"); + QString tooltip = QCoreApplication::translate("SyncEdit3DColorAction", + "Sets the 3D Editor to use the Scene Environment " + "color as background color."); + + return new Edit3DAction( + QmlDesigner::Constants::EDIT3D_EDIT_SYNC_BACKGROUND_COLOR, View3DActionCommand::SyncBackgroundColor, + description, + {}, true, false, {}, {}, {}, + tooltip); +} + void Edit3DView::createEdit3DActions() { m_selectionModeAction @@ -569,6 +584,7 @@ void Edit3DView::createEdit3DActions() m_backgroundColorActions << createSelectBackgrounColorAction(); m_backgroundColorActions << createGridColorSelectionAction(); + m_backgroundColorActions << createSyncBackgroundColorAction(); m_backgroundColorActions << createResetColorAction(); } diff --git a/src/plugins/qmldesigner/components/edit3d/edit3dview.h b/src/plugins/qmldesigner/components/edit3d/edit3dview.h index 4d96a7549f3..8b242058efb 100644 --- a/src/plugins/qmldesigner/components/edit3d/edit3dview.h +++ b/src/plugins/qmldesigner/components/edit3d/edit3dview.h @@ -88,6 +88,7 @@ private: Edit3DAction *createSelectBackgrounColorAction(); Edit3DAction *createGridColorSelectionAction(); Edit3DAction *createResetColorAction(); + Edit3DAction *createSyncBackgroundColorAction(); QPointer m_edit3DWidget; QVector m_leftActions; diff --git a/src/plugins/qmldesigner/qmldesignerconstants.h b/src/plugins/qmldesigner/qmldesignerconstants.h index cf657bca537..3cc0c3b8ae6 100644 --- a/src/plugins/qmldesigner/qmldesignerconstants.h +++ b/src/plugins/qmldesigner/qmldesignerconstants.h @@ -68,6 +68,7 @@ const char EDIT3D_EDIT_SHOW_GRID[] = "QmlDesigner.Editor3D.ToggleGrid"; const char EDIT3D_EDIT_SELECT_BACKGROUND_COLOR[] = "QmlDesigner.Editor3D.SelectBackgroundColor"; const char EDIT3D_EDIT_SELECT_GRID_COLOR[] = "QmlDesigner.Editor3D.SelectGridColor"; const char EDIT3D_EDIT_RESET_BACKGROUND_COLOR[] = "QmlDesigner.Editor3D.ResetBackgroundColor"; +const char EDIT3D_EDIT_SYNC_BACKGROUND_COLOR[] = "QmlDesigner.Editor3D.SyncBackgroundColor"; const char EDIT3D_EDIT_SHOW_SELECTION_BOX[] = "QmlDesigner.Editor3D.ToggleSelectionBox"; const char EDIT3D_EDIT_SHOW_ICON_GIZMO[] = "QmlDesigner.Editor3D.ToggleIconGizmo"; const char EDIT3D_EDIT_SHOW_CAMERA_FRUSTUM[] = "QmlDesigner.Editor3D.ToggleCameraFrustum"; -- cgit v1.2.3