diff --git a/src/libkirigami/platformtheme.h b/src/libkirigami/platformtheme.h --- a/src/libkirigami/platformtheme.h +++ b/src/libkirigami/platformtheme.h @@ -166,6 +166,17 @@ */ Q_PROPERTY(QColor hoverColor READ hoverColor WRITE setCustomHoverColor RESET setCustomHoverColor NOTIFY colorsChanged) + // wm colors + /** + * The background color to use for a window's titlebar. + */ + Q_PROPERTY(QColor titlebarBackgroundColor READ titlebarBackgroundColor WRITE setCustomTitlebarBackgroundColor RESET setCustomTitlebarBackgroundColor NOTIFY colorsChanged) + + /** + * The foreground color to use for a window's titlebar. + */ + Q_PROPERTY(QColor titlebarTextColor READ titlebarTextColor WRITE setCustomTitlebarTextColor RESET setCustomTitlebarTextColor NOTIFY colorsChanged) + // font and palette Q_PROPERTY(QFont defaultFont READ defaultFont NOTIFY defaultFontChanged) //Active palette @@ -263,6 +274,12 @@ void setCustomFocusColor(const QColor &color = QColor()); void setCustomHoverColor(const QColor &color = QColor()); + //wm colors + QColor titlebarBackgroundColor() const; + void setCustomTitlebarBackgroundColor(const QColor &color = QColor()); + QColor titlebarTextColor() const; + void setCustomTitlebarTextColor(const QColor &color = QColor()); + //QML attached property static PlatformTheme *qmlAttachedProperties(QObject *object); @@ -305,6 +322,12 @@ void setFocusColor(const QColor &color); void setHoverColor(const QColor &color); + // wm colors + void setTitlebarBackgroundColor(const QColor &color); + void setTitlebarTextColor(const QColor &color); + void setTitlebarInactiveBackgroundColor(const QColor &color); + void setTitlebarInactiveTextColor(const QColor &color); + void setDefaultFont(const QFont &defaultFont); void setPalette(const QPalette &palette); private: diff --git a/src/libkirigami/platformtheme.cpp b/src/libkirigami/platformtheme.cpp --- a/src/libkirigami/platformtheme.cpp +++ b/src/libkirigami/platformtheme.cpp @@ -16,6 +16,9 @@ #include #include #include +#include +#include +#include namespace Kirigami { @@ -86,6 +89,14 @@ QColor customFocusColor; QColor customHoverColor; + QColor titlebarTextColor; + QColor titlebarBackgroundColor; + QColor customTitlebarTextColor; + QColor customTitlebarBackgroundColor; + + QColor titlebarInactiveTextColor; + QColor titlebarInactiveBackgroundColor; + QPalette customPalette; QFont font; @@ -102,6 +113,24 @@ PlatformThemePrivate::PlatformThemePrivate(PlatformTheme *q) : q(q) { + auto settings = new QSettings(QDir::cleanPath(QStandardPaths::writableLocation(QStandardPaths::ConfigLocation) + QDir::separator() + QStringLiteral("kdeglobals")), QSettings::IniFormat); + settings->beginGroup(QStringLiteral("WM")); + std::map map = { + {&titlebarBackgroundColor, QStringLiteral("activeBackground")}, + {&titlebarTextColor, QStringLiteral("activeForeground")}, + {&titlebarInactiveTextColor, QStringLiteral("inactiveForeground")}, + {&titlebarInactiveBackgroundColor, QStringLiteral("inactiveBackground")}, + }; + for (auto const &x: map) { + auto colorSetting = settings->value(x.second).toStringList(); + x.first->setRgb( + colorSetting.at(0).toInt(), + colorSetting.at(1).toInt(), + colorSetting.at(2).toInt(), + colorSetting.value(3, QStringLiteral("255")).toInt() + ); + } + delete settings; } PlatformThemePrivate::~PlatformThemePrivate() @@ -170,6 +199,8 @@ q->setCustomNegativeBackgroundColor(t->d->customNegativeBackgroundColor); q->setCustomNeutralBackgroundColor(t->d->customNeutralBackgroundColor); q->setCustomPositiveBackgroundColor(t->d->customPositiveBackgroundColor); + q->setCustomTitlebarBackgroundColor(t->d->customTitlebarTextColor); + q->setCustomTitlebarTextColor(t->d->customTitlebarTextColor); q->setCustomFocusColor(t->d->customFocusColor); q->setCustomHoverColor(t->d->customHoverColor); } @@ -398,6 +429,28 @@ return d->customHoverColor.isValid() ? d->customHoverColor : d->hoverColor; } +QColor PlatformTheme::titlebarBackgroundColor() const +{ + return d->customTitlebarBackgroundColor.isValid() ? d->customTitlebarBackgroundColor : [=]() { + if (colorGroup() == PlatformTheme::Inactive) { + return d->titlebarInactiveBackgroundColor; + } else { + return d->titlebarBackgroundColor; + } + }(); +} + +QColor PlatformTheme::titlebarTextColor() const +{ + return d->customTitlebarTextColor.isValid() ? d->customTitlebarTextColor : [=](){ + if (colorGroup() == PlatformTheme::Inactive) { + return d->titlebarInactiveTextColor; + } else { + return d->titlebarTextColor; + } + }(); +} + //setters for theme implementations void PlatformTheme::setTextColor(const QColor &color) { @@ -599,6 +652,38 @@ d->emitCompressedColorChanged(); } +void PlatformTheme::setTitlebarBackgroundColor(const QColor& color) +{ + if (d->titlebarBackgroundColor == color) return; + + d->titlebarBackgroundColor = color; + d->emitCompressedColorChanged(); +} + +void PlatformTheme::setTitlebarTextColor(const QColor& color) +{ + if (d->titlebarTextColor == color) return; + + d->titlebarBackgroundColor = color; + d->emitCompressedColorChanged(); +} + +void PlatformTheme::setTitlebarInactiveBackgroundColor(const QColor& color) +{ + if (d->titlebarInactiveBackgroundColor == color) return; + + d->titlebarInactiveBackgroundColor = color; + d->emitCompressedColorChanged(); +} + +void PlatformTheme::setTitlebarInactiveTextColor(const QColor& color) +{ + if (d->titlebarInactiveTextColor == color) return; + + d->titlebarInactiveBackgroundColor = color; + d->emitCompressedColorChanged(); +} + QFont PlatformTheme::defaultFont() const { return d->font; @@ -844,6 +929,28 @@ d->emitCompressedColorChanged(); } +void PlatformTheme::setCustomTitlebarBackgroundColor(const QColor &color) +{ + if (d->customTitlebarBackgroundColor == color) { + return; + } + + d->customTitlebarBackgroundColor = color; + PROPAGATECUSTOMCOLOR(CustomTitlebarBackgroundColor, color) + d->emitCompressedColorChanged(); +} + +void PlatformTheme::setCustomTitlebarTextColor(const QColor &color) +{ + if (d->customTitlebarTextColor == color) { + return; + } + + d->customTitlebarTextColor = color; + PROPAGATECUSTOMCOLOR(CustomTitlebarTextColor, color) + d->emitCompressedColorChanged(); +} + QPalette PlatformTheme::palette() const {