Start to build tray icons

This commit is contained in:
Pierre HUBERT 2020-06-13 14:39:34 +02:00
parent 2a536d57ed
commit bf1ee550e3
4 changed files with 58 additions and 0 deletions

View File

@ -23,6 +23,7 @@ SOURCES += \
notificationshelper.cpp \ notificationshelper.cpp \
notificationsnumber.cpp \ notificationsnumber.cpp \
refreshservice.cpp \ refreshservice.cpp \
trayicon.cpp \
wsclient.cpp wsclient.cpp
HEADERS += \ HEADERS += \
@ -35,6 +36,7 @@ HEADERS += \
notificationshelper.h \ notificationshelper.h \
notificationsnumber.h \ notificationsnumber.h \
refreshservice.h \ refreshservice.h \
trayicon.h \
wsclient.h wsclient.h
FORMS += \ FORMS += \

View File

@ -7,6 +7,7 @@
#pragma once #pragma once
#include "notificationshelper.h" #include "notificationshelper.h"
#include "trayicon.h"
#include "wsclient.h" #include "wsclient.h"
#include <QObject> #include <QObject>
@ -30,4 +31,5 @@ private:
static RefreshService *svc; static RefreshService *svc;
WsClient mWsClient; WsClient mWsClient;
NotificationsHelper mNotifsHelper; NotificationsHelper mNotifsHelper;
TrayIcon mTrayIcon;
}; };

26
trayicon.cpp Normal file
View File

@ -0,0 +1,26 @@
#include <QApplication>
#include <QMenu>
#include "trayicon.h"
TrayIcon::TrayIcon(QObject *parent) : QObject(parent)
{
mMenu = new QMenu;
QAction *closeAction = mMenu->addAction(tr("Quit"));
connect(closeAction, &QAction::triggered, this, &TrayIcon::onQuit);
mTrayIcon.setIcon(QIcon(":/logo_large.png"));
mTrayIcon.setContextMenu(mMenu);
mTrayIcon.show();
}
TrayIcon::~TrayIcon()
{
mMenu->deleteLater();
}
void TrayIcon::onQuit()
{
QApplication::exit();
}

28
trayicon.h Normal file
View File

@ -0,0 +1,28 @@
/**
* Tray icon
*
* @author Pierre Hubert
*/
#pragma once
#include <QObject>
#include <QSystemTrayIcon>
class TrayIcon : public QObject
{
Q_OBJECT
public:
explicit TrayIcon(QObject *parent = nullptr);
~TrayIcon();
signals:
private slots:
void onQuit();
private:
QMenu *mMenu;
QSystemTrayIcon mTrayIcon;
};