This repository has been archived by the owner on May 12, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtrayiconwidget.cpp
117 lines (92 loc) · 2.86 KB
/
trayiconwidget.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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
#include "trayiconwidget.h"
TrayIconWidget::TrayIconWidget(QWidget *parent) :
QWidget(parent,Qt::FramelessWindowHint)
{
#ifndef QT_NO_DEBUG
qDebug()<<"Debug Version Running...";
#endif
this->setAttribute(Qt::WA_TranslucentBackground,true);
this->setWindowFlag(Qt::Tool);
this->setAcceptDrops(true);
this->move(0,0);
this->info = new infoForm();
this->isShowing = true;
createTrayIcon();
showSpirits();
}
void TrayIconWidget::createTrayIcon(){
createTrayMenu();
if(!QSystemTrayIcon::isSystemTrayAvailable())return;
trayIcon = new QSystemTrayIcon(this);
QIcon icon(":/image/ghost_icon");
trayIcon->setIcon(icon);
trayIcon->setToolTip("Despirit");
trayIcon->setContextMenu(trayMenu);
connect(trayIcon , SIGNAL(activated(QSystemTrayIcon::ActivationReason)), this, SLOT(iconIsActived(QSystemTrayIcon::ActivationReason)));
trayIcon->show();
}
void TrayIconWidget::createTrayMenu(){
addSpiritAction = new QAction("New Spirit",this);
quitAction = new QAction("Quit",this);
infoAction = new QAction("@Croxx");
connect(addSpiritAction,SIGNAL(triggered()),this,SLOT(addSpiritSlot()));
connect(quitAction,SIGNAL(triggered()),qApp,SLOT(quit()));
connect(infoAction,SIGNAL(triggered()),this,SLOT(showInfo()));
trayMenu = new QMenu((QWidget*)QApplication::desktop());
trayMenu->addAction(addSpiritAction);
trayMenu->addSeparator();
trayMenu->addAction(infoAction);
trayMenu->addSeparator();
trayMenu->addAction(quitAction);
}
void TrayIconWidget::addSpiritSlot(){
int id = SettingsUtils::addSpirit();
showFloatingWidget(id);
}
void TrayIconWidget::showFloatingWidget(int id){
QPoint pos = SettingsUtils::getPosition(id);
FloatingWidget *spirit = new FloatingWidget(id);
spirit->move(pos);
spirit->show();
spirits.append(spirit);
}
void TrayIconWidget::showSpirits(){
QList<int> ids = SettingsUtils::getSpiritIds();
for(int i=0;i<ids.size();i++){
showFloatingWidget(ids.at(i));
}
}
void TrayIconWidget::hideAllSpirits(){
this->isShowing = false;
for(int i=0;i<spirits.size();i++){
FloatingWidget *spirit = spirits.at(i);
spirit->hide();
}
}
void TrayIconWidget::showAllSpirits(){
this->isShowing = true;
for(int i=0;i<spirits.size();i++){
FloatingWidget *spirit = spirits.at(i);
if(spirit->inuse){
qDebug()<<"show :"<<spirit->id;
spirit->showNormal();
spirit->raise();
spirit->activateWindow();
}
}
}
void TrayIconWidget::showInfo(){
this->info->show();
}
void TrayIconWidget::iconIsActived(QSystemTrayIcon::ActivationReason reason){
switch(reason)
{
case QSystemTrayIcon::DoubleClick:
if(this->isShowing){
hideAllSpirits();
}else{
showAllSpirits();
}
break;
}
}