From 66cde802ecfbd64b5c919667048c930d3326e7b3 Mon Sep 17 00:00:00 2001 From: ArgonarioD Date: Sun, 19 Mar 2023 14:12:44 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=BAGraphicElement=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?=E4=BA=86isClosed=E6=8E=A5=E5=8F=A3=20|=20#11?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/Editor/GraphicElement.cpp | 15 ++++++++++++++- .../src/Editor/GraphicElement.h | 5 +++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/ArchitectureColoredPainting/src/Editor/GraphicElement.cpp b/ArchitectureColoredPainting/src/Editor/GraphicElement.cpp index 5c0acb0..4cc2ef3 100644 --- a/ArchitectureColoredPainting/src/Editor/GraphicElement.cpp +++ b/ArchitectureColoredPainting/src/Editor/GraphicElement.cpp @@ -17,7 +17,10 @@ void SimpleElement::loadSvgFile(const QString& filePath) // TODO 样式问题 SvgFileLoader loader; loader.loadSvgFile(filePath, painterPath); - qDebug() << "load svg file success " << painterPath.elementCount(); + auto startPoint = static_cast(painterPath.elementAt(0)); + auto endPoint = static_cast(painterPath.elementAt(painterPath.elementCount() - 1)); + this->closed = startPoint == endPoint; + qDebug() << "load svg file success " << painterPath.elementCount() << (isClosed() ? "is" : "not") << "closed"; } SimpleElement::SimpleElement(QJsonObject jsonSource) : jsonSource(jsonSource) @@ -117,11 +120,21 @@ void SimpleElement::paint(QPainter* painter, QTransform transform, const LayerSt painter->restore(); } +bool SimpleElement::isClosed() const +{ + return closed; +} + void GroupElement::paint(QPainter* painter, QTransform transform, const LayerStyleContainer& styles) { sourceLayer->paint(painter, transform); } +bool GroupElement::isClosed() const +{ + return false; +} + QPixmap SimpleElement::getPreview(QSize size) { diff --git a/ArchitectureColoredPainting/src/Editor/GraphicElement.h b/ArchitectureColoredPainting/src/Editor/GraphicElement.h index d0500b2..377b9e5 100644 --- a/ArchitectureColoredPainting/src/Editor/GraphicElement.h +++ b/ArchitectureColoredPainting/src/Editor/GraphicElement.h @@ -28,11 +28,14 @@ public: virtual PixelPath getPaintObject() const = 0; virtual PixelPath getPaintObject(const LayerStyleContainer& styles) const = 0; virtual void paint(QPainter* painter, QTransform transform, const LayerStyleContainer& styles) = 0; + virtual bool isClosed() const = 0; virtual QPixmap getPreview(QSize size) = 0; }; class SimpleElement : public GraphicElement { +private: + bool closed; public: QJsonObject jsonSource; // TODO: 改为ComposedPainterPath @@ -48,6 +51,7 @@ public: PixelPath getPaintObject() const override; PixelPath getPaintObject(const LayerStyleContainer& styles) const override; void paint(QPainter* painter, QTransform transform, const LayerStyleContainer& styles) override; + bool isClosed() const override; QPixmap getPreview(QSize size) override; }; @@ -65,6 +69,7 @@ public: PixelPath getPaintObject(const LayerStyleContainer& styles) const override; void setSourceLayer(FolderLayerWrapper* sourceLayer); void paint(QPainter* painter, QTransform transform, const LayerStyleContainer& styles) override; + bool isClosed() const override; QPixmap getPreview(QSize size) override; void collectReachable(std::set& set) const; };