aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSamuel Ghinet <samuel.ghinet@qt.io>2022-06-20 16:06:28 +0300
committerSamuel Ghinet <samuel.ghinet@qt.io>2022-08-03 09:35:11 +0000
commit86f93b89499c63af5b011c8d832f01e195764465 (patch)
tree3b7fe317099303e77d1f6d3300d037a965105359
parentc1d75d8df715bf430490a59e52fea56089054a12 (diff)
Sync color between environment map and 3D Editor background
Task-number: QDS-7097 Change-Id: I5f2c83bc43bd589d0d1f32e01e7512ab20a03bcf Reviewed-by: Miikka Heikkinen <miikka.heikkinen@qt.io> Reviewed-by: Mahmoud Badri <mahmoud.badri@qt.io>
-rw-r--r--share/qtcreator/qml/qmlpuppet/commands/view3dactioncommand.h1
-rw-r--r--share/qtcreator/qml/qmlpuppet/mockfiles/qt5/EditView3D.qml31
-rw-r--r--share/qtcreator/qml/qmlpuppet/mockfiles/qt6/EditView3D.qml13
-rw-r--r--share/qtcreator/qml/qmlpuppet/qml2puppet/editor3d/generalhelper.cpp10
-rw-r--r--share/qtcreator/qml/qmlpuppet/qml2puppet/editor3d/generalhelper.h4
-rw-r--r--share/qtcreator/qml/qmlpuppet/qml2puppet/instances/qt5informationnodeinstanceserver.cpp60
-rw-r--r--share/qtcreator/qml/qmlpuppet/qml2puppet/instances/qt5informationnodeinstanceserver.h1
-rw-r--r--src/plugins/qmldesigner/components/edit3d/edit3dview.cpp16
-rw-r--r--src/plugins/qmldesigner/components/edit3d/edit3dview.h1
-rw-r--r--src/plugins/qmldesigner/qmldesignerconstants.h1
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 13d3973943..4373a1c9dd 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 09a4ebdc3f..1376610984 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 a3f14e9d11..721e74ac30 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 590785a30e..f8ab464df2 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 8014a71187..e3ae249755 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<QQuick3DNode *> &nodes);
@@ -136,6 +139,7 @@ private:
QTimer m_toolStateUpdateTimer;
QHash<QString, QVariantMap> m_toolStates;
QHash<QString, QVariantMap> m_toolStatesPending;
+ QHash<QString, QColor> m_sceneEnvironmentColor;
QSet<QQuick3DNode *> 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 4448e2cee1..c95a81641e 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<QmlDesigner::Internal::GeneralHelper *>(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<QmlDesigner::Internal::GeneralHelper *>(m_3dHelper);
+ if (!helper || !hasInstanceForId(container.instanceId()) || !m_active3DView)
+ return;
+
+ ServerNodeInstance sceneEnvInstance = instanceForId(container.instanceId());
+ if (!sceneEnvInstance.isSubclassOf("QQuick3DSceneEnvironment"))
+ return;
+
+ auto activeView = qobject_cast<QQuick3DViewport *>(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<QColor>();
+ 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 c85a2730c4..f3448de4ad 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 bcce905b4f..f848b58b3f 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 4d96a7549f..8b242058ef 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<Edit3DWidget> m_edit3DWidget;
QVector<Edit3DAction *> m_leftActions;
diff --git a/src/plugins/qmldesigner/qmldesignerconstants.h b/src/plugins/qmldesigner/qmldesignerconstants.h
index cf657bca53..3cc0c3b8ae 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";