mirror of
https://gitlab.linphone.org/BC/public/linphone-desktop.git
synced 2026-04-23 01:08:30 +00:00
feat(MessagesCountNotifier): use a blink in sys tray icon on GNU/Linux
This commit is contained in:
parent
7fc1047e4c
commit
ef3cbf5044
2 changed files with 38 additions and 5 deletions
|
|
@ -24,9 +24,11 @@
|
||||||
#include <QPainter>
|
#include <QPainter>
|
||||||
#include <QSvgRenderer>
|
#include <QSvgRenderer>
|
||||||
#include <QSystemTrayIcon>
|
#include <QSystemTrayIcon>
|
||||||
|
#include <QTimer>
|
||||||
|
|
||||||
#include "../../../app/App.hpp"
|
#include "../../../app/App.hpp"
|
||||||
#include "../../../utils/LinphoneUtils.hpp"
|
#include "../../../utils/LinphoneUtils.hpp"
|
||||||
|
#include "../../../utils/Utils.hpp"
|
||||||
|
|
||||||
#include "MessagesCountNotifierLinux.hpp"
|
#include "MessagesCountNotifierLinux.hpp"
|
||||||
|
|
||||||
|
|
@ -35,6 +37,7 @@
|
||||||
|
|
||||||
#define ICON_COUNTER_BACKGROUND_COLOR "#FF3C31"
|
#define ICON_COUNTER_BACKGROUND_COLOR "#FF3C31"
|
||||||
#define ICON_COUNTER_BACKGROUND_RADIUS 100
|
#define ICON_COUNTER_BACKGROUND_RADIUS 100
|
||||||
|
#define ICON_COUNTER_BLINK_INTERVAL 1000
|
||||||
#define ICON_COUNTER_TEXT_COLOR "#FFFBFA"
|
#define ICON_COUNTER_TEXT_COLOR "#FFFBFA"
|
||||||
#define ICON_COUNTER_TEXT_PIXEL_SIZE 144
|
#define ICON_COUNTER_TEXT_PIXEL_SIZE 144
|
||||||
|
|
||||||
|
|
@ -52,10 +55,21 @@ MessagesCountNotifier::MessagesCountNotifier (QObject *parent) : AbstractMessage
|
||||||
renderer.render(&painter);
|
renderer.render(&painter);
|
||||||
|
|
||||||
mBuf = new QPixmap(buf);
|
mBuf = new QPixmap(buf);
|
||||||
|
mBufWithCounter = new QPixmap();
|
||||||
|
|
||||||
|
mBlinkTimer = new QTimer(this);
|
||||||
|
mBlinkTimer->setInterval(ICON_COUNTER_BLINK_INTERVAL);
|
||||||
|
QObject::connect(mBlinkTimer, &QTimer::timeout, this, &MessagesCountNotifier::update);
|
||||||
|
|
||||||
|
Utils::connectOnce(
|
||||||
|
App::getInstance(), &App::focusWindowChanged,
|
||||||
|
this, &MessagesCountNotifier::updateUnreadMessagesCount
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
MessagesCountNotifier::~MessagesCountNotifier () {
|
MessagesCountNotifier::~MessagesCountNotifier () {
|
||||||
delete mBuf;
|
delete mBuf;
|
||||||
|
delete mBufWithCounter;
|
||||||
}
|
}
|
||||||
|
|
||||||
void MessagesCountNotifier::notifyUnreadMessagesCount (int n) {
|
void MessagesCountNotifier::notifyUnreadMessagesCount (int n) {
|
||||||
|
|
@ -64,15 +78,16 @@ void MessagesCountNotifier::notifyUnreadMessagesCount (int n) {
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (!n) {
|
if (!n) {
|
||||||
|
mBlinkTimer->stop();
|
||||||
sysTrayIcon->setIcon(QIcon(*mBuf));
|
sysTrayIcon->setIcon(QIcon(*mBuf));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
QPixmap buf(*mBuf);
|
*mBufWithCounter = *mBuf;
|
||||||
QPainter p(&buf);
|
QPainter p(mBufWithCounter);
|
||||||
|
|
||||||
const int width = buf.width();
|
const int width = mBufWithCounter->width();
|
||||||
const int height = buf.height();
|
const int height = mBufWithCounter->height();
|
||||||
|
|
||||||
// Draw background.
|
// Draw background.
|
||||||
{
|
{
|
||||||
|
|
@ -90,5 +105,16 @@ void MessagesCountNotifier::notifyUnreadMessagesCount (int n) {
|
||||||
p.drawText(QRect(0, 0, width, height), Qt::AlignCenter, QString::number(n));
|
p.drawText(QRect(0, 0, width, height), Qt::AlignCenter, QString::number(n));
|
||||||
}
|
}
|
||||||
|
|
||||||
sysTrayIcon->setIcon(QIcon(buf));
|
// Change counter.
|
||||||
|
mBlinkTimer->stop();
|
||||||
|
mBlinkTimer->start();
|
||||||
|
mDisplayCounter = true;
|
||||||
|
update();
|
||||||
|
}
|
||||||
|
|
||||||
|
void MessagesCountNotifier::update () {
|
||||||
|
QSystemTrayIcon *sysTrayIcon = App::getInstance()->getSystemTrayIcon();
|
||||||
|
Q_CHECK_PTR(sysTrayIcon);
|
||||||
|
sysTrayIcon->setIcon(QIcon(mDisplayCounter ? *mBufWithCounter : *mBuf));
|
||||||
|
mDisplayCounter = !mDisplayCounter;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -24,6 +24,8 @@
|
||||||
|
|
||||||
// =============================================================================
|
// =============================================================================
|
||||||
|
|
||||||
|
class QTimer;
|
||||||
|
|
||||||
class MessagesCountNotifier : public AbstractMessagesCountNotifier {
|
class MessagesCountNotifier : public AbstractMessagesCountNotifier {
|
||||||
public:
|
public:
|
||||||
MessagesCountNotifier (QObject *parent = Q_NULLPTR);
|
MessagesCountNotifier (QObject *parent = Q_NULLPTR);
|
||||||
|
|
@ -33,5 +35,10 @@ protected:
|
||||||
void notifyUnreadMessagesCount (int n) override;
|
void notifyUnreadMessagesCount (int n) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
void update ();
|
||||||
|
|
||||||
const QPixmap *mBuf = nullptr;
|
const QPixmap *mBuf = nullptr;
|
||||||
|
QPixmap *mBufWithCounter = nullptr;
|
||||||
|
QTimer *mBlinkTimer = nullptr;
|
||||||
|
bool mDisplayCounter = false;
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue