From 0d5c513523400a4a487d0fa45e7c1472a442d3e2 Mon Sep 17 00:00:00 2001 From: ArgonarioD Date: Fri, 31 Mar 2023 17:44:31 +0800 Subject: [PATCH] =?UTF-8?q?[editor]=20=E5=B0=86=E9=A1=B9=E7=9B=AE=E8=AE=BE?= =?UTF-8?q?=E7=BD=AE=E6=94=BE=E5=88=B0=E4=BA=86=E8=8F=9C=E5=8D=95=E6=A0=8F?= =?UTF-8?q?=E4=B8=AD=20|=20#4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ArchitectureColoredPainting.vcxproj | 8 ++++ ...rchitectureColoredPainting.vcxproj.filters | 24 ++++++++++ .../EditorWidgetItem.ui | 40 +++++++---------- .../src/Editor/EditorWidget.cpp | 21 +++++++-- .../src/Editor/EditorWidgetItem.cpp | 25 ++++++----- .../src/Editor/EditorWidgetItem.h | 7 +-- .../Properties/CanvasPropertyWidget.cpp | 37 ++++++++++++++++ .../Editor/Properties/CanvasPropertyWidget.h | 24 ++++++++++ .../Properties/ProjectPropertyDialog.cpp | 44 +++++++++++++++++++ .../Editor/Properties/ProjectPropertyDialog.h | 26 +++++++++++ .../Properties/ProjectPropertyWidget.cpp | 20 +++++++++ .../Editor/Properties/ProjectPropertyWidget.h | 20 +++++++++ .../src/Editor/Properties/PropertyWidget.cpp | 1 + .../src/Editor/Properties/PropertyWidget.h | 16 +++++++ .../src/Editor/RightBar/InfoDisplayWidget.cpp | 1 + 15 files changed, 273 insertions(+), 41 deletions(-) create mode 100644 ArchitectureColoredPainting/src/Editor/Properties/CanvasPropertyWidget.cpp create mode 100644 ArchitectureColoredPainting/src/Editor/Properties/CanvasPropertyWidget.h create mode 100644 ArchitectureColoredPainting/src/Editor/Properties/ProjectPropertyDialog.cpp create mode 100644 ArchitectureColoredPainting/src/Editor/Properties/ProjectPropertyDialog.h create mode 100644 ArchitectureColoredPainting/src/Editor/Properties/ProjectPropertyWidget.cpp create mode 100644 ArchitectureColoredPainting/src/Editor/Properties/ProjectPropertyWidget.h create mode 100644 ArchitectureColoredPainting/src/Editor/Properties/PropertyWidget.cpp create mode 100644 ArchitectureColoredPainting/src/Editor/Properties/PropertyWidget.h diff --git a/ArchitectureColoredPainting/ArchitectureColoredPainting.vcxproj b/ArchitectureColoredPainting/ArchitectureColoredPainting.vcxproj index 92e8371..3f37fbb 100644 --- a/ArchitectureColoredPainting/ArchitectureColoredPainting.vcxproj +++ b/ArchitectureColoredPainting/ArchitectureColoredPainting.vcxproj @@ -105,6 +105,10 @@ + + + + @@ -208,6 +212,10 @@ + + + + diff --git a/ArchitectureColoredPainting/ArchitectureColoredPainting.vcxproj.filters b/ArchitectureColoredPainting/ArchitectureColoredPainting.vcxproj.filters index 4092917..ec4e2d1 100644 --- a/ArchitectureColoredPainting/ArchitectureColoredPainting.vcxproj.filters +++ b/ArchitectureColoredPainting/ArchitectureColoredPainting.vcxproj.filters @@ -270,6 +270,18 @@ Source Files + + Source Files + + + Source Files + + + Source Files + + + Source Files + @@ -332,6 +344,15 @@ Header Files\Editor\Element + + Header Files + + + Header Files + + + Header Files + @@ -543,6 +564,9 @@ Header Files + + Header Files + diff --git a/ArchitectureColoredPainting/EditorWidgetItem.ui b/ArchitectureColoredPainting/EditorWidgetItem.ui index a1eb7a1..671e9b5 100644 --- a/ArchitectureColoredPainting/EditorWidgetItem.ui +++ b/ArchitectureColoredPainting/EditorWidgetItem.ui @@ -98,7 +98,7 @@ - + 20 @@ -115,28 +115,24 @@ 11 - - - - 0 - 0 - + + + + 0 + 0 + - - 0 + + 图层信息 + + + Qt::AlignCenter - - - 图层信息 - - - - - 设置 - - + + + @@ -233,12 +229,6 @@
ElementPoolWidget.h
1 - - EditorSettingWidget - QWidget -
EditorSettingWidget.h
- 1 -
diff --git a/ArchitectureColoredPainting/src/Editor/EditorWidget.cpp b/ArchitectureColoredPainting/src/Editor/EditorWidget.cpp index e9fe251..8e6a5c5 100644 --- a/ArchitectureColoredPainting/src/Editor/EditorWidget.cpp +++ b/ArchitectureColoredPainting/src/Editor/EditorWidget.cpp @@ -1,6 +1,6 @@ #include "EditorWidget.h" #include "EditorWidgetItem.h" -#include +#include "Properties/ProjectPropertyDialog.h" #include #include #include @@ -104,6 +104,21 @@ void EditorWidget::initProjectMenu() projectMenuButton->setDisabled(true); } - auto* actionSettings = new QAction(QStringLiteral("Ŀ"), projectMenuButton); - projectMenuButton->addMenuAction(actionSettings); + auto* actionProjectSettings = new QAction(QStringLiteral("Ŀ"), projectMenuButton); + projectMenuButton->addMenuAction(actionProjectSettings); + + connect(actionProjectSettings, &QAction::triggered, [this] + { + auto* currentEditorWidgetItem = static_cast(this->tabWidget->currentWidget()); + const auto dialog = new ProjectPropertyDialog(currentEditorWidgetItem, this); + dialog->setWindowTitle(QStringLiteral("Ŀ")); + + connect(dialog, &ProjectPropertyDialog::projectNameChanged, + currentEditorWidgetItem, &EditorWidgetItem::handleProjectNameChange); + connect(dialog, &ProjectPropertyDialog::backgroundColorChanged, + currentEditorWidgetItem, &EditorWidgetItem::handleBackgroundColorChange); + connect(dialog, &ProjectPropertyDialog::canvasSizeChanged, + currentEditorWidgetItem, &EditorWidgetItem::handleCanvasSizeChange); + dialog->exec(); + }); } diff --git a/ArchitectureColoredPainting/src/Editor/EditorWidgetItem.cpp b/ArchitectureColoredPainting/src/Editor/EditorWidgetItem.cpp index 146abab..31bac39 100644 --- a/ArchitectureColoredPainting/src/Editor/EditorWidgetItem.cpp +++ b/ArchitectureColoredPainting/src/Editor/EditorWidgetItem.cpp @@ -15,11 +15,9 @@ EditorWidgetItem::EditorWidgetItem(QString filePath,QWidget *parent) : QWidget(p ui.setupUi(this); previewWindow = ui.Preview; treeWidget = ui.LayerTree; - tabWidget = ui.DisplayTab; this->filePath = filePath; elementInfoDisplayWidget = ui.ElementDisplay; - layerInfoDisplayWidget = dynamic_cast(tabWidget->widget(0)); - editorSettingWidget = dynamic_cast(tabWidget->widget(1)); + layerInfoDisplayWidget = ui.LayerDisplay; elementInfoDisplayWidget->enableEdit(); qDebug() << layerInfoDisplayWidget; qDebug() << elementInfoDisplayWidget; @@ -33,14 +31,11 @@ EditorWidgetItem::EditorWidgetItem(QString filePath,QWidget *parent) : QWidget(p connect(layerInfoDisplayWidget, &InfoDisplayWidget::triggerCentralRefresh, centralRefresh); connect(elementInfoDisplayWidget, &ElementPoolWidget::triggerCentralRefresh, centralRefresh); connect(treeWidget, &LayerTreeWidget::triggerCentralRefresh, centralRefresh); - connect(editorSettingWidget, &EditorSettingWidget::backgroundColorChanged, this, &EditorWidgetItem::handleBackgroundColorChange); - connect(editorSettingWidget, &EditorSettingWidget::projectNameChanged, this, &EditorWidgetItem::handleProjectNameChange); connect(previewWindow, &PreviewWindow::refreshElementPreviewByIndex, elementInfoDisplayWidget, &ElementPoolWidget::refreshPictureByIndex); connect(treeWidget, &LayerTreeWidget::displayLayerChange, previewWindow, &PreviewWindow::currentLayerChanged); //connect(treeWidget, &LayerTreeWidget::requireRefreshElementWidget, elementInfoDisplayWidget, &ElementPoolWidget::refresh); // connect(layerInfoDisplayWidget, &InfoDisplayWidget::requireRefreshElementWidget, elementInfoDisplayWidget, &ElementPoolWidget::refresh); connect(treeWidget, &LayerTreeWidget::displayLayerChange, this, &EditorWidgetItem::onLayerChange); - connect(editorSettingWidget, &EditorSettingWidget::canvasSizeChanged, previewWindow, &PreviewWindow::resize); // connect(layerInfoDisplayWidget, &InfoDisplayWidget::requireRefreshPreview, this, // &EditorWidgetItem::triggerRefreshPreview); // connect(treeWidget, &LayerTreeWidget::requireRefreshPreview, this, @@ -111,7 +106,7 @@ void EditorWidgetItem::onLayerChange(LayerWrapper *layer) { displayLayer = layer; // TODO : notify InfoDisplayWidget and update - dynamic_cast(tabWidget->widget(0))->setLayer(layer); + ui.LayerDisplay->setLayer(layer); this->update(); } @@ -165,13 +160,13 @@ void EditorWidgetItem::saveImpl(QString filePath) const file.close(); } -void EditorWidgetItem::handleBackgroundColorChange(QColor color) +void EditorWidgetItem::handleBackgroundColorChange(const QColor& color) { this->backgroundColor = color; previewWindow->setBackgroundColor(color); } -void EditorWidgetItem::handleProjectNameChange(QString name) +void EditorWidgetItem::handleProjectNameChange(const QString& name) { this->projectName = name; auto parent = dynamic_cast(this->parent); @@ -180,4 +175,14 @@ void EditorWidgetItem::handleProjectNameChange(QString name) { parent->renameTab(this, name); } -} \ No newline at end of file +} + +void EditorWidgetItem::handleCanvasSizeChange(const QSize& size) +{ + previewWindow->resize(size); +} + +QSize EditorWidgetItem::getCanvasReferSize() const +{ + return previewWindow->referSize; +} diff --git a/ArchitectureColoredPainting/src/Editor/EditorWidgetItem.h b/ArchitectureColoredPainting/src/Editor/EditorWidgetItem.h index d718423..ef65a19 100644 --- a/ArchitectureColoredPainting/src/Editor/EditorWidgetItem.h +++ b/ArchitectureColoredPainting/src/Editor/EditorWidgetItem.h @@ -24,7 +24,6 @@ class EditorWidgetItem : public QWidget // QT GUI PART Ui::EditorWidgetItem ui; LayerTreeWidget *treeWidget; - QTabWidget *tabWidget; InfoDisplayWidget* layerInfoDisplayWidget; ElementPoolWidget* elementInfoDisplayWidget; EditorSettingWidget* editorSettingWidget; @@ -45,8 +44,10 @@ public: void paintEvent(QPaintEvent *event) override; void save() const; void saveAs(QString filePath)const; - void handleBackgroundColorChange(QColor color); - void handleProjectNameChange(QString name); + void handleBackgroundColorChange(const QColor& color); + void handleProjectNameChange(const QString& name); + void handleCanvasSizeChange(const QSize& size); + QSize getCanvasReferSize() const; private slots: void onLayerChange(LayerWrapper *layer); diff --git a/ArchitectureColoredPainting/src/Editor/Properties/CanvasPropertyWidget.cpp b/ArchitectureColoredPainting/src/Editor/Properties/CanvasPropertyWidget.cpp new file mode 100644 index 0000000..8dc9e15 --- /dev/null +++ b/ArchitectureColoredPainting/src/Editor/Properties/CanvasPropertyWidget.cpp @@ -0,0 +1,37 @@ +#include "CanvasPropertyWidget.h" + +#include + +CanvasPropertyWidget::CanvasPropertyWidget(const EditorWidgetItem* editorWidgetItem, QWidget* parent) + :PropertyWidget( + std::make_unique(editorWidgetItem->backgroundColor, editorWidgetItem->getCanvasReferSize()), + parent + ), + backgroundColorPicker(new ColorPicker(clonedModel->backgroundColor, this)), + canvasWidth(new QtMaterialTextField(this)), + canvasHeight(new QtMaterialTextField(this)) +{ + auto* layout = new QFormLayout(this); + layout->addRow(QStringLiteral("ɫ"), backgroundColorPicker); + layout->addRow(QStringLiteral(""), canvasWidth); + layout->addRow(QStringLiteral("߶"), canvasHeight); + + canvasWidth->setText(QString::number(clonedModel->canvasSize.width())); + canvasHeight->setText(QString::number(clonedModel->canvasSize.height())); + + canvasWidth->setValidator(new QIntValidator(1, std::numeric_limits::max())); + canvasHeight->setValidator(new QIntValidator(1, std::numeric_limits::max())); + + connect(backgroundColorPicker, &ColorPicker::colorChanged, [this](const QColor& color) + { + this->clonedModel->backgroundColor = color; + }); + connect(canvasWidth, &QtMaterialTextField::textEdited, [this](const QString& newText) + { + this->clonedModel->canvasSize.setWidth(newText.toInt()); + }); + connect(canvasHeight, &QtMaterialTextField::textEdited, [this](const QString& newText) + { + this->clonedModel->canvasSize.setHeight(newText.toInt()); + }); +} diff --git a/ArchitectureColoredPainting/src/Editor/Properties/CanvasPropertyWidget.h b/ArchitectureColoredPainting/src/Editor/Properties/CanvasPropertyWidget.h new file mode 100644 index 0000000..4b23a1a --- /dev/null +++ b/ArchitectureColoredPainting/src/Editor/Properties/CanvasPropertyWidget.h @@ -0,0 +1,24 @@ +#pragma once +#include "PropertyWidget.h" +#include "EditorWidgetItem.h" +#include "EditorWidgetComponent/ColorPicker.h" +#include + +struct CanvasProperties +{ + QColor backgroundColor; + QSize canvasSize; +}; + +class CanvasPropertyWidget : public PropertyWidget +{ + Q_OBJECT +private: + ColorPicker* backgroundColorPicker; + QtMaterialTextField* canvasWidth; + QtMaterialTextField* canvasHeight; + +public: + CanvasPropertyWidget(const EditorWidgetItem* editorWidgetItem, QWidget* parent = nullptr); +}; + diff --git a/ArchitectureColoredPainting/src/Editor/Properties/ProjectPropertyDialog.cpp b/ArchitectureColoredPainting/src/Editor/Properties/ProjectPropertyDialog.cpp new file mode 100644 index 0000000..c3254f8 --- /dev/null +++ b/ArchitectureColoredPainting/src/Editor/Properties/ProjectPropertyDialog.cpp @@ -0,0 +1,44 @@ +#include "ProjectPropertyDialog.h" + +#include +#include +#include + +ProjectPropertyDialog::ProjectPropertyDialog(const EditorWidgetItem* editorWidgetItem, QWidget* parent) + : QDialog(parent), + projectPropertyWidget(new ProjectPropertyWidget(editorWidgetItem, this)), + canvasPropertyWidget(new CanvasPropertyWidget(editorWidgetItem, this)) +{ + auto* layout = new QVBoxLayout(this); + layout->addWidget(new QLabel(QStringLiteral("Ŀ"), this)); + layout->addWidget(projectPropertyWidget); + + layout->addWidget(new QLabel(QStringLiteral(""), this)); + layout->addWidget(canvasPropertyWidget); + + auto* buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel, this); + layout->addWidget(buttonBox); + + connect(buttonBox, &QDialogButtonBox::accepted, this, &ProjectPropertyDialog::accept); + connect(buttonBox, &QDialogButtonBox::rejected, this, &ProjectPropertyDialog::reject); +} + +void ProjectPropertyDialog::accept() +{ + const auto projectProperties = std::move(projectPropertyWidget->clonedModel); + if (!projectProperties->projectName.isEmpty()) + { + emit projectNameChanged(projectProperties->projectName); + } + + const auto canvasProperties = std::move(canvasPropertyWidget->clonedModel); + if (canvasProperties->backgroundColor.isValid()) + { + emit backgroundColorChanged(canvasProperties->backgroundColor); + } + if (canvasProperties->canvasSize.isValid()) + { + emit canvasSizeChanged(canvasProperties->canvasSize); + } + QDialog::accept(); +} diff --git a/ArchitectureColoredPainting/src/Editor/Properties/ProjectPropertyDialog.h b/ArchitectureColoredPainting/src/Editor/Properties/ProjectPropertyDialog.h new file mode 100644 index 0000000..06e8337 --- /dev/null +++ b/ArchitectureColoredPainting/src/Editor/Properties/ProjectPropertyDialog.h @@ -0,0 +1,26 @@ +#pragma once +#include + +#include "EditorWidgetItem.h" +#include "ProjectPropertyWidget.h" +#include "CanvasPropertyWidget.h" + +class ProjectPropertyDialog : public QDialog +{ + Q_OBJECT +private: + ProjectPropertyWidget* projectPropertyWidget; + CanvasPropertyWidget* canvasPropertyWidget; + +public: + ProjectPropertyDialog(const EditorWidgetItem* editorWidgetItem, QWidget* parent = nullptr); + +signals: + void backgroundColorChanged(const QColor& newBackgroundColor); + void canvasSizeChanged(const QSize& newCanvasSize); + void projectNameChanged(const QString& newProjectName); + +private slots: + void accept() override; +}; + diff --git a/ArchitectureColoredPainting/src/Editor/Properties/ProjectPropertyWidget.cpp b/ArchitectureColoredPainting/src/Editor/Properties/ProjectPropertyWidget.cpp new file mode 100644 index 0000000..3cccefd --- /dev/null +++ b/ArchitectureColoredPainting/src/Editor/Properties/ProjectPropertyWidget.cpp @@ -0,0 +1,20 @@ +#include "ProjectPropertyWidget.h" +#include + +ProjectPropertyWidget::ProjectPropertyWidget(const EditorWidgetItem* editorWidgetItem, QWidget* parent) + : PropertyWidget(std::make_unique(editorWidgetItem->projectName), parent), + projectName(new QtMaterialTextField(this)) +{ + auto* layout = new QFormLayout(this); + layout->addRow(QStringLiteral("Ŀ"), projectName); + + projectName->setText(editorWidgetItem->projectName); + + connect(projectName, &QtMaterialTextField::textEdited, [this](const QString& newText) + { + if (!newText.isEmpty()) + { + clonedModel->projectName = newText; + } + }); +} diff --git a/ArchitectureColoredPainting/src/Editor/Properties/ProjectPropertyWidget.h b/ArchitectureColoredPainting/src/Editor/Properties/ProjectPropertyWidget.h new file mode 100644 index 0000000..673b569 --- /dev/null +++ b/ArchitectureColoredPainting/src/Editor/Properties/ProjectPropertyWidget.h @@ -0,0 +1,20 @@ +#pragma once +#include "EditorWidgetItem.h" +#include "PropertyWidget.h" +#include + +struct ProjectProperties +{ + QString projectName; +}; + +class ProjectPropertyWidget : public PropertyWidget +{ + Q_OBJECT +private: + QtMaterialTextField* projectName; + +public: + ProjectPropertyWidget(const EditorWidgetItem* editorWidgetItem, QWidget* parent = nullptr); +}; + diff --git a/ArchitectureColoredPainting/src/Editor/Properties/PropertyWidget.cpp b/ArchitectureColoredPainting/src/Editor/Properties/PropertyWidget.cpp new file mode 100644 index 0000000..bb240b9 --- /dev/null +++ b/ArchitectureColoredPainting/src/Editor/Properties/PropertyWidget.cpp @@ -0,0 +1 @@ +#include "PropertyWidget.h" \ No newline at end of file diff --git a/ArchitectureColoredPainting/src/Editor/Properties/PropertyWidget.h b/ArchitectureColoredPainting/src/Editor/Properties/PropertyWidget.h new file mode 100644 index 0000000..b56ead7 --- /dev/null +++ b/ArchitectureColoredPainting/src/Editor/Properties/PropertyWidget.h @@ -0,0 +1,16 @@ +#pragma once +#include + +/** + * \brief ࣬ȷʱᷢһ save ź + */ +template +class PropertyWidget : public QWidget +{ +public: + std::unique_ptr clonedModel; + /** + * \param clonedModel ԭģ͵Ŀ¡ + */ + PropertyWidget(std::unique_ptr clonedModel, QWidget* parent = nullptr) : QWidget(parent), clonedModel(std::move(clonedModel)) {} +}; diff --git a/ArchitectureColoredPainting/src/Editor/RightBar/InfoDisplayWidget.cpp b/ArchitectureColoredPainting/src/Editor/RightBar/InfoDisplayWidget.cpp index 491fc3c..b15e175 100644 --- a/ArchitectureColoredPainting/src/Editor/RightBar/InfoDisplayWidget.cpp +++ b/ArchitectureColoredPainting/src/Editor/RightBar/InfoDisplayWidget.cpp @@ -78,6 +78,7 @@ InfoDisplayWidget::InfoDisplayWidget(QWidget* parent) :QWidget(parent) connect(ui.styleList, &LayerContainerListWidget::refreshStylePreview, [this] { emit triggerCentralRefresh(); }); + this->setAutoFillBackground(true); } void InfoDisplayWidget::setVisiable(bool visiable)