ISSUE-8 System tray is fully rewritten in C++ due to a bug in QT: https://bugreports.qt.io/browse/QTBUG-69226 #15
Merged
blago
merged 1 commits from ISSUE-8
into master
4 years ago
5 changed files with 102 additions and 23 deletions
@ -0,0 +1,47 @@ |
|||||
|
#include "tangratray.h" |
||||
|
|
||||
|
TangraTray::TangraTray(QObject *parent) : QObject(parent) |
||||
|
{ |
||||
|
|
||||
|
QMenu *trayIconMenu = new QMenu(); |
||||
|
|
||||
|
QAction * viewWindowAction = new QAction(tr("Показване"), this); |
||||
|
QAction * quitAction = new QAction(tr("Изход"), this); |
||||
|
|
||||
|
connect(viewWindowAction, &QAction::triggered, this, &TangraTray::signalIconActivated); |
||||
|
connect(quitAction, &QAction::triggered, this, &TangraTray::signalQuit); |
||||
|
|
||||
|
trayIconMenu->addAction(viewWindowAction); |
||||
|
trayIconMenu->addAction(quitAction); |
||||
|
|
||||
|
trayIcon = new QSystemTrayIcon(); |
||||
|
trayIcon->setContextMenu(trayIconMenu); |
||||
|
setTrayIcon(":Resources/tangra.ico"); |
||||
|
|
||||
|
trayIcon->show(); |
||||
|
|
||||
|
connect(trayIcon, SIGNAL(activated(QSystemTrayIcon::ActivationReason)), |
||||
|
this, SLOT(iconActivated(QSystemTrayIcon::ActivationReason))); |
||||
|
} |
||||
|
|
||||
|
void TangraTray::iconActivated(QSystemTrayIcon::ActivationReason reason) |
||||
|
{ |
||||
|
switch (reason){ |
||||
|
case QSystemTrayIcon::Trigger: |
||||
|
emit signalIconActivated(); |
||||
|
break; |
||||
|
default: |
||||
|
break; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
void TangraTray::setTrayIcon(QString image) |
||||
|
{ |
||||
|
QIcon icon = QIcon(image), tr("Icon"); |
||||
|
trayIcon->setIcon(icon); |
||||
|
} |
||||
|
|
||||
|
void TangraTray::hideIconTray() |
||||
|
{ |
||||
|
trayIcon->hide(); |
||||
|
} |
@ -0,0 +1,37 @@ |
|||||
|
#ifndef TANGRATRAY_H |
||||
|
#define TANGRATRAY_H |
||||
|
|
||||
|
#include <QObject> |
||||
|
#include <QAction> |
||||
|
#include <QSystemTrayIcon> |
||||
|
#include <QMenu> |
||||
|
#include <QApplication> |
||||
|
|
||||
|
class TangraTray : public QObject |
||||
|
{ |
||||
|
Q_OBJECT |
||||
|
public: |
||||
|
explicit TangraTray(QObject *parent = 0); |
||||
|
|
||||
|
signals: |
||||
|
void signalIconActivated(); |
||||
|
void signalShow(); |
||||
|
void signalQuit(); |
||||
|
|
||||
|
private slots: |
||||
|
/* The slot that will accept the signal from the event click on the application icon in the system tray
|
||||
|
*/ |
||||
|
void iconActivated(QSystemTrayIcon::ActivationReason reason); |
||||
|
|
||||
|
public slots: |
||||
|
void hideIconTray(); |
||||
|
|
||||
|
private: |
||||
|
/* Declare the object of future applications for the tray icon*/ |
||||
|
QSystemTrayIcon * trayIcon; |
||||
|
void setTrayIcon(QString image); |
||||
|
void createTrayIcon(); |
||||
|
}; |
||||
|
|
||||
|
#endif // SYSTEMTRAY_H
|
||||
|
|
Loading…
Reference in new issue