refactor: move attached types to own files
This commit is contained in:
parent
fc1b3ca2d6
commit
644e70679b
9 changed files with 261 additions and 239 deletions
|
|
@ -2,11 +2,13 @@ qml_module(caelestia-config
|
||||||
URI Caelestia.Config
|
URI Caelestia.Config
|
||||||
SOURCES
|
SOURCES
|
||||||
config.cpp
|
config.cpp
|
||||||
|
configattached.cpp
|
||||||
configobject.cpp
|
configobject.cpp
|
||||||
rootconfig.cpp
|
rootconfig.cpp
|
||||||
configscope.cpp
|
configscope.cpp
|
||||||
appearanceconfig.cpp
|
appearanceconfig.cpp
|
||||||
tokens.cpp
|
tokens.cpp
|
||||||
|
tokensattached.cpp
|
||||||
anim.cpp
|
anim.cpp
|
||||||
monitorconfigmanager.cpp
|
monitorconfigmanager.cpp
|
||||||
backgroundconfig.hpp
|
backgroundconfig.hpp
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,4 @@
|
||||||
#include "config.hpp"
|
#include "config.hpp"
|
||||||
#include "configscope.hpp"
|
|
||||||
#include "monitorconfigmanager.hpp"
|
#include "monitorconfigmanager.hpp"
|
||||||
#include "tokens.hpp"
|
#include "tokens.hpp"
|
||||||
|
|
||||||
|
|
@ -101,55 +100,4 @@ GlobalConfig* GlobalConfig::create(QQmlEngine*, QJSEngine*) {
|
||||||
return instance();
|
return instance();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Config (attached type)
|
|
||||||
|
|
||||||
Config::Config(ConfigScope* scope, QObject* parent)
|
|
||||||
: QObject(parent)
|
|
||||||
, m_scope(scope) {
|
|
||||||
connectScope();
|
|
||||||
}
|
|
||||||
|
|
||||||
void Config::connectScope() {
|
|
||||||
if (!m_scope)
|
|
||||||
return;
|
|
||||||
connect(m_scope, &ConfigScope::configChanged, this, &Config::sourceChanged);
|
|
||||||
connect(m_scope, &ConfigScope::tokensChanged, this, &Config::sourceChanged);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Helper: return per-monitor sub-object if scope exists, otherwise global
|
|
||||||
#define CONFIG_ATTACHED_GETTER(Type, name) \
|
|
||||||
const Type* Config::name() const { \
|
|
||||||
if (m_scope && m_scope->config()) \
|
|
||||||
return m_scope->config()->name(); \
|
|
||||||
return GlobalConfig::instance()->name(); \
|
|
||||||
}
|
|
||||||
|
|
||||||
CONFIG_ATTACHED_GETTER(AppearanceConfig, appearance)
|
|
||||||
CONFIG_ATTACHED_GETTER(GeneralConfig, general)
|
|
||||||
CONFIG_ATTACHED_GETTER(BackgroundConfig, background)
|
|
||||||
CONFIG_ATTACHED_GETTER(BarConfig, bar)
|
|
||||||
CONFIG_ATTACHED_GETTER(BorderConfig, border)
|
|
||||||
CONFIG_ATTACHED_GETTER(DashboardConfig, dashboard)
|
|
||||||
CONFIG_ATTACHED_GETTER(ControlCenterConfig, controlCenter)
|
|
||||||
CONFIG_ATTACHED_GETTER(LauncherConfig, launcher)
|
|
||||||
CONFIG_ATTACHED_GETTER(NotifsConfig, notifs)
|
|
||||||
CONFIG_ATTACHED_GETTER(OsdConfig, osd)
|
|
||||||
CONFIG_ATTACHED_GETTER(SessionConfig, session)
|
|
||||||
CONFIG_ATTACHED_GETTER(WInfoConfig, winfo)
|
|
||||||
CONFIG_ATTACHED_GETTER(LockConfig, lock)
|
|
||||||
CONFIG_ATTACHED_GETTER(UtilitiesConfig, utilities)
|
|
||||||
CONFIG_ATTACHED_GETTER(SidebarConfig, sidebar)
|
|
||||||
CONFIG_ATTACHED_GETTER(ServiceConfig, services)
|
|
||||||
CONFIG_ATTACHED_GETTER(UserPaths, paths)
|
|
||||||
|
|
||||||
#undef CONFIG_ATTACHED_GETTER
|
|
||||||
|
|
||||||
GlobalConfig* Config::forScreen(const QString& screen) {
|
|
||||||
return GlobalConfig::forScreen(screen);
|
|
||||||
}
|
|
||||||
|
|
||||||
Config* Config::qmlAttachedProperties(QObject* object) {
|
|
||||||
return new Config(ConfigScope::find(object), object);
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace caelestia::config
|
} // namespace caelestia::config
|
||||||
|
|
|
||||||
|
|
@ -65,68 +65,4 @@ private:
|
||||||
bool m_tokensBound = false;
|
bool m_tokensBound = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
class ConfigScope;
|
|
||||||
|
|
||||||
class Config : public QObject {
|
|
||||||
Q_OBJECT
|
|
||||||
Q_MOC_INCLUDE("configscope.hpp")
|
|
||||||
QML_ELEMENT
|
|
||||||
QML_UNCREATABLE("")
|
|
||||||
QML_ATTACHED(Config)
|
|
||||||
|
|
||||||
Q_PROPERTY(caelestia::config::ConfigScope* scope READ scope NOTIFY sourceChanged)
|
|
||||||
Q_PROPERTY(const caelestia::config::AppearanceConfig* appearance READ appearance NOTIFY sourceChanged)
|
|
||||||
Q_PROPERTY(const caelestia::config::GeneralConfig* general READ general NOTIFY sourceChanged)
|
|
||||||
Q_PROPERTY(const caelestia::config::BackgroundConfig* background READ background NOTIFY sourceChanged)
|
|
||||||
Q_PROPERTY(const caelestia::config::BarConfig* bar READ bar NOTIFY sourceChanged)
|
|
||||||
Q_PROPERTY(const caelestia::config::BorderConfig* border READ border NOTIFY sourceChanged)
|
|
||||||
Q_PROPERTY(const caelestia::config::DashboardConfig* dashboard READ dashboard NOTIFY sourceChanged)
|
|
||||||
Q_PROPERTY(const caelestia::config::ControlCenterConfig* controlCenter READ controlCenter NOTIFY sourceChanged)
|
|
||||||
Q_PROPERTY(const caelestia::config::LauncherConfig* launcher READ launcher NOTIFY sourceChanged)
|
|
||||||
Q_PROPERTY(const caelestia::config::NotifsConfig* notifs READ notifs NOTIFY sourceChanged)
|
|
||||||
Q_PROPERTY(const caelestia::config::OsdConfig* osd READ osd NOTIFY sourceChanged)
|
|
||||||
Q_PROPERTY(const caelestia::config::SessionConfig* session READ session NOTIFY sourceChanged)
|
|
||||||
Q_PROPERTY(const caelestia::config::WInfoConfig* winfo READ winfo NOTIFY sourceChanged)
|
|
||||||
Q_PROPERTY(const caelestia::config::LockConfig* lock READ lock NOTIFY sourceChanged)
|
|
||||||
Q_PROPERTY(const caelestia::config::UtilitiesConfig* utilities READ utilities NOTIFY sourceChanged)
|
|
||||||
Q_PROPERTY(const caelestia::config::SidebarConfig* sidebar READ sidebar NOTIFY sourceChanged)
|
|
||||||
Q_PROPERTY(const caelestia::config::ServiceConfig* services READ services NOTIFY sourceChanged)
|
|
||||||
Q_PROPERTY(const caelestia::config::UserPaths* paths READ paths NOTIFY sourceChanged)
|
|
||||||
|
|
||||||
public:
|
|
||||||
explicit Config(ConfigScope* scope, QObject* parent = nullptr);
|
|
||||||
|
|
||||||
[[nodiscard]] ConfigScope* scope() const { return m_scope; }
|
|
||||||
|
|
||||||
[[nodiscard]] const AppearanceConfig* appearance() const;
|
|
||||||
[[nodiscard]] const GeneralConfig* general() const;
|
|
||||||
[[nodiscard]] const BackgroundConfig* background() const;
|
|
||||||
[[nodiscard]] const BarConfig* bar() const;
|
|
||||||
[[nodiscard]] const BorderConfig* border() const;
|
|
||||||
[[nodiscard]] const DashboardConfig* dashboard() const;
|
|
||||||
[[nodiscard]] const ControlCenterConfig* controlCenter() const;
|
|
||||||
[[nodiscard]] const LauncherConfig* launcher() const;
|
|
||||||
[[nodiscard]] const NotifsConfig* notifs() const;
|
|
||||||
[[nodiscard]] const OsdConfig* osd() const;
|
|
||||||
[[nodiscard]] const SessionConfig* session() const;
|
|
||||||
[[nodiscard]] const WInfoConfig* winfo() const;
|
|
||||||
[[nodiscard]] const LockConfig* lock() const;
|
|
||||||
[[nodiscard]] const UtilitiesConfig* utilities() const;
|
|
||||||
[[nodiscard]] const SidebarConfig* sidebar() const;
|
|
||||||
[[nodiscard]] const ServiceConfig* services() const;
|
|
||||||
[[nodiscard]] const UserPaths* paths() const;
|
|
||||||
|
|
||||||
[[nodiscard]] Q_INVOKABLE static GlobalConfig* forScreen(const QString& screen);
|
|
||||||
|
|
||||||
static Config* qmlAttachedProperties(QObject* object);
|
|
||||||
|
|
||||||
signals:
|
|
||||||
void sourceChanged();
|
|
||||||
|
|
||||||
private:
|
|
||||||
void connectScope();
|
|
||||||
|
|
||||||
ConfigScope* m_scope;
|
|
||||||
};
|
|
||||||
|
|
||||||
} // namespace caelestia::config
|
} // namespace caelestia::config
|
||||||
|
|
|
||||||
56
plugin/src/Caelestia/Config/configattached.cpp
Normal file
56
plugin/src/Caelestia/Config/configattached.cpp
Normal file
|
|
@ -0,0 +1,56 @@
|
||||||
|
#include "configattached.hpp"
|
||||||
|
#include "config.hpp"
|
||||||
|
#include "configscope.hpp"
|
||||||
|
#include "monitorconfigmanager.hpp"
|
||||||
|
|
||||||
|
namespace caelestia::config {
|
||||||
|
|
||||||
|
Config::Config(ConfigScope* scope, QObject* parent)
|
||||||
|
: QObject(parent)
|
||||||
|
, m_scope(scope) {
|
||||||
|
connectScope();
|
||||||
|
}
|
||||||
|
|
||||||
|
void Config::connectScope() {
|
||||||
|
if (!m_scope)
|
||||||
|
return;
|
||||||
|
connect(m_scope, &ConfigScope::configChanged, this, &Config::sourceChanged);
|
||||||
|
connect(m_scope, &ConfigScope::tokensChanged, this, &Config::sourceChanged);
|
||||||
|
}
|
||||||
|
|
||||||
|
#define CONFIG_ATTACHED_GETTER(Type, name) \
|
||||||
|
const Type* Config::name() const { \
|
||||||
|
if (m_scope && m_scope->config()) \
|
||||||
|
return m_scope->config()->name(); \
|
||||||
|
return GlobalConfig::instance()->name(); \
|
||||||
|
}
|
||||||
|
|
||||||
|
CONFIG_ATTACHED_GETTER(AppearanceConfig, appearance)
|
||||||
|
CONFIG_ATTACHED_GETTER(GeneralConfig, general)
|
||||||
|
CONFIG_ATTACHED_GETTER(BackgroundConfig, background)
|
||||||
|
CONFIG_ATTACHED_GETTER(BarConfig, bar)
|
||||||
|
CONFIG_ATTACHED_GETTER(BorderConfig, border)
|
||||||
|
CONFIG_ATTACHED_GETTER(DashboardConfig, dashboard)
|
||||||
|
CONFIG_ATTACHED_GETTER(ControlCenterConfig, controlCenter)
|
||||||
|
CONFIG_ATTACHED_GETTER(LauncherConfig, launcher)
|
||||||
|
CONFIG_ATTACHED_GETTER(NotifsConfig, notifs)
|
||||||
|
CONFIG_ATTACHED_GETTER(OsdConfig, osd)
|
||||||
|
CONFIG_ATTACHED_GETTER(SessionConfig, session)
|
||||||
|
CONFIG_ATTACHED_GETTER(WInfoConfig, winfo)
|
||||||
|
CONFIG_ATTACHED_GETTER(LockConfig, lock)
|
||||||
|
CONFIG_ATTACHED_GETTER(UtilitiesConfig, utilities)
|
||||||
|
CONFIG_ATTACHED_GETTER(SidebarConfig, sidebar)
|
||||||
|
CONFIG_ATTACHED_GETTER(ServiceConfig, services)
|
||||||
|
CONFIG_ATTACHED_GETTER(UserPaths, paths)
|
||||||
|
|
||||||
|
#undef CONFIG_ATTACHED_GETTER
|
||||||
|
|
||||||
|
GlobalConfig* Config::forScreen(const QString& screen) {
|
||||||
|
return GlobalConfig::forScreen(screen);
|
||||||
|
}
|
||||||
|
|
||||||
|
Config* Config::qmlAttachedProperties(QObject* object) {
|
||||||
|
return new Config(ConfigScope::find(object), object);
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace caelestia::config
|
||||||
69
plugin/src/Caelestia/Config/configattached.hpp
Normal file
69
plugin/src/Caelestia/Config/configattached.hpp
Normal file
|
|
@ -0,0 +1,69 @@
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "config.hpp"
|
||||||
|
#include "configscope.hpp"
|
||||||
|
|
||||||
|
namespace caelestia::config {
|
||||||
|
|
||||||
|
class Config : public QObject {
|
||||||
|
Q_OBJECT
|
||||||
|
QML_ELEMENT
|
||||||
|
QML_UNCREATABLE("")
|
||||||
|
QML_ATTACHED(Config)
|
||||||
|
|
||||||
|
Q_PROPERTY(caelestia::config::ConfigScope* scope READ scope NOTIFY sourceChanged)
|
||||||
|
Q_PROPERTY(const caelestia::config::AppearanceConfig* appearance READ appearance NOTIFY sourceChanged)
|
||||||
|
Q_PROPERTY(const caelestia::config::GeneralConfig* general READ general NOTIFY sourceChanged)
|
||||||
|
Q_PROPERTY(const caelestia::config::BackgroundConfig* background READ background NOTIFY sourceChanged)
|
||||||
|
Q_PROPERTY(const caelestia::config::BarConfig* bar READ bar NOTIFY sourceChanged)
|
||||||
|
Q_PROPERTY(const caelestia::config::BorderConfig* border READ border NOTIFY sourceChanged)
|
||||||
|
Q_PROPERTY(const caelestia::config::DashboardConfig* dashboard READ dashboard NOTIFY sourceChanged)
|
||||||
|
Q_PROPERTY(const caelestia::config::ControlCenterConfig* controlCenter READ controlCenter NOTIFY sourceChanged)
|
||||||
|
Q_PROPERTY(const caelestia::config::LauncherConfig* launcher READ launcher NOTIFY sourceChanged)
|
||||||
|
Q_PROPERTY(const caelestia::config::NotifsConfig* notifs READ notifs NOTIFY sourceChanged)
|
||||||
|
Q_PROPERTY(const caelestia::config::OsdConfig* osd READ osd NOTIFY sourceChanged)
|
||||||
|
Q_PROPERTY(const caelestia::config::SessionConfig* session READ session NOTIFY sourceChanged)
|
||||||
|
Q_PROPERTY(const caelestia::config::WInfoConfig* winfo READ winfo NOTIFY sourceChanged)
|
||||||
|
Q_PROPERTY(const caelestia::config::LockConfig* lock READ lock NOTIFY sourceChanged)
|
||||||
|
Q_PROPERTY(const caelestia::config::UtilitiesConfig* utilities READ utilities NOTIFY sourceChanged)
|
||||||
|
Q_PROPERTY(const caelestia::config::SidebarConfig* sidebar READ sidebar NOTIFY sourceChanged)
|
||||||
|
Q_PROPERTY(const caelestia::config::ServiceConfig* services READ services NOTIFY sourceChanged)
|
||||||
|
Q_PROPERTY(const caelestia::config::UserPaths* paths READ paths NOTIFY sourceChanged)
|
||||||
|
|
||||||
|
public:
|
||||||
|
explicit Config(ConfigScope* scope, QObject* parent = nullptr);
|
||||||
|
|
||||||
|
[[nodiscard]] ConfigScope* scope() const { return m_scope; }
|
||||||
|
|
||||||
|
[[nodiscard]] const AppearanceConfig* appearance() const;
|
||||||
|
[[nodiscard]] const GeneralConfig* general() const;
|
||||||
|
[[nodiscard]] const BackgroundConfig* background() const;
|
||||||
|
[[nodiscard]] const BarConfig* bar() const;
|
||||||
|
[[nodiscard]] const BorderConfig* border() const;
|
||||||
|
[[nodiscard]] const DashboardConfig* dashboard() const;
|
||||||
|
[[nodiscard]] const ControlCenterConfig* controlCenter() const;
|
||||||
|
[[nodiscard]] const LauncherConfig* launcher() const;
|
||||||
|
[[nodiscard]] const NotifsConfig* notifs() const;
|
||||||
|
[[nodiscard]] const OsdConfig* osd() const;
|
||||||
|
[[nodiscard]] const SessionConfig* session() const;
|
||||||
|
[[nodiscard]] const WInfoConfig* winfo() const;
|
||||||
|
[[nodiscard]] const LockConfig* lock() const;
|
||||||
|
[[nodiscard]] const UtilitiesConfig* utilities() const;
|
||||||
|
[[nodiscard]] const SidebarConfig* sidebar() const;
|
||||||
|
[[nodiscard]] const ServiceConfig* services() const;
|
||||||
|
[[nodiscard]] const UserPaths* paths() const;
|
||||||
|
|
||||||
|
[[nodiscard]] Q_INVOKABLE static GlobalConfig* forScreen(const QString& screen);
|
||||||
|
|
||||||
|
static Config* qmlAttachedProperties(QObject* object);
|
||||||
|
|
||||||
|
signals:
|
||||||
|
void sourceChanged();
|
||||||
|
|
||||||
|
private:
|
||||||
|
void connectScope();
|
||||||
|
|
||||||
|
ConfigScope* m_scope;
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace caelestia::config
|
||||||
|
|
@ -1,6 +1,5 @@
|
||||||
#include "tokens.hpp"
|
#include "tokens.hpp"
|
||||||
#include "config.hpp"
|
#include "config.hpp"
|
||||||
#include "configscope.hpp"
|
|
||||||
#include "monitorconfigmanager.hpp"
|
#include "monitorconfigmanager.hpp"
|
||||||
|
|
||||||
#include <qqmlengine.h>
|
#include <qqmlengine.h>
|
||||||
|
|
@ -53,83 +52,4 @@ TokenConfig* TokenConfig::create(QQmlEngine*, QJSEngine*) {
|
||||||
return instance();
|
return instance();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Tokens (attached type)
|
|
||||||
|
|
||||||
// Resolve appearance from per-monitor GlobalConfig overlay or global GlobalConfig
|
|
||||||
static const AppearanceConfig* resolveAppearance(ConfigScope* scope) {
|
|
||||||
if (scope && scope->config())
|
|
||||||
return scope->config()->appearance();
|
|
||||||
auto* global = GlobalConfig::instance();
|
|
||||||
return global ? global->appearance() : nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
Tokens::Tokens(ConfigScope* scope, QObject* parent)
|
|
||||||
: QObject(parent)
|
|
||||||
, m_scope(scope)
|
|
||||||
, m_anim(new AnimTokens(this)) {
|
|
||||||
connectScope();
|
|
||||||
bindAnim();
|
|
||||||
}
|
|
||||||
|
|
||||||
void Tokens::connectScope() {
|
|
||||||
if (!m_scope)
|
|
||||||
return;
|
|
||||||
connect(m_scope, &ConfigScope::configChanged, this, &Tokens::sourceChanged);
|
|
||||||
connect(m_scope, &ConfigScope::configChanged, this, &Tokens::bindAnim);
|
|
||||||
}
|
|
||||||
|
|
||||||
void Tokens::bindAnim() {
|
|
||||||
auto* appearance = resolveAppearance(m_scope);
|
|
||||||
if (!appearance)
|
|
||||||
return;
|
|
||||||
|
|
||||||
// Bind durations from resolved GlobalConfig appearance
|
|
||||||
m_anim->bindDurations(appearance->anim()->durations());
|
|
||||||
|
|
||||||
// Bind curves from TokenConfig
|
|
||||||
auto* tokens = TokenConfig::instance();
|
|
||||||
if (tokens)
|
|
||||||
m_anim->bindCurves(tokens->appearance()->curves());
|
|
||||||
}
|
|
||||||
|
|
||||||
const AppearanceRounding* Tokens::rounding() const {
|
|
||||||
auto* a = resolveAppearance(m_scope);
|
|
||||||
return a ? a->rounding() : nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
const AppearanceSpacing* Tokens::spacing() const {
|
|
||||||
auto* a = resolveAppearance(m_scope);
|
|
||||||
return a ? a->spacing() : nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
const AppearancePadding* Tokens::padding() const {
|
|
||||||
auto* a = resolveAppearance(m_scope);
|
|
||||||
return a ? a->padding() : nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
const AppearanceFont* Tokens::font() const {
|
|
||||||
auto* a = resolveAppearance(m_scope);
|
|
||||||
return a ? a->font() : nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
const AppearanceTransparency* Tokens::transparency() const {
|
|
||||||
auto* a = resolveAppearance(m_scope);
|
|
||||||
return a ? a->transparency() : nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
const SizeTokens* Tokens::sizes() const {
|
|
||||||
if (m_scope && m_scope->tokens())
|
|
||||||
return m_scope->tokens()->sizes();
|
|
||||||
auto* global = TokenConfig::instance();
|
|
||||||
return global ? global->sizes() : nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
TokenConfig* Tokens::forScreen(const QString& screen) {
|
|
||||||
return TokenConfig::forScreen(screen);
|
|
||||||
}
|
|
||||||
|
|
||||||
Tokens* Tokens::qmlAttachedProperties(QObject* object) {
|
|
||||||
return new Tokens(ConfigScope::find(object), object);
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace caelestia::config
|
} // namespace caelestia::config
|
||||||
|
|
|
||||||
|
|
@ -342,47 +342,4 @@ private:
|
||||||
TokenConfig* m_defaults = nullptr;
|
TokenConfig* m_defaults = nullptr;
|
||||||
};
|
};
|
||||||
|
|
||||||
class Tokens : public QObject {
|
|
||||||
Q_OBJECT
|
|
||||||
Q_MOC_INCLUDE("configscope.hpp")
|
|
||||||
QML_ELEMENT
|
|
||||||
QML_UNCREATABLE("")
|
|
||||||
QML_ATTACHED(Tokens)
|
|
||||||
|
|
||||||
Q_PROPERTY(const caelestia::config::AppearanceRounding* rounding READ rounding NOTIFY sourceChanged)
|
|
||||||
Q_PROPERTY(const caelestia::config::AppearanceSpacing* spacing READ spacing NOTIFY sourceChanged)
|
|
||||||
Q_PROPERTY(const caelestia::config::AppearancePadding* padding READ padding NOTIFY sourceChanged)
|
|
||||||
Q_PROPERTY(const caelestia::config::AppearanceFont* font READ font NOTIFY sourceChanged)
|
|
||||||
Q_PROPERTY(const caelestia::config::AppearanceTransparency* transparency READ transparency NOTIFY sourceChanged)
|
|
||||||
Q_PROPERTY(const caelestia::config::SizeTokens* sizes READ sizes NOTIFY sourceChanged)
|
|
||||||
Q_PROPERTY(const caelestia::config::AnimTokens* anim READ anim NOTIFY sourceChanged)
|
|
||||||
|
|
||||||
public:
|
|
||||||
explicit Tokens(ConfigScope* scope, QObject* parent = nullptr);
|
|
||||||
|
|
||||||
[[nodiscard]] const AppearanceRounding* rounding() const;
|
|
||||||
[[nodiscard]] const AppearanceSpacing* spacing() const;
|
|
||||||
[[nodiscard]] const AppearancePadding* padding() const;
|
|
||||||
[[nodiscard]] const AppearanceFont* font() const;
|
|
||||||
[[nodiscard]] const AppearanceTransparency* transparency() const;
|
|
||||||
|
|
||||||
[[nodiscard]] const SizeTokens* sizes() const;
|
|
||||||
|
|
||||||
[[nodiscard]] const AnimTokens* anim() const { return m_anim; }
|
|
||||||
|
|
||||||
[[nodiscard]] Q_INVOKABLE static TokenConfig* forScreen(const QString& screen);
|
|
||||||
|
|
||||||
static Tokens* qmlAttachedProperties(QObject* object);
|
|
||||||
|
|
||||||
signals:
|
|
||||||
void sourceChanged();
|
|
||||||
|
|
||||||
private:
|
|
||||||
void connectScope();
|
|
||||||
void bindAnim();
|
|
||||||
|
|
||||||
ConfigScope* m_scope;
|
|
||||||
AnimTokens* m_anim = nullptr;
|
|
||||||
};
|
|
||||||
|
|
||||||
} // namespace caelestia::config
|
} // namespace caelestia::config
|
||||||
|
|
|
||||||
82
plugin/src/Caelestia/Config/tokensattached.cpp
Normal file
82
plugin/src/Caelestia/Config/tokensattached.cpp
Normal file
|
|
@ -0,0 +1,82 @@
|
||||||
|
#include "tokensattached.hpp"
|
||||||
|
#include "anim.hpp"
|
||||||
|
#include "config.hpp"
|
||||||
|
#include "configscope.hpp"
|
||||||
|
#include "monitorconfigmanager.hpp"
|
||||||
|
#include "tokens.hpp"
|
||||||
|
|
||||||
|
namespace caelestia::config {
|
||||||
|
|
||||||
|
static const AppearanceConfig* resolveAppearance(ConfigScope* scope) {
|
||||||
|
if (scope && scope->config())
|
||||||
|
return scope->config()->appearance();
|
||||||
|
return GlobalConfig::instance()->appearance();
|
||||||
|
}
|
||||||
|
|
||||||
|
Tokens::Tokens(ConfigScope* scope, QObject* parent)
|
||||||
|
: QObject(parent)
|
||||||
|
, m_scope(scope)
|
||||||
|
, m_anim(new AnimTokens(this)) {
|
||||||
|
connectScope();
|
||||||
|
bindAnim();
|
||||||
|
}
|
||||||
|
|
||||||
|
void Tokens::connectScope() {
|
||||||
|
if (!m_scope)
|
||||||
|
return;
|
||||||
|
connect(m_scope, &ConfigScope::configChanged, this, &Tokens::sourceChanged);
|
||||||
|
connect(m_scope, &ConfigScope::configChanged, this, &Tokens::bindAnim);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Tokens::bindAnim() {
|
||||||
|
auto* appearance = resolveAppearance(m_scope);
|
||||||
|
if (!appearance)
|
||||||
|
return;
|
||||||
|
|
||||||
|
m_anim->bindDurations(appearance->anim()->durations());
|
||||||
|
|
||||||
|
auto* tokens = TokenConfig::instance();
|
||||||
|
if (tokens)
|
||||||
|
m_anim->bindCurves(tokens->appearance()->curves());
|
||||||
|
}
|
||||||
|
|
||||||
|
const AppearanceRounding* Tokens::rounding() const {
|
||||||
|
auto* a = resolveAppearance(m_scope);
|
||||||
|
return a ? a->rounding() : nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
const AppearanceSpacing* Tokens::spacing() const {
|
||||||
|
auto* a = resolveAppearance(m_scope);
|
||||||
|
return a ? a->spacing() : nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
const AppearancePadding* Tokens::padding() const {
|
||||||
|
auto* a = resolveAppearance(m_scope);
|
||||||
|
return a ? a->padding() : nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
const AppearanceFont* Tokens::font() const {
|
||||||
|
auto* a = resolveAppearance(m_scope);
|
||||||
|
return a ? a->font() : nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
const AppearanceTransparency* Tokens::transparency() const {
|
||||||
|
auto* a = resolveAppearance(m_scope);
|
||||||
|
return a ? a->transparency() : nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
const SizeTokens* Tokens::sizes() const {
|
||||||
|
if (m_scope && m_scope->tokens())
|
||||||
|
return m_scope->tokens()->sizes();
|
||||||
|
return TokenConfig::instance()->sizes();
|
||||||
|
}
|
||||||
|
|
||||||
|
TokenConfig* Tokens::forScreen(const QString& screen) {
|
||||||
|
return TokenConfig::forScreen(screen);
|
||||||
|
}
|
||||||
|
|
||||||
|
Tokens* Tokens::qmlAttachedProperties(QObject* object) {
|
||||||
|
return new Tokens(ConfigScope::find(object), object);
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace caelestia::config
|
||||||
52
plugin/src/Caelestia/Config/tokensattached.hpp
Normal file
52
plugin/src/Caelestia/Config/tokensattached.hpp
Normal file
|
|
@ -0,0 +1,52 @@
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "anim.hpp"
|
||||||
|
#include "appearanceconfig.hpp"
|
||||||
|
#include "configscope.hpp"
|
||||||
|
#include "tokens.hpp"
|
||||||
|
|
||||||
|
namespace caelestia::config {
|
||||||
|
|
||||||
|
class Tokens : public QObject {
|
||||||
|
Q_OBJECT
|
||||||
|
QML_ELEMENT
|
||||||
|
QML_UNCREATABLE("")
|
||||||
|
QML_ATTACHED(Tokens)
|
||||||
|
|
||||||
|
Q_PROPERTY(const caelestia::config::AppearanceRounding* rounding READ rounding NOTIFY sourceChanged)
|
||||||
|
Q_PROPERTY(const caelestia::config::AppearanceSpacing* spacing READ spacing NOTIFY sourceChanged)
|
||||||
|
Q_PROPERTY(const caelestia::config::AppearancePadding* padding READ padding NOTIFY sourceChanged)
|
||||||
|
Q_PROPERTY(const caelestia::config::AppearanceFont* font READ font NOTIFY sourceChanged)
|
||||||
|
Q_PROPERTY(const caelestia::config::AppearanceTransparency* transparency READ transparency NOTIFY sourceChanged)
|
||||||
|
Q_PROPERTY(const caelestia::config::SizeTokens* sizes READ sizes NOTIFY sourceChanged)
|
||||||
|
Q_PROPERTY(const caelestia::config::AnimTokens* anim READ anim NOTIFY sourceChanged)
|
||||||
|
|
||||||
|
public:
|
||||||
|
explicit Tokens(ConfigScope* scope, QObject* parent = nullptr);
|
||||||
|
|
||||||
|
[[nodiscard]] const AppearanceRounding* rounding() const;
|
||||||
|
[[nodiscard]] const AppearanceSpacing* spacing() const;
|
||||||
|
[[nodiscard]] const AppearancePadding* padding() const;
|
||||||
|
[[nodiscard]] const AppearanceFont* font() const;
|
||||||
|
[[nodiscard]] const AppearanceTransparency* transparency() const;
|
||||||
|
|
||||||
|
[[nodiscard]] const SizeTokens* sizes() const;
|
||||||
|
|
||||||
|
[[nodiscard]] const AnimTokens* anim() const { return m_anim; }
|
||||||
|
|
||||||
|
[[nodiscard]] Q_INVOKABLE static TokenConfig* forScreen(const QString& screen);
|
||||||
|
|
||||||
|
static Tokens* qmlAttachedProperties(QObject* object);
|
||||||
|
|
||||||
|
signals:
|
||||||
|
void sourceChanged();
|
||||||
|
|
||||||
|
private:
|
||||||
|
void connectScope();
|
||||||
|
void bindAnim();
|
||||||
|
|
||||||
|
ConfigScope* m_scope;
|
||||||
|
AnimTokens* m_anim = nullptr;
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace caelestia::config
|
||||||
Loading…
Add table
Reference in a new issue