From 03ee0a683982ef25a4ab5300ef34be147efbd99e Mon Sep 17 00:00:00 2001 From: "Aaron J. Seigo" Date: Fri, 1 May 2009 16:28:10 +0000 Subject: [PATCH] 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 --- framesvg.cpp | 29 ++---- private/framebackgroundprovider.h | 73 ---------------- private/framesvg_p.h | 2 - private/windowpreview.cpp | 9 +- svg.cpp | 46 +++++----- theme.cpp | 141 +----------------------------- theme.h | 3 +- 7 files changed, 41 insertions(+), 262 deletions(-) delete mode 100644 private/framebackgroundprovider.h diff --git a/framesvg.cpp b/framesvg.cpp index f2a0f9262..3d4d62412 100644 --- a/framesvg.cpp +++ b/framesvg.cpp @@ -32,7 +32,6 @@ #include #include -#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"< - * - * 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 PatternAlphaPair; //The alpha value is statically applied to the pattern - static QMap m_cachedPatterns; -}; - -} - -#endif diff --git a/private/framesvg_p.h b/private/framesvg_p.h index 837ecf04c..f81f6bebc 100644 --- a/private/framesvg_p.h +++ b/private/framesvg_p.h @@ -85,8 +85,6 @@ public: frames.clear(); } - QString cacheId(const FrameData* frame) const; - void generateBackground(FrameData *frame); void scheduledCacheUpdate(); void updateSizes(); diff --git a/private/windowpreview.cpp b/private/windowpreview.cpp index e204a76c3..7a6870928 100644 --- a/private/windowpreview.cpp +++ b/private/windowpreview.cpp @@ -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 data(1 + 6*numWindows); + QVarLengthArray data(1 + (6 * numWindows)); data[0] = numWindows; - for (int i = 0; iimagePath(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(); } diff --git a/theme.cpp b/theme.cpp index ad8def380..4915c7342 100644 --- a/theme.cpp +++ b/theme.cpp @@ -22,7 +22,6 @@ #include #include #include -#include #ifdef Q_WS_X11 #include #endif @@ -41,7 +40,6 @@ #include #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 StandardThemeBackgroundProvider::m_cachedPatterns; - class ThemePrivate { public: @@ -86,10 +82,6 @@ public: return KConfigGroup(KSharedConfig::openConfig(themeRcFile), "CachePolicies"); } - const KConfigGroup& config() const { - return const_cast(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 - 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("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("frameBackgroundColor", Qt::black, imagePath); - if(theme->d->hasOptionalConfig("frameBackgroundColor")) - m_color.setAlpha(theme->d->readOptionalConfig("frameBackgroundColorAlpha", 255, imagePath)); - else - m_color.setAlpha(0); - - m_pattern = theme->d->readOptionalConfig("frameBackgroundPattern", QString(), imagePath); - m_patternAlpha = theme->d->readOptionalConfig("frameBackgroundPatternAlpha", 255, imagePath); - m_offsetX = theme->d->readOptionalConfig("frameBackgroundPatternOffsetX", 0, imagePath); - m_offsetY = theme->d->readOptionalConfig("frameBackgroundPatternOffsetY", 0, imagePath); - int randomX = theme->d->readOptionalConfig("frameBackgroundPatternOffsetRandomX", 0, imagePath); - int randomY = theme->d->readOptionalConfig("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 diff --git a/theme.h b/theme.h index 28880622f..0d15f94d3 100644 --- a/theme.h +++ b/theme.h @@ -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())