From b944572204b614587d868bb7ad6ff17ba9c03c79 Mon Sep 17 00:00:00 2001 From: karlis <2995621482@qq.com> Date: Mon, 20 Mar 2023 21:12:23 +0800 Subject: [PATCH 1/3] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E9=A1=B9=E7=9B=AE?= =?UTF-8?q?=E4=BF=A1=E6=81=AF=E7=AE=A1=E7=90=86=E5=99=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ArchitectureColoredPainting.vcxproj | 2 + ...rchitectureColoredPainting.vcxproj.filters | 6 +++ .../Editor/DataManager/ProjectDataManager.cpp | 38 +++++++++++++++++++ .../Editor/DataManager/ProjectDataManager.h | 30 +++++++++++++++ .../src/Editor/EditorWidgetItem.cpp | 11 +++++- .../src/Editor/EditorWidgetItem.h | 2 +- .../src/Editor/PreviewWindow.cpp | 21 ++++++++++ .../src/Editor/PreviewWindow.h | 9 +++++ 8 files changed, 117 insertions(+), 2 deletions(-) create mode 100644 ArchitectureColoredPainting/src/Editor/DataManager/ProjectDataManager.cpp create mode 100644 ArchitectureColoredPainting/src/Editor/DataManager/ProjectDataManager.h diff --git a/ArchitectureColoredPainting/ArchitectureColoredPainting.vcxproj b/ArchitectureColoredPainting/ArchitectureColoredPainting.vcxproj index 7414c08..4041213 100644 --- a/ArchitectureColoredPainting/ArchitectureColoredPainting.vcxproj +++ b/ArchitectureColoredPainting/ArchitectureColoredPainting.vcxproj @@ -104,6 +104,7 @@ + @@ -202,6 +203,7 @@ + diff --git a/ArchitectureColoredPainting/ArchitectureColoredPainting.vcxproj.filters b/ArchitectureColoredPainting/ArchitectureColoredPainting.vcxproj.filters index 835a354..b43e857 100644 --- a/ArchitectureColoredPainting/ArchitectureColoredPainting.vcxproj.filters +++ b/ArchitectureColoredPainting/ArchitectureColoredPainting.vcxproj.filters @@ -258,6 +258,9 @@ Source Files + + Source Files + @@ -522,6 +525,9 @@ Header Files + + Header Files + diff --git a/ArchitectureColoredPainting/src/Editor/DataManager/ProjectDataManager.cpp b/ArchitectureColoredPainting/src/Editor/DataManager/ProjectDataManager.cpp new file mode 100644 index 0000000..1bddf5a --- /dev/null +++ b/ArchitectureColoredPainting/src/Editor/DataManager/ProjectDataManager.cpp @@ -0,0 +1,38 @@ +#include "ProjectDataManager.h" + +using namespace std; + +ProjectDataManager* ProjectDataManager::instance = nullptr; + +ProjectDataManager* ProjectDataManager::Instance() +{ + if (instance == nullptr) + instance = new ProjectDataManager(); + return instance; +} + +void ProjectDataManager::addProjectData(ProjectData data) +{ + projectDataList.push_back(data); +} + +void ProjectDataManager::setZoom(double x, double y, EditorWidgetItem* item) +{ + for (auto& data : projectDataList) { + if (data.item == item) { + data.zoomX = x; + data.zoomY = y; + return; + } + } +} + +QPointF ProjectDataManager::getZoomByPainterDeivce(QPaintDevice* device) +{ + for (auto& data : projectDataList) { + if (data.item->previewWindow == device) { + return QPointF(data.zoomX, data.zoomY); + } + } + return QPointF(1, 1); +} diff --git a/ArchitectureColoredPainting/src/Editor/DataManager/ProjectDataManager.h b/ArchitectureColoredPainting/src/Editor/DataManager/ProjectDataManager.h new file mode 100644 index 0000000..8c5ffbf --- /dev/null +++ b/ArchitectureColoredPainting/src/Editor/DataManager/ProjectDataManager.h @@ -0,0 +1,30 @@ +#pragma once +#include +#include +#include +#include +#include "EditorWidgetItem.h" + +struct ProjectData +{ + int width, height; + double zoomX, zoomY; + QString fileHome; + EditorWidgetItem* item; +}; + +class ProjectDataManager +{ +private: + std::vector projectDataList; + ProjectDataManager() = default; + ~ProjectDataManager() = default; + static ProjectDataManager* instance; + +public: + static ProjectDataManager* Instance(); + void addProjectData(ProjectData data); + void setZoom(double x, double y, EditorWidgetItem* item); + QPointF getZoomByPainterDeivce(QPaintDevice* device); +}; + diff --git a/ArchitectureColoredPainting/src/Editor/EditorWidgetItem.cpp b/ArchitectureColoredPainting/src/Editor/EditorWidgetItem.cpp index 2693b45..2f5b1e6 100644 --- a/ArchitectureColoredPainting/src/Editor/EditorWidgetItem.cpp +++ b/ArchitectureColoredPainting/src/Editor/EditorWidgetItem.cpp @@ -1,6 +1,8 @@ #include "EditorWidgetItem.h" #include "EditorWidget.h" +#include "DataManager/ProjectDataManager.h" #include +#include EditorWidgetItem::EditorWidgetItem(QString filePath,QWidget *parent) : QWidget(parent) { @@ -54,6 +56,14 @@ EditorWidgetItem::EditorWidgetItem(QString filePath,QWidget *parent) : QWidget(p QJsonDocument jsonDoc(QJsonDocument::fromJson(setting, &jError)); qDebug() << jsonDoc.object().value("height").toDouble(); qDebug() << jError.errorString(); + ProjectData data; + data.fileHome = QFileInfo(filePath).absolutePath(); + data.width = jsonDoc.object().value("height").toInt(); + data.height = jsonDoc.object().value("width").toInt(); + data.zoomX = 1.0; + data.zoomY = 1.0; + data.item = this; + ProjectDataManager::Instance()->addProjectData(data); // end test QJsonObject source = jsonDoc.object(); elementManager = new ElementManager(source,Renderer::ElementRenderer::instance()); @@ -79,7 +89,6 @@ EditorWidgetItem::EditorWidgetItem(QString filePath,QWidget *parent) : QWidget(p handleProjectNameChange(this->projectName); centralRefresh(); }); - } EditorWidgetItem::~EditorWidgetItem() diff --git a/ArchitectureColoredPainting/src/Editor/EditorWidgetItem.h b/ArchitectureColoredPainting/src/Editor/EditorWidgetItem.h index 409374a..d718423 100644 --- a/ArchitectureColoredPainting/src/Editor/EditorWidgetItem.h +++ b/ArchitectureColoredPainting/src/Editor/EditorWidgetItem.h @@ -16,7 +16,7 @@ class EditorWidgetItem : public QWidget { Q_OBJECT - private: + public: // DATA PART PreviewWindow *previewWindow; ElementManager *elementManager; diff --git a/ArchitectureColoredPainting/src/Editor/PreviewWindow.cpp b/ArchitectureColoredPainting/src/Editor/PreviewWindow.cpp index 410b8af..7745de2 100644 --- a/ArchitectureColoredPainting/src/Editor/PreviewWindow.cpp +++ b/ArchitectureColoredPainting/src/Editor/PreviewWindow.cpp @@ -14,6 +14,7 @@ PreviewWindow::PreviewWindow(QWidget *parent) : QOpenGLWidget(parent) painter->setRenderHint(QPainter::HighQualityAntialiasing); layerManager = nullptr; currentLayer = nullptr; + zoomStep = 0; backgroundColor = QColor(255, 255, 255, 255); } @@ -21,6 +22,7 @@ void PreviewWindow::initialize(LayerManager *layerManager,QSize windowSize) { this->logicalSize = windowSize; this->layerManager = layerManager; + this->setFixedSize(windowSize); } void PreviewWindow::show() @@ -49,6 +51,7 @@ void PreviewWindow::paintGL() glClearColor(backgroundColor.redF(), backgroundColor.greenF(), backgroundColor.blueF(), backgroundColor.alphaF()); glClear(GL_COLOR_BUFFER_BIT); painter->begin(this); + painter->setWindow(0, 0, logicalSize.width(), logicalSize.height()); painter->setRenderHint(QPainter::Antialiasing); painter->setRenderHint(QPainter::HighQualityAntialiasing); layerManager->paint(painter,this->size(),currentLayer); @@ -129,4 +132,22 @@ void PreviewWindow::setBackgroundColor(QColor color) { this->backgroundColor = color; this->repaint(); +} + +void PreviewWindow::wheelEvent(QWheelEvent* event) +{ + if (QApplication::keyboardModifiers() == Qt::ControlModifier) + { + if (event->delta() > 0 && zoomStep < ZOOM_STEP_MAX) + { + zoomStep++; + this->setFixedSize(logicalSize * (1 + zoomStep * ZOOM_RATE)); + } + else if(event->delta() < 0 && zoomStep > ZOOM_STEP_MIN) + { + zoomStep--; + this->setFixedSize(logicalSize * (1 + zoomStep * ZOOM_RATE)); + } + this->repaint(); + } } \ No newline at end of file diff --git a/ArchitectureColoredPainting/src/Editor/PreviewWindow.h b/ArchitectureColoredPainting/src/Editor/PreviewWindow.h index 4fd002d..1d7761a 100644 --- a/ArchitectureColoredPainting/src/Editor/PreviewWindow.h +++ b/ArchitectureColoredPainting/src/Editor/PreviewWindow.h @@ -16,6 +16,14 @@ class PreviewWindow : public QOpenGLWidget, protected QOpenGLFunctions Q_OBJECT private: + constexpr static double ZOOM_RATE = 0.25; + constexpr static double ZOOM_DEFAULT = 1.0; + constexpr static int ZOOM_STEP_MIN = -2; + constexpr static int ZOOM_STEP_MAX = 4; + + + private: + int zoomStep; QPainter *painter; LayerManager *layerManager; Renderer::ElementRenderer* renderer; @@ -27,6 +35,7 @@ class PreviewWindow : public QOpenGLWidget, protected QOpenGLFunctions void mousePressEvent(QMouseEvent* event) override; void mouseMoveEvent(QMouseEvent* event) override; void mouseReleaseEvent(QMouseEvent* event) override; + void wheelEvent(QWheelEvent* event) override; public: PreviewWindow(QWidget *parent = nullptr); From a07bf3bcedf189c5506c74e859186804c53c4918 Mon Sep 17 00:00:00 2001 From: wuyize Date: Mon, 20 Mar 2023 21:49:02 +0800 Subject: [PATCH 2/3] =?UTF-8?q?=E4=BC=98=E5=8C=96=E5=8C=85=E5=9B=B4?= =?UTF-8?q?=E7=9B=92=E8=AE=A1=E7=AE=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 4_L0.json | 424 ++++++++++++++++++ .../res/Shaders/painting.comp | 2 +- .../src/Editor/util/PaintingUtil.cpp | 5 +- .../src/Editor/util/PaintingUtil.h | 2 +- svg/4_L0-fill.svg | 12 + test.json | 4 +- 6 files changed, 442 insertions(+), 7 deletions(-) create mode 100644 4_L0.json create mode 100644 svg/4_L0-fill.svg diff --git a/4_L0.json b/4_L0.json new file mode 100644 index 0000000..2465bb6 --- /dev/null +++ b/4_L0.json @@ -0,0 +1,424 @@ +{ + "background-color": "#b7a386", + "elements": [ + { + "data": { + "include": "../svg/2.svg" + }, + "name": "ababa", + "type": "svg-file" + }, + { + "data": { + "reference-layer": "0.0" + }, + "name": "ababa-group", + "type": "group" + }, + { + "data": { + "include": "../svg/0.svg" + }, + "name": "ababa2", + "type": "svg-file" + }, + { + "data": { + "include": "D:/BigC2022/temp/ArchitectureColoredPainting/svg/4_L0-fill.svg" + }, + "name": "4_L0-fill.svg", + "type": "svg-file" + } + ], + "height": 1080, + "project-name": "样例1", + "root-layer": { + "children": [ + { + "children": [ + { + "element": 3, + "is-folder": false, + "name": "4_L0", + "styles": [ + { + "material": "AH8A/2pkiv8=", + "type": "fill" + }, + { + "enableEachSideIndependent": true, + "left": "AADAQAEAJJwAf///9dKG/w==", + "right": "AADgQAAACpw=", + "type": "stroke" + } + ], + "transform": { + "offset": { + "x": -230, + "y": -533 + }, + "rotation": 0, + "scale": { + "x": 0.32341007644113307, + "y": 0.32341007644113307 + } + } + } + ], + "is-folder": true, + "name": "GroupFolderExample", + "referenced-by": 1, + "transform": { + "offset": { + "x": 50, + "y": 50 + }, + "rotation": 0, + "scale": { + "x": 1, + "y": 1 + } + } + }, + { + "element": 1, + "is-folder": false, + "name": "aaaa2", + "styles": [ + ], + "transform": { + "offset": { + "x": 127, + "y": -109 + }, + "rotation": 90, + "scale": { + "x": 1, + "y": 1 + } + } + }, + { + "element": 1, + "is-folder": false, + "name": "aaaa3", + "styles": [ + ], + "transform": { + "offset": { + "x": 232, + "y": 17 + }, + "rotation": 180, + "scale": { + "x": 1, + "y": 1 + } + } + }, + { + "element": 1, + "is-folder": false, + "name": "aaaa4", + "styles": [ + ], + "transform": { + "offset": { + "x": 103, + "y": 130 + }, + "rotation": 270, + "scale": { + "x": 1, + "y": 1 + } + } + }, + { + "element": 1, + "is-folder": false, + "name": "bbbb1", + "styles": [ + ], + "transform": { + "offset": { + "x": 197, + "y": 265 + }, + "rotation": 0, + "scale": { + "x": 1, + "y": 1 + } + } + }, + { + "element": 1, + "is-folder": false, + "name": "bbbb2", + "styles": [ + ], + "transform": { + "offset": { + "x": 323, + "y": 156 + }, + "rotation": 90, + "scale": { + "x": 1, + "y": 1 + } + } + }, + { + "element": 1, + "is-folder": false, + "name": "bbbb3", + "styles": [ + ], + "transform": { + "offset": { + "x": 432, + "y": 285 + }, + "rotation": 180, + "scale": { + "x": 1, + "y": 1 + } + } + }, + { + "element": 1, + "is-folder": false, + "name": "bbbb4", + "styles": [ + ], + "transform": { + "offset": { + "x": 302, + "y": 399 + }, + "rotation": 270, + "scale": { + "x": 1, + "y": 1 + } + } + }, + { + "element": 1, + "is-folder": false, + "name": "cccc1", + "styles": [ + ], + "transform": { + "offset": { + "x": 467, + "y": 71 + }, + "rotation": 0, + "scale": { + "x": 1, + "y": 1 + } + } + }, + { + "element": 1, + "is-folder": false, + "name": "cccc2", + "styles": [ + ], + "transform": { + "offset": { + "x": 361, + "y": -70 + }, + "rotation": 90, + "scale": { + "x": 1, + "y": 1 + } + } + }, + { + "element": 1, + "is-folder": false, + "name": "cccc3", + "styles": [ + ], + "transform": { + "offset": { + "x": 273, + "y": -211 + }, + "rotation": 180, + "scale": { + "x": 1, + "y": 1 + } + } + }, + { + "element": 1, + "is-folder": false, + "name": "cccc4", + "styles": [ + ], + "transform": { + "offset": { + "x": 574, + "y": 198 + }, + "rotation": 270, + "scale": { + "x": 1, + "y": 1 + } + } + }, + { + "element": 1, + "is-folder": false, + "name": "dddd1", + "styles": [ + ], + "transform": { + "offset": { + "x": 33, + "y": -231 + }, + "rotation": 0, + "scale": { + "x": 1, + "y": 1 + } + } + }, + { + "element": 1, + "is-folder": false, + "name": "dddd2", + "styles": [ + ], + "transform": { + "offset": { + "x": 55, + "y": 352 + }, + "rotation": 90, + "scale": { + "x": 1, + "y": 1 + } + } + }, + { + "element": 1, + "is-folder": false, + "name": "dddd3", + "styles": [ + ], + "transform": { + "offset": { + "x": -40, + "y": 220 + }, + "rotation": 180, + "scale": { + "x": 1, + "y": 1 + } + } + }, + { + "element": 1, + "is-folder": false, + "name": "dddd4", + "styles": [ + ], + "transform": { + "offset": { + "x": 0, + "y": 0 + }, + "rotation": 0, + "scale": { + "x": 1, + "y": 1 + } + } + }, + { + "element": 1, + "is-folder": false, + "name": "eeee1", + "styles": [ + ], + "transform": { + "offset": { + "x": 0, + "y": 0 + }, + "rotation": 0, + "scale": { + "x": 1, + "y": 1 + } + } + }, + { + "element": 1, + "is-folder": false, + "name": "eeee2", + "styles": [ + ], + "transform": { + "offset": { + "x": -149, + "y": 85 + }, + "rotation": 90, + "scale": { + "x": 1, + "y": 1 + } + } + }, + { + "element": 1, + "is-folder": false, + "name": "eeee3", + "styles": [ + ], + "transform": { + "offset": { + "x": 166, + "y": 482 + }, + "rotation": 180, + "scale": { + "x": 1, + "y": 1 + } + } + } + ], + "is-folder": true, + "name": "root", + "referenced-by": null, + "transform": { + "offset": { + "x": 8, + "y": 20 + }, + "rotation": 0, + "scale": { + "x": 1.7159367435419115, + "y": 1.7159367435419115 + } + } + }, + "width": 1080 +} diff --git a/ArchitectureColoredPainting/res/Shaders/painting.comp b/ArchitectureColoredPainting/res/Shaders/painting.comp index 6e166cf..324e093 100644 --- a/ArchitectureColoredPainting/res/Shaders/painting.comp +++ b/ArchitectureColoredPainting/res/Shaders/painting.comp @@ -1409,7 +1409,7 @@ void main() imageStore(gBaseColor, pixelLocation, vec4(color.rgb, 1)); imageStore(gMetallicRoughness, pixelLocation, vec4(metallicRoughness, 0, 1)); - //return; + return; if (/*color.a!=-1&&*/ debugBVH == vec3(0)) { // imageStore(gBaseColor, pixelLocation, vec4(vec3(1, 1, 0),1)); diff --git a/ArchitectureColoredPainting/src/Editor/util/PaintingUtil.cpp b/ArchitectureColoredPainting/src/Editor/util/PaintingUtil.cpp index aa23ce6..c6b7b55 100644 --- a/ArchitectureColoredPainting/src/Editor/util/PaintingUtil.cpp +++ b/ArchitectureColoredPainting/src/Editor/util/PaintingUtil.cpp @@ -14,8 +14,6 @@ using std::make_shared; using std::min; using std::queue; -const double PaintingUtil::pi = acos(-1); - struct LayerNode { LayerWrapper* nowLayer; QTransform transfrom; @@ -109,8 +107,9 @@ FolderLayerWrapper* PaintingUtil::handleLayerWrapper(LayerWrapper* nowLayer, QTr qDebug() << material->halfWidth; } QPainterPathStroker stroker; - stroker.setWidth(lineWidth); + stroker.setWidth(lineWidth * 2); stroker.setCapStyle(Qt::RoundCap); + stroker.setJoinStyle(Qt::RoundJoin); QPainterPath strokePath = stroker.createStroke(painterPath); auto rect = transform.map(strokePath).boundingRect(); elementTransform.bound = glm::vec4(rect.x(), rect.y(), rect.x() + rect.width(), rect.y() + rect.height()); diff --git a/ArchitectureColoredPainting/src/Editor/util/PaintingUtil.h b/ArchitectureColoredPainting/src/Editor/util/PaintingUtil.h index 850bfc0..332a0a4 100644 --- a/ArchitectureColoredPainting/src/Editor/util/PaintingUtil.h +++ b/ArchitectureColoredPainting/src/Editor/util/PaintingUtil.h @@ -5,7 +5,7 @@ class PaintingUtil { private: - static const double pi; + //static const double pi; static QJsonObject readJsonFile(QString jsonFilePath); static FolderLayerWrapper* handleLayerWrapper(LayerWrapper* nowLayer, QTransform& transform, Renderer::Painting& painting); //static double getMaxLineWidth(LayerWrapper* root); diff --git a/svg/4_L0-fill.svg b/svg/4_L0-fill.svg new file mode 100644 index 0000000..7248976 --- /dev/null +++ b/svg/4_L0-fill.svg @@ -0,0 +1,12 @@ + + + + + + diff --git a/test.json b/test.json index ce11428..c5158fb 100644 --- a/test.json +++ b/test.json @@ -59,9 +59,9 @@ "name": "Leaf2", "styles": [ { - "enableEachSideIndependent": true, + "enableEachSideIndependent": false, "left": "AAAAQAEAIZwAf////1UA/w==", - "right": "AADgQAAACJw=", + "right": "AADgQAEACJwAf///AFqe/w==", "type": "stroke" } ], From 769effe49cd819435d7506f04ba46e00521e4929 Mon Sep 17 00:00:00 2001 From: karlis <2995621482@qq.com> Date: Mon, 20 Mar 2023 22:26:38 +0800 Subject: [PATCH 3/3] =?UTF-8?q?FIX:=20=E4=BF=AE=E6=AD=A3=E6=96=87=E4=BB=B6?= =?UTF-8?q?=E8=B7=AF=E5=BE=84=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/Editor/EditorWidgetItem.cpp | 21 ++++++++++++++++++- .../src/Editor/ElementManager.cpp | 16 +++++++++----- .../src/Editor/ElementManager.h | 3 ++- .../src/Editor/GraphicElement.cpp | 8 ++++--- .../src/Editor/GraphicElement.h | 2 +- .../src/Editor/LayerWrapper.cpp | 7 ++++--- .../src/Editor/RightBar/LayerTreeWidget.cpp | 1 + .../src/Editor/util/PaintingUtil.cpp | 3 ++- data.json | 4 ++-- 9 files changed, 48 insertions(+), 17 deletions(-) diff --git a/ArchitectureColoredPainting/src/Editor/EditorWidgetItem.cpp b/ArchitectureColoredPainting/src/Editor/EditorWidgetItem.cpp index 2f5b1e6..529d648 100644 --- a/ArchitectureColoredPainting/src/Editor/EditorWidgetItem.cpp +++ b/ArchitectureColoredPainting/src/Editor/EditorWidgetItem.cpp @@ -3,6 +3,8 @@ #include "DataManager/ProjectDataManager.h" #include #include +#include +#include EditorWidgetItem::EditorWidgetItem(QString filePath,QWidget *parent) : QWidget(parent) { @@ -66,7 +68,7 @@ EditorWidgetItem::EditorWidgetItem(QString filePath,QWidget *parent) : QWidget(p ProjectDataManager::Instance()->addProjectData(data); // end test QJsonObject source = jsonDoc.object(); - elementManager = new ElementManager(source,Renderer::ElementRenderer::instance()); + elementManager = new ElementManager(source, QFileInfo(filePath).absolutePath()); layerManager = new LayerManager(source, elementManager); elementInfoDisplayWidget->setElementManager(elementManager); treeWidget->elementManager = elementManager; @@ -125,6 +127,23 @@ void EditorWidgetItem::save() const void EditorWidgetItem::saveAs(QString filePath) const { saveImpl(filePath); + QString srcHome = QFileInfo(this->filePath).absolutePath(); + if (!QDir(QFileInfo(filePath).absolutePath() + "/svg").exists()) + { + QDir().mkdir(QFileInfo(filePath).absolutePath() + "/svg"); + } + for (auto& ele : elementManager->elements) + { + auto e = dynamic_cast(ele); + if (e != nullptr) + { + QString fileName = e->jsonSource["data"].toObject()["include"].toString(); + QString src = srcHome + fileName; + QString dst = QFileInfo(filePath).absolutePath() + fileName; + QFile::copy(src, dst); + } + } + } void EditorWidgetItem::saveImpl(QString filePath) const diff --git a/ArchitectureColoredPainting/src/Editor/ElementManager.cpp b/ArchitectureColoredPainting/src/Editor/ElementManager.cpp index b711794..2f601aa 100644 --- a/ArchitectureColoredPainting/src/Editor/ElementManager.cpp +++ b/ArchitectureColoredPainting/src/Editor/ElementManager.cpp @@ -1,16 +1,20 @@ #include "ElementManager.h" -ElementManager::ElementManager(QJsonObject source,Renderer::ElementRenderer* renderer) +#include +#include +#include + +ElementManager::ElementManager(QJsonObject source, QString fileHome) { auto elementsJson = source.value("elements").toArray(); + this->fileHome = fileHome; int index = 0; for (auto elementJson : elementsJson) { if (elementJson.toObject().value("type").toString() == "group") elements.push_back(new GroupElement()); else - elements.push_back(new SimpleElement(elementJson.toObject())); + elements.push_back(new SimpleElement(elementJson.toObject(), fileHome)); (*elements.rbegin())->name = elementJson.toObject().value("name").toString(); - (*elements.rbegin())->renderer = renderer; } for (auto element : elements) element->index = index++; @@ -90,9 +94,11 @@ void ElementManager::createGroupElement(QString name, FolderLayerWrapper* source void ElementManager::createSimpleElement(QString name, QString filePath) { QJsonObject json; QJsonObject data; - data.insert("include", filePath); + QFile fileSrc(filePath); + QFile::copy(filePath, QDir::cleanPath(fileHome + "/svg/" + QFileInfo(filePath).fileName())); + data.insert("include", "/svg/"+QFileInfo(filePath).fileName()); json.insert("data", data); - auto element = new SimpleElement(json); + auto element = new SimpleElement(json, fileHome); element->name = name; addElement(element); } \ No newline at end of file diff --git a/ArchitectureColoredPainting/src/Editor/ElementManager.h b/ArchitectureColoredPainting/src/Editor/ElementManager.h index 6c48feb..7cb3839 100644 --- a/ArchitectureColoredPainting/src/Editor/ElementManager.h +++ b/ArchitectureColoredPainting/src/Editor/ElementManager.h @@ -14,9 +14,10 @@ class ElementManager { public: vector elements; + QString fileHome; public: - ElementManager(QJsonObject source,Renderer::ElementRenderer *renderer); + ElementManager(QJsonObject source, QString fileHome); ~ElementManager(); void addElement(GraphicElement *element); void removeElement(GraphicElement *pElement); diff --git a/ArchitectureColoredPainting/src/Editor/GraphicElement.cpp b/ArchitectureColoredPainting/src/Editor/GraphicElement.cpp index 01f6df5..16a7bc8 100644 --- a/ArchitectureColoredPainting/src/Editor/GraphicElement.cpp +++ b/ArchitectureColoredPainting/src/Editor/GraphicElement.cpp @@ -2,6 +2,8 @@ #include "util/SvgFileLoader.h" #include #include +#include + using namespace std; PixelPath SimpleElement::getPaintObject() const @@ -23,13 +25,13 @@ void SimpleElement::loadSvgFile(const QString& filePath) qDebug() << "load svg file success " << painterPath.elementCount() << (isClosed() ? "is" : "not") << "closed"; } -SimpleElement::SimpleElement(QJsonObject jsonSource) : jsonSource(jsonSource) +SimpleElement::SimpleElement(QJsonObject jsonSource, QString fileHome) : jsonSource(jsonSource) { painterPath.clear(); filePath = jsonSource["data"].toObject()["include"].toString(); //loadSvgFile("D:\\Projects\\BigC\\svg\\3.svg"); - QFileInfo info(filePath); - loadSvgFile(filePath); + QFileInfo info(QDir::cleanPath(fileHome + "/" + filePath)); + loadSvgFile(info.absoluteFilePath()); } GroupElement::GroupElement(FolderLayerWrapper* sourceLayer) diff --git a/ArchitectureColoredPainting/src/Editor/GraphicElement.h b/ArchitectureColoredPainting/src/Editor/GraphicElement.h index 8ce9bf2..7415dcc 100644 --- a/ArchitectureColoredPainting/src/Editor/GraphicElement.h +++ b/ArchitectureColoredPainting/src/Editor/GraphicElement.h @@ -46,7 +46,7 @@ public: public: QJsonObject toJson() const override; - SimpleElement(QJsonObject jsonSource); + SimpleElement(QJsonObject jsonSource, QString fileHome); SimpleElement(QString filePath); ~SimpleElement() = default; PixelPath getPaintObject() const override; diff --git a/ArchitectureColoredPainting/src/Editor/LayerWrapper.cpp b/ArchitectureColoredPainting/src/Editor/LayerWrapper.cpp index d2f1453..caf6dc8 100644 --- a/ArchitectureColoredPainting/src/Editor/LayerWrapper.cpp +++ b/ArchitectureColoredPainting/src/Editor/LayerWrapper.cpp @@ -75,7 +75,7 @@ FolderLayerWrapper::FolderLayerWrapper(QJsonObject json, ElementManager *element } LeafLayerWrapper::LeafLayerWrapper(QJsonObject json, ElementManager* elementManager, FolderLayerWrapper* parent) - : LayerWrapper(json, parent), + : LayerWrapper(json, parent, elementManager), wrappedElement(elementManager->getElementById(json.value("element").toInt())), styles(LayerStyleContainer::fromJson(wrappedElement->isClosed(), json.value("styles").toArray())) { @@ -255,7 +255,8 @@ QJsonObject FolderLayerWrapper::toJson() const QJsonObject json = LayerWrapper::toJson(); QJsonArray childrenJson; for (auto& child : children) - childrenJson.push_back(child->toJson()); + if(child != nullptr) + childrenJson.push_back(child->toJson()); json.insert("children", childrenJson); json.insert("is-folder", true); if(this->getReferencedBy() != -1) @@ -268,7 +269,7 @@ QJsonObject FolderLayerWrapper::toJson() const QJsonObject LeafLayerWrapper::toJson() const { QJsonObject json = LayerWrapper::toJson(); - json.insert("element", wrappedElement->index); + json.insert("element", elementManager->getElementIndex(wrappedElement)); json.insert("is-folder", false); json.insert("styles", styles.toJson()); return json; diff --git a/ArchitectureColoredPainting/src/Editor/RightBar/LayerTreeWidget.cpp b/ArchitectureColoredPainting/src/Editor/RightBar/LayerTreeWidget.cpp index 0c5857b..448c6f6 100644 --- a/ArchitectureColoredPainting/src/Editor/RightBar/LayerTreeWidget.cpp +++ b/ArchitectureColoredPainting/src/Editor/RightBar/LayerTreeWidget.cpp @@ -59,6 +59,7 @@ void LayerTreeWidget::popMenu(const QPoint &pos) connect(dialog, &LayerCreateWidget::LayerInfoReturned, this, [this, layer](QJsonObject jsonObj) { auto folderLayer = dynamic_cast(layer); LayerWrapper* newLayer; + qDebug() << this->elementManager; if(jsonObj.value("is-folder").toBool()) newLayer = new FolderLayerWrapper(jsonObj, this->elementManager, folderLayer); else diff --git a/ArchitectureColoredPainting/src/Editor/util/PaintingUtil.cpp b/ArchitectureColoredPainting/src/Editor/util/PaintingUtil.cpp index aa23ce6..f3db226 100644 --- a/ArchitectureColoredPainting/src/Editor/util/PaintingUtil.cpp +++ b/ArchitectureColoredPainting/src/Editor/util/PaintingUtil.cpp @@ -3,6 +3,7 @@ #include #include "PainterPathUtil.h" #include +#include using Renderer::Painting; using Renderer::BaseElement; @@ -37,7 +38,7 @@ Painting PaintingUtil::transfromToPainting(QString jsonFilePath) { glm::bvec2 flip(0, 0); QJsonObject jsonObj = readJsonFile(jsonFilePath); qDebug() << jsonObj; - shared_ptr elementManager = make_shared(jsonObj, Renderer::ElementRenderer::instance()); + shared_ptr elementManager = make_shared(jsonObj, QFileInfo(jsonFilePath).absolutePath()); shared_ptr layerManager = make_shared(jsonObj, elementManager.get()); //qDebug() << elementManager->toJson(); //qDebug() << layerManager->toJson(); diff --git a/data.json b/data.json index 93398a4..141180f 100644 --- a/data.json +++ b/data.json @@ -8,7 +8,7 @@ "name": "ababa", "type": "svg-file", "data": { - "include": "../svg/2.svg" + "include": "/svg/2.svg" } }, { @@ -22,7 +22,7 @@ "name": "ababa2", "type": "svg-file", "data": { - "include": "../svg/0.svg" + "include": "/svg/0.svg" } } ],