src/gui/image/qicon.cpp
branchRCL_3
changeset 8 3f74d0d4af4c
parent 4 3b1da2848fc7
equal deleted inserted replaced
6:dee5afe5301f 8:3f74d0d4af4c
   101   \value Off  Display the pixmap when the widget is in an "off" state
   101   \value Off  Display the pixmap when the widget is in an "off" state
   102   \value On  Display the pixmap when the widget is in an "on" state
   102   \value On  Display the pixmap when the widget is in an "on" state
   103 */
   103 */
   104 
   104 
   105 static QBasicAtomicInt serialNumCounter = Q_BASIC_ATOMIC_INITIALIZER(1);
   105 static QBasicAtomicInt serialNumCounter = Q_BASIC_ATOMIC_INITIALIZER(1);
       
   106 
       
   107 static void qt_cleanup_icon_cache();
       
   108 typedef QCache<QString, QIcon> IconCache;
       
   109 Q_GLOBAL_STATIC_WITH_INITIALIZER(IconCache, qtIconCache, qAddPostRoutine(qt_cleanup_icon_cache))
       
   110 
       
   111 static void qt_cleanup_icon_cache()
       
   112 {
       
   113     qtIconCache()->clear();
       
   114 }
   106 
   115 
   107 QIconPrivate::QIconPrivate()
   116 QIconPrivate::QIconPrivate()
   108     : engine(0), ref(1),
   117     : engine(0), ref(1),
   109     serialNum(serialNumCounter.fetchAndAddRelaxed(1)),
   118     serialNum(serialNumCounter.fetchAndAddRelaxed(1)),
   110     detach_no(0),
   119     detach_no(0),
   961 
   970 
   962     \sa themeName(), setThemeName(), themeSearchPaths()
   971     \sa themeName(), setThemeName(), themeSearchPaths()
   963 */
   972 */
   964 QIcon QIcon::fromTheme(const QString &name, const QIcon &fallback)
   973 QIcon QIcon::fromTheme(const QString &name, const QIcon &fallback)
   965 {
   974 {
   966     static QCache <QString, QIcon> iconCache;
       
   967 
       
   968     QIcon icon;
   975     QIcon icon;
   969 
   976 
   970     if (iconCache.contains(name)) {
   977     if (qtIconCache()->contains(name)) {
   971         icon = *iconCache.object(name);
   978         icon = *qtIconCache()->object(name);
   972     } else {
   979     } else {
   973         QIcon *cachedIcon  = new QIcon(new QIconLoaderEngine(name));
   980         QIcon *cachedIcon  = new QIcon(new QIconLoaderEngine(name));
   974         iconCache.insert(name, cachedIcon);
   981         qtIconCache()->insert(name, cachedIcon);
   975         icon = *cachedIcon;
   982         icon = *cachedIcon;
   976     }
   983     }
   977 
   984 
   978     if (icon.availableSizes().isEmpty())
   985     // Note the qapp check is to allow lazy loading of static icons
       
   986     // Supporting fallbacks will not work for this case.
       
   987     if (qApp && icon.availableSizes().isEmpty())
   979         return fallback;
   988         return fallback;
   980 
   989 
   981     return icon;
   990     return icon;
   982 }
   991 }
   983 
   992