From 5884df4cfcb1c6f8a767fdc7d1b61e7e51583c21 Mon Sep 17 00:00:00 2001 From: Marco Martin Date: Thu, 21 May 2020 18:43:38 +0200 Subject: [PATCH] support the Header color grgoup Support the new Header color group in KColorScheme by proxying it in Plasma::Theme and the kirigami styles here --- src/declarativeimports/core/quicktheme.cpp | 40 ++++++++++++ src/declarativeimports/core/quicktheme.h | 64 ++++++++++++++++++- .../AbstractApplicationHeader.qml | 3 +- .../kirigamiplasmastyle/Theme.qml | 9 +++ src/plasma/pluginloader.cpp | 1 - src/plasma/private/theme_p.cpp | 35 ++++++++++ src/plasma/private/theme_p.h | 1 + src/plasma/theme.h | 3 +- 8 files changed, 150 insertions(+), 6 deletions(-) diff --git a/src/declarativeimports/core/quicktheme.cpp b/src/declarativeimports/core/quicktheme.cpp index ef31e3eab..e2294f7e3 100644 --- a/src/declarativeimports/core/quicktheme.cpp +++ b/src/declarativeimports/core/quicktheme.cpp @@ -204,6 +204,46 @@ QColor QuickTheme::complementaryNegativeTextColor() const return Plasma::Theme::color(Plasma::Theme::TextColor, Plasma::Theme::ComplementaryColorGroup); } + +QColor QuickTheme::headerTextColor() const +{ + return Plasma::Theme::color(Plasma::Theme::TextColor, Plasma::Theme::HeaderColorGroup); +} + +QColor QuickTheme::headerBackgroundColor() const +{ + return Plasma::Theme::color(Plasma::Theme::BackgroundColor, Plasma::Theme::HeaderColorGroup); +} + +QColor QuickTheme::headerHoverColor() const +{ + return Plasma::Theme::color(Plasma::Theme::HoverColor, Plasma::Theme::HeaderColorGroup); +} + +QColor QuickTheme::headerFocusColor() const +{ + return Plasma::Theme::color(Plasma::Theme::FocusColor, Plasma::Theme::HeaderColorGroup); +} + +QColor QuickTheme::headerHighlightedTextColor() const +{ + return Plasma::Theme::color(Plasma::Theme::HighlightedTextColor, Plasma::Theme::HeaderColorGroup); +} + +QColor QuickTheme::headerPositiveTextColor() const +{ + return Plasma::Theme::color(Plasma::Theme::TextColor, Plasma::Theme::HeaderColorGroup); +} + +QColor QuickTheme::headerNeutralTextColor() const +{ + return Plasma::Theme::color(Plasma::Theme::TextColor, Plasma::Theme::HeaderColorGroup); +} + +QColor QuickTheme::headerNegativeTextColor() const +{ + return Plasma::Theme::color(Plasma::Theme::TextColor, Plasma::Theme::HeaderColorGroup); +} } #include "moc_quicktheme.cpp" diff --git a/src/declarativeimports/core/quicktheme.h b/src/declarativeimports/core/quicktheme.h index 72efed7f8..ccb91ce2b 100644 --- a/src/declarativeimports/core/quicktheme.h +++ b/src/declarativeimports/core/quicktheme.h @@ -81,9 +81,18 @@ class QuickTheme : public Plasma::Theme Q_PROPERTY(QColor complementaryHoverColor READ complementaryHoverColor NOTIFY themeChangedProxy) Q_PROPERTY(QColor complementaryFocusColor READ complementaryFocusColor NOTIFY themeChangedProxy) Q_PROPERTY(QColor complementaryHighlightedTextColor READ complementaryHighlightedTextColor NOTIFY themeChangedProxy) - Q_PROPERTY(QColor complementaryPositiveTextColor READ buttonPositiveTextColor NOTIFY themeChangedProxy) - Q_PROPERTY(QColor complementaryNeutralTextColor READ buttonNeutralTextColor NOTIFY themeChangedProxy) - Q_PROPERTY(QColor complementaryNegativeTextColor READ buttonNegativeTextColor NOTIFY themeChangedProxy) + Q_PROPERTY(QColor complementaryPositiveTextColor READ complementaryPositiveTextColor NOTIFY themeChangedProxy) + Q_PROPERTY(QColor complementaryNeutralTextColor READ complementaryNeutralTextColor NOTIFY themeChangedProxy) + Q_PROPERTY(QColor complementaryNegativeTextColor READ complementaryNegativeTextColor NOTIFY themeChangedProxy) + + Q_PROPERTY(QColor headerTextColor READ headerTextColor NOTIFY themeChangedProxy) + Q_PROPERTY(QColor headerBackgroundColor READ headerBackgroundColor NOTIFY themeChangedProxy) + Q_PROPERTY(QColor headerHoverColor READ headerHoverColor NOTIFY themeChangedProxy) + Q_PROPERTY(QColor headerFocusColor READ headerFocusColor NOTIFY themeChangedProxy) + Q_PROPERTY(QColor headerHighlightedTextColor READ headerHighlightedTextColor NOTIFY themeChangedProxy) + Q_PROPERTY(QColor headerPositiveTextColor READ headerPositiveTextColor NOTIFY themeChangedProxy) + Q_PROPERTY(QColor headerNeutralTextColor READ headerNeutralTextColor NOTIFY themeChangedProxy) + Q_PROPERTY(QColor headerNegativeTextColor READ headerNegativeTextColor NOTIFY themeChangedProxy) public: explicit QuickTheme(QObject *parent = nullptr); @@ -295,6 +304,55 @@ public: */ QColor complementaryNegativeTextColor() const; + + /** + * @return The theme's colorscheme's text color of "header" areas + * @since 5.0 + */ + QColor headerTextColor() const; + + /** + * @return The theme's colorscheme's background color of "header" areas + * @since 5.0 + */ + QColor headerBackgroundColor() const; + + /** + * @return The theme's colorscheme's color of hovered "header" areas + * @since 5.0 + */ + QColor headerHoverColor() const; + + /** + * @return The theme's colorscheme's color of focused "header" areas + * @since 5.0 + */ + QColor headerFocusColor() const; + + /** + * @return The theme's colorscheme's highlighted text color for "header" areas + * @since 5.22 + */ + QColor headerHighlightedTextColor() const; + + /** + * @return The theme's colorscheme's positive text color of header + * @since 5.22 + */ + QColor headerPositiveTextColor() const; + + /** + * @return The theme's colorscheme's neutral text color of header + * @since 5.22 + */ + QColor headerNeutralTextColor() const; + + /** + * @return The theme's colorscheme's negative text color of header + * @since 5.22 + */ + QColor headerNegativeTextColor() const; + Q_SIGNALS: void themeChangedProxy(); }; diff --git a/src/declarativeimports/kirigamiplasmastyle/AbstractApplicationHeader.qml b/src/declarativeimports/kirigamiplasmastyle/AbstractApplicationHeader.qml index 91d332b99..33998c86c 100644 --- a/src/declarativeimports/kirigamiplasmastyle/AbstractApplicationHeader.qml +++ b/src/declarativeimports/kirigamiplasmastyle/AbstractApplicationHeader.qml @@ -14,7 +14,8 @@ import "../../private" as KirigamiPrivate T.AbstractApplicationHeader { id: root - Kirigami.Theme.inherit: true + Kirigami.Theme.inherit: false + Kirigami.Theme.colorSet: Kirigami.Theme.Header background: Rectangle { color: Kirigami.Theme.backgroundColor diff --git a/src/declarativeimports/kirigamiplasmastyle/Theme.qml b/src/declarativeimports/kirigamiplasmastyle/Theme.qml index 2de2c3f12..3158268c8 100644 --- a/src/declarativeimports/kirigamiplasmastyle/Theme.qml +++ b/src/declarativeimports/kirigamiplasmastyle/Theme.qml @@ -69,6 +69,12 @@ QtObject { property color complementaryHoverColor: theme.complementaryHoverColor property color complementaryFocusColor: theme.complementaryFocusColor + property color headerTextColor: theme.headerTextColor + property color headerBackgroundColor: theme.headerBackgroundColor + property color headerAlternateBackgroundColor: Qt.darker(theme.headerBackgroundColor, 1.05) + property color headerHoverColor: theme.headerHoverColor + property color headerFocusColor: theme.headerFocusColor + property variant defaultFont: theme.defaultFont property variant smallFont: theme.smallestFont @@ -93,6 +99,9 @@ QtObject { case Kirigami.Theme.Complementary: object.PlasmaCore.ColorScope.colorGroup = PlasmaCore.Theme.ComplementaryColorGroup; break; + case Kirigami.Theme.Header: + object.PlasmaCore.ColorScope.colorGroup = PlasmaCore.Theme.HeaderColorGroup; + break; } } function __propagateTextColor(object, color) {} diff --git a/src/plasma/pluginloader.cpp b/src/plasma/pluginloader.cpp index 6f06846ad..afad50995 100644 --- a/src/plasma/pluginloader.cpp +++ b/src/plasma/pluginloader.cpp @@ -208,7 +208,6 @@ Applet *PluginLoader::loadApplet(const QString &name, uint appletId, const QVari return applet; } - if (!applet) { //qCDebug(LOG_PLASMA) << name << "not a C++ applet: Falling back to an empty one"; diff --git a/src/plasma/private/theme_p.cpp b/src/plasma/private/theme_p.cpp index 84c75244f..edd614046 100644 --- a/src/plasma/private/theme_p.cpp +++ b/src/plasma/private/theme_p.cpp @@ -56,6 +56,7 @@ ThemePrivate::ThemePrivate(QObject *parent) buttonColorScheme(QPalette::Active, KColorScheme::Button, KSharedConfigPtr(nullptr)), viewColorScheme(QPalette::Active, KColorScheme::View, KSharedConfigPtr(nullptr)), complementaryColorScheme(QPalette::Active, KColorScheme::Complementary, KSharedConfigPtr(nullptr)), + headerColorScheme(QPalette::Active, KColorScheme::Header, KSharedConfigPtr(nullptr)), defaultWallpaperTheme(QStringLiteral(DEFAULT_WALLPAPER_THEME)), defaultWallpaperSuffix(QStringLiteral(DEFAULT_WALLPAPER_SUFFIX)), defaultWallpaperWidth(DEFAULT_WALLPAPER_WIDTH), @@ -486,6 +487,15 @@ const QString ThemePrivate::processStyleSheet(const QString &css, Plasma::Svg::S elements[QStringLiteral("%complementaryneutraltextcolor")] = color(Theme::NeutralTextColor, Theme::ComplementaryColorGroup).name(); elements[QStringLiteral("%complementarynegativetextcolor")] = color(Theme::NegativeTextColor, Theme::ComplementaryColorGroup).name(); + elements[QStringLiteral("%headertextcolor")] = color(status == Svg::Status::Selected ? Theme::HighlightedTextColor : Theme::TextColor, Theme::HeaderColorGroup).name(); + elements[QStringLiteral("%headerbackgroundcolor")] = color(status == Svg::Status::Selected ? Theme::HighlightColor : Theme::BackgroundColor, Theme::HeaderColorGroup).name(); + elements[QStringLiteral("%headerhovercolor")] = color(Theme::HoverColor, Theme::HeaderColorGroup).name(); + elements[QStringLiteral("%headerfocuscolor")] = color(Theme::FocusColor, Theme::HeaderColorGroup).name(); + elements[QStringLiteral("%headerhighlightedtextcolor")] = color(Theme::HighlightedTextColor, Theme::HeaderColorGroup).name(); + elements[QStringLiteral("%headerpositivetextcolor")] = color(Theme::PositiveTextColor, Theme::HeaderColorGroup).name(); + elements[QStringLiteral("%headerneutraltextcolor")] = color(Theme::NeutralTextColor, Theme::HeaderColorGroup).name(); + elements[QStringLiteral("%headernegativetextcolor")] = color(Theme::NegativeTextColor, Theme::HeaderColorGroup).name(); + QFont font = QGuiApplication::font(); elements[QStringLiteral("%fontsize")] = QStringLiteral("%1pt").arg(font.pointSize()); elements[QStringLiteral("%fontfamily")] = font.family().splitRef(QLatin1Char('[')).first().toString(); @@ -536,6 +546,16 @@ const QString ThemePrivate::svgStyleSheet(Plasma::Theme::ColorGroup group, Plasm stylesheet += skel.arg(QStringLiteral("NeutralText"), QStringLiteral("%complementaryneutraltextcolor")); stylesheet += skel.arg(QStringLiteral("NegativeText"), QStringLiteral("%complementarynegativetextcolor")); break; + case Theme::HeaderColorGroup: + stylesheet += skel.arg(QStringLiteral("Text"), QStringLiteral("%headertextcolor")); + stylesheet += skel.arg(QStringLiteral("Background"), QStringLiteral("%headerbackgroundcolor")); + + stylesheet += skel.arg(QStringLiteral("Highlight"), QStringLiteral("%headerhovercolor")); + stylesheet += skel.arg(QStringLiteral("HighlightedText"), QStringLiteral("%headerhighlightedtextcolor")); + stylesheet += skel.arg(QStringLiteral("PositiveText"), QStringLiteral("%headerpositivetextcolor")); + stylesheet += skel.arg(QStringLiteral("NeutralText"), QStringLiteral("%headerneutraltextcolor")); + stylesheet += skel.arg(QStringLiteral("NegativeText"), QStringLiteral("%headernegativetextcolor")); + break; default: stylesheet += skel.arg(QStringLiteral("Text"), QStringLiteral("%textcolor")); stylesheet += skel.arg(QStringLiteral("Background"), QStringLiteral("%backgroundcolor")); @@ -574,6 +594,15 @@ const QString ThemePrivate::svgStyleSheet(Plasma::Theme::ColorGroup group, Plasm stylesheet += skel.arg(QStringLiteral("ComplementaryNeutralText"), QStringLiteral("%complementaryneutraltextcolor")); stylesheet += skel.arg(QStringLiteral("ComplementaryNegativeText"), QStringLiteral("%complementarynegativetextcolor")); + stylesheet += skel.arg(QStringLiteral("HeaderText"), QStringLiteral("%headertextcolor")); + stylesheet += skel.arg(QStringLiteral("HeaderBackground"), QStringLiteral("%headerbackgroundcolor")); + stylesheet += skel.arg(QStringLiteral("HeaderHover"), QStringLiteral("%headerhovercolor")); + stylesheet += skel.arg(QStringLiteral("HeaderFocus"), QStringLiteral("%headerfocuscolor")); + stylesheet += skel.arg(QStringLiteral("HeaderHighlightedText"), QStringLiteral("%headerhighlightedtextcolor")); + stylesheet += skel.arg(QStringLiteral("HeaderPositiveText"), QStringLiteral("%headerpositivetextcolor")); + stylesheet += skel.arg(QStringLiteral("HeaderNeutralText"), QStringLiteral("%headerneutraltextcolor")); + stylesheet += skel.arg(QStringLiteral("HeaderNegativeText"), QStringLiteral("%headernegativetextcolor")); + stylesheet = processStyleSheet(stylesheet, status); if (status == Svg::Status::Selected) { cachedSelectedSvgStyleSheets.insert(group, stylesheet); @@ -652,6 +681,11 @@ QColor ThemePrivate::color(Theme::ColorRole role, Theme::ColorGroup group) const break; } + case Theme::HeaderColorGroup: { + scheme = &headerColorScheme; + break; + } + case Theme::NormalColorGroup: default: { scheme = &colorScheme; @@ -803,6 +837,7 @@ void ThemePrivate::setThemeName(const QString &tempThemeName, bool writeSettings buttonColorScheme = KColorScheme(QPalette::Active, KColorScheme::Button, colors); viewColorScheme = KColorScheme(QPalette::Active, KColorScheme::View, colors); complementaryColorScheme = KColorScheme(QPalette::Active, KColorScheme::Complementary, colors); + headerColorScheme = KColorScheme(QPalette::Active, KColorScheme::Header, colors); palette = KColorScheme::createApplicationPalette(colors); const QString wallpaperPath = QLatin1String(PLASMA_RELATIVE_DATA_INSTALL_DIR "/desktoptheme/") % theme % QLatin1String("/wallpapers/"); hasWallpapers = !QStandardPaths::locate(QStandardPaths::GenericDataLocation, wallpaperPath, QStandardPaths::LocateDirectory).isEmpty(); diff --git a/src/plasma/private/theme_p.h b/src/plasma/private/theme_p.h index b99376786..8beaa10e9 100644 --- a/src/plasma/private/theme_p.h +++ b/src/plasma/private/theme_p.h @@ -119,6 +119,7 @@ public: KColorScheme buttonColorScheme; KColorScheme viewColorScheme; KColorScheme complementaryColorScheme; + KColorScheme headerColorScheme; QPalette palette; bool eventFilter(QObject *watched, QEvent *event) override; KConfigGroup cfg; diff --git a/src/plasma/theme.h b/src/plasma/theme.h index 13009c328..1627d9783 100644 --- a/src/plasma/theme.h +++ b/src/plasma/theme.h @@ -90,7 +90,8 @@ public: NormalColorGroup = 0, ButtonColorGroup = 1, ViewColorGroup = 2, - ComplementaryColorGroup = 3 + ComplementaryColorGroup = 3, + HeaderColorGroup }; Q_ENUM(ColorGroup)