PaitingUtil读取画布大小

main
wuyize 2023-03-27 13:08:58 +08:00
parent 5ac322fb30
commit e0813ba364
3 changed files with 7 additions and 8 deletions

View File

@ -41,7 +41,7 @@ Painting PaintingUtil::transfromToPainting(QString jsonFilePath) {
shared_ptr<LayerManager> layerManager = make_shared<LayerManager>(jsonObj, elementManager.get());
LayerWrapper* root = layerManager->getRoot();
root->getCache();
handleLayerWrapper(root, QTransform(), painting, contourMap);
handleLayerWrapper(root, QTransform(), painting, contourMap, QSize(jsonObj.value("width").toVariant().value<int>(), jsonObj.value("height").toVariant().value<int>()));
clear();
return painting;
//qDebug() << elementManager->toJson();
@ -70,7 +70,7 @@ Painting PaintingUtil::transfromToPainting(QString jsonFilePath) {
}
void PaintingUtil::handleLayerWrapper(LayerWrapper* nowLayer, QTransform transform, Painting& painting, std::unordered_map<LayerWrapper*, Contour>& contourMap) {
void PaintingUtil::handleLayerWrapper(LayerWrapper* nowLayer, QTransform transform, Painting& painting, std::unordered_map<LayerWrapper*, Contour>& contourMap, const QSize& screenSize) {
LeafLayerWrapper* leafLayer = dynamic_cast<LeafLayerWrapper*>(nowLayer);
qDebug() << nowLayer;
@ -80,7 +80,7 @@ void PaintingUtil::handleLayerWrapper(LayerWrapper* nowLayer, QTransform transfo
GroupElement* wrapperElement = dynamic_cast<GroupElement*>(leafLayer->wrappedElement);
if (wrapperElement != nullptr) {
handleLayerWrapper(wrapperElement->sourceLayer, transform, painting, contourMap);
handleLayerWrapper(wrapperElement->sourceLayer, transform, painting, contourMap, screenSize);
return;
}
@ -106,7 +106,6 @@ void PaintingUtil::handleLayerWrapper(LayerWrapper* nowLayer, QTransform transfo
contourMap.insert({ nowLayer, contour });
;
}
QSize screenSize = QSize(1080, 1080);
ElementTransform elementTransform;
QTransform leafTransform = trans.inverted() * transform * QTransform::fromScale(2. / screenSize.width(), 2. / screenSize.height()) * QTransform::fromTranslate(-1, -1) * QTransform::fromScale(1, -1);
@ -158,7 +157,7 @@ void PaintingUtil::handleLayerWrapper(LayerWrapper* nowLayer, QTransform transfo
FolderLayerWrapper* folderLayer = dynamic_cast<FolderLayerWrapper*>(nowLayer);
if (folderLayer != nullptr) {
for (auto sonLayer : folderLayer->children) {
handleLayerWrapper(sonLayer.get(), transform, painting, contourMap);
handleLayerWrapper(sonLayer.get(), transform, painting, contourMap, screenSize);
}
}
return;

View File

@ -12,7 +12,7 @@ private:
static void clear();
//static const double pi;
static QJsonObject readJsonFile(QString jsonFilePath);
static void handleLayerWrapper(LayerWrapper* nowLayer, QTransform transform, Renderer::Painting& painting, std::unordered_map<LayerWrapper*, Contour>& contourMap);
static void handleLayerWrapper(LayerWrapper* nowLayer, QTransform transform, Renderer::Painting& painting, std::unordered_map<LayerWrapper*, Contour>& contourMap, const QSize& screenSize);
//static double getMaxLineWidth(LayerWrapper* root);
public:
static Renderer::Painting transfromToPainting(QString jsonFilePath);

View File

@ -272,8 +272,8 @@ namespace UnitTest
{1.00, Material{QColor(58,64,151)}}
};
return { BaseStyle(std::make_shared<TransformStyle>(),
std::make_shared<MaterialStyleStroke>(80, StrokeType::kRightSide, StrokeEndType::kFlatRound,
std::make_shared<StrokeRadialGradient>(materialMap, false), std::map<float, float>{ {0,1},{1,0}})) };
std::make_shared<MaterialStyleStroke>(90, StrokeType::kRightSide, StrokeEndType::kFlatRound,
std::make_shared<StrokeRadialGradient>(materialMap, false), std::map<float, float>{ {0.6,1},{0.8, 0.8},{0.94,0.6}, {0.96,0.6},{0.97,0.4},{1,0.1}})) };
}
} style;
TestGLWidget w(style, testPath);