From a932a68a4026c48563d7406fd56c11f4a0177b1a Mon Sep 17 00:00:00 2001 From: 2 * r + 2 * t <61896496+soramanew@users.noreply.github.com> Date: Sat, 11 Apr 2026 15:40:19 +1000 Subject: [PATCH] feat: add config scope --- plugin/src/Caelestia/Config/CMakeLists.txt | 1 + plugin/src/Caelestia/Config/config.cpp | 16 +++++----------- plugin/src/Caelestia/Config/config.hpp | 15 +++++++++++---- plugin/src/Caelestia/Config/configscope.cpp | 20 ++++++++++++++++++++ plugin/src/Caelestia/Config/configscope.hpp | 18 ++++++++++++++++++ plugin/src/Caelestia/Config/tokens.cpp | 16 +++++----------- plugin/src/Caelestia/Config/tokens.hpp | 14 +++++++++++--- 7 files changed, 71 insertions(+), 29 deletions(-) create mode 100644 plugin/src/Caelestia/Config/configscope.cpp create mode 100644 plugin/src/Caelestia/Config/configscope.hpp diff --git a/plugin/src/Caelestia/Config/CMakeLists.txt b/plugin/src/Caelestia/Config/CMakeLists.txt index 61f14735..dcaf1e69 100644 --- a/plugin/src/Caelestia/Config/CMakeLists.txt +++ b/plugin/src/Caelestia/Config/CMakeLists.txt @@ -3,6 +3,7 @@ qml_module(caelestia-config SOURCES config.cpp configobject.cpp + configscope.cpp appearanceconfig.cpp tokens.cpp backgroundconfig.hpp diff --git a/plugin/src/Caelestia/Config/config.cpp b/plugin/src/Caelestia/Config/config.cpp index f6fb721d..0a71fdc9 100644 --- a/plugin/src/Caelestia/Config/config.cpp +++ b/plugin/src/Caelestia/Config/config.cpp @@ -1,4 +1,5 @@ #include "config.hpp" +#include "configscope.hpp" #include #include @@ -64,19 +65,12 @@ void GlobalConfig::reload() { // Config (attached type) -Config::Config(QQuickItem* parent) - : QQuickItem(parent) {} +Config::Config(ConfigScope* scope, QObject* parent) + : QObject(parent) + , m_scope(scope) {} Config* Config::qmlAttachedProperties(QObject* object) { - auto* item = qobject_cast(object); - - while (item) { - if (auto* config = qobject_cast(item)) - return config; - item = item->parentItem(); - } - - return nullptr; + return new Config(ConfigScope::find(object), object); } } // namespace caelestia::config diff --git a/plugin/src/Caelestia/Config/config.hpp b/plugin/src/Caelestia/Config/config.hpp index bd18b7fb..2f5fd570 100644 --- a/plugin/src/Caelestia/Config/config.hpp +++ b/plugin/src/Caelestia/Config/config.hpp @@ -1,7 +1,6 @@ #pragma once -#include -#include +#include #include "appearanceconfig.hpp" #include "backgroundconfig.hpp" @@ -59,15 +58,23 @@ private: explicit GlobalConfig(QObject* parent = nullptr); }; -class Config : public QQuickItem { +class ConfigScope; + +class Config : public QObject { Q_OBJECT QML_ELEMENT + QML_UNCREATABLE("") QML_ATTACHED(Config) public: - explicit Config(QQuickItem* parent = nullptr); + explicit Config(ConfigScope* scope, QObject* parent = nullptr); + + [[nodiscard]] ConfigScope* scope() const { return m_scope; } static Config* qmlAttachedProperties(QObject* object); + +private: + ConfigScope* m_scope; }; } // namespace caelestia::config diff --git a/plugin/src/Caelestia/Config/configscope.cpp b/plugin/src/Caelestia/Config/configscope.cpp new file mode 100644 index 00000000..e7e8452b --- /dev/null +++ b/plugin/src/Caelestia/Config/configscope.cpp @@ -0,0 +1,20 @@ +#include "configscope.hpp" + +namespace caelestia::config { + +ConfigScope::ConfigScope(QQuickItem* parent) + : QQuickItem(parent) {} + +ConfigScope* ConfigScope::find(QObject* object) { + auto* item = qobject_cast(object); + + while (item) { + if (auto* scope = qobject_cast(item)) + return scope; + item = item->parentItem(); + } + + return nullptr; +} + +} // namespace caelestia::config diff --git a/plugin/src/Caelestia/Config/configscope.hpp b/plugin/src/Caelestia/Config/configscope.hpp new file mode 100644 index 00000000..94380c80 --- /dev/null +++ b/plugin/src/Caelestia/Config/configscope.hpp @@ -0,0 +1,18 @@ +#pragma once + +#include +#include + +namespace caelestia::config { + +class ConfigScope : public QQuickItem { + Q_OBJECT + QML_ELEMENT + +public: + explicit ConfigScope(QQuickItem* parent = nullptr); + + static ConfigScope* find(QObject* object); +}; + +} // namespace caelestia::config diff --git a/plugin/src/Caelestia/Config/tokens.cpp b/plugin/src/Caelestia/Config/tokens.cpp index 8c8146b7..c81567d6 100644 --- a/plugin/src/Caelestia/Config/tokens.cpp +++ b/plugin/src/Caelestia/Config/tokens.cpp @@ -1,5 +1,6 @@ #include "tokens.hpp" #include "config.hpp" +#include "configscope.hpp" #include #include @@ -67,19 +68,12 @@ void TokenConfig::reload() { // Tokens (attached type) -Tokens::Tokens(QQuickItem* parent) - : QQuickItem(parent) {} +Tokens::Tokens(ConfigScope* scope, QObject* parent) + : QObject(parent) + , m_scope(scope) {} Tokens* Tokens::qmlAttachedProperties(QObject* object) { - auto* item = qobject_cast(object); - - while (item) { - if (auto* tokens = qobject_cast(item)) - return tokens; - item = item->parentItem(); - } - - return nullptr; + return new Tokens(ConfigScope::find(object), object); } } // namespace caelestia::config diff --git a/plugin/src/Caelestia/Config/tokens.hpp b/plugin/src/Caelestia/Config/tokens.hpp index d94f173f..a3ea6f69 100644 --- a/plugin/src/Caelestia/Config/tokens.hpp +++ b/plugin/src/Caelestia/Config/tokens.hpp @@ -3,10 +3,12 @@ #include "configobject.hpp" #include -#include +#include namespace caelestia::config { +class ConfigScope; + class AnimCurves : public ConfigObject { Q_OBJECT QML_ANONYMOUS @@ -318,15 +320,21 @@ private: explicit TokenConfig(QObject* parent = nullptr); }; -class Tokens : public QQuickItem { +class Tokens : public QObject { Q_OBJECT QML_ELEMENT + QML_UNCREATABLE("") QML_ATTACHED(Tokens) public: - explicit Tokens(QQuickItem* parent = nullptr); + explicit Tokens(ConfigScope* scope, QObject* parent = nullptr); + + [[nodiscard]] ConfigScope* scope() const { return m_scope; } static Tokens* qmlAttachedProperties(QObject* object); + +private: + ConfigScope* m_scope; }; } // namespace caelestia::config