mirror of
https://github.com/Nheko-Reborn/nheko.git
synced 2024-11-24 20:18:53 +03:00
Fix tray icon badge count not getting updated since 838b091acd
This commit is contained in:
parent
941f7f5ed5
commit
a486d8d7fc
3 changed files with 21 additions and 19 deletions
|
@ -60,7 +60,7 @@ MainWindow::MainWindow(QWindow *parent)
|
|||
|
||||
connect(chat_page_, &ChatPage::closing, this, [this] { switchToLoginPage(""); });
|
||||
connect(chat_page_, &ChatPage::unreadMessages, this, &MainWindow::setWindowTitle);
|
||||
connect(chat_page_, SIGNAL(unreadMessages(int)), trayIcon_, SLOT(setUnreadCount(int)));
|
||||
connect(chat_page_, &ChatPage::unreadMessages, trayIcon_, &TrayIcon::setUnreadCount);
|
||||
connect(chat_page_, &ChatPage::showLoginPage, this, &MainWindow::switchToLoginPage);
|
||||
connect(chat_page_, &ChatPage::showNotification, this, &MainWindow::showNotification);
|
||||
|
||||
|
|
|
@ -12,9 +12,9 @@
|
|||
|
||||
#include "TrayIcon.h"
|
||||
|
||||
MsgCountComposedIcon::MsgCountComposedIcon(const QString &filename)
|
||||
MsgCountComposedIcon::MsgCountComposedIcon(const QIcon &icon)
|
||||
: QIconEngine()
|
||||
, icon_{QIcon{filename}}
|
||||
, icon_{icon}
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -41,8 +41,8 @@ MsgCountComposedIcon::paint(QPainter *painter,
|
|||
brush.setColor(backgroundColor);
|
||||
|
||||
QFont f;
|
||||
f.setPointSizeF(8);
|
||||
f.setWeight(QFont::Thin);
|
||||
f.setPixelSize(int(BubbleDiameter * 0.6));
|
||||
f.setWeight(QFont::Bold);
|
||||
|
||||
painter->setBrush(brush);
|
||||
painter->setPen(Qt::NoPen);
|
||||
|
@ -66,9 +66,6 @@ MsgCountComposedIcon::clone() const
|
|||
|
||||
QList<QSize>
|
||||
MsgCountComposedIcon::availableSizes(QIcon::Mode mode, QIcon::State state)
|
||||
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
|
||||
const
|
||||
#endif
|
||||
{
|
||||
Q_UNUSED(mode);
|
||||
Q_UNUSED(state);
|
||||
|
@ -97,11 +94,12 @@ MsgCountComposedIcon::pixmap(const QSize &size, QIcon::Mode mode, QIcon::State s
|
|||
|
||||
TrayIcon::TrayIcon(const QString &filename, QWindow *parent)
|
||||
: QSystemTrayIcon(parent)
|
||||
, icon(filename)
|
||||
{
|
||||
#if defined(Q_OS_MACOS) || defined(Q_OS_WIN)
|
||||
setIcon(QIcon(filename));
|
||||
setIcon(icon);
|
||||
#else
|
||||
icon_ = new MsgCountComposedIcon(filename);
|
||||
auto icon_ = new MsgCountComposedIcon(icon);
|
||||
setIcon(QIcon(icon_));
|
||||
#endif
|
||||
|
||||
|
@ -122,6 +120,15 @@ void
|
|||
TrayIcon::setUnreadCount(int count)
|
||||
{
|
||||
qGuiApp->setBadgeNumber(count);
|
||||
|
||||
#if !defined(Q_OS_MACOS) && !defined(Q_OS_WIN)
|
||||
if (count != previousCount) {
|
||||
auto i = new MsgCountComposedIcon(icon);
|
||||
i->msgCount = count;
|
||||
setIcon(QIcon(i));
|
||||
previousCount = count;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
#include "moc_TrayIcon.cpp"
|
||||
|
|
|
@ -15,15 +15,11 @@ class QPainter;
|
|||
class MsgCountComposedIcon final : public QIconEngine
|
||||
{
|
||||
public:
|
||||
MsgCountComposedIcon(const QString &filename);
|
||||
MsgCountComposedIcon(const QIcon &icon);
|
||||
|
||||
void paint(QPainter *p, const QRect &rect, QIcon::Mode mode, QIcon::State state) override;
|
||||
QIconEngine *clone() const override;
|
||||
QList<QSize> availableSizes(QIcon::Mode mode, QIcon::State state)
|
||||
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
|
||||
const
|
||||
#endif
|
||||
override;
|
||||
QList<QSize> availableSizes(QIcon::Mode mode, QIcon::State state) override;
|
||||
QPixmap pixmap(const QSize &size, QIcon::Mode mode, QIcon::State state) override;
|
||||
|
||||
int msgCount = 0;
|
||||
|
@ -47,7 +43,6 @@ private:
|
|||
QAction *viewAction_;
|
||||
QAction *quitAction_;
|
||||
|
||||
#if !defined(Q_OS_MACOS) && !defined(Q_OS_WIN)
|
||||
MsgCountComposedIcon *icon_;
|
||||
#endif
|
||||
int previousCount = 0;
|
||||
QIcon icon;
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue