Creating a KColorScheme is expensive, so let's not do that every time

someone calls Theme::color().

svn path=/trunk/KDE/kdebase/workspace/libs/plasma/; revision=867517
This commit is contained in:
Fredrik Höglund 2008-10-03 17:44:04 +00:00
parent 22919a4b27
commit 48b41f3a85

View File

@ -50,6 +50,7 @@ class ThemePrivate
public: public:
ThemePrivate(Theme *theme) ThemePrivate(Theme *theme)
: q(theme), : q(theme),
colorScheme(QPalette::Active, KColorScheme::Window, KSharedConfigPtr(0)),
defaultWallpaperTheme(DEFAULT_WALLPAPER_THEME), defaultWallpaperTheme(DEFAULT_WALLPAPER_THEME),
defaultWallpaperSuffix(DEFAULT_WALLPAPER_SUFFIX), defaultWallpaperSuffix(DEFAULT_WALLPAPER_SUFFIX),
defaultWallpaperWidth(DEFAULT_WALLPAPER_WIDTH), defaultWallpaperWidth(DEFAULT_WALLPAPER_WIDTH),
@ -92,6 +93,7 @@ public:
Theme *q; Theme *q;
QString themeName; QString themeName;
KSharedConfigPtr colors; KSharedConfigPtr colors;
KColorScheme colorScheme;
KConfigGroup cfg; KConfigGroup cfg;
QFont generalFont; QFont generalFont;
QString defaultWallpaperTheme; QString defaultWallpaperTheme;
@ -260,6 +262,7 @@ void Theme::setThemeName(const QString &themeName)
d->colors = KSharedConfig::openConfig(colorsFile); d->colors = KSharedConfig::openConfig(colorsFile);
} }
d->colorScheme = KColorScheme(QPalette::Active, KColorScheme::Window, d->colors);
d->hasWallpapers = !KStandardDirs::locate("data", "desktoptheme/" + theme + "/wallpapers").isEmpty(); d->hasWallpapers = !KStandardDirs::locate("data", "desktoptheme/" + theme + "/wallpapers").isEmpty();
if (d->isDefault) { if (d->isDefault) {
@ -381,19 +384,17 @@ KSharedConfigPtr Theme::colorScheme() const
QColor Theme::color(ColorRole role) const QColor Theme::color(ColorRole role) const
{ {
KColorScheme colorScheme(QPalette::Active, KColorScheme::Window, Theme::defaultTheme()->colorScheme());
switch (role) { switch (role) {
case TextColor: case TextColor:
return colorScheme.foreground(KColorScheme::NormalText).color(); return d->colorScheme.foreground(KColorScheme::NormalText).color();
break; break;
case HighlightColor: case HighlightColor:
return colorScheme.background(KColorScheme::ActiveBackground).color(); return d->colorScheme.background(KColorScheme::ActiveBackground).color();
break; break;
case BackgroundColor: case BackgroundColor:
return colorScheme.background().color(); return d->colorScheme.background().color();
break; break;
} }