diff --git a/src/platformtheme/khintssettings.h b/src/platformtheme/khintssettings.h --- a/src/platformtheme/khintssettings.h +++ b/src/platformtheme/khintssettings.h @@ -81,6 +81,7 @@ void updateQtSettings(KConfigGroup &cg); void updateShowIconsInMenuItems(KConfigGroup &cg); Qt::ToolButtonStyle toolButtonStyle(const KConfigGroup &cg); + void updateColorTheme(const QString &path); void updateCursorTheme(); void updatePortalSetting(); diff --git a/src/platformtheme/khintssettings.cpp b/src/platformtheme/khintssettings.cpp --- a/src/platformtheme/khintssettings.cpp +++ b/src/platformtheme/khintssettings.cpp @@ -87,7 +87,7 @@ , mUsePortal(checkUsePortalSupport()) { if (!mKdeGlobals) { - mKdeGlobals = KSharedConfig::openConfig(); + mKdeGlobals = KSharedConfig::openConfig(QStringLiteral("kdeglobals")); } KConfigGroup cg(mKdeGlobals, "KDE"); @@ -459,19 +459,116 @@ const QString looknfeel = readConfigValue(cg, QStringLiteral("LookAndFeelPackage"), defaultLookAndFeelPackage).toString(); QString path = QStandardPaths::locate(QStandardPaths::GenericDataLocation, QStringLiteral("plasma/look-and-feel/") + looknfeel + QStringLiteral("/contents/colors")); if (!path.isEmpty()) { - m_palettes[QPlatformTheme::SystemPalette] = new QPalette(KColorScheme::createApplicationPalette(KSharedConfig::openConfig(path))); + updateColorTheme(path); return; } const QString scheme = readConfigValue(QStringLiteral("General"), QStringLiteral("ColorScheme"), QStringLiteral("Breeze")).toString(); path = QStandardPaths::locate(QStandardPaths::GenericDataLocation, QStringLiteral("color-schemes/") + scheme + QStringLiteral(".colors")); if (!path.isEmpty()) { - m_palettes[QPlatformTheme::SystemPalette] = new QPalette(KColorScheme::createApplicationPalette(KSharedConfig::openConfig(path))); + updateColorTheme(path); } } } +void KHintsSettings::updateColorTheme(const QString &path) +{ + m_palettes[QPlatformTheme::SystemPalette] = new QPalette(KColorScheme::createApplicationPalette(KSharedConfig::openConfig(path))); + + // Build the colorscheme in kdeglobals as it wasn't initialized yet + KSharedConfigPtr config = KSharedConfig::openConfig(path); + + const QStringList colorSetGroupList{ + QStringLiteral("Colors:View"), + QStringLiteral("Colors:Window"), + QStringLiteral("Colors:Button"), + QStringLiteral("Colors:Selection"), + QStringLiteral("Colors:Tooltip"), + QStringLiteral("Colors:Complementary") + }; + + const QList colorSchemes{ + KColorScheme(QPalette::Active, KColorScheme::View, config), + KColorScheme(QPalette::Active, KColorScheme::Window, config), + KColorScheme(QPalette::Active, KColorScheme::Button, config), + KColorScheme(QPalette::Active, KColorScheme::Selection, config), + KColorScheme(QPalette::Active, KColorScheme::Tooltip, config), + KColorScheme(QPalette::Active, KColorScheme::Complementary, config) + }; + + for (int i = 0; i < colorSchemes.length(); ++i) { + KConfigGroup group(mKdeGlobals, colorSetGroupList.value(i)); + group.writeEntry("BackgroundNormal", colorSchemes[i].background(KColorScheme::NormalBackground).color()); + group.writeEntry("BackgroundAlternate", colorSchemes[i].background(KColorScheme::AlternateBackground).color()); + group.writeEntry("ForegroundNormal", colorSchemes[i].foreground(KColorScheme::NormalText).color()); + group.writeEntry("ForegroundInactive", colorSchemes[i].foreground(KColorScheme::InactiveText).color()); + group.writeEntry("ForegroundActive", colorSchemes[i].foreground(KColorScheme::ActiveText).color()); + group.writeEntry("ForegroundLink", colorSchemes[i].foreground(KColorScheme::LinkText).color()); + group.writeEntry("ForegroundVisited", colorSchemes[i].foreground(KColorScheme::VisitedText).color()); + group.writeEntry("ForegroundNegative", colorSchemes[i].foreground(KColorScheme::NegativeText).color()); + group.writeEntry("ForegroundNeutral", colorSchemes[i].foreground(KColorScheme::NeutralText).color()); + group.writeEntry("ForegroundPositive", colorSchemes[i].foreground(KColorScheme::PositiveText).color()); + group.writeEntry("DecorationFocus", colorSchemes[i].decoration(KColorScheme::FocusColor).color()); + group.writeEntry("DecorationHover", colorSchemes[i].decoration(KColorScheme::HoverColor).color()); + } + + KConfigGroup groupWMTheme(config, "WM"); + KConfigGroup groupWMOut(mKdeGlobals, "WM"); + + const QStringList colorItemListWM{ + QStringLiteral("activeBackground"), + QStringLiteral("activeForeground"), + QStringLiteral("inactiveBackground"), + QStringLiteral("inactiveForeground"), + QStringLiteral("activeBlend"), + QStringLiteral("inactiveBlend") + }; + + const QVector defaultWMColors{ + QColor(71,80,87), + QColor(239,240,241), + QColor(239,240,241), + QColor(189,195,199), + QColor(255,255,255), + QColor(75,71,67) + }; + + int i = 0; + for (const QString &coloritem : colorItemListWM) { + groupWMOut.writeEntry(coloritem, groupWMTheme.readEntry(coloritem, defaultWMColors.value(i))); + ++i; + } + + const QStringList groupNameList{ + QStringLiteral("ColorEffects:Inactive"), + QStringLiteral("ColorEffects:Disabled") + }; + + const QStringList effectList{ + QStringLiteral("Enable"), + QStringLiteral("ChangeSelectionColor"), + QStringLiteral("IntensityEffect"), + QStringLiteral("IntensityAmount"), + QStringLiteral("ColorEffect"), + QStringLiteral("ColorAmount"), + QStringLiteral("Color"), + QStringLiteral("ContrastEffect"), + QStringLiteral("ContrastAmount") + }; + + for (const QString &groupName : groupNameList) { + KConfigGroup groupEffectOut(mKdeGlobals, groupName); + KConfigGroup groupEffectTheme(config, groupName); + + for (const QString &effect : effectList) { + groupEffectOut.writeEntry(effect, groupEffectTheme.readEntry(effect)); + } + } + + mKdeGlobals->sync(); +} + void KHintsSettings::updateCursorTheme() { KConfig config(QStringLiteral("kcminputrc"));