mirror of
https://github.com/Nheko-Reborn/nheko.git
synced 2024-10-30 09:30:47 +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::closing, this, [this] { switchToLoginPage(""); });
|
||||||
connect(chat_page_, &ChatPage::unreadMessages, this, &MainWindow::setWindowTitle);
|
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::showLoginPage, this, &MainWindow::switchToLoginPage);
|
||||||
connect(chat_page_, &ChatPage::showNotification, this, &MainWindow::showNotification);
|
connect(chat_page_, &ChatPage::showNotification, this, &MainWindow::showNotification);
|
||||||
|
|
||||||
|
|
|
@ -12,9 +12,9 @@
|
||||||
|
|
||||||
#include "TrayIcon.h"
|
#include "TrayIcon.h"
|
||||||
|
|
||||||
MsgCountComposedIcon::MsgCountComposedIcon(const QString &filename)
|
MsgCountComposedIcon::MsgCountComposedIcon(const QIcon &icon)
|
||||||
: QIconEngine()
|
: QIconEngine()
|
||||||
, icon_{QIcon{filename}}
|
, icon_{icon}
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -41,8 +41,8 @@ MsgCountComposedIcon::paint(QPainter *painter,
|
||||||
brush.setColor(backgroundColor);
|
brush.setColor(backgroundColor);
|
||||||
|
|
||||||
QFont f;
|
QFont f;
|
||||||
f.setPointSizeF(8);
|
f.setPixelSize(int(BubbleDiameter * 0.6));
|
||||||
f.setWeight(QFont::Thin);
|
f.setWeight(QFont::Bold);
|
||||||
|
|
||||||
painter->setBrush(brush);
|
painter->setBrush(brush);
|
||||||
painter->setPen(Qt::NoPen);
|
painter->setPen(Qt::NoPen);
|
||||||
|
@ -66,9 +66,6 @@ MsgCountComposedIcon::clone() const
|
||||||
|
|
||||||
QList<QSize>
|
QList<QSize>
|
||||||
MsgCountComposedIcon::availableSizes(QIcon::Mode mode, QIcon::State state)
|
MsgCountComposedIcon::availableSizes(QIcon::Mode mode, QIcon::State state)
|
||||||
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
|
|
||||||
const
|
|
||||||
#endif
|
|
||||||
{
|
{
|
||||||
Q_UNUSED(mode);
|
Q_UNUSED(mode);
|
||||||
Q_UNUSED(state);
|
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)
|
TrayIcon::TrayIcon(const QString &filename, QWindow *parent)
|
||||||
: QSystemTrayIcon(parent)
|
: QSystemTrayIcon(parent)
|
||||||
|
, icon(filename)
|
||||||
{
|
{
|
||||||
#if defined(Q_OS_MACOS) || defined(Q_OS_WIN)
|
#if defined(Q_OS_MACOS) || defined(Q_OS_WIN)
|
||||||
setIcon(QIcon(filename));
|
setIcon(icon);
|
||||||
#else
|
#else
|
||||||
icon_ = new MsgCountComposedIcon(filename);
|
auto icon_ = new MsgCountComposedIcon(icon);
|
||||||
setIcon(QIcon(icon_));
|
setIcon(QIcon(icon_));
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -122,6 +120,15 @@ void
|
||||||
TrayIcon::setUnreadCount(int count)
|
TrayIcon::setUnreadCount(int count)
|
||||||
{
|
{
|
||||||
qGuiApp->setBadgeNumber(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"
|
#include "moc_TrayIcon.cpp"
|
||||||
|
|
|
@ -15,15 +15,11 @@ class QPainter;
|
||||||
class MsgCountComposedIcon final : public QIconEngine
|
class MsgCountComposedIcon final : public QIconEngine
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
MsgCountComposedIcon(const QString &filename);
|
MsgCountComposedIcon(const QIcon &icon);
|
||||||
|
|
||||||
void paint(QPainter *p, const QRect &rect, QIcon::Mode mode, QIcon::State state) override;
|
void paint(QPainter *p, const QRect &rect, QIcon::Mode mode, QIcon::State state) override;
|
||||||
QIconEngine *clone() const override;
|
QIconEngine *clone() const override;
|
||||||
QList<QSize> availableSizes(QIcon::Mode mode, QIcon::State state)
|
QList<QSize> availableSizes(QIcon::Mode mode, QIcon::State state) override;
|
||||||
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
|
|
||||||
const
|
|
||||||
#endif
|
|
||||||
override;
|
|
||||||
QPixmap pixmap(const QSize &size, QIcon::Mode mode, QIcon::State state) override;
|
QPixmap pixmap(const QSize &size, QIcon::Mode mode, QIcon::State state) override;
|
||||||
|
|
||||||
int msgCount = 0;
|
int msgCount = 0;
|
||||||
|
@ -47,7 +43,6 @@ private:
|
||||||
QAction *viewAction_;
|
QAction *viewAction_;
|
||||||
QAction *quitAction_;
|
QAction *quitAction_;
|
||||||
|
|
||||||
#if !defined(Q_OS_MACOS) && !defined(Q_OS_WIN)
|
int previousCount = 0;
|
||||||
MsgCountComposedIcon *icon_;
|
QIcon icon;
|
||||||
#endif
|
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue