add svg data, trigger preview update when layer property changes

dev-VirtualTexture
白封羽 2023-01-19 12:38:12 +08:00
parent 6b283c2017
commit 23ee917033
11 changed files with 18 additions and 9 deletions

View File

@ -11,12 +11,14 @@ void SimpleElement::loadSvgFile(const QString& filePath)
// TODO ÑùʽÎÊÌâ // TODO ÑùʽÎÊÌâ
SvgFileLoader loader; SvgFileLoader loader;
loader.loadSvgFile(filePath, painterPath); loader.loadSvgFile(filePath, painterPath);
qDebug() << "load svg file success "<<painterPath.elementCount();
} }
SimpleElement::SimpleElement(QJsonObject jsonSource) : jsonSource(jsonSource) SimpleElement::SimpleElement(QJsonObject jsonSource) : jsonSource(jsonSource)
{ {
painterPath.clear(); painterPath.clear();
loadSvgFile(jsonSource.value("data").toObject().value("include").toString()); loadSvgFile("D:\\Projects\\BigC\\svg\\3.svg");
//loadSvgFile(jsonSource.value("data").toObject().value("include").toString());
} }
GroupElement::GroupElement(FolderLayerWrapper *sourceLayer) GroupElement::GroupElement(FolderLayerWrapper *sourceLayer)

View File

@ -79,16 +79,16 @@ LeafLayerWrapper::LeafLayerWrapper(QJsonObject json, ElementManager *elementMana
void LayerWrapper::SimpleProperty::apply(QPainterPath &cache) const void LayerWrapper::SimpleProperty::apply(QPainterPath &cache) const
{ {
QTransform trans; QTransform trans;
double delX = cache.boundingRect().width(); double centerX = cache.boundingRect().center().x();
double delY = cache.boundingRect().height(); double centerY = cache.boundingRect().center().y();
trans.translate(-delX, -delY); qDebug() << name << " " << cache.boundingRect().center();
qDebug() << name << " " << cache.boundingRect();
trans.translate(centerX, centerY);
trans.scale(scale.x(), scale.y()); trans.scale(scale.x(), scale.y());
trans.rotate(rotation); trans.rotate(rotation);
trans.translate(-centerX, -centerY);
trans.translate(offset.x(), offset.y());
cache = trans.map(cache); cache = trans.map(cache);
trans.reset();
trans.translate(delX + offset.x(), delY + offset.y());
cache = trans.map(cache);
// cache.translate(offset);
} }
void LayerWrapper::refresh() void LayerWrapper::refresh()
{ {

View File

@ -6,7 +6,7 @@
"name": "ababa", "name": "ababa",
"type": "svg-file", "type": "svg-file",
"data": { "data": {
"include": "./svg/ababa.svg" "include": "./svg/2.svg"
} }
}, },
{ {

1
svg/0.svg Normal file
View File

@ -0,0 +1 @@
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 106.93 99.81"><defs><style>.cls-1{fill:none;stroke:#00ff1c;stroke-miterlimit:10;}</style></defs><title>0</title><g id="图层_2" data-name="图层 2"><polyline class="cls-1" points="27.24 16.75 27.24 2.15 7.2 2.15 7.2 22.78 46.7 22.78"/></g><g id="图层_3" data-name="图层 3"><polyline class="cls-1" points="27.24 30.37 27.24 44.97 0 44.97"/></g><g id="图层_4" data-name="图层 4"><path class="cls-1" d="M292.82,107.78s0,0,0,0,0,3.59,0,7.62c0,3.85,0,5.78.06,6.43a19.94,19.94,0,0,0,2.87,7.58,15.85,15.85,0,0,0,6.61,6.23A14.75,14.75,0,0,0,310,137a11.69,11.69,0,0,0,7.59-2.92,11,11,0,0,0,3.2-6.84c.15-1.27.58-4.84-1.79-7.64a8.54,8.54,0,0,0-3.56-2.44c-1.32-.52-3.32-1.31-5.06-.33a5.41,5.41,0,0,0-2.14,3,3.48,3.48,0,0,0-.16,2.71c.78,1.86,3.36,2.14,3.47,2.15" transform="translate(-287.18 -56.2)"/></g><g id="图层_5" data-name="图层 5"><path class="cls-1" d="M339.72,85.41V58.75a69.07,69.07,0,0,1,14.79,0c5.9.63,9.31,1,12.84,3.5,1.76,1.22,6.37,4.43,6.68,9.92.25,4.38-2.27,9.26-6.72,11-3.5,1.39-8.46,1-10.71-2.06-.14-.18-2-2.82-.92-5.46.63-1.51,2.34-3.23,4.28-2.92a3.76,3.76,0,0,1,2.33,1.55" transform="translate(-287.18 -56.2)"/></g><g id="图层_6" data-name="图层 6"><path class="cls-1" d="M301.38,145.93a8.21,8.21,0,0,1-.77,5.83c-.26.44-2.5,4.23-5.84,3.7a5,5,0,0,1-3.89-3.5c-.1-.35-1-3,.58-4.09a3.28,3.28,0,0,1,3.89.58" transform="translate(-287.18 -56.2)"/><path class="cls-1" d="M323.18,115.76a7.37,7.37,0,0,1,7.39-8.17c.49,0,4.07.12,5.65,2.92.19.34,1.52,2.7.19,4.67a4.33,4.33,0,0,1-4.67,1.56" transform="translate(-287.18 -56.2)"/></g><g id="图层_7" data-name="图层 7"><path class="cls-1" d="M352.17,86.57a14.23,14.23,0,0,0-4.67,2.73c-1.59,1.4-3.37,3-3.5,5.45a6.45,6.45,0,0,0,2.14,4.86c1.28,1.1,3.68,2.22,5.84,1.17,1.64-.8,3.31-3,2.53-4.67a3.6,3.6,0,0,0-3.31-1.75" transform="translate(-287.18 -56.2)"/><path class="cls-1" d="M382.34,66.53a17.27,17.27,0,0,0,3.89.39c2.16,0,3.53,0,4.86-1a6.15,6.15,0,0,0,2.34-3.89c.17-1,.53-2.93-.78-4.29a4.32,4.32,0,0,0-4.48-.77A3.62,3.62,0,0,0,386,58.75a3.75,3.75,0,0,0,.2,3.31" transform="translate(-287.18 -56.2)"/></g></svg>

After

Width:  |  Height:  |  Size: 2.1 KiB

1
svg/1.svg Normal file
View File

@ -0,0 +1 @@
<svg id="图层_2" data-name="图层 2" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 40 21.63"><defs><style>.cls-1{fill:none;stroke:#00ff1c;stroke-miterlimit:10;}</style></defs><title>1</title><polyline class="cls-1" points="20.54 15.1 20.54 0.5 0.5 0.5 0.5 21.13 40 21.13"/></svg>

After

Width:  |  Height:  |  Size: 284 B

1
svg/2.svg Normal file
View File

@ -0,0 +1 @@
<svg id="图层_3" data-name="图层 3" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 27.74 15.09"><defs><style>.cls-1{fill:none;stroke:#00ff1c;stroke-miterlimit:10;}</style></defs><title>2</title><polyline class="cls-1" points="27.24 0 27.24 14.6 0 14.6"/></svg>

After

Width:  |  Height:  |  Size: 265 B

1
svg/3.svg Normal file
View File

@ -0,0 +1 @@
<svg id="图层_4" data-name="图层 4" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 29.07 30.28"><defs><style>.cls-1{fill:none;stroke:#00ff1c;stroke-miterlimit:10;}</style></defs><title>3</title><path class="cls-1" d="M292.82,107.78s0,0,0,0,0,3.59,0,7.62c0,3.85,0,5.78.06,6.43a19.94,19.94,0,0,0,2.87,7.58,15.85,15.85,0,0,0,6.61,6.23A14.75,14.75,0,0,0,310,137a11.69,11.69,0,0,0,7.59-2.92,11,11,0,0,0,3.2-6.84c.15-1.27.58-4.84-1.79-7.64a8.54,8.54,0,0,0-3.56-2.44c-1.32-.52-3.32-1.31-5.06-.33a5.41,5.41,0,0,0-2.14,3,3.48,3.48,0,0,0-.16,2.71c.78,1.86,3.36,2.14,3.47,2.15" transform="translate(-292.3 -107.25)"/></svg>

After

Width:  |  Height:  |  Size: 617 B

1
svg/4.svg Normal file
View File

@ -0,0 +1 @@
<svg id="图层_5" data-name="图层 5" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 35.33 27.55"><defs><style>.cls-1{fill:none;stroke:#00ff1c;stroke-miterlimit:10;}</style></defs><title>4</title><path class="cls-1" d="M339.72,85.41V58.75a69.07,69.07,0,0,1,14.79,0c5.9.63,9.31,1,12.84,3.5,1.76,1.22,6.37,4.43,6.68,9.92.25,4.38-2.27,9.26-6.72,11-3.5,1.39-8.46,1-10.71-2.06-.14-.18-2-2.82-.92-5.46.63-1.51,2.34-3.23,4.28-2.92a3.76,3.76,0,0,1,2.33,1.55" transform="translate(-339.22 -57.85)"/></svg>

After

Width:  |  Height:  |  Size: 499 B

1
svg/5.svg Normal file
View File

@ -0,0 +1 @@
<svg id="图层_6" data-name="图层 6" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 47.45 48.92"><defs><style>.cls-1{fill:none;stroke:#00ff1c;stroke-miterlimit:10;}</style></defs><title>5</title><path class="cls-1" d="M301.38,145.93a8.21,8.21,0,0,1-.77,5.83c-.26.44-2.5,4.23-5.84,3.7a5,5,0,0,1-3.89-3.5c-.1-.35-1-3,.58-4.09a3.28,3.28,0,0,1,3.89.58" transform="translate(-290.04 -107.09)"/><path class="cls-1" d="M323.18,115.76a7.37,7.37,0,0,1,7.39-8.17c.49,0,4.07.12,5.65,2.92.19.34,1.52,2.7.19,4.67a4.33,4.33,0,0,1-4.67,1.56" transform="translate(-290.04 -107.09)"/></svg>

After

Width:  |  Height:  |  Size: 577 B

1
svg/6.svg Normal file
View File

@ -0,0 +1 @@
<svg id="图层_7" data-name="图层 7" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 50.62 45.5"><defs><style>.cls-1{fill:none;stroke:#00ff1c;stroke-miterlimit:10;}</style></defs><title>6</title><path class="cls-1" d="M352.17,86.57a14.23,14.23,0,0,0-4.67,2.73c-1.59,1.4-3.37,3-3.5,5.45a6.45,6.45,0,0,0,2.14,4.86c1.28,1.1,3.68,2.22,5.84,1.17,1.64-.8,3.31-3,2.53-4.67a3.6,3.6,0,0,0-3.31-1.75" transform="translate(-343.49 -56.2)"/><path class="cls-1" d="M382.34,66.53a17.27,17.27,0,0,0,3.89.39c2.16,0,3.53,0,4.86-1a6.15,6.15,0,0,0,2.34-3.89c.17-1,.53-2.93-.78-4.29a4.32,4.32,0,0,0-4.48-.77A3.62,3.62,0,0,0,386,58.75a3.75,3.75,0,0,0,.2,3.31" transform="translate(-343.49 -56.2)"/></svg>

After

Width:  |  Height:  |  Size: 686 B

BIN
svg/原图.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 124 KiB