From 3d770ea92fcd0be4e7afd7efa7baf9a7d198d39d Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E7=99=BD=E5=B0=81=E7=BE=BD?= <2360164671@qq.com>
Date: Mon, 16 Jan 2023 21:19:35 +0800
Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0layer=E6=A0=91=E5=BD=A2?=
=?UTF-8?q?=E5=B1=95=E7=A4=BA=E5=92=8C=E5=8F=B3=E9=94=AE=E8=8F=9C=E5=8D=95?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../ArchitectureColoredPainting.vcxproj | 4 +-
...rchitectureColoredPainting.vcxproj.filters | 12 +++--
ArchitectureColoredPainting/EditorWidget.ui | 54 ++++++++++++++-----
.../src/Editor/EditorWidget.cpp | 5 ++
.../src/Editor/EditorWidget.h | 4 +-
.../src/Editor/LayerManager.cpp | 12 +++++
.../src/Editor/LayerManager.h | 7 +++
.../src/Editor/LayerWrapper.cpp | 32 ++++++++---
.../src/Editor/LayerWrapper.h | 11 ++++
.../src/Editor/RightBar/InfoDisplayWidget.h | 1 +
.../src/Editor/RightBar/LayerTreeWidget.cpp | 53 ++++++++++++++++++
.../src/Editor/RightBar/LayerTreeWidget.h | 18 +++++++
12 files changed, 189 insertions(+), 24 deletions(-)
create mode 100644 ArchitectureColoredPainting/src/Editor/RightBar/InfoDisplayWidget.h
create mode 100644 ArchitectureColoredPainting/src/Editor/RightBar/LayerTreeWidget.cpp
create mode 100644 ArchitectureColoredPainting/src/Editor/RightBar/LayerTreeWidget.h
diff --git a/ArchitectureColoredPainting/ArchitectureColoredPainting.vcxproj b/ArchitectureColoredPainting/ArchitectureColoredPainting.vcxproj
index b06b955..6555ec8 100644
--- a/ArchitectureColoredPainting/ArchitectureColoredPainting.vcxproj
+++ b/ArchitectureColoredPainting/ArchitectureColoredPainting.vcxproj
@@ -68,7 +68,7 @@
stdcpp17
- $(SolutionDir)QGoodWindow;%(AdditionalIncludeDirectories);
+ $(SolutionDir)ArchitectureColoredPainting\src\Editor\RightBar;$(SolutionDir)ArchitectureColoredPainting\src\Editor\;$(SolutionDir)QGoodWindow;%(AdditionalIncludeDirectories)
@@ -105,6 +105,7 @@
+
@@ -161,6 +162,7 @@
+
diff --git a/ArchitectureColoredPainting/ArchitectureColoredPainting.vcxproj.filters b/ArchitectureColoredPainting/ArchitectureColoredPainting.vcxproj.filters
index 0d4ccee..d127dfd 100644
--- a/ArchitectureColoredPainting/ArchitectureColoredPainting.vcxproj.filters
+++ b/ArchitectureColoredPainting/ArchitectureColoredPainting.vcxproj.filters
@@ -174,6 +174,9 @@
Source Files\Editor\third-party modules
+
+ Source Files
+
@@ -203,6 +206,9 @@
Header Files\Editor
+
+ Header Files
+
@@ -330,9 +336,6 @@
Header Files\Editor
-
- Header Files\Editor
-
Header Files\Renderer\Painting
@@ -354,6 +357,9 @@
Header Files\Editor\util
+
+ Header Files\Editor
+
diff --git a/ArchitectureColoredPainting/EditorWidget.ui b/ArchitectureColoredPainting/EditorWidget.ui
index 7f00648..b4a34e5 100644
--- a/ArchitectureColoredPainting/EditorWidget.ui
+++ b/ArchitectureColoredPainting/EditorWidget.ui
@@ -27,18 +27,43 @@
0
-
-
-
-
-
-
- 纹理编辑
-
-
-
- -
-
-
-
+
+
+ -
+
+
+ 纹理编辑
+
+
+ Qt::AlignCenter
+
+
+
+ -
+
+
-
+
+
+ -
+
+
+ -
+
+
+
-
+
+
+ Qt::CustomContextMenu
+
+
+
+
+
+
+
+
+
+
@@ -49,6 +74,11 @@
QOpenGLWidget
+
+ LayerTreeWidget
+ QTreeWidget
+
+
diff --git a/ArchitectureColoredPainting/src/Editor/EditorWidget.cpp b/ArchitectureColoredPainting/src/Editor/EditorWidget.cpp
index c61e341..17bd5f9 100644
--- a/ArchitectureColoredPainting/src/Editor/EditorWidget.cpp
+++ b/ArchitectureColoredPainting/src/Editor/EditorWidget.cpp
@@ -4,6 +4,7 @@ EditorWidget::EditorWidget(QWidget *parent) : QWidget(parent)
{
ui.setupUi(this);
previewWindow = ui.Preview;
+ treeWidget = ui.LayerTree;
qDebug() << "123";
// test
QFile settingFile;
@@ -19,6 +20,10 @@ EditorWidget::EditorWidget(QWidget *parent) : QWidget(parent)
elementManager = new ElementManager(source);
layerManager = new LayerManager(source, elementManager);
previewWindow->initialize(layerManager);
+ if (layerManager->getRoot() != nullptr)
+ {
+ treeWidget->addTopLevelItem(layerManager->getRoot()->qTreeItem);
+ }
}
EditorWidget::~EditorWidget()
diff --git a/ArchitectureColoredPainting/src/Editor/EditorWidget.h b/ArchitectureColoredPainting/src/Editor/EditorWidget.h
index 14ce226..26ac4c0 100644
--- a/ArchitectureColoredPainting/src/Editor/EditorWidget.h
+++ b/ArchitectureColoredPainting/src/Editor/EditorWidget.h
@@ -2,11 +2,12 @@
#include "ElementManager.h"
#include "LayerManager.h"
+#include "LayerTreeWidget.h"
#include "PreviewWindow.h"
#include "ui_EditorWidget.h"
#include
+#include
#include
-
class EditorWidget : public QWidget
{
Q_OBJECT
@@ -16,6 +17,7 @@ class EditorWidget : public QWidget
PreviewWindow *previewWindow;
ElementManager *elementManager;
LayerManager *layerManager;
+ LayerTreeWidget *treeWidget;
public:
EditorWidget(QWidget *parent = nullptr);
diff --git a/ArchitectureColoredPainting/src/Editor/LayerManager.cpp b/ArchitectureColoredPainting/src/Editor/LayerManager.cpp
index dfc7ea6..3a9a60f 100644
--- a/ArchitectureColoredPainting/src/Editor/LayerManager.cpp
+++ b/ArchitectureColoredPainting/src/Editor/LayerManager.cpp
@@ -7,6 +7,10 @@ LayerManager::LayerManager(QJsonObject source, ElementManager *elementManager)
else
root = new LeafLayerWrapper(rootJson, elementManager, nullptr);
}
+LayerWrapper *LayerManager::getRoot() const
+{
+ return root;
+}
void LayerManager::paint(QPainter *painter) const
{
painter->drawPath(root->getCache());
@@ -57,3 +61,11 @@ bool LayerManager::changeParent(FolderLayerWrapper *newParent) const
selectedLayers[0]->setParent(newParent);
return true;
}
+void LayerManager::addLayer(LayerWrapper *layer)
+{
+ layerSet.insert(layer);
+}
+void LayerManager::removeLayer(LayerWrapper *layer)
+{
+ layerSet.erase(layer);
+}
diff --git a/ArchitectureColoredPainting/src/Editor/LayerManager.h b/ArchitectureColoredPainting/src/Editor/LayerManager.h
index 370861a..a3a9742 100644
--- a/ArchitectureColoredPainting/src/Editor/LayerManager.h
+++ b/ArchitectureColoredPainting/src/Editor/LayerManager.h
@@ -3,9 +3,11 @@
#include "LayerWrapper.h"
#include
#include
+#include
#include
#include
using std::pair;
+using std::set;
using std::vector;
class ElementManager;
class LayerWrapper;
@@ -21,8 +23,13 @@ class LayerManager
LayerPtrs involvedLeafLayersCache;
bool singleSelectedCheck() const;
bool multipleSelectedCheck() const;
+ set layerSet;
public:
+ void addLayer(LayerWrapper *layer);
+ void removeLayer(LayerWrapper *layer);
+ LayerWrapper *getRoot() const;
+ LayerManager() = default;
LayerManager(QJsonObject source, ElementManager *elementManager);
void paint(QPainter *painter) const;
bool rename(QString newName) const;
diff --git a/ArchitectureColoredPainting/src/Editor/LayerWrapper.cpp b/ArchitectureColoredPainting/src/Editor/LayerWrapper.cpp
index 96ea1af..a06788e 100644
--- a/ArchitectureColoredPainting/src/Editor/LayerWrapper.cpp
+++ b/ArchitectureColoredPainting/src/Editor/LayerWrapper.cpp
@@ -33,15 +33,23 @@ LayerWrapper::LayerWrapper(QJsonObject json, LayerWrapper *parent)
{
this->parent = shared_ptr(parent);
auto transformJson = json.value("transform").toObject();
- property.offset = { transformJson.value("offset").toObject().value("x").toDouble(), transformJson.value("offset").toObject().value("y").toDouble() };
- property.scale = { transformJson.value("scale").toObject().value("x").toDouble(), transformJson.value("scale").toObject().value("y").toDouble() };
- property.rotation = { transformJson.value("rotation").toDouble()};
+ property.name = json.value("name").toString();
+ property.offset = {transformJson.value("offset").toObject().value("x").toDouble(),
+ transformJson.value("offset").toObject().value("y").toDouble()};
+ property.scale = {transformJson.value("scale").toObject().value("x").toDouble(),
+ transformJson.value("scale").toObject().value("y").toDouble()};
+ property.rotation = {transformJson.value("rotation").toDouble()};
+ qTreeItem = new QTreeWidgetItem();
+ qTreeItem->setText(0, property.name);
+ if (parent != nullptr)
+ parent->qTreeItem->addChild(qTreeItem);
+ qTreeItem->setData(0, Qt::UserRole, QVariant::fromValue(this));
}
FolderLayerWrapper::FolderLayerWrapper(QJsonObject json, ElementManager *elementManager, LayerWrapper *parent)
: LayerWrapper(json, parent)
{
- qDebug() << json.value("name").toString()<<" "<getPaintObject());
}
LayerWrapper::refresh();
@@ -113,3 +122,12 @@ void FolderLayerWrapper::removeAllChild()
{
children.clear();
}
+
+namespace LayerEvent
+{
+
+static void onDoubleClick(QTreeWidgetItem *qItem, LayerWrapper *layerWrapper)
+{
+}
+
+} // namespace LayerEvent
diff --git a/ArchitectureColoredPainting/src/Editor/LayerWrapper.h b/ArchitectureColoredPainting/src/Editor/LayerWrapper.h
index 0aefcc0..b36fb74 100644
--- a/ArchitectureColoredPainting/src/Editor/LayerWrapper.h
+++ b/ArchitectureColoredPainting/src/Editor/LayerWrapper.h
@@ -7,7 +7,9 @@
#include
#include
#include
+#include
#include
+#include
#include
#include
using std::shared_ptr;
@@ -19,6 +21,7 @@ class ElementManager;
class LayerWrapper
{
+
protected:
shared_ptr parent;
QPointF referencePoint;
@@ -26,6 +29,7 @@ class LayerWrapper
QPainterPath cache;
public:
+ QTreeWidgetItem *qTreeItem;
struct SimpleProperty
{
QString name = "";
@@ -42,6 +46,11 @@ class LayerWrapper
LayerWrapper *getParent() const; // invoke by manager, then invoke parent's applyStyles
LayerWrapper(QJsonObject json, LayerWrapper *parent);
LayerWrapper() = default;
+ // TODO : export Function
+ // virtual LayerWrapper *addChild() = 0; // Leaf Child Only
+ // virtual LayerWrapper *addParent() = 0; // Folder Parent Only
+ // virtual void deleteSelf() const = 0;
+ // virtual void deleteAll() const = 0;
};
class FolderLayerWrapper : public LayerWrapper
@@ -68,3 +77,5 @@ class LeafLayerWrapper : public LayerWrapper
LeafLayerWrapper() = default;
LeafLayerWrapper(QJsonObject json, ElementManager *elementManager, LayerWrapper *parent);
};
+
+Q_DECLARE_METATYPE(LayerWrapper *)
diff --git a/ArchitectureColoredPainting/src/Editor/RightBar/InfoDisplayWidget.h b/ArchitectureColoredPainting/src/Editor/RightBar/InfoDisplayWidget.h
new file mode 100644
index 0000000..6f70f09
--- /dev/null
+++ b/ArchitectureColoredPainting/src/Editor/RightBar/InfoDisplayWidget.h
@@ -0,0 +1 @@
+#pragma once
diff --git a/ArchitectureColoredPainting/src/Editor/RightBar/LayerTreeWidget.cpp b/ArchitectureColoredPainting/src/Editor/RightBar/LayerTreeWidget.cpp
new file mode 100644
index 0000000..13137c5
--- /dev/null
+++ b/ArchitectureColoredPainting/src/Editor/RightBar/LayerTreeWidget.cpp
@@ -0,0 +1,53 @@
+#include "LayerTreeWidget.h"
+#include
+#include
+LayerTreeWidget::LayerTreeWidget(QWidget *parent)
+{
+ this->selectedItem = nullptr;
+ this->copiedItem = nullptr;
+ this->setContextMenuPolicy(Qt::CustomContextMenu);
+ this->setHeaderLabel("Layer Content");
+ connect(this, &QTreeWidget::customContextMenuRequested, this, &LayerTreeWidget::popMenu);
+ // connect(this, &QTreeWidget::itemDoubleClicked, this, &LayerTreeWidget::onItemDoubleClicked);
+}
+
+// void LayerTreeWidget::mouseDoubleClickEvent(QMouseEvent *event)
+//{
+// // stay empty to avoid the default behavior
+// }
+//
+// void LayerTreeWidget::onItemDoubleClicked(QTreeWidgetItem *item, int column)
+//{
+// this->selectedItem = item;
+// // TODO
+// }
+
+void LayerTreeWidget::popMenu(const QPoint &pos)
+{
+ QMenu menu;
+ QTreeWidgetItem *item = itemAt(pos);
+ this->selectedItem = item;
+ // TODO
+ menu.addAction("Add Child", this, &LayerTreeWidget::onRenameEvent);
+ menu.addAction("Rename", this, &LayerTreeWidget::onRenameEvent);
+ menu.addAction("Copy", this, &LayerTreeWidget::onRenameEvent);
+ if (item != nullptr && item->childCount() > 0)
+ menu.addAction("Delete (Self Only)", this, &LayerTreeWidget::onRenameEvent);
+ menu.addAction("Delete", this, &LayerTreeWidget::onRenameEvent);
+ menu.exec(mapToGlobal(pos));
+}
+
+void LayerTreeWidget::onRenameEvent()
+{
+ if (this->selectedItem == nullptr)
+ return;
+ qDebug() << this->selectedItem->data(0, Qt::UserRole).value()->property.name;
+ bool bOk = false;
+ QString sName =
+ QInputDialog::getText(this, "Rename", "New Name:", QLineEdit::Normal, this->selectedItem->text(0), &bOk);
+ if (bOk && !sName.isEmpty())
+ {
+ this->selectedItem->setText(0, sName);
+ this->selectedItem->data(0, Qt::UserRole).value()->property.name = sName;
+ }
+}
diff --git a/ArchitectureColoredPainting/src/Editor/RightBar/LayerTreeWidget.h b/ArchitectureColoredPainting/src/Editor/RightBar/LayerTreeWidget.h
new file mode 100644
index 0000000..cf6359a
--- /dev/null
+++ b/ArchitectureColoredPainting/src/Editor/RightBar/LayerTreeWidget.h
@@ -0,0 +1,18 @@
+#pragma once
+#include "LayerWrapper.h"
+#include
+#include
+class LayerTreeWidget : public QTreeWidget
+{
+ Q_OBJECT
+ private:
+ QTreeWidgetItem *selectedItem;
+ LayerWrapper *copiedItem;
+
+ public:
+ LayerTreeWidget(QWidget *parent = nullptr);
+ void onRenameEvent();
+ void popMenu(const QPoint &pos);
+ // void mouseDoubleClickEvent(QMouseEvent *event) override;
+ // void onItemDoubleClicked(QTreeWidgetItem *item, int column = 0);
+};