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); } }
void PsMainWindow::psSetupTrayIcon() { if (!trayIcon) { trayIcon = new QSystemTrayIcon(this); QIcon icon(QPixmap::fromImage(psTrayIcon(), Qt::ColorOnly)); icon.addPixmap(QPixmap::fromImage(psTrayIcon(true), Qt::ColorOnly), QIcon::Selected); trayIcon->setIcon(icon); trayIcon->setToolTip(QString::fromStdWString(AppName)); connect(trayIcon, SIGNAL(activated(QSystemTrayIcon::ActivationReason)), this, SLOT(toggleTray(QSystemTrayIcon::ActivationReason)), Qt::UniqueConnection); App::wnd()->updateTrayMenu(); } psUpdateCounter(); trayIcon->show(); }
void Window::setupTrayIcon() { if (!trayIcon) { if (trayIcon) trayIcon->deleteLater(); trayIcon = new QSystemTrayIcon(this); #ifdef Q_OS_MAC QIcon icon(QPixmap::fromImage(psTrayIcon())); icon.addPixmap(QPixmap::fromImage(psTrayIcon(true)), QIcon::Selected); #else QIcon icon(QPixmap::fromImage(iconLarge())); #endif trayIcon->setIcon(icon); trayIcon->setToolTip(QString::fromStdWString(AppName)); connect(trayIcon, SIGNAL(activated(QSystemTrayIcon::ActivationReason)), this, SLOT(toggleTray(QSystemTrayIcon::ActivationReason)), Qt::UniqueConnection); if (cPlatform() != dbipMac) { connect(trayIcon, SIGNAL(messageClicked()), this, SLOT(showFromTray())); } updateTrayMenu(); } psUpdateCounter(); trayIcon->show(); psUpdateDelegate(); }