cache clearing fixes, some performance improvements

svn path=/trunk/KDE/kdebase/workspace/libs/plasma/; revision=800759
This commit is contained in:
Aaron J. Seigo 2008-04-24 19:49:24 +00:00
parent 9425318d08
commit f4cb38cef1

View File

@ -96,7 +96,6 @@ PanelSvg::PanelSvg(QObject* parent)
d(new Private(this)) d(new Private(this))
{ {
connect(this, SIGNAL(repaintNeeded()), this, SLOT(updateSizes())); connect(this, SIGNAL(repaintNeeded()), this, SLOT(updateSizes()));
d->panels.insert(QString(), new PanelData()); d->panels.insert(QString(), new PanelData());
} }
@ -113,11 +112,8 @@ void PanelSvg::setImagePath(const QString& path)
Svg::setImagePath(path); Svg::setImagePath(path);
qDeleteAll(d->panels); clearCache();
d->updateAndSignalSizes();
d->panels.insert(QString(), new PanelData());
d->panels[QString()]->panelSize = size();
d->updateSizes();
} }
void PanelSvg::setEnabledBorders(const EnabledBorders borders) void PanelSvg::setEnabledBorders(const EnabledBorders borders)
@ -190,8 +186,9 @@ void PanelSvg::setElementPrefix(const QString & prefix)
QString PanelSvg::prefix() QString PanelSvg::prefix()
{ {
if (d->prefix.isEmpty()) { if (d->prefix.isEmpty()) {
return QString(); return d->prefix;
} }
return d->prefix.left(d->prefix.size() - 1); return d->prefix.left(d->prefix.size() - 1);
} }
@ -258,9 +255,20 @@ bool PanelSvg::cacheAllRenderedPanels() const
void PanelSvg::clearCache() void PanelSvg::clearCache()
{ {
PanelData *panel = d->panels[d->prefix];
if (panel) {
// make a copy of the panel data to preserve settings,
// but then reset the cached image
panel = new PanelData(*panel);
panel->cachedBackground = 0;
} else {
panel = new PanelData();
}
qDeleteAll(d->panels); qDeleteAll(d->panels);
d->panels.clear(); d->panels.clear();
d->panels.insert(d->prefix, new PanelData());
d->panels[d->prefix] = panel;
} }
void PanelSvg::paint(QPainter* painter, const QRectF& rect, const QPointF& pos) void PanelSvg::paint(QPainter* painter, const QRectF& rect, const QPointF& pos)
@ -342,11 +350,11 @@ void PanelSvg::Private::generateBackground(PanelData *panel)
(panel->topHeight + panel->bottomHeight) + (panel->topHeight + panel->bottomHeight) +
panel->panelSize.height()*(((qreal)(panel->topHeight + panel->bottomHeight)) / panel->panelSize.height())); panel->panelSize.height()*(((qreal)(panel->topHeight + panel->bottomHeight)) / panel->panelSize.height()));
q->Svg::resize(scaledSize.width(), scaledSize.height()); q->resize(scaledSize.width(), scaledSize.height());
q->Svg::paint(&p, QRect(contentLeft - panel->leftWidth, contentTop - panel->topHeight, q->Svg::paint(&p, QRect(contentLeft - panel->leftWidth, contentTop - panel->topHeight,
contentWidth + panel->leftWidth*2, contentHeight + panel->topHeight*2), contentWidth + panel->leftWidth*2, contentHeight + panel->topHeight*2),
prefix + "center"); prefix + "center");
q->Svg::resize(); q->resize();
} }
} }
@ -458,13 +466,16 @@ void PanelSvg::Private::generateBackground(PanelData *panel)
} }
// re-enable this once Qt's svg rendering is un-buggered // re-enable this once Qt's svg rendering is un-buggered
//q->Svg::resize(contentWidth, contentHeight); //q->resize(contentWidth, contentHeight);
//paint(&p, QRect(contentLeft, contentTop, contentWidth, contentHeight), "center"); //paint(&p, QRect(contentLeft, contentTop, contentWidth, contentHeight), "center");
} }
void PanelSvg::Private::updateSizes() void PanelSvg::Private::updateSizes()
{ {
//kDebug() << "!!!!!!!!!!!!!!!!!!!!!! updating sizes" << prefix;
q->clearCache();
PanelData *panel = panels[prefix]; PanelData *panel = panels[prefix];
Q_ASSERT(panel);
delete panel->cachedBackground; delete panel->cachedBackground;
panel->cachedBackground = 0; panel->cachedBackground = 0;
@ -502,7 +513,7 @@ void PanelSvg::Private::updateSizes()
void PanelSvg::Private::updateAndSignalSizes() void PanelSvg::Private::updateAndSignalSizes()
{ {
updateSizes(); // updateSizes(); <-- this gets called when repaintNeeded is emitted
emit q->repaintNeeded(); emit q->repaintNeeded();
} }