From bf1ee550e3f818cc44be157600af23f7de1be523 Mon Sep 17 00:00:00 2001 From: Pierre HUBERT Date: Sat, 13 Jun 2020 14:39:34 +0200 Subject: [PATCH] Start to build tray icons --- ComunicWatcher.pro | 2 ++ refreshservice.h | 2 ++ trayicon.cpp | 26 ++++++++++++++++++++++++++ trayicon.h | 28 ++++++++++++++++++++++++++++ 4 files changed, 58 insertions(+) create mode 100644 trayicon.cpp create mode 100644 trayicon.h diff --git a/ComunicWatcher.pro b/ComunicWatcher.pro index 538f972..c2e9135 100644 --- a/ComunicWatcher.pro +++ b/ComunicWatcher.pro @@ -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 += \ diff --git a/refreshservice.h b/refreshservice.h index 0d56692..2f2bea4 100644 --- a/refreshservice.h +++ b/refreshservice.h @@ -7,6 +7,7 @@ #pragma once #include "notificationshelper.h" +#include "trayicon.h" #include "wsclient.h" #include @@ -30,4 +31,5 @@ private: static RefreshService *svc; WsClient mWsClient; NotificationsHelper mNotifsHelper; + TrayIcon mTrayIcon; }; diff --git a/trayicon.cpp b/trayicon.cpp new file mode 100644 index 0000000..cafad97 --- /dev/null +++ b/trayicon.cpp @@ -0,0 +1,26 @@ +#include +#include + +#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(); +} diff --git a/trayicon.h b/trayicon.h new file mode 100644 index 0000000..addd1ab --- /dev/null +++ b/trayicon.h @@ -0,0 +1,28 @@ +/** + * Tray icon + * + * @author Pierre Hubert + */ + +#pragma once + +#include +#include + +class TrayIcon : public QObject +{ + Q_OBJECT +public: + explicit TrayIcon(QObject *parent = nullptr); + ~TrayIcon(); + +signals: + +private slots: + void onQuit(); + +private: + QMenu *mMenu; + QSystemTrayIcon mTrayIcon; +}; +