bug:黑屏
parent
4c9fe168a9
commit
3f1421a1bd
|
@ -13,8 +13,8 @@ LayerWrapper *LayerManager::getRoot() const
|
||||||
}
|
}
|
||||||
void LayerManager::paint(QPainter *painter, QSize size,LayerWrapper* selecetedLayer) const
|
void LayerManager::paint(QPainter *painter, QSize size,LayerWrapper* selecetedLayer) const
|
||||||
{
|
{
|
||||||
auto p = root->getCache(selecetedLayer).resizedPixel(size);
|
root->getCache();
|
||||||
painter->drawPixmap(0, 0, p);
|
root->paint(painter);
|
||||||
}
|
}
|
||||||
bool LayerManager::singleSelectedCheck() const
|
bool LayerManager::singleSelectedCheck() const
|
||||||
{
|
{
|
||||||
|
|
|
@ -79,6 +79,7 @@ LeafLayerWrapper::LeafLayerWrapper(QJsonObject json, ElementManager *elementMana
|
||||||
int elementIndex = json.value("element").toInt();
|
int elementIndex = json.value("element").toInt();
|
||||||
wrappedElement = elementManager->getElementById(elementIndex);
|
wrappedElement = elementManager->getElementById(elementIndex);
|
||||||
}
|
}
|
||||||
|
|
||||||
void LayerWrapper::SimpleProperty::apply(PixelPath&cache) const
|
void LayerWrapper::SimpleProperty::apply(PixelPath&cache) const
|
||||||
{
|
{
|
||||||
QTransform trans;
|
QTransform trans;
|
||||||
|
@ -88,12 +89,27 @@ void LayerWrapper::SimpleProperty::apply(PixelPath&cache) const
|
||||||
//qDebug() << name << " " << cache.boundingRect();
|
//qDebug() << name << " " << cache.boundingRect();
|
||||||
trans.translate(centerX, centerY);
|
trans.translate(centerX, centerY);
|
||||||
trans.translate(offset.x(), offset.y());
|
trans.translate(offset.x(), offset.y());
|
||||||
qDebug() << offset;
|
|
||||||
trans.rotate(rotation);
|
trans.rotate(rotation);
|
||||||
trans.scale(scale.x(), scale.y());
|
trans.scale(scale.x(), scale.y());
|
||||||
trans.translate(-centerX, -centerY);
|
trans.translate(-centerX, -centerY);
|
||||||
cache = cache.trans(trans);
|
cache = cache.trans(trans);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QTransform LayerWrapper::getTransform()
|
||||||
|
{
|
||||||
|
QTransform trans;
|
||||||
|
double centerX = cache.getBoundingRect().center().x();
|
||||||
|
double centerY = cache.getBoundingRect().center().y();
|
||||||
|
//qDebug() << name << " " << cache.boundingRect().center();
|
||||||
|
//qDebug() << name << " " << cache.boundingRect();
|
||||||
|
trans.translate(centerX, centerY);
|
||||||
|
trans.translate(property.offset.x(), property.offset.y());
|
||||||
|
trans.rotate(property.rotation);
|
||||||
|
trans.scale(property.scale.x(), property.scale.y());
|
||||||
|
trans.translate(-centerX, -centerY);
|
||||||
|
return trans;
|
||||||
|
}
|
||||||
|
|
||||||
void LayerWrapper::refresh(LayerWrapper* layer)
|
void LayerWrapper::refresh(LayerWrapper* layer)
|
||||||
{
|
{
|
||||||
property.apply(cache);
|
property.apply(cache);
|
||||||
|
@ -233,3 +249,32 @@ int FolderLayerWrapper::getReferencedBy()const
|
||||||
else
|
else
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void LayerWrapper::paint(QPainter* painter)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void FolderLayerWrapper::paint(QPainter* painter)
|
||||||
|
{
|
||||||
|
for (auto& child : children)
|
||||||
|
child->paint(painter);
|
||||||
|
}
|
||||||
|
|
||||||
|
void LeafLayerWrapper::paint(QPainter* painter)
|
||||||
|
{
|
||||||
|
if (wrappedElement != nullptr)
|
||||||
|
{
|
||||||
|
//painter->save();
|
||||||
|
QTransform trans;
|
||||||
|
LayerWrapper* layer = this;
|
||||||
|
while (layer != nullptr) {
|
||||||
|
trans *= layer->getTransform();
|
||||||
|
layer = layer->getParent();
|
||||||
|
}
|
||||||
|
auto p = wrappedElement->getPaintObject(&this->styles);
|
||||||
|
p.trans(trans);
|
||||||
|
painter->drawPixmap(0, 0, p.getPixmap());
|
||||||
|
//painter->restore();
|
||||||
|
}
|
||||||
|
}
|
|
@ -51,9 +51,11 @@ class LayerWrapper
|
||||||
virtual QTreeWidgetItem* getQTreeItem();
|
virtual QTreeWidgetItem* getQTreeItem();
|
||||||
// TODO: 将QPainterPath改为BitmapPath/QImage,或者直接将其删除,绘制时直接使用BitmapPath的paint方法
|
// TODO: 将QPainterPath改为BitmapPath/QImage,或者直接将其删除,绘制时直接使用BitmapPath的paint方法
|
||||||
virtual PixelPath getCache(LayerWrapper* selectedLayer=nullptr);
|
virtual PixelPath getCache(LayerWrapper* selectedLayer=nullptr);
|
||||||
|
QTransform getTransform();
|
||||||
FolderLayerWrapper*getParent() const; // invoke by manager, then invoke parent's applyStyles
|
FolderLayerWrapper*getParent() const; // invoke by manager, then invoke parent's applyStyles
|
||||||
LayerWrapper(QJsonObject json, FolderLayerWrapper*parent, ElementManager* elementManager=nullptr);
|
LayerWrapper(QJsonObject json, FolderLayerWrapper*parent, ElementManager* elementManager=nullptr);
|
||||||
LayerWrapper() = default;
|
LayerWrapper() = default;
|
||||||
|
virtual void paint(QPainter* painter);
|
||||||
// TODO : export Function
|
// TODO : export Function
|
||||||
// virtual LayerWrapper *addChild() = 0; // Leaf Child Only
|
// virtual LayerWrapper *addChild() = 0; // Leaf Child Only
|
||||||
// virtual LayerWrapper *addParent() = 0; // Folder Parent Only
|
// virtual LayerWrapper *addParent() = 0; // Folder Parent Only
|
||||||
|
@ -86,6 +88,7 @@ class FolderLayerWrapper : public LayerWrapper
|
||||||
QTreeWidgetItem* getQTreeItem() override;
|
QTreeWidgetItem* getQTreeItem() override;
|
||||||
QJsonObject toJson() const override;
|
QJsonObject toJson() const override;
|
||||||
int getReferencedBy()const;
|
int getReferencedBy()const;
|
||||||
|
void paint(QPainter* painter) override;
|
||||||
};
|
};
|
||||||
|
|
||||||
class LeafLayerWrapper : public LayerWrapper
|
class LeafLayerWrapper : public LayerWrapper
|
||||||
|
@ -101,6 +104,7 @@ class LeafLayerWrapper : public LayerWrapper
|
||||||
LeafLayerWrapper() = default;
|
LeafLayerWrapper() = default;
|
||||||
LeafLayerWrapper(QJsonObject json, ElementManager *elementManager, FolderLayerWrapper*parent);
|
LeafLayerWrapper(QJsonObject json, ElementManager *elementManager, FolderLayerWrapper*parent);
|
||||||
QJsonObject toJson() const override;
|
QJsonObject toJson() const override;
|
||||||
|
void paint(QPainter* painter) override;
|
||||||
};
|
};
|
||||||
|
|
||||||
Q_DECLARE_METATYPE(LayerWrapper *)
|
Q_DECLARE_METATYPE(LayerWrapper *)
|
||||||
|
|
Loading…
Reference in New Issue