From 61c133f48a3e7f0afc8f5f8baba01e3d311709ef Mon Sep 17 00:00:00 2001 From: Samuel Ghinet Date: Tue, 25 Oct 2022 18:24:19 +0300 Subject: [PATCH] QmlDesigner Fix: Select Background Color doesn't clear Environment Color checkbox Task-number: QDS-7439 Change-Id: I5546e02f7cc2d0bcf3197f94a6ccc557cfb84e7b Reviewed-by: Qt CI Bot Reviewed-by: Mahmoud Badri --- .../edit3d/backgroundcolorselection.cpp | 35 ++++++++++-------- .../edit3d/backgroundcolorselection.h | 6 ++-- .../components/edit3d/edit3dview.cpp | 36 ++++++++++++------- .../components/edit3d/edit3dview.h | 5 +-- .../components/edit3d/edit3dviewconfig.h | 20 +++++++---- .../qmldesignerexternaldependencies.cpp | 4 +-- 6 files changed, 66 insertions(+), 40 deletions(-) diff --git a/src/plugins/qmldesigner/components/edit3d/backgroundcolorselection.cpp b/src/plugins/qmldesigner/components/edit3d/backgroundcolorselection.cpp index be4970e7c1e..07d65cb3c33 100644 --- a/src/plugins/qmldesigner/components/edit3d/backgroundcolorselection.cpp +++ b/src/plugins/qmldesigner/components/edit3d/backgroundcolorselection.cpp @@ -13,12 +13,13 @@ using namespace QmlDesigner; void BackgroundColorSelection::showBackgroundColorSelectionWidget(QWidget *parent, const QByteArray &key, AbstractView *view, - View3DActionType actionType) + View3DActionType actionType, + const std::function &colorSelected) { if (m_dialog) return; - m_dialog = BackgroundColorSelection::createColorDialog(parent, key, view, actionType); + m_dialog = BackgroundColorSelection::createColorDialog(parent, key, view, actionType, colorSelected); QTC_ASSERT(m_dialog, return); QObject::connect(m_dialog, &QWidget::destroyed, m_dialog, [&]() { @@ -29,32 +30,36 @@ void BackgroundColorSelection::showBackgroundColorSelectionWidget(QWidget *paren QColorDialog *BackgroundColorSelection::createColorDialog(QWidget *parent, const QByteArray &key, AbstractView *view, - View3DActionType actionType) + View3DActionType actionType, + const std::function &colorSelected) { auto dialog = new QColorDialog(parent); dialog->setModal(true); dialog->setAttribute(Qt::WA_DeleteOnClose); - QList oldColorConfig = Edit3DViewConfig::load(key); + QList oldColorConfig = Edit3DViewConfig::loadColor(key); dialog->show(); - QObject::connect(dialog, - &QColorDialog::currentColorChanged, - dialog, + QObject::connect(dialog, &QColorDialog::currentColorChanged, dialog, [actionType, view](const QColor &color) { - Edit3DViewConfig::set(view, actionType, color); + Edit3DViewConfig::setColor(view, actionType, color); }); - QObject::connect(dialog, &QColorDialog::colorSelected, dialog, [key](const QColor &color) { - Edit3DViewConfig::save(key, color); - }); + QObject::connect(dialog, &QColorDialog::colorSelected, dialog, + [key, colorSelected](const QColor &color) { + if (colorSelected) + colorSelected(); - if (Edit3DViewConfig::isValid(oldColorConfig)) { - QObject::connect(dialog, &QColorDialog::rejected, dialog, [actionType, oldColorConfig, view]() { - Edit3DViewConfig::set(view, actionType, oldColorConfig); - }); + Edit3DViewConfig::saveColor(key, color); + }); + + if (Edit3DViewConfig::isColorValid(oldColorConfig)) { + QObject::connect(dialog, &QColorDialog::rejected, dialog, + [actionType, oldColorConfig, view]() { + Edit3DViewConfig::setColor(view, actionType, oldColorConfig); + }); } return dialog; diff --git a/src/plugins/qmldesigner/components/edit3d/backgroundcolorselection.h b/src/plugins/qmldesigner/components/edit3d/backgroundcolorselection.h index 061c5b7ea7a..25663ad886b 100644 --- a/src/plugins/qmldesigner/components/edit3d/backgroundcolorselection.h +++ b/src/plugins/qmldesigner/components/edit3d/backgroundcolorselection.h @@ -25,13 +25,15 @@ public: static void showBackgroundColorSelectionWidget(QWidget *parent, const QByteArray &key, AbstractView *view, - View3DActionType actionType); + View3DActionType actionType, + const std::function &colorSelected = {}); private: static QColorDialog *createColorDialog(QWidget *parent, const QByteArray &key, AbstractView *view, - View3DActionType actionType); + View3DActionType actionType, + const std::function &colorSelected); inline static QColorDialog *m_dialog = nullptr; }; diff --git a/src/plugins/qmldesigner/components/edit3d/edit3dview.cpp b/src/plugins/qmldesigner/components/edit3d/edit3dview.cpp index cbf78003754..2159c3c9ee8 100644 --- a/src/plugins/qmldesigner/components/edit3d/edit3dview.cpp +++ b/src/plugins/qmldesigner/components/edit3d/edit3dview.cpp @@ -315,19 +315,25 @@ void Edit3DView::setSeeker(SeekerSlider *slider) m_seeker = slider; } -Edit3DAction *Edit3DView::createSelectBackgrounColorAction() +Edit3DAction *Edit3DView::createSelectBackgroundColorAction(QAction *syncBackgroundColorAction) { QString description = QCoreApplication::translate("SelectBackgroundColorAction", "Select Background Color"); QString tooltip = QCoreApplication::translate("SelectBackgroundColorAction", "Select a color for the background of the 3D view."); - auto operation = [this](const SelectionContext &) { + auto operation = [this, syncBackgroundColorAction](const SelectionContext &) { BackgroundColorSelection::showBackgroundColorSelectionWidget( edit3DWidget(), DesignerSettingsKey::EDIT3DVIEW_BACKGROUND_COLOR, this, - View3DActionType::SelectBackgroundColor); + View3DActionType::SelectBackgroundColor, + [this, syncBackgroundColorAction]() { + if (syncBackgroundColorAction->isChecked()) { + Edit3DViewConfig::set(this, View3DActionType::SyncBackgroundColor, false); + syncBackgroundColorAction->setChecked(false); + } + }); }; return new Edit3DAction(Constants::EDIT3D_EDIT_SELECT_BACKGROUND_COLOR, @@ -370,21 +376,26 @@ Edit3DAction *Edit3DView::createGridColorSelectionAction() tooltip); } -Edit3DAction *Edit3DView::createResetColorAction() +Edit3DAction *Edit3DView::createResetColorAction(QAction *syncBackgroundColorAction) { QString description = QCoreApplication::translate("ResetEdit3DColorsAction", "Reset Colors"); QString tooltip = QCoreApplication::translate("ResetEdit3DColorsAction", "Reset the background color and the color of the " "grid lines of the 3D view to the default values."); - auto operation = [&](const SelectionContext &) { + auto operation = [this, syncBackgroundColorAction](const SelectionContext &) { QList bgColors = {QRgb(0x222222), QRgb(0x999999)}; - Edit3DViewConfig::set(this, View3DActionType::SelectBackgroundColor, bgColors); - Edit3DViewConfig::save(DesignerSettingsKey::EDIT3DVIEW_BACKGROUND_COLOR, bgColors); + Edit3DViewConfig::setColor(this, View3DActionType::SelectBackgroundColor, bgColors); + Edit3DViewConfig::saveColor(DesignerSettingsKey::EDIT3DVIEW_BACKGROUND_COLOR, bgColors); QColor gridColor{0xaaaaaa}; - Edit3DViewConfig::set(this, View3DActionType::SelectGridColor, gridColor); - Edit3DViewConfig::save(DesignerSettingsKey::EDIT3DVIEW_GRID_COLOR, gridColor); + Edit3DViewConfig::setColor(this, View3DActionType::SelectGridColor, gridColor); + Edit3DViewConfig::saveColor(DesignerSettingsKey::EDIT3DVIEW_GRID_COLOR, gridColor); + + if (syncBackgroundColorAction->isChecked()) { + Edit3DViewConfig::set(this, View3DActionType::SyncBackgroundColor, false); + syncBackgroundColorAction->setChecked(false); + } }; return new Edit3DAction(QmlDesigner::Constants::EDIT3D_EDIT_RESET_BACKGROUND_COLOR, @@ -772,10 +783,11 @@ void Edit3DView::createEdit3DActions() m_visibilityToggleActions << m_showCameraFrustumAction; m_visibilityToggleActions << m_showParticleEmitterAction; - m_backgroundColorActions << createSelectBackgrounColorAction(); + Edit3DAction *syncBackgroundColorAction = createSyncBackgroundColorAction(); + m_backgroundColorActions << createSelectBackgroundColorAction(syncBackgroundColorAction->action()); m_backgroundColorActions << createGridColorSelectionAction(); - m_backgroundColorActions << createSyncBackgroundColorAction(); - m_backgroundColorActions << createResetColorAction(); + m_backgroundColorActions << syncBackgroundColorAction; + m_backgroundColorActions << createResetColorAction(syncBackgroundColorAction->action()); } QVector Edit3DView::leftActions() const diff --git a/src/plugins/qmldesigner/components/edit3d/edit3dview.h b/src/plugins/qmldesigner/components/edit3d/edit3dview.h index b3c7be17a0e..eaa881d5b1e 100644 --- a/src/plugins/qmldesigner/components/edit3d/edit3dview.h +++ b/src/plugins/qmldesigner/components/edit3d/edit3dview.h @@ -15,6 +15,7 @@ QT_BEGIN_NAMESPACE class QInputEvent; +class QAction; QT_END_NAMESPACE namespace QmlDesigner { @@ -77,9 +78,9 @@ private: void checkImports(); void handleEntriesChanged(); - Edit3DAction *createSelectBackgrounColorAction(); + Edit3DAction *createSelectBackgroundColorAction(QAction *syncBackgroundColorAction); Edit3DAction *createGridColorSelectionAction(); - Edit3DAction *createResetColorAction(); + Edit3DAction *createResetColorAction(QAction *syncBackgroundColorAction); Edit3DAction *createSyncBackgroundColorAction(); QPointer m_edit3DWidget; diff --git a/src/plugins/qmldesigner/components/edit3d/edit3dviewconfig.h b/src/plugins/qmldesigner/components/edit3d/edit3dviewconfig.h index 2bee2d2b3bd..267e27042c9 100644 --- a/src/plugins/qmldesigner/components/edit3d/edit3dviewconfig.h +++ b/src/plugins/qmldesigner/components/edit3d/edit3dviewconfig.h @@ -14,7 +14,7 @@ namespace QmlDesigner { class Edit3DViewConfig { public: - static QList load(const char key[]) + static QList loadColor(const char key[]) { QVariant var = QmlDesignerPlugin::settings().value(key); @@ -28,20 +28,26 @@ public: }); } - static void set(AbstractView *view, View3DActionType type, const QList &colorConfig) + static void setColor(AbstractView *view, View3DActionType type, const QList &colorConfig) { if (colorConfig.size() == 1) - set(view, type, colorConfig.at(0)); + setColor(view, type, colorConfig.at(0)); else setVariant(view, type, QVariant::fromValue(colorConfig)); } - static void set(AbstractView *view, View3DActionType type, const QColor &color) + static void setColor(AbstractView *view, View3DActionType type, const QColor &color) { setVariant(view, type, QVariant::fromValue(color)); } - static void save(const QByteArray &key, const QList &colorConfig) + template + static void set(AbstractView *view, View3DActionType type, const T &value) + { + setVariant(view, type, QVariant::fromValue(value)); + } + + static void saveColor(const QByteArray &key, const QList &colorConfig) { QStringList colorNames = Utils::transform(colorConfig, [](const QColor &color) { return color.name(); @@ -50,12 +56,12 @@ public: saveVariant(key, QVariant::fromValue(colorNames)); } - static void save(const QByteArray &key, const QColor &color) + static void saveColor(const QByteArray &key, const QColor &color) { saveVariant(key, QVariant::fromValue(color.name())); } - static bool isValid(const QList &colorConfig) { return !colorConfig.isEmpty(); } + static bool isColorValid(const QList &colorConfig) { return !colorConfig.isEmpty(); } private: static void setVariant(AbstractView *view, View3DActionType type, const QVariant &colorConfig) diff --git a/src/plugins/qmldesigner/qmldesignerexternaldependencies.cpp b/src/plugins/qmldesigner/qmldesignerexternaldependencies.cpp index 7cff56d272b..cc872abbf6e 100644 --- a/src/plugins/qmldesigner/qmldesignerexternaldependencies.cpp +++ b/src/plugins/qmldesigner/qmldesignerexternaldependencies.cpp @@ -62,12 +62,12 @@ QString ExternalDependencies::currentProjectDirPath() const QList ExternalDependencies::designerSettingsEdit3DViewBackgroundColor() const { - return Edit3DViewConfig::load(DesignerSettingsKey::EDIT3DVIEW_BACKGROUND_COLOR); + return Edit3DViewConfig::loadColor(DesignerSettingsKey::EDIT3DVIEW_BACKGROUND_COLOR); } QColor ExternalDependencies::designerSettingsEdit3DViewGridColor() const { - QList gridColorList = Edit3DViewConfig::load(DesignerSettingsKey::EDIT3DVIEW_GRID_COLOR); + QList gridColorList = Edit3DViewConfig::loadColor(DesignerSettingsKey::EDIT3DVIEW_GRID_COLOR); if (!gridColorList.isEmpty()) return gridColorList.front();