From f25f2d2a81f4b0129713a90796b4097740dec961 Mon Sep 17 00:00:00 2001 From: karlis <2995621482@qq.com> Date: Mon, 20 Mar 2023 17:35:33 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=9E=E7=8E=B0=E9=AB=98=E4=BA=AE=E9=80=89?= =?UTF-8?q?=E4=B8=ADLayer?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/Editor/LayerManager.cpp | 13 ++++++++++ .../src/Editor/LayerWrapper.cpp | 26 ++++++++++++++++++- .../src/Editor/LayerWrapper.h | 1 + .../src/Editor/PixelPath.cpp | 3 ++- 4 files changed, 41 insertions(+), 2 deletions(-) diff --git a/ArchitectureColoredPainting/src/Editor/LayerManager.cpp b/ArchitectureColoredPainting/src/Editor/LayerManager.cpp index 06f0170..b1d2e60 100644 --- a/ArchitectureColoredPainting/src/Editor/LayerManager.cpp +++ b/ArchitectureColoredPainting/src/Editor/LayerManager.cpp @@ -13,8 +13,21 @@ LayerWrapper *LayerManager::getRoot() const } void LayerManager::paint(QPainter *painter, QSize size,LayerWrapper* selecetedLayer) const { + painter->save(); root->getCache(); root->paint(painter); + painter->restore(); + painter->save(); + // painter->setBrush(QBrush(Qt::white)); + //painter->setCompositionMode(QPainter::CompositionMode_Difference); + if (selecetedLayer != nullptr) + { + painter->setPen(QPen(Qt::gray, 2, Qt::DashLine)); + selecetedLayer->paintVisualBounding(painter); + //painter->setPen(QPen(Qt::gray, 2, Qt::DashDotLine)); + //selecetedLayer->paintVisualBounding(painter); + } + painter->restore(); } bool LayerManager::singleSelectedCheck() const { diff --git a/ArchitectureColoredPainting/src/Editor/LayerWrapper.cpp b/ArchitectureColoredPainting/src/Editor/LayerWrapper.cpp index 1240eb2..d2f1453 100644 --- a/ArchitectureColoredPainting/src/Editor/LayerWrapper.cpp +++ b/ArchitectureColoredPainting/src/Editor/LayerWrapper.cpp @@ -284,7 +284,14 @@ int FolderLayerWrapper::getReferencedBy()const void LayerWrapper::paint(QPainter* painter, QTransform transform, bool force) { - + // if (this->selected) + // { + // painter->save(); + //painter->setPen(QPen(Qt::red, 2)); + //painter->setTransform(transform); + //painter->drawRect(this->cache.getBoundingRect()); + //painter->restore(); + // } } void FolderLayerWrapper::paint(QPainter* painter, QTransform transform, bool force) @@ -428,4 +435,21 @@ bool LeafLayerWrapper::referencingGroupElement() const bool LayerWrapper::canApplyStyles() const { return typeid(*this) == typeid(LeafLayerWrapper) && !referencingGroupElement(); +} + +void LayerWrapper::paintVisualBounding(QPainter* painter) const +{ + if (hidden) + return; + QTransform transform; + auto layer = this->parent; + while (layer != nullptr) + { + transform = transform * layer->property.transform; + layer = layer->parent; + } + painter->save(); + painter->setTransform(transform); + painter->drawRect(cache.getBoundingRect()); + painter->restore(); } \ No newline at end of file diff --git a/ArchitectureColoredPainting/src/Editor/LayerWrapper.h b/ArchitectureColoredPainting/src/Editor/LayerWrapper.h index 6312f12..c45ec21 100644 --- a/ArchitectureColoredPainting/src/Editor/LayerWrapper.h +++ b/ArchitectureColoredPainting/src/Editor/LayerWrapper.h @@ -75,6 +75,7 @@ class LayerWrapper virtual size_t referencedCount(bool excludeSelf = false) const; virtual bool deleteable(bool excludeSubTree = false) const; virtual bool referencingGroupElement() const; + virtual void paintVisualBounding(QPainter* painter) const; bool canApplyStyles() const; }; diff --git a/ArchitectureColoredPainting/src/Editor/PixelPath.cpp b/ArchitectureColoredPainting/src/Editor/PixelPath.cpp index 3087f39..e673504 100644 --- a/ArchitectureColoredPainting/src/Editor/PixelPath.cpp +++ b/ArchitectureColoredPainting/src/Editor/PixelPath.cpp @@ -78,7 +78,8 @@ PixelPath PixelPath::trans(QTransform& mat)const painter.setTransform(mat); painter.drawPixmap(0, 0, pixmap); result.painterPath.addPath(this->painterPath); - result.boundingRect = mat.mapRect(boundingRect); + result.painterPath = mat.map(result.painterPath); + result.boundingRect = result.painterPath.boundingRect(); return result; }