diff --git a/svg.cpp b/svg.cpp index 9135d9372..6f56720ac 100644 --- a/svg.cpp +++ b/svg.cpp @@ -23,7 +23,6 @@ #include #include #include -#include #include #include @@ -69,7 +68,6 @@ class SvgPrivate SvgPrivate(Svg *svg) : q(svg), theme(0), - saveTimer(0), renderer(0), lastModified(0), multipleImages(false), @@ -77,9 +75,6 @@ class SvgPrivate applyColors(false), cacheRendering(true) { - saveTimer = new QTimer(q); - saveTimer->setSingleShot(true); - QObject::connect(saveTimer, SIGNAL(timeout()), q, SLOT(scheduledCacheUpdate())); } ~SvgPrivate() @@ -233,27 +228,13 @@ class SvgPrivate p = p.fromImage(itmp); } - if (cacheRendering && !itemsToSave.contains(id)) { - itemsToSave.insert(id, p); - saveTimer->start(300); + if (cacheRendering) { + actualTheme()->insertIntoCache(id, p); } return p; } - void scheduledCacheUpdate() - { - QHash::const_iterator i = itemsToSave.constBegin(); - - while (i != itemsToSave.constEnd()) { - //kDebug()<<"Saving item to cache: " << i.key(); - actualTheme()->insertIntoCache(i.key(), i.value()); - ++i; - } - - itemsToSave.clear(); - } - void createRenderer() { if (renderer) { @@ -395,8 +376,6 @@ class SvgPrivate eraseRenderer(); localRectCache.clear(); - itemsToSave.clear(); - saveTimer->stop(); //kDebug() << themePath << ">>>>>>>>>>>>>>>>>> theme changed"; emit q->repaintNeeded(); @@ -409,8 +388,6 @@ class SvgPrivate } eraseRenderer(); - itemsToSave.clear(); - saveTimer->stop(); emit q->repaintNeeded(); } @@ -419,8 +396,6 @@ class SvgPrivate Svg *q; QPointer theme; QHash localRectCache; - QHash itemsToSave; - QTimer *saveTimer; SharedSvgRenderer::Ptr renderer; QString themePath; QString path; diff --git a/svg.h b/svg.h index e25e616aa..ef792990f 100644 --- a/svg.h +++ b/svg.h @@ -261,7 +261,6 @@ class PLASMA_EXPORT Svg : public QObject Q_PRIVATE_SLOT(d, void themeChanged()) Q_PRIVATE_SLOT(d, void colorsChanged()) - Q_PRIVATE_SLOT(d, void scheduledCacheUpdate()) friend class SvgPrivate; friend class FrameSvgPrivate; diff --git a/theme.cpp b/theme.cpp index 59199ff8f..52b307d09 100644 --- a/theme.cpp +++ b/theme.cpp @@ -22,6 +22,7 @@ #include #include #include +#include #ifdef Q_WS_X11 #include #endif @@ -84,6 +85,10 @@ public: QObject::connect(compositeWatch, SIGNAL(lostOwner()), q, SLOT(compositingChanged())); } #endif + + saveTimer = new QTimer(q); + saveTimer->setSingleShot(true); + QObject::connect(saveTimer, SIGNAL(timeout()), q, SLOT(scheduledCacheUpdate())); } ~ThemePrivate() @@ -120,6 +125,7 @@ public: void compositingChanged(); void discardCache(); void discardCache(bool recreateElementsCache); + void scheduledCacheUpdate(); void colorsChanged(); bool useCache(); void settingsFileChanged(const QString &); @@ -143,6 +149,8 @@ public: KPixmapCache *pixmapCache; KSharedConfigPtr svgElementsCache; QHash > invalidElements; + QHash pixmapsToCache; + QTimer *saveTimer; #ifdef Q_WS_X11 KSelectionWatcher *compositeWatch; @@ -216,9 +224,10 @@ void ThemePrivate::discardCache(bool recreateElementsCache) delete pixmapCache; pixmapCache = 0; invalidElements.clear(); + pixmapsToCache.clear(); + saveTimer->stop(); svgElementsCache = 0; - QString svgElementsFile = KStandardDirs::locateLocal("cache", "plasma-svgelements-" + themeName); if (!svgElementsFile.isEmpty()) { QFile f(svgElementsFile); @@ -230,6 +239,20 @@ void ThemePrivate::discardCache(bool recreateElementsCache) } } +void ThemePrivate::scheduledCacheUpdate() +{ + //kDebug()<< "Saving to cache:"; + QHash::const_iterator it = pixmapsToCache.constBegin(); + + while (it != pixmapsToCache.constEnd()) { + //kDebug()<< "Saving item to cache: " << it.key(); + pixmapCache->insert(it.key(), it.value()); + ++it; + } + + pixmapsToCache.clear(); +} + void ThemePrivate::colorsChanged() { discardCache(true); @@ -618,7 +641,16 @@ bool Theme::useNativeWidgetStyle() const bool Theme::findInCache(const QString &key, QPixmap &pix) { - return d->useCache() && d->pixmapCache->find(key, pix); + if (d->useCache()) { + if (d->pixmapsToCache.contains(key)) { + pix = d->pixmapsToCache.value(key); + return true; + } + + return d->pixmapCache->find(key, pix); + } + + return false; } // BIC FIXME: Should be merged with the other findInCache method above when we break BC @@ -634,7 +666,8 @@ bool Theme::findInCache(const QString &key, QPixmap &pix, unsigned int lastModif void Theme::insertIntoCache(const QString& key, const QPixmap& pix) { if (d->useCache()) { - d->pixmapCache->insert(key, pix); + d->pixmapsToCache.insert(key, pix); + d->saveTimer->start(500); } } diff --git a/theme.h b/theme.h index 9a24087db..0335d5a24 100644 --- a/theme.h +++ b/theme.h @@ -307,6 +307,7 @@ class PLASMA_EXPORT Theme : public QObject Q_PRIVATE_SLOT(d, void discardCache()) Q_PRIVATE_SLOT(d, void colorsChanged()) Q_PRIVATE_SLOT(d, void settingsFileChanged(const QString &)) + Q_PRIVATE_SLOT(d, void scheduledCacheUpdate()) }; } // Plasma namespace