* 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
This commit is contained in:
parent
177be5f6af
commit
9e50b9b61e
63
framesvg.cpp
63
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<QString, FrameData*> 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"<<id;
|
||||
|
||||
Theme::defaultTheme()->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"<<id;
|
||||
|
||||
Theme::defaultTheme()->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()
|
||||
|
@ -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
|
||||
|
@ -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<QString, FrameData*> frames;
|
||||
|
Loading…
Reference in New Issue
Block a user