forked from qt-creator/qt-creator
QmlDesigner Fix: Select Background Color doesn't clear Environment Color checkbox
Task-number: QDS-7439 Change-Id: I5546e02f7cc2d0bcf3197f94a6ccc557cfb84e7b Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Mahmoud Badri <mahmoud.badri@qt.io>
This commit is contained in:
@@ -13,12 +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)
|
View3DActionType actionType,
|
||||||
|
const std::function<void()> &colorSelected)
|
||||||
{
|
{
|
||||||
if (m_dialog)
|
if (m_dialog)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
m_dialog = BackgroundColorSelection::createColorDialog(parent, key, view, actionType);
|
m_dialog = BackgroundColorSelection::createColorDialog(parent, key, view, actionType, 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, [&]() {
|
||||||
@@ -29,31 +30,35 @@ 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)
|
View3DActionType actionType,
|
||||||
|
const std::function<void()> &colorSelected)
|
||||||
{
|
{
|
||||||
auto dialog = new QColorDialog(parent);
|
auto dialog = new QColorDialog(parent);
|
||||||
|
|
||||||
dialog->setModal(true);
|
dialog->setModal(true);
|
||||||
dialog->setAttribute(Qt::WA_DeleteOnClose);
|
dialog->setAttribute(Qt::WA_DeleteOnClose);
|
||||||
|
|
||||||
QList<QColor> oldColorConfig = Edit3DViewConfig::load(key);
|
QList<QColor> oldColorConfig = Edit3DViewConfig::loadColor(key);
|
||||||
|
|
||||||
dialog->show();
|
dialog->show();
|
||||||
|
|
||||||
QObject::connect(dialog,
|
QObject::connect(dialog, &QColorDialog::currentColorChanged, dialog,
|
||||||
&QColorDialog::currentColorChanged,
|
|
||||||
dialog,
|
|
||||||
[actionType, view](const QColor &color) {
|
[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) {
|
QObject::connect(dialog, &QColorDialog::colorSelected, dialog,
|
||||||
Edit3DViewConfig::save(key, color);
|
[key, colorSelected](const QColor &color) {
|
||||||
|
if (colorSelected)
|
||||||
|
colorSelected();
|
||||||
|
|
||||||
|
Edit3DViewConfig::saveColor(key, color);
|
||||||
});
|
});
|
||||||
|
|
||||||
if (Edit3DViewConfig::isValid(oldColorConfig)) {
|
if (Edit3DViewConfig::isColorValid(oldColorConfig)) {
|
||||||
QObject::connect(dialog, &QColorDialog::rejected, dialog, [actionType, oldColorConfig, view]() {
|
QObject::connect(dialog, &QColorDialog::rejected, dialog,
|
||||||
Edit3DViewConfig::set(view, actionType, oldColorConfig);
|
[actionType, oldColorConfig, view]() {
|
||||||
|
Edit3DViewConfig::setColor(view, actionType, oldColorConfig);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -25,13 +25,15 @@ public:
|
|||||||
static void showBackgroundColorSelectionWidget(QWidget *parent,
|
static void showBackgroundColorSelectionWidget(QWidget *parent,
|
||||||
const QByteArray &key,
|
const QByteArray &key,
|
||||||
AbstractView *view,
|
AbstractView *view,
|
||||||
View3DActionType actionType);
|
View3DActionType actionType,
|
||||||
|
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);
|
View3DActionType actionType,
|
||||||
|
const std::function<void ()> &colorSelected);
|
||||||
|
|
||||||
inline static QColorDialog *m_dialog = nullptr;
|
inline static QColorDialog *m_dialog = nullptr;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -315,19 +315,25 @@ void Edit3DView::setSeeker(SeekerSlider *slider)
|
|||||||
m_seeker = slider;
|
m_seeker = slider;
|
||||||
}
|
}
|
||||||
|
|
||||||
Edit3DAction *Edit3DView::createSelectBackgrounColorAction()
|
Edit3DAction *Edit3DView::createSelectBackgroundColorAction(QAction *syncBackgroundColorAction)
|
||||||
{
|
{
|
||||||
QString description = QCoreApplication::translate("SelectBackgroundColorAction",
|
QString description = QCoreApplication::translate("SelectBackgroundColorAction",
|
||||||
"Select Background Color");
|
"Select Background Color");
|
||||||
QString tooltip = QCoreApplication::translate("SelectBackgroundColorAction",
|
QString tooltip = QCoreApplication::translate("SelectBackgroundColorAction",
|
||||||
"Select a color for the background of the 3D view.");
|
"Select a color for the background of the 3D view.");
|
||||||
|
|
||||||
auto operation = [this](const SelectionContext &) {
|
auto operation = [this, syncBackgroundColorAction](const SelectionContext &) {
|
||||||
BackgroundColorSelection::showBackgroundColorSelectionWidget(
|
BackgroundColorSelection::showBackgroundColorSelectionWidget(
|
||||||
edit3DWidget(),
|
edit3DWidget(),
|
||||||
DesignerSettingsKey::EDIT3DVIEW_BACKGROUND_COLOR,
|
DesignerSettingsKey::EDIT3DVIEW_BACKGROUND_COLOR,
|
||||||
this,
|
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,
|
return new Edit3DAction(Constants::EDIT3D_EDIT_SELECT_BACKGROUND_COLOR,
|
||||||
@@ -370,21 +376,26 @@ Edit3DAction *Edit3DView::createGridColorSelectionAction()
|
|||||||
tooltip);
|
tooltip);
|
||||||
}
|
}
|
||||||
|
|
||||||
Edit3DAction *Edit3DView::createResetColorAction()
|
Edit3DAction *Edit3DView::createResetColorAction(QAction *syncBackgroundColorAction)
|
||||||
{
|
{
|
||||||
QString description = QCoreApplication::translate("ResetEdit3DColorsAction", "Reset Colors");
|
QString description = QCoreApplication::translate("ResetEdit3DColorsAction", "Reset Colors");
|
||||||
QString tooltip = QCoreApplication::translate("ResetEdit3DColorsAction",
|
QString tooltip = QCoreApplication::translate("ResetEdit3DColorsAction",
|
||||||
"Reset the background color and the color of the "
|
"Reset the background color and the color of the "
|
||||||
"grid lines of the 3D view to the default values.");
|
"grid lines of the 3D view to the default values.");
|
||||||
|
|
||||||
auto operation = [&](const SelectionContext &) {
|
auto operation = [this, syncBackgroundColorAction](const SelectionContext &) {
|
||||||
QList<QColor> bgColors = {QRgb(0x222222), QRgb(0x999999)};
|
QList<QColor> bgColors = {QRgb(0x222222), QRgb(0x999999)};
|
||||||
Edit3DViewConfig::set(this, View3DActionType::SelectBackgroundColor, bgColors);
|
Edit3DViewConfig::setColor(this, View3DActionType::SelectBackgroundColor, bgColors);
|
||||||
Edit3DViewConfig::save(DesignerSettingsKey::EDIT3DVIEW_BACKGROUND_COLOR, bgColors);
|
Edit3DViewConfig::saveColor(DesignerSettingsKey::EDIT3DVIEW_BACKGROUND_COLOR, bgColors);
|
||||||
|
|
||||||
QColor gridColor{0xaaaaaa};
|
QColor gridColor{0xaaaaaa};
|
||||||
Edit3DViewConfig::set(this, View3DActionType::SelectGridColor, gridColor);
|
Edit3DViewConfig::setColor(this, View3DActionType::SelectGridColor, gridColor);
|
||||||
Edit3DViewConfig::save(DesignerSettingsKey::EDIT3DVIEW_GRID_COLOR, 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,
|
return new Edit3DAction(QmlDesigner::Constants::EDIT3D_EDIT_RESET_BACKGROUND_COLOR,
|
||||||
@@ -772,10 +783,11 @@ void Edit3DView::createEdit3DActions()
|
|||||||
m_visibilityToggleActions << m_showCameraFrustumAction;
|
m_visibilityToggleActions << m_showCameraFrustumAction;
|
||||||
m_visibilityToggleActions << m_showParticleEmitterAction;
|
m_visibilityToggleActions << m_showParticleEmitterAction;
|
||||||
|
|
||||||
m_backgroundColorActions << createSelectBackgrounColorAction();
|
Edit3DAction *syncBackgroundColorAction = createSyncBackgroundColorAction();
|
||||||
|
m_backgroundColorActions << createSelectBackgroundColorAction(syncBackgroundColorAction->action());
|
||||||
m_backgroundColorActions << createGridColorSelectionAction();
|
m_backgroundColorActions << createGridColorSelectionAction();
|
||||||
m_backgroundColorActions << createSyncBackgroundColorAction();
|
m_backgroundColorActions << syncBackgroundColorAction;
|
||||||
m_backgroundColorActions << createResetColorAction();
|
m_backgroundColorActions << createResetColorAction(syncBackgroundColorAction->action());
|
||||||
}
|
}
|
||||||
|
|
||||||
QVector<Edit3DAction *> Edit3DView::leftActions() const
|
QVector<Edit3DAction *> Edit3DView::leftActions() const
|
||||||
|
|||||||
@@ -15,6 +15,7 @@
|
|||||||
|
|
||||||
QT_BEGIN_NAMESPACE
|
QT_BEGIN_NAMESPACE
|
||||||
class QInputEvent;
|
class QInputEvent;
|
||||||
|
class QAction;
|
||||||
QT_END_NAMESPACE
|
QT_END_NAMESPACE
|
||||||
|
|
||||||
namespace QmlDesigner {
|
namespace QmlDesigner {
|
||||||
@@ -77,9 +78,9 @@ private:
|
|||||||
void checkImports();
|
void checkImports();
|
||||||
void handleEntriesChanged();
|
void handleEntriesChanged();
|
||||||
|
|
||||||
Edit3DAction *createSelectBackgrounColorAction();
|
Edit3DAction *createSelectBackgroundColorAction(QAction *syncBackgroundColorAction);
|
||||||
Edit3DAction *createGridColorSelectionAction();
|
Edit3DAction *createGridColorSelectionAction();
|
||||||
Edit3DAction *createResetColorAction();
|
Edit3DAction *createResetColorAction(QAction *syncBackgroundColorAction);
|
||||||
Edit3DAction *createSyncBackgroundColorAction();
|
Edit3DAction *createSyncBackgroundColorAction();
|
||||||
|
|
||||||
QPointer<Edit3DWidget> m_edit3DWidget;
|
QPointer<Edit3DWidget> m_edit3DWidget;
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ namespace QmlDesigner {
|
|||||||
class Edit3DViewConfig
|
class Edit3DViewConfig
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
static QList<QColor> load(const char key[])
|
static QList<QColor> loadColor(const char key[])
|
||||||
{
|
{
|
||||||
QVariant var = QmlDesignerPlugin::settings().value(key);
|
QVariant var = QmlDesignerPlugin::settings().value(key);
|
||||||
|
|
||||||
@@ -28,20 +28,26 @@ public:
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
static void set(AbstractView *view, View3DActionType type, const QList<QColor> &colorConfig)
|
static void setColor(AbstractView *view, View3DActionType type, const QList<QColor> &colorConfig)
|
||||||
{
|
{
|
||||||
if (colorConfig.size() == 1)
|
if (colorConfig.size() == 1)
|
||||||
set(view, type, colorConfig.at(0));
|
setColor(view, type, colorConfig.at(0));
|
||||||
else
|
else
|
||||||
setVariant(view, type, QVariant::fromValue(colorConfig));
|
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));
|
setVariant(view, type, QVariant::fromValue(color));
|
||||||
}
|
}
|
||||||
|
|
||||||
static void save(const QByteArray &key, const QList<QColor> &colorConfig)
|
template <typename T>
|
||||||
|
static void set(AbstractView *view, View3DActionType type, const T &value)
|
||||||
|
{
|
||||||
|
setVariant(view, type, QVariant::fromValue(value));
|
||||||
|
}
|
||||||
|
|
||||||
|
static void saveColor(const QByteArray &key, const QList<QColor> &colorConfig)
|
||||||
{
|
{
|
||||||
QStringList colorNames = Utils::transform(colorConfig, [](const QColor &color) {
|
QStringList colorNames = Utils::transform(colorConfig, [](const QColor &color) {
|
||||||
return color.name();
|
return color.name();
|
||||||
@@ -50,12 +56,12 @@ public:
|
|||||||
saveVariant(key, QVariant::fromValue(colorNames));
|
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()));
|
saveVariant(key, QVariant::fromValue(color.name()));
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool isValid(const QList<QColor> &colorConfig) { return !colorConfig.isEmpty(); }
|
static bool isColorValid(const QList<QColor> &colorConfig) { return !colorConfig.isEmpty(); }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static void setVariant(AbstractView *view, View3DActionType type, const QVariant &colorConfig)
|
static void setVariant(AbstractView *view, View3DActionType type, const QVariant &colorConfig)
|
||||||
|
|||||||
@@ -62,12 +62,12 @@ QString ExternalDependencies::currentProjectDirPath() const
|
|||||||
|
|
||||||
QList<QColor> ExternalDependencies::designerSettingsEdit3DViewBackgroundColor() const
|
QList<QColor> ExternalDependencies::designerSettingsEdit3DViewBackgroundColor() const
|
||||||
{
|
{
|
||||||
return Edit3DViewConfig::load(DesignerSettingsKey::EDIT3DVIEW_BACKGROUND_COLOR);
|
return Edit3DViewConfig::loadColor(DesignerSettingsKey::EDIT3DVIEW_BACKGROUND_COLOR);
|
||||||
}
|
}
|
||||||
|
|
||||||
QColor ExternalDependencies::designerSettingsEdit3DViewGridColor() const
|
QColor ExternalDependencies::designerSettingsEdit3DViewGridColor() const
|
||||||
{
|
{
|
||||||
QList<QColor> gridColorList = Edit3DViewConfig::load(DesignerSettingsKey::EDIT3DVIEW_GRID_COLOR);
|
QList<QColor> gridColorList = Edit3DViewConfig::loadColor(DesignerSettingsKey::EDIT3DVIEW_GRID_COLOR);
|
||||||
if (!gridColorList.isEmpty())
|
if (!gridColorList.isEmpty())
|
||||||
return gridColorList.front();
|
return gridColorList.front();
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user