-
Notifications
You must be signed in to change notification settings - Fork 6
/
SystemTray.cc
53 lines (40 loc) · 1.36 KB
/
SystemTray.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#include <QCoreApplication>
#include <SystemTray.hpp>
SystemTray::SystemTray(QObject *parent)
: QObject(parent)
{
auto arguments = QCoreApplication::arguments();
if(arguments.size() != 1 &&
arguments.at(1).toLower() == QString::fromUtf8("--minimized")) {
emit forceHide();
}
m_TIcon = new QSystemTrayIcon;
m_TIcon->setIcon(QIcon(QPixmap(QString::fromUtf8(":/logo.png"))));
auto menu = new QMenu;
menu->addAction(QString::fromUtf8("Show / Hide"), this, &SystemTray::showOrHide);
menu->addAction(QString::fromUtf8("Quit"), this, &SystemTray::quit);
m_CurrentContextMenu = menu;
m_TIcon->setContextMenu(menu);
connect(m_TIcon, &QSystemTrayIcon::activated, this, &SystemTray::raise);
m_TIcon->show();
}
SystemTray::~SystemTray()
{
m_TIcon->deleteLater();
m_CurrentContextMenu->deleteLater();
}
void SystemTray::raise() {
emit raiseApp();
}
void SystemTray::notify(const QString &message) {
m_TIcon->showMessage(QString::fromUtf8("AppImage Updater"), message);
}
void SystemTray::changeTrayIconToBlue() {
m_TIcon->setIcon(QIcon(QPixmap(QString::fromUtf8(":/logo_blue.png"))));
}
void SystemTray::changeTrayIconToRed() {
m_TIcon->setIcon(QIcon(QPixmap(QString::fromUtf8(":/logo_red.png"))));
}
void SystemTray::changeTrayIconDefault() {
m_TIcon->setIcon(QIcon(QPixmap(QString::fromUtf8(":/logo.png"))));
}