src/gui/image/qicon.cpp
branchGCC_SURGE
changeset 31 5daf16870df6
parent 30 5dc02b23752f
equal deleted inserted replaced
27:93b982ccede2 31:5daf16870df6
    64 #ifdef Q_WS_X11
    64 #ifdef Q_WS_X11
    65 #include "private/qt_x11_p.h"
    65 #include "private/qt_x11_p.h"
    66 #include "private/qkde_p.h"
    66 #include "private/qkde_p.h"
    67 #endif
    67 #endif
    68 
    68 
       
    69 #include "private/qstylehelper_p.h"
       
    70 
    69 #ifndef QT_NO_ICON
    71 #ifndef QT_NO_ICON
    70 QT_BEGIN_NAMESPACE
    72 QT_BEGIN_NAMESPACE
    71 
    73 
    72 /*!
    74 /*!
    73     \enum QIcon::Mode
    75     \enum QIcon::Mode
   259 
   261 
   260     QSize actualSize = pm.size();
   262     QSize actualSize = pm.size();
   261     if (!actualSize.isNull() && (actualSize.width() > size.width() || actualSize.height() > size.height()))
   263     if (!actualSize.isNull() && (actualSize.width() > size.width() || actualSize.height() > size.height()))
   262         actualSize.scale(size, Qt::KeepAspectRatio);
   264         actualSize.scale(size, Qt::KeepAspectRatio);
   263 
   265 
   264     QString key = QLatin1String("$qt_icon_")
   266     QString key = QLatin1Literal("qt_")
   265                   + QString::number(pm.cacheKey())
   267                   % HexString<quint64>(pm.cacheKey())
   266                   + QString::number(pe->mode)
   268                   % HexString<uint>(pe->mode)
   267                   + QString::number(QApplication::palette().cacheKey())
   269                   % HexString<quint64>(QApplication::palette().cacheKey())
   268                   + QLatin1Char('_')
   270                   % HexString<uint>(actualSize.width())
   269                   + QString::number(actualSize.width())
   271                   % HexString<uint>(actualSize.height());
   270                   + QLatin1Char('_')
       
   271                   + QString::number(actualSize.height())
       
   272                   + QLatin1Char('_');
       
   273 
       
   274 
   272 
   275     if (mode == QIcon::Active) {
   273     if (mode == QIcon::Active) {
   276         if (QPixmapCache::find(key + QString::number(mode), pm))
   274         if (QPixmapCache::find(key % HexString<uint>(mode), pm))
   277             return pm; // horray
   275             return pm; // horray
   278         if (QPixmapCache::find(key + QString::number(QIcon::Normal), pm)) {
   276         if (QPixmapCache::find(key % HexString<uint>(QIcon::Normal), pm)) {
   279             QStyleOption opt(0);
   277             QStyleOption opt(0);
   280             opt.palette = QApplication::palette();
   278             opt.palette = QApplication::palette();
   281             QPixmap active = QApplication::style()->generatedIconPixmap(QIcon::Active, pm, &opt);
   279             QPixmap active = QApplication::style()->generatedIconPixmap(QIcon::Active, pm, &opt);
   282             if (pm.cacheKey() == active.cacheKey())
   280             if (pm.cacheKey() == active.cacheKey())
   283                 return pm;
   281                 return pm;
   284         }
   282         }
   285     }
   283     }
   286 
   284 
   287     if (!QPixmapCache::find(key + QString::number(mode), pm)) {
   285     if (!QPixmapCache::find(key % HexString<uint>(mode), pm)) {
   288         if (pm.size() != actualSize)
   286         if (pm.size() != actualSize)
   289             pm = pm.scaled(actualSize, Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
   287             pm = pm.scaled(actualSize, Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
   290         if (pe->mode != mode && mode != QIcon::Normal) {
   288         if (pe->mode != mode && mode != QIcon::Normal) {
   291             QStyleOption opt(0);
   289             QStyleOption opt(0);
   292             opt.palette = QApplication::palette();
   290             opt.palette = QApplication::palette();
   293             QPixmap generated = QApplication::style()->generatedIconPixmap(mode, pm, &opt);
   291             QPixmap generated = QApplication::style()->generatedIconPixmap(mode, pm, &opt);
   294             if (!generated.isNull())
   292             if (!generated.isNull())
   295                 pm = generated;
   293                 pm = generated;
   296         }
   294         }
   297         QPixmapCache::insert(key + QString::number(mode), pm);
   295         QPixmapCache::insert(key % HexString<uint>(mode), pm);
   298     }
   296     }
   299     return pm;
   297     return pm;
   300 }
   298 }
   301 
   299 
   302 QSize QPixmapIconEngine::actualSize(const QSize &size, QIcon::Mode mode, QIcon::State state)
   300 QSize QPixmapIconEngine::actualSize(const QSize &size, QIcon::Mode mode, QIcon::State state)
   439     default:
   437     default:
   440         QIconEngineV2::virtual_hook(id, data);
   438         QIconEngineV2::virtual_hook(id, data);
   441     }
   439     }
   442 }
   440 }
   443 
   441 
   444 #if !defined (QT_NO_LIBRARY) && !defined(QT_NO_SETTINGS)
   442 #ifndef QT_NO_LIBRARY
   445 Q_GLOBAL_STATIC_WITH_ARGS(QFactoryLoader, loader,
   443 Q_GLOBAL_STATIC_WITH_ARGS(QFactoryLoader, loader,
   446     (QIconEngineFactoryInterface_iid, QLatin1String("/iconengines"), Qt::CaseInsensitive))
   444     (QIconEngineFactoryInterface_iid, QLatin1String("/iconengines"), Qt::CaseInsensitive))
   447 Q_GLOBAL_STATIC_WITH_ARGS(QFactoryLoader, loaderV2,
   445 Q_GLOBAL_STATIC_WITH_ARGS(QFactoryLoader, loaderV2,
   448     (QIconEngineFactoryInterfaceV2_iid, QLatin1String("/iconengines"), Qt::CaseInsensitive))
   446     (QIconEngineFactoryInterfaceV2_iid, QLatin1String("/iconengines"), Qt::CaseInsensitive))
   449 #endif
   447 #endif
   877     QIconEngineV2 *engine = static_cast<QIconEngineV2*>(d->engine);
   875     QIconEngineV2 *engine = static_cast<QIconEngineV2*>(d->engine);
   878     return engine->availableSizes(mode, state);
   876     return engine->availableSizes(mode, state);
   879 }
   877 }
   880 
   878 
   881 /*!
   879 /*!
       
   880     \since 4.7
       
   881 
       
   882     Returns the name used to create the icon, if available.
       
   883 
       
   884     Depending on the way the icon was created, it may have an associated
       
   885     name. This is the case for icons created with fromTheme() or icons
       
   886     using a QIconEngine which supports the QIconEngineV2::IconNameHook.
       
   887 
       
   888     \sa fromTheme(), QIconEngine
       
   889 */
       
   890 QString QIcon::name() const
       
   891 {
       
   892     if (!d || !d->engine || d->engine_version < 2)
       
   893         return QString();
       
   894     QIconEngineV2 *engine = static_cast<QIconEngineV2*>(d->engine);
       
   895     return engine->iconName();
       
   896 }
       
   897 
       
   898 /*!
   882     \since 4.6
   899     \since 4.6
   883 
   900 
   884     Sets the search paths for icon themes to \a paths.
   901     Sets the search paths for icon themes to \a paths.
   885     \sa themeSearchPaths(), fromTheme(), setThemeName()
   902     \sa themeSearchPaths(), fromTheme(), setThemeName()
   886 */
   903 */