when changing the prefix, let's base it on the previous size.

svn path=/trunk/KDE/kdebase/workspace/libs/plasma/; revision=811927
This commit is contained in:
Aaron J. Seigo 2008-05-24 05:29:42 +00:00
parent 88260fabd2
commit 9f4246059e

View File

@ -40,6 +40,14 @@ public:
{ {
} }
PanelData(const PanelData &other)
: enabledBorders(other.enabledBorders),
cachedBackground(0),
panelSize(other.panelSize),
contentAtOrigin(other.contentAtOrigin)
{
}
~PanelData() ~PanelData()
{ {
delete cachedBackground; delete cachedBackground;
@ -178,15 +186,16 @@ void PanelSvg::setElementPrefix(const QString & prefix)
return; return;
} }
if (!d->panels.contains(d->prefix)) {
d->panels.insert(d->prefix, new PanelData(*(d->panels[oldPrefix])));
d->updateSizes();
}
if (!d->cacheAll) { if (!d->cacheAll) {
delete d->panels[oldPrefix]; delete d->panels[oldPrefix];
d->panels.remove(oldPrefix); d->panels.remove(oldPrefix);
} }
if (!d->panels.contains(d->prefix)) {
d->panels.insert(d->prefix, new PanelData());
}
d->location = Floating; d->location = Floating;
} }
@ -233,13 +242,15 @@ QString PanelSvg::prefix()
void PanelSvg::resizePanel(const QSizeF& size) void PanelSvg::resizePanel(const QSizeF& size)
{ {
bool sizeValid = size.width() > 0 && size.height() > 0; if (size.isEmpty()) {
if (!sizeValid || size == d->panels[d->prefix]->panelSize) {
if (!sizeValid)
kWarning() << "Invalid size" << size; kWarning() << "Invalid size" << size;
return; return;
} }
if (size == d->panels[d->prefix]->panelSize) {
return;
}
d->updateSizes(); d->updateSizes();
d->panels[d->prefix]->panelSize = size; d->panels[d->prefix]->panelSize = size;
} }
@ -283,10 +294,17 @@ qreal PanelSvg::marginSize(const Plasma::MarginEdge edge) const
void PanelSvg::getMargins(qreal &left, qreal &top, qreal &right, qreal &bottom) const void PanelSvg::getMargins(qreal &left, qreal &top, qreal &right, qreal &bottom) const
{ {
top = marginSize(Plasma::TopMargin); PanelData *panel = d->panels[d->prefix];
left = marginSize(Plasma::LeftMargin);
right = marginSize(Plasma::RightMargin); if (!panel || panel->noBorderPadding) {
bottom = marginSize(Plasma::BottomMargin); left = top = right = bottom = 0;
return;
}
top = panel->topHeight;
left = panel->leftWidth;
right = panel->rightWidth;
bottom = panel->bottomHeight;
} }
QBitmap PanelSvg::mask() const QBitmap PanelSvg::mask() const
@ -317,23 +335,21 @@ bool PanelSvg::cacheAllRenderedPanels() const
void PanelSvg::clearCache() void PanelSvg::clearCache()
{ {
PanelData *panel = d->panels[d->prefix]; PanelData *panel = d->panels[d->prefix];
if (panel) {
// make a copy of the panel data to preserve settings, // delete all the panels that aren't this one
// but then reset the cached image QMutableHashIterator<QString, PanelData*> it(d->panels);
panel = new PanelData(*panel); while (it.hasNext()) {
panel->cachedBackground = 0; PanelData *p = it.next().value();
} else { if (panel != p) {
panel = new PanelData(); delete p;
it.remove();
}
} }
qDeleteAll(d->panels);
d->panels.clear();
d->panels[d->prefix] = panel;
} }
void PanelSvg::paintPanel(QPainter* painter, const QRectF& rect, const QPointF& pos) void PanelSvg::paintPanel(QPainter* painter, const QRectF& rect, const QPointF& pos)
{ {
//kDebug();
PanelData *panel = d->panels[d->prefix]; PanelData *panel = d->panels[d->prefix];
if (!panel->cachedBackground) { if (!panel->cachedBackground) {
d->generateBackground(panel); d->generateBackground(panel);
@ -350,6 +366,7 @@ void PanelSvg::paintPanel(QPainter* painter, const QRectF& rect, const QPointF&
void PanelSvg::Private::generateBackground(PanelData *panel) void PanelSvg::Private::generateBackground(PanelData *panel)
{ {
kDebug() << "generating background";
bool origined = panel->contentAtOrigin; bool origined = panel->contentAtOrigin;
const int topWidth = q->elementSize(prefix + "top").width(); const int topWidth = q->elementSize(prefix + "top").width();
const int leftHeight = q->elementSize(prefix + "left").height(); const int leftHeight = q->elementSize(prefix + "left").height();
@ -359,6 +376,7 @@ void PanelSvg::Private::generateBackground(PanelData *panel)
if (panel->cachedBackground) { if (panel->cachedBackground) {
return; return;
} }
if (!panel->panelSize.isValid()) { if (!panel->panelSize.isValid()) {
kWarning() << "Invalid panel size" << panel->panelSize; kWarning() << "Invalid panel size" << panel->panelSize;
panel->cachedBackground = new QPixmap(); panel->cachedBackground = new QPixmap();