don't repaint the entire item *every time* if the exposed area is just a small section. this saves huge numbers of whole screen repaints.

svn path=/trunk/KDE/kdebase/workspace/libs/plasma/; revision=856476
This commit is contained in:
Aaron J. Seigo 2008-09-02 23:29:54 +00:00
parent 9367d50a83
commit 3c7c59d9f8

View File

@ -851,7 +851,7 @@ void Applet::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QW
{ {
QPainter *p; QPainter *p;
//FIXME: we should probably set the pixmap to screenSize(), but that breaks stuff atm. //FIXME: we should probably set the pixmap to screenSize(), but that breaks stuff atm.
QPixmap pixmap(boundingRect().size().toSize()); QPixmap *pixmap = 0;
QGraphicsView* qgv = qobject_cast<QGraphicsView*>(widget ? widget->parent() : 0); QGraphicsView* qgv = qobject_cast<QGraphicsView*>(widget ? widget->parent() : 0);
bool ghost = (qgv && (qgv == d->ghostView)); bool ghost = (qgv && (qgv == d->ghostView));
@ -861,11 +861,11 @@ void Applet::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QW
// that pixmap where the applet can draw on so we can draw the result transparently // that pixmap where the applet can draw on so we can draw the result transparently
// at the end. // at the end.
kDebug() << "Painting ghosted..."; kDebug() << "Painting ghosted...";
pixmap = new QPixmap(boundingRect().size().toSize());
pixmap.fill(Qt::transparent); pixmap->fill(Qt::transparent);
p = new QPainter(); p = new QPainter();
p->begin(&pixmap); p->begin(pixmap);
} else { } else {
p = painter; p = painter;
} }
@ -887,8 +887,16 @@ void Applet::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QW
if (!d->failed) { if (!d->failed) {
qreal left, top, right, bottom; qreal left, top, right, bottom;
getContentsMargins(&left, &top, &right, &bottom); getContentsMargins(&left, &top, &right, &bottom);
const QRect contentsRect = QRectF(QPointF(0,0), boundingRect().size()) QRectF contentsRect = QRectF(QPointF(0,0), boundingRect().size())
.adjusted(left, top, -right, -bottom).toAlignedRect(); .adjusted(left, top, -right, -bottom);
if (!ghost) {
// only paint the bare minimum when not ghosting
contentsRect = option->exposedRect.intersected(contentsRect);
}
QRect exposed = contentsRect.toAlignedRect();
if (widget && isContainment()) { if (widget && isContainment()) {
// note that the widget we get is actually the viewport of the view, not the view itself // note that the widget we get is actually the viewport of the view, not the view itself
View* v = qobject_cast<Plasma::View*>(widget->parent()); View* v = qobject_cast<Plasma::View*>(widget->parent());
@ -896,12 +904,12 @@ void Applet::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QW
if (!v || v->isWallpaperEnabled()) { if (!v || v->isWallpaperEnabled()) {
Containment* c = qobject_cast<Plasma::Containment*>(this); Containment* c = qobject_cast<Plasma::Containment*>(this);
if (c && c->drawWallpaper() && c->wallpaper()) { if (c && c->drawWallpaper() && c->wallpaper()) {
c->wallpaper()->paint(p, contentsRect); c->wallpaper()->paint(p, exposed);
} }
Containment::StyleOption coption(*option); Containment::StyleOption coption(*option);
coption.view = v; coption.view = v;
paintInterface(p, &coption, contentsRect); paintInterface(p, &coption, exposed);
} }
p->restore(); p->restore();
@ -909,19 +917,19 @@ void Applet::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QW
} }
//kDebug() << "paint interface of" << (QObject*) this; //kDebug() << "paint interface of" << (QObject*) this;
paintInterface(p, option, contentsRect); paintInterface(p, option, exposed);
} }
p->restore(); p->restore();
if (ghost) { if (ghost) {
// Lets display the pixmap that we've just drawn... transparently. // Lets display the pixmap that we've just drawn... transparently.
p->setCompositionMode(QPainter::CompositionMode_DestinationIn); p->setCompositionMode(QPainter::CompositionMode_DestinationIn);
p->fillRect(pixmap.rect(), QColor(0, 0, 0, (0.3 * 255))); p->fillRect(pixmap->rect(), QColor(0, 0, 0, (0.3 * 255)));
p->end(); p->end();
delete p; delete p;
painter->drawPixmap(0, 0, pixmap); painter->drawPixmap(0, 0, *pixmap);
delete pixmap;
} }
} }