-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSimSystemTray.cpp
More file actions
79 lines (67 loc) · 2.67 KB
/
Copy pathSimSystemTray.cpp
File metadata and controls
79 lines (67 loc) · 2.67 KB
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
#include "SimSystemTray.h"
#include <QEvent>
#include <QVBoxLayout>
#include <QPainter>
#include <QIcon>
#include <QApplication>
#include <QFile>
#include <QTextStream>
SimSystemTray::SimSystemTray(QWidget *parent):QSystemTrayIcon(parent){
trayMenu=new QMenu();
QFile menuStyleFile(":/StyleSheet/img/StyleSheet/SimStyleSheet.qss");
if (!menuStyleFile.open(QIODevice::ReadOnly | QIODevice::Text))
return;
QTextStream fileData(&menuStyleFile);
QString menuStyleStr=fileData.readAll();
trayMenu->setStyleSheet(menuStyleStr);
this->setIcon(QIcon("://img/qq.ico"));
createTopWidget();
createContextMenu();
this->setContextMenu(trayMenu);
//定义信号连接
connect(restoreAction,SIGNAL(toggled(bool)),this,SIGNAL(restore()));
connect(settingAction,SIGNAL(triggered(bool)),this,SIGNAL(setting()));
connect(exitAction,SIGNAL(triggered(bool)),qApp,SLOT(quit()));
connect(selfStartAction,SIGNAL(triggered()),this,SIGNAL(selfStart()));
}
//重新绘制顶层部件
bool SimSystemTray::eventFilter(QObject * target, QEvent * e){
if(target==topWidget&&e->type()==QEvent::Paint){
QPainter painter(topWidget);
painter.setPen(Qt::NoPen);
painter.setBrush(QColor(42, 120, 192));
painter.drawRect(topWidget->rect());
}
return QSystemTrayIcon::eventFilter(target,e);
}
void SimSystemTray::createTopWidget(){
topWidget=new QWidget();
topWidgetAction=new QWidgetAction(this->trayMenu);
topLabel=new QLabel("Secure Instant Message");
QVBoxLayout* m_topLayout = new QVBoxLayout();
m_topLayout->addWidget(topLabel, 0, Qt::AlignLeft|Qt::AlignVCenter);
topWidget->setLayout(m_topLayout);
topWidget->installEventFilter(this);
topWidgetAction->setDefaultWidget(topWidget);
trayMenu->addAction(topWidgetAction);
trayMenu->addSeparator();
}
void SimSystemTray::createContextMenu(){
selfStartAction=new QAction("开机启动",this);
selfStartAction->setIcon(QIcon(":/SIMSystemTray/img/SystemTray/SelfStart.png"));
restoreAction=new QAction("打开主面板",this);
restoreAction->setIcon(QIcon(":/SIMSystemTray/img/SystemTray/Restore.png"));
settingAction=new QAction("设置",this);
settingAction->setIcon(QIcon(":/SIMSystemTray/img/SystemTray/Setting.png"));
exitAction=new QAction("退出",this);
exitAction->setIcon(QIcon(":/SIMSystemTray/img/SystemTray/Exit.png"));
trayMenu->addAction(selfStartAction);
trayMenu->addSeparator();
trayMenu->addAction(restoreAction);
trayMenu->addAction(settingAction);
trayMenu->addSeparator();
trayMenu->addAction(exitAction);
}
void SimSystemTray::showMyself(){
this->show();
}