diff --git a/ArchitectureColoredPainting/EditorWidgetItem.ui b/ArchitectureColoredPainting/EditorWidgetItem.ui index 93811f0..aea28b0 100644 --- a/ArchitectureColoredPainting/EditorWidgetItem.ui +++ b/ArchitectureColoredPainting/EditorWidgetItem.ui @@ -6,8 +6,8 @@ 0 0 - 1124 - 1010 + 1473 + 1103 @@ -56,7 +56,20 @@ - + + + + 1080 + 1080 + + + + + 1080 + 1080 + + + diff --git a/ArchitectureColoredPainting/src/Editor/EditorWidgetItem.cpp b/ArchitectureColoredPainting/src/Editor/EditorWidgetItem.cpp index af02032..0a3f01b 100644 --- a/ArchitectureColoredPainting/src/Editor/EditorWidgetItem.cpp +++ b/ArchitectureColoredPainting/src/Editor/EditorWidgetItem.cpp @@ -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) diff --git a/ArchitectureColoredPainting/src/Editor/LayerManager.cpp b/ArchitectureColoredPainting/src/Editor/LayerManager.cpp index a9b73b8..958e958 100644 --- a/ArchitectureColoredPainting/src/Editor/LayerManager.cpp +++ b/ArchitectureColoredPainting/src/Editor/LayerManager.cpp @@ -11,9 +11,9 @@ 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); + auto p = root->getCache(selecetedLayer).resizedPixel(size); painter->drawPixmap(0, 0, p); } bool LayerManager::singleSelectedCheck() const diff --git a/ArchitectureColoredPainting/src/Editor/LayerManager.h b/ArchitectureColoredPainting/src/Editor/LayerManager.h index 390cfed..6f065fc 100644 --- a/ArchitectureColoredPainting/src/Editor/LayerManager.h +++ b/ArchitectureColoredPainting/src/Editor/LayerManager.h @@ -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; diff --git a/ArchitectureColoredPainting/src/Editor/LayerWrapper.cpp b/ArchitectureColoredPainting/src/Editor/LayerWrapper.cpp index c149185..a38eff5 100644 --- a/ArchitectureColoredPainting/src/Editor/LayerWrapper.cpp +++ b/ArchitectureColoredPainting/src/Editor/LayerWrapper.cpp @@ -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; } @@ -82,28 +86,29 @@ void LayerWrapper::SimpleProperty::apply(PixelPath&cache) const double centerY = cache.getBoundingRect().center().y(); //qDebug() << name << " " << cache.boundingRect().center(); //qDebug() << name << " " << cache.boundingRect(); + trans.translate(centerX, centerY); trans.translate(offset.x(), offset.y()); - trans.translate(-centerX, -centerY); + qDebug() << offset; trans.rotate(rotation); trans.scale(scale.x(), scale.y()); - trans.translate(centerX, centerY); + trans.translate(-centerX, -centerY); cache = cache.trans(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) diff --git a/ArchitectureColoredPainting/src/Editor/LayerWrapper.h b/ArchitectureColoredPainting/src/Editor/LayerWrapper.h index 84e7cab..5728b70 100644 --- a/ArchitectureColoredPainting/src/Editor/LayerWrapper.h +++ b/ArchitectureColoredPainting/src/Editor/LayerWrapper.h @@ -47,10 +47,10 @@ class LayerWrapper void apply(PixelPath&cache) const; } 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); FolderLayerWrapper*getParent() const; // invoke by manager, then invoke parent's applyStyles LayerWrapper(QJsonObject json, FolderLayerWrapper*parent, ElementManager* elementManager=nullptr); LayerWrapper() = default; @@ -75,7 +75,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 child); @@ -97,7 +97,7 @@ 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; diff --git a/ArchitectureColoredPainting/src/Editor/PixelPath.cpp b/ArchitectureColoredPainting/src/Editor/PixelPath.cpp index 447f8aa..89f4bbc 100644 --- a/ArchitectureColoredPainting/src/Editor/PixelPath.cpp +++ b/ArchitectureColoredPainting/src/Editor/PixelPath.cpp @@ -102,4 +102,19 @@ QPixmap PixelPath::getDetail()const qDebug() << rect; 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(); } \ No newline at end of file diff --git a/ArchitectureColoredPainting/src/Editor/PixelPath.h b/ArchitectureColoredPainting/src/Editor/PixelPath.h index 33268db..a764ce8 100644 --- a/ArchitectureColoredPainting/src/Editor/PixelPath.h +++ b/ArchitectureColoredPainting/src/Editor/PixelPath.h @@ -26,4 +26,5 @@ public: PixelPath trans(QTransform& mat)const; QPixmap resizedPixel(QSize size)const; QPixmap getDetail()const; + void highLight(); }; \ No newline at end of file diff --git a/ArchitectureColoredPainting/src/Editor/PreviewWindow.cpp b/ArchitectureColoredPainting/src/Editor/PreviewWindow.cpp index af17bbf..723f0b1 100644 --- a/ArchitectureColoredPainting/src/Editor/PreviewWindow.cpp +++ b/ArchitectureColoredPainting/src/Editor/PreviewWindow.cpp @@ -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(); }