QmlDesigner: Refactor 3D view background and grid color implementation

The new implementation doesn't require these colors to be stored in
external dependencies anymore, as auxiliary properties are used for
them instead.

Fixes: QDS-10496
Change-Id: Ie71408617259d1af73a45f327d4bdfa4f2fa3a2b
Reviewed-by: Mahmoud Badri <mahmoud.badri@qt.io>
This commit is contained in:
Miikka Heikkinen
2023-09-04 17:08:37 +03:00
parent 0d04bf9560
commit 6251730f8f
18 changed files with 153 additions and 142 deletions

View File

@@ -38,9 +38,7 @@ public:
const QString &language, const QString &language,
QSize captureImageMinimumSize, QSize captureImageMinimumSize,
QSize captureImageMaximumSize, QSize captureImageMaximumSize,
qint32 stateInstanceId, qint32 stateInstanceId)
const QList<QColor> &edit3dBackgroundColor,
const QColor &edit3dGridColor)
: instances(instanceContainer) : instances(instanceContainer)
, reparentInstances(reparentContainer) , reparentInstances(reparentContainer)
, ids(idVector) , ids(idVector)
@@ -56,8 +54,6 @@ public:
, captureImageMinimumSize(captureImageMinimumSize) , captureImageMinimumSize(captureImageMinimumSize)
, captureImageMaximumSize(captureImageMaximumSize) , captureImageMaximumSize(captureImageMaximumSize)
, stateInstanceId{stateInstanceId} , stateInstanceId{stateInstanceId}
, edit3dBackgroundColor{edit3dBackgroundColor}
, edit3dGridColor{edit3dGridColor}
{} {}
friend QDataStream &operator<<(QDataStream &out, const CreateSceneCommand &command) friend QDataStream &operator<<(QDataStream &out, const CreateSceneCommand &command)
@@ -77,8 +73,6 @@ public:
out << command.stateInstanceId; out << command.stateInstanceId;
out << command.captureImageMinimumSize; out << command.captureImageMinimumSize;
out << command.captureImageMaximumSize; out << command.captureImageMaximumSize;
out << command.edit3dBackgroundColor;
out << command.edit3dGridColor;
return out; return out;
} }
@@ -100,8 +94,6 @@ public:
in >> command.stateInstanceId; in >> command.stateInstanceId;
in >> command.captureImageMinimumSize; in >> command.captureImageMinimumSize;
in >> command.captureImageMaximumSize; in >> command.captureImageMaximumSize;
in >> command.edit3dBackgroundColor;
in >> command.edit3dGridColor;
return in; return in;
} }
@@ -122,8 +114,6 @@ public:
QSize captureImageMinimumSize; QSize captureImageMinimumSize;
QSize captureImageMaximumSize; QSize captureImageMaximumSize;
qint32 stateInstanceId = 0; qint32 stateInstanceId = 0;
QList<QColor> edit3dBackgroundColor;
QColor edit3dGridColor;
}; };
QDebug operator<<(QDebug debug, const CreateSceneCommand &command); QDebug operator<<(QDebug debug, const CreateSceneCommand &command);

View File

@@ -44,9 +44,6 @@ enum class View3DActionType {
ParticlesPlay, ParticlesPlay,
ParticlesRestart, ParticlesRestart,
ParticlesSeek, ParticlesSeek,
SelectBackgroundColor,
SelectGridColor,
ResetBackgroundColor,
SyncBackgroundColor, SyncBackgroundColor,
GetNodeAtPos, GetNodeAtPos,
SetBakeLightsView3D SetBakeLightsView3D

View File

@@ -13,13 +13,13 @@ using namespace QmlDesigner;
void BackgroundColorSelection::showBackgroundColorSelectionWidget(QWidget *parent, void BackgroundColorSelection::showBackgroundColorSelectionWidget(QWidget *parent,
const QByteArray &key, const QByteArray &key,
AbstractView *view, AbstractView *view,
View3DActionType actionType, const AuxiliaryDataKeyView &auxProp,
const std::function<void()> &colorSelected) const std::function<void()> &colorSelected)
{ {
if (m_dialog) if (m_dialog)
return; return;
m_dialog = BackgroundColorSelection::createColorDialog(parent, key, view, actionType, colorSelected); m_dialog = BackgroundColorSelection::createColorDialog(parent, key, view, auxProp, colorSelected);
QTC_ASSERT(m_dialog, return); QTC_ASSERT(m_dialog, return);
QObject::connect(m_dialog, &QWidget::destroyed, m_dialog, [&]() { QObject::connect(m_dialog, &QWidget::destroyed, m_dialog, [&]() {
@@ -30,7 +30,7 @@ void BackgroundColorSelection::showBackgroundColorSelectionWidget(QWidget *paren
QColorDialog *BackgroundColorSelection::createColorDialog(QWidget *parent, QColorDialog *BackgroundColorSelection::createColorDialog(QWidget *parent,
const QByteArray &key, const QByteArray &key,
AbstractView *view, AbstractView *view,
View3DActionType actionType, const AuxiliaryDataKeyView &auxProp,
const std::function<void()> &colorSelected) const std::function<void()> &colorSelected)
{ {
auto dialog = new QColorDialog(parent); auto dialog = new QColorDialog(parent);
@@ -43,8 +43,8 @@ QColorDialog *BackgroundColorSelection::createColorDialog(QWidget *parent,
dialog->show(); dialog->show();
QObject::connect(dialog, &QColorDialog::currentColorChanged, dialog, QObject::connect(dialog, &QColorDialog::currentColorChanged, dialog,
[actionType, view](const QColor &color) { [auxProp, view](const QColor &color) {
Edit3DViewConfig::setColors(view, actionType, {color}); Edit3DViewConfig::setColors(view, auxProp, {color});
}); });
QObject::connect(dialog, &QColorDialog::colorSelected, dialog, QObject::connect(dialog, &QColorDialog::colorSelected, dialog,
@@ -57,8 +57,8 @@ QColorDialog *BackgroundColorSelection::createColorDialog(QWidget *parent,
if (Edit3DViewConfig::colorsValid(oldColorConfig)) { if (Edit3DViewConfig::colorsValid(oldColorConfig)) {
QObject::connect(dialog, &QColorDialog::rejected, dialog, QObject::connect(dialog, &QColorDialog::rejected, dialog,
[actionType, oldColorConfig, view]() { [auxProp, oldColorConfig, view]() {
Edit3DViewConfig::setColors(view, actionType, oldColorConfig); Edit3DViewConfig::setColors(view, auxProp, oldColorConfig);
}); });
} }

View File

@@ -3,7 +3,7 @@
#pragma once #pragma once
#include <nodeinstanceglobal.h> #include <auxiliarydata.h>
#include <QByteArray> #include <QByteArray>
#include <QObject> #include <QObject>
@@ -13,6 +13,11 @@ QT_FORWARD_DECLARE_CLASS(QColorDialog)
namespace QmlDesigner { namespace QmlDesigner {
class AbstractView; class AbstractView;
inline constexpr AuxiliaryDataKeyView edit3dGridColorProperty{AuxiliaryDataType::NodeInstanceAuxiliary,
"edit3dGridColor"};
inline constexpr AuxiliaryDataKeyView edit3dBgColorProperty{AuxiliaryDataType::NodeInstanceAuxiliary,
"edit3dBgColor"};
class BackgroundColorSelection : public QObject class BackgroundColorSelection : public QObject
{ {
Q_OBJECT Q_OBJECT
@@ -25,14 +30,14 @@ public:
static void showBackgroundColorSelectionWidget(QWidget *parent, static void showBackgroundColorSelectionWidget(QWidget *parent,
const QByteArray &key, const QByteArray &key,
AbstractView *view, AbstractView *view,
View3DActionType actionType, const AuxiliaryDataKeyView &auxProp,
const std::function<void()> &colorSelected = {}); const std::function<void()> &colorSelected = {});
private: private:
static QColorDialog *createColorDialog(QWidget *parent, static QColorDialog *createColorDialog(QWidget *parent,
const QByteArray &key, const QByteArray &key,
AbstractView *view, AbstractView *view,
View3DActionType actionType, const AuxiliaryDataKeyView &auxProp,
const std::function<void ()> &colorSelected); const std::function<void ()> &colorSelected);
inline static QColorDialog *m_dialog = nullptr; inline static QColorDialog *m_dialog = nullptr;

View File

@@ -25,10 +25,8 @@ Edit3DActionTemplate::Edit3DActionTemplate(const QString &description,
void Edit3DActionTemplate::actionTriggered(bool b) void Edit3DActionTemplate::actionTriggered(bool b)
{ {
if (m_type != View3DActionType::Empty && m_type != View3DActionType::SelectBackgroundColor if (m_type != View3DActionType::Empty)
&& m_type != View3DActionType::SelectGridColor) {
m_view->emitView3DAction(m_type, b); m_view->emitView3DAction(m_type, b);
}
if (m_action) if (m_action)
m_action(m_selectionContext); m_action(m_selectionContext);

View File

@@ -119,6 +119,7 @@ void Edit3DView::updateActiveScene3D(const QVariantMap &sceneState)
const QString cameraFrustumKey = QStringLiteral("showCameraFrustum"); const QString cameraFrustumKey = QStringLiteral("showCameraFrustum");
const QString particleEmitterKey = QStringLiteral("showParticleEmitter"); const QString particleEmitterKey = QStringLiteral("showParticleEmitter");
const QString particlesPlayKey = QStringLiteral("particlePlay"); const QString particlesPlayKey = QStringLiteral("particlePlay");
const QString syncBgColorKey = QStringLiteral("syncBackgroundColor");
if (sceneState.contains(sceneKey)) { if (sceneState.contains(sceneKey)) {
qint32 newActiveScene = sceneState[sceneKey].value<qint32>(); qint32 newActiveScene = sceneState[sceneKey].value<qint32>();
@@ -189,6 +190,11 @@ void Edit3DView::updateActiveScene3D(const QVariantMap &sceneState)
else else
m_particlesPlayAction->action()->setChecked(true); m_particlesPlayAction->action()->setChecked(true);
if (sceneState.contains(syncBgColorKey))
m_syncBackgroundColorAction->action()->setChecked(sceneState[syncBgColorKey].toBool());
else
m_syncBackgroundColorAction->action()->setChecked(true);
// Selection context change updates visible and enabled states // Selection context change updates visible and enabled states
SelectionContext selectionContext(this); SelectionContext selectionContext(this);
selectionContext.setUpdateMode(SelectionContext::UpdateMode::Fast); selectionContext.setUpdateMode(SelectionContext::UpdateMode::Fast);
@@ -202,6 +208,13 @@ void Edit3DView::modelAttached(Model *model)
syncSnapAuxPropsToSettings(); syncSnapAuxPropsToSettings();
rootModelNode().setAuxiliaryData(edit3dGridColorProperty,
QVariant::fromValue(Edit3DViewConfig::loadColor(
DesignerSettingsKey::EDIT3DVIEW_GRID_COLOR)));
rootModelNode().setAuxiliaryData(edit3dBgColorProperty,
QVariant::fromValue(Edit3DViewConfig::loadColor(
DesignerSettingsKey::EDIT3DVIEW_BACKGROUND_COLOR)));
checkImports(); checkImports();
auto cachedImage = m_canvasCache.take(model); auto cachedImage = m_canvasCache.take(model);
if (cachedImage) { if (cachedImage) {
@@ -423,10 +436,10 @@ void Edit3DView::createSelectBackgroundColorAction(QAction *syncBackgroundColorA
edit3DWidget(), edit3DWidget(),
DesignerSettingsKey::EDIT3DVIEW_BACKGROUND_COLOR, DesignerSettingsKey::EDIT3DVIEW_BACKGROUND_COLOR,
this, this,
View3DActionType::SelectBackgroundColor, edit3dBgColorProperty,
[this, syncBackgroundColorAction]() { [this, syncBackgroundColorAction]() {
if (syncBackgroundColorAction->isChecked()) { if (syncBackgroundColorAction->isChecked()) {
Edit3DViewConfig::set(this, View3DActionType::SyncBackgroundColor, false); emitView3DAction(View3DActionType::SyncBackgroundColor, false);
syncBackgroundColorAction->setChecked(false); syncBackgroundColorAction->setChecked(false);
} }
}); });
@@ -434,7 +447,7 @@ void Edit3DView::createSelectBackgroundColorAction(QAction *syncBackgroundColorA
m_selectBackgroundColorAction = std::make_unique<Edit3DAction>( m_selectBackgroundColorAction = std::make_unique<Edit3DAction>(
Constants::EDIT3D_EDIT_SELECT_BACKGROUND_COLOR, Constants::EDIT3D_EDIT_SELECT_BACKGROUND_COLOR,
View3DActionType::SelectBackgroundColor, View3DActionType::Empty,
description, description,
QKeySequence(), QKeySequence(),
false, false,
@@ -456,12 +469,12 @@ void Edit3DView::createGridColorSelectionAction()
edit3DWidget(), edit3DWidget(),
DesignerSettingsKey::EDIT3DVIEW_GRID_COLOR, DesignerSettingsKey::EDIT3DVIEW_GRID_COLOR,
this, this,
View3DActionType::SelectGridColor); edit3dGridColorProperty);
}; };
m_selectGridColorAction = std::make_unique<Edit3DAction>( m_selectGridColorAction = std::make_unique<Edit3DAction>(
Constants::EDIT3D_EDIT_SELECT_GRID_COLOR, Constants::EDIT3D_EDIT_SELECT_GRID_COLOR,
View3DActionType::SelectGridColor, View3DActionType::Empty,
description, description,
QKeySequence(), QKeySequence(),
false, false,
@@ -481,22 +494,22 @@ void Edit3DView::createResetColorAction(QAction *syncBackgroundColorAction)
auto operation = [this, syncBackgroundColorAction](const SelectionContext &) { auto operation = [this, syncBackgroundColorAction](const SelectionContext &) {
QList<QColor> bgColors = {QRgb(0x222222), QRgb(0x999999)}; QList<QColor> bgColors = {QRgb(0x222222), QRgb(0x999999)};
Edit3DViewConfig::setColors(this, View3DActionType::SelectBackgroundColor, bgColors); Edit3DViewConfig::setColors(this, edit3dBgColorProperty, bgColors);
Edit3DViewConfig::saveColors(DesignerSettingsKey::EDIT3DVIEW_BACKGROUND_COLOR, bgColors); Edit3DViewConfig::saveColors(DesignerSettingsKey::EDIT3DVIEW_BACKGROUND_COLOR, bgColors);
QColor gridColor{0xaaaaaa}; QColor gridColor{0xaaaaaa};
Edit3DViewConfig::setColors(this, View3DActionType::SelectGridColor, {gridColor}); Edit3DViewConfig::setColors(this, edit3dGridColorProperty, {gridColor});
Edit3DViewConfig::saveColors(DesignerSettingsKey::EDIT3DVIEW_GRID_COLOR, {gridColor}); Edit3DViewConfig::saveColors(DesignerSettingsKey::EDIT3DVIEW_GRID_COLOR, {gridColor});
if (syncBackgroundColorAction->isChecked()) { if (syncBackgroundColorAction->isChecked()) {
Edit3DViewConfig::set(this, View3DActionType::SyncBackgroundColor, false); emitView3DAction(View3DActionType::SyncBackgroundColor, false);
syncBackgroundColorAction->setChecked(false); syncBackgroundColorAction->setChecked(false);
} }
}; };
m_resetColorAction = std::make_unique<Edit3DAction>( m_resetColorAction = std::make_unique<Edit3DAction>(
QmlDesigner::Constants::EDIT3D_EDIT_RESET_BACKGROUND_COLOR, QmlDesigner::Constants::EDIT3D_EDIT_RESET_BACKGROUND_COLOR,
View3DActionType::ResetBackgroundColor, View3DActionType::Empty,
description, description,
QKeySequence(), QKeySequence(),
false, false,

View File

@@ -3,7 +3,7 @@
#pragma once #pragma once
#include <nodeinstanceview.h> #include <auxiliarydata.h>
#include <qmldesignerplugin.h> #include <qmldesignerplugin.h>
#include <utils/algorithm.h> #include <utils/algorithm.h>
@@ -38,20 +38,20 @@ public:
QmlDesignerPlugin::settings().insert(key, value); QmlDesignerPlugin::settings().insert(key, value);
} }
static void setColors(AbstractView *view, View3DActionType type, const QList<QColor> &colorConfig) static void setColors(AbstractView *view, const AuxiliaryDataKeyView &auxProp, const QList<QColor> &colorConfig)
{ {
QVariant param; QVariant param;
if (type == View3DActionType::SelectGridColor) if (auxProp.name == "edit3dGridColor")
param = colorConfig.isEmpty() ? QColor() : colorConfig[0]; param = colorConfig.isEmpty() ? QColor() : colorConfig[0];
else else
param = QVariant::fromValue(colorConfig); param = QVariant::fromValue(colorConfig);
setVariant(view, type, param); setVariant(view, auxProp, param);
} }
template <typename T> template <typename T>
static void set(AbstractView *view, View3DActionType type, const T &value) static void set(AbstractView *view, const AuxiliaryDataKeyView &auxProp, const T &value)
{ {
setVariant(view, type, QVariant::fromValue(value)); setVariant(view, auxProp, QVariant::fromValue(value));
} }
static void saveColors(const QByteArray &key, const QList<QColor> &colorConfig) static void saveColors(const QByteArray &key, const QList<QColor> &colorConfig)
@@ -66,11 +66,10 @@ public:
static bool colorsValid(const QList<QColor> &colorConfig) { return !colorConfig.isEmpty(); } static bool colorsValid(const QList<QColor> &colorConfig) { return !colorConfig.isEmpty(); }
private: private:
static void setVariant(AbstractView *view, View3DActionType type, const QVariant &value) static void setVariant(AbstractView *view, const AuxiliaryDataKeyView &auxProp, const QVariant &value)
{ {
view->emitView3DAction(type, value); view->rootModelNode().setAuxiliaryData(auxProp, value);
} }
}; };
} // namespace QmlDesigner } // namespace QmlDesigner

View File

@@ -29,8 +29,6 @@ public:
virtual QString defaultPuppetToplevelBuildDirectory() const = 0; virtual QString defaultPuppetToplevelBuildDirectory() const = 0;
virtual QUrl projectUrl() const = 0; virtual QUrl projectUrl() const = 0;
virtual QString currentProjectDirPath() const = 0; virtual QString currentProjectDirPath() const = 0;
virtual QList<QColor> designerSettingsEdit3DViewBackgroundColor() const = 0;
virtual QColor designerSettingsEdit3DViewGridColor() const = 0;
virtual QUrl currentResourcePath() const = 0; virtual QUrl currentResourcePath() const = 0;
virtual void parseItemLibraryDescriptions() = 0; virtual void parseItemLibraryDescriptions() = 0;
virtual const DesignerSettings &designerSettings() const = 0; virtual const DesignerSettings &designerSettings() const = 0;

View File

@@ -1182,9 +1182,6 @@ CreateSceneCommand NodeInstanceView::createCreateSceneCommand()
if (stateNode.isValid() && stateNode.metaInfo().isQtQuickState()) if (stateNode.isValid() && stateNode.metaInfo().isQtQuickState())
stateInstanceId = stateNode.internalId(); stateInstanceId = stateNode.internalId();
QColor gridColor = m_externalDependencies.designerSettingsEdit3DViewGridColor();
QList<QColor> backgroundColor = m_externalDependencies.designerSettingsEdit3DViewBackgroundColor();
return CreateSceneCommand(instanceContainerList, return CreateSceneCommand(instanceContainerList,
reparentContainerList, reparentContainerList,
idContainerList, idContainerList,
@@ -1199,9 +1196,7 @@ CreateSceneCommand NodeInstanceView::createCreateSceneCommand()
lastUsedLanguage, lastUsedLanguage,
m_captureImageMinimumSize, m_captureImageMinimumSize,
m_captureImageMaximumSize, m_captureImageMaximumSize,
stateInstanceId, stateInstanceId);
backgroundColor,
gridColor);
} }
ClearSceneCommand NodeInstanceView::createClearSceneCommand() const ClearSceneCommand NodeInstanceView::createClearSceneCommand() const

View File

@@ -62,20 +62,6 @@ QString ExternalDependencies::currentProjectDirPath() const
return QmlDesignerPlugin::instance()->documentManager().currentProjectDirPath().toString(); return QmlDesignerPlugin::instance()->documentManager().currentProjectDirPath().toString();
} }
QList<QColor> ExternalDependencies::designerSettingsEdit3DViewBackgroundColor() const
{
return Edit3DViewConfig::loadColor(DesignerSettingsKey::EDIT3DVIEW_BACKGROUND_COLOR);
}
QColor ExternalDependencies::designerSettingsEdit3DViewGridColor() const
{
QList<QColor> gridColorList = Edit3DViewConfig::loadColor(DesignerSettingsKey::EDIT3DVIEW_GRID_COLOR);
if (!gridColorList.isEmpty())
return gridColorList.front();
return {};
}
QUrl ExternalDependencies::currentResourcePath() const QUrl ExternalDependencies::currentResourcePath() const
{ {
return QUrl::fromLocalFile( return QUrl::fromLocalFile(

View File

@@ -22,8 +22,6 @@ public:
QString defaultPuppetToplevelBuildDirectory() const override; QString defaultPuppetToplevelBuildDirectory() const override;
QUrl projectUrl() const override; QUrl projectUrl() const override;
QString currentProjectDirPath() const override; QString currentProjectDirPath() const override;
QList<QColor> designerSettingsEdit3DViewBackgroundColor() const override;
QColor designerSettingsEdit3DViewGridColor() const override;
QUrl currentResourcePath() const override; QUrl currentResourcePath() const override;
void parseItemLibraryDescriptions() override; void parseItemLibraryDescriptions() override;
const DesignerSettings &designerSettings() const override; const DesignerSettings &designerSettings() const override;

View File

@@ -136,6 +136,11 @@ Item {
} }
} }
if (syncBackgroundColor)
updateBackgroundColors([_generalHelper.sceneEnvironmentColor(sceneId)]);
else
updateBackgroundColors(_generalHelper.bgColor);
notifyActiveSceneChange(); notifyActiveSceneChange();
} }
} }
@@ -191,21 +196,14 @@ Item {
cameraControl.alignView(cameraNodes); cameraControl.alignView(cameraNodes);
} }
function updateViewStates(viewStates) function updateBackgroundColors(colors) {
{ if (colors.length === 1) {
if ("selectBackgroundColor" in viewStates) { backgroundGradientColorStart = colors[0];
var colors = viewStates.selectBackgroundColor backgroundGradientColorEnd = colors[0];
if (colors.length === 1) { } else {
backgroundGradientColorStart = colors[0]; backgroundGradientColorStart = colors[0];
backgroundGradientColorEnd = colors[0]; backgroundGradientColorEnd = colors[1];
} else {
backgroundGradientColorStart = colors[0];
backgroundGradientColorEnd = colors[1];
}
} }
if ("selectGridColor" in viewStates)
viewRoot.gridColor = viewStates.selectGridColor
} }
// If resetToDefault is true, tool states not specifically set to anything will be reset to // If resetToDefault is true, tool states not specifically set to anything will be reset to
@@ -224,13 +222,13 @@ Item {
if ("syncBackgroundColor" in toolStates) { if ("syncBackgroundColor" in toolStates) {
syncBackgroundColor = toolStates.syncBackgroundColor; syncBackgroundColor = toolStates.syncBackgroundColor;
if (syncBackgroundColor) { if (syncBackgroundColor)
var color = []; updateBackgroundColors([_generalHelper.sceneEnvironmentColor(sceneId)]);
color[0] = _generalHelper.sceneEnvironmentColor(sceneId); else
updateViewStates({"selectBackgroundColor": color}); updateBackgroundColors(_generalHelper.bgColor);
}
} else if (resetToDefault) { } else if (resetToDefault) {
syncBackgroundColor = false; syncBackgroundColor = false;
updateBackgroundColors(_generalHelper.bgColor);
} }
if ("showSelectionBox" in toolStates) if ("showSelectionBox" in toolStates)

View File

@@ -568,6 +568,11 @@ QColor GeneralHelper::sceneEnvironmentColor(const QString &sceneId) const
return m_sceneEnvironmentColor[sceneId]; return m_sceneEnvironmentColor[sceneId];
} }
void GeneralHelper::clearSceneEnvironmentColors()
{
m_sceneEnvironmentColor.clear();
}
void GeneralHelper::initToolStates(const QString &sceneId, const QVariantMap &toolStates) void GeneralHelper::initToolStates(const QString &sceneId, const QVariantMap &toolStates)
{ {
m_toolStates[sceneId] = toolStates; m_toolStates[sceneId] = toolStates;
@@ -977,6 +982,14 @@ QVector3D GeneralHelper::adjustScaleForSnap(const QVector3D &newScale)
return adjScale; return adjScale;
} }
void GeneralHelper::setBgColor(const QVariant &colors)
{
if (m_bgColor != colors) {
m_bgColor = colors;
emit bgColorChanged();
}
}
void GeneralHelper::handlePendingToolStateUpdate() void GeneralHelper::handlePendingToolStateUpdate()
{ {
m_toolStateUpdateTimer.stop(); m_toolStateUpdateTimer.stop();

View File

@@ -32,6 +32,7 @@ class GeneralHelper : public QObject
{ {
Q_OBJECT Q_OBJECT
Q_PROPERTY(bool isMacOS READ isMacOS CONSTANT) Q_PROPERTY(bool isMacOS READ isMacOS CONSTANT)
Q_PROPERTY(QVariant bgColor READ bgColor NOTIFY bgColorChanged FINAL)
public: public:
GeneralHelper(); GeneralHelper();
@@ -94,6 +95,7 @@ public:
void setSceneEnvironmentColor(const QString &sceneId, const QColor &color); void setSceneEnvironmentColor(const QString &sceneId, const QColor &color);
Q_INVOKABLE QColor sceneEnvironmentColor(const QString &sceneId) const; Q_INVOKABLE QColor sceneEnvironmentColor(const QString &sceneId) const;
void clearSceneEnvironmentColors();
bool isMacOS() const; bool isMacOS() const;
@@ -118,13 +120,16 @@ public:
void setSnapRotationInterval(double interval) { m_snapRotationInterval = interval; } void setSnapRotationInterval(double interval) { m_snapRotationInterval = interval; }
void setSnapScaleInterval(double interval) { m_snapScaleInterval = interval / 100.; } void setSnapScaleInterval(double interval) { m_snapScaleInterval = interval / 100.; }
void setBgColor(const QVariant &colors);
QVariant bgColor() const { return m_bgColor; }
signals: signals:
void overlayUpdateNeeded(); void overlayUpdateNeeded();
void toolStateChanged(const QString &sceneId, const QString &tool, const QVariant &toolState); void toolStateChanged(const QString &sceneId, const QString &tool, const QVariant &toolState);
void hiddenStateChanged(QQuick3DNode *node); void hiddenStateChanged(QQuick3DNode *node);
void lockedStateChanged(QQuick3DNode *node); void lockedStateChanged(QQuick3DNode *node);
void rotationBlocksChanged(); void rotationBlocksChanged();
void bgColorChanged();
private: private:
void handlePendingToolStateUpdate(); void handlePendingToolStateUpdate();
QVector3D pivotScenePosition(QQuick3DNode *node) const; QVector3D pivotScenePosition(QQuick3DNode *node) const;
@@ -159,6 +164,8 @@ private:
double m_snapPositionInterval = 50.; double m_snapPositionInterval = 50.;
double m_snapRotationInterval = 5.; double m_snapRotationInterval = 5.;
double m_snapScaleInterval = .1; double m_snapScaleInterval = .1;
QVariant m_bgColor;
}; };
} }

View File

@@ -393,6 +393,25 @@ void Qt5InformationNodeInstanceServer::updateSnapSettings(const QVector<Property
#endif #endif
} }
void Qt5InformationNodeInstanceServer::updateColorSettings(const QVector<PropertyValueContainer> &valueChanges)
{
#ifdef QUICK3D_MODULE
if (m_editView3DData.rootItem) {
for (const auto &container : valueChanges) {
if (container.name() == "edit3dGridColor") {
QQmlProperty gridProp(m_editView3DData.rootItem, "gridColor", context());
gridProp.write(container.value());
} else if (container.name() == "edit3dBgColor") {
QMetaObject::invokeMethod(m_editView3DData.rootItem, "updateBackgroundColors",
Q_ARG(QVariant, container.value()));
if (auto helper = qobject_cast<QmlDesigner::Internal::GeneralHelper *>(m_3dHelper))
helper->setBgColor(container.value());
}
}
}
#endif
}
void Qt5InformationNodeInstanceServer::removeRotationBlocks( void Qt5InformationNodeInstanceServer::removeRotationBlocks(
[[maybe_unused]] const QVector<qint32> &instanceIds) [[maybe_unused]] const QVector<qint32> &instanceIds)
{ {
@@ -943,20 +962,8 @@ void Qt5InformationNodeInstanceServer::updateActiveSceneToEditView3D([[maybe_unu
updateView3DRect(m_active3DView); updateView3DRect(m_active3DView);
auto helper = qobject_cast<QmlDesigner::Internal::GeneralHelper *>(m_3dHelper); if (auto helper = qobject_cast<QmlDesigner::Internal::GeneralHelper *>(m_3dHelper))
if (helper) {
helper->storeToolState(helper->globalStateId(), helper->lastSceneIdKey(), QVariant(sceneId), 0); 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) {
QList<QColor> colors{helper->sceneEnvironmentColor(sceneId)};
View3DActionCommand cmd(View3DActionType::SelectBackgroundColor,
QVariant::fromValue(colors));
view3DAction(cmd);
}
}
}
#endif #endif
} }
@@ -1036,6 +1043,9 @@ void Qt5InformationNodeInstanceServer::resolveSceneRoots()
} }
++it; ++it;
} }
updateSceneEnvColorsToHelper();
if (updateActiveScene) { if (updateActiveScene) {
m_active3DView = findView3DForSceneRoot(m_active3DScene); m_active3DView = findView3DForSceneRoot(m_active3DScene);
updateActiveSceneToEditView3D(); updateActiveSceneToEditView3D();
@@ -1975,18 +1985,7 @@ void Qt5InformationNodeInstanceServer::setup3DEditView(
m_editView3DSetupDone = true; m_editView3DSetupDone = true;
auto activeView = qobject_cast<QQuick3DViewport *>(m_active3DView); updateSceneEnvColorsToHelper();
if (activeView) {
QQuick3DSceneEnvironment *activeEnv = activeView->environment();
QColor clearColor = activeEnv->clearColor();
if (clearColor.isValid() && helper) {
ServerNodeInstance activeSceneInstance = active3DSceneInstance();
const QString sceneId = activeSceneInstance.id();
helper->setSceneEnvironmentColor(sceneId, clearColor);
}
}
if (toolStates.contains({})) { if (toolStates.contains({})) {
// Update tool state to an existing no-scene state before updating the active scene to // Update tool state to an existing no-scene state before updating the active scene to
@@ -2000,19 +1999,6 @@ void Qt5InformationNodeInstanceServer::setup3DEditView(
createCameraAndLightGizmos(instanceList); createCameraAndLightGizmos(instanceList);
if (!command.edit3dBackgroundColor.isEmpty()) {
View3DActionCommand backgroundColorCommand(View3DActionType::SelectBackgroundColor,
QVariant::fromValue(
command.edit3dBackgroundColor));
view3DAction(backgroundColorCommand);
}
if (command.edit3dGridColor.isValid()) {
View3DActionCommand backgroundColorCommand(View3DActionType::SelectGridColor,
QVariant::fromValue(command.edit3dGridColor));
view3DAction(backgroundColorCommand);
}
// Queue two renders to make sure icon gizmos update properly // Queue two renders to make sure icon gizmos update properly
render3DEditView(2); render3DEditView(2);
#endif #endif
@@ -2140,6 +2126,7 @@ void Qt5InformationNodeInstanceServer::createScene(const CreateSceneCommand &com
updateRotationBlocks(command.auxiliaryChanges); updateRotationBlocks(command.auxiliaryChanges);
updateMaterialPreviewData(command.auxiliaryChanges); updateMaterialPreviewData(command.auxiliaryChanges);
updateSnapSettings(command.auxiliaryChanges); updateSnapSettings(command.auxiliaryChanges);
updateColorSettings(command.auxiliaryChanges);
} }
QObject::connect(&m_renderModelNodeImageViewTimer, &QTimer::timeout, QObject::connect(&m_renderModelNodeImageViewTimer, &QTimer::timeout,
@@ -2346,11 +2333,10 @@ void Qt5InformationNodeInstanceServer::setSceneEnvironmentColor(const PropertyVa
if (toolStates.contains("syncBackgroundColor")) { if (toolStates.contains("syncBackgroundColor")) {
bool sync = toolStates["syncBackgroundColor"].toBool(); bool sync = toolStates["syncBackgroundColor"].toBool();
QList<QColor> colors{color};
if (sync) { if (sync) {
View3DActionCommand cmd(View3DActionType::SelectBackgroundColor, QList<QColor> colors{color};
QVariant::fromValue(colors)); QMetaObject::invokeMethod(m_editView3DData.rootItem, "updateBackgroundColors",
view3DAction(cmd); Q_ARG(QVariant, QVariant::fromValue(colors)));
} }
} }
#else #else
@@ -2396,6 +2382,42 @@ QVariantList Qt5InformationNodeInstanceServer::alignCameraList() const
return cameras; return cameras;
} }
void Qt5InformationNodeInstanceServer::updateSceneEnvColorsToHelper()
{
#ifdef QUICK3D_MODULE
// Update stored scene environment colors for all scenes
auto helper = qobject_cast<QmlDesigner::Internal::GeneralHelper *>(m_3dHelper);
if (!helper)
return;
helper->clearSceneEnvironmentColors();
const auto sceneRoots = m_3DSceneMap.uniqueKeys();
for (QObject *sceneRoot : sceneRoots) {
auto view3D = qobject_cast<QQuick3DViewport *>(findView3DForSceneRoot(sceneRoot));
if (!view3D)
continue;
QQuick3DSceneEnvironment *env = view3D->environment();
if (!env)
continue;
QColor clearColor = env->clearColor();
if (clearColor.isValid() && helper) {
ServerNodeInstance sceneInstance;
if (hasInstanceForObject(sceneRoot))
sceneInstance = instanceForObject(sceneRoot);
else if (hasInstanceForObject(view3D))
sceneInstance = instanceForObject(view3D);
const QString sceneId = sceneInstance.id();
helper->setSceneEnvironmentColor(sceneId, clearColor);
}
}
#endif
}
void Qt5InformationNodeInstanceServer::changePropertyValues(const ChangeValuesCommand &command) void Qt5InformationNodeInstanceServer::changePropertyValues(const ChangeValuesCommand &command)
{ {
bool hasDynamicProperties = false; bool hasDynamicProperties = false;
@@ -2510,13 +2532,6 @@ void Qt5InformationNodeInstanceServer::view3DAction(const View3DActionCommand &c
case View3DActionType::SyncBackgroundColor: case View3DActionType::SyncBackgroundColor:
updatedToolState.insert("syncBackgroundColor", command.isEnabled()); updatedToolState.insert("syncBackgroundColor", command.isEnabled());
break; break;
case View3DActionType::SelectBackgroundColor:
updatedViewState.insert("selectBackgroundColor", command.value());
break;
case View3DActionType::SelectGridColor: {
updatedViewState.insert("selectGridColor", command.value());
break;
}
#ifdef QUICK3D_PARTICLES_MODULE #ifdef QUICK3D_PARTICLES_MODULE
case View3DActionType::ShowParticleEmitter: case View3DActionType::ShowParticleEmitter:
updatedToolState.insert("showParticleEmitter", command.isEnabled()); updatedToolState.insert("showParticleEmitter", command.isEnabled());
@@ -2581,6 +2596,7 @@ void Qt5InformationNodeInstanceServer::changeAuxiliaryValues(const ChangeAuxilia
updateRotationBlocks(command.auxiliaryChanges); updateRotationBlocks(command.auxiliaryChanges);
updateMaterialPreviewData(command.auxiliaryChanges); updateMaterialPreviewData(command.auxiliaryChanges);
updateSnapSettings(command.auxiliaryChanges); updateSnapSettings(command.auxiliaryChanges);
updateColorSettings(command.auxiliaryChanges);
Qt5NodeInstanceServer::changeAuxiliaryValues(command); Qt5NodeInstanceServer::changeAuxiliaryValues(command);
render3DEditView(); render3DEditView();
} }

View File

@@ -126,6 +126,7 @@ private:
void updateMaterialPreviewData(const QVector<PropertyValueContainer> &valueChanges); void updateMaterialPreviewData(const QVector<PropertyValueContainer> &valueChanges);
void updateRotationBlocks(const QVector<PropertyValueContainer> &valueChanges); void updateRotationBlocks(const QVector<PropertyValueContainer> &valueChanges);
void updateSnapSettings(const QVector<PropertyValueContainer> &valueChanges); void updateSnapSettings(const QVector<PropertyValueContainer> &valueChanges);
void updateColorSettings(const QVector<PropertyValueContainer> &valueChanges);
void removeRotationBlocks(const QVector<qint32> &instanceIds); void removeRotationBlocks(const QVector<qint32> &instanceIds);
void getNodeAtPos(const QPointF &pos); void getNodeAtPos(const QPointF &pos);
@@ -137,6 +138,7 @@ private:
#endif #endif
void setSceneEnvironmentColor(const PropertyValueContainer &container); void setSceneEnvironmentColor(const PropertyValueContainer &container);
QVariantList alignCameraList() const; QVariantList alignCameraList() const;
void updateSceneEnvColorsToHelper();
RenderViewData m_editView3DData; RenderViewData m_editView3DData;
RenderViewData m_modelNode3DImageViewData; RenderViewData m_modelNode3DImageViewData;

View File

@@ -146,8 +146,6 @@ public:
QString defaultPuppetToplevelBuildDirectory() const override { return {}; } QString defaultPuppetToplevelBuildDirectory() const override { return {}; }
QString qmlPuppetFallbackDirectory() const override { return {}; } QString qmlPuppetFallbackDirectory() const override { return {}; }
QUrl projectUrl() const override { return {}; } QUrl projectUrl() const override { return {}; }
QList<QColor> designerSettingsEdit3DViewBackgroundColor() const override { return {}; }
QColor designerSettingsEdit3DViewGridColor() const override { return {}; }
void parseItemLibraryDescriptions() override {} void parseItemLibraryDescriptions() override {}
const QmlDesigner::DesignerSettings &designerSettings() const override { return settings; } const QmlDesigner::DesignerSettings &designerSettings() const override { return settings; }
void undoOnCurrentDesignDocument() override {} void undoOnCurrentDesignDocument() override {}

View File

@@ -16,8 +16,6 @@ public:
MOCK_METHOD(QString, defaultPuppetToplevelBuildDirectory, (), (const, override)); MOCK_METHOD(QString, defaultPuppetToplevelBuildDirectory, (), (const, override));
MOCK_METHOD(QUrl, projectUrl, (), (const, override)); MOCK_METHOD(QUrl, projectUrl, (), (const, override));
MOCK_METHOD(QString, currentProjectDirPath, (), (const, override)); MOCK_METHOD(QString, currentProjectDirPath, (), (const, override));
MOCK_METHOD(QList<QColor>, designerSettingsEdit3DViewBackgroundColor, (), (const, override));
MOCK_METHOD(QColor, designerSettingsEdit3DViewGridColor, (), (const, override));
MOCK_METHOD(QUrl, currentResourcePath, (), (const, override)); MOCK_METHOD(QUrl, currentResourcePath, (), (const, override));
MOCK_METHOD(void, parseItemLibraryDescriptions, (), (override)); MOCK_METHOD(void, parseItemLibraryDescriptions, (), (override));
MOCK_METHOD(const QmlDesigner::DesignerSettings &, designerSettings, (), (const, override)); MOCK_METHOD(const QmlDesigner::DesignerSettings &, designerSettings, (), (const, override));