bug fix
parent
3f1421a1bd
commit
684c28dafd
|
@ -84,3 +84,18 @@ QJsonObject GraphicElement::toJson() const
|
||||||
result.insert("name", name);
|
result.insert("name", name);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void SimpleElement::paint(QPainter* painter, QTransform transform, vector<std::shared_ptr<LayerStyle>> styles)
|
||||||
|
{
|
||||||
|
Renderer::ElementStyleStrokeDemo demo(2);
|
||||||
|
auto [img, mov] = renderer->drawElement(painterPath, demo, 1.0);
|
||||||
|
painter->save();
|
||||||
|
painter->setTransform(transform);
|
||||||
|
painter->drawImage(mov, img);
|
||||||
|
painter->restore();
|
||||||
|
}
|
||||||
|
|
||||||
|
void GroupElement::paint(QPainter* painter, QTransform transform, vector<std::shared_ptr<LayerStyle>> styles)
|
||||||
|
{
|
||||||
|
sourceLayer->paint(painter, transform);
|
||||||
|
}
|
|
@ -28,6 +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;
|
||||||
};
|
};
|
||||||
|
|
||||||
class SimpleElement : public GraphicElement
|
class SimpleElement : public GraphicElement
|
||||||
|
@ -44,6 +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;
|
||||||
};
|
};
|
||||||
|
|
||||||
class GroupElement : public GraphicElement
|
class GroupElement : public GraphicElement
|
||||||
|
@ -58,6 +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;
|
||||||
};
|
};
|
||||||
|
|
||||||
//******************************** BitmapPath ********************************//
|
//******************************** BitmapPath ********************************//
|
||||||
|
|
|
@ -46,6 +46,7 @@ LayerWrapper::LayerWrapper(QJsonObject json, FolderLayerWrapper*parent, ElementM
|
||||||
property.scale = {transformJson.value("scale").toObject().value("x").toDouble(),
|
property.scale = {transformJson.value("scale").toObject().value("x").toDouble(),
|
||||||
transformJson.value("scale").toObject().value("y").toDouble()};
|
transformJson.value("scale").toObject().value("y").toDouble()};
|
||||||
property.rotation = {transformJson.value("rotation").toDouble()};
|
property.rotation = {transformJson.value("rotation").toDouble()};
|
||||||
|
selected = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
FolderLayerWrapper::FolderLayerWrapper(QJsonObject json, ElementManager *elementManager, FolderLayerWrapper*parent)
|
FolderLayerWrapper::FolderLayerWrapper(QJsonObject json, ElementManager *elementManager, FolderLayerWrapper*parent)
|
||||||
|
@ -80,19 +81,19 @@ LeafLayerWrapper::LeafLayerWrapper(QJsonObject json, ElementManager *elementMana
|
||||||
wrappedElement = elementManager->getElementById(elementIndex);
|
wrappedElement = elementManager->getElementById(elementIndex);
|
||||||
}
|
}
|
||||||
|
|
||||||
void LayerWrapper::SimpleProperty::apply(PixelPath&cache) const
|
void LayerWrapper::SimpleProperty::apply(PixelPath&cache)
|
||||||
{
|
{
|
||||||
QTransform trans;
|
transform.reset();
|
||||||
double centerX = cache.getBoundingRect().center().x();
|
double centerX = cache.getBoundingRect().center().x();
|
||||||
double centerY = cache.getBoundingRect().center().y();
|
double centerY = cache.getBoundingRect().center().y();
|
||||||
//qDebug() << name << " " << cache.boundingRect().center();
|
//qDebug() << name << " " << cache.boundingRect().center();
|
||||||
//qDebug() << name << " " << cache.boundingRect();
|
//qDebug() << name << " " << cache.boundingRect();
|
||||||
trans.translate(centerX, centerY);
|
transform.translate(-centerX, -centerY);
|
||||||
trans.translate(offset.x(), offset.y());
|
transform.translate(offset.x(), offset.y());
|
||||||
trans.rotate(rotation);
|
transform.rotate(rotation);
|
||||||
trans.scale(scale.x(), scale.y());
|
transform.scale(scale.x(), scale.y());
|
||||||
trans.translate(-centerX, -centerY);
|
transform.translate(centerX, centerY);
|
||||||
cache = cache.trans(trans);
|
cache = cache.trans(transform);
|
||||||
}
|
}
|
||||||
|
|
||||||
QTransform LayerWrapper::getTransform()
|
QTransform LayerWrapper::getTransform()
|
||||||
|
@ -250,31 +251,35 @@ int FolderLayerWrapper::getReferencedBy()const
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
void LayerWrapper::paint(QPainter* painter)
|
void LayerWrapper::paint(QPainter* painter, QTransform transform)
|
||||||
{
|
{
|
||||||
|
if (this->selected)
|
||||||
|
{
|
||||||
|
painter->save();
|
||||||
|
painter->setTransform(transform);
|
||||||
|
painter->setPen(QPen(Qt::gray, 2));
|
||||||
|
painter->setPen(Qt::DashLine);
|
||||||
|
painter->drawRect(cache.getBoundingRect());
|
||||||
|
painter->restore();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void FolderLayerWrapper::paint(QPainter* painter)
|
void FolderLayerWrapper::paint(QPainter* painter, QTransform transform)
|
||||||
{
|
{
|
||||||
|
LayerWrapper::paint(painter, transform);
|
||||||
|
transform = property.transform * transform;
|
||||||
|
qDebug() << transform;
|
||||||
for (auto& child : children)
|
for (auto& child : children)
|
||||||
child->paint(painter);
|
child->paint(painter, transform);
|
||||||
}
|
}
|
||||||
|
|
||||||
void LeafLayerWrapper::paint(QPainter* painter)
|
void LeafLayerWrapper::paint(QPainter* painter, QTransform transform)
|
||||||
{
|
{
|
||||||
|
LayerWrapper::paint(painter, transform);
|
||||||
|
transform = property.transform * transform;
|
||||||
|
qDebug() << transform;
|
||||||
if (wrappedElement != nullptr)
|
if (wrappedElement != nullptr)
|
||||||
{
|
{
|
||||||
//painter->save();
|
wrappedElement->paint(painter, transform, styles);
|
||||||
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();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -35,6 +35,7 @@ class LayerWrapper
|
||||||
|
|
||||||
public:
|
public:
|
||||||
QTreeWidgetItem* qTreeWidgetItem;
|
QTreeWidgetItem* qTreeWidgetItem;
|
||||||
|
bool selected;
|
||||||
struct SimpleProperty
|
struct SimpleProperty
|
||||||
{
|
{
|
||||||
QString name = "";
|
QString name = "";
|
||||||
|
@ -43,8 +44,9 @@ class LayerWrapper
|
||||||
double rotation = 0;
|
double rotation = 0;
|
||||||
bool flipHorizontally = 0;
|
bool flipHorizontally = 0;
|
||||||
bool flipVertically = 0;
|
bool flipVertically = 0;
|
||||||
|
QTransform transform;
|
||||||
// TODO: ½«QPainterPath¸ÄΪBitmapPath
|
// TODO: ½«QPainterPath¸ÄΪBitmapPath
|
||||||
void apply(PixelPath&cache) const;
|
void apply(PixelPath&cache);
|
||||||
} property;
|
} property;
|
||||||
virtual void setParent(FolderLayerWrapper*newParent);
|
virtual void setParent(FolderLayerWrapper*newParent);
|
||||||
virtual void refresh(LayerWrapper* layer = nullptr);
|
virtual void refresh(LayerWrapper* layer = nullptr);
|
||||||
|
@ -55,7 +57,7 @@ class LayerWrapper
|
||||||
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);
|
virtual void paint(QPainter* painter, QTransform transform=QTransform());
|
||||||
// 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
|
||||||
|
@ -88,7 +90,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;
|
void paint(QPainter* painter, QTransform transform = QTransform()) override;
|
||||||
};
|
};
|
||||||
|
|
||||||
class LeafLayerWrapper : public LayerWrapper
|
class LeafLayerWrapper : public LayerWrapper
|
||||||
|
@ -104,7 +106,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;
|
void paint(QPainter* painter, QTransform transform = QTransform()) override;
|
||||||
};
|
};
|
||||||
|
|
||||||
Q_DECLARE_METATYPE(LayerWrapper *)
|
Q_DECLARE_METATYPE(LayerWrapper *)
|
||||||
|
|
|
@ -87,13 +87,11 @@ void PreviewWindow::mouseMoveEvent(QMouseEvent* event)
|
||||||
currentLayer->property.offset.setX(currentLayer->property.offset.x() + dx);
|
currentLayer->property.offset.setX(currentLayer->property.offset.x() + dx);
|
||||||
currentLayer->property.offset.setY(currentLayer->property.offset.y() + dy);
|
currentLayer->property.offset.setY(currentLayer->property.offset.y() + dy);
|
||||||
qDebug() << dx << "----" << dy;
|
qDebug() << dx << "----" << dy;
|
||||||
emit layerInfoChanged();
|
|
||||||
}
|
}
|
||||||
else if (event->buttons() & Qt::RightButton) {
|
else if (event->buttons() & Qt::RightButton) {
|
||||||
// 如果按下的是右键,那么旋转图形
|
// 如果按下的是右键,那么旋转图形
|
||||||
qreal angle = -sqrt(dx * dx + dy * dy) / 1.0;
|
qreal angle = -sqrt(dx * dx + dy * dy) / 1.0;
|
||||||
currentLayer->property.rotation += angle;
|
currentLayer->property.rotation += angle;
|
||||||
emit layerInfoChanged();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// 更新上一次的位置
|
// 更新上一次的位置
|
||||||
|
@ -103,5 +101,5 @@ void PreviewWindow::mouseMoveEvent(QMouseEvent* event)
|
||||||
|
|
||||||
void PreviewWindow::mouseReleaseEvent(QMouseEvent* event)
|
void PreviewWindow::mouseReleaseEvent(QMouseEvent* event)
|
||||||
{
|
{
|
||||||
// 当鼠标释放时,不做任何操作
|
emit layerInfoChanged();
|
||||||
}
|
}
|
|
@ -12,9 +12,13 @@ LayerTreeWidget::LayerTreeWidget(QWidget *parent)
|
||||||
this->setHeaderLabel("Layer Content");
|
this->setHeaderLabel("Layer Content");
|
||||||
connect(this, &QTreeWidget::customContextMenuRequested, this, &LayerTreeWidget::popMenu);
|
connect(this, &QTreeWidget::customContextMenuRequested, this, &LayerTreeWidget::popMenu);
|
||||||
connect(this, &QTreeWidget::currentItemChanged, [=](QTreeWidgetItem *currentItem) {
|
connect(this, &QTreeWidget::currentItemChanged, [=](QTreeWidgetItem *currentItem) {
|
||||||
|
if (this->selectedItem != nullptr) {
|
||||||
|
this->selectedItem->data(0, Qt::UserRole).value<LayerWrapper*>()->selected = false;
|
||||||
|
}
|
||||||
this->selectedItem = currentItem;
|
this->selectedItem = currentItem;
|
||||||
if (this->selectedItem != nullptr) {
|
if (this->selectedItem != nullptr) {
|
||||||
auto layer = this->selectedItem->data(0, Qt::UserRole).value<LayerWrapper*>();
|
auto layer = this->selectedItem->data(0, Qt::UserRole).value<LayerWrapper*>();
|
||||||
|
layer->selected = true;
|
||||||
emit displayLayerChange(layer);
|
emit displayLayerChange(layer);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|
Loading…
Reference in New Issue