diff --git a/trayicon.cpp b/trayicon.cpp index 7e3b081..fbc3638 100644 --- a/trayicon.cpp +++ b/trayicon.cpp @@ -1,5 +1,7 @@ #include #include +#include +#include #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)); +} diff --git a/trayicon.h b/trayicon.h index 7363294..fb3e28f 100644 --- a/trayicon.h +++ b/trayicon.h @@ -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;