2
0
mirror of https://github.com/kotatogram/kotatogram-desktop synced 2025-08-31 06:35:14 +00:00

Make WithSmallCounter adaptive

This commit is contained in:
Ilya Fedin
2023-10-30 23:06:35 +04:00
committed by John Preston
parent 9e10a80e00
commit 0f45abd534
3 changed files with 60 additions and 143 deletions

View File

@@ -58,7 +58,7 @@ private:
const QString _mutePanelTrayIconName;
const QString _attentionPanelTrayIconName;
const int _iconSizes[5];
const int _iconSizes[7];
bool _muted = true;
int32 _count = 0;
@@ -73,7 +73,7 @@ IconGraphic::IconGraphic()
: _panelTrayIconName("telegram-panel")
, _mutePanelTrayIconName("telegram-mute-panel")
, _attentionPanelTrayIconName("telegram-attention-panel")
, _iconSizes{ 16, 22, 24, 32, 48 } {
, _iconSizes{ 16, 22, 32, 48, 64, 128, 256 } {
}
IconGraphic::~IconGraphic() = default;
@@ -214,46 +214,13 @@ QIcon IconGraphic::trayIcon(
}
}
auto iconImage = currentImageBack;
if (counter > 0) {
const auto &bg = muted
? st::trayCounterBgMute
: st::trayCounterBg;
const auto &fg = st::trayCounterFg;
if (iconSize >= 22) {
const auto imageSize = dprSize(iconImage);
const auto layerSize = (iconSize >= 48)
? 32
: (iconSize >= 36)
? 24
: (iconSize >= 32)
? 20
: 16;
const auto layer = Window::GenerateCounterLayer({
.size = layerSize,
.devicePixelRatio = iconImage.devicePixelRatio(),
.count = counter,
.bg = bg,
.fg = fg,
});
QPainter p(&iconImage);
p.drawImage(
imageSize.width() - layer.width() - 1,
imageSize.height() - layer.height() - 1,
layer);
} else {
iconImage = Window::WithSmallCounter(std::move(iconImage), {
.size = 16,
.count = counter,
.bg = bg,
.fg = fg,
});
}
}
result.addPixmap(Ui::PixmapFromImage(std::move(iconImage)));
result.addPixmap(Ui::PixmapFromImage(counter > 0
? Window::WithSmallCounter(std::move(currentImageBack), {
.size = iconSize,
.count = counter,
.bg = muted ? st::trayCounterBgMute : st::trayCounterBg,
.fg = st::trayCounterFg,
}) : std::move(currentImageBack)));
}
updateIconRegenerationNeeded(