From e5577e43f8f41d5b332796287a4ab1aedc0cd5c4 Mon Sep 17 00:00:00 2001 From: Chocobo1 Date: Tue, 8 May 2018 21:30:12 +0800 Subject: [PATCH] Replace raster qbt logo with vector version Add helper function for svg icons. --- src/gui/about_imp.h | 2 +- src/gui/mainwindow.cpp | 10 ++++++---- src/gui/utils.cpp | 15 +++++++++++++++ src/gui/utils.h | 1 + 4 files changed, 23 insertions(+), 5 deletions(-) diff --git a/src/gui/about_imp.h b/src/gui/about_imp.h index 2625bedb4..a1bf05f69 100644 --- a/src/gui/about_imp.h +++ b/src/gui/about_imp.h @@ -55,7 +55,7 @@ public: lb_name->setText("

qBittorrent " QBT_VERSION " (32-bit)

"); #endif - logo->setPixmap(Utils::Gui::scaledPixmap(":/icons/skin/qbittorrent32.png", this)); + logo->setPixmap(Utils::Gui::scaledPixmapSvg(":/icons/skin/qbittorrent-tray.svg", this, 32)); // About QString aboutText = QString( diff --git a/src/gui/mainwindow.cpp b/src/gui/mainwindow.cpp index 0d3f8214b..61e48b19e 100644 --- a/src/gui/mainwindow.cpp +++ b/src/gui/mainwindow.cpp @@ -160,11 +160,13 @@ MainWindow::MainWindow(QWidget *parent) // Setting icons #ifndef Q_OS_MAC #ifdef Q_OS_UNIX - if (Preferences::instance()->useSystemIconTheme()) - setWindowIcon(QIcon::fromTheme("qbittorrent", QIcon(":/icons/skin/qbittorrent32.png"))); - else + const QIcon appLogo = Preferences::instance()->useSystemIconTheme() + ? QIcon::fromTheme("qbittorrent", QIcon(":/icons/skin/qbittorrent-tray.svg")) + : QIcon(":/icons/skin/qbittorrent-tray.svg"); +#else + const QIcon appLogo(":/icons/skin/qbittorrent-tray.svg"); #endif // Q_OS_UNIX - setWindowIcon(QIcon(":/icons/skin/qbittorrent32.png")); + setWindowIcon(appLogo); #endif // Q_OS_MAC #if (defined(Q_OS_UNIX)) diff --git a/src/gui/utils.cpp b/src/gui/utils.cpp index 4b83e3fda..c01c70f73 100644 --- a/src/gui/utils.cpp +++ b/src/gui/utils.cpp @@ -30,6 +30,7 @@ #include #include +#include #include #include #include @@ -69,6 +70,20 @@ QPixmap Utils::Gui::scaledPixmap(const QString &path, const QWidget *widget, con return pixmap.scaledToHeight(scaledHeight, Qt::SmoothTransformation); } +QPixmap Utils::Gui::scaledPixmapSvg(const QString &path, const QWidget *widget, const int baseHeight) +{ + const int scaledHeight = baseHeight * Utils::Gui::screenScalingFactor(widget); + const QString normalizedKey = path + "@" + QString::number(scaledHeight); + + QPixmap pm; + QPixmapCache cache; + if (!cache.find(normalizedKey, &pm)) { + pm = QIcon(path).pixmap(scaledHeight); + cache.insert(normalizedKey, pm); + } + return pm; +} + 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 8e44f1457..05da593be 100644 --- a/src/gui/utils.h +++ b/src/gui/utils.h @@ -49,6 +49,7 @@ namespace Utils } QPixmap scaledPixmap(const QString &path, const QWidget *widget, const int height = 0); + QPixmap scaledPixmapSvg(const QString &path, const QWidget *widget, const int baseHeight); QSize smallIconSize(const QWidget *widget = nullptr); QSize mediumIconSize(const QWidget *widget = nullptr); QSize largeIconSize(const QWidget *widget = nullptr);