diff --git a/4_L0.json b/4_L0.json index 2465bb6..59a7b1f 100644 --- a/4_L0.json +++ b/4_L0.json @@ -1,33 +1,40 @@ { - "background-color": "#b7a386", + "background-color": "#ae9f86", "elements": [ { "data": { - "include": "../svg/2.svg" + "include": "/svg/2.svg" }, "name": "ababa", "type": "svg-file" }, { "data": { - "reference-layer": "0.0" - }, - "name": "ababa-group", - "type": "group" - }, - { - "data": { - "include": "../svg/0.svg" + "include": "/svg/0.svg" }, "name": "ababa2", "type": "svg-file" }, { "data": { - "include": "D:/BigC2022/temp/ArchitectureColoredPainting/svg/4_L0-fill.svg" + "include": "/svg/4_L0.svg" }, - "name": "4_L0-fill.svg", + "name": "4_L0.svg", "type": "svg-file" + }, + { + "data": { + "reference-layer": "0.0" + }, + "name": "图源工", + "type": "group" + }, + { + "data": { + "reference-layer": "0.0" + }, + "name": "图源万", + "type": "group" } ], "height": 1080, @@ -37,307 +44,109 @@ { "children": [ { - "element": 3, - "is-folder": false, - "name": "4_L0", - "styles": [ + "children": [ { - "material": "AH8A/2pkiv8=", - "type": "fill" - }, - { - "enableEachSideIndependent": true, - "left": "AADAQAEAJJwAf///9dKG/w==", - "right": "AADgQAAACpw=", - "type": "stroke" + "element": 2, + "is-folder": false, + "name": "4_L0", + "styles": [ + { + "material": "AH8A/1JOff8=", + "type": "fill" + }, + { + "enableEachSideIndependent": true, + "left": "AAAAQAEAJJwAf///9c19/w==", + "right": "AADgQAAACpw=", + "type": "stroke" + } + ], + "transform": { + "offset": { + "x": 0, + "y": 0 + }, + "rotation": 0, + "scale": { + "x": 1, + "y": 1 + } + } } ], + "is-folder": true, + "name": "工", + "referenced-by": 3, "transform": { "offset": { - "x": -230, - "y": -533 + "x": 0, + "y": 0 }, "rotation": 0, "scale": { - "x": 0.32341007644113307, - "y": 0.32341007644113307 + "x": 1, + "y": 1 + } + } + }, + { + "element": 3, + "is-folder": false, + "name": "1", + "styles": [ + ], + "transform": { + "offset": { + "x": 103, + "y": -1 + }, + "rotation": 90, + "scale": { + "x": 1, + "y": 1 + } + } + }, + { + "element": 3, + "is-folder": false, + "name": "2", + "styles": [ + ], + "transform": { + "offset": { + "x": 104, + "y": 100 + }, + "rotation": 0, + "scale": { + "x": 1, + "y": 1 + } + } + }, + { + "element": 3, + "is-folder": false, + "name": "3", + "styles": [ + ], + "transform": { + "offset": { + "x": 3, + "y": 102 + }, + "rotation": 90, + "scale": { + "x": 1, + "y": 1 } } } ], "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": [ - ], + "name": "子图层-1", + "referenced-by": 4, "transform": { "offset": { "x": 0, @@ -351,14 +160,14 @@ } }, { - "element": 1, + "element": 4, "is-folder": false, - "name": "eeee1", + "name": "子图层-2", "styles": [ ], "transform": { "offset": { - "x": 0, + "x": 204, "y": 0 }, "rotation": 0, @@ -369,17 +178,17 @@ } }, { - "element": 1, + "element": 4, "is-folder": false, - "name": "eeee2", + "name": "子图层-3", "styles": [ ], "transform": { "offset": { - "x": -149, - "y": 85 + "x": 3, + "y": 205 }, - "rotation": 90, + "rotation": 0, "scale": { "x": 1, "y": 1 @@ -387,17 +196,107 @@ } }, { - "element": 1, + "element": 4, "is-folder": false, - "name": "eeee3", + "name": "子图层-4", "styles": [ ], "transform": { "offset": { - "x": 166, - "y": 482 + "x": 207, + "y": 203 }, - "rotation": 180, + "rotation": 0, + "scale": { + "x": 1, + "y": 1 + } + } + }, + { + "element": 4, + "is-folder": false, + "name": "子图层-5", + "styles": [ + ], + "transform": { + "offset": { + "x": 407, + "y": -2 + }, + "rotation": 0, + "scale": { + "x": 1, + "y": 1 + } + } + }, + { + "element": 4, + "is-folder": false, + "name": "子图层-6", + "styles": [ + ], + "transform": { + "offset": { + "x": 411, + "y": 201 + }, + "rotation": 0, + "scale": { + "x": 1, + "y": 1 + } + } + }, + { + "element": 4, + "is-folder": false, + "name": "子图层-7", + "styles": [ + ], + "transform": { + "offset": { + "x": 6, + "y": 408 + }, + "rotation": 0, + "scale": { + "x": 1, + "y": 1 + } + } + }, + { + "element": 4, + "is-folder": false, + "name": "子图层-8", + "styles": [ + ], + "transform": { + "offset": { + "x": 210, + "y": 408 + }, + "rotation": 0, + "scale": { + "x": 1, + "y": 1 + } + } + }, + { + "element": 4, + "is-folder": false, + "name": "子图层-9", + "styles": [ + ], + "transform": { + "offset": { + "x": 414, + "y": 405 + }, + "rotation": 0, "scale": { "x": 1, "y": 1 @@ -410,13 +309,13 @@ "referenced-by": null, "transform": { "offset": { - "x": 8, - "y": 20 + "x": -9, + "y": -34 }, - "rotation": 0, + "rotation": 60, "scale": { - "x": 1.7159367435419115, - "y": 1.7159367435419115 + "x": 1, + "y": 1 } } }, diff --git a/ArchitectureColoredPainting/src/Editor/GraphicElement.cpp b/ArchitectureColoredPainting/src/Editor/GraphicElement.cpp index 16a7bc8..1f5f8ad 100644 --- a/ArchitectureColoredPainting/src/Editor/GraphicElement.cpp +++ b/ArchitectureColoredPainting/src/Editor/GraphicElement.cpp @@ -114,10 +114,22 @@ void SimpleElement::paint(QPainter* painter, QTransform transform, const LayerSt else maxScale = std::max(fabs(transform.m12() / sin(angle)), fabs(transform.m21() / sin(angle))); double pixelRatio = maxScale * QGuiApplication::primaryScreen()->devicePixelRatio(); - auto [img, mov] = Renderer::ElementRenderer::instance()->drawElement(painterPath, styles, pixelRatio); - transform.translate(mov.x(), mov.y()); - painter->setTransform(transform.scale(1 / pixelRatio, 1 / pixelRatio)); - painter->drawImage(0, 0, img); + if (painterPath == painterPathPrev && styles.getHash() == stylesHashValue) + { + transform.translate(movPrev.x(), movPrev.y()); + painter->setTransform(transform.scale(1 / pixelRatio, 1 / pixelRatio)); + painter->drawImage(0, 0, imagePrev); + } + else + { + auto [img, mov] = Renderer::ElementRenderer::instance()->drawElement(painterPath, styles, pixelRatio); + transform.translate(mov.x(), mov.y()); + painter->setTransform(transform.scale(1 / pixelRatio, 1 / pixelRatio)); + painter->drawImage(0, 0, img); + stylesHashValue = styles.getHash(); + painterPathPrev = painterPath; + } + } painter->restore(); } diff --git a/ArchitectureColoredPainting/src/Editor/GraphicElement.h b/ArchitectureColoredPainting/src/Editor/GraphicElement.h index 7415dcc..74368be 100644 --- a/ArchitectureColoredPainting/src/Editor/GraphicElement.h +++ b/ArchitectureColoredPainting/src/Editor/GraphicElement.h @@ -23,6 +23,10 @@ public: size_t referencedCount = 0; Renderer::ElementRenderer *renderer; QString name = ""; + size_t stylesHashValue; + QPainterPath painterPathPrev; + QPointF movPrev; + QImage imagePrev; int index; // TODO: ΪBitmapPath virtual QJsonObject toJson() const = 0; @@ -31,6 +35,7 @@ public: virtual void paint(QPainter* painter, QTransform transform, const LayerStyleContainer& styles) = 0; virtual bool isClosed() const = 0; virtual QPixmap getPreview(QSize size) = 0; + }; class SimpleElement : public GraphicElement diff --git a/svg/4_L0.svg b/svg/4_L0.svg index 58facaf..5947e66 100644 --- a/svg/4_L0.svg +++ b/svg/4_L0.svg @@ -1,5 +1,11 @@ - - 4_L0 - - + + + + +