Compare commits
3 Commits
de9d7143b6
...
72f0f78e64
Author | SHA1 | Date |
---|---|---|
karlis | 72f0f78e64 | |
karlis | 3f1421a1bd | |
karlis | 4c9fe168a9 |
|
@ -6,8 +6,8 @@
|
|||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>1124</width>
|
||||
<height>1010</height>
|
||||
<width>1473</width>
|
||||
<height>1103</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="minimumSize">
|
||||
|
@ -56,7 +56,20 @@
|
|||
<widget class="QWidget" name="LeftBar" native="true"/>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="PreviewWindow" name="Preview"/>
|
||||
<widget class="PreviewWindow" name="Preview">
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>1080</width>
|
||||
<height>1080</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="maximumSize">
|
||||
<size>
|
||||
<width>1080</width>
|
||||
<height>1080</height>
|
||||
</size>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QWidget" name="RightBar" native="true">
|
||||
|
|
|
@ -59,7 +59,11 @@ EditorWidgetItem::~EditorWidgetItem()
|
|||
|
||||
void EditorWidgetItem::paintEvent(QPaintEvent *event)
|
||||
{
|
||||
QPainter painter(this);
|
||||
|
||||
// 设置画刷的颜色为灰色,并填充整个窗口区域
|
||||
painter.setBrush(Qt::gray);
|
||||
painter.drawRect(this->rect());
|
||||
}
|
||||
|
||||
void EditorWidgetItem::onLayerChange(LayerWrapper *layer)
|
||||
|
|
|
@ -84,3 +84,18 @@ QJsonObject GraphicElement::toJson() const
|
|||
result.insert("name", name);
|
||||
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 PixelPath getPaintObject() 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
|
||||
|
@ -44,6 +45,7 @@ public:
|
|||
~SimpleElement() = default;
|
||||
PixelPath getPaintObject() 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
|
||||
|
@ -58,6 +60,7 @@ public:
|
|||
PixelPath getPaintObject() const override;
|
||||
PixelPath getPaintObject(std::vector<std::shared_ptr<LayerStyle>>*) const override;
|
||||
void setSourceLayer(FolderLayerWrapper* sourceLayer);
|
||||
void paint(QPainter* painter, QTransform transform, std::vector<std::shared_ptr<LayerStyle>> styles) override;
|
||||
};
|
||||
|
||||
//******************************** BitmapPath ********************************//
|
||||
|
|
|
@ -11,10 +11,10 @@ LayerWrapper *LayerManager::getRoot() const
|
|||
{
|
||||
return root;
|
||||
}
|
||||
void LayerManager::paint(QPainter *painter, QSize size) const
|
||||
void LayerManager::paint(QPainter *painter, QSize size,LayerWrapper* selecetedLayer) const
|
||||
{
|
||||
auto p = root->getCache().resizedPixel(size);
|
||||
painter->drawPixmap(0, 0, p);
|
||||
root->getCache();
|
||||
root->paint(painter);
|
||||
}
|
||||
bool LayerManager::singleSelectedCheck() const
|
||||
{
|
||||
|
|
|
@ -32,7 +32,7 @@ class LayerManager
|
|||
LayerManager() = default;
|
||||
LayerManager(QJsonObject source, ElementManager* elementManager);
|
||||
QJsonObject toJson() const;
|
||||
void paint(QPainter *painter, QSize size) const;
|
||||
void paint(QPainter *painter, QSize size, LayerWrapper* selecetedLayer=nullptr) const;
|
||||
bool rename(QString newName) const;
|
||||
bool combine() const;
|
||||
// bool seperate() const;
|
||||
|
|
|
@ -23,9 +23,13 @@ FolderLayerWrapper*LayerWrapper::getParent() const
|
|||
return this == nullptr ? nullptr : this->parent;
|
||||
}
|
||||
|
||||
PixelPath LayerWrapper::getCache()
|
||||
PixelPath LayerWrapper::getCache(LayerWrapper* selectedLayer)
|
||||
{
|
||||
this->refresh();
|
||||
this->refresh(selectedLayer);
|
||||
if (selectedLayer == this)
|
||||
{
|
||||
this->cache.highLight();
|
||||
}
|
||||
return cache;
|
||||
}
|
||||
|
||||
|
@ -42,6 +46,7 @@ LayerWrapper::LayerWrapper(QJsonObject json, FolderLayerWrapper*parent, ElementM
|
|||
property.scale = {transformJson.value("scale").toObject().value("x").toDouble(),
|
||||
transformJson.value("scale").toObject().value("y").toDouble()};
|
||||
property.rotation = {transformJson.value("rotation").toDouble()};
|
||||
selected = false;
|
||||
}
|
||||
|
||||
FolderLayerWrapper::FolderLayerWrapper(QJsonObject json, ElementManager *elementManager, FolderLayerWrapper*parent)
|
||||
|
@ -75,35 +80,52 @@ LeafLayerWrapper::LeafLayerWrapper(QJsonObject json, ElementManager *elementMana
|
|||
int elementIndex = json.value("element").toInt();
|
||||
wrappedElement = elementManager->getElementById(elementIndex);
|
||||
}
|
||||
void LayerWrapper::SimpleProperty::apply(PixelPath&cache) const
|
||||
|
||||
void LayerWrapper::SimpleProperty::apply(PixelPath&cache)
|
||||
{
|
||||
transform.reset();
|
||||
double centerX = cache.getBoundingRect().center().x();
|
||||
double centerY = cache.getBoundingRect().center().y();
|
||||
//qDebug() << name << " " << cache.boundingRect().center();
|
||||
//qDebug() << name << " " << cache.boundingRect();
|
||||
transform.translate(-centerX, -centerY);
|
||||
transform.translate(offset.x(), offset.y());
|
||||
transform.rotate(rotation);
|
||||
transform.scale(scale.x(), scale.y());
|
||||
transform.translate(centerX, centerY);
|
||||
cache = cache.trans(transform);
|
||||
}
|
||||
|
||||
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(offset.x(), offset.y());
|
||||
trans.translate(-centerX, -centerY);
|
||||
trans.rotate(rotation);
|
||||
trans.scale(scale.x(), scale.y());
|
||||
trans.translate(centerX, centerY);
|
||||
cache = cache.trans(trans);
|
||||
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()
|
||||
|
||||
void LayerWrapper::refresh(LayerWrapper* layer)
|
||||
{
|
||||
property.apply(cache);
|
||||
}
|
||||
|
||||
void FolderLayerWrapper::refresh()
|
||||
void FolderLayerWrapper::refresh(LayerWrapper* layer)
|
||||
{
|
||||
cache.clear();
|
||||
for (auto& child : children) {
|
||||
cache.addPath(child.get()->getCache());
|
||||
cache.addPath(child.get()->getCache(layer));
|
||||
}
|
||||
LayerWrapper::refresh();
|
||||
}
|
||||
|
||||
void LeafLayerWrapper::refresh()
|
||||
void LeafLayerWrapper::refresh(LayerWrapper* layer)
|
||||
{
|
||||
cache.clear();
|
||||
if (wrappedElement != nullptr)
|
||||
|
@ -228,3 +250,36 @@ int FolderLayerWrapper::getReferencedBy()const
|
|||
else
|
||||
return -1;
|
||||
}
|
||||
|
||||
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, QTransform transform)
|
||||
{
|
||||
LayerWrapper::paint(painter, transform);
|
||||
transform = property.transform * transform;
|
||||
qDebug() << transform;
|
||||
for (auto& child : children)
|
||||
child->paint(painter, transform);
|
||||
}
|
||||
|
||||
void LeafLayerWrapper::paint(QPainter* painter, QTransform transform)
|
||||
{
|
||||
LayerWrapper::paint(painter, transform);
|
||||
transform = property.transform * transform;
|
||||
qDebug() << transform;
|
||||
if (wrappedElement != nullptr)
|
||||
{
|
||||
wrappedElement->paint(painter, transform, styles);
|
||||
}
|
||||
}
|
|
@ -35,6 +35,7 @@ class LayerWrapper
|
|||
|
||||
public:
|
||||
QTreeWidgetItem* qTreeWidgetItem;
|
||||
bool selected;
|
||||
struct SimpleProperty
|
||||
{
|
||||
QString name = "";
|
||||
|
@ -43,17 +44,20 @@ class LayerWrapper
|
|||
double rotation = 0;
|
||||
bool flipHorizontally = 0;
|
||||
bool flipVertically = 0;
|
||||
QTransform transform;
|
||||
// TODO: 将QPainterPath改为BitmapPath
|
||||
void apply(PixelPath&cache) const;
|
||||
void apply(PixelPath&cache);
|
||||
} property;
|
||||
virtual void setParent(FolderLayerWrapper*newParent);
|
||||
virtual void refresh();
|
||||
virtual void refresh(LayerWrapper* layer = nullptr);
|
||||
virtual QTreeWidgetItem* getQTreeItem();
|
||||
// TODO: 将QPainterPath改为BitmapPath/QImage,或者直接将其删除,绘制时直接使用BitmapPath的paint方法
|
||||
virtual PixelPath getCache();
|
||||
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, QTransform transform=QTransform());
|
||||
// TODO : export Function
|
||||
// virtual LayerWrapper *addChild() = 0; // Leaf Child Only
|
||||
// virtual LayerWrapper *addParent() = 0; // Folder Parent Only
|
||||
|
@ -75,7 +79,7 @@ class FolderLayerWrapper : public LayerWrapper
|
|||
public:
|
||||
|
||||
~FolderLayerWrapper() = default;
|
||||
void refresh() override;
|
||||
void refresh(LayerWrapper* layer=nullptr) override;
|
||||
FolderLayerWrapper() = default;
|
||||
FolderLayerWrapper(QJsonObject json, ElementManager *elementManager, FolderLayerWrapper*parent);
|
||||
void addChild(shared_ptr<LayerWrapper> child);
|
||||
|
@ -86,6 +90,7 @@ class FolderLayerWrapper : public LayerWrapper
|
|||
QTreeWidgetItem* getQTreeItem() override;
|
||||
QJsonObject toJson() const override;
|
||||
int getReferencedBy()const;
|
||||
void paint(QPainter* painter, QTransform transform = QTransform()) override;
|
||||
};
|
||||
|
||||
class LeafLayerWrapper : public LayerWrapper
|
||||
|
@ -97,10 +102,11 @@ class LeafLayerWrapper : public LayerWrapper
|
|||
|
||||
public:
|
||||
~LeafLayerWrapper() = default;
|
||||
void refresh() override;
|
||||
void refresh(LayerWrapper* layer = nullptr) override;
|
||||
LeafLayerWrapper() = default;
|
||||
LeafLayerWrapper(QJsonObject json, ElementManager *elementManager, FolderLayerWrapper*parent);
|
||||
QJsonObject toJson() const override;
|
||||
void paint(QPainter* painter, QTransform transform = QTransform()) override;
|
||||
};
|
||||
|
||||
Q_DECLARE_METATYPE(LayerWrapper *)
|
||||
|
|
|
@ -103,3 +103,18 @@ QPixmap PixelPath::getDetail()const
|
|||
result = pixmap.copy(rect);
|
||||
return result;
|
||||
}
|
||||
|
||||
void PixelPath::highLight()
|
||||
{
|
||||
// 创建一个QPainter对象,关联到QPixmap对象
|
||||
QPainter painter(&pixmap);
|
||||
|
||||
// 设置画笔的颜色、宽度和样式
|
||||
painter.setPen(QPen(Qt::black, 1, Qt::DashLine));
|
||||
|
||||
// 绘制一个矩形,指定左上角和右下角的坐标
|
||||
painter.drawRect(boundingRect);
|
||||
|
||||
// 结束绘制
|
||||
painter.end();
|
||||
}
|
|
@ -26,4 +26,5 @@ public:
|
|||
PixelPath trans(QTransform& mat)const;
|
||||
QPixmap resizedPixel(QSize size)const;
|
||||
QPixmap getDetail()const;
|
||||
void highLight();
|
||||
};
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
PreviewWindow::PreviewWindow(QWidget *parent) : QOpenGLWidget(parent)
|
||||
{
|
||||
this->setFixedSize(QSize(1080, 1080));
|
||||
this->renderer = Renderer::ElementRenderer::instance();
|
||||
QSurfaceFormat surfaceFormat;
|
||||
surfaceFormat.setSamples(16);
|
||||
|
@ -47,15 +48,7 @@ void PreviewWindow::paintGL()
|
|||
painter->begin(this);
|
||||
painter->setRenderHint(QPainter::Antialiasing);
|
||||
painter->setRenderHint(QPainter::HighQualityAntialiasing);
|
||||
layerManager->paint(painter,this->size());
|
||||
if (currentLayer != nullptr)
|
||||
{
|
||||
QPen pen = painter->pen(); // 获取当前的画笔
|
||||
pen.setStyle(Qt::DashLine); // 设置画笔样式为虚线
|
||||
painter->setPen(pen); // 应用画笔设置
|
||||
painter->drawRect(this->currentLayer->getCache().getBoundingRect()); // 绘制矩形
|
||||
}
|
||||
|
||||
layerManager->paint(painter,this->size(),currentLayer);
|
||||
painter->end();
|
||||
}
|
||||
|
||||
|
|
|
@ -12,9 +12,13 @@ LayerTreeWidget::LayerTreeWidget(QWidget *parent)
|
|||
this->setHeaderLabel("Layer Content");
|
||||
connect(this, &QTreeWidget::customContextMenuRequested, this, &LayerTreeWidget::popMenu);
|
||||
connect(this, &QTreeWidget::currentItemChanged, [=](QTreeWidgetItem *currentItem) {
|
||||
if (this->selectedItem != nullptr) {
|
||||
this->selectedItem->data(0, Qt::UserRole).value<LayerWrapper*>()->selected = false;
|
||||
}
|
||||
this->selectedItem = currentItem;
|
||||
if (this->selectedItem != nullptr) {
|
||||
auto layer = this->selectedItem->data(0, Qt::UserRole).value<LayerWrapper*>();
|
||||
layer->selected = true;
|
||||
emit displayLayerChange(layer);
|
||||
}
|
||||
else {
|
||||
|
|
Loading…
Reference in New Issue