forked from IJHack/QtPass
-
Notifications
You must be signed in to change notification settings - Fork 0
/
trayicon.cpp
84 lines (67 loc) · 1.99 KB
/
trayicon.cpp
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#include "trayicon.h"
trayIcon::trayIcon(QMainWindow *parent)
{
parentwin = parent;
createActions();
createTrayIcon();
sysTrayIcon->setIcon(QIcon(":/artwork/icon.png"));
sysTrayIcon->show();
QObject::connect(sysTrayIcon, SIGNAL(activated(QSystemTrayIcon::ActivationReason)),
this, SLOT(iconActivated(QSystemTrayIcon::ActivationReason)));
}
void trayIcon::setVisible(bool visible)
{
if(visible == true) {
parentwin->show();
} else {
parentwin->hide();
}
}
void trayIcon::createActions()
{
// minimizeAction = new QAction(tr("Mi&nimize"), this);
// connect(minimizeAction, SIGNAL(triggered()), this, SLOT(hide()));
// maximizeAction = new QAction(tr("Ma&ximize"), this);
// connect(maximizeAction, SIGNAL(triggered()), this, SLOT(showMaximized()));
// restoreAction = new QAction(tr("&Restore"), this);
// connect(restoreAction, SIGNAL(triggered()), this, SLOT(showNormal()));
quitAction = new QAction(tr("&Quit"), this);
connect(quitAction, SIGNAL(triggered()), qApp, SLOT(quit()));
}
void trayIcon::createTrayIcon()
{
trayIconMenu = new QMenu(this);
// trayIconMenu->addAction(minimizeAction);
// trayIconMenu->addAction(maximizeAction);
// trayIconMenu->addAction(restoreAction);
// trayIconMenu->addSeparator();
trayIconMenu->addAction(quitAction);
sysTrayIcon = new QSystemTrayIcon(this);
sysTrayIcon->setContextMenu(trayIconMenu);
}
void trayIcon::showHideParent()
{
if(parentwin->isVisible() == true) {
parentwin->hide();
} else {
parentwin->show();
}
}
void trayIcon::iconActivated(QSystemTrayIcon::ActivationReason reason)
{
switch (reason) {
case QSystemTrayIcon::Trigger:
case QSystemTrayIcon::DoubleClick:
showHideParent();
break;
case QSystemTrayIcon::MiddleClick:
showMessage("test", "test msg", 1000);
break;
default:
;
}
}
void trayIcon::showMessage(QString title, QString msg, int time)
{
sysTrayIcon->showMessage(title, msg, QSystemTrayIcon::Information, time);
}