From 3a35d74fdaaef38c48324d6ef2928b2d6eb15557 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=99=BD=E5=B0=81=E7=BE=BD?= <2360164671@qq.com> Date: Thu, 12 Jan 2023 21:23:30 +0800 Subject: [PATCH] =?UTF-8?q?=E9=87=8D=E7=BD=AE=E4=BA=86=E6=A0=B7=E4=BE=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/Editor/ElementManager.cpp | 2 +- .../src/Editor/GraphicElement.cpp | 5 +- .../src/Editor/GraphicElement.h | 2 +- .../src/Editor/LayerWrapper.cpp | 22 +- .../src/Editor/LayerWrapper.h | 6 +- .../src/Editor/PreviewWindow.cpp | 2 +- data.json | 315 ++++-------------- 7 files changed, 85 insertions(+), 269 deletions(-) diff --git a/ArchitectureColoredPainting/src/Editor/ElementManager.cpp b/ArchitectureColoredPainting/src/Editor/ElementManager.cpp index ef5cfdc..63008cd 100644 --- a/ArchitectureColoredPainting/src/Editor/ElementManager.cpp +++ b/ArchitectureColoredPainting/src/Editor/ElementManager.cpp @@ -5,7 +5,7 @@ ElementManager::ElementManager(QJsonObject source) qDebug() << elementsJson.size(); for (auto elementJson : elementsJson) { - if (elementJson.toObject().value("type") == "group") + if (elementJson.toObject().value("type").toString() == "group") elements.push_back(new GroupElement()); else elements.push_back(new SimpleElement(elementJson.toObject())); diff --git a/ArchitectureColoredPainting/src/Editor/GraphicElement.cpp b/ArchitectureColoredPainting/src/Editor/GraphicElement.cpp index cdd8e42..33c7994 100644 --- a/ArchitectureColoredPainting/src/Editor/GraphicElement.cpp +++ b/ArchitectureColoredPainting/src/Editor/GraphicElement.cpp @@ -8,6 +8,7 @@ QPainterPath SimpleElement::getPaintObject() const void SimpleElement::loadSvgFile(const QString& filePath) { // TODO + painterPath.addRect(0, 0,100,100); } SimpleElement::SimpleElement(QJsonObject jsonSource) : jsonSource(jsonSource) @@ -26,8 +27,10 @@ void GroupElement::setSourceLayer(FolderLayerWrapper *sourceLayer) } QPainterPath GroupElement::getPaintObject() const { - if (sourceLayer != nullptr) + if (sourceLayer != nullptr) { + sourceLayer->refresh(); return sourceLayer->getCache(); + } else return QPainterPath(); } diff --git a/ArchitectureColoredPainting/src/Editor/GraphicElement.h b/ArchitectureColoredPainting/src/Editor/GraphicElement.h index b191304..a55327c 100644 --- a/ArchitectureColoredPainting/src/Editor/GraphicElement.h +++ b/ArchitectureColoredPainting/src/Editor/GraphicElement.h @@ -28,7 +28,7 @@ class SimpleElement : public GraphicElement }; class GroupElement : public GraphicElement { - private: + public: FolderLayerWrapper *sourceLayer; public: diff --git a/ArchitectureColoredPainting/src/Editor/LayerWrapper.cpp b/ArchitectureColoredPainting/src/Editor/LayerWrapper.cpp index d9f5336..96ea1af 100644 --- a/ArchitectureColoredPainting/src/Editor/LayerWrapper.cpp +++ b/ArchitectureColoredPainting/src/Editor/LayerWrapper.cpp @@ -32,14 +32,16 @@ QPainterPath LayerWrapper::getCache() LayerWrapper::LayerWrapper(QJsonObject json, LayerWrapper *parent) { this->parent = shared_ptr(parent); - auto offsetJson = json.value("offset").toObject(); - property.offset = {offsetJson.value("x").toDouble(), offsetJson.value("y").toDouble()}; + 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()}; } FolderLayerWrapper::FolderLayerWrapper(QJsonObject json, ElementManager *elementManager, LayerWrapper *parent) : LayerWrapper(json, parent) { - qDebug() << json.value("name").toString(); + qDebug() << json.value("name").toString()<<" "<getElementById(elementIndex); } void LayerWrapper::SimpleProperty::apply(QPainterPath &cache) const { QTransform trans; - trans.scale(zoom.x(), zoom.y()); + double delX = cache.boundingRect().width(); + double delY = cache.boundingRect().height(); + trans.translate(-delX,-delY); + trans.scale(scale.x(), scale.y()); trans.rotate(rotation); - trans.translate(offset.x(), offset.y()); + cache = trans.map(cache); + trans.reset(); + trans.translate(delX+offset.x(), delY+offset.y()); cache = trans.map(cache); // cache.translate(offset); } @@ -91,8 +98,9 @@ void FolderLayerWrapper::refresh() void LeafLayerWrapper::refresh() { cache.clear(); - if (wrappedElement != nullptr) + if (wrappedElement != nullptr) { cache.addPath(wrappedElement->getPaintObject()); + } LayerWrapper::refresh(); } diff --git a/ArchitectureColoredPainting/src/Editor/LayerWrapper.h b/ArchitectureColoredPainting/src/Editor/LayerWrapper.h index 826dbb6..0aefcc0 100644 --- a/ArchitectureColoredPainting/src/Editor/LayerWrapper.h +++ b/ArchitectureColoredPainting/src/Editor/LayerWrapper.h @@ -29,7 +29,7 @@ class LayerWrapper struct SimpleProperty { QString name = ""; - QPointF zoom = {1.0, 1.0}; + QPointF scale = {1.0, 1.0}; QPointF offset = {0, 0}; double rotation = 0; bool flipHorizontally = 0; @@ -46,7 +46,7 @@ class LayerWrapper class FolderLayerWrapper : public LayerWrapper { - private: + public: vector> children; public: @@ -60,7 +60,7 @@ class FolderLayerWrapper : public LayerWrapper class LeafLayerWrapper : public LayerWrapper { - private: + public: GraphicElement *wrappedElement; public: diff --git a/ArchitectureColoredPainting/src/Editor/PreviewWindow.cpp b/ArchitectureColoredPainting/src/Editor/PreviewWindow.cpp index 5c9dbd6..3b30cff 100644 --- a/ArchitectureColoredPainting/src/Editor/PreviewWindow.cpp +++ b/ArchitectureColoredPainting/src/Editor/PreviewWindow.cpp @@ -35,7 +35,7 @@ void PreviewWindow::initializeGL() initializeOpenGLFunctions(); glClearColor(1.0, 1.0, 1.0, 1.0); } -#include "./third-party modules/qquick/qquicksvgparser_p.h" + void PreviewWindow::paintGL() { glClear(GL_COLOR_BUFFER_BIT); diff --git a/data.json b/data.json index 364bcb6..b5abde9 100644 --- a/data.json +++ b/data.json @@ -3,127 +3,14 @@ "width": 1080, "elements": [ { - "type": "path", + "name": "ababa", + "type": "svg-file", "data": { - "operations": [ - { - "type": "line", - "data": { - "target": { - "x": 15, - "y": 20 - } - } - }, - { - "type": "cubic", - "data": { - "target": { - "x": 18, - "y": 21 - }, - "control": { - "start": { - "x": 17, - "y": 22 - }, - "end": { - "x": 20, - "y": 23 - } - } - } - }, - { - "type": "cubic-smooth", - "data": { - "target": { - "x": 18, - "y": 21 - }, - "control": { - "x": 18, - "y": 21 - } - } - }, - { - "type": "quadratic", - "data": { - "target": { - "x": 18, - "y": 21 - }, - "control": { - "x": 18, - "y": 21 - } - } - }, - { - "type": "quadratic-smooth", - "data": { - "target": { - "x": 18, - "y": 21 - } - } - }, - { - "type": "arc", - "data": { - "center": { - "x": 18, - "y": 21 - }, - "x-axis": 40, - "y-axis": 50, - "angle": 60 - } - }, - { - "type": "zeal" - } - ] - } - }, - { - "type": "polygon", - "data": { - "points": [ - { - "x": 0, - "y": 0 - }, - { - "x": 100, - "y": 200 - }, - { - "x": 300, - "y": 400 - }, - { - "x": 500, - "y": 600 - }, - { - "x": 0, - "y": 0 - } - ] - } - }, - { - "type": "round", - "data": { - "x-axis": 300, - "y-axis": 400, - "origin": 270, - "angle": 30 + "include": "./svg/ababa.svg" } }, { + "name": "ababa-group", "type": "group", "data": { "reference-layer": "0.0" @@ -132,172 +19,90 @@ ], "root-layer": { "name": "root", - "offset": { - "x": 0, - "y": 0 + "transform": { + "offset": { + "x": 0, + "y": 0 + }, + "scale": { + "x": 1.0, + "y": 1.0 + }, + "rotation": 0.0 }, - "transformation": [ - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0 - ], "effects": [], "is-folder": true, "referenced-by": null, "children": [ { "name": "GroupFolderExample", - "offset": { - "x": 5, - "y": 10 + "transform": { + "offset": { + "x": 50, + "y": 50 + }, + "scale": { + "x": 1.0, + "y": 1.0 + }, + "rotation": 0.0 }, - "transformation": [ - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0 - ], - "effects": [ - { - "type": "iterate", - "data": { - "time": 5, - "operations": [ - { - "type": "move", - "data": { - "offset": { - "x": 5, - "y": 6 - } - } - }, - { - "type": "rotate", - "data": { - "center-offset": { - "x": 0, - "y": 0 - }, - "angle": 60 - } - }, - { - "type": "zoom", - "data": { - "zoom": 1.5 - } - }, - { - "type": "flip", - "data": { - "k": 1.2, - "b": 3 - } - } - ] - } - } - ], + "effects": [], "is-folder": true, - "referenced-by": 3, + "referenced-by": 1, "children": [ { - "name": "GroupedLayer1", - "offset": { - "x": 10, - "y": 20 + "name": "Leaf1", + "transform": { + "offset": { + "x": 0, + "y": 0 + }, + "scale": { + "x": 1.0, + "y": 1.0 + }, + "rotation": 0.0 }, - "transformation": [ - 5, - 0, - 0, - 0, - 6, - 0, - 0, - 0, - 0 - ], "effects": [], "is-folder": false, "element": 0 }, { - "name": "GroupedLayer2", - "offset": { - "x": 15, - "y": 25 + "name": "Leaf2", + "transform": { + "offset": { + "x": 150, + "y": 0 + }, + "scale": { + "x": 1.5, + "y": 1.5 + }, + "rotation": 0.0 }, - "transformation": [ - 5, - 0, - 0, - 0, - 6, - 0, - 0, - 0, - 0 - ], "effects": [], "is-folder": false, - "element": 1 + "element": 0 } ] }, { "name": "ReferencingGroupLayer", - "offset": { - "x": 10, - "y": 20 + "transform": { + "offset": { + "x": 100, + "y": 0 + }, + "scale": { + "x": 1, + "y": 1 + }, + "rotation": 45 }, - "transformation": [ - 5, - 0, - 0, - 0, - 6, - 0, - 0, - 0, - 0 - ], "effects": [], "is-folder": false, - "element": 3 - }, - { - "name": "Layer1", - "offset": { - "x": 10, - "y": 20 - }, - "transformation": [ - 5, - 0, - 0, - 0, - 6, - 0, - 0, - 0, - 0 - ], - "effects": [], - "is-folder": false, - "element": 2 + "element": 1 } ] }