bug: pixmap溢出
parent
de9d7143b6
commit
4c9fe168a9
|
@ -6,8 +6,8 @@
|
||||||
<rect>
|
<rect>
|
||||||
<x>0</x>
|
<x>0</x>
|
||||||
<y>0</y>
|
<y>0</y>
|
||||||
<width>1124</width>
|
<width>1473</width>
|
||||||
<height>1010</height>
|
<height>1103</height>
|
||||||
</rect>
|
</rect>
|
||||||
</property>
|
</property>
|
||||||
<property name="minimumSize">
|
<property name="minimumSize">
|
||||||
|
@ -56,7 +56,20 @@
|
||||||
<widget class="QWidget" name="LeftBar" native="true"/>
|
<widget class="QWidget" name="LeftBar" native="true"/>
|
||||||
</item>
|
</item>
|
||||||
<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>
|
||||||
<item>
|
<item>
|
||||||
<widget class="QWidget" name="RightBar" native="true">
|
<widget class="QWidget" name="RightBar" native="true">
|
||||||
|
|
|
@ -59,7 +59,11 @@ EditorWidgetItem::~EditorWidgetItem()
|
||||||
|
|
||||||
void EditorWidgetItem::paintEvent(QPaintEvent *event)
|
void EditorWidgetItem::paintEvent(QPaintEvent *event)
|
||||||
{
|
{
|
||||||
|
QPainter painter(this);
|
||||||
|
|
||||||
|
// 设置画刷的颜色为灰色,并填充整个窗口区域
|
||||||
|
painter.setBrush(Qt::gray);
|
||||||
|
painter.drawRect(this->rect());
|
||||||
}
|
}
|
||||||
|
|
||||||
void EditorWidgetItem::onLayerChange(LayerWrapper *layer)
|
void EditorWidgetItem::onLayerChange(LayerWrapper *layer)
|
||||||
|
|
|
@ -11,9 +11,9 @@ LayerWrapper *LayerManager::getRoot() const
|
||||||
{
|
{
|
||||||
return root;
|
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);
|
auto p = root->getCache(selecetedLayer).resizedPixel(size);
|
||||||
painter->drawPixmap(0, 0, p);
|
painter->drawPixmap(0, 0, p);
|
||||||
}
|
}
|
||||||
bool LayerManager::singleSelectedCheck() const
|
bool LayerManager::singleSelectedCheck() const
|
||||||
|
|
|
@ -32,7 +32,7 @@ class LayerManager
|
||||||
LayerManager() = default;
|
LayerManager() = default;
|
||||||
LayerManager(QJsonObject source, ElementManager* elementManager);
|
LayerManager(QJsonObject source, ElementManager* elementManager);
|
||||||
QJsonObject toJson() const;
|
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 rename(QString newName) const;
|
||||||
bool combine() const;
|
bool combine() const;
|
||||||
// bool seperate() const;
|
// bool seperate() const;
|
||||||
|
|
|
@ -23,9 +23,13 @@ FolderLayerWrapper*LayerWrapper::getParent() const
|
||||||
return this == nullptr ? nullptr : this->parent;
|
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;
|
return cache;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -82,28 +86,29 @@ void LayerWrapper::SimpleProperty::apply(PixelPath&cache) const
|
||||||
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);
|
||||||
trans.translate(offset.x(), offset.y());
|
trans.translate(offset.x(), offset.y());
|
||||||
trans.translate(-centerX, -centerY);
|
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);
|
||||||
}
|
}
|
||||||
void LayerWrapper::refresh()
|
void LayerWrapper::refresh(LayerWrapper* layer)
|
||||||
{
|
{
|
||||||
property.apply(cache);
|
property.apply(cache);
|
||||||
}
|
}
|
||||||
|
|
||||||
void FolderLayerWrapper::refresh()
|
void FolderLayerWrapper::refresh(LayerWrapper* layer)
|
||||||
{
|
{
|
||||||
cache.clear();
|
cache.clear();
|
||||||
for (auto& child : children) {
|
for (auto& child : children) {
|
||||||
cache.addPath(child.get()->getCache());
|
cache.addPath(child.get()->getCache(layer));
|
||||||
}
|
}
|
||||||
LayerWrapper::refresh();
|
LayerWrapper::refresh();
|
||||||
}
|
}
|
||||||
|
|
||||||
void LeafLayerWrapper::refresh()
|
void LeafLayerWrapper::refresh(LayerWrapper* layer)
|
||||||
{
|
{
|
||||||
cache.clear();
|
cache.clear();
|
||||||
if (wrappedElement != nullptr)
|
if (wrappedElement != nullptr)
|
||||||
|
|
|
@ -47,10 +47,10 @@ class LayerWrapper
|
||||||
void apply(PixelPath&cache) const;
|
void apply(PixelPath&cache) const;
|
||||||
} property;
|
} property;
|
||||||
virtual void setParent(FolderLayerWrapper*newParent);
|
virtual void setParent(FolderLayerWrapper*newParent);
|
||||||
virtual void refresh();
|
virtual void refresh(LayerWrapper* layer = nullptr);
|
||||||
virtual QTreeWidgetItem* getQTreeItem();
|
virtual QTreeWidgetItem* getQTreeItem();
|
||||||
// TODO: 将QPainterPath改为BitmapPath/QImage,或者直接将其删除,绘制时直接使用BitmapPath的paint方法
|
// TODO: 将QPainterPath改为BitmapPath/QImage,或者直接将其删除,绘制时直接使用BitmapPath的paint方法
|
||||||
virtual PixelPath getCache();
|
virtual PixelPath getCache(LayerWrapper* selectedLayer=nullptr);
|
||||||
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;
|
||||||
|
@ -75,7 +75,7 @@ class FolderLayerWrapper : public LayerWrapper
|
||||||
public:
|
public:
|
||||||
|
|
||||||
~FolderLayerWrapper() = default;
|
~FolderLayerWrapper() = default;
|
||||||
void refresh() override;
|
void refresh(LayerWrapper* layer=nullptr) override;
|
||||||
FolderLayerWrapper() = default;
|
FolderLayerWrapper() = default;
|
||||||
FolderLayerWrapper(QJsonObject json, ElementManager *elementManager, FolderLayerWrapper*parent);
|
FolderLayerWrapper(QJsonObject json, ElementManager *elementManager, FolderLayerWrapper*parent);
|
||||||
void addChild(shared_ptr<LayerWrapper> child);
|
void addChild(shared_ptr<LayerWrapper> child);
|
||||||
|
@ -97,7 +97,7 @@ class LeafLayerWrapper : public LayerWrapper
|
||||||
|
|
||||||
public:
|
public:
|
||||||
~LeafLayerWrapper() = default;
|
~LeafLayerWrapper() = default;
|
||||||
void refresh() override;
|
void refresh(LayerWrapper* layer = nullptr) override;
|
||||||
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;
|
||||||
|
|
|
@ -102,4 +102,19 @@ QPixmap PixelPath::getDetail()const
|
||||||
qDebug() << rect;
|
qDebug() << rect;
|
||||||
result = pixmap.copy(rect);
|
result = pixmap.copy(rect);
|
||||||
return result;
|
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;
|
PixelPath trans(QTransform& mat)const;
|
||||||
QPixmap resizedPixel(QSize size)const;
|
QPixmap resizedPixel(QSize size)const;
|
||||||
QPixmap getDetail()const;
|
QPixmap getDetail()const;
|
||||||
|
void highLight();
|
||||||
};
|
};
|
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
PreviewWindow::PreviewWindow(QWidget *parent) : QOpenGLWidget(parent)
|
PreviewWindow::PreviewWindow(QWidget *parent) : QOpenGLWidget(parent)
|
||||||
{
|
{
|
||||||
|
this->setFixedSize(QSize(1080, 1080));
|
||||||
this->renderer = Renderer::ElementRenderer::instance();
|
this->renderer = Renderer::ElementRenderer::instance();
|
||||||
QSurfaceFormat surfaceFormat;
|
QSurfaceFormat surfaceFormat;
|
||||||
surfaceFormat.setSamples(16);
|
surfaceFormat.setSamples(16);
|
||||||
|
@ -47,15 +48,7 @@ void PreviewWindow::paintGL()
|
||||||
painter->begin(this);
|
painter->begin(this);
|
||||||
painter->setRenderHint(QPainter::Antialiasing);
|
painter->setRenderHint(QPainter::Antialiasing);
|
||||||
painter->setRenderHint(QPainter::HighQualityAntialiasing);
|
painter->setRenderHint(QPainter::HighQualityAntialiasing);
|
||||||
layerManager->paint(painter,this->size());
|
layerManager->paint(painter,this->size(),currentLayer);
|
||||||
if (currentLayer != nullptr)
|
|
||||||
{
|
|
||||||
QPen pen = painter->pen(); // 获取当前的画笔
|
|
||||||
pen.setStyle(Qt::DashLine); // 设置画笔样式为虚线
|
|
||||||
painter->setPen(pen); // 应用画笔设置
|
|
||||||
painter->drawRect(this->currentLayer->getCache().getBoundingRect()); // 绘制矩形
|
|
||||||
}
|
|
||||||
|
|
||||||
painter->end();
|
painter->end();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue