From bff4441e4129d5a40093fe12dd342a8e01ca6635 Mon Sep 17 00:00:00 2001 From: Grozamir <48309973+Grozamir@users.noreply.github.com> Date: Thu, 13 Jun 2024 19:45:46 +0700 Subject: [PATCH] Optimizing performance | Add shadow enabler --- docs/features.rst | 1 + examples/styles/main.cpp | 1 + include/QtNodes/internal/NodeStyle.hpp | 1 + resources/DefaultStyle.json | 1 + src/NodeGraphicsObject.cpp | 1 + src/NodeStyle.cpp | 14 ++++++++++++++ 6 files changed, 19 insertions(+) diff --git a/docs/features.rst b/docs/features.rst index 536e57480..9f379cbdd 100644 --- a/docs/features.rst +++ b/docs/features.rst @@ -196,6 +196,7 @@ the moment of writing this documentation. "GradientColor2": [64, 64, 64], "GradientColor3": [58, 58, 58], "ShadowColor": [20, 20, 20], + "ShadowEnabled": false, "FontColor" : "white", "FontColorFaded" : "gray", "ConnectionPointColor": [169, 169, 169], diff --git a/examples/styles/main.cpp b/examples/styles/main.cpp index 528780583..7afbaabda 100644 --- a/examples/styles/main.cpp +++ b/examples/styles/main.cpp @@ -52,6 +52,7 @@ static void setStyle() "GradientColor2": "mintcream", "GradientColor3": "mintcream", "ShadowColor": [200, 200, 200], + "ShadowEnabled": true, "FontColor": [10, 10, 10], "FontColorFaded": [100, 100, 100], "ConnectionPointColor": "white", diff --git a/include/QtNodes/internal/NodeStyle.hpp b/include/QtNodes/internal/NodeStyle.hpp index 5eca74924..85abc5612 100644 --- a/include/QtNodes/internal/NodeStyle.hpp +++ b/include/QtNodes/internal/NodeStyle.hpp @@ -34,6 +34,7 @@ class NODE_EDITOR_PUBLIC NodeStyle : public Style QColor GradientColor2; QColor GradientColor3; QColor ShadowColor; + bool ShadowEnabled; QColor FontColor; QColor FontColorFaded; diff --git a/resources/DefaultStyle.json b/resources/DefaultStyle.json index da8dfe84c..6893c1a9d 100644 --- a/resources/DefaultStyle.json +++ b/resources/DefaultStyle.json @@ -12,6 +12,7 @@ "GradientColor2": [64, 64, 64], "GradientColor3": [58, 58, 58], "ShadowColor": [20, 20, 20], + "ShadowEnabled": false, "FontColor" : "white", "FontColorFaded" : "gray", "ConnectionPointColor": [169, 169, 169], diff --git a/src/NodeGraphicsObject.cpp b/src/NodeGraphicsObject.cpp index aa727cdaa..3976de79b 100644 --- a/src/NodeGraphicsObject.cpp +++ b/src/NodeGraphicsObject.cpp @@ -37,6 +37,7 @@ NodeGraphicsObject::NodeGraphicsObject(BasicGraphicsScene &scene, NodeId nodeId) NodeStyle nodeStyle(nodeStyleJson); + if(nodeStyle.ShadowEnabled) { auto effect = new QGraphicsDropShadowEffect; effect->setOffset(4, 4); diff --git a/src/NodeStyle.cpp b/src/NodeStyle.cpp index a82bf8fe2..41b872bba 100644 --- a/src/NodeStyle.cpp +++ b/src/NodeStyle.cpp @@ -88,6 +88,18 @@ void NodeStyle::setNodeStyle(QString jsonText) values[#variable] = variable; \ } +#define NODE_STYLE_READ_BOOL(values, variable) \ + { \ + auto valueRef = values[#variable]; \ + NODE_STYLE_CHECK_UNDEFINED_VALUE(valueRef, variable) \ + variable = valueRef.toBool(); \ + } + +#define NODE_STYLE_WRITE_BOOL(values, variable) \ + { \ + values[#variable] = variable; \ + } + void NodeStyle::loadJson(QJsonObject const &json) { QJsonValue nodeStyleValues = json["NodeStyle"]; @@ -101,6 +113,7 @@ void NodeStyle::loadJson(QJsonObject const &json) NODE_STYLE_READ_COLOR(obj, GradientColor2); NODE_STYLE_READ_COLOR(obj, GradientColor3); NODE_STYLE_READ_COLOR(obj, ShadowColor); + NODE_STYLE_READ_BOOL(obj, ShadowEnabled); NODE_STYLE_READ_COLOR(obj, FontColor); NODE_STYLE_READ_COLOR(obj, FontColorFaded); NODE_STYLE_READ_COLOR(obj, ConnectionPointColor); @@ -126,6 +139,7 @@ QJsonObject NodeStyle::toJson() const NODE_STYLE_WRITE_COLOR(obj, GradientColor2); NODE_STYLE_WRITE_COLOR(obj, GradientColor3); NODE_STYLE_WRITE_COLOR(obj, ShadowColor); + NODE_STYLE_WRITE_BOOL(obj, ShadowEnabled); NODE_STYLE_WRITE_COLOR(obj, FontColor); NODE_STYLE_WRITE_COLOR(obj, FontColorFaded); NODE_STYLE_WRITE_COLOR(obj, ConnectionPointColor);