summaryrefslogtreecommitdiff
path: root/src/plugins/qmldesigner/components
diff options
context:
space:
mode:
Diffstat (limited to 'src/plugins/qmldesigner/components')
-rw-r--r--src/plugins/qmldesigner/components/edit3d/backgroundcolorselection.cpp79
-rw-r--r--src/plugins/qmldesigner/components/edit3d/backgroundcolorselection.h13
-rw-r--r--src/plugins/qmldesigner/components/edit3d/edit3dactions.cpp3
-rw-r--r--src/plugins/qmldesigner/components/edit3d/edit3dview.cpp99
-rw-r--r--src/plugins/qmldesigner/components/edit3d/edit3dview.h6
-rw-r--r--src/plugins/qmldesigner/components/edit3d/edit3dviewconfig.h98
6 files changed, 208 insertions, 90 deletions
diff --git a/src/plugins/qmldesigner/components/edit3d/backgroundcolorselection.cpp b/src/plugins/qmldesigner/components/edit3d/backgroundcolorselection.cpp
index 76db41a177..3d7a9207c0 100644
--- a/src/plugins/qmldesigner/components/edit3d/backgroundcolorselection.cpp
+++ b/src/plugins/qmldesigner/components/edit3d/backgroundcolorselection.cpp
@@ -23,85 +23,56 @@
**
****************************************************************************/
-#include "backgroundcolorselection.h"
+#pragma once
+
+#include <QColorDialog>
-#include <nodeinstanceview.h>
#include <utils/qtcassert.h>
-#include <view3dactioncommand.h>
-#include <qmldesignerplugin.h>
+
+#include "backgroundcolorselection.h"
+#include "edit3dviewconfig.h"
using namespace QmlDesigner;
-namespace {
-QList<QColor> readBackgroundColorConfiguration()
+void BackgroundColorSelection::showBackgroundColorSelectionWidget(QWidget *parent, const QByteArray &key,
+ View3DActionCommand::Type cmdType)
{
- QVariant var = QmlDesigner::DesignerSettings::getValue(
- QmlDesigner::DesignerSettingsKey::EDIT3DVIEW_BACKGROUND_COLOR);
-
- if (!var.isValid())
- return {};
-
- auto colorNameList = var.value<QList<QString>>();
- QTC_ASSERT(colorNameList.size() == 2, return {});
-
- return {colorNameList[0], colorNameList[1]};
-}
+ if (m_dialog)
+ return;
-void setBackgroundColorConfiguration(const QList<QColor> &colorConfig)
-{
- auto view = QmlDesignerPlugin::instance()->viewManager().nodeInstanceView();
- View3DActionCommand cmd(View3DActionCommand::SelectBackgroundColor,
- QVariant::fromValue(colorConfig));
- view->view3DAction(cmd);
-}
+ m_dialog = BackgroundColorSelection::createColorDialog(parent, key, cmdType);
+ QTC_ASSERT(m_dialog, return);
-void saveBackgroundColorConfiguration(const QList<QColor> &colorConfig)
-{
- QList<QString> colorsSaved = {colorConfig[0].name(), colorConfig[1].name()};
- QmlDesigner::DesignerSettings::setValue(
- QmlDesigner::DesignerSettingsKey::EDIT3DVIEW_BACKGROUND_COLOR,
- QVariant::fromValue(colorsSaved));
+ QObject::connect(m_dialog, &QWidget::destroyed, m_dialog, [&]() {
+ m_dialog = nullptr;
+ });
}
-} // namespace
-
-QColorDialog *BackgroundColorSelection::createDialog(QWidget *parent)
+QColorDialog *BackgroundColorSelection::createColorDialog(QWidget *parent, const QByteArray &key,
+ View3DActionCommand::Type cmdType)
{
auto dialog = new QColorDialog(parent);
dialog->setModal(true);
dialog->setAttribute(Qt::WA_DeleteOnClose);
- const QList<QColor> oldColorConfig = readBackgroundColorConfiguration();
+ QList<QColor> oldColorConfig = Edit3DViewConfig::load(key);
dialog->show();
- QObject::connect(dialog, &QColorDialog::currentColorChanged, dialog, [](const QColor &color) {
- setBackgroundColorConfiguration({color, color});
+ QObject::connect(dialog, &QColorDialog::currentColorChanged, dialog, [cmdType](const QColor &color) {
+ Edit3DViewConfig::set(cmdType, color);
});
- QObject::connect(dialog, &QColorDialog::colorSelected, dialog, [](const QColor &color) {
- saveBackgroundColorConfiguration({color, color});
+ QObject::connect(dialog, &QColorDialog::colorSelected, dialog, [key](const QColor &color) {
+ Edit3DViewConfig::save(key, color);
});
- if (!oldColorConfig.isEmpty()) {
- QObject::connect(dialog, &QColorDialog::rejected, dialog, [oldColorConfig]() {
- setBackgroundColorConfiguration(oldColorConfig);
+ if (Edit3DViewConfig::isValid(oldColorConfig)) {
+ QObject::connect(dialog, &QColorDialog::rejected, dialog, [cmdType, oldColorConfig]() {
+ Edit3DViewConfig::set(cmdType, oldColorConfig);
});
}
return dialog;
}
-
-void BackgroundColorSelection::showBackgroundColorSelectionWidget(QWidget *parent)
-{
- if (m_dialog)
- return;
-
- m_dialog = BackgroundColorSelection::createDialog(parent);
- QTC_ASSERT(m_dialog, return);
-
- QObject::connect(m_dialog, &QWidget::destroyed, m_dialog, [&]() {
- m_dialog = nullptr;
- });
-}
diff --git a/src/plugins/qmldesigner/components/edit3d/backgroundcolorselection.h b/src/plugins/qmldesigner/components/edit3d/backgroundcolorselection.h
index d8832f40fd..f7df55b8e3 100644
--- a/src/plugins/qmldesigner/components/edit3d/backgroundcolorselection.h
+++ b/src/plugins/qmldesigner/components/edit3d/backgroundcolorselection.h
@@ -25,9 +25,13 @@
#pragma once
-#include <QColorDialog>
+#include <QByteArray>
+#include <view3dactioncommand.h>
+
+QT_FORWARD_DECLARE_CLASS(QColorDialog)
namespace QmlDesigner {
+
class BackgroundColorSelection : public QObject
{
Q_OBJECT
@@ -37,10 +41,13 @@ public:
: QObject{parent}
{}
- static void showBackgroundColorSelectionWidget(QWidget *parent);
+ static void showBackgroundColorSelectionWidget(QWidget *parent, const QByteArray &key,
+ View3DActionCommand::Type cmdType);
private:
- static QColorDialog *createDialog(QWidget *parent);
+ static QColorDialog *createColorDialog(QWidget *parent, const QByteArray &key,
+ View3DActionCommand::Type cmdType);
+
inline static QColorDialog *m_dialog = nullptr;
};
diff --git a/src/plugins/qmldesigner/components/edit3d/edit3dactions.cpp b/src/plugins/qmldesigner/components/edit3d/edit3dactions.cpp
index 76343584c9..e90f20767d 100644
--- a/src/plugins/qmldesigner/components/edit3d/edit3dactions.cpp
+++ b/src/plugins/qmldesigner/components/edit3d/edit3dactions.cpp
@@ -48,7 +48,8 @@ Edit3DActionTemplate::Edit3DActionTemplate(const QString &description,
void Edit3DActionTemplate::actionTriggered(bool b)
{
- if (m_type != View3DActionCommand::Empty && m_type != View3DActionCommand::SelectBackgroundColor) {
+ if (m_type != View3DActionCommand::Empty && m_type != View3DActionCommand::SelectBackgroundColor
+ && m_type != View3DActionCommand::SelectGridColor) {
auto view = QmlDesignerPlugin::instance()->viewManager().nodeInstanceView();
View3DActionCommand cmd(m_type, b);
view->view3DAction(cmd);
diff --git a/src/plugins/qmldesigner/components/edit3d/edit3dview.cpp b/src/plugins/qmldesigner/components/edit3d/edit3dview.cpp
index 1ef3055ada..aa76d58370 100644
--- a/src/plugins/qmldesigner/components/edit3d/edit3dview.cpp
+++ b/src/plugins/qmldesigner/components/edit3d/edit3dview.cpp
@@ -28,6 +28,8 @@
#include "edit3dcanvas.h"
#include "edit3dview.h"
#include "edit3dwidget.h"
+#include "edit3dviewconfig.h"
+#include "backgroundcolorselection.h"
#include <coreplugin/icore.h>
#include <coreplugin/messagebox.h>
@@ -42,8 +44,6 @@
#include <utils/qtcassert.h>
#include <utils/utilsicons.h>
-#include <backgroundcolorselection.h>
-
#include <QDebug>
#include <QToolButton>
@@ -266,6 +266,70 @@ void Edit3DView::setSeeker(SeekerSlider *slider)
m_seeker = slider;
}
+Edit3DAction *Edit3DView::createSelectBackgrounColorAction()
+{
+ QString description = QCoreApplication::translate("SelectBackgroundColorAction",
+ "Select Background Color");
+ QString tooltip = QCoreApplication::translate("SelectBackgroundColorAction",
+ "Select a color for the background of the 3D Editor.");
+
+ auto operation = [this](const SelectionContext &) {
+ BackgroundColorSelection::showBackgroundColorSelectionWidget(
+ edit3DWidget(),
+ DesignerSettingsKey::EDIT3DVIEW_BACKGROUND_COLOR,
+ View3DActionCommand::SelectBackgroundColor);
+ };
+
+ return new Edit3DAction(
+ Constants::EDIT3D_EDIT_SELECT_BACKGROUND_COLOR, View3DActionCommand::SelectBackgroundColor,
+ description,
+ {}, false, false, {}, {}, operation,
+ tooltip);
+}
+
+Edit3DAction *Edit3DView::createGridColorSelectionAction()
+{
+ QString description = QCoreApplication::translate("SelectGridColorAction", "Select Grid Color");
+ QString tooltip = QCoreApplication::translate("SelectGridColorAction",
+ "Select a color for the grid lines of the 3D Editor.");
+
+ auto operation = [this](const SelectionContext &) {
+ BackgroundColorSelection::showBackgroundColorSelectionWidget(
+ edit3DWidget(),
+ DesignerSettingsKey::EDIT3DVIEW_GRID_COLOR,
+ View3DActionCommand::SelectGridColor);
+ };
+
+ return new Edit3DAction(
+ Constants::EDIT3D_EDIT_SELECT_GRID_COLOR, View3DActionCommand::SelectGridColor,
+ description, {}, false, false, {}, {}, operation,
+ tooltip);
+}
+
+Edit3DAction *Edit3DView::createResetColorAction()
+{
+ 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 Editor to the default valus.");
+
+ auto operation = [](const SelectionContext &) {
+ QList<QColor> bgColors = {QRgb(0x222222), QRgb(0x999999)};
+ Edit3DViewConfig::set(View3DActionCommand::SelectBackgroundColor, bgColors);
+ Edit3DViewConfig::save(DesignerSettingsKey::EDIT3DVIEW_BACKGROUND_COLOR, bgColors);
+
+ QColor gridColor{0xaaaaaa};
+ Edit3DViewConfig::set(View3DActionCommand::SelectGridColor, gridColor);
+ Edit3DViewConfig::save(DesignerSettingsKey::EDIT3DVIEW_GRID_COLOR, gridColor);
+ };
+
+ return new Edit3DAction(
+ QmlDesigner::Constants::EDIT3D_EDIT_RESET_BACKGROUND_COLOR, View3DActionCommand::ResetBackgroundColor,
+ description,
+ {}, false, false, {}, {}, operation,
+ tooltip);
+}
+
void Edit3DView::createEdit3DActions()
{
m_selectionModeAction
@@ -338,32 +402,6 @@ void Edit3DView::createEdit3DActions()
QKeySequence(Qt::Key_G), true, true, {}, {}, nullptr,
QCoreApplication::translate("ShowGridAction", "Toggle the visibility of the helper grid."));
- SelectionContextOperation showBackgroundColorSelection = [this](const SelectionContext &) {
- BackgroundColorSelection::showBackgroundColorSelectionWidget(edit3DWidget());
- };
-
- m_backgroundColorSelectionAction = new Edit3DAction(
- QmlDesigner::Constants::EDIT3D_EDIT_SELECT_BACKGROUND_COLOR, View3DActionCommand::SelectBackgroundColor,
- QCoreApplication::translate("SelectBackgroundColorAction", "Select Background Color"),
- {}, false, false, {}, {}, showBackgroundColorSelection,
- QCoreApplication::translate("SelectBackgroundColorAction", "Select a color for the background of the 3D Editor."));
-
- m_resetBackgroundColorAction = new Edit3DAction(
- QmlDesigner::Constants::EDIT3D_EDIT_RESET_BACKGROUND_COLOR, View3DActionCommand::ResetBackgroundColor,
- QCoreApplication::translate("ResetBackgroundColorAction", "Reset Background Color"),
- {}, false, false, {}, {}, [](const SelectionContext &) {
- QList<QColor> colors = {QRgb(0x222222), QRgb(0x999999)};
- auto view = QmlDesignerPlugin::instance()->viewManager().nodeInstanceView();
- View3DActionCommand cmd(View3DActionCommand::SelectBackgroundColor, QVariant::fromValue(colors));
- view->view3DAction(cmd);
-
- QList<QString> colorsToSave = {colors[0].name(), colors[1].name()};
- QmlDesigner::DesignerSettings::setValue(
- QmlDesigner::DesignerSettingsKey::EDIT3DVIEW_BACKGROUND_COLOR,
- QVariant::fromValue(colorsToSave));
- },
- QCoreApplication::translate("ResetBackgroundColorAction", "Reset background color of the 3D Editor to the default value."));
-
m_showSelectionBoxAction = new Edit3DAction(
QmlDesigner::Constants::EDIT3D_EDIT_SHOW_SELECTION_BOX, View3DActionCommand::ShowSelectionBox,
QCoreApplication::translate("ShowSelectionBoxAction", "Show Selection Boxes"),
@@ -521,8 +559,9 @@ void Edit3DView::createEdit3DActions()
m_visibilityToggleActions << m_showCameraFrustumAction;
m_visibilityToggleActions << m_showParticleEmitterAction;
- m_backgroundColorActions << m_backgroundColorSelectionAction;
- m_backgroundColorActions << m_resetBackgroundColorAction;
+ m_backgroundColorActions << createSelectBackgrounColorAction();
+ m_backgroundColorActions << createGridColorSelectionAction();
+ m_backgroundColorActions << createResetColorAction();
}
QVector<Edit3DAction *> Edit3DView::leftActions() const
diff --git a/src/plugins/qmldesigner/components/edit3d/edit3dview.h b/src/plugins/qmldesigner/components/edit3d/edit3dview.h
index e5cb2aba51..b817c20d1a 100644
--- a/src/plugins/qmldesigner/components/edit3d/edit3dview.h
+++ b/src/plugins/qmldesigner/components/edit3d/edit3dview.h
@@ -85,6 +85,10 @@ private:
void createEdit3DWidget();
void checkImports();
+ Edit3DAction *createSelectBackgrounColorAction();
+ Edit3DAction *createGridColorSelectionAction();
+ Edit3DAction *createResetColorAction();
+
QPointer<Edit3DWidget> m_edit3DWidget;
QVector<Edit3DAction *> m_leftActions;
QVector<Edit3DAction *> m_rightActions;
@@ -101,8 +105,6 @@ private:
Edit3DAction *m_orientationModeAction = nullptr;
Edit3DAction *m_editLightAction = nullptr;
Edit3DAction *m_showGridAction = nullptr;
- Edit3DAction *m_backgroundColorSelectionAction = nullptr;
- Edit3DAction *m_resetBackgroundColorAction = nullptr;
Edit3DAction *m_showSelectionBoxAction = nullptr;
Edit3DAction *m_showIconGizmoAction = nullptr;
Edit3DAction *m_showCameraFrustumAction = nullptr;
diff --git a/src/plugins/qmldesigner/components/edit3d/edit3dviewconfig.h b/src/plugins/qmldesigner/components/edit3d/edit3dviewconfig.h
new file mode 100644
index 0000000000..8e4081176a
--- /dev/null
+++ b/src/plugins/qmldesigner/components/edit3d/edit3dviewconfig.h
@@ -0,0 +1,98 @@
+/****************************************************************************
+**
+** Copyright (C) 2022 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of Qt Creator.
+**
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3 as published by the Free Software
+** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-3.0.html.
+**
+****************************************************************************/
+
+#pragma once
+
+#include <view3dactioncommand.h>
+
+#include <nodeinstanceview.h>
+#include <qmldesignerplugin.h>
+
+#include <utils/algorithm.h>
+#include <utils/qtcassert.h>
+
+namespace QmlDesigner {
+
+class Edit3DViewConfig
+{
+public:
+ static QList<QColor> load(const char key[])
+ {
+ QVariant var = DesignerSettings::getValue(key);
+
+ if (!var.isValid())
+ return {};
+
+ auto colorNameList = var.value<QStringList>();
+
+ return Utils::transform(colorNameList, [](const QString &colorName) {
+ return QColor{colorName};
+ });
+ }
+
+ static void set(View3DActionCommand::Type type, const QList<QColor> &colorConfig)
+ {
+ if (colorConfig.size() == 1)
+ set(type, colorConfig.at(0));
+ else
+ setVariant(type, QVariant::fromValue(colorConfig));
+ }
+
+ static void set(View3DActionCommand::Type type, const QColor &color)
+ {
+ setVariant(type, QVariant::fromValue(color));
+ }
+
+ static void save(const QByteArray &key, const QList<QColor> &colorConfig)
+ {
+ QStringList colorNames = Utils::transform(colorConfig, [](const QColor &color) {
+ return color.name();
+ });
+
+ saveVariant(key, QVariant::fromValue(colorNames));
+ }
+
+ static void save(const QByteArray &key, const QColor &color)
+ {
+ saveVariant(key, QVariant::fromValue(color.name()));
+ }
+
+ static bool isValid(const QList<QColor> &colorConfig) { return !colorConfig.isEmpty(); }
+
+private:
+ static void setVariant(View3DActionCommand::Type type, const QVariant &colorConfig)
+ {
+ auto view = QmlDesignerPlugin::instance()->viewManager().nodeInstanceView();
+ View3DActionCommand cmd(type, colorConfig);
+ view->view3DAction(cmd);
+ }
+
+ static void saveVariant(const QByteArray &key, const QVariant &colorConfig)
+ {
+ DesignerSettings::setValue(key, colorConfig);
+ }
+};
+
+} // namespace QmlDesigner