mirror of
https://github.com/qbittorrent/qBittorrent
synced 2025-07-15 01:33:07 -07:00
Make the icon cache a class variable
This commit is contained in:
parent
35a3265657
commit
00eb61543d
2 changed files with 9 additions and 7 deletions
|
@ -31,7 +31,6 @@
|
||||||
|
|
||||||
#include <QApplication>
|
#include <QApplication>
|
||||||
#include <QFile>
|
#include <QFile>
|
||||||
#include <QIcon>
|
|
||||||
#include <QJsonDocument>
|
#include <QJsonDocument>
|
||||||
#include <QJsonObject>
|
#include <QJsonObject>
|
||||||
#include <QPalette>
|
#include <QPalette>
|
||||||
|
@ -127,14 +126,15 @@ QIcon UIThemeManager::getIcon(const QString &iconId, const QString &fallback) co
|
||||||
return icon;
|
return icon;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
// cache to avoid rescaling svg icons
|
|
||||||
static QHash<QString, QIcon> iconCache;
|
// Cache to avoid rescaling svg icons
|
||||||
const auto iter = iconCache.find(iconId);
|
// And don't cache system icons because users might change them at run time
|
||||||
if (iter != iconCache.end())
|
const auto iter = m_iconCache.find(iconId);
|
||||||
|
if (iter != m_iconCache.end())
|
||||||
return *iter;
|
return *iter;
|
||||||
|
|
||||||
const QIcon icon {getIconPathFromResources(iconId, fallback)};
|
const QIcon icon {getIconPathFromResources(iconId, fallback)};
|
||||||
iconCache[iconId] = icon;
|
m_iconCache[iconId] = icon;
|
||||||
return icon;
|
return icon;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -153,7 +153,7 @@ QString UIThemeManager::getIconPath(const QString &iconId) const
|
||||||
{
|
{
|
||||||
#if (defined(Q_OS_UNIX) && !defined(Q_OS_MACOS))
|
#if (defined(Q_OS_UNIX) && !defined(Q_OS_MACOS))
|
||||||
if (m_useSystemTheme) {
|
if (m_useSystemTheme) {
|
||||||
QString path = Utils::Fs::tempPath() + iconId + ".png";
|
QString path = Utils::Fs::tempPath() + iconId + QLatin1String(".png");
|
||||||
if (!QFile::exists(path)) {
|
if (!QFile::exists(path)) {
|
||||||
const QIcon icon = QIcon::fromTheme(iconId);
|
const QIcon icon = QIcon::fromTheme(iconId);
|
||||||
if (!icon.isNull())
|
if (!icon.isNull())
|
||||||
|
|
|
@ -31,6 +31,7 @@
|
||||||
|
|
||||||
#include <QColor>
|
#include <QColor>
|
||||||
#include <QHash>
|
#include <QHash>
|
||||||
|
#include <QIcon>
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
#include <QString>
|
#include <QString>
|
||||||
|
|
||||||
|
@ -60,6 +61,7 @@ private:
|
||||||
|
|
||||||
static UIThemeManager *m_instance;
|
static UIThemeManager *m_instance;
|
||||||
QHash<QString, QColor> m_colors;
|
QHash<QString, QColor> m_colors;
|
||||||
|
mutable QHash<QString, QIcon> m_iconCache;
|
||||||
const bool m_useCustomTheme;
|
const bool m_useCustomTheme;
|
||||||
#if (defined(Q_OS_UNIX) && !defined(Q_OS_MACOS))
|
#if (defined(Q_OS_UNIX) && !defined(Q_OS_MACOS))
|
||||||
bool m_useSystemTheme;
|
bool m_useSystemTheme;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue