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 \
notificationsnumber.cpp \
refreshservice.cpp \
trayicon.cpp \
wsclient.cpp
HEADERS += \
@ -35,6 +36,7 @@ HEADERS += \
notificationshelper.h \
notificationsnumber.h \
refreshservice.h \
trayicon.h \
wsclient.h
FORMS += \

View File

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