mirror of
https://github.com/kotatogram/kotatogram-desktop
synced 2025-08-30 06:07:45 +00:00
Scale window icon manually when getting from icon theme (#154)
This commit is contained in:
parent
550001dcca
commit
7fdae8f79c
@ -141,11 +141,48 @@ QIcon CreateIcon(Main::Session *session) {
|
||||
auto result = CreateOfficialIcon(session);
|
||||
|
||||
#if defined Q_OS_UNIX && !defined Q_OS_MAC
|
||||
if (
|
||||
(!session || !session->supportMode())
|
||||
&& cCustomAppIcon() == 0
|
||||
&& !QFileInfo::exists(cWorkingDir() + "tdata/icon.png")) {
|
||||
return QIcon::fromTheme(Platform::GetIconName(), result);
|
||||
if ((session && session->supportMode())
|
||||
|| (cCustomAppIcon() != 0)
|
||||
|| QFileInfo::exists(cWorkingDir() + "tdata/icon.png")) {
|
||||
return result;
|
||||
}
|
||||
|
||||
const auto iconFromTheme = QIcon::fromTheme(
|
||||
Platform::GetIconName(),
|
||||
result);
|
||||
|
||||
result = QIcon();
|
||||
|
||||
static const auto iconSizes = {
|
||||
16,
|
||||
22,
|
||||
32,
|
||||
48,
|
||||
64,
|
||||
128,
|
||||
256,
|
||||
};
|
||||
|
||||
// Qt's standard QIconLoaderEngine sets availableSizes
|
||||
// to XDG directories sizes, since svg icons are scalable,
|
||||
// they could be only in one XDG folder (like 48x48)
|
||||
// and Qt will set only a 48px icon to the window
|
||||
// even though the icon could be scaled to other sizes.
|
||||
// Thus, scale it manually to the most widespread sizes.
|
||||
for (const auto iconSize : iconSizes) {
|
||||
// We can't use QIcon::actualSize here
|
||||
// since it works incorrectly with svg icon themes
|
||||
const auto iconPixmap = iconFromTheme.pixmap(iconSize);
|
||||
|
||||
const auto iconPixmapSize = iconPixmap.size()
|
||||
/ iconPixmap.devicePixelRatio();
|
||||
|
||||
// Not a svg icon, don't scale it
|
||||
if (iconPixmapSize.width() != iconSize) {
|
||||
return iconFromTheme;
|
||||
}
|
||||
|
||||
result.addPixmap(iconPixmap);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user