Skip to content

Commit

Permalink
settings: provide accent-color settings
Browse files Browse the repository at this point in the history
  • Loading branch information
easyteacher committed Sep 3, 2023
1 parent 9357ee6 commit fc716f2
Showing 1 changed file with 27 additions and 4 deletions.
31 changes: 27 additions & 4 deletions src/settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -176,14 +176,13 @@ class FdoAppearanceSettings : public SettingsModule
{
Q_OBJECT
static constexpr auto colorScheme = "color-scheme"_L1;
static constexpr auto accentColor = "accent-color"_L1;

public:
explicit FdoAppearanceSettings(QObject *parent = nullptr)
: SettingsModule(parent)
{
connect(qGuiApp, &QGuiApplication::paletteChanged, this, [this] {
Q_EMIT settingChanged(group(), colorScheme, readFdoColorScheme());
});
connect(qGuiApp, &QGuiApplication::paletteChanged, this, &FdoAppearanceSettings::onPaletteChanged);
}

inline QString group() final
Expand All @@ -197,14 +196,20 @@ class FdoAppearanceSettings : public SettingsModule
VariantMapMap result;
QVariantMap appearanceSettings;
appearanceSettings.insert(colorScheme, readFdoColorScheme().variant());
appearanceSettings.insert(accentColor, readAccentColor().variant());
result.insert(group(), appearanceSettings);
return result;
}

QVariant read(const QString &group, const QString &key) final
{
if (group == this->group() && key == colorScheme) {
if (group != this->group()) {
return {};
}
if (key == colorScheme) {
return QVariant::fromValue(readFdoColorScheme());
} else if (key == accentColor) {
return QVariant::fromValue(readAccentColor());
}
return {};
}
Expand All @@ -225,6 +230,24 @@ class FdoAppearanceSettings : public SettingsModule

return QDBusVariant(result);
}

/**
* Returns a list that contains redF, blueF and greenF and represents
* the current accent color.
* Format: (ddd)
*/
QDBusVariant readAccentColor() const
{
const QColor accentColor = qGuiApp->palette().highlight().color();
return QDBusVariant(QVariantList{double(accentColor.redF()), double(accentColor.greenF()), double(accentColor.blueF())});
}

private Q_SLOTS:
void onPaletteChanged()
{
Q_EMIT settingChanged(group(), colorScheme, readFdoColorScheme());
Q_EMIT settingChanged(group(), accentColor, readAccentColor());
}
};

class KDEGlobalsSettings : public SettingsModule
Expand Down

0 comments on commit fc716f2

Please sign in to comment.