From 5d5ea2307f33a4f2de22e74ff150a1a7f863a12b Mon Sep 17 00:00:00 2001 From: karlis <2995621482@qq.com> Date: Thu, 23 Mar 2023 16:17:01 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=8D=95=E5=90=91=E6=B8=B2?= =?UTF-8?q?=E6=9F=93=E9=80=BB=E8=BE=91=E5=92=8C=E5=86=85=E5=AD=98=E5=BC=BA?= =?UTF-8?q?=E5=88=B6=E5=9B=9E=E6=94=B6=E6=8E=AA=E6=96=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ArchitectureColoredPainting.vcxproj | 2 +- .../ArchitectureColoredPainting.vcxproj.filters | 6 +++--- .../src/Editor/ElementManager.cpp | 8 ++++++++ ArchitectureColoredPainting/src/Editor/ElementManager.h | 5 ++++- .../src/Editor/GraphicElement.cpp | 9 +++++---- ArchitectureColoredPainting/src/Editor/GraphicElement.h | 1 + 6 files changed, 22 insertions(+), 9 deletions(-) diff --git a/ArchitectureColoredPainting/ArchitectureColoredPainting.vcxproj b/ArchitectureColoredPainting/ArchitectureColoredPainting.vcxproj index 4d9e8c2..5e66811 100644 --- a/ArchitectureColoredPainting/ArchitectureColoredPainting.vcxproj +++ b/ArchitectureColoredPainting/ArchitectureColoredPainting.vcxproj @@ -212,7 +212,7 @@ - + diff --git a/ArchitectureColoredPainting/ArchitectureColoredPainting.vcxproj.filters b/ArchitectureColoredPainting/ArchitectureColoredPainting.vcxproj.filters index 75a8390..4092917 100644 --- a/ArchitectureColoredPainting/ArchitectureColoredPainting.vcxproj.filters +++ b/ArchitectureColoredPainting/ArchitectureColoredPainting.vcxproj.filters @@ -329,6 +329,9 @@ Header Files + + Header Files\Editor\Element + @@ -519,9 +522,6 @@ Header Files\Editor\util - - Header Files\Editor\Element - Header Files\Editor\Element diff --git a/ArchitectureColoredPainting/src/Editor/ElementManager.cpp b/ArchitectureColoredPainting/src/Editor/ElementManager.cpp index 2f601aa..5c46d99 100644 --- a/ArchitectureColoredPainting/src/Editor/ElementManager.cpp +++ b/ArchitectureColoredPainting/src/Editor/ElementManager.cpp @@ -18,6 +18,14 @@ ElementManager::ElementManager(QJsonObject source, QString fileHome) } for (auto element : elements) element->index = index++; + timer = new QTimer(); + timer->setInterval(30000); + connect(timer, &QTimer::timeout, this, [this]() { + for (auto element : elements) + if (typeid(*element) == typeid(SimpleElement)) + ((SimpleElement*)element)->forceRefresh = true; + }); + timer->start(); } void ElementManager::addElement(GraphicElement *element) diff --git a/ArchitectureColoredPainting/src/Editor/ElementManager.h b/ArchitectureColoredPainting/src/Editor/ElementManager.h index 7cb3839..17803b4 100644 --- a/ArchitectureColoredPainting/src/Editor/ElementManager.h +++ b/ArchitectureColoredPainting/src/Editor/ElementManager.h @@ -4,17 +4,20 @@ #include #include "../Renderer/Preview/ElementRenderer.h" #include +#include using std::vector; class LayerManager; class GraphicElement; class Renderer::ElementRenderer; class FolderLayerWrapper; -class ElementManager +class ElementManager : public QObject { + Q_OBJECT public: vector elements; QString fileHome; + QTimer* timer; public: ElementManager(QJsonObject source, QString fileHome); diff --git a/ArchitectureColoredPainting/src/Editor/GraphicElement.cpp b/ArchitectureColoredPainting/src/Editor/GraphicElement.cpp index 580d3a3..bcee199 100644 --- a/ArchitectureColoredPainting/src/Editor/GraphicElement.cpp +++ b/ArchitectureColoredPainting/src/Editor/GraphicElement.cpp @@ -112,12 +112,12 @@ void SimpleElement::paint(QPainter* painter, QTransform transform, const LayerSt maxScale = std::max(fabs(transform.m11() / cos(angle)), fabs(transform.m22() / cos(angle))); else maxScale = std::max(fabs(transform.m12() / sin(angle)), fabs(transform.m21() / sin(angle))); - //double pixelRatio = maxScale * QGuiApplication::primaryScreen()->devicePixelRatio(); - double pixelRatio = 5; - if (painterPath == painterPathPrev && styles.getHash() == stylesHashValue && fabs(pixelRatio - pixelRatioPrev) < 1e-3) + double pixelRatio = maxScale * QGuiApplication::primaryScreen()->devicePixelRatio(); + //double pixelRatio = 5; + if (painterPath == painterPathPrev && styles.getHash() == stylesHashValue && pixelRatioPrev >= pixelRatio && !forceRefresh) { transform.translate(movPrev.x(), movPrev.y()); - painter->setTransform(transform.scale(1 / pixelRatio, 1 / pixelRatio)); + painter->setTransform(transform.scale(1 / pixelRatioPrev, 1 / pixelRatioPrev)); painter->drawImage(0, 0, imagePrev); } else @@ -131,6 +131,7 @@ void SimpleElement::paint(QPainter* painter, QTransform transform, const LayerSt imagePrev = img; movPrev = mov; pixelRatioPrev = pixelRatio; + forceRefresh = false; } } diff --git a/ArchitectureColoredPainting/src/Editor/GraphicElement.h b/ArchitectureColoredPainting/src/Editor/GraphicElement.h index 6e6c301..7962d5c 100644 --- a/ArchitectureColoredPainting/src/Editor/GraphicElement.h +++ b/ArchitectureColoredPainting/src/Editor/GraphicElement.h @@ -61,6 +61,7 @@ public: void paint(QPainter* painter, QTransform transform, const LayerStyleContainer& styles) override; bool isClosed() const override; void paintPreview(QPainter* painter) override; + bool forceRefresh = false; }; class GroupElement : public GraphicElement