mirror of
https://github.com/d47081/qBittorrent.git
synced 2025-01-11 07:18:08 +00:00
Merge pull request #12861 from jagannatharjun/style-icons
Allow changing GUI icons from theme bundles
This commit is contained in:
commit
35a3265657
@ -33,6 +33,7 @@
|
||||
#include "base/unicodestrings.h"
|
||||
#include "base/utils/misc.h"
|
||||
#include "ui_aboutdialog.h"
|
||||
#include "uithememanager.h"
|
||||
#include "utils.h"
|
||||
|
||||
AboutDialog::AboutDialog(QWidget *parent)
|
||||
@ -45,7 +46,7 @@ AboutDialog::AboutDialog(QWidget *parent)
|
||||
// Title
|
||||
m_ui->labelName->setText(QString::fromLatin1("<b><h2>qBittorrent " QBT_VERSION " (%1-bit)</h2></b>").arg(QT_POINTER_SIZE * 8));
|
||||
|
||||
m_ui->logo->setPixmap(Utils::Gui::scaledPixmapSvg(":/icons/qbittorrent-tray.svg", this, 32));
|
||||
m_ui->logo->setPixmap(Utils::Gui::scaledPixmapSvg(UIThemeManager::instance()->getIconPath(QLatin1String("qbittorrent-tray")), this, 32));
|
||||
|
||||
// About
|
||||
const QString aboutText = QString(
|
||||
|
@ -150,13 +150,7 @@ MainWindow::MainWindow(QWidget *parent)
|
||||
m_displaySpeedInTitle = pref->speedInTitleBar();
|
||||
// Setting icons
|
||||
#ifndef Q_OS_MACOS
|
||||
#ifdef Q_OS_UNIX
|
||||
const QIcon appLogo = Preferences::instance()->useSystemIconTheme()
|
||||
? QIcon::fromTheme("qbittorrent", QIcon(":/icons/qbittorrent-tray.svg"))
|
||||
: QIcon(":/icons/qbittorrent-tray.svg");
|
||||
#else
|
||||
const QIcon appLogo(":/icons/qbittorrent-tray.svg");
|
||||
#endif // Q_OS_UNIX
|
||||
const QIcon appLogo(UIThemeManager::instance()->getIcon(QLatin1String("qbittorrent"), QLatin1String("qbittorrent-tray")));
|
||||
setWindowIcon(appLogo);
|
||||
#endif // Q_OS_MACOS
|
||||
|
||||
@ -1539,12 +1533,14 @@ void MainWindow::reloadSessionStats()
|
||||
"qBittorrent"
|
||||
"</div>"
|
||||
"<div style='vertical-align: baseline; height: 18px;'>"
|
||||
"<img src=':/icons/downloading_small.svg' height='14'/> %1"
|
||||
"<img src='%1' height='14'/> %2"
|
||||
"</div>"
|
||||
"<div style='vertical-align: baseline; height: 18px;'>"
|
||||
"<img src=':/icons/seeding.svg' height='14'/> %2"
|
||||
"<img src='%3' height='14'/> %4"
|
||||
"</div>")
|
||||
.arg(tr("DL speed: %1", "e.g: Download speed: 10 KiB/s").arg(Utils::Misc::friendlyUnit(status.payloadDownloadRate, true))
|
||||
.arg(UIThemeManager::instance()->getIconPath("downloading_small")
|
||||
, tr("DL speed: %1", "e.g: Download speed: 10 KiB/s").arg(Utils::Misc::friendlyUnit(status.payloadDownloadRate, true))
|
||||
, UIThemeManager::instance()->getIconPath("seeding")
|
||||
, tr("UP speed: %1", "e.g: Upload speed: 10 KiB/s").arg(Utils::Misc::friendlyUnit(status.payloadUploadRate, true)));
|
||||
#else
|
||||
// OSes such as Windows do not support html here
|
||||
@ -1984,18 +1980,18 @@ QIcon MainWindow::getSystrayIcon() const
|
||||
#else
|
||||
switch (style) {
|
||||
case TrayIcon::NORMAL:
|
||||
return QIcon(QLatin1String(":/icons/qbittorrent-tray.svg"));
|
||||
return UIThemeManager::instance()->getIcon(QLatin1String("qbittorrent-tray"));
|
||||
case TrayIcon::MONO_DARK:
|
||||
return QIcon(QLatin1String(":/icons/qbittorrent-tray-dark.svg"));
|
||||
return UIThemeManager::instance()->getIcon(QLatin1String("qbittorrent-tray-dark"));
|
||||
case TrayIcon::MONO_LIGHT:
|
||||
return QIcon(QLatin1String(":/icons/qbittorrent-tray-light.svg"));
|
||||
return UIThemeManager::instance()->getIcon(QLatin1String("qbittorrent-tray-light"));
|
||||
default:
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
|
||||
// As a failsafe in case the enum is invalid
|
||||
return QIcon(QLatin1String(":/icons/qbittorrent-tray.svg"));
|
||||
return UIThemeManager::instance()->getIcon(QLatin1String("qbittorrent-tray"));
|
||||
}
|
||||
#endif // Q_OS_MACOS
|
||||
|
||||
|
@ -202,8 +202,8 @@ OptionsDialog::OptionsDialog(QWidget *parent)
|
||||
|
||||
m_ui->IpFilterRefreshBtn->setIcon(UIThemeManager::instance()->getIcon("view-refresh"));
|
||||
|
||||
m_ui->labelGlobalRate->setPixmap(Utils::Gui::scaledPixmap(":/icons/slow_off.svg", this, 16));
|
||||
m_ui->labelAltRate->setPixmap(Utils::Gui::scaledPixmap(":/icons/slow.svg", this, 16));
|
||||
m_ui->labelGlobalRate->setPixmap(Utils::Gui::scaledPixmap(UIThemeManager::instance()->getIcon(QLatin1String("slow_off")), this, 16));
|
||||
m_ui->labelAltRate->setPixmap(Utils::Gui::scaledPixmap(UIThemeManager::instance()->getIcon(QLatin1String("slow")), this, 16));
|
||||
|
||||
m_ui->deleteTorrentWarningIcon->setPixmap(QApplication::style()->standardIcon(QStyle::SP_MessageBoxCritical).pixmap(16, 16));
|
||||
m_ui->deleteTorrentWarningIcon->hide();
|
||||
@ -1691,7 +1691,7 @@ QString OptionsDialog::webUiPassword() const
|
||||
void OptionsDialog::webUIHttpsCertChanged(const QString &path, const ShowError showError)
|
||||
{
|
||||
m_ui->textWebUIHttpsCert->setSelectedPath(path);
|
||||
m_ui->lblSslCertStatus->setPixmap(Utils::Gui::scaledPixmapSvg(":/icons/security-low.svg", this, 24));
|
||||
m_ui->lblSslCertStatus->setPixmap(Utils::Gui::scaledPixmapSvg(UIThemeManager::instance()->getIconPath(QLatin1String("security-low")), this, 24));
|
||||
|
||||
if (path.isEmpty())
|
||||
return;
|
||||
@ -1709,13 +1709,13 @@ void OptionsDialog::webUIHttpsCertChanged(const QString &path, const ShowError s
|
||||
return;
|
||||
}
|
||||
|
||||
m_ui->lblSslCertStatus->setPixmap(Utils::Gui::scaledPixmapSvg(":/icons/security-high.svg", this, 24));
|
||||
m_ui->lblSslCertStatus->setPixmap(Utils::Gui::scaledPixmapSvg(UIThemeManager::instance()->getIconPath(QLatin1String("security-high")), this, 24));
|
||||
}
|
||||
|
||||
void OptionsDialog::webUIHttpsKeyChanged(const QString &path, const ShowError showError)
|
||||
{
|
||||
m_ui->textWebUIHttpsKey->setSelectedPath(path);
|
||||
m_ui->lblSslKeyStatus->setPixmap(Utils::Gui::scaledPixmapSvg(":/icons/security-low.svg", this, 24));
|
||||
m_ui->lblSslKeyStatus->setPixmap(Utils::Gui::scaledPixmapSvg(UIThemeManager::instance()->getIconPath(QLatin1String("security-low")), this, 24));
|
||||
|
||||
if (path.isEmpty())
|
||||
return;
|
||||
@ -1733,7 +1733,7 @@ void OptionsDialog::webUIHttpsKeyChanged(const QString &path, const ShowError sh
|
||||
return;
|
||||
}
|
||||
|
||||
m_ui->lblSslKeyStatus->setPixmap(Utils::Gui::scaledPixmapSvg(":/icons/security-high.svg", this, 24));
|
||||
m_ui->lblSslKeyStatus->setPixmap(Utils::Gui::scaledPixmapSvg(UIThemeManager::instance()->getIconPath(QLatin1String("security-high")), this, 24));
|
||||
}
|
||||
|
||||
void OptionsDialog::showConnectionTab()
|
||||
|
@ -33,6 +33,7 @@
|
||||
#include "base/global.h"
|
||||
#include "base/rss/rss_article.h"
|
||||
#include "base/rss/rss_item.h"
|
||||
#include "uithememanager.h"
|
||||
|
||||
ArticleListWidget::ArticleListWidget(QWidget *parent)
|
||||
: QListWidget(parent)
|
||||
@ -98,7 +99,7 @@ void ArticleListWidget::handleArticleRead(RSS::Article *rssArticle)
|
||||
if (!item) return;
|
||||
|
||||
item->setData(Qt::ForegroundRole, QPalette().color(QPalette::Inactive, QPalette::WindowText));
|
||||
item->setData(Qt::DecorationRole, QIcon(":/icons/sphere.png"));
|
||||
item->setData(Qt::DecorationRole, UIThemeManager::instance()->getIcon(QLatin1String("sphere")));
|
||||
|
||||
checkInvariant();
|
||||
}
|
||||
@ -123,11 +124,11 @@ QListWidgetItem *ArticleListWidget::createItem(RSS::Article *article) const
|
||||
item->setData(Qt::UserRole, reinterpret_cast<quintptr>(article));
|
||||
if (article->isRead()) {
|
||||
item->setData(Qt::ForegroundRole, QPalette().color(QPalette::Inactive, QPalette::WindowText));
|
||||
item->setData(Qt::DecorationRole, QIcon(":/icons/sphere.png"));
|
||||
item->setData(Qt::DecorationRole, UIThemeManager::instance()->getIcon(QLatin1String("sphere")));
|
||||
}
|
||||
else {
|
||||
item->setData(Qt::ForegroundRole, QPalette().color(QPalette::Active, QPalette::Link));
|
||||
item->setData(Qt::DecorationRole, QIcon(":/icons/sphere2.png"));
|
||||
item->setData(Qt::DecorationRole, UIThemeManager::instance()->getIcon(QLatin1String("sphere")));
|
||||
}
|
||||
|
||||
return item;
|
||||
|
@ -85,7 +85,7 @@ void FeedListWidget::handleFeedStateChanged(RSS::Feed *feed)
|
||||
|
||||
QIcon icon;
|
||||
if (feed->isLoading())
|
||||
icon = QIcon(QStringLiteral(":/icons/loading.png"));
|
||||
icon = UIThemeManager::instance()->getIcon(QStringLiteral("loading"));
|
||||
else if (feed->hasError())
|
||||
icon = UIThemeManager::instance()->getIcon(QStringLiteral("unavailable"));
|
||||
else if (!feed->iconPath().isEmpty())
|
||||
@ -235,7 +235,7 @@ QTreeWidgetItem *FeedListWidget::createItem(RSS::Item *rssItem, QTreeWidgetItem
|
||||
QIcon icon;
|
||||
if (auto feed = qobject_cast<RSS::Feed *>(rssItem)) {
|
||||
if (feed->isLoading())
|
||||
icon = QIcon(QStringLiteral(":/icons/loading.png"));
|
||||
icon = UIThemeManager::instance()->getIcon(QLatin1String("loading"));
|
||||
else if (feed->hasError())
|
||||
icon = UIThemeManager::instance()->getIcon(QStringLiteral("unavailable"));
|
||||
else if (!feed->iconPath().isEmpty())
|
||||
|
@ -40,6 +40,7 @@
|
||||
#include "base/bittorrent/sessionstatus.h"
|
||||
#include "base/utils/misc.h"
|
||||
#include "speedlimitdialog.h"
|
||||
#include "uithememanager.h"
|
||||
#include "utils.h"
|
||||
|
||||
StatusBar::StatusBar(QWidget *parent)
|
||||
@ -62,14 +63,14 @@ StatusBar::StatusBar(QWidget *parent)
|
||||
m_connecStatusLblIcon->setFlat(true);
|
||||
m_connecStatusLblIcon->setFocusPolicy(Qt::NoFocus);
|
||||
m_connecStatusLblIcon->setCursor(Qt::PointingHandCursor);
|
||||
m_connecStatusLblIcon->setIcon(QIcon(":/icons/firewalled.svg"));
|
||||
m_connecStatusLblIcon->setIcon(UIThemeManager::instance()->getIcon(QLatin1String("firewalled")));
|
||||
m_connecStatusLblIcon->setToolTip(
|
||||
QString::fromLatin1("<b>%1</b><br><i>%2</i>").arg(tr("Connection status:")
|
||||
, tr("No direct connections. This may indicate network configuration problems.")));
|
||||
connect(m_connecStatusLblIcon, &QAbstractButton::clicked, this, &StatusBar::connectionButtonClicked);
|
||||
|
||||
m_dlSpeedLbl = new QPushButton(this);
|
||||
m_dlSpeedLbl->setIcon(QIcon(":/icons/downloading_small.svg"));
|
||||
m_dlSpeedLbl->setIcon(UIThemeManager::instance()->getIcon(QLatin1String("downloading_small")));
|
||||
connect(m_dlSpeedLbl, &QAbstractButton::clicked, this, &StatusBar::capDownloadSpeed);
|
||||
m_dlSpeedLbl->setFlat(true);
|
||||
m_dlSpeedLbl->setFocusPolicy(Qt::NoFocus);
|
||||
@ -78,7 +79,7 @@ StatusBar::StatusBar(QWidget *parent)
|
||||
m_dlSpeedLbl->setMinimumWidth(200);
|
||||
|
||||
m_upSpeedLbl = new QPushButton(this);
|
||||
m_upSpeedLbl->setIcon(QIcon(":/icons/seeding.svg"));
|
||||
m_upSpeedLbl->setIcon(UIThemeManager::instance()->getIcon(QLatin1String("seeding")));
|
||||
connect(m_upSpeedLbl, &QAbstractButton::clicked, this, &StatusBar::capUploadSpeed);
|
||||
m_upSpeedLbl->setFlat(true);
|
||||
m_upSpeedLbl->setFocusPolicy(Qt::NoFocus);
|
||||
@ -173,17 +174,17 @@ void StatusBar::updateConnectionStatus()
|
||||
const BitTorrent::SessionStatus &sessionStatus = BitTorrent::Session::instance()->status();
|
||||
|
||||
if (!BitTorrent::Session::instance()->isListening()) {
|
||||
m_connecStatusLblIcon->setIcon(QIcon(QLatin1String(":/icons/disconnected.svg")));
|
||||
m_connecStatusLblIcon->setIcon(UIThemeManager::instance()->getIcon(QLatin1String("disconnected")));
|
||||
m_connecStatusLblIcon->setToolTip(QLatin1String("<b>") + tr("Connection Status:") + QLatin1String("</b><br>") + tr("Offline. This usually means that qBittorrent failed to listen on the selected port for incoming connections."));
|
||||
}
|
||||
else {
|
||||
if (sessionStatus.hasIncomingConnections) {
|
||||
// Connection OK
|
||||
m_connecStatusLblIcon->setIcon(QIcon(QLatin1String(":/icons/connected.svg")));
|
||||
m_connecStatusLblIcon->setIcon(UIThemeManager::instance()->getIcon(QLatin1String("connected")));
|
||||
m_connecStatusLblIcon->setToolTip(QLatin1String("<b>") + tr("Connection Status:") + QLatin1String("</b><br>") + tr("Online"));
|
||||
}
|
||||
else {
|
||||
m_connecStatusLblIcon->setIcon(QIcon(QLatin1String(":/icons/firewalled.svg")));
|
||||
m_connecStatusLblIcon->setIcon(UIThemeManager::instance()->getIcon(QLatin1String("firewalled")));
|
||||
m_connecStatusLblIcon->setToolTip(QLatin1String("<b>") + tr("Connection status:") + QLatin1String("</b><br>") + QLatin1String("<i>") + tr("No direct connections. This may indicate network configuration problems.") + QLatin1String("</i>"));
|
||||
}
|
||||
}
|
||||
@ -230,12 +231,12 @@ void StatusBar::refresh()
|
||||
void StatusBar::updateAltSpeedsBtn(bool alternative)
|
||||
{
|
||||
if (alternative) {
|
||||
m_altSpeedsBtn->setIcon(QIcon(":/icons/slow.svg"));
|
||||
m_altSpeedsBtn->setIcon(UIThemeManager::instance()->getIcon(QLatin1String("slow")));
|
||||
m_altSpeedsBtn->setToolTip(tr("Click to switch to regular speed limits"));
|
||||
m_altSpeedsBtn->setDown(true);
|
||||
}
|
||||
else {
|
||||
m_altSpeedsBtn->setIcon(QIcon(":/icons/slow_off.svg"));
|
||||
m_altSpeedsBtn->setIcon(UIThemeManager::instance()->getIcon(QLatin1String("slow_off")));
|
||||
m_altSpeedsBtn->setToolTip(tr("Click to switch to alternative speed limits"));
|
||||
m_altSpeedsBtn->setDown(false);
|
||||
}
|
||||
|
@ -165,40 +165,40 @@ StatusFilterWidget::StatusFilterWidget(QWidget *parent, TransferListWidget *tran
|
||||
// Add status filters
|
||||
auto *all = new QListWidgetItem(this);
|
||||
all->setData(Qt::DisplayRole, tr("All (0)", "this is for the status filter"));
|
||||
all->setData(Qt::DecorationRole, QIcon(":/icons/filterall.svg"));
|
||||
all->setData(Qt::DecorationRole, UIThemeManager::instance()->getIcon(QLatin1String("filterall")));
|
||||
auto *downloading = new QListWidgetItem(this);
|
||||
downloading->setData(Qt::DisplayRole, tr("Downloading (0)"));
|
||||
downloading->setData(Qt::DecorationRole, QIcon(":/icons/downloading.svg"));
|
||||
downloading->setData(Qt::DecorationRole, UIThemeManager::instance()->getIcon(QLatin1String("downloading")));
|
||||
auto *seeding = new QListWidgetItem(this);
|
||||
seeding->setData(Qt::DisplayRole, tr("Seeding (0)"));
|
||||
seeding->setData(Qt::DecorationRole, QIcon(":/icons/uploading.svg"));
|
||||
seeding->setData(Qt::DecorationRole, UIThemeManager::instance()->getIcon(QLatin1String("uploading")));
|
||||
auto *completed = new QListWidgetItem(this);
|
||||
completed->setData(Qt::DisplayRole, tr("Completed (0)"));
|
||||
completed->setData(Qt::DecorationRole, QIcon(":/icons/completed.svg"));
|
||||
completed->setData(Qt::DecorationRole, UIThemeManager::instance()->getIcon(QLatin1String("completed")));
|
||||
auto *resumed = new QListWidgetItem(this);
|
||||
resumed->setData(Qt::DisplayRole, tr("Resumed (0)"));
|
||||
resumed->setData(Qt::DecorationRole, QIcon(":/icons/resumed.svg"));
|
||||
resumed->setData(Qt::DecorationRole, UIThemeManager::instance()->getIcon(QLatin1String("resumed")));
|
||||
auto *paused = new QListWidgetItem(this);
|
||||
paused->setData(Qt::DisplayRole, tr("Paused (0)"));
|
||||
paused->setData(Qt::DecorationRole, QIcon(":/icons/paused.svg"));
|
||||
paused->setData(Qt::DecorationRole, UIThemeManager::instance()->getIcon(QLatin1String("paused")));
|
||||
auto *active = new QListWidgetItem(this);
|
||||
active->setData(Qt::DisplayRole, tr("Active (0)"));
|
||||
active->setData(Qt::DecorationRole, QIcon(":/icons/filteractive.svg"));
|
||||
active->setData(Qt::DecorationRole, UIThemeManager::instance()->getIcon(QLatin1String("filteractive")));
|
||||
auto *inactive = new QListWidgetItem(this);
|
||||
inactive->setData(Qt::DisplayRole, tr("Inactive (0)"));
|
||||
inactive->setData(Qt::DecorationRole, QIcon(":/icons/filterinactive.svg"));
|
||||
inactive->setData(Qt::DecorationRole, UIThemeManager::instance()->getIcon(QLatin1String("filterinactive")));
|
||||
auto *stalled = new QListWidgetItem(this);
|
||||
stalled->setData(Qt::DisplayRole, tr("Stalled (0)"));
|
||||
stalled->setData(Qt::DecorationRole, QIcon(":/icons/filterstalled.svg"));
|
||||
stalled->setData(Qt::DecorationRole, UIThemeManager::instance()->getIcon(QLatin1String("filterstalled")));
|
||||
auto *stalledUploading = new QListWidgetItem(this);
|
||||
stalledUploading->setData(Qt::DisplayRole, tr("Stalled Uploading (0)"));
|
||||
stalledUploading->setData(Qt::DecorationRole, QIcon(":/icons/stalledUP.svg"));
|
||||
stalledUploading->setData(Qt::DecorationRole, UIThemeManager::instance()->getIcon(QLatin1String("stalledUP")));
|
||||
auto *stalledDownloading = new QListWidgetItem(this);
|
||||
stalledDownloading->setData(Qt::DisplayRole, tr("Stalled Downloading (0)"));
|
||||
stalledDownloading->setData(Qt::DecorationRole, QIcon(":/icons/stalledDL.svg"));
|
||||
stalledDownloading->setData(Qt::DecorationRole, UIThemeManager::instance()->getIcon(QLatin1String("stalledDL")));
|
||||
auto *errored = new QListWidgetItem(this);
|
||||
errored->setData(Qt::DisplayRole, tr("Errored (0)"));
|
||||
errored->setData(Qt::DecorationRole, QIcon(":/icons/error.svg"));
|
||||
errored->setData(Qt::DecorationRole, UIThemeManager::instance()->getIcon(QLatin1String("error")));
|
||||
|
||||
const Preferences *const pref = Preferences::instance();
|
||||
setCurrentRow(pref->getTransSelFilter(), QItemSelectionModel::SelectCurrent);
|
||||
|
@ -727,55 +727,55 @@ QColor getDefaultColorByState(const BitTorrent::TorrentState state)
|
||||
|
||||
QIcon getPausedIcon()
|
||||
{
|
||||
static QIcon cached = QIcon(":/icons/paused.svg");
|
||||
static QIcon cached = UIThemeManager::instance()->getIcon(QLatin1String("paused"));
|
||||
return cached;
|
||||
}
|
||||
|
||||
QIcon getQueuedIcon()
|
||||
{
|
||||
static QIcon cached = QIcon(":/icons/queued.svg");
|
||||
static QIcon cached = UIThemeManager::instance()->getIcon(QLatin1String("queued"));
|
||||
return cached;
|
||||
}
|
||||
|
||||
QIcon getDownloadingIcon()
|
||||
{
|
||||
static QIcon cached = QIcon(":/icons/downloading.svg");
|
||||
static QIcon cached = UIThemeManager::instance()->getIcon(QLatin1String("downloading"));
|
||||
return cached;
|
||||
}
|
||||
|
||||
QIcon getStalledDownloadingIcon()
|
||||
{
|
||||
static QIcon cached = QIcon(":/icons/stalledDL.svg");
|
||||
static QIcon cached = UIThemeManager::instance()->getIcon(QLatin1String("stalledDL"));
|
||||
return cached;
|
||||
}
|
||||
|
||||
QIcon getUploadingIcon()
|
||||
{
|
||||
static QIcon cached = QIcon(":/icons/uploading.svg");
|
||||
static QIcon cached = UIThemeManager::instance()->getIcon(QLatin1String("uploading"));
|
||||
return cached;
|
||||
}
|
||||
|
||||
QIcon getStalledUploadingIcon()
|
||||
{
|
||||
static QIcon cached = QIcon(":/icons/stalledUP.svg");
|
||||
static QIcon cached = UIThemeManager::instance()->getIcon(QLatin1String("stalledUP"));
|
||||
return cached;
|
||||
}
|
||||
|
||||
QIcon getCompletedIcon()
|
||||
{
|
||||
static QIcon cached = QIcon(":/icons/completed.svg");
|
||||
static QIcon cached = UIThemeManager::instance()->getIcon(QLatin1String("completed"));
|
||||
return cached;
|
||||
}
|
||||
|
||||
QIcon getCheckingIcon()
|
||||
{
|
||||
static QIcon cached = QIcon(":/icons/checking.svg");
|
||||
static QIcon cached = UIThemeManager::instance()->getIcon(QLatin1String("checking"));
|
||||
return cached;
|
||||
}
|
||||
|
||||
QIcon getErrorIcon()
|
||||
{
|
||||
static QIcon cached = QIcon(":/icons/error.svg");
|
||||
static QIcon cached = UIThemeManager::instance()->getIcon(QLatin1String("error"));
|
||||
return cached;
|
||||
}
|
||||
|
||||
|
@ -865,7 +865,7 @@ void TransferListWidget::displayListMenu(const QPoint &)
|
||||
connect(actionDelete, &QAction::triggered, this, &TransferListWidget::softDeleteSelectedTorrents);
|
||||
auto *actionPreviewFile = new QAction(UIThemeManager::instance()->getIcon("view-preview"), tr("Preview file..."), listMenu);
|
||||
connect(actionPreviewFile, &QAction::triggered, this, &TransferListWidget::previewSelectedTorrents);
|
||||
auto *actionSetMaxRatio = new QAction(QIcon(QLatin1String(":/icons/ratio.svg")), tr("Limit share ratio..."), listMenu);
|
||||
auto *actionSetMaxRatio = new QAction(UIThemeManager::instance()->getIcon(QLatin1String("ratio")), tr("Limit share ratio..."), listMenu);
|
||||
connect(actionSetMaxRatio, &QAction::triggered, this, &TransferListWidget::setMaxRatioSelectedTorrents);
|
||||
auto *actionSetUploadLimit = new QAction(UIThemeManager::instance()->getIcon("kt-set-max-upload-speed"), tr("Limit upload rate..."), listMenu);
|
||||
connect(actionSetUploadLimit, &QAction::triggered, this, &TransferListWidget::setUpLimitSelectedTorrents);
|
||||
|
@ -37,14 +37,28 @@
|
||||
#include <QPalette>
|
||||
#include <QResource>
|
||||
|
||||
#include "base/iconprovider.h"
|
||||
#include "base/logger.h"
|
||||
#include "base/preferences.h"
|
||||
#include "base/utils/fs.h"
|
||||
|
||||
namespace
|
||||
{
|
||||
const QString ICONS_DIR = QStringLiteral(":icons/");
|
||||
const QString THEME_ICONS_DIR = QStringLiteral(":uitheme/icons/");
|
||||
const QString CONFIG_FILE_NAME = QStringLiteral(":uitheme/config.json");
|
||||
|
||||
QString findIcon(const QString &iconId, const QString &dir)
|
||||
{
|
||||
const QString pathSvg = dir + iconId + QLatin1String(".svg");
|
||||
if (QFile::exists(pathSvg))
|
||||
return pathSvg;
|
||||
|
||||
const QString pathPng = dir + iconId + QLatin1String(".png");
|
||||
if (QFile::exists(pathPng))
|
||||
return pathPng;
|
||||
|
||||
return {};
|
||||
}
|
||||
}
|
||||
|
||||
UIThemeManager *UIThemeManager::m_instance = nullptr;
|
||||
@ -62,9 +76,10 @@ void UIThemeManager::initInstance()
|
||||
}
|
||||
|
||||
UIThemeManager::UIThemeManager()
|
||||
: m_useCustomTheme(Preferences::instance()->useCustomUITheme())
|
||||
{
|
||||
const Preferences *const pref = Preferences::instance();
|
||||
if (pref->useCustomUITheme()) {
|
||||
if (m_useCustomTheme) {
|
||||
if (!QResource::registerResource(pref->customUIThemePath(), "/uitheme")) {
|
||||
LogMsg(tr("Failed to load UI theme from file: \"%1\"").arg(pref->customUIThemePath()), Log::WARNING);
|
||||
}
|
||||
@ -86,7 +101,7 @@ UIThemeManager *UIThemeManager::instance()
|
||||
|
||||
void UIThemeManager::applyStyleSheet() const
|
||||
{
|
||||
if (!Preferences::instance()->useCustomUITheme()) {
|
||||
if (!m_useCustomTheme) {
|
||||
qApp->setStyleSheet({});
|
||||
return;
|
||||
}
|
||||
@ -102,22 +117,15 @@ void UIThemeManager::applyStyleSheet() const
|
||||
qApp->setStyleSheet(qssFile.readAll());
|
||||
}
|
||||
|
||||
QIcon UIThemeManager::getIcon(const QString &iconId) const
|
||||
{
|
||||
return getIcon(iconId, iconId);
|
||||
}
|
||||
|
||||
QIcon UIThemeManager::getIcon(const QString &iconId, const QString &fallback) const
|
||||
{
|
||||
#if (defined(Q_OS_UNIX) && !defined(Q_OS_MACOS))
|
||||
if (m_useSystemTheme) {
|
||||
QIcon icon = QIcon::fromTheme(iconId);
|
||||
if (icon.name() != iconId)
|
||||
icon = QIcon::fromTheme(fallback, QIcon(IconProvider::instance()->getIconPath(iconId)));
|
||||
icon = QIcon::fromTheme(fallback, QIcon(getIconPathFromResources(iconId, fallback)));
|
||||
return icon;
|
||||
}
|
||||
#else
|
||||
Q_UNUSED(fallback)
|
||||
#endif
|
||||
// cache to avoid rescaling svg icons
|
||||
static QHash<QString, QIcon> iconCache;
|
||||
@ -125,7 +133,7 @@ QIcon UIThemeManager::getIcon(const QString &iconId, const QString &fallback) co
|
||||
if (iter != iconCache.end())
|
||||
return *iter;
|
||||
|
||||
const QIcon icon {IconProvider::instance()->getIconPath(iconId)};
|
||||
const QIcon icon {getIconPathFromResources(iconId, fallback)};
|
||||
iconCache[iconId] = icon;
|
||||
return icon;
|
||||
}
|
||||
@ -151,13 +159,30 @@ QString UIThemeManager::getIconPath(const QString &iconId) const
|
||||
if (!icon.isNull())
|
||||
icon.pixmap(32).save(path);
|
||||
else
|
||||
path = IconProvider::instance()->getIconPath(iconId);
|
||||
path = getIconPathFromResources(iconId);
|
||||
}
|
||||
|
||||
return path;
|
||||
}
|
||||
#endif
|
||||
return IconProvider::instance()->getIconPath(iconId);
|
||||
return getIconPathFromResources(iconId, {});
|
||||
}
|
||||
|
||||
QString UIThemeManager::getIconPathFromResources(const QString &iconId, const QString &fallback) const
|
||||
{
|
||||
if (m_useCustomTheme) {
|
||||
const QString customIcon = findIcon(iconId, THEME_ICONS_DIR);
|
||||
if (!customIcon.isEmpty())
|
||||
return customIcon;
|
||||
|
||||
if (!fallback.isEmpty()) {
|
||||
const QString fallbackIcon = findIcon(fallback, THEME_ICONS_DIR);
|
||||
if (!fallbackIcon.isEmpty())
|
||||
return fallbackIcon;
|
||||
}
|
||||
}
|
||||
|
||||
return findIcon(iconId, ICONS_DIR);
|
||||
}
|
||||
|
||||
void UIThemeManager::loadColorsFromJSONConfig()
|
||||
|
@ -46,20 +46,21 @@ public:
|
||||
|
||||
void applyStyleSheet() const;
|
||||
|
||||
QIcon getIcon(const QString &iconId) const;
|
||||
QIcon getIcon(const QString &iconId, const QString &fallback) const;
|
||||
QString getIconPath(const QString &iconId) const;
|
||||
QIcon getIcon(const QString &iconId, const QString &fallback = {}) const;
|
||||
QIcon getFlagIcon(const QString &countryIsoCode) const;
|
||||
|
||||
QColor getColor(const QString &id, const QColor &defaultColor) const;
|
||||
|
||||
private:
|
||||
UIThemeManager(); // singleton class
|
||||
QString getIconPath(const QString &iconId) const;
|
||||
QString getIconPathFromResources(const QString &iconId, const QString &fallback = {}) const;
|
||||
void loadColorsFromJSONConfig();
|
||||
void applyPalette() const;
|
||||
|
||||
static UIThemeManager *m_instance;
|
||||
QHash<QString, QColor> m_colors;
|
||||
const bool m_useCustomTheme;
|
||||
#if (defined(Q_OS_UNIX) && !defined(Q_OS_MACOS))
|
||||
bool m_useSystemTheme;
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user