src/gui/image/qicon.cpp
changeset 30 5dc02b23752f
parent 19 fcece45ef507
--- a/src/gui/image/qicon.cpp	Wed Jun 23 19:07:03 2010 +0300
+++ b/src/gui/image/qicon.cpp	Tue Jul 06 15:10:48 2010 +0300
@@ -66,6 +66,8 @@
 #include "private/qkde_p.h"
 #endif
 
+#include "private/qstylehelper_p.h"
+
 #ifndef QT_NO_ICON
 QT_BEGIN_NAMESPACE
 
@@ -261,21 +263,17 @@
     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 +282,7 @@
         }
     }
 
-    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 +292,7 @@
             if (!generated.isNull())
                 pm = generated;
         }
-        QPixmapCache::insert(key + QString::number(mode), pm);
+        QPixmapCache::insert(key % HexString<uint>(mode), pm);
     }
     return pm;
 }
@@ -441,7 +439,7 @@
     }
 }
 
-#if !defined (QT_NO_LIBRARY) && !defined(QT_NO_SETTINGS)
+#ifndef QT_NO_LIBRARY
 Q_GLOBAL_STATIC_WITH_ARGS(QFactoryLoader, loader,
     (QIconEngineFactoryInterface_iid, QLatin1String("/iconengines"), Qt::CaseInsensitive))
 Q_GLOBAL_STATIC_WITH_ARGS(QFactoryLoader, loaderV2,
@@ -879,6 +877,25 @@
 }
 
 /*!
+    \since 4.7
+
+    Returns the name used to create the icon, if available.
+
+    Depending on the way the icon was created, it may have an associated
+    name. This is the case for icons created with fromTheme() or icons
+    using a QIconEngine which supports the QIconEngineV2::IconNameHook.
+
+    \sa fromTheme(), QIconEngine
+*/
+QString QIcon::name() const
+{
+    if (!d || !d->engine || d->engine_version < 2)
+        return QString();
+    QIconEngineV2 *engine = static_cast<QIconEngineV2*>(d->engine);
+    return engine->iconName();
+}
+
+/*!
     \since 4.6
 
     Sets the search paths for icon themes to \a paths.