From 2d44fd4d9f2b665123fe2be9f38adf1ba5c7bf1c Mon Sep 17 00:00:00 2001 From: ArgonarioD Date: Tue, 7 Feb 2023 15:57:59 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=BA=E6=96=B0=E7=9A=84QImage=E6=B8=B2?= =?UTF-8?q?=E6=9F=93=E6=96=B9=E5=BC=8F=E4=BF=AE=E6=94=B9=E4=BA=86=E5=A4=B4?= =?UTF-8?q?=E6=96=87=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 淇敼浜咷raphicElement銆丩ayerWrapper --- .../src/Editor/GraphicElement.h | 68 ++++++++++++++++--- .../src/Editor/LayerWrapper.h | 6 +- ArchitectureColoredPainting/src/main.cpp | 1 + 3 files changed, 65 insertions(+), 10 deletions(-) diff --git a/ArchitectureColoredPainting/src/Editor/GraphicElement.h b/ArchitectureColoredPainting/src/Editor/GraphicElement.h index a55327c..4228e52 100644 --- a/ArchitectureColoredPainting/src/Editor/GraphicElement.h +++ b/ArchitectureColoredPainting/src/Editor/GraphicElement.h @@ -4,37 +4,87 @@ #include #include #include + +#include "../Renderer/Painting/ElementStyle.h" + class LayerWrapper; class LeafLayerWrapper; class FolderLayerWrapper; +class ComposedPainterPath; class GraphicElement { - public: - QString name=""; +public: + QString name = ""; + // TODO: 改为BitmapPath virtual QPainterPath getPaintObject() const = 0; }; + class SimpleElement : public GraphicElement { - private: +private: QJsonObject jsonSource; + // TODO: 改为ComposedPainterPath QPainterPath painterPath; void loadSvgFile(const QString& filePath); - public: +public: SimpleElement(QJsonObject jsonSource); ~SimpleElement() = default; QPainterPath getPaintObject() const override; }; + class GroupElement : public GraphicElement { - public: - FolderLayerWrapper *sourceLayer; +public: + FolderLayerWrapper* sourceLayer; - public: +public: GroupElement() = default; - GroupElement(FolderLayerWrapper *mSourceLayer); + GroupElement(FolderLayerWrapper* mSourceLayer); ~GroupElement() = default; QPainterPath getPaintObject() const override; - void setSourceLayer(FolderLayerWrapper *sourceLayer); + void setSourceLayer(FolderLayerWrapper* sourceLayer); }; + +//******************************** BitmapPath ********************************// + +class BitmapPath +{ +protected: + QRectF boundingRect; + QImage stylesAppliedCache; + void applyTransformation(QTransform &transformation); + +public: + /** + * 用painter的引用将它的QImage画到画布上 + */ + virtual void paint(QPainter* painter) const = 0; + virtual QImage getStylesAppliedCache() const = 0; +}; + +class FolderBitmapPath : public BitmapPath +{ +public: + const vector children; + virtual QImage getStylesAppliedCache() const override; +}; + +/** + * 当获取cache的时候应该调用Render的接口 + */ +class ComposedPainterPath : public BitmapPath +{ +public: + /** + * 因为ElementStyle应该被应用至整个叶子图层节点,所以它应该只用zealed来确定某些Style是否应该被作用于该Path + */ + struct SinglePath { + shared_ptr path; + bool zealed; + }; + + const vector paths; + virtual QImage getStylesAppliedCache() const override; +}; \ No newline at end of file diff --git a/ArchitectureColoredPainting/src/Editor/LayerWrapper.h b/ArchitectureColoredPainting/src/Editor/LayerWrapper.h index b36fb74..456ac11 100644 --- a/ArchitectureColoredPainting/src/Editor/LayerWrapper.h +++ b/ArchitectureColoredPainting/src/Editor/LayerWrapper.h @@ -25,7 +25,8 @@ class LayerWrapper protected: shared_ptr parent; QPointF referencePoint; - vector styles; + // vector styles; + // TODO: 将cache移到子类,对Leaf用ComposedPainterPath,对Folder用FolderBitmapPath QPainterPath cache; public: @@ -38,10 +39,12 @@ class LayerWrapper double rotation = 0; bool flipHorizontally = 0; bool flipVertically = 0; + // TODO: 将QPainterPath改为BitmapPath void apply(QPainterPath &cache) const; } property; void setParent(LayerWrapper *newParent); virtual void refresh(); + // TODO: 将QPainterPath改为BitmapPath/QImage,或者直接将其删除,绘制时直接使用BitmapPath的paint方法 QPainterPath getCache(); LayerWrapper *getParent() const; // invoke by manager, then invoke parent's applyStyles LayerWrapper(QJsonObject json, LayerWrapper *parent); @@ -71,6 +74,7 @@ class LeafLayerWrapper : public LayerWrapper { public: GraphicElement *wrappedElement; + const vector styles; public: void refresh() override; diff --git a/ArchitectureColoredPainting/src/main.cpp b/ArchitectureColoredPainting/src/main.cpp index f1449eb..7758559 100644 --- a/ArchitectureColoredPainting/src/main.cpp +++ b/ArchitectureColoredPainting/src/main.cpp @@ -21,6 +21,7 @@ int main(int argc, char* argv[]) QApplication::setHighDpiScaleFactorRoundingPolicy(Qt::HighDpiScaleFactorRoundingPolicy::PassThrough); QApplication a(argc, argv); FramelessHelper::Core::setApplicationOSThemeAware(); + FramelessConfig::instance()->set(Global::Option::ForceNonNativeBackgroundBlur); FramelessConfig::instance()->set(Global::Option::EnableBlurBehindWindow); FramelessConfig::instance()->set(Global::Option::CenterWindowBeforeShow); MainWindow w;