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