revert these changes as they go violate a number of design principles; this has been patiently explained a number of times now.

svn path=/trunk/KDE/kdelibs/; revision=962172
This commit is contained in:
Aaron J. Seigo 2009-05-01 16:28:10 +00:00
parent 0e8b03d2fa
commit 03ee0a6839
7 changed files with 41 additions and 262 deletions

View File

@ -32,7 +32,6 @@
#include <plasma/theme.h>
#include <plasma/applet.h>
#include "private/framebackgroundprovider.h"
namespace Plasma
{
@ -385,27 +384,20 @@ void FrameSvg::paintFrame(QPainter *painter, const QPointF &pos)
painter->drawPixmap(pos, frame->cachedBackground);
}
QString FrameSvgPrivate::cacheId(const FrameData* frame) const
{
Theme *theme = Theme::defaultTheme();
StandardThemeBackgroundProvider backgroundProvider(theme, q->imagePath());
return QString::fromLatin1("%6_%5_%4_%3_%2_%1_").
arg(frame->enabledBorders).arg(frame->frameSize.width()).arg(frame->frameSize.height()).arg(prefix)
.arg(q->imagePath()).arg(backgroundProvider.identity());
}
void FrameSvgPrivate::generateBackground(FrameData *frame)
{
if (!frame->cachedBackground.isNull()) {
return;
}
QString id = cacheId(frame);
QString id = QString::fromLatin1("%5_%4_%3_%2_%1_").
arg(frame->enabledBorders).arg(frame->frameSize.width()).arg(frame->frameSize.height()).arg(prefix).arg(q->imagePath());
Theme *theme = Theme::defaultTheme();
if (theme->findInCache(id, frame->cachedBackground) && !frame->cachedBackground.isNull())
if (theme->findInCache(id, frame->cachedBackground) && !frame->cachedBackground.isNull()) {
return;
}
//kDebug() << "generating background";
const int topWidth = q->elementSize(prefix + "top").width();
@ -610,14 +602,6 @@ void FrameSvgPrivate::generateBackground(FrameData *frame)
p.drawPixmap(overlayPos, overlay, QRect(overlayPos, overlaySize));
}
if(!prefix.startsWith("mask-")) {
StandardThemeBackgroundProvider backgroundProvider(theme, q->imagePath());
if(backgroundProvider) {
p.setClipRegion(q->mask() );
backgroundProvider.apply(p);
}
}
if (!framesToSave.contains(prefix)) {
framesToSave.append(prefix);
}
@ -633,7 +617,8 @@ void FrameSvgPrivate::scheduledCacheUpdate()
FrameData *frame = frames[prefix];
framesToSave.removeAll(prefixToSave);
QString id = cacheId(frame);
QString id = QString::fromLatin1("%5_%4_%3_%2_%1_").
arg(frame->enabledBorders).arg(frame->frameSize.width()).arg(frame->frameSize.height()).arg(prefix).arg(q->imagePath());
//kDebug()<<"Saving to cache frame"<<id;

View File

@ -1,73 +0,0 @@
/*
* Copyright 2009 David Nolden <david.nolden.kdevelop@art-master.de>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Library General Public License as
* published by the Free Software Foundation; either version 2, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details
*
* You should have received a copy of the GNU Library General Public
* License along with this program; if not, write to the
* Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#ifndef PLASMA_PANELBACKGROUNDPROVIDER_H
#define PLASMA_PANELBACKGROUNDPROVIDER_H
namespace Plasma {
class Theme;
/**
* A class that paints an additional background behind specific elements of a theme.
* Construct it locally right before using it.
*/
class StandardThemeBackgroundProvider {
public:
/**
* Constructs a background-provider for the given theme
*/
StandardThemeBackgroundProvider(Theme* theme, QString imagePath);
/**
* Applies the background to the given target. The target must have correct alpha-values,
* so the background can be painted under it. Also the clip-region must be already set correctly
* to restrict the area where the background is painted.
* @param target The target where the background should be painted
* @param offset Additional offset for the rendering: The render-source is translated by this offset
*/
void apply(QPainter& target) const;
/**
* Returns an identity that can be used for caching the result of the background rendering.
* @return The identity string
*/
QString identity() const;
static void clearCache();
/**
* Returns true if this background-provider will paint something
*/
operator bool() const;
private:
QColor m_color;
QString m_pattern;
int m_patternAlpha;
int m_offsetX;
int m_offsetY;
bool m_valid;
//Maps file-name to (image, alpha)
typedef QPair<QImage, int> PatternAlphaPair; //The alpha value is statically applied to the pattern
static QMap<QString, PatternAlphaPair > m_cachedPatterns;
};
}
#endif

View File

@ -85,8 +85,6 @@ public:
frames.clear();
}
QString cacheId(const FrameData* frame) const;
void generateBackground(FrameData *frame);
void scheduledCacheUpdate();
void updateSizes();

View File

@ -155,13 +155,16 @@ void WindowPreview::setInfo()
XDeleteProperty(dpy, parentWidget()->winId(), atom);
return;
}
if (windowSizes.size() == 0) {
readWindowSizes();
}
if (windowSizes.size() == 0) {
XDeleteProperty(dpy, parentWidget()->winId(), atom);
return;
}
Q_ASSERT(parentWidget()->isWindow()); // parent must be toplevel
QSize thumbnailSize = sizeHint();
@ -184,11 +187,11 @@ void WindowPreview::setInfo()
x += s.width() + WINDOW_MARGIN;
}
QVarLengthArray<long, 1024> data(1 + 6*numWindows);
QVarLengthArray<long, 1024> data(1 + (6 * numWindows));
data[0] = numWindows;
for (int i = 0; i<numWindows; ++i) {
const int start = i*6+1;
for (int i = 0; i < numWindows; ++i) {
const int start = (i * 6) + 1;
const QRect thumbnailRect = m_thumbnailRects[i];
data[start] = 5;

46
svg.cpp
View File

@ -364,29 +364,31 @@ class SvgPrivate
QString newPath = Theme::defaultTheme()->imagePath(themePath);
if (path != newPath) {
path = newPath;
//delete d->renderer; we're a KSharedPtr
eraseRenderer();
// check if new theme svg wants colorscheme applied
bool wasApplyColors = applyColors;
checkApplyColorHint();
if (applyColors && !Theme::defaultTheme()->colorScheme()) {
if (!wasApplyColors) {
QObject::connect(KGlobalSettings::self(), SIGNAL(kdisplayPaletteChanged()),
q, SLOT(colorsChanged()));
}
} else {
QObject::disconnect(KGlobalSettings::self(), SIGNAL(kdisplayPaletteChanged()),
q, SLOT(colorsChanged()));
}
localRectCache.clear();
itemsToSave.clear();
saveTimer->stop();
if (path == newPath) {
return;
}
//Even trigger a repaint when the theme path has not changed.
//It may be other aspects of the theme rendering that changed (Composition type, background color, ...)
path = newPath;
//delete d->renderer; we're a KSharedPtr
eraseRenderer();
// check if new theme svg wants colorscheme applied
bool wasApplyColors = applyColors;
checkApplyColorHint();
if (applyColors && !Theme::defaultTheme()->colorScheme()) {
if (!wasApplyColors) {
QObject::connect(KGlobalSettings::self(), SIGNAL(kdisplayPaletteChanged()),
q, SLOT(colorsChanged()));
}
} else {
QObject::disconnect(KGlobalSettings::self(), SIGNAL(kdisplayPaletteChanged()),
q, SLOT(colorsChanged()));
}
localRectCache.clear();
itemsToSave.clear();
saveTimer->stop();
//kDebug() << themePath << ">>>>>>>>>>>>>>>>>> theme changed";
emit q->repaintNeeded();
}

141
theme.cpp
View File

@ -22,7 +22,6 @@
#include <QApplication>
#include <QFile>
#include <QFileInfo>
#include <QtGui/QPainter>
#ifdef Q_WS_X11
#include <QX11Info>
#endif
@ -41,7 +40,6 @@
#include <kwindowsystem.h>
#include "private/packages_p.h"
#include "private/framebackgroundprovider.h"
namespace Plasma
{
@ -51,8 +49,6 @@ namespace Plasma
static const int DEFAULT_WALLPAPER_WIDTH = 1920;
static const int DEFAULT_WALLPAPER_HEIGHT = 1200;
QMap<QString, StandardThemeBackgroundProvider::PatternAlphaPair> StandardThemeBackgroundProvider::m_cachedPatterns;
class ThemePrivate
{
public:
@ -86,10 +82,6 @@ public:
return KConfigGroup(KSharedConfig::openConfig(themeRcFile), "CachePolicies");
}
const KConfigGroup& config() const {
return const_cast<ThemePrivate*>(this)->config();
}
KConfigGroup &config()
{
if (!cfg.isValid()) {
@ -110,28 +102,6 @@ public:
return cfg;
}
/**
* Reads optional configuration, that is specific to the current composite mode:
* When composition is active, the configuration entry is prefixed with "composite_".
* Optionally, the configuration can also be specific to the specified image path:
* Then the image path has to be appended to the configuration name
*/
template<class T>
T readOptionalConfig(QString configName, T _default, QString imagePath) {
if(compositingActive)
configName = "composite_" + configName;
T ret = config().readEntry(configName, _default);
return config().readEntry(configName + "_" + imagePath, ret);
}
bool hasOptionalConfig(QString configName, QString imagePath = QString()) {
if(compositingActive)
configName = "composite_" + configName;
return config().hasKey(configName) || config().hasKey(configName + "_" + imagePath);
}
QString findInTheme(const QString &image, const QString &theme) const;
void compositingChanged();
void discardCache();
@ -194,7 +164,7 @@ QString ThemePrivate::findInTheme(const QString &image, const QString &theme) co
if (locolor) {
search = "desktoptheme/" + theme + "/locolor/" + image;
search = KStandardDirs::locate("data", search);
} else if (!compositingActive && !config().readEntry<bool>("forceTransparentTheme", false)) {
} else if (!compositingActive) {
search = "desktoptheme/" + theme + "/opaque/" + image;
search = KStandardDirs::locate("data", search);
}
@ -322,26 +292,13 @@ PackageStructure::Ptr Theme::packageStructure()
void ThemePrivate::settingsFileChanged(const QString &file)
{
kDebug() << file;
QMap< QString, QString > oldEntries = config().entryMap();
config().config()->reparseConfiguration();
if(oldEntries != config().entryMap())
q->settingsChanged();
q->settingsChanged();
}
void Theme::settingsChanged()
{
StandardThemeBackgroundProvider::clearCache(); //So we don't waste memory with background images that are not used
QString newThemeName = d->config().readEntry("name", ThemePrivate::defaultTheme);
if(newThemeName != d->themeName) {
d->setThemeName(newThemeName, false);
}else{
///@todo More precise monitoring of attributes
d->discardCache(true);
emit themeChanged();
}
d->setThemeName(d->config().readEntry("name", ThemePrivate::defaultTheme), false);
}
void Theme::setThemeName(const QString &themeName)
@ -740,98 +697,6 @@ void Theme::setCacheLimit(int kbytes)
}
}
void StandardThemeBackgroundProvider::clearCache()
{
m_cachedPatterns.clear();
}
StandardThemeBackgroundProvider::StandardThemeBackgroundProvider(Theme* theme, QString imagePath) : m_color(Qt::black), m_patternAlpha(0), m_valid(false)
{
if(theme->d->locolor)
return;
if((imagePath.startsWith("widgets/panel-") || imagePath.startsWith("dialogs/")) &&
(theme->d->hasOptionalConfig("frameBackgroundColor") || theme->d->hasOptionalConfig("frameBackgroundPattern")))
{
m_valid = true;
m_color = theme->d->readOptionalConfig<QColor>("frameBackgroundColor", Qt::black, imagePath);
if(theme->d->hasOptionalConfig("frameBackgroundColor"))
m_color.setAlpha(theme->d->readOptionalConfig<int>("frameBackgroundColorAlpha", 255, imagePath));
else
m_color.setAlpha(0);
m_pattern = theme->d->readOptionalConfig<QString>("frameBackgroundPattern", QString(), imagePath);
m_patternAlpha = theme->d->readOptionalConfig<int>("frameBackgroundPatternAlpha", 255, imagePath);
m_offsetX = theme->d->readOptionalConfig<int>("frameBackgroundPatternOffsetX", 0, imagePath);
m_offsetY = theme->d->readOptionalConfig<int>("frameBackgroundPatternOffsetY", 0, imagePath);
int randomX = theme->d->readOptionalConfig<int>("frameBackgroundPatternOffsetRandomX", 0, imagePath);
int randomY = theme->d->readOptionalConfig<int>("frameBackgroundPatternOffsetRandomY", 0, imagePath);
if(randomX || randomY) {
//Add "this" so the offsets are different after every startup, but stay same for the same image path
qsrand(qHash(imagePath) + ((size_t)this) + randomX + 11 * randomY);
if(randomX)
m_offsetX += qrand() % randomX;
if(randomY)
m_offsetY += qrand() % randomY;
}
}
}
void StandardThemeBackgroundProvider::apply(QPainter& target) const
{
if(!m_valid)
return;
target.setCompositionMode(QPainter::CompositionMode_DestinationOver);
//Apply color
if(m_color.alpha())
target.fillRect(target.clipRegion().boundingRect(), m_color);
//Apply pattern
if(m_patternAlpha && !m_pattern.isEmpty()) {
if(!m_cachedPatterns.contains(m_pattern) || m_cachedPatterns[m_pattern].second != m_patternAlpha) {
m_cachedPatterns.remove(m_pattern);
m_cachedPatterns.insert(m_pattern, PatternAlphaPair(QImage(m_pattern), m_patternAlpha));
if(m_patternAlpha != 255) {
PatternAlphaPair& cached(m_cachedPatterns[m_pattern]);
//Apply lower alpha value to the pattern
QImage alpha(cached.first.size(), QImage::Format_ARGB32);
alpha.fill(QColor(cached.second, cached.second, cached.second).rgb());
cached.first.setAlphaChannel(alpha);
}
}
PatternAlphaPair& cached(m_cachedPatterns[m_pattern]);
if(!cached.first.isNull()) {
QBrush brush;
QColor col(Qt::white);
col.setAlpha(m_patternAlpha);
brush.setColor(col);
brush.setTextureImage(cached.first);
target.setBrushOrigin(-m_offsetX, -m_offsetY);
target.fillRect(target.clipRegion().boundingRect(), brush);
}else{
kDebug() << "failed to load pattern" << m_pattern;
}
}
}
StandardThemeBackgroundProvider::operator bool() const
{
return m_valid;
}
QString StandardThemeBackgroundProvider::identity() const
{
if(!m_valid)
return QString();
return QString("bgcolor_%1=").arg(m_color.alpha()) + m_color.name()+QString("_pattern_%1=").arg(m_patternAlpha)+m_pattern + QString("_offsets_%1_%2__").arg(m_offsetX).arg(m_offsetY);
}
}
#include <theme.moc>

View File

@ -31,7 +31,7 @@
namespace Plasma
{
class StandardThemeBackgroundProvider;
class ThemePrivate;
/**
@ -282,7 +282,6 @@ class PLASMA_EXPORT Theme : public QObject
private:
friend class ThemeSingleton;
friend class ThemePrivate;
friend class StandardThemeBackgroundProvider;
ThemePrivate *const d;
Q_PRIVATE_SLOT(d, void compositingChanged())