KDEUI
Go to the documentation of this file.
22 #include <QtGui/QPixmap>
23 #include <QtGui/QImage>
24 #include <QtCore/QBuffer>
25 #include <QtCore/QCache>
26 #include <QtCore/QCoreApplication>
34 class KImageCache::Private :
public QObject
42 , enablePixmapCaching(true)
44 QObject::connect(QCoreApplication::instance(), SIGNAL(aboutToQuit()),
45 this, SLOT(clearPixmaps()));
54 if (enablePixmapCaching && pixmap && !pixmap->isNull()) {
57 return pixmapCache.insert(key, pixmap,
58 pixmap->width() * pixmap->height() * pixmap->depth() / 8);
77 QCache<QString, QPixmap> pixmapCache;
79 bool enablePixmapCaching;
83 unsigned defaultCacheSize,
84 unsigned expectedItemSize)
89 d->pixmapCache.setMaxCost(qMax(defaultCacheSize / 8, (
unsigned int) 16384));
100 buffer.open(QBuffer::WriteOnly);
101 image.save(&buffer,
"PNG");
103 if (this->
insert(key, buffer.buffer())) {
104 d->timestamp = ::time(0);
113 d->insertPixmap(key,
new QPixmap(pixmap));
124 QByteArray cachedData;
125 if (!this->
find(key, &cachedData) || cachedData.isNull()) {
130 destination->loadFromData(cachedData,
"PNG");
138 if (d->enablePixmapCaching) {
139 QPixmap *cachedPixmap = d->pixmapCache.object(key);
142 *destination = *cachedPixmap;
149 QByteArray cachedData;
150 if (!this->
find(key, &cachedData) || cachedData.isNull()) {
155 destination->loadFromData(cachedData,
"PNG");
158 d->insertPixmap(key,
new QPixmap(*destination));
166 d->pixmapCache.clear();
177 return d->enablePixmapCaching;
182 if (enable != d->enablePixmapCaching) {
183 d->enablePixmapCaching = enable;
185 d->pixmapCache.clear();
192 return d->pixmapCache.maxCost();
197 d->pixmapCache.setMaxCost(size);
200 #include "kimagecache.moc"
~KImageCache()
Deconstructor.
time_t lastModifiedTime() const
unsigned timestamp() const
bool pixmapCaching() const
bool findPixmap(const QString &key, QPixmap *destination) const
Copies the cached pixmap identified by key to destination.
void clear()
Removes all entries from the cache.
int pixmapCacheLimit() const
KImageCache(const QString &cacheName, unsigned defaultCacheSize, unsigned expectedItemSize=0)
Constructs an image cache, named by cacheName, with a default size of defaultCacheSize.
bool insertPixmap(const QString &key, const QPixmap &pixmap)
Inserts the pixmap given by pixmap to the cache, accessible with key.
bool insertImage(const QString &key, const QImage &image)
Inserts the image into the shared cache, accessible with key.
void setPixmapCacheLimit(int size)
Sets the highest memory size the pixmap cache should use.
bool insert(const QString &key, const QByteArray &data)
void setPixmapCaching(bool enable)
Enables or disables local pixmap caching.
bool find(const QString &key, QByteArray *destination) const
bool findImage(const QString &key, QImage *destination) const
Copies the cached image identified by key to destination.
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Thu Jan 30 2020 00:00:00 by
doxygen 1.8.17 written
by
Dimitri van Heesch, © 1997-2006
KDE's Doxygen guidelines are available online.