Esempio n. 1
0
void PsMainWindow::psUpdateCounter() {
	int32 counter = App::histories().unreadFull - (cIncludeMuted() ? 0 : App::histories().unreadMuted);

    setWindowTitle((counter > 0) ? qsl("Telegram (%1)").arg(counter) : qsl("Telegram"));
	setWindowIcon(wndIcon);

    QString cnt = (counter < 1000) ? QString("%1").arg(counter) : QString("..%1").arg(counter % 100, 2, 10, QChar('0'));
    _private.setWindowBadge(counter ? cnt : QString());

	if (trayIcon) {
		bool muted = cIncludeMuted() ? (App::histories().unreadMuted >= counter) : false;
		bool dm = objc_darkMode();

		style::color bg = muted ? st::counterMuteBG : st::counterBG;
		QIcon icon;
		QImage img(psTrayIcon(dm)), imgsel(psTrayIcon(true));
		img.detach();
		imgsel.detach();
		int32 size = cRetina() ? 44 : 22;
		_placeCounter(img, size, counter, bg, (dm && muted) ? st::counterMacInvColor : st::counterColor);
		_placeCounter(imgsel, size, counter, st::white, st::counterMacInvColor);
		icon.addPixmap(QPixmap::fromImage(img, Qt::ColorOnly));
		icon.addPixmap(QPixmap::fromImage(imgsel, Qt::ColorOnly), QIcon::Selected);
		trayIcon->setIcon(icon);
	}
}
Esempio n. 2
0
void TitleWidget::updateCounter() {
	if (cWideMode() || !MTP::authedId()) return;

	int32 counter = App::histories().unreadFull - (cIncludeMuted() ? 0 : App::histories().unreadMuted);
	bool muted = cIncludeMuted() ? (App::histories().unreadMuted >= counter) : false;

	style::color bg = muted ? st::counterMuteBG : st::counterBG;
	
	if (counter > 0) {
		int32 size = cRetina() ? -32 : -16;
		switch (cScale()) {
		case dbisOneAndQuarter: size = -20; break;
		case dbisOneAndHalf: size = -24; break;
		case dbisTwo: size = -32; break;
		}
		_counter = QPixmap::fromImage(App::wnd()->iconWithCounter(size, counter, bg, false), Qt::ColorOnly);
		_counter.setDevicePixelRatio(cRetinaFactor());
		update(QRect(st::titleIconPos, st::titleIconImg.pxSize()));
	} else {
		if (!_counter.isNull()) {
			_counter = QPixmap();
			update(QRect(st::titleIconPos, st::titleIconImg.pxSize()));
		}
	}
}