Compare commits

..

2 Commits

Author SHA1 Message Date
ArgonarioD e97e6d5281 令drawElement时会应用style 2023-03-14 18:19:41 +08:00
ArgonarioD b429761d81 merged 2023-03-14 18:12:31 +08:00
2 changed files with 24 additions and 11 deletions

View File

@ -11,7 +11,7 @@ PixelPath SimpleElement::getPaintObject() const
void SimpleElement::loadSvgFile(const QString& filePath) void SimpleElement::loadSvgFile(const QString& filePath)
{ {
// TODO <EFBFBD><EFBFBD>ʽ<EFBFBD><EFBFBD><EFBFBD><EFBFBD> // TODO 样式问题
SvgFileLoader loader; SvgFileLoader loader;
loader.loadSvgFile(filePath, painterPath); loader.loadSvgFile(filePath, painterPath);
qDebug() << "load svg file success " << painterPath.elementCount(); qDebug() << "load svg file success " << painterPath.elementCount();
@ -21,7 +21,7 @@ SimpleElement::SimpleElement(QJsonObject jsonSource) : jsonSource(jsonSource)
{ {
painterPath.clear(); painterPath.clear();
//loadSvgFile("D:\\Projects\\BigC\\svg\\3.svg"); //loadSvgFile("D:\\Projects\\BigC\\svg\\3.svg");
loadSvgFile("../"/*TODO: <EFBFBD>ij<EFBFBD>json<EFBFBD>ļ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD><EFBFBD><EFBFBD>·<EFBFBD><EFBFBD>*/ + jsonSource.value("data").toObject().value("include").toString()); loadSvgFile("../"/*TODO: 改成json文件所在文件夹路径*/ + jsonSource.value("data").toObject().value("include").toString());
} }
GroupElement::GroupElement(FolderLayerWrapper* sourceLayer) GroupElement::GroupElement(FolderLayerWrapper* sourceLayer)
@ -45,7 +45,6 @@ PixelPath GroupElement::getPaintObject() const
//TODO: apply styles and send back //TODO: apply styles and send back
PixelPath SimpleElement::getPaintObject(std::vector<std::shared_ptr<LayerStyle>>* styles) const { PixelPath SimpleElement::getPaintObject(std::vector<std::shared_ptr<LayerStyle>>* styles) const {
PixelPath result; PixelPath result;
//Renderer::ElementStyleStrokeDemo demo(2);
std::shared_ptr<Renderer::ElementStyle> style; std::shared_ptr<Renderer::ElementStyle> style;
if ((*styles).empty()) if ((*styles).empty())
{ {
@ -91,7 +90,7 @@ PixelPath GroupElement::getPaintObject(std::vector<std::shared_ptr<LayerStyle>>*
// rawPath.addPath(path); // rawPath.addPath(path);
// } // }
//} //}
//TODO : <EFBFBD><EFBFBD><EFBFBD>ϸ<EFBFBD><EFBFBD> //TODO : 添加细节
QJsonObject GraphicElement::toJson() const QJsonObject GraphicElement::toJson() const
{ {
QJsonObject result; QJsonObject result;
@ -99,7 +98,7 @@ QJsonObject GraphicElement::toJson() const
return result; return result;
} }
void SimpleElement::paint(QPainter* painter, QTransform transform, vector<std::shared_ptr<LayerStyle>> styles) void SimpleElement::paint(QPainter* painter, QTransform transform, const vector<std::shared_ptr<LayerStyle>> &styles)
{ {
painter->save(); painter->save();
painter->setTransform(transform); painter->setTransform(transform);
@ -109,16 +108,30 @@ void SimpleElement::paint(QPainter* painter, QTransform transform, vector<std::s
} }
else else
{ {
// TODO:Ӧ<><D3A6>style
Renderer::ElementStyleStrokeDemo demo(2); Renderer::ElementStyleStrokeDemo demo(2);
auto [img, mov] = renderer->drawElement(painterPath, demo, 1.0); std::shared_ptr<Renderer::ElementStyle> style;
if (styles.empty())
{
style = std::make_shared<Renderer::ElementStyleStrokeDemo>(2);
}
else
{
style = styles[0];
/*qDebug() << std::dynamic_pointer_cast<Renderer::StrokePlain>(
std::dynamic_pointer_cast<StrokeElementLayerStyle>(style)->materialStyles[0]->materialStroke
)->material.color.name();*/
/*qDebug() << std::dynamic_pointer_cast<Renderer::StrokeRadialGradient>(
std::dynamic_pointer_cast<StrokeElementLayerStyle>(style)->materialStyles[0]->materialStroke
)->materialMap[1.0].color;*/
}
auto [img, mov] = renderer->drawElement(painterPath, *style, 1.0);
painter->drawImage(mov, img); painter->drawImage(mov, img);
} }
painter->restore(); painter->restore();
} }
void GroupElement::paint(QPainter* painter, QTransform transform, vector<std::shared_ptr<LayerStyle>> styles) void GroupElement::paint(QPainter* painter, QTransform transform, const vector<std::shared_ptr<LayerStyle>> &styles)
{ {
sourceLayer->paint(painter, transform); sourceLayer->paint(painter, transform);
} }

View File

@ -28,7 +28,7 @@ public:
virtual QJsonObject toJson() const; virtual QJsonObject toJson() const;
virtual PixelPath getPaintObject() const = 0; virtual PixelPath getPaintObject() const = 0;
virtual PixelPath getPaintObject(std::vector<std::shared_ptr<LayerStyle>>*) const = 0; virtual PixelPath getPaintObject(std::vector<std::shared_ptr<LayerStyle>>*) const = 0;
virtual void paint(QPainter* painter, QTransform transform, std::vector<std::shared_ptr<LayerStyle>> styles) = 0; virtual void paint(QPainter* painter, QTransform transform, const std::vector<std::shared_ptr<LayerStyle>> &styles) = 0;
}; };
class SimpleElement : public GraphicElement class SimpleElement : public GraphicElement
@ -45,7 +45,7 @@ public:
~SimpleElement() = default; ~SimpleElement() = default;
PixelPath getPaintObject() const override; PixelPath getPaintObject() const override;
PixelPath getPaintObject(std::vector<std::shared_ptr<LayerStyle>>*) const override; PixelPath getPaintObject(std::vector<std::shared_ptr<LayerStyle>>*) const override;
void paint(QPainter* painter, QTransform transform, std::vector<std::shared_ptr<LayerStyle>> styles) override; void paint(QPainter* painter, QTransform transform, const std::vector<std::shared_ptr<LayerStyle>> &styles) override;
}; };
class GroupElement : public GraphicElement class GroupElement : public GraphicElement
@ -60,7 +60,7 @@ public:
PixelPath getPaintObject() const override; PixelPath getPaintObject() const override;
PixelPath getPaintObject(std::vector<std::shared_ptr<LayerStyle>>*) const override; PixelPath getPaintObject(std::vector<std::shared_ptr<LayerStyle>>*) const override;
void setSourceLayer(FolderLayerWrapper* sourceLayer); void setSourceLayer(FolderLayerWrapper* sourceLayer);
void paint(QPainter* painter, QTransform transform, std::vector<std::shared_ptr<LayerStyle>> styles) override; void paint(QPainter* painter, QTransform transform, const std::vector<std::shared_ptr<LayerStyle>> &styles) override;
}; };
//******************************** BitmapPath ********************************// //******************************** BitmapPath ********************************//