修改了PixelPath
parent
073f68e360
commit
3b87644e21
|
@ -41,7 +41,7 @@ EditorWidgetItem::EditorWidgetItem(QString filePath,QWidget *parent) : QWidget(p
|
|||
layerManager = new LayerManager(source, elementManager);
|
||||
elementInfoDisplayWidget->setElementManager(elementManager);
|
||||
treeWidget->elementManager = elementManager;
|
||||
qDebug() << layerManager->toJson();
|
||||
//qDebug() << layerManager->toJson();
|
||||
previewWindow->initialize(layerManager,QSize(jsonDoc.object().value("width").toDouble(),jsonDoc.object().value("height").toDouble()));
|
||||
|
||||
|
||||
|
|
|
@ -1,11 +1,14 @@
|
|||
#include "GraphicElement.h"
|
||||
#include "util/SvgFileLoader.h"
|
||||
#include <QGuiApplication>
|
||||
#include <QScreen>
|
||||
using namespace std;
|
||||
|
||||
PixelPath SimpleElement::getPaintObject() const
|
||||
{
|
||||
PixelPath result;
|
||||
result.addPath(painterPath);
|
||||
qDebug() << result.getPainterPath();
|
||||
return result;
|
||||
}
|
||||
|
||||
|
@ -48,7 +51,7 @@ PixelPath SimpleElement::getPaintObject(std::vector<std::shared_ptr<LayerStyle>>
|
|||
std::shared_ptr<Renderer::ElementStyle> style;
|
||||
if ((*styles).empty())
|
||||
{
|
||||
style = std::make_shared<Renderer::ElementStyleStrokeDemo>(2);
|
||||
return this->getPaintObject();
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -63,6 +66,7 @@ PixelPath SimpleElement::getPaintObject(std::vector<std::shared_ptr<LayerStyle>>
|
|||
auto [img, mov] = renderer->drawElement(painterPath, *style, 1.0);
|
||||
//qDebug() << img << " ------";
|
||||
result.addImage(img, mov);
|
||||
result.addPath(painterPath);
|
||||
//result.addPath(painterPath);
|
||||
// QImage img(80,80,QImage::Format_ARGB32);
|
||||
// QPainter pt(&img);
|
||||
|
@ -124,8 +128,15 @@ void SimpleElement::paint(QPainter* painter, QTransform transform, const vector<
|
|||
std::dynamic_pointer_cast<StrokeElementLayerStyle>(style)->materialStyles[0]->materialStroke
|
||||
)->materialMap[1.0].color;*/
|
||||
}
|
||||
auto [img, mov] = renderer->drawElement(painterPath, *style, 1.0);
|
||||
QVector2D scale(transform.m11(), transform.m22());
|
||||
scale /= transform.m33();
|
||||
double maxScale = std::max(scale.x(), scale.y());
|
||||
double pixelRatio = maxScale * QGuiApplication::primaryScreen()->devicePixelRatio();
|
||||
auto [img, mov] = renderer->drawElement(painterPath, *style, pixelRatio);
|
||||
painter->setTransform(transform.scale(1 / pixelRatio, 1 / pixelRatio));
|
||||
//img = img.scaled(img.width() / pixelRatio, img.height() / pixelRatio, Qt::KeepAspectRatio, Qt::SmoothTransformation);
|
||||
painter->drawImage(mov, img);
|
||||
|
||||
}
|
||||
|
||||
painter->restore();
|
||||
|
|
|
@ -33,7 +33,7 @@ public:
|
|||
|
||||
class SimpleElement : public GraphicElement
|
||||
{
|
||||
private:
|
||||
public:
|
||||
QJsonObject jsonSource;
|
||||
// TODO: 改为ComposedPainterPath
|
||||
QPainterPath painterPath;
|
||||
|
|
|
@ -26,6 +26,7 @@ FolderLayerWrapper*LayerWrapper::getParent() const
|
|||
PixelPath LayerWrapper::getCache(LayerWrapper* selectedLayer)
|
||||
{
|
||||
this->refresh(selectedLayer);
|
||||
qDebug() << cache.painterPath;
|
||||
if (selectedLayer == this)
|
||||
{
|
||||
this->cache.highLight();
|
||||
|
@ -130,7 +131,9 @@ void LeafLayerWrapper::refresh(LayerWrapper* layer)
|
|||
cache.clear();
|
||||
if (wrappedElement != nullptr)
|
||||
{
|
||||
qDebug() << cache.painterPath;
|
||||
cache.addPath(wrappedElement->getPaintObject(&(this->styles)));
|
||||
qDebug() << cache.painterPath;
|
||||
}
|
||||
LayerWrapper::refresh();
|
||||
}
|
||||
|
|
|
@ -66,6 +66,7 @@ void PixelPath::clear()
|
|||
{
|
||||
pixmap.fill(Qt::transparent);
|
||||
boundingRect = QRectF(0, 0, 0, 0);
|
||||
painterPath.clear();
|
||||
}
|
||||
|
||||
PixelPath PixelPath::trans(QTransform& mat)const
|
||||
|
@ -76,6 +77,7 @@ PixelPath PixelPath::trans(QTransform& mat)const
|
|||
painter.setRenderHint(QPainter::HighQualityAntialiasing);
|
||||
painter.setTransform(mat);
|
||||
painter.drawPixmap(0, 0, pixmap);
|
||||
result.addPath(this->painterPath);
|
||||
result.boundingRect = mat.mapRect(boundingRect);
|
||||
return result;
|
||||
}
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
|
||||
class PixelPath
|
||||
{
|
||||
private:
|
||||
public:
|
||||
QRectF boundingRect;
|
||||
QPixmap pixmap;
|
||||
QPainterPath painterPath;
|
||||
|
|
|
@ -27,8 +27,15 @@ Painting PaintingUtil::transfromToPainting(QString jsonFilePath) {
|
|||
QTransform transform;
|
||||
glm::bvec2 flip(0, 0);
|
||||
QJsonObject jsonObj = readJsonFile(jsonFilePath);
|
||||
qDebug() << jsonObj;
|
||||
ElementManager *elementManager = new ElementManager(jsonObj, Renderer::ElementRenderer::instance());
|
||||
LayerManager* layerManager = new LayerManager(jsonObj, elementManager);
|
||||
//qDebug() << elementManager->toJson();
|
||||
//qDebug() << layerManager->toJson();
|
||||
qDebug() << ((SimpleElement*)((LeafLayerWrapper*)((FolderLayerWrapper*)((FolderLayerWrapper*)layerManager->getRoot())->children[0].get())->children[0].get())->wrappedElement)->painterPath;
|
||||
qDebug() << ((LeafLayerWrapper*)((FolderLayerWrapper*)((FolderLayerWrapper*)layerManager->getRoot())->children[0].get())->children[0].get())->getCache().painterPath;
|
||||
|
||||
|
||||
traverseLayTree(layerManager->getRoot(), transform, flip, painting);
|
||||
return painting;
|
||||
}
|
||||
|
@ -43,6 +50,7 @@ void PaintingUtil::traverseLayTree(LayerWrapper* nowLayer, QTransform transform,
|
|||
transform = nowLayer->property.transform * transform;
|
||||
|
||||
if (leafLayer != nullptr) {
|
||||
qDebug() << leafLayer<<"------" << painterPath;
|
||||
Element element;
|
||||
ElementTransform elementTrans;
|
||||
element.ratio = bound.width() / bound.height();
|
||||
|
@ -52,10 +60,10 @@ void PaintingUtil::traverseLayTree(LayerWrapper* nowLayer, QTransform transform,
|
|||
trans.scale(1 / bound.width(), 1 / bound.height());
|
||||
trans.translate(-bound.center().x(), -bound.center().y());
|
||||
|
||||
element.contour.reset(new vector<vector<Renderer::Point> >(PainterPathUtil::transformToLines(trans.map(painterPath))));
|
||||
element.contour = std::make_shared<vector<vector<Renderer::Point> >>(PainterPathUtil::transformToLines(trans.map(painterPath)));
|
||||
QSize screenSize = pixelPath.getPixmap().size();
|
||||
//element.style.reset(new Renderer::ElementStyleStrokeDemo(0.06));
|
||||
|
||||
element.style = std::make_shared<Renderer::ElementStyleStrokeDemo>(0.06);
|
||||
|
||||
|
||||
painterPath = transform.map(painterPath);
|
||||
bound = painterPath.boundingRect();
|
||||
|
|
|
@ -229,7 +229,7 @@ GLuint Renderer::Model::loadPainting(std::string path)
|
|||
if (iter != paintingLoaded.end())
|
||||
return iter->second;
|
||||
|
||||
Painting painting = PaintingUtil::transfromToPainting("D:\\BigC\\Project\\ArchitectureColoredPainting\\data.json");
|
||||
Painting painting = PaintingUtil::transfromToPainting("../data.json");
|
||||
|
||||
painting.generateBuffers(glFunc);
|
||||
|
||||
|
|
|
@ -0,0 +1,5 @@
|
|||
<svg id="万字笔画" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 1068 1045">
|
||||
<title>4_L0</title>
|
||||
<polyline points="873 0 360 390 427 483 490 439 600 592 690 524 750 608 189 1045" fill="none"/>
|
||||
<polyline points="1068 830 651 303 566 373 629 455 487 566 538 632 461 696 0 99" fill="none"/>
|
||||
</svg>
|
After Width: | Height: | Size: 307 B |
|
@ -0,0 +1,31 @@
|
|||
{
|
||||
"height": 1080,
|
||||
"width": 1080,
|
||||
"elements": [
|
||||
{
|
||||
"name": "ababa",
|
||||
"type": "svg-file",
|
||||
"data": {
|
||||
"include": "./svg/0.svg"
|
||||
}
|
||||
}
|
||||
],
|
||||
"root-layer": {
|
||||
"name": "root",
|
||||
"transform": {
|
||||
"offset": {
|
||||
"x": 0,
|
||||
"y": 0
|
||||
},
|
||||
"scale": {
|
||||
"x": 1.0,
|
||||
"y": 1.0
|
||||
},
|
||||
"rotation": 0.0
|
||||
},
|
||||
"effects": [],
|
||||
"is-folder": true,
|
||||
"referenced-by": null,
|
||||
"children":[]
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue