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
This commit is contained in:
parent
7da6eebdcb
commit
caa4c70909
48
theme.cpp
48
theme.cpp
@ -19,6 +19,8 @@
|
||||
|
||||
#include "theme.h"
|
||||
|
||||
#include <QFile>
|
||||
|
||||
#include <KSharedConfig>
|
||||
#include <KStandardDirs>
|
||||
#include <kdebug.h>
|
||||
@ -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 <theme.moc>
|
||||
|
9
theme.h
9
theme.h
@ -22,6 +22,8 @@
|
||||
|
||||
#include <QtCore/QObject>
|
||||
|
||||
#include <KSharedConfig>
|
||||
|
||||
#include <plasma/plasma_export.h>
|
||||
|
||||
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
|
||||
|
Loading…
x
Reference in New Issue
Block a user