-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbasepage.cpp
175 lines (156 loc) · 3.91 KB
/
basepage.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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
#include "basepage.h"
#include "ui_basepage.h"
BasePage::BasePage(QWidget *parent) :
QWidget(parent),
ui(new Ui::BasePage)
{
ui->setupUi(this);
this->setWindowTitle("BasePage");
this->setWindowIcon(QIcon(":/icons/Res/icons/WindowIcon.png"));
this->setWindowFlags(Qt::FramelessWindowHint | Qt::WindowMinimizeButtonHint);
this->setAttribute(Qt::WA_TranslucentBackground, true);
//绘制窗口阴影
QGraphicsDropShadowEffect *shadow = new QGraphicsDropShadowEffect(this);
shadow->setOffset(0, 0);
shadow->setColor(QColor(102,102,102));
shadow->setBlurRadius(20);
ui->BaseFrame->setGraphicsEffect(shadow);
//默认隐藏大标题
ui->label_ApplicationLarge->hide();
}
BasePage::~BasePage()
{
delete ui;
}
//系统托盘常驻
void BasePage::initPage()
{
systemtrayicon = new QSystemTrayIcon(this);
QIcon icon = QIcon(":/icons/Res/icons/SystemTrayIcon.png");
systemtrayicon->setIcon(icon);
systemtrayicon->setToolTip(QObject::tr("PWKeeper"));
createActions();
createMenu();
systemtrayicon->show();
connect(systemtrayicon,SIGNAL(activated(QSystemTrayIcon::ActivationReason)),this,SLOT(on_activatedSysTrayIcon(QSystemTrayIcon::ActivationReason)));
isInt = 1;
}
//从系统托盘移除
void BasePage::recyclePage()
{
delete systemtrayicon;
systemtrayicon = NULL;
isInt = 0;
}
//设置窗口大标题
void BasePage::largeTitle()
{
ui->label_ApplicationSmall->hide();
ui->label_ApplicationLarge->show();
}
//最小化按钮槽函数
void BasePage::on_toolButton_Minimize_clicked()
{
showMinimized();
}
//关闭按钮槽函数
void BasePage::on_toolButton_Quit_clicked()
{
if(closeDirectly)
{
if(isInt)
{
recyclePage();
}
//qDebug()<<"exit";
exit(0);
}
else
{
if(isInt)
{
this->hide();
}
else
{
this->close();
}
}
}
//自定义标题栏
//记录窗口坐标
static QPoint last(0,0);
//标题栏高度
const int TITLE_HEIGHT = 50;
//窗口拖动
void BasePage::mousePressEvent(QMouseEvent *event)
{
if(event->position().y()<TITLE_HEIGHT)
{
last = event->globalPosition().toPoint();
}
}
void BasePage::mouseMoveEvent(QMouseEvent *event)
{
if(event->position().y()<TITLE_HEIGHT)
{
int dx = event->globalPosition().x() - last.x();
int dy = event->globalPosition().y() - last.y();
last = event->globalPosition().toPoint();
this->move(this->x()+dx,this->y()+dy);
}
}
void BasePage::mouseReleaseEvent(QMouseEvent *event)
{
if(event->position().y()<TITLE_HEIGHT)
{
int dx = event->globalPosition().x() - last.x();
int dy = event->globalPosition().y() - last.y();
this->move(this->x()+dx,this->y()+dy);
}
}
//托盘事件
void BasePage::on_activatedSysTrayIcon(QSystemTrayIcon::ActivationReason reason)
{
switch(reason)
{
case QSystemTrayIcon::Trigger:
break;
case QSystemTrayIcon::DoubleClick:
this->show();
break;
default:
break;
}
}
//托盘菜单
void BasePage::createActions()
{
mShowMainAction = new QAction(QObject::tr("打开PWKeeper"),this);
connect(mShowMainAction,SIGNAL(triggered()),this,SLOT(on_showMainAction()));
mExitAppAction = new QAction(QObject::tr("退出"),this);
connect(mExitAppAction,SIGNAL(triggered()),this,SLOT(on_exitAppAction()));
}
void BasePage::createMenu()
{
mMenu = new QMenu(this);
mMenu->addAction(mShowMainAction);
mMenu->addSeparator();
mMenu->addAction(mExitAppAction);
systemtrayicon->setContextMenu(mMenu);
}
void BasePage::on_showMainAction()
{
this->show();
}
void BasePage::on_exitAppAction()
{
delete systemtrayicon;
systemtrayicon=NULL;
exit(0);
}
//切换关闭按钮功能
void BasePage::refreshCloseDirectly(bool tclose)
{
closeDirectly = tclose;
}