mirror of
https://gitlab.com/comunic/comunicwatcher
synced 2024-12-25 04:58:57 +00:00
Automatically change tray icon
This commit is contained in:
parent
2635e92b8d
commit
1cbae38ee5
31
trayicon.cpp
31
trayicon.cpp
@ -1,5 +1,7 @@
|
||||
#include <QApplication>
|
||||
#include <QMenu>
|
||||
#include <QPixmap>
|
||||
#include <QPainter>
|
||||
|
||||
#include "trayicon.h"
|
||||
|
||||
@ -27,6 +29,7 @@ void TrayIcon::onNewNumber(const NotificationsNumber &number)
|
||||
}
|
||||
|
||||
mOldNumber = number.sum();
|
||||
refreshIcon();
|
||||
}
|
||||
|
||||
void TrayIcon::onQuit()
|
||||
@ -58,3 +61,31 @@ void TrayIcon::showNotification(const NotificationsNumber &n)
|
||||
|
||||
mTrayIcon.showMessage(tr("Comunic"), msg, QIcon(":/logo_large.png"));
|
||||
}
|
||||
|
||||
void TrayIcon::refreshIcon()
|
||||
{
|
||||
if(mOldNumber == 0) {
|
||||
mTrayIcon.setIcon(QIcon(":/logo_large.png"));
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
QPixmap bm = QPixmap::fromImage(QImage(":/logo_large.png"), Qt::ColorOnly);
|
||||
|
||||
QPainter engine(&bm);
|
||||
QColor red(255, 0, 0, 255);
|
||||
QRect r(QPoint(bm.width()/3, 0), QPoint(bm.width(), bm.height() - bm.height()/3));
|
||||
engine.fillRect(r, red);
|
||||
|
||||
engine.setPen(QColor(255,255,255,255));
|
||||
|
||||
QFont f = engine.font();
|
||||
f.setFamily("Arial");
|
||||
f.setPointSize(bm.width()/1.8);
|
||||
f.setBold(true);
|
||||
engine.setFont(f);
|
||||
|
||||
engine.drawText(r, Qt::AlignCenter, QString::number(mOldNumber));
|
||||
|
||||
mTrayIcon.setIcon(QIcon(bm));
|
||||
}
|
||||
|
@ -35,6 +35,11 @@ private:
|
||||
*/
|
||||
void showNotification(const NotificationsNumber &n);
|
||||
|
||||
/**
|
||||
* Refresh the icon shown in the taskbar
|
||||
*/
|
||||
void refreshIcon();
|
||||
|
||||
// Class members
|
||||
QMenu *mMenu;
|
||||
QSystemTrayIcon mTrayIcon;
|
||||
|
Loading…
Reference in New Issue
Block a user