summaryrefslogtreecommitdiffstats
path: root/libraries/iconfix
diff options
context:
space:
mode:
Diffstat (limited to 'libraries/iconfix')
-rw-r--r--libraries/iconfix/CMakeLists.txt8
-rw-r--r--libraries/iconfix/internal/qhexstring_p.h60
-rw-r--r--libraries/iconfix/internal/qiconloader.cpp934
-rw-r--r--libraries/iconfix/internal/qiconloader_p.h222
-rw-r--r--libraries/iconfix/xdgicon.cpp108
-rw-r--r--libraries/iconfix/xdgicon.h12
6 files changed, 672 insertions, 672 deletions
diff --git a/libraries/iconfix/CMakeLists.txt b/libraries/iconfix/CMakeLists.txt
index 93bfdd06..ccf0edea 100644
--- a/libraries/iconfix/CMakeLists.txt
+++ b/libraries/iconfix/CMakeLists.txt
@@ -15,14 +15,14 @@ internal/qiconloader_p.h
add_library(MultiMC_iconfix SHARED ${ICONFIX_SOURCES})
target_include_directories(MultiMC_iconfix PUBLIC ${CMAKE_CURRENT_SOURCE_DIR} "${CMAKE_CURRENT_BINARY_DIR}" )
-qt5_use_modules(MultiMC_iconfix Core Widgets)
+target_link_libraries(MultiMC_iconfix Qt5::Core Qt5::Widgets)
set_target_properties(MultiMC_iconfix PROPERTIES CXX_VISIBILITY_PRESET hidden VISIBILITY_INLINES_HIDDEN 1)
generate_export_header(MultiMC_iconfix)
# Install it
install(
- TARGETS MultiMC_iconfix
- RUNTIME DESTINATION ${LIBRARY_DEST_DIR}
- LIBRARY DESTINATION ${LIBRARY_DEST_DIR}
+ TARGETS MultiMC_iconfix
+ RUNTIME DESTINATION ${LIBRARY_DEST_DIR}
+ LIBRARY DESTINATION ${LIBRARY_DEST_DIR}
) \ No newline at end of file
diff --git a/libraries/iconfix/internal/qhexstring_p.h b/libraries/iconfix/internal/qhexstring_p.h
index f01b4cdd..c81904e5 100644
--- a/libraries/iconfix/internal/qhexstring_p.h
+++ b/libraries/iconfix/internal/qhexstring_p.h
@@ -61,40 +61,40 @@
// internal helper. Converts an integer value to an unique string token
template <typename T> struct HexString
{
- inline HexString(const T t) : val(t)
- {
- }
+ inline HexString(const T t) : val(t)
+ {
+ }
- inline void write(QChar *&dest) const
- {
- const ushort hexChars[] = {'0', '1', '2', '3', '4', '5', '6', '7',
- '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'};
- const char *c = reinterpret_cast<const char *>(&val);
- for (uint i = 0; i < sizeof(T); ++i)
- {
- *dest++ = hexChars[*c & 0xf];
- *dest++ = hexChars[(*c & 0xf0) >> 4];
- ++c;
- }
- }
- const T val;
+ inline void write(QChar *&dest) const
+ {
+ const ushort hexChars[] = {'0', '1', '2', '3', '4', '5', '6', '7',
+ '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'};
+ const char *c = reinterpret_cast<const char *>(&val);
+ for (uint i = 0; i < sizeof(T); ++i)
+ {
+ *dest++ = hexChars[*c & 0xf];
+ *dest++ = hexChars[(*c & 0xf0) >> 4];
+ ++c;
+ }
+ }
+ const T val;
};
// specialization to enable fast concatenating of our string tokens to a string
template <typename T> struct QConcatenable<HexString<T>>
{
- typedef HexString<T> type;
- enum
- {
- ExactSize = true
- };
- static int size(const HexString<T> &)
- {
- return sizeof(T) * 2;
- }
- static inline void appendTo(const HexString<T> &str, QChar *&out)
- {
- str.write(out);
- }
- typedef QString ConvertTo;
+ typedef HexString<T> type;
+ enum
+ {
+ ExactSize = true
+ };
+ static int size(const HexString<T> &)
+ {
+ return sizeof(T) * 2;
+ }
+ static inline void appendTo(const HexString<T> &str, QChar *&out)
+ {
+ str.write(out);
+ }
+ typedef QString ConvertTo;
};
diff --git a/libraries/iconfix/internal/qiconloader.cpp b/libraries/iconfix/internal/qiconloader.cpp
index b1195893..41cf3d50 100644
--- a/libraries/iconfix/internal/qiconloader.cpp
+++ b/libraries/iconfix/internal/qiconloader.cpp
@@ -55,7 +55,7 @@ Q_GLOBAL_STATIC(QIconLoader, iconLoaderInstance)
static QString fallbackTheme()
{
- return QString("hicolor");
+ return QString("hicolor");
}
QIconLoader::QIconLoader() : m_themeKey(1), m_supportsSvg(false), m_initialized(false)
@@ -67,403 +67,403 @@ QIconLoader::QIconLoader() : m_themeKey(1), m_supportsSvg(false), m_initialized(
static inline QString systemThemeName()
{
- return QIcon::themeName();
+ return QIcon::themeName();
}
static inline QStringList systemIconSearchPaths()
{
- auto paths = QIcon::themeSearchPaths();
- paths.push_front(":/icons");
- return paths;
+ auto paths = QIcon::themeSearchPaths();
+ paths.push_front(":/icons");
+ return paths;
}
void QIconLoader::ensureInitialized()
{
- if (!m_initialized)
- {
- m_initialized = true;
+ if (!m_initialized)
+ {
+ m_initialized = true;
- Q_ASSERT(qApp);
+ Q_ASSERT(qApp);
- m_systemTheme = QIcon::themeName();
+ m_systemTheme = QIcon::themeName();
- if (m_systemTheme.isEmpty())
- m_systemTheme = fallbackTheme();
- m_supportsSvg = true;
- }
+ if (m_systemTheme.isEmpty())
+ m_systemTheme = fallbackTheme();
+ m_supportsSvg = true;
+ }
}
QIconLoader *QIconLoader::instance()
{
- iconLoaderInstance()->ensureInitialized();
- return iconLoaderInstance();
+ iconLoaderInstance()->ensureInitialized();
+ return iconLoaderInstance();
}
// Queries the system theme and invalidates existing
// icons if the theme has changed.
void QIconLoader::updateSystemTheme()
{
- // Only change if this is not explicitly set by the user
- if (m_userTheme.isEmpty())
- {
- QString theme = systemThemeName();
- if (theme.isEmpty())
- theme = fallbackTheme();
- if (theme != m_systemTheme)
- {
- m_systemTheme = theme;
- invalidateKey();
- }
- }
+ // Only change if this is not explicitly set by the user
+ if (m_userTheme.isEmpty())
+ {
+ QString theme = systemThemeName();
+ if (theme.isEmpty())
+ theme = fallbackTheme();
+ if (theme != m_systemTheme)
+ {
+ m_systemTheme = theme;
+ invalidateKey();
+ }
+ }
}
void QIconLoader::setThemeName(const QString &themeName)
{
- m_userTheme = themeName;
- invalidateKey();
+ m_userTheme = themeName;
+ invalidateKey();
}
void QIconLoader::setThemeSearchPath(const QStringList &searchPaths)
{
- m_iconDirs = searchPaths;
- themeList.clear();
- invalidateKey();
+ m_iconDirs = searchPaths;
+ themeList.clear();
+ invalidateKey();
}
QStringList QIconLoader::themeSearchPaths() const
{
- if (m_iconDirs.isEmpty())
- {
- m_iconDirs = systemIconSearchPaths();
- }
- return m_iconDirs;
+ if (m_iconDirs.isEmpty())
+ {
+ m_iconDirs = systemIconSearchPaths();
+ }
+ return m_iconDirs;
}
QIconTheme::QIconTheme(const QString &themeName) : m_valid(false)
{
- QFile themeIndex;
-
- QStringList iconDirs = systemIconSearchPaths();
- for (int i = 0; i < iconDirs.size(); ++i)
- {
- QDir iconDir(iconDirs[i]);
- QString themeDir = iconDir.path() + QLatin1Char('/') + themeName;
- themeIndex.setFileName(themeDir + QLatin1String("/index.theme"));
- if (themeIndex.exists())
- {
- m_contentDir = themeDir;
- m_valid = true;
-
- foreach (QString path, iconDirs)
- {
- if (QFileInfo(path).isDir())
- m_contentDirs.append(path + QLatin1Char('/') + themeName);
- }
-
- break;
- }
- }
-
- // if there is no index file, abscond.
- if (!themeIndex.exists())
- return;
-
- // otherwise continue reading index file
- const QSettings indexReader(themeIndex.fileName(), QSettings::IniFormat);
- QStringListIterator keyIterator(indexReader.allKeys());
- while (keyIterator.hasNext())
- {
- const QString key = keyIterator.next();
- if (!key.endsWith(QLatin1String("/Size")))
- continue;
-
- // Note the QSettings ini-format does not accept
- // slashes in key names, hence we have to cheat
- int size = indexReader.value(key).toInt();
- if (!size)
- continue;
-
- QString directoryKey = key.left(key.size() - 5);
- QIconDirInfo dirInfo(directoryKey);
- dirInfo.size = size;
- QString type =
- indexReader.value(directoryKey + QLatin1String("/Type")).toString();
-
- if (type == QLatin1String("Fixed"))
- dirInfo.type = QIconDirInfo::Fixed;
- else if (type == QLatin1String("Scalable"))
- dirInfo.type = QIconDirInfo::Scalable;
- else
- dirInfo.type = QIconDirInfo::Threshold;
-
- dirInfo.threshold =
- indexReader.value(directoryKey + QLatin1String("/Threshold"), 2)
- .toInt();
-
- dirInfo.minSize =
- indexReader.value(directoryKey + QLatin1String("/MinSize"), size)
- .toInt();
-
- dirInfo.maxSize =
- indexReader.value(directoryKey + QLatin1String("/MaxSize"), size)
- .toInt();
- m_keyList.append(dirInfo);
- }
-
- // Parent themes provide fallbacks for missing icons
- m_parents = indexReader.value(QLatin1String("Icon Theme/Inherits")).toStringList();
- m_parents.removeAll(QString());
-
- // Ensure a default platform fallback for all themes
- if (m_parents.isEmpty())
- {
- const QString fallback = fallbackTheme();
- if (!fallback.isEmpty())
- m_parents.append(fallback);
- }
-
- // Ensure that all themes fall back to hicolor
- if (!m_parents.contains(QLatin1String("hicolor")))
- m_parents.append(QLatin1String("hicolor"));
+ QFile themeIndex;
+
+ QStringList iconDirs = systemIconSearchPaths();
+ for (int i = 0; i < iconDirs.size(); ++i)
+ {
+ QDir iconDir(iconDirs[i]);
+ QString themeDir = iconDir.path() + QLatin1Char('/') + themeName;
+ themeIndex.setFileName(themeDir + QLatin1String("/index.theme"));
+ if (themeIndex.exists())
+ {
+ m_contentDir = themeDir;
+ m_valid = true;
+
+ foreach (QString path, iconDirs)
+ {
+ if (QFileInfo(path).isDir())
+ m_contentDirs.append(path + QLatin1Char('/') + themeName);
+ }
+
+ break;
+ }
+ }
+
+ // if there is no index file, abscond.
+ if (!themeIndex.exists())
+ return;
+
+ // otherwise continue reading index file
+ const QSettings indexReader(themeIndex.fileName(), QSettings::IniFormat);
+ QStringListIterator keyIterator(indexReader.allKeys());
+ while (keyIterator.hasNext())
+ {
+ const QString key = keyIterator.next();
+ if (!key.endsWith(QLatin1String("/Size")))
+ continue;
+
+ // Note the QSettings ini-format does not accept
+ // slashes in key names, hence we have to cheat
+ int size = indexReader.value(key).toInt();
+ if (!size)
+ continue;
+
+ QString directoryKey = key.left(key.size() - 5);
+ QIconDirInfo dirInfo(directoryKey);
+ dirInfo.size = size;
+ QString type =
+ indexReader.value(directoryKey + QLatin1String("/Type")).toString();
+
+ if (type == QLatin1String("Fixed"))
+ dirInfo.type = QIconDirInfo::Fixed;
+ else if (type == QLatin1String("Scalable"))
+ dirInfo.type = QIconDirInfo::Scalable;
+ else
+ dirInfo.type = QIconDirInfo::Threshold;
+
+ dirInfo.threshold =
+ indexReader.value(directoryKey + QLatin1String("/Threshold"), 2)
+ .toInt();
+
+ dirInfo.minSize =
+ indexReader.value(directoryKey + QLatin1String("/MinSize"), size)
+ .toInt();
+
+ dirInfo.maxSize =
+ indexReader.value(directoryKey + QLatin1String("/MaxSize"), size)
+ .toInt();
+ m_keyList.append(dirInfo);
+ }
+
+ // Parent themes provide fallbacks for missing icons
+ m_parents = indexReader.value(QLatin1String("Icon Theme/Inherits")).toStringList();
+ m_parents.removeAll(QString());
+
+ // Ensure a default platform fallback for all themes
+ if (m_parents.isEmpty())
+ {
+ const QString fallback = fallbackTheme();
+ if (!fallback.isEmpty())
+ m_parents.append(fallback);
+ }
+
+ // Ensure that all themes fall back to hicolor
+ if (!m_parents.contains(QLatin1String("hicolor")))
+ m_parents.append(QLatin1String("hicolor"));
}
QThemeIconEntries QIconLoader::findIconHelper(const QString &themeName, const QString &iconName,
- QStringList &visited) const
-{
- QThemeIconEntries entries;
- Q_ASSERT(!themeName.isEmpty());
-
- QPixmap pixmap;
-
- // Used to protect against potential recursions
- visited << themeName;
-
- QIconTheme theme = themeList.value(themeName);
- if (!theme.isValid())
- {
- theme = QIconTheme(themeName);
- if (!theme.isValid())
- theme = QIconTheme(fallbackTheme());
-
- themeList.insert(themeName, theme);
- }
-
- QStringList contentDirs = theme.contentDirs();
- const QVector<QIconDirInfo> subDirs = theme.keyList();
-
- const QString svgext(QLatin1String(".svg"));
- const QString pngext(QLatin1String(".png"));
- const QString xpmext(QLatin1String(".xpm"));
-
- // Add all relevant files
- for (int i = 0; i < subDirs.size(); ++i)
- {
- const QIconDirInfo &dirInfo = subDirs.at(i);
- QString subdir = dirInfo.path;
-
- foreach (QString contentDir, contentDirs)
- {
- QDir currentDir(contentDir + '/' + subdir);
-
- if (currentDir.exists(iconName + pngext))
- {
- PixmapEntry *iconEntry = new PixmapEntry;
- iconEntry->dir = dirInfo;
- iconEntry->filename = currentDir.filePath(iconName + pngext);
- // Notice we ensure that pixmap entries always come before
- // scalable to preserve search order afterwards
- entries.prepend(iconEntry);
- }
- else if (m_supportsSvg && currentDir.exists(iconName + svgext))
- {
- ScalableEntry *iconEntry = new ScalableEntry;
- iconEntry->dir = dirInfo;
- iconEntry->filename = currentDir.filePath(iconName + svgext);
- entries.append(iconEntry);
- break;
- }
- else if (currentDir.exists(iconName + xpmext))
- {
- PixmapEntry *iconEntry = new PixmapEntry;
- iconEntry->dir = dirInfo;
- iconEntry->filename = currentDir.filePath(iconName + xpmext);
- // Notice we ensure that pixmap entries always come before
- // scalable to preserve search order afterwards
- entries.append(iconEntry);
- break;
- }
- }
- }
-
- if (entries.isEmpty())
- {
- const QStringList parents = theme.parents();
- // Search recursively through inherited themes
- for (int i = 0; i < parents.size(); ++i)
- {
-
- const QString parentTheme = parents.at(i).trimmed();
-
- if (!visited.contains(parentTheme)) // guard against recursion
- entries = findIconHelper(parentTheme, iconName, visited);
-
- if (!entries.isEmpty()) // success
- break;
- }
- }
+ QStringList &visited) const
+{
+ QThemeIconEntries entries;
+ Q_ASSERT(!themeName.isEmpty());
+
+ QPixmap pixmap;
+
+ // Used to protect against potential recursions
+ visited << themeName;
+
+ QIconTheme theme = themeList.value(themeName);
+ if (!theme.isValid())
+ {
+ theme = QIconTheme(themeName);
+ if (!theme.isValid())
+ theme = QIconTheme(fallbackTheme());
+
+ themeList.insert(themeName, theme);
+ }
+
+ QStringList contentDirs = theme.contentDirs();
+ const QVector<QIconDirInfo> subDirs = theme.keyList();
+
+ const QString svgext(QLatin1String(".svg"));
+ const QString pngext(QLatin1String(".png"));
+ const QString xpmext(QLatin1String(".xpm"));
+
+ // Add all relevant files
+ for (int i = 0; i < subDirs.size(); ++i)
+ {
+ const QIconDirInfo &dirInfo = subDirs.at(i);
+ QString subdir = dirInfo.path;
+
+ foreach (QString contentDir, contentDirs)
+ {
+ QDir currentDir(contentDir + '/' + subdir);
+
+ if (currentDir.exists(iconName + pngext))
+ {
+ PixmapEntry *iconEntry = new PixmapEntry;
+ iconEntry->dir = dirInfo;
+ iconEntry->filename = currentDir.filePath(iconName + pngext);
+ // Notice we ensure that pixmap entries always come before
+ // scalable to preserve search order afterwards
+ entries.prepend(iconEntry);
+ }
+ else if (m_supportsSvg && currentDir.exists(iconName + svgext))
+ {
+ ScalableEntry *iconEntry = new ScalableEntry;
+ iconEntry->dir = dirInfo;
+ iconEntry->filename = currentDir.filePath(iconName + svgext);
+ entries.append(iconEntry);
+ break;
+ }
+ else if (currentDir.exists(iconName + xpmext))
+ {
+ PixmapEntry *iconEntry = new PixmapEntry;
+ iconEntry->dir = dirInfo;
+ iconEntry->filename = currentDir.filePath(iconName + xpmext);
+ // Notice we ensure that pixmap entries always come before
+ // scalable to preserve search order afterwards
+ entries.append(iconEntry);
+ break;
+ }
+ }
+ }
+
+ if (entries.isEmpty())
+ {
+ const QStringList parents = theme.parents();
+ // Search recursively through inherited themes
+ for (int i = 0; i < parents.size(); ++i)
+ {
+
+ const QString parentTheme = parents.at(i).trimmed();
+
+ if (!visited.contains(parentTheme)) // guard against recursion
+ entries = findIconHelper(parentTheme, iconName, visited);
+
+ if (!entries.isEmpty()) // success
+ break;
+ }
+ }
/*********************************************************************
Author: Kaitlin Rupert <kaitlin.rupert@intel.com>
Date: Aug 12, 2010
Description: Make it so that the QIcon loader honors /usr/share/pixmaps
- directory. This is a valid directory per the Freedesktop.org
- icon theme specification.
+ directory. This is a valid directory per the Freedesktop.org
+ icon theme specification.
Bug: https://bugreports.qt.nokia.com/browse/QTBUG-12874
*********************************************************************/
#ifdef Q_OS_LINUX
- /* Freedesktop standard says to look in /usr/share/pixmaps last */
- if (entries.isEmpty())
- {
- const QString pixmaps(QLatin1String("/usr/share/pixmaps"));
-
- QDir currentDir(pixmaps);
- QIconDirInfo dirInfo(pixmaps);
- if (currentDir.exists(iconName + pngext))
- {
- PixmapEntry *iconEntry = new PixmapEntry;
- iconEntry->dir = dirInfo;
- iconEntry->filename = currentDir.filePath(iconName + pngext);
- // Notice we ensure that pixmap entries always come before
- // scalable to preserve search order afterwards
- entries.prepend(iconEntry);
- }
- else if (m_supportsSvg && currentDir.exists(iconName + svgext))
- {
- ScalableEntry *iconEntry = new ScalableEntry;
- iconEntry->dir = dirInfo;
- iconEntry->filename = currentDir.filePath(iconName + svgext);
- entries.append(iconEntry);
- }
- else if (currentDir.exists(iconName + xpmext))
- {
- PixmapEntry *iconEntry = new PixmapEntry;
- iconEntry->dir = dirInfo;
- iconEntry->filename = currentDir.filePath(iconName + xpmext);
- // Notice we ensure that pixmap entries always come before
- // scalable to preserve search order afterwards
- entries.append(iconEntry);
- }
- }
+ /* Freedesktop standard says to look in /usr/share/pixmaps last */
+ if (entries.isEmpty())
+ {
+ const QString pixmaps(QLatin1String("/usr/share/pixmaps"));
+
+ QDir currentDir(pixmaps);
+ QIconDirInfo dirInfo(pixmaps);
+ if (currentDir.exists(iconName + pngext))
+ {
+ PixmapEntry *iconEntry = new PixmapEntry;
+ iconEntry->dir = dirInfo;
+ iconEntry->filename = currentDir.filePath(iconName + pngext);
+ // Notice we ensure that pixmap entries always come before
+ // scalable to preserve search order afterwards
+ entries.prepend(iconEntry);
+ }
+ else if (m_supportsSvg && currentDir.exists(iconName + svgext))
+ {
+ ScalableEntry *iconEntry = new ScalableEntry;
+ iconEntry->dir = dirInfo;
+ iconEntry->filename = currentDir.filePath(iconName + svgext);
+ entries.append(iconEntry);
+ }
+ else if (currentDir.exists(iconName + xpmext))
+ {
+ PixmapEntry *iconEntry = new PixmapEntry;
+ iconEntry->dir = dirInfo;
+ iconEntry->filename = currentDir.filePath(iconName + xpmext);
+ // Notice we ensure that pixmap entries always come before
+ // scalable to preserve search order afterwards
+ entries.append(iconEntry);
+ }
+ }
#endif
- if (entries.isEmpty())
- {
- // Search for unthemed icons in main dir of search paths
- QStringList themeSearchPaths = QIcon::themeSearchPaths();
- foreach (QString contentDir, themeSearchPaths)
- {
- QDir currentDir(contentDir);
-
- if (currentDir.exists(iconName + pngext))
- {
- PixmapEntry *iconEntry = new PixmapEntry;
- iconEntry->filename = currentDir.filePath(iconName + pngext);
- // Notice we ensure that pixmap entries always come before
- // scalable to preserve search order afterwards
- entries.prepend(iconEntry);
- }
- else if (m_supportsSvg && currentDir.exists(iconName + svgext))
- {
- ScalableEntry *iconEntry = new ScalableEntry;
- iconEntry->filename = currentDir.filePath(iconName + svgext);
- entries.append(iconEntry);
- break;
- }
- else if (currentDir.exists(iconName + xpmext))
- {
- PixmapEntry *iconEntry = new PixmapEntry;
- iconEntry->filename = currentDir.filePath(iconName + xpmext);
- // Notice we ensure that pixmap entries always come before
- // scalable to preserve search order afterwards
- entries.append(iconEntry);
- break;
- }
- }
- }
- return entries;
+ if (entries.isEmpty())
+ {
+ // Search for unthemed icons in main dir of search paths
+ QStringList themeSearchPaths = QIcon::themeSearchPaths();
+ foreach (QString contentDir, themeSearchPaths)
+ {
+ QDir currentDir(contentDir);
+
+ if (currentDir.exists(iconName + pngext))
+ {
+ PixmapEntry *iconEntry = new PixmapEntry;
+ iconEntry->filename = currentDir.filePath(iconName + pngext);
+ // Notice we ensure that pixmap entries always come before
+ // scalable to preserve search order afterwards
+ entries.prepend(iconEntry);
+ }
+ else if (m_supportsSvg && currentDir.exists(iconName + svgext))
+ {
+ ScalableEntry *iconEntry = new ScalableEntry;
+ iconEntry->filename = currentDir.filePath(iconName + svgext);
+ entries.append(iconEntry);
+ break;
+ }
+ else if (currentDir.exists(iconName + xpmext))
+ {
+ PixmapEntry *iconEntry = new PixmapEntry;
+ iconEntry->filename = currentDir.filePath(iconName + xpmext);
+ // Notice we ensure that pixmap entries always come before
+ // scalable to preserve search order afterwards
+ entries.append(iconEntry);
+ break;
+ }
+ }
+ }
+ return entries;
}
QThemeIconEntries QIconLoader::loadIcon(const QString &name) const
{
- if (!themeName().isEmpty())
- {
- QStringList visited;
- return findIconHelper(themeName(), name, visited);
- }
+ if (!themeName().isEmpty())
+ {
+ QStringList visited;
+ return findIconHelper(themeName(), name, visited);
+ }
- return QThemeIconEntries();
+ return QThemeIconEntries();
}
// -------- Icon Loader Engine -------- //
QIconLoaderEngineFixed::QIconLoaderEngineFixed(const QString &iconName)
- : m_iconName(iconName), m_key(0)
+ : m_iconName(iconName), m_key(0)
{
}
QIconLoaderEngineFixed::~QIconLoaderEngineFixed()
{
- qDeleteAll(m_entries);
+ qDeleteAll(m_entries);
}
QIconLoaderEngineFixed::QIconLoaderEngineFixed(const QIconLoaderEngineFixed &other)
- : QIconEngine(other), m_iconName(other.m_iconName), m_key(0)
+ : QIconEngine(other), m_iconName(other.m_iconName), m_key(0)
{
}
QIconEngine *QIconLoaderEngineFixed::clone() const
{
- return new QIconLoaderEngineFixed(*this);
+ return new QIconLoaderEngineFixed(*this);
}
bool QIconLoaderEngineFixed::read(QDataStream &in)
{
- in >> m_iconName;
- return true;
+ in >> m_iconName;
+ return true;
}
bool QIconLoaderEngineFixed::write(QDataStream &out) const
{
- out << m_iconName;
- return true;
+ out << m_iconName;
+ return true;
}
bool QIconLoaderEngineFixed::hasIcon() const
{
- return !(m_entries.isEmpty());
+ return !(m_entries.isEmpty());
}
// Lazily load the icon
void QIconLoaderEngineFixed::ensureLoaded()
{
- if (!(QIconLoader::instance()->themeKey() == m_key))
- {
+ if (!(QIconLoader::instance()->themeKey() == m_key))
+ {
- qDeleteAll(m_entries);
+ qDeleteAll(m_entries);
- m_entries = QIconLoader::instance()->loadIcon(m_iconName);
- m_key = QIconLoader::instance()->themeKey();
- }
+ m_entries = QIconLoader::instance()->loadIcon(m_iconName);
+ m_key = QIconLoader::instance()->themeKey();
+ }
}
void QIconLoaderEngineFixed::paint(QPainter *painter, const QRect &rect, QIcon::Mode mode,
- QIcon::State state)
+ QIcon::State state)
{
- QSize pixmapSize = rect.size();
+ QSize pixmapSize = rect.size();
#if defined(Q_WS_MAC)
- pixmapSize *= qt_mac_get_scalefactor();
+ pixmapSize *= qt_mac_get_scalefactor();
#endif
- painter->drawPixmap(rect, pixmap(pixmapSize, mode, state));
+ painter->drawPixmap(rect, pixmap(pixmapSize, mode, state));
}
/*
@@ -472,21 +472,21 @@ void QIconLoaderEngineFixed::paint(QPainter *painter, const QRect &rect, QIcon::
*/
static bool directoryMatchesSize(const QIconDirInfo &dir, int iconsize)
{
- if (dir.type == QIconDirInfo::Fixed)
- {
- return dir.size == iconsize;
- }
- else if (dir.type == QIconDirInfo::Scalable)
- {
- return dir.size <= dir.maxSize && iconsize >= dir.minSize;
- }
- else if (dir.type == QIconDirInfo::Threshold)
- {
- return iconsize >= dir.size - dir.threshold && iconsize <= dir.size + dir.threshold;
- }
-
- Q_ASSERT(1); // Not a valid value
- return false;
+ if (dir.type == QIconDirInfo::Fixed)
+ {
+ return dir.size == iconsize;
+ }
+ else if (dir.type == QIconDirInfo::Scalable)
+ {
+ return dir.size <= dir.maxSize && iconsize >= dir.minSize;
+ }
+ else if (dir.type == QIconDirInfo::Threshold)
+ {
+ return iconsize >= dir.size - dir.threshold && iconsize <= dir.size + dir.threshold;
+ }
+
+ Q_ASSERT(1); // Not a valid value
+ return false;
}
/*
@@ -495,66 +495,66 @@ static bool directoryMatchesSize(const QIconDirInfo &dir, int iconsize)
*/
static int directorySizeDistance(const QIconDirInfo &dir, int iconsize)
{
- if (dir.type == QIconDirInfo::Fixed)
- {
- return qAbs(dir.size - iconsize);
- }
- else if (dir.type == QIconDirInfo::Scalable)
- {
- if (iconsize < dir.minSize)
- return dir.minSize - iconsize;
- else if (iconsize > dir.maxSize)
- return iconsize - dir.maxSize;
- else
- return 0;
- }
- else if (dir.type == QIconDirInfo::Threshold)
- {
- if (iconsize < dir.size - dir.threshold)
- return dir.minSize - iconsize;
- else if (iconsize > dir.size + dir.threshold)
- return iconsize - dir.maxSize;
- else
- return 0;
- }
-
- Q_ASSERT(1); // Not a valid value
- return INT_MAX;
+ if (dir.type == QIconDirInfo::Fixed)
+ {
+ return qAbs(dir.size - iconsize);
+ }
+ else if (dir.type == QIconDirInfo::Scalable)
+ {
+ if (iconsize < dir.minSize)
+ return dir.minSize - iconsize;
+ else if (iconsize > dir.maxSize)
+ return iconsize - dir.maxSize;
+ else
+ return 0;
+ }
+ else if (dir.type == QIconDirInfo::Threshold)
+ {
+ if (iconsize < dir.size - dir.threshold)
+ return dir.minSize - iconsize;
+ else if (iconsize > dir.size + dir.threshold)
+ return iconsize - dir.maxSize;
+ else
+ return 0;
+ }
+
+ Q_ASSERT(1); // Not a valid value
+ return INT_MAX;
}
QIconLoaderEngineEntry *QIconLoaderEngineFixed::entryForSize(const QSize &size)
{
- int iconsize = qMin(size.width(), size.height());
-
- // Note that m_entries are sorted so that png-files
- // come first
-
- const int numEntries = m_entries.size();
-
- // Search for exact matches first
- for (int i = 0; i < numEntries; ++i)
- {
- QIconLoaderEngineEntry *entry = m_entries.at(i);
- if (directoryMatchesSize(entry->dir, iconsize))
- {
- return entry;
- }
- }
-
- // Find the minimum distance icon
- int minimalSize = INT_MAX;
- QIconLoaderEngineEntry *closestMatch = 0;
- for (int i = 0; i < numEntries; ++i)
- {
- QIconLoaderEngineEntry *entry = m_entries.at(i);
- int distance = directorySizeDistance(entry->dir, iconsize);
- if (distance < minimalSize)
- {
- minimalSize = distance;
- closestMatch = entry;
- }
- }
- return closestMatch;
+ int iconsize = qMin(size.width(), size.height());
+
+ // Note that m_entries are sorted so that png-files
+ // come first
+
+ const int numEntries = m_entries.size();
+
+ // Search for exact matches first
+ for (int i = 0; i < numEntries; ++i)
+ {
+ QIconLoaderEngineEntry *entry = m_entries.at(i);
+ if (directoryMatchesSize(entry->dir, iconsize))
+ {
+ return entry;
+ }
+ }
+
+ // Find the minimum distance icon
+ int minimalSize = INT_MAX;
+ QIconLoaderEngineEntry *closestMatch = 0;
+ for (int i = 0; i < numEntries; ++i)
+ {
+ QIconLoaderEngineEntry *entry = m_entries.at(i);
+ int distance = directorySizeDistance(entry->dir, iconsize);
+ if (distance < minimalSize)
+ {
+ minimalSize = distance;
+ closestMatch = entry;
+ }
+ }
+ return closestMatch;
}
/*
@@ -564,125 +564,125 @@ QIconLoaderEngineEntry *QIconLoaderEngineFixed::entryForSize(const QSize &size)
*
*/
QSize QIconLoaderEngineFixed::actualSize(const QSize &size, QIcon::Mode mode,
- QIcon::State state)
-{
- ensureLoaded();
-
- QIconLoaderEngineEntry *entry = entryForSize(size);
- if (entry)
- {
- const QIconDirInfo &dir = entry->dir;
- if (dir.type == QIconDirInfo::Scalable)
- return size;
- else
- {
- int result = qMin<int>(dir.size, qMin(size.width(), size.height()));
- return QSize(result, result);
- }
- }
- return QIconEngine::actualSize(size, mode, state);
+ QIcon::State state)
+{
+ ensureLoaded();
+
+ QIconLoaderEngineEntry *entry = entryForSize(size);
+ if (entry)
+ {
+ const QIconDirInfo &dir = entry->dir;
+ if (dir.type == QIconDirInfo::Scalable)
+ return size;
+ else
+ {
+ int result = qMin<int>(dir.size, qMin(size.width(), size.height()));
+ return QSize(result, result);
+ }
+ }
+ return QIconEngine::actualSize(size, mode, state);
}
QPixmap PixmapEntry::pixmap(const QSize &size, QIcon::Mode mode, QIcon::State state)
{
- Q_UNUSED(state);
-
- // Ensure that basePixmap is lazily initialized before generating the
- // key, otherwise the cache key is not unique
- if (basePixmap.isNull())
- basePixmap.load(filename);
-
- QSize actualSize = basePixmap.size();
- if (!actualSize.isNull() &&
- (actualSize.width() > size.width() || actualSize.height() > size.height()))
- actualSize.scale(size, Qt::KeepAspectRatio);
-
- QString key = QLatin1String("$qt_theme_") % HexString<qint64>(basePixmap.cacheKey()) %
- HexString<int>(mode) %
- HexString<qint64>(QGuiApplication::palette().cacheKey()) %
- HexString<int>(actualSize.width()) % HexString<int>(actualSize.height());
-
- QPixmap cachedPixmap;
- if (QPixmapCache::find(key, &cachedPixmap))
- {
- return cachedPixmap;
- }
- else
- {
- if (basePixmap.size() != actualSize)
- {
- cachedPixmap = basePixmap.scaled(actualSize, Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
- }
- else
- {
- cachedPixmap = basePixmap;
- }
- QPixmapCache::insert(key, cachedPixmap);
- }
- return cachedPixmap;
+ Q_UNUSED(state);
+
+ // Ensure that basePixmap is lazily initialized before generating the
+ // key, otherwise the cache key is not unique
+ if (basePixmap.isNull())
+ basePixmap.load(filename);
+
+ QSize actualSize = basePixmap.size();
+ if (!actualSize.isNull() &&
+ (actualSize.width() > size.width() || actualSize.height() > size.height()))
+ actualSize.scale(size, Qt::KeepAspectRatio);
+
+ QString key = QLatin1String("$qt_theme_") % HexString<qint64>(basePixmap.cacheKey()) %
+ HexString<int>(mode) %
+ HexString<qint64>(QGuiApplication::palette().cacheKey()) %
+ HexString<int>(actualSize.width()) % HexString<int>(actualSize.height());
+
+ QPixmap cachedPixmap;
+ if (QPixmapCache::find(key, &cachedPixmap))
+ {
+ return cachedPixmap;
+ }
+ else
+ {
+ if (basePixmap.size() != actualSize)
+ {
+ cachedPixmap = basePixmap.scaled(actualSize, Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
+ }
+ else
+ {
+ cachedPixmap = basePixmap;
+ }
+ QPixmapCache::insert(key, cachedPixmap);
+ }
+ return cachedPixmap;
}
QPixmap ScalableEntry::pixmap(const QSize &size, QIcon::Mode mode, QIcon::State state)
{
- if (svgIcon.isNull())
- {
- svgIcon = QIcon(filename);
- }
+ if (svgIcon.isNull())
+ {
+ svgIcon = QIcon(filename);
+ }
- // Simply reuse svg icon engine
- return svgIcon.pixmap(size, mode, state);
+ // Simply reuse svg icon engine
+ return svgIcon.pixmap(size, mode, state);
}
QPixmap QIconLoaderEngineFixed::pixmap(const QSize &size, QIcon::Mode mode, QIcon::State state)
{
- ensureLoaded();
+ ensureLoaded();
- QIconLoaderEngineEntry *entry = entryForSize(size);
- if (entry)
- {
- return entry->pixmap(size, mode, state);
- }
+ QIconLoaderEngineEntry *entry = entryForSize(size);
+ if (entry)
+ {
+ return entry->pixmap(size, mode, state);
+ }
- return QPixmap();
+ return QPixmap();
}
QString QIconLoaderEngineFixed::key() const
{
- return QLatin1String("QIconLoaderEngineFixed");
+ return QLatin1String("QIconLoaderEngineFixed");
}
void QIconLoaderEngineFixed::virtual_hook(int id, void *data)
{
- ensureLoaded();
-
- switch (id)
- {
- case QIconEngine::AvailableSizesHook:
- {
- QIconEngine::AvailableSizesArgument &arg =
- *reinterpret_cast<QIconEngine::AvailableSizesArgument *>(data);
- const int N = m_entries.size();
- QList<QSize> sizes;
- sizes.reserve(N);
-
- // Gets all sizes from the DirectoryInfo entries
- for (int i = 0; i < N; ++i)
- {
- int size = m_entries.at(i)->dir.size;
- sizes.append(QSize(size, size));
- }
- arg.sizes.swap(sizes); // commit
- }
- break;
- case QIconEngine::IconNameHook:
- {
- QString &name = *reinterpret_cast<QString *>(data);
- name = m_iconName;
- }
- break;
- default:
- QIconEngine::virtual_hook(id, data);
- }
+ ensureLoaded();
+
+ switch (id)
+ {
+ case QIconEngine::AvailableSizesHook:
+ {
+ QIconEngine::AvailableSizesArgument &arg =
+ *reinterpret_cast<QIconEngine::AvailableSizesArgument *>(data);
+ const int N = m_entries.size();
+ QList<QSize> sizes;
+ sizes.reserve(N);
+
+ // Gets all sizes from the DirectoryInfo entries
+ for (int i = 0; i < N; ++i)
+ {
+ int size = m_entries.at(i)->dir.size;
+ sizes.append(QSize(size, size));
+ }
+ arg.sizes.swap(sizes); // commit
+ }
+ break;
+ case QIconEngine::IconNameHook:
+ {
+ QString &name = *reinterpret_cast<QString *>(data);
+ name = m_iconName;
+ }
+ break;
+ default:
+ QIconEngine::virtual_hook(id, data);
+ }
}
} // QtXdg
diff --git a/libraries/iconfix/internal/qiconloader_p.h b/libraries/iconfix/internal/qiconloader_p.h
index b71bdd83..e45a08d6 100644
--- a/libraries/iconfix/internal/qiconloader_p.h
+++ b/libraries/iconfix/internal/qiconloader_p.h
@@ -61,46 +61,46 @@ class QIconLoader;
struct QIconDirInfo
{
- enum Type
- {
- Fixed,
- Scalable,
- Threshold
- };
- QIconDirInfo(const QString &_path = QString())
- : path(_path), size(0), maxSize(0), minSize(0), threshold(0), type(Threshold)
- {
- }
- QString path;
- short size;
- short maxSize;
- short minSize;
- short threshold;
- Type type : 4;
+ enum Type
+ {
+ Fixed,
+ Scalable,
+ Threshold
+ };
+ QIconDirInfo(const QString &_path = QString())
+ : path(_path), size(0), maxSize(0), minSize(0), threshold(0), type(Threshold)
+ {
+ }
+ QString path;
+ short size;
+ short maxSize;
+ short minSize;
+ short threshold;
+ Type type : 4;
};
class QIconLoaderEngineEntry
{
public:
- virtual ~QIconLoaderEngineEntry()
- {
- }
- virtual QPixmap pixmap(const QSize &size, QIcon::Mode mode, QIcon::State state) = 0;
- QString filename;
- QIconDirInfo dir;
- static int count;
+ virtual ~QIconLoaderEngineEntry()
+ {
+ }
+ virtual QPixmap pixmap(const QSize &size, QIcon::Mode mode, QIcon::State state) = 0;
+ QString filename;
+ QIconDirInfo dir;
+ static int count;
};
struct ScalableEntry : public QIconLoaderEngineEntry
{
- QPixmap pixmap(const QSize &size, QIcon::Mode mode, QIcon::State state) Q_DECL_OVERRIDE;
- QIcon svgIcon;
+ QPixmap pixmap(const QSize &size, QIcon::Mode mode, QIcon::State state) Q_DECL_OVERRIDE;
+ QIcon svgIcon;
};
struct PixmapEntry : public QIconLoaderEngineEntry
{
- QPixmap pixmap(const QSize &size, QIcon::Mode mode, QIcon::State state) Q_DECL_OVERRIDE;
- QPixmap basePixmap;
+ QPixmap pixmap(const QSize &size, QIcon::Mode mode, QIcon::State state) Q_DECL_OVERRIDE;
+ QPixmap basePixmap;
};
typedef QList<QIconLoaderEngineEntry *> QThemeIconEntries;
@@ -109,107 +109,107 @@ typedef QList<QIconLoaderEngineEntry *> QThemeIconEntries;
class QIconLoaderEngineFixed : public QIconEngine
{
public:
- QIconLoaderEngineFixed(const QString &iconName = QString());
- ~QIconLoaderEngineFixed();
+ QIconLoaderEngineFixed(const QString &iconName = QString());
+ ~QIconLoaderEngineFixed();
- void paint(QPainter *painter, const QRect &rect, QIcon::Mode mode, QIcon::State state);
- QPixmap pixmap(const QSize &size, QIcon::Mode mode, QIcon::State state);
- QSize actualSize(const QSize &size, QIcon::Mode mode, QIcon::State state);
- QIconEngine *clone() const;
- bool read(QDataStream &in);
- bool write(QDataStream &out) const;
+ void paint(QPainter *painter, const QRect &rect, QIcon::Mode mode, QIcon::State state);
+ QPixmap pixmap(const QSize &size, QIcon::Mode mode, QIcon::State state);
+ QSize actualSize(const QSize &size, QIcon::Mode mode, QIcon::State state);
+ QIconEngine *clone() const;
+ bool read(QDataStream &in);
+ bool write(QDataStream &out) const;
private:
- QString key() const;
- bool hasIcon() const;
- void ensureLoaded();
- void virtual_hook(int id, void *data);
- QIconLoaderEngineEntry *entryForSize(const QSize &size);
- QIconLoaderEngineFixed(const QIconLoaderEngineFixed &other);
- QThemeIconEntries m_entries;
- QString m_iconName;
- uint m_key;
-
- friend class QIconLoader;
+ QString key() const;
+ bool hasIcon() const;
+ void ensureLoaded();
+ void virtual_hook(int id, void *data);
+ QIconLoaderEngineEntry *entryForSize(const QSize &size);
+ QIconLoaderEngineFixed(const QIconLoaderEngineFixed &other);
+ QThemeIconEntries m_entries;
+ QString m_iconName;
+ uint m_key;
+
+ friend class QIconLoader;
};
class QIconTheme
{
public:
- QIconTheme(const QString &name);
- QIconTheme() : m_valid(false)
- {
- }
- QStringList parents()
- {
- return m_parents;
- }
- QVector<QIconDirInfo> keyList()
- {
- return m_keyList;
- }
- QString contentDir()
- {
- return m_contentDir;
- }
- QStringList contentDirs()
- {
- return m_contentDirs;
- }
- bool isValid()
- {
- return m_valid;
- }
+ QIconTheme(const QString &name);
+ QIconTheme() : m_valid(false)
+ {
+ }
+ QStringList parents()
+ {
+ return m_parents;
+ }
+ QVector<QIconDirInfo> keyList()
+ {
+ return m_keyList;
+ }
+ QString contentDir()
+ {
+ return m_contentDir;
+ }
+ QStringList contentDirs()
+ {
+ return m_contentDirs;
+ }
+ bool isValid()
+ {
+ return m_valid;
+ }
private:
- QString m_contentDir;
- QStringList m_contentDirs;
- QVector<QIconDirInfo> m_keyList;
- QStringList m_parents;
- bool m_valid;
+ QString m_contentDir;
+ QStringList m_contentDirs;
+ QVector<QIconDirInfo> m_keyList;
+ QStringList m_parents;
+ bool m_valid;
};
class QIconLoader
{
public:
- QIconLoader();
- QThemeIconEntries loadIcon(const QString &iconName) const;
- uint themeKey() const
- {
- return m_themeKey;
- }
-
- QString themeName() const
- {
- return m_userTheme.isEmpty() ? m_systemTheme : m_userTheme;
- }
- void setThemeName(const QString &themeName);
- QIconTheme theme()
- {
- return themeList.value(themeName());
- }
- void setThemeSearchPath(const QStringList &searchPaths);
- QStringList themeSearchPaths() const;
- QIconDirInfo dirInfo(int dirindex);
- static QIconLoader *instance();
- void updateSystemTheme();
- void invalidateKey()
- {
- m_themeKey++;
- }
- void ensureInitialized();
+ QIconLoader();
+ QThemeIconEntries loadIcon(const QString &iconName) const;
+ uint themeKey() const
+ {
+ return m_themeKey;
+ }
+
+ QString themeName() const
+ {
+ return m_userTheme.isEmpty() ? m_systemTheme : m_userTheme;
+ }
+ void setThemeName(const QString &themeName);
+ QIconTheme theme()
+ {
+ return themeList.value(themeName());
+ }
+ void setThemeSearchPath(const QStringList &searchPaths);
+ QStringList themeSearchPaths() const;
+ QIconDirInfo dirInfo(int dirindex);
+ static QIconLoader *instance();
+ void updateSystemTheme();
+ void invalidateKey()
+ {
+ m_themeKey++;
+ }
+ void ensureInitialized();
private:
- QThemeIconEntries findIconHelper(const QString &themeName, const QString &iconName,
- QStringList &visited) const;
- uint m_themeKey;
- bool m_supportsSvg;
- bool m_initialized;
-
- mutable QString m_userTheme;
- mutable QString m_systemTheme;
- mutable QStringList m_iconDirs;
- mutable QHash<QString, QIconTheme> themeList;
+ QThemeIconEntries findIconHelper(const QString &themeName, const QString &iconName,
+ QStringList &visited) const;
+ uint m_themeKey;
+ bool m_supportsSvg;
+ bool m_initialized;
+
+ mutable QString m_userTheme;
+ mutable QString m_systemTheme;
+ mutable QStringList m_iconDirs;
+ mutable QHash<QString, QIconTheme> themeList;
};
} // QtXdg
diff --git a/libraries/iconfix/xdgicon.cpp b/libraries/iconfix/xdgicon.cpp
index a36d80a9..36fb7d42 100644
--- a/libraries/iconfix/xdgicon.cpp
+++ b/libraries/iconfix/xdgicon.cpp
@@ -46,17 +46,17 @@ namespace
{
struct QtIconCache : public IconCache
{
- QtIconCache()
- {
- qAddPostRoutine(qt_cleanup_icon_cache);
- }
+ QtIconCache()
+ {
+ qAddPostRoutine(qt_cleanup_icon_cache);
+ }
};
}
-Q_GLOBAL_STATIC(IconCache, qtIconCache);
+Q_GLOBAL_STATIC(IconCache, qtIconCache)
static void qt_cleanup_icon_cache()
{
- qtIconCache()->clear();
+ qtIconCache()->clear();
}
/************************************************
@@ -78,7 +78,7 @@ XdgIcon::~XdgIcon()
************************************************/
QString XdgIcon::themeName()
{
- return QIcon::themeName();
+ return QIcon::themeName();
}
/************************************************
@@ -86,8 +86,8 @@ QString XdgIcon::themeName()
************************************************/
void XdgIcon::setThemeName(const QString &themeName)
{
- QIcon::setThemeName(themeName);
- QtXdg::QIconLoader::instance()->updateSystemTheme();
+ QIcon::setThemeName(themeName);
+ QtXdg::QIconLoader::instance()->updateSystemTheme();
}
/************************************************
@@ -96,43 +96,43 @@ void XdgIcon::setThemeName(const QString &themeName)
************************************************/
QIcon XdgIcon::fromTheme(const QString &iconName, const QIcon &fallback)
{
- if (iconName.isEmpty())
- return fallback;
-
- bool isAbsolute = (iconName[0] == '/');
-
- QString name = QFileInfo(iconName).fileName();
- if (name.endsWith(".png", Qt::CaseInsensitive) ||
- name.endsWith(".svg", Qt::CaseInsensitive) ||
- name.endsWith(".xpm", Qt::CaseInsensitive))
- {
- name.truncate(name.length() - 4);
- }
-
- QIcon icon;
-
- if (qtIconCache()->contains(name))
- {
- icon = *qtIconCache()->object(name);
- }
- else
- {
- QIcon *cachedIcon;
- if (!isAbsolute)
- cachedIcon = new QIcon(new QtXdg::QIconLoaderEngineFixed(name));
- else
- cachedIcon = new QIcon(iconName);
- qtIconCache()->insert(name, cachedIcon);
- icon = *cachedIcon;
- }
-
- // Note the qapp check is to allow lazy loading of static icons
- // Supporting fallbacks will not work for this case.
- if (qApp && !isAbsolute && icon.availableSizes().isEmpty())
- {
- return fallback;
- }
- return icon;
+ if (iconName.isEmpty())
+ return fallback;
+
+ bool isAbsolute = (iconName[0] == '/');
+
+ QString name = QFileInfo(iconName).fileName();
+ if (name.endsWith(".png", Qt::CaseInsensitive) ||
+ name.endsWith(".svg", Qt::CaseInsensitive) ||
+ name.endsWith(".xpm", Qt::CaseInsensitive))
+ {
+ name.truncate(name.length() - 4);
+ }
+
+ QIcon icon;
+
+ if (qtIconCache()->contains(name))
+ {
+ icon = *qtIconCache()->object(name);
+ }
+ else
+ {
+ QIcon *cachedIcon;
+ if (!isAbsolute)
+ cachedIcon = new QIcon(new QtXdg::QIconLoaderEngineFixed(name));
+ else
+ cachedIcon = new QIcon(iconName);
+ qtIconCache()->insert(name, cachedIcon);
+ icon = *cachedIcon;
+ }
+
+ // Note the qapp check is to allow lazy loading of static icons
+ // Supporting fallbacks will not work for this case.
+ if (qApp && !isAbsolute && icon.availableSizes().isEmpty())
+ {
+ return fallback;
+ }
+ return icon;
}
/************************************************
@@ -141,12 +141,12 @@ QIcon XdgIcon::fromTheme(const QString &iconName, const QIcon &fallback)
************************************************/
QIcon XdgIcon::fromTheme(const QStringList &iconNames, const QIcon &fallback)
{
- foreach (QString iconName, iconNames)
- {
- QIcon icon = fromTheme(iconName);
- if (!icon.isNull())
- return icon;
- }
-
- return fallback;
+ foreach (QString iconName, iconNames)
+ {
+ QIcon icon = fromTheme(iconName);
+ if (!icon.isNull())
+ return icon;
+ }
+
+ return fallback;
}
diff --git a/libraries/iconfix/xdgicon.h b/libraries/iconfix/xdgicon.h
index df8f026e..1380607c 100644
--- a/libraries/iconfix/xdgicon.h
+++ b/libraries/iconfix/xdgicon.h
@@ -36,13 +36,13 @@
class MULTIMC_ICONFIX_EXPORT XdgIcon
{
public:
- static QIcon fromTheme(const QString &iconName, const QIcon &fallback = QIcon());
- static QIcon fromTheme(const QStringList &iconNames, const QIcon &fallback = QIcon());
+ static QIcon fromTheme(const QString &iconName, const QIcon &fallback = QIcon());
+ static QIcon fromTheme(const QStringList &iconNames, const QIcon &fallback = QIcon());
- static QString themeName();
- static void setThemeName(const QString &themeName);
+ static QString themeName();
+ static void setThemeName(const QString &themeName);
protected:
- explicit XdgIcon();
- virtual ~XdgIcon();
+ explicit XdgIcon();
+ virtual ~XdgIcon();
};