Compare commits

..

2 Commits

Author SHA1 Message Date
白封羽 d5959ba8ad merge 2023-01-16 14:44:10 +08:00
白封羽 3a35d74fda 重置了样例 2023-01-12 21:23:30 +08:00
7 changed files with 83 additions and 269 deletions

View File

@ -5,7 +5,7 @@ ElementManager::ElementManager(QJsonObject source)
qDebug() << elementsJson.size(); qDebug() << elementsJson.size();
for (auto elementJson : elementsJson) for (auto elementJson : elementsJson)
{ {
if (elementJson.toObject().value("type") == "group") if (elementJson.toObject().value("type").toString() == "group")
elements.push_back(new GroupElement()); elements.push_back(new GroupElement());
else else
elements.push_back(new SimpleElement(elementJson.toObject())); elements.push_back(new SimpleElement(elementJson.toObject()));

View File

@ -29,7 +29,8 @@ void GroupElement::setSourceLayer(FolderLayerWrapper *sourceLayer)
} }
QPainterPath GroupElement::getPaintObject() const QPainterPath GroupElement::getPaintObject() const
{ {
if (sourceLayer != nullptr) if (sourceLayer != nullptr) {
sourceLayer->refresh();
return sourceLayer->getCache(); return sourceLayer->getCache();
else else
return QPainterPath(); return QPainterPath();

View File

@ -28,7 +28,7 @@ class SimpleElement : public GraphicElement
}; };
class GroupElement : public GraphicElement class GroupElement : public GraphicElement
{ {
private: public:
FolderLayerWrapper *sourceLayer; FolderLayerWrapper *sourceLayer;
public: public:

View File

@ -32,14 +32,16 @@ QPainterPath LayerWrapper::getCache()
LayerWrapper::LayerWrapper(QJsonObject json, LayerWrapper *parent) LayerWrapper::LayerWrapper(QJsonObject json, LayerWrapper *parent)
{ {
this->parent = shared_ptr<LayerWrapper>(parent); this->parent = shared_ptr<LayerWrapper>(parent);
auto offsetJson = json.value("offset").toObject(); auto transformJson = json.value("transform").toObject();
property.offset = {offsetJson.value("x").toDouble(), offsetJson.value("y").toDouble()}; 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) FolderLayerWrapper::FolderLayerWrapper(QJsonObject json, ElementManager *elementManager, LayerWrapper *parent)
: LayerWrapper(json, parent) : LayerWrapper(json, parent)
{ {
qDebug() << json.value("name").toString(); qDebug() << json.value("name").toString()<<" "<<this;
QJsonArray childrenJson = json.value("children").toArray(); QJsonArray childrenJson = json.value("children").toArray();
QJsonValue referencedJson = json.value("referenced-by"); QJsonValue referencedJson = json.value("referenced-by");
if (!referencedJson.isNull()) if (!referencedJson.isNull())
@ -62,16 +64,21 @@ FolderLayerWrapper::FolderLayerWrapper(QJsonObject json, ElementManager *element
LeafLayerWrapper::LeafLayerWrapper(QJsonObject json, ElementManager *elementManager, LayerWrapper *parent) LeafLayerWrapper::LeafLayerWrapper(QJsonObject json, ElementManager *elementManager, LayerWrapper *parent)
: LayerWrapper(json, parent) : LayerWrapper(json, parent)
{ {
qDebug() << json.value("name").toString(); qDebug() << json.value("name").toString() << " " << this;
int elementIndex = json.value("element").toInt(); int elementIndex = json.value("element").toInt();
wrappedElement = elementManager->getElementById(elementIndex); wrappedElement = elementManager->getElementById(elementIndex);
} }
void LayerWrapper::SimpleProperty::apply(QPainterPath &cache) const void LayerWrapper::SimpleProperty::apply(QPainterPath &cache) const
{ {
QTransform trans; 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.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 = trans.map(cache);
// cache.translate(offset); // cache.translate(offset);
} }
@ -91,8 +98,9 @@ void FolderLayerWrapper::refresh()
void LeafLayerWrapper::refresh() void LeafLayerWrapper::refresh()
{ {
cache.clear(); cache.clear();
if (wrappedElement != nullptr) if (wrappedElement != nullptr) {
cache.addPath(wrappedElement->getPaintObject()); cache.addPath(wrappedElement->getPaintObject());
}
LayerWrapper::refresh(); LayerWrapper::refresh();
} }

View File

@ -29,7 +29,7 @@ class LayerWrapper
struct SimpleProperty struct SimpleProperty
{ {
QString name = ""; QString name = "";
QPointF zoom = {1.0, 1.0}; QPointF scale = {1.0, 1.0};
QPointF offset = {0, 0}; QPointF offset = {0, 0};
double rotation = 0; double rotation = 0;
bool flipHorizontally = 0; bool flipHorizontally = 0;
@ -46,7 +46,7 @@ class LayerWrapper
class FolderLayerWrapper : public LayerWrapper class FolderLayerWrapper : public LayerWrapper
{ {
private: public:
vector<shared_ptr<LayerWrapper>> children; vector<shared_ptr<LayerWrapper>> children;
public: public:
@ -60,7 +60,7 @@ class FolderLayerWrapper : public LayerWrapper
class LeafLayerWrapper : public LayerWrapper class LeafLayerWrapper : public LayerWrapper
{ {
private: public:
GraphicElement *wrappedElement; GraphicElement *wrappedElement;
public: public:

View File

@ -35,7 +35,7 @@ void PreviewWindow::initializeGL()
initializeOpenGLFunctions(); initializeOpenGLFunctions();
glClearColor(1.0, 1.0, 1.0, 1.0); glClearColor(1.0, 1.0, 1.0, 1.0);
} }
#include "./third-party modules/qquick/qquicksvgparser_p.h"
void PreviewWindow::paintGL() void PreviewWindow::paintGL()
{ {
glClear(GL_COLOR_BUFFER_BIT); glClear(GL_COLOR_BUFFER_BIT);

297
data.json
View File

@ -3,127 +3,14 @@
"width": 1080, "width": 1080,
"elements": [ "elements": [
{ {
"type": "path", "name": "ababa",
"type": "svg-file",
"data": { "data": {
"operations": [ "include": "./svg/ababa.svg"
{
"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
} }
}, },
{ {
"name": "ababa-group",
"type": "group", "type": "group",
"data": { "data": {
"reference-layer": "0.0" "reference-layer": "0.0"
@ -132,172 +19,90 @@
], ],
"root-layer": { "root-layer": {
"name": "root", "name": "root",
"transform": {
"offset": { "offset": {
"x": 0, "x": 0,
"y": 0 "y": 0
}, },
"transformation": [ "scale": {
0, "x": 1.0,
0, "y": 1.0
0, },
0, "rotation": 0.0
0, },
0,
0,
0,
0
],
"effects": [], "effects": [],
"is-folder": true, "is-folder": true,
"referenced-by": null, "referenced-by": null,
"children": [ "children": [
{ {
"name": "GroupFolderExample", "name": "GroupFolderExample",
"transform": {
"offset": { "offset": {
"x": 5, "x": 50,
"y": 10 "y": 50
}, },
"transformation": [ "scale": {
0, "x": 1.0,
0, "y": 1.0
0, },
0, "rotation": 0.0
0, },
0, "effects": [],
0, "is-folder": true,
0, "referenced-by": 1,
0 "children": [
],
"effects": [
{ {
"type": "iterate", "name": "Leaf1",
"data": { "transform": {
"time": 5,
"operations": [
{
"type": "move",
"data": {
"offset": { "offset": {
"x": 5,
"y": 6
}
}
},
{
"type": "rotate",
"data": {
"center-offset": {
"x": 0, "x": 0,
"y": 0 "y": 0
}, },
"angle": 60 "scale": {
} "x": 1.0,
"y": 1.0
}, },
{ "rotation": 0.0
"type": "zoom",
"data": {
"zoom": 1.5
}
}, },
{
"type": "flip",
"data": {
"k": 1.2,
"b": 3
}
}
]
}
}
],
"is-folder": true,
"referenced-by": 3,
"children": [
{
"name": "GroupedLayer1",
"offset": {
"x": 10,
"y": 20
},
"transformation": [
5,
0,
0,
0,
6,
0,
0,
0,
0
],
"effects": [], "effects": [],
"is-folder": false, "is-folder": false,
"element": 0 "element": 0
}, },
{ {
"name": "GroupedLayer2", "name": "Leaf2",
"transform": {
"offset": { "offset": {
"x": 15, "x": 150,
"y": 25 "y": 0
},
"scale": {
"x": 1.5,
"y": 1.5
},
"rotation": 0.0
}, },
"transformation": [
5,
0,
0,
0,
6,
0,
0,
0,
0
],
"effects": [], "effects": [],
"is-folder": false, "is-folder": false,
"element": 1 "element": 0
} }
] ]
}, },
{ {
"name": "ReferencingGroupLayer", "name": "ReferencingGroupLayer",
"transform": {
"offset": { "offset": {
"x": 10, "x": 100,
"y": 20 "y": 0
},
"scale": {
"x": 1,
"y": 1
},
"rotation": 45
}, },
"transformation": [
5,
0,
0,
0,
6,
0,
0,
0,
0
],
"effects": [], "effects": [],
"is-folder": false, "is-folder": false,
"element": 3 "element": 1
},
{
"name": "Layer1",
"offset": {
"x": 10,
"y": 20
},
"transformation": [
5,
0,
0,
0,
6,
0,
0,
0,
0
],
"effects": [],
"is-folder": false,
"element": 2
} }
] ]
} }