From 9e50b9b61e48293245f04073b7bcfb6ed9110666 Mon Sep 17 00:00:00 2001 From: "Aaron J. Seigo" Date: Sun, 31 May 2009 05:38:42 +0000 Subject: [PATCH] * use the to-disk-cache-delay in Theme rather than do it per-FrameSvg object * be a bit more careful to use value() instead of [] in places as we sometimes check the hash for existence of an entry, and [] creates an entry while value() is more kind in that way svn path=/trunk/KDE/kdelibs/; revision=975773 --- framesvg.cpp | 63 ++++++++++++++++++++------------------------ framesvg.h | 1 - private/framesvg_p.h | 31 +++++++++++++++++----- 3 files changed, 54 insertions(+), 41 deletions(-) diff --git a/framesvg.cpp b/framesvg.cpp index cb79461dd..2a184faf4 100644 --- a/framesvg.cpp +++ b/framesvg.cpp @@ -42,10 +42,6 @@ FrameSvg::FrameSvg(QObject *parent) { connect(this, SIGNAL(repaintNeeded()), this, SLOT(updateNeeded())); d->frames.insert(QString(), new FrameData()); - - d->saveTimer = new QTimer(this); - d->saveTimer->setSingleShot(true); - connect(d->saveTimer, SIGNAL(timeout()), this, SLOT(scheduledCacheUpdate())); } FrameSvg::~FrameSvg() @@ -106,10 +102,11 @@ void FrameSvg::setElementPrefix(Plasma::Location location) setElementPrefix(QString()); break; } + d->location = location; } -void FrameSvg::setElementPrefix(const QString & prefix) +void FrameSvg::setElementPrefix(const QString &prefix) { const QString oldPrefix(d->prefix); @@ -120,21 +117,25 @@ void FrameSvg::setElementPrefix(const QString & prefix) if (!d->prefix.isEmpty()) { d->prefix += '-'; } - } - if (oldPrefix == d->prefix && d->frames[oldPrefix]) { + FrameData *oldFrameData = d->frames.value(oldPrefix); + if (oldPrefix == d->prefix && oldFrameData) { return; } if (!d->frames.contains(d->prefix)) { - d->frames.insert(d->prefix, new FrameData(*(d->frames[oldPrefix]))); + if (oldFrameData) { + d->frames.insert(d->prefix, new FrameData(*oldFrameData)); + } else { + d->frames.insert(d->prefix, new FrameData()); + } + d->updateSizes(); } if (!d->cacheAll) { delete d->frames[oldPrefix]; - d->framesToSave.removeAll(oldPrefix); d->frames.remove(oldPrefix); } @@ -329,15 +330,13 @@ void FrameSvg::clearCache() { FrameData *frame = d->frames[d->prefix]; - d->saveTimer->stop(); - d->framesToSave.clear(); - // delete all the frames that aren't this one QMutableHashIterator it(d->frames); while (it.hasNext()) { FrameData *p = it.next().value(); if (frame != p) { + //TODO: should we clear from the pixmap cache as well? delete p; it.remove(); } @@ -598,39 +597,35 @@ void FrameSvgPrivate::generateBackground(FrameData *frame) p.drawPixmap(overlayPos, overlay, QRect(overlayPos, overlaySize)); } - if (!framesToSave.contains(prefix)) { - framesToSave.append(prefix); - } - - saveTimer->start(300); + cacheFrame(prefix); } -void FrameSvgPrivate::scheduledCacheUpdate() +void FrameSvgPrivate::cacheFrame(const QString &prefixToSave) { if (!q->isUsingRenderingCache()) { - framesToSave.clear(); return; } - foreach (QString prefixToSave, framesToSave) { - //insert background - FrameData *frame = frames[prefixToSave]; - QString id = QString::fromLatin1("%7_%6_%5_%4_%3_%2_%1_"). - arg(overlayPos.y()).arg(overlayPos.x()).arg(frame->enabledBorders).arg(frame->frameSize.width()).arg(frame->frameSize.height()).arg(prefixToSave).arg(q->imagePath()); + //insert background + FrameData *frame = frames.value(prefixToSave); - //kDebug()<<"Saving to cache frame"<insertIntoCache(id, frame->cachedBackground); - - //insert overlay - id = QString::fromLatin1("overlay_%7_%6_%5_%4_%3_%2_%1_"). - arg(overlayPos.y()).arg(overlayPos.x()).arg(frame->enabledBorders).arg(frame->frameSize.width()).arg(frame->frameSize.height()).arg(prefixToSave).arg(q->imagePath()); - - Theme::defaultTheme()->insertIntoCache(id, frame->cachedBackground); + if (!frame) { + return; } - framesToSave.clear(); + QString id = QString::fromLatin1("%7_%6_%5_%4_%3_%2_%1_"). + arg(overlayPos.y()).arg(overlayPos.x()).arg(frame->enabledBorders).arg(frame->frameSize.width()).arg(frame->frameSize.height()).arg(prefixToSave).arg(q->imagePath()); + + //kDebug()<<"Saving to cache frame"<insertIntoCache(id, frame->cachedBackground); + + //insert overlay + id = QString::fromLatin1("overlay_%7_%6_%5_%4_%3_%2_%1_"). + arg(overlayPos.y()).arg(overlayPos.x()).arg(frame->enabledBorders).arg(frame->frameSize.width()).arg(frame->frameSize.height()).arg(prefixToSave).arg(q->imagePath()); + + Theme::defaultTheme()->insertIntoCache(id, frame->cachedBackground); } void FrameSvgPrivate::updateSizes() diff --git a/framesvg.h b/framesvg.h index 606f13e6a..6155e68f9 100644 --- a/framesvg.h +++ b/framesvg.h @@ -262,7 +262,6 @@ class PLASMA_EXPORT FrameSvg : public Svg Q_PRIVATE_SLOT(d, void updateSizes()) Q_PRIVATE_SLOT(d, void updateNeeded()) - Q_PRIVATE_SLOT(d, void scheduledCacheUpdate()) }; } // Plasma namespace diff --git a/private/framesvg_p.h b/private/framesvg_p.h index f81f6bebc..85e7d44bc 100644 --- a/private/framesvg_p.h +++ b/private/framesvg_p.h @@ -30,13 +30,35 @@ class FrameData public: FrameData() : enabledBorders(FrameSvg::AllBorders), - frameSize(-1,-1) + frameSize(-1,-1), + topHeight(0), + leftWidth(0), + rightWidth(0), + bottomHeight(0), + topMargin(0), + leftMargin(0), + rightMargin(0), + bottomMargin(0), + noBorderPadding(false), + stretchBorders(false), + tileCenter(false) { } FrameData(const FrameData &other) : enabledBorders(other.enabledBorders), - frameSize(other.frameSize) + frameSize(other.frameSize), + topHeight(0), + leftWidth(0), + rightWidth(0), + bottomHeight(0), + topMargin(0), + leftMargin(0), + rightMargin(0), + bottomMargin(0), + noBorderPadding(false), + stretchBorders(false), + tileCenter(false) { } @@ -74,7 +96,6 @@ public: FrameSvgPrivate(FrameSvg *psvg) : q(psvg), cacheAll(false), - saveTimer(0), overlayPos(0,0) { } @@ -86,7 +107,7 @@ public: } void generateBackground(FrameData *frame); - void scheduledCacheUpdate(); + void cacheFrame(const QString &prefix); void updateSizes(); void updateNeeded(); void updateAndSignalSizes(); @@ -97,8 +118,6 @@ public: FrameSvg *q; bool cacheAll : 1; - QStringList framesToSave; - QTimer *saveTimer; QPoint overlayPos; QHash frames;