Compare commits

..

No commits in common. "d5959ba8ad521b7dd3443d5da3f36bbde33e7c1c" and "96dac4151e956503ee44a312135046e87b00a710" have entirely different histories.

7 changed files with 269 additions and 83 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").toString() == "group") if (elementJson.toObject().value("type") == "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,8 +29,7 @@ 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
{ {
public: private:
FolderLayerWrapper *sourceLayer; FolderLayerWrapper *sourceLayer;
public: public:

View File

@ -32,16 +32,14 @@ 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 transformJson = json.value("transform").toObject(); auto offsetJson = json.value("offset").toObject();
property.offset = { transformJson.value("offset").toObject().value("x").toDouble(), transformJson.value("offset").toObject().value("y").toDouble() }; property.offset = {offsetJson.value("x").toDouble(), offsetJson.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()<<" "<<this; qDebug() << json.value("name").toString();
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())
@ -64,21 +62,16 @@ 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() << " " << this; qDebug() << json.value("name").toString();
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;
double delX = cache.boundingRect().width(); trans.scale(zoom.x(), zoom.y());
double delY = cache.boundingRect().height();
trans.translate(-delX,-delY);
trans.scale(scale.x(), scale.y());
trans.rotate(rotation); trans.rotate(rotation);
cache = trans.map(cache); trans.translate(offset.x(), offset.y());
trans.reset();
trans.translate(delX+offset.x(), delY+offset.y());
cache = trans.map(cache); cache = trans.map(cache);
// cache.translate(offset); // cache.translate(offset);
} }
@ -98,9 +91,8 @@ 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 scale = {1.0, 1.0}; QPointF zoom = {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
{ {
public: private:
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
{ {
public: private:
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);

313
data.json
View File

@ -3,14 +3,127 @@
"width": 1080, "width": 1080,
"elements": [ "elements": [
{ {
"name": "ababa", "type": "path",
"type": "svg-file",
"data": { "data": {
"include": "./svg/ababa.svg" "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
} }
}, },
{ {
"name": "ababa-group",
"type": "group", "type": "group",
"data": { "data": {
"reference-layer": "0.0" "reference-layer": "0.0"
@ -19,91 +132,173 @@
], ],
"root-layer": { "root-layer": {
"name": "root", "name": "root",
"transform": {
"offset": { "offset": {
"x": 0, "x": 0,
"y": 0 "y": 0
}, },
"scale": { "transformation": [
"x": 1.0, 0,
"y": 1.0 0,
}, 0,
"rotation": 0.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": 50, "x": 5,
"y": 50 "y": 10
}, },
"scale": { "transformation": [
"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": [ 0
],
"effects": [
{ {
"name": "Leaf1", "type": "iterate",
"transform": { "data": {
"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
}, },
"scale": { "angle": 60
"x": 1.0, }
"y": 1.0
},
"rotation": 0.0
},
"effects": [],
"is-folder": false,
"element": 0
}, },
{ {
"name": "Leaf2", "type": "zoom",
"transform": { "data": {
"offset": { "zoom": 1.5
"x": 150, }
"y": 0
}, },
"scale": { {
"x": 1.5, "type": "flip",
"y": 1.5 "data": {
}, "k": 1.2,
"rotation": 0.0 "b": 3
}, }
"effects": [],
"is-folder": false,
"element": 0
} }
] ]
}
}
],
"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": [],
"is-folder": false,
"element": 0
}, },
{ {
"name": "ReferencingGroupLayer", "name": "GroupedLayer2",
"transform": {
"offset": { "offset": {
"x": 100, "x": 15,
"y": 0 "y": 25
},
"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": 1 "element": 1
} }
] ]
},
{
"name": "ReferencingGroupLayer",
"offset": {
"x": 10,
"y": 20
},
"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
}
]
} }
} }