mirror of
https://github.com/kotatogram/kotatogram-desktop
synced 2025-09-03 08:05:12 +00:00
Refactor icon unread counter painting.
This commit is contained in:
@@ -81,17 +81,6 @@ void FeedLangTestingKey(int key) {
|
||||
|
||||
MainWindow::MainWindow(not_null<Window::Controller*> controller)
|
||||
: Platform::MainWindow(controller) {
|
||||
|
||||
auto logo = Core::App().logo();
|
||||
icon16 = logo.scaledToWidth(16, Qt::SmoothTransformation);
|
||||
icon32 = logo.scaledToWidth(32, Qt::SmoothTransformation);
|
||||
icon64 = logo.scaledToWidth(64, Qt::SmoothTransformation);
|
||||
|
||||
auto logoNoMargin = Core::App().logoNoMargin();
|
||||
iconbig16 = logoNoMargin.scaledToWidth(16, Qt::SmoothTransformation);
|
||||
iconbig32 = logoNoMargin.scaledToWidth(32, Qt::SmoothTransformation);
|
||||
iconbig64 = logoNoMargin.scaledToWidth(64, Qt::SmoothTransformation);
|
||||
|
||||
resize(st::windowDefaultWidth, st::windowDefaultHeight);
|
||||
|
||||
setLocale(QLocale(QLocale::English, QLocale::UnitedStates));
|
||||
@@ -842,122 +831,6 @@ void MainWindow::updateControlsGeometry() {
|
||||
if (_main) _main->checkMainSectionToLayer();
|
||||
}
|
||||
|
||||
void MainWindow::placeSmallCounter(QImage &img, int size, int count, style::color bg, const QPoint &shift, style::color color) {
|
||||
QPainter p(&img);
|
||||
|
||||
QString cnt = (count < 100) ? QString("%1").arg(count) : QString("..%1").arg(count % 10, 1, 10, QChar('0'));
|
||||
int32 cntSize = cnt.size();
|
||||
|
||||
p.setBrush(bg->b);
|
||||
p.setPen(Qt::NoPen);
|
||||
p.setRenderHint(QPainter::Antialiasing);
|
||||
int32 fontSize;
|
||||
if (size == 16) {
|
||||
fontSize = 8;
|
||||
} else if (size == 32) {
|
||||
fontSize = (cntSize < 2) ? 12 : 12;
|
||||
} else {
|
||||
fontSize = (cntSize < 2) ? 22 : 22;
|
||||
}
|
||||
style::font f = { fontSize, 0, 0 };
|
||||
int32 w = f->width(cnt), d, r;
|
||||
if (size == 16) {
|
||||
d = (cntSize < 2) ? 2 : 1;
|
||||
r = (cntSize < 2) ? 4 : 3;
|
||||
} else if (size == 32) {
|
||||
d = (cntSize < 2) ? 5 : 2;
|
||||
r = (cntSize < 2) ? 8 : 7;
|
||||
} else {
|
||||
d = (cntSize < 2) ? 9 : 4;
|
||||
r = (cntSize < 2) ? 16 : 14;
|
||||
}
|
||||
p.drawRoundedRect(QRect(shift.x() + size - w - d * 2, shift.y() + size - f->height, w + d * 2, f->height), r, r);
|
||||
p.setFont(f->f);
|
||||
|
||||
p.setPen(color->p);
|
||||
|
||||
p.drawText(shift.x() + size - w - d, shift.y() + size - f->height + f->ascent, cnt);
|
||||
|
||||
}
|
||||
|
||||
QImage MainWindow::iconWithCounter(int size, int count, style::color bg, style::color fg, bool smallIcon) {
|
||||
bool layer = false;
|
||||
if (size < 0) {
|
||||
size = -size;
|
||||
layer = true;
|
||||
}
|
||||
if (layer) {
|
||||
if (size != 16 && size != 20 && size != 24) size = 32;
|
||||
|
||||
// platform/linux/main_window_linux depends on count used the same
|
||||
// way for all the same (count % 1000) values.
|
||||
QString cnt = (count < 1000) ? QString("%1").arg(count) : QString("..%1").arg(count % 100, 2, 10, QChar('0'));
|
||||
QImage result(size, size, QImage::Format_ARGB32);
|
||||
int32 cntSize = cnt.size();
|
||||
result.fill(Qt::transparent);
|
||||
{
|
||||
QPainter p(&result);
|
||||
p.setBrush(bg);
|
||||
p.setPen(Qt::NoPen);
|
||||
p.setRenderHint(QPainter::Antialiasing);
|
||||
int32 fontSize;
|
||||
if (size == 16) {
|
||||
fontSize = (cntSize < 2) ? 11 : ((cntSize < 3) ? 11 : 8);
|
||||
} else if (size == 20) {
|
||||
fontSize = (cntSize < 2) ? 14 : ((cntSize < 3) ? 13 : 10);
|
||||
} else if (size == 24) {
|
||||
fontSize = (cntSize < 2) ? 17 : ((cntSize < 3) ? 16 : 12);
|
||||
} else {
|
||||
fontSize = (cntSize < 2) ? 22 : ((cntSize < 3) ? 20 : 16);
|
||||
}
|
||||
style::font f = { fontSize, 0, 0 };
|
||||
int32 w = f->width(cnt), d, r;
|
||||
if (size == 16) {
|
||||
d = (cntSize < 2) ? 5 : ((cntSize < 3) ? 2 : 1);
|
||||
r = (cntSize < 2) ? 8 : ((cntSize < 3) ? 7 : 3);
|
||||
} else if (size == 20) {
|
||||
d = (cntSize < 2) ? 6 : ((cntSize < 3) ? 2 : 1);
|
||||
r = (cntSize < 2) ? 10 : ((cntSize < 3) ? 9 : 5);
|
||||
} else if (size == 24) {
|
||||
d = (cntSize < 2) ? 7 : ((cntSize < 3) ? 3 : 1);
|
||||
r = (cntSize < 2) ? 12 : ((cntSize < 3) ? 11 : 6);
|
||||
} else {
|
||||
d = (cntSize < 2) ? 9 : ((cntSize < 3) ? 4 : 2);
|
||||
r = (cntSize < 2) ? 16 : ((cntSize < 3) ? 14 : 8);
|
||||
}
|
||||
p.drawRoundedRect(QRect(size - w - d * 2, size - f->height, w + d * 2, f->height), r, r);
|
||||
p.setFont(f);
|
||||
|
||||
p.setPen(fg);
|
||||
|
||||
p.drawText(size - w - d, size - f->height + f->ascent, cnt);
|
||||
}
|
||||
return result;
|
||||
} else {
|
||||
if (size != 16 && size != 32) size = 64;
|
||||
}
|
||||
|
||||
QImage img(smallIcon ? ((size == 16) ? iconbig16 : (size == 32 ? iconbig32 : iconbig64)) : ((size == 16) ? icon16 : (size == 32 ? icon32 : icon64)));
|
||||
if (const auto controller = sessionController()) {
|
||||
if (controller->session().supportMode()) {
|
||||
Window::ConvertIconToBlack(img);
|
||||
}
|
||||
}
|
||||
if (!count) return img;
|
||||
|
||||
if (smallIcon) {
|
||||
placeSmallCounter(img, size, count, bg, QPoint(), fg);
|
||||
} else {
|
||||
QPainter p(&img);
|
||||
p.drawPixmap(
|
||||
size / 2,
|
||||
size / 2,
|
||||
Ui::PixmapFromImage(
|
||||
iconWithCounter(-size / 2, count, bg, fg, false)));
|
||||
}
|
||||
return img;
|
||||
}
|
||||
|
||||
void MainWindow::sendPaths() {
|
||||
if (controller().locked()) {
|
||||
return;
|
||||
|
Reference in New Issue
Block a user