src/gui/image/qiconloader.cpp
changeset 3 41300fa6a67c
parent 0 1918ee327afb
child 4 3b1da2848fc7
child 7 f7bc934e204c
equal deleted inserted replaced
2:56cd8111b7f7 3:41300fa6a67c
    36 **
    36 **
    37 **
    37 **
    38 ** $QT_END_LICENSE$
    38 ** $QT_END_LICENSE$
    39 **
    39 **
    40 ****************************************************************************/
    40 ****************************************************************************/
    41 
    41 #ifndef QT_NO_ICON
    42 #include <private/qiconloader_p.h>
    42 #include <private/qiconloader_p.h>
    43 
    43 
    44 #include <private/qapplication_p.h>
    44 #include <private/qapplication_p.h>
    45 #include <private/qicon_p.h>
    45 #include <private/qicon_p.h>
    46 #include <private/qguiplatformplugin_p.h>
    46 #include <private/qguiplatformplugin_p.h>
    59 #include <private/qt_cocoa_helpers_mac_p.h>
    59 #include <private/qt_cocoa_helpers_mac_p.h>
    60 #endif
    60 #endif
    61 
    61 
    62 #ifdef Q_WS_X11
    62 #ifdef Q_WS_X11
    63 #include <private/qt_x11_p.h>
    63 #include <private/qt_x11_p.h>
    64 #include <private/gtksymbols_p.h>
       
    65 #endif
    64 #endif
    66 
    65 
    67 QT_BEGIN_NAMESPACE
    66 QT_BEGIN_NAMESPACE
    68 
    67 
    69 Q_GLOBAL_STATIC(QIconLoader, iconLoaderInstance)
    68 Q_GLOBAL_STATIC(QIconLoader, iconLoaderInstance)
    90 {
    89 {
    91     m_systemTheme = qt_guiPlatformPlugin()->systemIconThemeName();
    90     m_systemTheme = qt_guiPlatformPlugin()->systemIconThemeName();
    92     if (m_systemTheme.isEmpty())
    91     if (m_systemTheme.isEmpty())
    93         m_systemTheme = fallbackTheme();
    92         m_systemTheme = fallbackTheme();
    94 
    93 
       
    94 #ifndef QT_NO_LIBRARY
    95     QFactoryLoader iconFactoryLoader(QIconEngineFactoryInterfaceV2_iid,
    95     QFactoryLoader iconFactoryLoader(QIconEngineFactoryInterfaceV2_iid,
    96                                      QLatin1String("/iconengines"),
    96                                      QLatin1String("/iconengines"),
    97                                      Qt::CaseInsensitive);
    97                                      Qt::CaseInsensitive);
    98     if (iconFactoryLoader.keys().contains(QLatin1String("svg")))
    98     if (iconFactoryLoader.keys().contains(QLatin1String("svg")))
    99         m_supportsSvg = true;
    99         m_supportsSvg = true;
       
   100 #endif //QT_NO_LIBRARY
   100 }
   101 }
   101 
   102 
   102 QIconLoader *QIconLoader::instance()
   103 QIconLoader *QIconLoader::instance()
   103 {
   104 {
   104    return iconLoaderInstance();
   105    return iconLoaderInstance();
   158             m_contentDir = themeDir;
   159             m_contentDir = themeDir;
   159             m_valid = true;
   160             m_valid = true;
   160             break;
   161             break;
   161         }
   162         }
   162     }
   163     }
   163 
   164 #ifndef QT_NO_SETTINGS
   164     if (themeIndex.exists()) {
   165     if (themeIndex.exists()) {
   165         const QSettings indexReader(themeIndex.fileName(), QSettings::IniFormat);
   166         const QSettings indexReader(themeIndex.fileName(), QSettings::IniFormat);
   166         QStringListIterator keyIterator(indexReader.allKeys());
   167         QStringListIterator keyIterator(indexReader.allKeys());
   167         while (keyIterator.hasNext()) {
   168         while (keyIterator.hasNext()) {
   168 
   169 
   211 
   212 
   212         // Ensure that all themes fall back to hicolor
   213         // Ensure that all themes fall back to hicolor
   213         if (!m_parents.contains(QLatin1String("hicolor")))
   214         if (!m_parents.contains(QLatin1String("hicolor")))
   214             m_parents.append(QLatin1String("hicolor"));
   215             m_parents.append(QLatin1String("hicolor"));
   215     }
   216     }
       
   217 #endif //QT_NO_SETTINGS
   216 }
   218 }
   217 
   219 
   218 QThemeIconEntries QIconLoader::findIconHelper(const QString &themeName,
   220 QThemeIconEntries QIconLoader::findIconHelper(const QString &themeName,
   219                                  const QString &iconName,
   221                                  const QString &iconName,
   220                                  QStringList &visited) const
   222                                  QStringList &visited) const
   245     // Add all relevant files
   247     // Add all relevant files
   246     for (int i = 0; i < subDirs.size() ; ++i) {
   248     for (int i = 0; i < subDirs.size() ; ++i) {
   247         const QIconDirInfo &dirInfo = subDirs.at(i);
   249         const QIconDirInfo &dirInfo = subDirs.at(i);
   248         QString subdir = dirInfo.path;
   250         QString subdir = dirInfo.path;
   249         QDir currentDir(contentDir + subdir);
   251         QDir currentDir(contentDir + subdir);
   250 
   252         if (currentDir.exists(iconName + pngext)) {
   251         if (dirInfo.type == QIconDirInfo::Scalable && m_supportsSvg &&
       
   252             currentDir.exists(iconName + svgext)) {
       
   253             ScalableEntry *iconEntry = new ScalableEntry;
       
   254             iconEntry->dir = dirInfo;
       
   255             iconEntry->filename = currentDir.filePath(iconName + svgext);
       
   256             entries.append(iconEntry);
       
   257 
       
   258         } else if (currentDir.exists(iconName + pngext)) {
       
   259             PixmapEntry *iconEntry = new PixmapEntry;
   253             PixmapEntry *iconEntry = new PixmapEntry;
   260             iconEntry->dir = dirInfo;
   254             iconEntry->dir = dirInfo;
   261             iconEntry->filename = currentDir.filePath(iconName + pngext);
   255             iconEntry->filename = currentDir.filePath(iconName + pngext);
   262             // Notice we ensure that pixmap entries allways come before
   256             // Notice we ensure that pixmap entries allways come before
   263             // scalable to preserve search order afterwards
   257             // scalable to preserve search order afterwards
   264             entries.prepend(iconEntry);
   258             entries.prepend(iconEntry);
       
   259         } else if (m_supportsSvg &&
       
   260             currentDir.exists(iconName + svgext)) {
       
   261             ScalableEntry *iconEntry = new ScalableEntry;
       
   262             iconEntry->dir = dirInfo;
       
   263             iconEntry->filename = currentDir.filePath(iconName + svgext);
       
   264             entries.append(iconEntry);
   265         }
   265         }
   266     }
   266     }
   267 
   267 
   268     if (entries.isEmpty()) {
   268     if (entries.isEmpty()) {
   269         const QStringList parents = theme.parents();
   269         const QStringList parents = theme.parents();
   440     return closestMatch;
   440     return closestMatch;
   441 }
   441 }
   442 
   442 
   443 /*
   443 /*
   444  * Returns the actual icon size. For scalable svg's this is equivalent
   444  * Returns the actual icon size. For scalable svg's this is equivalent
   445  * to the requested size. Otherwise the closest match is returned.
   445  * to the requested size. Otherwise the closest match is returned but
   446  *
   446  * we can never return a bigger size than the requested size.
   447  * todo: the spec is a bit fuzzy in this area, but we should probably
       
   448  * allow scaling down pixmap icons as well.
       
   449  *
   447  *
   450  */
   448  */
   451 QSize QIconLoaderEngine::actualSize(const QSize &size, QIcon::Mode mode,
   449 QSize QIconLoaderEngine::actualSize(const QSize &size, QIcon::Mode mode,
   452                                    QIcon::State state)
   450                                    QIcon::State state)
   453 {
   451 {
   456     QIconLoaderEngineEntry *entry = entryForSize(size);
   454     QIconLoaderEngineEntry *entry = entryForSize(size);
   457     if (entry) {
   455     if (entry) {
   458         const QIconDirInfo &dir = entry->dir;
   456         const QIconDirInfo &dir = entry->dir;
   459         if (dir.type == QIconDirInfo::Scalable)
   457         if (dir.type == QIconDirInfo::Scalable)
   460             return size;
   458             return size;
   461         else
   459         else {
   462             return QSize(dir.size, dir.size);
   460             int result = qMin<int>(dir.size, qMin(size.width(), size.height()));
       
   461             return QSize(result, result);
       
   462         }
   463     }
   463     }
   464     return QIconEngineV2::actualSize(size, mode, state);
   464     return QIconEngineV2::actualSize(size, mode, state);
   465 }
   465 }
   466 
   466 
   467 QPixmap PixmapEntry::pixmap(const QSize &size, QIcon::Mode mode, QIcon::State state)
   467 QPixmap PixmapEntry::pixmap(const QSize &size, QIcon::Mode mode, QIcon::State state)
   544         QIconEngineV2::virtual_hook(id, data);
   544         QIconEngineV2::virtual_hook(id, data);
   545     }
   545     }
   546 }
   546 }
   547 
   547 
   548 QT_END_NAMESPACE
   548 QT_END_NAMESPACE
       
   549 
       
   550 #endif //QT_NO_ICON