summaryrefslogtreecommitdiffstats
path: root/src/gui/image
diff options
context:
space:
mode:
authorJani Hautakangas <ext-jani.hautakangas@nokia.com>2010-05-20 10:04:34 (GMT)
committerJani Hautakangas <ext-jani.hautakangas@nokia.com>2010-05-20 10:04:34 (GMT)
commit6fb92f77f6d6b5b685b8748a1a35ffbd7df8b76b (patch)
treeba9ec7bc61be5ae87bd93fa055c6fb628b3d8404 /src/gui/image
parent98972c1b271de1292b4e46484fe689d62a8b8e62 (diff)
parente6557220bccbdbbc218dc9eab0eb426ba774435e (diff)
downloadQt-6fb92f77f6d6b5b685b8748a1a35ffbd7df8b76b.zip
Qt-6fb92f77f6d6b5b685b8748a1a35ffbd7df8b76b.tar.gz
Qt-6fb92f77f6d6b5b685b8748a1a35ffbd7df8b76b.tar.bz2
Merge branch '4.7' of scm.dev.troll.no:qt/qt-s60-public into 4.7
Diffstat (limited to 'src/gui/image')
-rw-r--r--src/gui/image/qicon.cpp25
-rw-r--r--src/gui/image/qpixmapcache.cpp43
-rw-r--r--src/gui/image/qpixmapcache.h10
-rw-r--r--src/gui/image/qpixmapcache_p.h2
4 files changed, 64 insertions, 16 deletions
diff --git a/src/gui/image/qicon.cpp b/src/gui/image/qicon.cpp
index 891b1db..7696632 100644
--- a/src/gui/image/qicon.cpp
+++ b/src/gui/image/qicon.cpp
@@ -55,6 +55,7 @@
#include "qcache.h"
#include "qdebug.h"
#include "private/qguiplatformplugin_p.h"
+#include "private/qstylehelper_p.h"
#ifdef Q_WS_MAC
#include <private/qt_mac_p.h>
@@ -261,21 +262,17 @@ QPixmap QPixmapIconEngine::pixmap(const QSize &size, QIcon::Mode mode, QIcon::St
if (!actualSize.isNull() && (actualSize.width() > size.width() || actualSize.height() > size.height()))
actualSize.scale(size, Qt::KeepAspectRatio);
- QString key = QLatin1String("$qt_icon_")
- + QString::number(pm.cacheKey())
- + QString::number(pe->mode)
- + QString::number(QApplication::palette().cacheKey())
- + QLatin1Char('_')
- + QString::number(actualSize.width())
- + QLatin1Char('_')
- + QString::number(actualSize.height())
- + QLatin1Char('_');
-
+ QString key = QLatin1Literal("qt_")
+ % HexString<quint64>(pm.cacheKey())
+ % HexString<uint>(pe->mode)
+ % HexString<quint64>(QApplication::palette().cacheKey())
+ % HexString<uint>(actualSize.width())
+ % HexString<uint>(actualSize.height());
if (mode == QIcon::Active) {
- if (QPixmapCache::find(key + QString::number(mode), pm))
+ if (QPixmapCache::find(key % HexString<uint>(mode), pm))
return pm; // horray
- if (QPixmapCache::find(key + QString::number(QIcon::Normal), pm)) {
+ if (QPixmapCache::find(key % HexString<uint>(QIcon::Normal), pm)) {
QStyleOption opt(0);
opt.palette = QApplication::palette();
QPixmap active = QApplication::style()->generatedIconPixmap(QIcon::Active, pm, &opt);
@@ -284,7 +281,7 @@ QPixmap QPixmapIconEngine::pixmap(const QSize &size, QIcon::Mode mode, QIcon::St
}
}
- if (!QPixmapCache::find(key + QString::number(mode), pm)) {
+ if (!QPixmapCache::find(key % HexString<uint>(mode), pm)) {
if (pm.size() != actualSize)
pm = pm.scaled(actualSize, Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
if (pe->mode != mode && mode != QIcon::Normal) {
@@ -294,7 +291,7 @@ QPixmap QPixmapIconEngine::pixmap(const QSize &size, QIcon::Mode mode, QIcon::St
if (!generated.isNull())
pm = generated;
}
- QPixmapCache::insert(key + QString::number(mode), pm);
+ QPixmapCache::insert(key % HexString<uint>(mode), pm);
}
return pm;
}
diff --git a/src/gui/image/qpixmapcache.cpp b/src/gui/image/qpixmapcache.cpp
index 5fc605a..7a6a73f 100644
--- a/src/gui/image/qpixmapcache.cpp
+++ b/src/gui/image/qpixmapcache.cpp
@@ -39,6 +39,7 @@
**
****************************************************************************/
+#define Q_TEST_QPIXMAPCACHE
#include "qpixmapcache.h"
#include "qobject.h"
#include "qdebug.h"
@@ -194,6 +195,9 @@ public:
static QPixmapCache::KeyData* getKeyData(QPixmapCache::Key *key);
+ QList< QPair<QString,QPixmap> > allPixmaps() const;
+ void flushDetachedPixmaps(bool nt);
+
private:
int *keyArray;
int theid;
@@ -235,10 +239,9 @@ QPMCache::~QPMCache()
When the last pixmap has been deleted from the cache, kill the
timer so Qt won't keep the CPU from going into sleep mode.
*/
-void QPMCache::timerEvent(QTimerEvent *)
+void QPMCache::flushDetachedPixmaps(bool nt)
{
int mc = maxCost();
- bool nt = totalCost() == ps;
setMaxCost(nt ? totalCost() * 3 / 4 : totalCost() -1);
setMaxCost(mc);
ps = totalCost();
@@ -252,6 +255,12 @@ void QPMCache::timerEvent(QTimerEvent *)
++it;
}
}
+}
+
+void QPMCache::timerEvent(QTimerEvent *)
+{
+ bool nt = totalCost() == ps;
+ flushDetachedPixmaps(nt);
if (!size()) {
killTimer(theid);
@@ -263,6 +272,7 @@ void QPMCache::timerEvent(QTimerEvent *)
}
}
+
QPixmap *QPMCache::object(const QString &key) const
{
QPixmapCache::Key cacheKey = cacheKeys.value(key);
@@ -422,6 +432,20 @@ QPixmapCache::KeyData* QPMCache::getKeyData(QPixmapCache::Key *key)
return key->d;
}
+QList< QPair<QString,QPixmap> > QPMCache::allPixmaps() const
+{
+ QList< QPair<QString,QPixmap> > r;
+ QHash<QString, QPixmapCache::Key>::const_iterator it = cacheKeys.begin();
+ while (it != cacheKeys.end()) {
+ QPixmap *ptr = QCache<QPixmapCache::Key, QPixmapCacheEntry>::object(it.value());
+ if (ptr)
+ r.append(QPair<QString,QPixmap>(it.key(),*ptr));
+ ++it;
+ }
+ return r;
+}
+
+
Q_GLOBAL_STATIC(QPMCache, pm_cache)
int Q_AUTOTEST_EXPORT q_QPixmapCache_keyHashSize()
@@ -633,4 +657,19 @@ void QPixmapCache::clear()
}
}
+void QPixmapCache::flushDetachedPixmaps()
+{
+ pm_cache()->flushDetachedPixmaps(true);
+}
+
+int QPixmapCache::totalUsed()
+{
+ return (pm_cache()->totalCost()+1023) / 1024;
+}
+
+QList< QPair<QString,QPixmap> > QPixmapCache::allPixmaps()
+{
+ return pm_cache()->allPixmaps();
+}
+
QT_END_NAMESPACE
diff --git a/src/gui/image/qpixmapcache.h b/src/gui/image/qpixmapcache.h
index 50a9369..e9c8c15 100644
--- a/src/gui/image/qpixmapcache.h
+++ b/src/gui/image/qpixmapcache.h
@@ -44,6 +44,10 @@
#include <QtGui/qpixmap.h>
+#ifdef Q_TEST_QPIXMAPCACHE
+#include <QtCore/qpair.h>
+#endif
+
QT_BEGIN_HEADER
QT_BEGIN_NAMESPACE
@@ -83,6 +87,12 @@ public:
static void remove(const QString &key);
static void remove(const Key &key);
static void clear();
+
+#ifdef Q_TEST_QPIXMAPCACHE
+ static void flushDetachedPixmaps();
+ static int totalUsed();
+ static QList< QPair<QString,QPixmap> > allPixmaps();
+#endif
};
QT_END_NAMESPACE
diff --git a/src/gui/image/qpixmapcache_p.h b/src/gui/image/qpixmapcache_p.h
index 0ed083c..6db3b20 100644
--- a/src/gui/image/qpixmapcache_p.h
+++ b/src/gui/image/qpixmapcache_p.h
@@ -96,6 +96,8 @@ public:
QPixmapCache::Key key;
};
+inline bool qIsDetached(QPixmapCacheEntry &t) { return t.isDetached(); }
+
QT_END_NAMESPACE
#endif // QPIXMAPCACHE_P_H