You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
48 lines
1.2 KiB
48 lines
1.2 KiB
4 years ago
|
#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();
|
||
|
}
|