From caa4c7090931f1216469646d92676fd2a956923a Mon Sep 17 00:00:00 2001 From: "Aaron J. Seigo" Date: Sun, 4 Nov 2007 06:57:42 +0000 Subject: [PATCH] color scheme support. now to get someone to make a proper color scheme for the default theme =) svn path=/trunk/KDE/kdebase/workspace/libs/plasma/; revision=732535 --- theme.cpp | 48 +++++++++++++++++++++++++++++++++++++++++------- theme.h | 9 +++++++++ 2 files changed, 50 insertions(+), 7 deletions(-) diff --git a/theme.cpp b/theme.cpp index 402573d28..4ae9a12ab 100644 --- a/theme.cpp +++ b/theme.cpp @@ -19,6 +19,8 @@ #include "theme.h" +#include + #include #include #include @@ -31,7 +33,6 @@ class Theme::Private { public: Private() - : themeName("default") { } @@ -42,12 +43,13 @@ public: groupName.append("-").append(app); } - KSharedConfig::Ptr config = KSharedConfig::openConfig("plasmarc"); + KSharedConfigPtr config = KSharedConfig::openConfig("plasmarc"); return KConfigGroup(config, groupName); } QString themeName; QString app; + KSharedConfigPtr colors; }; class ThemeSingleton @@ -86,16 +88,40 @@ void Theme::setApplication(const QString &appname) void Theme::settingsChanged() { - setThemeName(d->config().readEntry("name", d->themeName)); + setThemeName(d->config().readEntry("name", "default")); } void Theme::setThemeName(const QString &themeName) { - if (themeName != d->themeName && - !KStandardDirs::locate("data", "desktoptheme/" + d->themeName).isEmpty()) { - d->themeName = themeName; - emit changed(); + if (themeName.isEmpty() || themeName == d->themeName) { + // let's try and get the default theme at least + if (d->themeName.isEmpty()) { + setThemeName("default"); + } + return; } + + //TODO: should we care about names with relative paths in them? + QString themePath = KStandardDirs::locate("data", "desktoptheme/" + themeName + "/"); + if (themePath.isEmpty()) { + // let's try and get the default theme at least + if (d->themeName.isEmpty() && themeName != "default") { + setThemeName("default"); + } + return; + } + + d->themeName = themeName; + + // load the color scheme config + themePath = themePath.append("colors"); + if (QFile::exists(themePath)) { + d->colors = KSharedConfig::openConfig(themePath); + } else { + d->colors = 0; + } + + emit changed(); } QString Theme::themeName() const @@ -105,6 +131,9 @@ QString Theme::themeName() const QString Theme::image( const QString& name ) const { + //TODO: performance ... should we try and cache the results of KStandardDirs::locate? + // should we just use whatever theme path was returned and not care about cascades? + // (probably "no" on the last question) QString search = "desktoptheme/" + d->themeName + '/' + name + ".svg"; QString path = KStandardDirs::locate( "data", search ); @@ -123,6 +152,11 @@ QString Theme::image( const QString& name ) const return path; } +KSharedConfigPtr Theme::colors() const +{ + return d->colors; +} + } #include diff --git a/theme.h b/theme.h index 9a11f6cb5..569720d8c 100644 --- a/theme.h +++ b/theme.h @@ -22,6 +22,8 @@ #include +#include + #include namespace Plasma @@ -87,6 +89,13 @@ class PLASMA_EXPORT Theme : public QObject */ Q_INVOKABLE QString image( const QString& name ) const; + /** + * Returns the color scheme configurationthat goes along this theme. + * This can be used with KStatefulBrush and KColorScheme to determine + * the proper colours to use along with the visual elements in this theme. + */ + Q_INVOKABLE KSharedConfigPtr colors() const; + Q_SIGNALS: /** * Emitted when the user changes the theme. SVGs should be reloaded at