[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: KDE/kdelibs/kdeui/widgets
From: Maks Orlovich <maksim () kde ! org>
Date: 2008-04-04 19:08:11
Message-ID: 1207336091.198793.15875.nullmailer () svn ! kde ! org
[Download RAW message or body]
SVN commit 793673 by orlovich:
automatically merged revision 793672:
Cache and reuse pixmaps for each frame. Before, new ones were created,
and Qt would stick every single one of them into the pixmap cache,
potentially keeping as many as ~1000 X pixmaps pointlessly, which
could slow down things such as EXA (though FredrikH made the latest
devel X handle that better..)
M +14 -3 kanimatedbutton.cpp
--- trunk/KDE/kdelibs/kdeui/widgets/kanimatedbutton.cpp #793672:793673
@@ -48,6 +48,9 @@
QPixmap pixmap;
QTimer timer;
QString icon_name;
+ QVector<QPixmap*> framesCache; // We keep copies of each frame so that
+ // the icon code can properly cache them in QPixmapCache,
+ // and not fill it up with dead copies
};
KAnimatedButton::KAnimatedButton( QWidget *parent )
@@ -59,6 +62,7 @@
KAnimatedButton::~KAnimatedButton()
{
d->timer.stop();
+ qDeleteAll(d->framesCache);
delete d;
}
@@ -110,14 +114,18 @@
int w = pixmap.width();
int h = w;
- QPixmap pix(w, h);
+ QPixmap* frame = framesCache[current_frame];
+ if (!frame)
{
- QPainter p(&pix);
+ frame = new QPixmap(w, h);
+ QPainter p(frame);
p.drawPixmap(QPoint(0,0), pixmap, QRect(0, current_frame * h, w, h));
+ p.end();
+ framesCache[current_frame] = frame;
}
- q->setIcon(QIcon(pix));
+ q->setIcon(QIcon(*frame));
}
void KAnimatedButton::updateIcons()
@@ -136,6 +144,9 @@
}
d->pixmap = QPixmap::fromImage(img);
+ qDeleteAll(d->framesCache);
+ d->framesCache.resize(d->frames);
+
d->updateCurrentIcon();
}
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic