增加图片刷新的槽函数

dev-LayerStyle
yang.yongquan 2023-03-15 17:37:12 +08:00
parent fa91d80b70
commit 5d88ddf0ca
4 changed files with 69 additions and 25 deletions

View File

@ -78,4 +78,14 @@ void ElementPoolWidget::setElementManager(ElementManager* element)
void ElementPoolWidget::refresh() {
this->setElementList(this->elementManager->elements);
// update();
}
void ElementPoolWidget::refreshPicture(GraphicElement* element) {
for (int i = 0; i < elements.size(); i++) {
if (element == elements[i]) {
pictureList->item(i)->setIcon(element->getPaintObject().getDetail().scaled(QSize(iconWidth - 25, iconHeight - 25)));
// update();
return;
}
}
}

View File

@ -28,5 +28,6 @@ signals:
public slots:
int pictureItemClicked(QListWidgetItem* item);
void refresh();
void refreshPicture(GraphicElement* element);
};

View File

@ -2,16 +2,26 @@
#include <QFile>
#include <QJsondocument>
#include "PainterPathUtil.h"
#include <queue>
using Renderer::Painting;
using Renderer::Element;
using Renderer::ElementTransform;
using glm::bvec2;
using std::max;
using std::shared_ptr;
using std::make_shared;
using std::min;
using std::queue;
const double PaintingUtil::pi = acos(-1);
struct LayerNode {
LayerWrapper* nowLayer;
QTransform transfrom;
bvec2 flip;
};
QJsonObject PaintingUtil::readJsonFile(QString jsonFilePath) {
QFile jsonFile(jsonFilePath);
jsonFile.open(QFile::ReadOnly);
@ -28,29 +38,47 @@ Painting PaintingUtil::transfromToPainting(QString jsonFilePath) {
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);
shared_ptr<ElementManager> elementManager = make_shared<ElementManager>(jsonObj, Renderer::ElementRenderer::instance());
shared_ptr<LayerManager> layerManager = make_shared<LayerManager>(jsonObj, elementManager.get());
//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);
//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;
queue<LayerNode> layerQueue;
LayerWrapper* root = layerManager->getRoot();
root->getCache();
layerQueue.push({ root, transform, flip });
while (!layerQueue.empty()) {
auto layerNode = layerQueue.front();
layerQueue.pop();
FolderLayerWrapper* nowLayer = handleLayerWrapper(layerNode.nowLayer, layerNode.transfrom, layerNode.flip, painting);
if (nowLayer != nullptr) {
for (auto sonLayer : nowLayer->children) {
layerQueue.push({ sonLayer.get(), layerNode.transfrom, layerNode.flip});
}
}
}
return painting;
}
void PaintingUtil::traverseLayTree(LayerWrapper* nowLayer, QTransform transform, bvec2 flip, Painting& painting) {
FolderLayerWrapper* PaintingUtil::handleLayerWrapper(LayerWrapper* nowLayer, QTransform& transform, bvec2& flip, Painting& painting) {
LeafLayerWrapper* leafLayer = dynamic_cast<LeafLayerWrapper*>(nowLayer);
PixelPath pixelPath = nowLayer->getCache();
QPainterPath painterPath = pixelPath.getPainterPath();
QRectF bound = painterPath.boundingRect();
flip ^= bvec2(nowLayer->property.flipHorizontally, nowLayer->property.flipVertically);
transform = nowLayer->property.transform * transform;
if (leafLayer != nullptr) {
qDebug() << leafLayer<<"------" << painterPath;
GroupElement* wrapperElement = dynamic_cast<GroupElement*>(leafLayer->wrappedElement);
if (wrapperElement != nullptr)
return wrapperElement->sourceLayer;
PixelPath pixelPath = nowLayer->getCache();
QPainterPath painterPath = pixelPath.getPainterPath();
QRectF bound = painterPath.boundingRect();
//qDebug() << leafLayer<<"------" << painterPath;
//qDebug() << transform;
Element element;
ElementTransform elementTrans;
element.ratio = bound.width() / bound.height();
@ -60,36 +88,40 @@ void PaintingUtil::traverseLayTree(LayerWrapper* nowLayer, QTransform transform,
trans.scale(1 / bound.width(), 1 / bound.height());
trans.translate(-bound.center().x(), -bound.center().y());
qDebug() << trans.map(painterPath);
element.contour = std::make_shared<vector<vector<Renderer::Point> >>(PainterPathUtil::transformToLines(trans.map(painterPath)));
QSize screenSize = pixelPath.getPixmap().size();
element.style = std::make_shared<Renderer::ElementStyleStrokeDemo>(0.06);
painterPath = transform.map(painterPath);
qDebug() << painterPath;
bound = painterPath.boundingRect();
qDebug() << bound;
elementTrans.center = glm::vec2(
(bound.center().x() - screenSize.width()) / screenSize.width(),
(bound.center().y() - screenSize.height()) / screenSize.height()
(2 * bound.center().x() - screenSize.width()) / screenSize.width(),
(2 * bound.center().y() - screenSize.height()) / screenSize.height()
);
qDebug() << elementTrans.center.x << elementTrans.center.y;
decomposeTransform(transform, elementTrans.rotation, elementTrans.scale);
elementTrans.scale = glm::vec2(
bound.width() / screenSize.width(),
bound.height() / screenSize.height()
);
elementTrans.flip = glm::bvec2(
nowLayer->property.flipHorizontally,
nowLayer->property.flipVertically
);
qDebug() << elementTrans.scale.x << elementTrans.scale.y;
painting.addElement(element, elementTrans);
return;
return nullptr;
}
FolderLayerWrapper* folderLayer = dynamic_cast<FolderLayerWrapper*>(nowLayer);
if (folderLayer != nullptr) {
for (auto sonLayer : folderLayer->children) {
traverseLayTree(sonLayer.get(), transform, flip, painting);
}
}
return;
return folderLayer;
}
void PaintingUtil::decomposeTransform(QTransform trans, float& angle, glm::vec2& scale) {
qDebug() << trans;
//qDebug() << trans;
trans.setMatrix(
trans.m11(), trans.m12(), trans.m13(),
trans.m21(), trans.m22(), trans.m23(),
@ -134,7 +166,8 @@ void PaintingUtil::decomposeTransform(QTransform trans, float& angle, glm::vec2&
angle = 360 - angle;
}
qDebug() << angle;
R = R.inverted() * trans;
scale = glm::vec2(R.m11(), R.m22());
//R = R.inverted() * trans;
//scale = glm::vec2(R.m11(), R.m22());
//qDebug() << scale.x << scale.y;
return;
}

View File

@ -7,7 +7,7 @@ class PaintingUtil
private:
static const double pi;
static QJsonObject readJsonFile(QString jsonFilePath);
static void traverseLayTree(LayerWrapper* nowLayer, QTransform transform, glm::bvec2 flip, Renderer::Painting& painting);
static FolderLayerWrapper* handleLayerWrapper(LayerWrapper* nowLayer, QTransform& transform, glm::bvec2& flip, Renderer::Painting& painting);
public:
static Renderer::Painting transfromToPainting(QString jsonFilePath);
static void decomposeTransform(QTransform trans, float& angle, glm::vec2& scale);