Adapt linux tray icon implementation to the new QIcon::pixmap behavior

More info: https://codereview.qt-project.org/c/qt/qtbase/+/314618
This commit is contained in:
Ilya Fedin 2020-11-10 03:09:16 +04:00 committed by John Preston
parent c3b638449a
commit 9d6e5f2a5b
1 changed files with 11 additions and 8 deletions

View File

@ -201,7 +201,7 @@ QIcon TrayIconGen(int counter, bool muted) {
QIcon result; QIcon result;
QIcon systemIcon; QIcon systemIcon;
const auto iconSizes = { static const auto iconSizes = {
22, 22,
24, 24,
32, 32,
@ -240,9 +240,12 @@ QIcon TrayIconGen(int counter, bool muted) {
currentImageBack = Core::App().logo(); currentImageBack = Core::App().logo();
} }
if (currentImageBack.size() != desiredSize) { const auto currentImageBackSize = currentImageBack.size()
/ currentImageBack.devicePixelRatio();
if (currentImageBackSize != desiredSize) {
currentImageBack = currentImageBack.scaled( currentImageBack = currentImageBack.scaled(
desiredSize, desiredSize * currentImageBack.devicePixelRatio(),
Qt::IgnoreAspectRatio, Qt::IgnoreAspectRatio,
Qt::SmoothTransformation); Qt::SmoothTransformation);
} }
@ -327,8 +330,7 @@ std::unique_ptr<QTemporaryFile> TrayIconFile(
static const auto templateName = AppRuntimeDirectory() static const auto templateName = AppRuntimeDirectory()
+ kTrayIconFilename.utf16(); + kTrayIconFilename.utf16();
const auto dpr = style::DevicePixelRatio(); static const auto desiredSize = QSize(22, 22);
const auto desiredSize = QSize(22 * dpr, 22 * dpr);
auto ret = std::make_unique<QTemporaryFile>( auto ret = std::make_unique<QTemporaryFile>(
templateName, templateName,
@ -346,10 +348,11 @@ std::unique_ptr<QTemporaryFile> TrayIconFile(
std::less<>(), std::less<>(),
&QSize::width); &QSize::width);
icon const auto iconPixmap = icon.pixmap(*biggestSize);
.pixmap(*biggestSize)
iconPixmap
.scaled( .scaled(
desiredSize, desiredSize * iconPixmap.devicePixelRatio(),
Qt::IgnoreAspectRatio, Qt::IgnoreAspectRatio,
Qt::SmoothTransformation) Qt::SmoothTransformation)
.save(ret.get()); .save(ret.get());