feat: add config scope
This commit is contained in:
parent
9f8fd7d660
commit
a932a68a40
7 changed files with 71 additions and 29 deletions
|
|
@ -3,6 +3,7 @@ qml_module(caelestia-config
|
|||
SOURCES
|
||||
config.cpp
|
||||
configobject.cpp
|
||||
configscope.cpp
|
||||
appearanceconfig.cpp
|
||||
tokens.cpp
|
||||
backgroundconfig.hpp
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
#include "config.hpp"
|
||||
#include "configscope.hpp"
|
||||
|
||||
#include <qqmlengine.h>
|
||||
#include <qstandardpaths.h>
|
||||
|
|
@ -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<QQuickItem*>(object);
|
||||
|
||||
while (item) {
|
||||
if (auto* config = qobject_cast<Config*>(item))
|
||||
return config;
|
||||
item = item->parentItem();
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
return new Config(ConfigScope::find(object), object);
|
||||
}
|
||||
|
||||
} // namespace caelestia::config
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
#pragma once
|
||||
|
||||
#include <qqmlintegration.h>
|
||||
#include <qquickitem.h>
|
||||
#include <qqmlengine.h>
|
||||
|
||||
#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
|
||||
|
|
|
|||
20
plugin/src/Caelestia/Config/configscope.cpp
Normal file
20
plugin/src/Caelestia/Config/configscope.cpp
Normal file
|
|
@ -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<QQuickItem*>(object);
|
||||
|
||||
while (item) {
|
||||
if (auto* scope = qobject_cast<ConfigScope*>(item))
|
||||
return scope;
|
||||
item = item->parentItem();
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
} // namespace caelestia::config
|
||||
18
plugin/src/Caelestia/Config/configscope.hpp
Normal file
18
plugin/src/Caelestia/Config/configscope.hpp
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
#pragma once
|
||||
|
||||
#include <qqmlintegration.h>
|
||||
#include <qquickitem.h>
|
||||
|
||||
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
|
||||
|
|
@ -1,5 +1,6 @@
|
|||
#include "tokens.hpp"
|
||||
#include "config.hpp"
|
||||
#include "configscope.hpp"
|
||||
|
||||
#include <qqmlengine.h>
|
||||
#include <qstandardpaths.h>
|
||||
|
|
@ -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<QQuickItem*>(object);
|
||||
|
||||
while (item) {
|
||||
if (auto* tokens = qobject_cast<Tokens*>(item))
|
||||
return tokens;
|
||||
item = item->parentItem();
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
return new Tokens(ConfigScope::find(object), object);
|
||||
}
|
||||
|
||||
} // namespace caelestia::config
|
||||
|
|
|
|||
|
|
@ -3,10 +3,12 @@
|
|||
#include "configobject.hpp"
|
||||
|
||||
#include <qlist.h>
|
||||
#include <qquickitem.h>
|
||||
#include <qqmlengine.h>
|
||||
|
||||
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
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue