mirror of
https://github.com/d47081/qBittorrent.git
synced 2025-03-13 05:41:17 +00:00
Provide scaled pixmaps by UIThemeManager
Avoid leaking the paths of the theme resource files outside of the theme support implementation. PR #18269.
This commit is contained in:
parent
43e059801e
commit
53cec6db09
@ -51,7 +51,7 @@ AboutDialog::AboutDialog(QWidget *parent)
|
||||
// Title
|
||||
m_ui->labelName->setText(QStringLiteral("<b><h2>qBittorrent " QBT_VERSION " (%1-bit)</h2></b>").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 =
|
||||
|
@ -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
|
||||
|
@ -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)
|
||||
{
|
||||
|
@ -35,6 +35,7 @@
|
||||
#include <QJsonDocument>
|
||||
#include <QJsonObject>
|
||||
#include <QPalette>
|
||||
#include <QPixmapCache>
|
||||
#include <QResource>
|
||||
|
||||
#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)
|
||||
|
@ -34,6 +34,7 @@
|
||||
#include <QHash>
|
||||
#include <QIcon>
|
||||
#include <QObject>
|
||||
#include <QPixmap>
|
||||
#include <QString>
|
||||
|
||||
#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;
|
||||
|
||||
|
@ -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
|
||||
|
@ -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);
|
||||
|
Loading…
x
Reference in New Issue
Block a user