From 25eec60e5c0c079de22f747cbd0637e93941776e Mon Sep 17 00:00:00 2001
From: karlis <2995621482@qq.com>
Date: Thu, 9 Mar 2023 19:04:33 +0800
Subject: [PATCH] =?UTF-8?q?=E5=88=9D=E6=AD=A5=E5=AE=8C=E6=88=90Layer?=
=?UTF-8?q?=E6=96=B0=E5=BB=BA?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../ArchitectureColoredPainting.vcxproj | 3 +
...rchitectureColoredPainting.vcxproj.filters | 12 +-
.../LayerCreateWidget.cpp | 44 +++++++
.../EditorWidgetComponent/LayerCreateWidget.h | 29 ++++
.../LayerCreateWidget.ui | 124 ++++++++++++++++++
.../src/Editor/EditorWidgetItem.cpp | 1 +
.../src/Editor/ElementPoolWidget.cpp | 4 +
.../src/Editor/ElementPoolWidget.h | 1 +
.../src/Editor/RightBar/LayerTreeWidget.cpp | 20 ++-
.../src/Editor/RightBar/LayerTreeWidget.h | 2 +
10 files changed, 236 insertions(+), 4 deletions(-)
create mode 100644 ArchitectureColoredPainting/src/Editor/EditorWidgetComponent/LayerCreateWidget.cpp
create mode 100644 ArchitectureColoredPainting/src/Editor/EditorWidgetComponent/LayerCreateWidget.h
create mode 100644 ArchitectureColoredPainting/src/Editor/EditorWidgetComponent/LayerCreateWidget.ui
diff --git a/ArchitectureColoredPainting/ArchitectureColoredPainting.vcxproj b/ArchitectureColoredPainting/ArchitectureColoredPainting.vcxproj
index 8bb0b0a..66e8521 100644
--- a/ArchitectureColoredPainting/ArchitectureColoredPainting.vcxproj
+++ b/ArchitectureColoredPainting/ArchitectureColoredPainting.vcxproj
@@ -104,6 +104,7 @@
+
@@ -154,6 +155,7 @@
+
@@ -188,6 +190,7 @@
+
diff --git a/ArchitectureColoredPainting/ArchitectureColoredPainting.vcxproj.filters b/ArchitectureColoredPainting/ArchitectureColoredPainting.vcxproj.filters
index 750b755..5f47d95 100644
--- a/ArchitectureColoredPainting/ArchitectureColoredPainting.vcxproj.filters
+++ b/ArchitectureColoredPainting/ArchitectureColoredPainting.vcxproj.filters
@@ -73,6 +73,9 @@
Form Files
+
+ Form Files
+
@@ -213,6 +216,9 @@
Source Files\Editor\util
+
+ Source Files
+
@@ -248,6 +254,9 @@
Header Files
+
+ Header Files
+
@@ -441,9 +450,6 @@
Header Files\Renderer
-
- Header Files
-
Header Files\Editor\util
diff --git a/ArchitectureColoredPainting/src/Editor/EditorWidgetComponent/LayerCreateWidget.cpp b/ArchitectureColoredPainting/src/Editor/EditorWidgetComponent/LayerCreateWidget.cpp
new file mode 100644
index 0000000..a567453
--- /dev/null
+++ b/ArchitectureColoredPainting/src/Editor/EditorWidgetComponent/LayerCreateWidget.cpp
@@ -0,0 +1,44 @@
+#include "LayerCreateWidget.h"
+#include
+
+LayerCreateWidget::LayerCreateWidget(ElementManager* elementManager, QWidget* parent) :
+ QDialog(parent)
+{
+ ui.setupUi(this);
+ connect(ui.buttonBox, SIGNAL(accepted()), this, SLOT(accept()));
+ connect(ui.buttonBox, SIGNAL(rejected()), this, SLOT(reject()));
+ connect(ui.comboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(onCurrentIndexChanged(int)));
+ elementPool = new ElementPoolWidget(ui.elementPool);
+ elementPool->setElementList(elementManager->elements);
+}
+
+LayerCreateWidget::~LayerCreateWidget()
+{
+}
+
+void LayerCreateWidget::accept()
+{
+ QJsonObject jsonObj;
+ jsonObj.insert("name", ui.name->text());
+ if (ui.comboBox->currentIndex() == 0) {
+ jsonObj.insert("is-folder", false);
+ jsonObj.insert("element", elementPool->currentIndex);
+ }
+ else {
+ jsonObj.insert("is-folder", true);
+ jsonObj.insert("children", QJsonArray());
+ }
+ jsonObj.insert("tranform", "{\"offset\":{\"x\":0,\"y\":0},\"scale\":{\"x\":1,\"y\":1},\"rotation\":0}");
+ jsonObj.insert("referenced-by", QJsonValue());
+ emit LayerInfoReturned(jsonObj);
+ QDialog::accept();
+}
+
+void LayerCreateWidget::onCurrentIndexChanged(int index) {
+ if (index == 0) {// leaf layer
+ elementPool->setVisible(true);
+ }
+ else {// folder layer
+ elementPool->setVisible(false);
+ }
+}
\ No newline at end of file
diff --git a/ArchitectureColoredPainting/src/Editor/EditorWidgetComponent/LayerCreateWidget.h b/ArchitectureColoredPainting/src/Editor/EditorWidgetComponent/LayerCreateWidget.h
new file mode 100644
index 0000000..c9b7c89
--- /dev/null
+++ b/ArchitectureColoredPainting/src/Editor/EditorWidgetComponent/LayerCreateWidget.h
@@ -0,0 +1,29 @@
+#pragma once
+#include
+#include
+#include "ElementPoolWidget.h"
+#include "ElementManager.h"
+#include "ui_LayerCreateWidget.h"
+
+class LayerCreateWidget :
+ public QDialog
+{
+ Q_OBJECT
+
+private:
+ Ui::LayerCreateWidget ui;
+ ElementPoolWidget* elementPool;
+
+
+public:
+ LayerCreateWidget(ElementManager* elementManager,QWidget* parent = nullptr);
+ ~LayerCreateWidget();
+ void accept() override;
+
+public slots:
+ void onCurrentIndexChanged(int index);
+
+signals:
+ void LayerInfoReturned(QJsonObject jsonObj);
+};
+
diff --git a/ArchitectureColoredPainting/src/Editor/EditorWidgetComponent/LayerCreateWidget.ui b/ArchitectureColoredPainting/src/Editor/EditorWidgetComponent/LayerCreateWidget.ui
new file mode 100644
index 0000000..345306c
--- /dev/null
+++ b/ArchitectureColoredPainting/src/Editor/EditorWidgetComponent/LayerCreateWidget.ui
@@ -0,0 +1,124 @@
+
+
+ LayerCreateWidget
+
+
+
+ 0
+ 0
+ 326
+ 355
+
+
+
+ Form
+
+
+ -
+
+
-
+
+
+
+ 90
+ 16777215
+
+
+
+ 0
+
+
+ 2
+
+
+ 2
+
+
+ QComboBox::NoInsert
+
+
+ QComboBox::AdjustToContents
+
+
-
+
+ 叶子节点
+
+
+ -
+
+ 组合节点
+
+
+
+
+ -
+
+
+
+ 0
+
+
+ 0
+
+
+ 0
+
+
+ 0
+
+
-
+
+
+ 11
+
+
+ 11
+
+
-
+
+
+ 图层名:
+
+
+
+ -
+
+
+
+
+
+
+
+ -
+
+
+ -
+
+
+ QDialogButtonBox::Close|QDialogButtonBox::Ok
+
+
+ false
+
+
+
+ -
+
+
+ Qt::Horizontal
+
+
+
+ 40
+ 20
+
+
+
+
+
+
+
+
+
+
+
diff --git a/ArchitectureColoredPainting/src/Editor/EditorWidgetItem.cpp b/ArchitectureColoredPainting/src/Editor/EditorWidgetItem.cpp
index ca16384..deebf88 100644
--- a/ArchitectureColoredPainting/src/Editor/EditorWidgetItem.cpp
+++ b/ArchitectureColoredPainting/src/Editor/EditorWidgetItem.cpp
@@ -36,6 +36,7 @@ EditorWidgetItem::EditorWidgetItem(QString filePath,QWidget *parent) : QWidget(p
elementManager = new ElementManager(source,previewWindow->getRenderer());
layerManager = new LayerManager(source, elementManager);
elementInfoDisplayWidget->setElementManager(elementManager);
+ treeWidget->elementManager = elementManager;
qDebug() << layerManager->toJson();
previewWindow->initialize(layerManager,QSize(jsonDoc.object().value("width").toDouble(),jsonDoc.object().value("height").toDouble()));
diff --git a/ArchitectureColoredPainting/src/Editor/ElementPoolWidget.cpp b/ArchitectureColoredPainting/src/Editor/ElementPoolWidget.cpp
index 5a07153..e9d9b82 100644
--- a/ArchitectureColoredPainting/src/Editor/ElementPoolWidget.cpp
+++ b/ArchitectureColoredPainting/src/Editor/ElementPoolWidget.cpp
@@ -53,6 +53,9 @@ void ElementPoolWidget::setElementList(std::vector elements) {
pItem->setSizeHint(QSize(iconWidth, iconHeight));
pictureList->insertItem(index, pItem);
}
+ if(elements.size() > 0)
+ pictureList->setCurrentRow(0),
+ currentIndex = 0;
}
ElementPoolWidget::~ElementPoolWidget() {
@@ -61,6 +64,7 @@ ElementPoolWidget::~ElementPoolWidget() {
int ElementPoolWidget::pictureItemClicked(QListWidgetItem* item) {
//qDebug() << pictureList->currentRow();
+ currentIndex = pictureList->currentRow();
emit elementSelected(this->elements[pictureList->currentRow()]);
return pictureList->currentRow();
}
diff --git a/ArchitectureColoredPainting/src/Editor/ElementPoolWidget.h b/ArchitectureColoredPainting/src/Editor/ElementPoolWidget.h
index 19f0961..2a880a7 100644
--- a/ArchitectureColoredPainting/src/Editor/ElementPoolWidget.h
+++ b/ArchitectureColoredPainting/src/Editor/ElementPoolWidget.h
@@ -16,6 +16,7 @@ private:
ElementManager* elementManager;
public:
+ int currentIndex = -1;
ElementPoolWidget(QWidget* parent = nullptr);
void setElementList(std::vector elementList);
void setElementManager(ElementManager* element);
diff --git a/ArchitectureColoredPainting/src/Editor/RightBar/LayerTreeWidget.cpp b/ArchitectureColoredPainting/src/Editor/RightBar/LayerTreeWidget.cpp
index f309ba4..1d7cee7 100644
--- a/ArchitectureColoredPainting/src/Editor/RightBar/LayerTreeWidget.cpp
+++ b/ArchitectureColoredPainting/src/Editor/RightBar/LayerTreeWidget.cpp
@@ -1,6 +1,8 @@
#include "LayerTreeWidget.h"
#include
#include
+#include "./EditorWidgetComponent/LayerCreateWidget.h"
+
LayerTreeWidget::LayerTreeWidget(QWidget *parent)
{
emit displayLayerChange(nullptr);
@@ -39,7 +41,23 @@ void LayerTreeWidget::popMenu(const QPoint &pos)
auto layer = this->selectedItem->data(0, Qt::UserRole).value();
if (layer != nullptr) {
if (typeid(*layer) == typeid(FolderLayerWrapper)) {
- menu.addAction(QString::fromLocal8Bit("ӽڵ"), this, &LayerTreeWidget::onRenameEvent);
+ menu.addAction(QString::fromLocal8Bit("ӽڵ"), this, [this, layer]() {
+ auto dialog = new LayerCreateWidget(elementManager, this);
+ connect(dialog, &LayerCreateWidget::LayerInfoReturned, this, [this, layer](QJsonObject jsonObj) {
+ auto folderLayer = dynamic_cast(layer);
+ LayerWrapper* newLayer;
+ if(jsonObj.value("is-folder").toBool())
+ newLayer = new FolderLayerWrapper(jsonObj, this->elementManager, folderLayer);
+ else
+ newLayer = new LeafLayerWrapper(jsonObj, this->elementManager, folderLayer);
+ folderLayer->addChild(std::shared_ptr(newLayer));
+ folderLayer->qTreeWidgetItem.addChild(newLayer->getQTreeItem());
+ qDebug() << jsonObj<<"----------------------";
+ this->refresh();
+ emit requireRefreshPreview();
+ });
+ dialog->exec();
+ });
menu.addAction(QString::fromLocal8Bit("ɾӽڵ㣩"), this, [this]() {
auto layer = this->selectedItem->data(0, Qt::UserRole).value();
layer->delSelf();
diff --git a/ArchitectureColoredPainting/src/Editor/RightBar/LayerTreeWidget.h b/ArchitectureColoredPainting/src/Editor/RightBar/LayerTreeWidget.h
index e935371..9c2f574 100644
--- a/ArchitectureColoredPainting/src/Editor/RightBar/LayerTreeWidget.h
+++ b/ArchitectureColoredPainting/src/Editor/RightBar/LayerTreeWidget.h
@@ -1,5 +1,6 @@
#pragma once
#include "LayerWrapper.h"
+#include "ElementManager.h"
#include
#include
class LayerTreeWidget : public QTreeWidget
@@ -10,6 +11,7 @@ class LayerTreeWidget : public QTreeWidget
LayerWrapper *copiedItem;
public:
+ ElementManager* elementManager;
LayerWrapper* root;
LayerTreeWidget(QWidget *parent = nullptr);
void onRenameEvent();