add support for locolor support in themes

svn path=/trunk/KDE/kdebase/workspace/libs/plasma/; revision=772585
This commit is contained in:
Aaron J. Seigo 2008-02-09 04:54:43 +00:00
parent 75c4518154
commit cf6a9e6cb9

View File

@ -38,6 +38,8 @@ class Theme::Private
{ {
public: public:
Private() Private()
: locolor(false),
compositingActive(KWindowSystem::compositingActive())
{ {
generalFont = QApplication::font(); generalFont = QApplication::font();
} }
@ -53,16 +55,22 @@ public:
return KConfigGroup(config, groupName); return KConfigGroup(config, groupName);
} }
QString findInTheme(const QString &image, const QString &theme) const;
static const char *defaultTheme;
QString themeName; QString themeName;
QString app; QString app;
KSharedConfigPtr colors; KSharedConfigPtr colors;
QFont generalFont; QFont generalFont;
bool locolor;
bool compositingActive; bool compositingActive;
#ifdef Q_WS_X11 #ifdef Q_WS_X11
KSelectionWatcher *compositeWatch; KSelectionWatcher *compositeWatch;
#endif #endif
}; };
const char *Theme::Private::defaultTheme = "default";
class ThemeSingleton class ThemeSingleton
{ {
public: public:
@ -81,14 +89,19 @@ Theme::Theme(QObject* parent)
d(new Private) d(new Private)
{ {
settingsChanged(); settingsChanged();
d->compositingActive = KWindowSystem::compositingActive();
#ifdef Q_WS_X11 #ifdef Q_WS_X11
char net_wm_cm_name[100]; Display *dpy = QX11Info::display();
sprintf(net_wm_cm_name, "_NET_WM_CM_S%d", DefaultScreen(QX11Info::display())); int screen = DefaultScreen(dpy);
d->compositeWatch = new KSelectionWatcher(net_wm_cm_name, -1, this); d->locolor = DefaultDepth(dpy, screen) < 16;
connect(d->compositeWatch, SIGNAL(newOwner(Window)), this, SLOT(compositingChanged()));
connect(d->compositeWatch, SIGNAL(lostOwner()), this, SLOT(compositingChanged())); if (!d->locolor) {
char net_wm_cm_name[100];
sprintf(net_wm_cm_name, "_NET_WM_CM_S%d", screen);
d->compositeWatch = new KSelectionWatcher(net_wm_cm_name, -1, this);
connect(d->compositeWatch, SIGNAL(newOwner(Window)), this, SLOT(compositingChanged()));
connect(d->compositeWatch, SIGNAL(lostOwner()), this, SLOT(compositingChanged()));
}
#endif #endif
} }
@ -108,7 +121,7 @@ void Theme::setApplication(const QString &appname)
void Theme::settingsChanged() void Theme::settingsChanged()
{ {
setThemeName(d->config().readEntry("name", "default")); setThemeName(d->config().readEntry("name", Private::defaultTheme));
} }
void Theme::compositingChanged() void Theme::compositingChanged()
@ -129,7 +142,7 @@ void Theme::setThemeName(const QString &themeName)
if (theme.isEmpty() || theme == d->themeName) { if (theme.isEmpty() || theme == d->themeName) {
// let's try and get the default theme at least // let's try and get the default theme at least
if (d->themeName.isEmpty()) { if (d->themeName.isEmpty()) {
theme = "default"; theme = Private::defaultTheme;
} else { } else {
return; return;
} }
@ -144,7 +157,7 @@ void Theme::setThemeName(const QString &themeName)
return; return;
} }
theme = "default"; theme = Private::defaultTheme;
} }
d->themeName = theme; d->themeName = theme;
@ -167,36 +180,38 @@ QString Theme::themeName() const
return d->themeName; return d->themeName;
} }
QString Theme::image( const QString& name ) const QString Theme::Private::findInTheme(const QString &image, const QString &theme) const
{ {
//TODO: this should be using Package
QString search; QString search;
QString path;
if (!d->compositingActive) { if (locolor) {
search = "desktoptheme/" + d->themeName + "/opaque/" + name + ".svg"; search = "desktoptheme/" + theme + "/locolor/" + image + ".svg";
path = KStandardDirs::locate( "data", search ); search = KStandardDirs::locate("data", search);
} else if (!compositingActive) {
search = "desktoptheme/" + theme + "/opaque/" + image + ".svg";
search = KStandardDirs::locate("data", search);
} }
//not found or compositing enabled //not found or compositing enabled
if (path.isEmpty()) { if (search.isEmpty()) {
search = "desktoptheme/" + d->themeName + '/' + name + ".svg"; search = "desktoptheme/" + theme + '/' + image + ".svg";
path = KStandardDirs::locate( "data", search ); search = KStandardDirs::locate("data", search);
}
return search;
}
QString Theme::image(const QString& name) const
{
QString path = d->findInTheme(name, d->themeName);
if (path.isEmpty() && d->themeName != Private::defaultTheme) {
path = d->findInTheme(name, Private::defaultTheme);
} }
if (path.isEmpty()) { if (path.isEmpty()) {
if (d->themeName != "default") { kDebug() << "Theme says: bad image path " << name;
if (!d->compositingActive) {
search = "desktoptheme/default/opaque/" + name + ".svg";
path = KStandardDirs::locate("data", search);
}
if (path.isEmpty()) {
search = "desktoptheme/default/" + name + ".svg";
path = KStandardDirs::locate("data", search);
}
}
if (path.isEmpty()) {
kDebug() << "Theme says: bad image path " << name
<< "; looked in: " << search << endl;
}
} }
return path; return path;