Esempio n. 1
0
void PsMainWindow::psUpdateCounter() {
    setWindowIcon(wndIcon);

	int32 counter = App::histories().unreadFull;

    setWindowTitle((counter > 0) ? qsl("Telegram (%1)").arg(counter) : qsl("Telegram"));
    if (_psUnityLauncherEntry) {
        if (counter > 0) {
            ps_unity_launcher_entry_set_count(_psUnityLauncherEntry, (counter > 9999) ? 9999 : counter);
            ps_unity_launcher_entry_set_count_visible(_psUnityLauncherEntry, TRUE);
        } else {
            ps_unity_launcher_entry_set_count_visible(_psUnityLauncherEntry, FALSE);
        }
    }

    if (noQtTrayIcon) {
        if (useAppIndicator) {
            if (getms() > _psLastIndicatorUpdate + 1000) {
                psUpdateIndicator();
            } else if (!_psUpdateIndicatorTimer.isActive()) {
                _psUpdateIndicatorTimer.start(100);
            }
        } else if (useStatusIcon && trayIconChecked) {
            loadPixbuf(_trayIconImageGen());
            ps_gtk_status_icon_set_from_pixbuf(_trayIcon, _trayPixbuf);
        }
    } else if (trayIcon) {
        int32 counter = App::histories().unreadFull;
        style::color bg = (App::histories().unreadMuted < counter) ? st::counterBG : st::counterMuteBG;
        QIcon iconSmall;
        iconSmall.addPixmap(QPixmap::fromImage(iconWithCounter(16, counter, bg, true), Qt::ColorOnly));
        iconSmall.addPixmap(QPixmap::fromImage(iconWithCounter(32, counter, bg, true), Qt::ColorOnly));
        trayIcon->setIcon(iconSmall);
    }
}
Esempio n. 2
0
QImage Window::iconWithCounter(int size, int count, style::color bg, bool smallIcon) {
	bool layer = false;
	if (size < 0) {
		size = -size;
		layer = true;
	}
	if (layer) {
		if (size != 16) size = 32;

		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(st::transparent->c);
		{
			QPainter p(&result);
			p.setBrush(bg->b);
			p.setPen(Qt::NoPen);
			p.setRenderHint(QPainter::Antialiasing);
			int32 fontSize;
			if (size == 8) {
				fontSize = 6;
			} else if (size == 16) {
				fontSize = (cntSize < 2) ? 11 : ((cntSize < 3) ? 11 : 8);
			} else {
				fontSize = (cntSize < 2) ? 22 : ((cntSize < 3) ? 20 : 16);
			}
			style::font f(fontSize);
			int32 w = f->m.width(cnt), d, r;
			if (size == 8) {
				d = (cntSize < 2) ? 2 : 1;
				r = (cntSize < 2) ? 4 : 3;
			} else if (size == 16) {
				d = (cntSize < 2) ? 5 : ((cntSize < 3) ? 2 : 1);
				r = (cntSize < 2) ? 8 : ((cntSize < 3) ? 7 : 3);
			} 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->f);

			p.setPen(st::counterColor->p);

			p.drawText(size - w - d, size - f->height + f->ascent, cnt);
		}
		return result;
	} else {
		if (size != 16 && size != 32) size = 64;
	}

	QImage img((size == 16) ? icon16 : (size == 32 ? icon32 : icon64));
	if (!count) return img;

	if (smallIcon) {
		placeSmallCounter(img, size, count, bg, QPoint(), st::counterColor);
	} else {
		QPainter p(&img);
		p.drawPixmap(size / 2, size / 2, QPixmap::fromImage(iconWithCounter(-size / 2, count, bg, false)));
	}
	return img;
}