diff --git a/src/gui/aboutdialog.cpp b/src/gui/aboutdialog.cpp
index 9e9959209..c54697b2d 100644
--- a/src/gui/aboutdialog.cpp
+++ b/src/gui/aboutdialog.cpp
@@ -51,7 +51,7 @@ AboutDialog::AboutDialog(QWidget *parent)
// Title
m_ui->labelName->setText(QStringLiteral("qBittorrent " QBT_VERSION " (%1-bit)
").arg(QT_POINTER_SIZE * 8));
- m_ui->logo->setPixmap(Utils::Gui::scaledPixmapSvg(UIThemeManager::instance()->getIconPath(u"qbittorrent-tray"_qs), this, 32));
+ m_ui->logo->setPixmap(UIThemeManager::instance()->getScaledPixmap(u"qbittorrent-tray"_qs, 32));
// About
const QString aboutText =
diff --git a/src/gui/optionsdialog.cpp b/src/gui/optionsdialog.cpp
index 7535805eb..b3b14fde6 100644
--- a/src/gui/optionsdialog.cpp
+++ b/src/gui/optionsdialog.cpp
@@ -884,11 +884,11 @@ void OptionsDialog::loadSpeedTabOptions()
const auto *pref = Preferences::instance();
const auto *session = BitTorrent::Session::instance();
- m_ui->labelGlobalRate->setPixmap(Utils::Gui::scaledPixmapSvg(UIThemeManager::instance()->getIconPath(u"slow_off"_qs), this, Utils::Gui::mediumIconSize(this).height()));
+ m_ui->labelGlobalRate->setPixmap(UIThemeManager::instance()->getScaledPixmap(u"slow_off"_qs, Utils::Gui::mediumIconSize(this).height()));
m_ui->spinUploadLimit->setValue(session->globalUploadSpeedLimit() / 1024);
m_ui->spinDownloadLimit->setValue(session->globalDownloadSpeedLimit() / 1024);
- m_ui->labelAltRate->setPixmap(Utils::Gui::scaledPixmapSvg(UIThemeManager::instance()->getIconPath(u"slow"_qs), this, Utils::Gui::mediumIconSize(this).height()));
+ m_ui->labelAltRate->setPixmap(UIThemeManager::instance()->getScaledPixmap(u"slow"_qs, Utils::Gui::mediumIconSize(this).height()));
m_ui->spinUploadLimitAlt->setValue(session->altGlobalUploadSpeedLimit() / 1024);
m_ui->spinDownloadLimitAlt->setValue(session->altGlobalDownloadSpeedLimit() / 1024);
@@ -1769,8 +1769,8 @@ void OptionsDialog::webUIHttpsCertChanged(const Path &path)
};
m_ui->textWebUIHttpsCert->setSelectedPath(path);
- m_ui->lblSslCertStatus->setPixmap(Utils::Gui::scaledPixmapSvg(UIThemeManager::instance()->getIconPath(
- isCertFileValid() ? u"security-high"_qs : u"security-low"_qs), this, 24));
+ m_ui->lblSslCertStatus->setPixmap(UIThemeManager::instance()->getScaledPixmap(
+ (isCertFileValid() ? u"security-high"_qs : u"security-low"_qs), 24));
}
void OptionsDialog::webUIHttpsKeyChanged(const Path &path)
@@ -1791,8 +1791,8 @@ void OptionsDialog::webUIHttpsKeyChanged(const Path &path)
};
m_ui->textWebUIHttpsKey->setSelectedPath(path);
- m_ui->lblSslKeyStatus->setPixmap(Utils::Gui::scaledPixmapSvg(UIThemeManager::instance()->getIconPath(
- isKeyFileValid() ? u"security-high"_qs : u"security-low"_qs), this, 24));
+ m_ui->lblSslKeyStatus->setPixmap(UIThemeManager::instance()->getScaledPixmap(
+ (isKeyFileValid() ? u"security-high"_qs : u"security-low"_qs), 24));
}
bool OptionsDialog::isWebUiEnabled() const
diff --git a/src/gui/speedlimitdialog.cpp b/src/gui/speedlimitdialog.cpp
index 165ece724..eebd306db 100644
--- a/src/gui/speedlimitdialog.cpp
+++ b/src/gui/speedlimitdialog.cpp
@@ -56,10 +56,10 @@ SpeedLimitDialog::SpeedLimitDialog(QWidget *parent)
{
m_ui->setupUi(this);
- m_ui->labelGlobalSpeedIcon->setPixmap(Utils::Gui::scaledPixmapSvg(UIThemeManager::instance()->getIconPath(u"slow_off"_qs)
- , this, Utils::Gui::mediumIconSize(this).height()));
- m_ui->labelAltGlobalSpeedIcon->setPixmap(Utils::Gui::scaledPixmapSvg(UIThemeManager::instance()->getIconPath(u"slow"_qs)
- , this, Utils::Gui::mediumIconSize(this).height()));
+ m_ui->labelGlobalSpeedIcon->setPixmap(
+ UIThemeManager::instance()->getScaledPixmap(u"slow_off"_qs, Utils::Gui::mediumIconSize(this).height()));
+ m_ui->labelAltGlobalSpeedIcon->setPixmap(
+ UIThemeManager::instance()->getScaledPixmap(u"slow"_qs, Utils::Gui::mediumIconSize(this).height()));
const auto initSlider = [](QSlider *slider, const int value, const int maximum)
{
diff --git a/src/gui/uithememanager.cpp b/src/gui/uithememanager.cpp
index 43ebc97db..5f41df9c0 100644
--- a/src/gui/uithememanager.cpp
+++ b/src/gui/uithememanager.cpp
@@ -35,6 +35,7 @@
#include
#include
#include
+#include
#include
#include "base/global.h"
@@ -237,6 +238,25 @@ QIcon UIThemeManager::getFlagIcon(const QString &countryIsoCode) const
return icon;
}
+QPixmap UIThemeManager::getScaledPixmap(const QString &iconId, const int height) const
+{
+ // (workaround) svg images require the use of `QIcon()` to load and scale losslessly,
+ // otherwise other image classes will convert it to pixmap first and follow-up scaling will become lossy.
+
+ Q_ASSERT(height > 0);
+
+ const QString cacheKey = iconId + u'@' + QString::number(height);
+
+ QPixmap pixmap;
+ if (!QPixmapCache::find(cacheKey, &pixmap))
+ {
+ pixmap = getIcon(iconId).pixmap(height);
+ QPixmapCache::insert(cacheKey, pixmap);
+ }
+
+ return pixmap;
+}
+
QColor UIThemeManager::getColor(const QString &id, const QColor &defaultColor) const
{
return m_colors.value(id, defaultColor);
@@ -272,28 +292,6 @@ QIcon UIThemeManager::getSystrayIcon() const
}
#endif
-Path UIThemeManager::getIconPath(const QString &iconId) const
-{
-#if (defined(Q_OS_UNIX) && !defined(Q_OS_MACOS))
- if (m_useSystemIcons)
- {
- Path path = Utils::Fs::tempPath() / Path(iconId + u".png");
- if (!path.exists())
- {
- const QIcon icon = QIcon::fromTheme(iconId);
- if (!icon.isNull())
- icon.pixmap(32).save(path.toString());
- else
- path = getIconPathFromResources(iconId);
- }
-
- return path;
- }
-#endif
-
- return getIconPathFromResources(iconId);
-}
-
Path UIThemeManager::getIconPathFromResources(const QString &iconId) const
{
if (m_themeSource)
diff --git a/src/gui/uithememanager.h b/src/gui/uithememanager.h
index fe5bc4738..8262ce418 100644
--- a/src/gui/uithememanager.h
+++ b/src/gui/uithememanager.h
@@ -34,6 +34,7 @@
#include
#include
#include
+#include
#include
#include "base/pathfwd.h"
@@ -58,9 +59,9 @@ public:
static void freeInstance();
static UIThemeManager *instance();
- Path getIconPath(const QString &iconId) const;
QIcon getIcon(const QString &iconId, const QString &fallback = {}) const;
QIcon getFlagIcon(const QString &countryIsoCode) const;
+ QPixmap getScaledPixmap(const QString &iconId, int height) const;
QColor getColor(const QString &id, const QColor &defaultColor) const;
diff --git a/src/gui/utils.cpp b/src/gui/utils.cpp
index 35e8d9217..b57e8a1e9 100644
--- a/src/gui/utils.cpp
+++ b/src/gui/utils.cpp
@@ -81,26 +81,6 @@ QPixmap Utils::Gui::scaledPixmap(const Path &path, const QWidget *widget, const
return (height == 0) ? pixmap : pixmap.scaledToHeight(height, Qt::SmoothTransformation);
}
-QPixmap Utils::Gui::scaledPixmapSvg(const Path &path, const QWidget *widget, const int height)
-{
- // (workaround) svg images require the use of `QIcon()` to load and scale losslessly,
- // otherwise other image classes will convert it to pixmap first and follow-up scaling will become lossy.
-
- Q_UNUSED(widget);
- Q_ASSERT(height > 0);
-
- const QString cacheKey = path.data() + u'@' + QString::number(height);
-
- QPixmap pixmap;
- QPixmapCache cache;
- if (!cache.find(cacheKey, &pixmap))
- {
- pixmap = QIcon(path.data()).pixmap(height);
- cache.insert(cacheKey, pixmap);
- }
- return pixmap;
-}
-
QSize Utils::Gui::smallIconSize(const QWidget *widget)
{
// Get DPI scaled icon size (device-dependent), see QT source
diff --git a/src/gui/utils.h b/src/gui/utils.h
index ccf67f172..34cfd58ee 100644
--- a/src/gui/utils.h
+++ b/src/gui/utils.h
@@ -42,7 +42,6 @@ namespace Utils::Gui
QPixmap scaledPixmap(const QIcon &icon, const QWidget *widget, int height);
QPixmap scaledPixmap(const Path &path, const QWidget *widget, int height = 0);
- QPixmap scaledPixmapSvg(const Path &path, const QWidget *widget, int height);
QSize smallIconSize(const QWidget *widget = nullptr);
QSize mediumIconSize(const QWidget *widget = nullptr);