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();
for (auto elementJson : elementsJson)
{
if (elementJson.toObject().value("type").toString() == "group")
if (elementJson.toObject().value("type") == "group")
elements.push_back(new GroupElement());
else
elements.push_back(new SimpleElement(elementJson.toObject()));

View File

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

View File

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

View File

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

View File

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

View File

@ -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);

313
data.json
View File

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