-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathforyouos.cpp
More file actions
412 lines (350 loc) · 12.6 KB
/
Copy pathforyouos.cpp
File metadata and controls
412 lines (350 loc) · 12.6 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
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
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
#include "foryouos.h"
#include "ui_foryouos.h"
#include "MainWidget/mainwidget.h"
#include "ToDoListWidget/todolistwidget.h"
#include "ColorWidget/colorwidget.h"
#include "FitWidget/fitwidget.h"
foryouos::foryouos(QWidget *parent)
: QMainWindow(parent)
, ui(new Ui::foryouos)
{
ui->setupUi(this);
setWindowIcon(QIcon(":/photo/Tools.png"));
setWindowTitle("Foryouos 工具箱");
// 子窗体加入到主窗体初始化
this->AddWidget_Init();
// 使系统退出时,位于系统托盘
this->Set_App_SysTray();
// 初始化ACtion事件
this->UIACtion_Init();
// 初始化Button按钮
this->Button_Init();
// 初始化 Foryouos控制器
this->ForyouControlInit();
//首次呈现在首页
ui->MainStackWidget->setCurrentIndex(0);
// 初始化Notify
this->Notify_init();
// 初始化相关的侧边栏操作
this->Slide_Bar_Init();
#ifdef Debug
// 测试主UI页面透明度
QPropertyAnimation *animation = new QPropertyAnimation(this, "windowOpacity");
animation->setDuration(2000); // 2 seconds
animation->setStartValue(1.0); // Fully opaque
animation->setEndValue(0.0); // Fully transparent
animation->start();
#endif
}
foryouos::~foryouos()
{
// TODO:清理所有初始化的资源
if(foryoucontrol != nullptr && mthread != nullptr && mthread->isRunning())
{
mthread->quit();
mthread->wait();
mthread->exit();
delete mthread;
mthread = nullptr;
delete foryoucontrol;
foryoucontrol = nullptr;
}
delete ui;
}
void foryouos::AddWidget_Init()
{
// 初始化布局
MainWidget *mainwidget = new MainWidget(this);
ui->Main_Page_Loyout->addWidget(mainwidget);
// 初始化ToDoList布局
ToDoListWidget *todolistwidget = new ToDoListWidget(this);
ui->TODOPage_Layout->addWidget(todolistwidget);
// 初始化color widget
ColorWidget *colorwidget = new ColorWidget(this);
ui->ColorWidget_Layout->addWidget(colorwidget);
// 初始化 健康模块
FitWidget *fitwidget = new FitWidget(this);
ui->FitWidgetLayout->addWidget(fitwidget);
}
void foryouos::UIACtion_Init()
{
//TODO:初始化UIACtion
connect(ui->Mainaction, &QAction::triggered,this,[&](){ui->MainStackWidget->setCurrentIndex(0);});
connect(ui->ChineseColor, &QAction::triggered,this,[&]()
{
this->Chinese_Web_Page_Init();
ui->MainStackWidget->setCurrentIndex(1);
});
connect(ui->ToDoaction, &QAction::triggered,this,[&](){ui->MainStackWidget->setCurrentIndex(2);});
// 点击健康 管理
connect(ui->FitAction,&QAction::triggered,this,[&](){ui->MainStackWidget->setCurrentIndex(3);});
}
void foryouos::Button_Init()
{
//TODO:初始化Button
connect(ui->MainactionBtn, &QPushButton::clicked,this,[&](){ui->MainStackWidget->setCurrentIndex(0);});
connect(ui->ChineseColorBtn, &QPushButton::clicked,this,[&]()
{
this->Chinese_Web_Page_Init();
ui->MainStackWidget->setCurrentIndex(1);
});
connect(ui->ToDoactionBtn, &QPushButton::clicked,this,[&](){ui->MainStackWidget->setCurrentIndex(2);});
//初始化侧边栏
connect(ui->HideSideBtn,&QPushButton::clicked,this,&foryouos::Main_Slide_Hide_Display_Control);
}
void foryouos::Slide_Bar_Init()
{
//************* 主页面的 侧边框 **************
// QPropertyAnimation 隐藏窗体后 让其它窗体 呈现出来
MainpropertyAnimation = new QPropertyAnimation(ui->sideBar, "pos", this);
MainpropertyAnimation->setEasingCurve(QEasingCurve::InOutCubic);
MainpropertyAnimation->setDuration(1000);
//使用信号与槽机制 让隐藏与呈现动作实时呈现 t
// 连接动画值变化的信号
connect(MainpropertyAnimation, &QPropertyAnimation::valueChanged, this, [this](const QVariant &value) {
// 每次动画值改变时,更新主控件的位置
//qDebug()<<"数值发生改变";
QPoint newPos = value.toPoint();
int new_Pox_Change = newPos.x()+80;
int New_Width = 0;
if(G_Main_Slide_Status) //打开状态呢
{
// newPos.x() 从0 ~ -80 // 让其主窗体宽度逐渐变大
New_Width = G_initialRightWidgetWidth - newPos.x(); // Right_Main_Widget的宽度一直变化,会出现累加的结果,要注意此处的Bug = G_initialRightWidgetWidth - newPos.x(); // 使用初始宽度 // Right_Main_Widget的宽度一直变化,会出现累加的结果,要注意此处的Bug
// qDebug()<<"从打开到关闭"<<"newPos.x() :"<<newPos.x()<<"调整x轴:"<<new_Pox_Change<<"新宽度:"<<New_Width;
}
else
{
// newPos.x() 从 -80 ~ 0
New_Width = G_initialRightWidgetWidth - (80 + newPos.x()); //宽度逐渐变小
// qDebug()<<"从关闭到打开"<<"newPos.x() :"<<newPos.x()<<"调整x轴:"<<new_Pox_Change<<"新宽度:"<<New_Width;
}
ui->Right_Main_Widget->setGeometry(new_Pox_Change,0,New_Width, ui->Right_Main_Widget->height()); // 更新主控件位置
});
connect(MainpropertyAnimation, &QPropertyAnimation::finished, this, [this]() {
// 当动画完成后更新布局
ui->Main_Widget->update();
// 更新主控件的位置 实时更新其位置
if(G_Main_Slide_Status) //打开状态呢
{
// 打开到关闭
ui->sideBar->setVisible(false); // 隐藏 是在完成之后
G_Main_Slide_Status = false;
}
else
{
// 关闭到打开
G_Main_Slide_Status = true;
}
});
}
void foryouos::ForyouControlInit()
{
mthread = new QThread;
foryoucontrol = new ForyouControl;
connect(mthread,&QThread::started,foryoucontrol,&ForyouControl::ForyouControl_Init);
foryoucontrol->moveToThread(mthread);
mthread->start();
}
void foryouos::Chinese_Web_Page_Init()
{
}
void foryouos::Notify_init()
{
qDebug()<<"2,Notify 初始化";
notify = new NotifyManager(this);
notify->setMaxCount(5); // 设置 同时呈现 浮动提示框的数量 默认为 5
notify->setDisplayTime(5000); // 设置 浮动提示框 呈现的时间 默认值为 10000 即 10秒
notify->setAnimateTime(100); // 设置 浮动提示框 从出现到呈现,从呈现时间到消失的逐步变化的是时间 默认值为300ms
notify->setSpacing(10); // 设置 浮动提示框之前 的 间隔默认值为 10
notify->setCornerMargins(20,20); // 设置 浮动提示框 圆角 默认为 10
notify->setNotifyWndSize(300, 80); // 设置 浮动提示框的 尺寸 宽度和高度
// 设置样式
notify->setStyleSheet("#notify-background {"
"background: black;"
"}"
"#notify-title{"
"font: bold 14px 黑体;"
"color: #eeeeee;"
"}"
"#notify-body{"
"font: 12px 黑体;"
"color: #dddddd;"
"}"
"#notify-close-btn{ "
"border: 0;"
"color: #999999;"
"}"
"#notify-close-btn:hover{ "
"background: #444444;"
"}", "black");
// connect 连接 起来 如果点击了 消息通知 之后
QObject::connect(notify, &NotifyManager::notifyDetail, [&](const QVariantMap &data)
{
this->Qmessagebox_Detail(("新消息"),data.value("title").toString(),data.value("body").toString());
});
// 初始化测试
#ifdef Debug
int count = 1;
QString text = g_notifies[rand()%g_notifies.size()];
for(int i = 0;i<9;i++)
{
notify->notify(QStringLiteral("新消息%1").arg(count++), text);
}
#endif
}
void foryouos::Qmessagebox_Detail(QString title, QString log, QString details)
{
QMessageBox msgbox(QMessageBox::Information, title, log);
// 涉及Detail的详细信息
msgbox.setDetailedText(details);
// msgbox.findChild<QDialogButtonBox*>()->setMinimumWidth(500);
msgbox.exec();
}
void foryouos::Main_Slide_Hide_Display_Control()
{
G_initialRightWidgetWidth = ui->Right_Main_Widget->width();
//qDebug() << "动画开始时的 Right_Main_Widget 宽度:" << G_initialRightWidgetWidth;
//首先判断 当前侧边栏的状态
if(G_Main_Slide_Status) //打开状态呢
{
// 关闭侧边栏
MainpropertyAnimation->setStartValue(QPoint(0, 0));
MainpropertyAnimation->setEndValue(QPoint(-ui->sideBar->width(), 0));
}
else
{
//打开侧边栏
ui->sideBar->setVisible(true); // 打开要立即
MainpropertyAnimation->setStartValue(QPoint(-ui->sideBar->width(), 0)); //从负左边即进入隐藏区域
MainpropertyAnimation->setEndValue(QPoint(0, 0));
}
//开启侧边栏移动
MainpropertyAnimation->start();
}
void foryouos::Set_App_SysTray()
{
// 判断系统托盘是否支持
if(QSystemTrayIcon::isSystemTrayAvailable()){
if(menu == nullptr)
{
menu = new QMenu(this);
}
QIcon icon(":/photo/Tools.png");
SysIcon = new QSystemTrayIcon(this);
SysIcon->setIcon(icon);
SysIcon->setToolTip("Foryou工具集");
min = new QAction("最小化",this);
QIcon icon_min(":/Tray/photo/TrayMini.png");
min->setIcon(icon_min);
connect(min,&QAction::triggered,this,&QMainWindow::hide);
QIcon icon_max(":/Tray/photo/TrayMax.png");
max = new QAction("最大化",this);
max->setIcon(icon_max);
connect(max,&QAction::triggered,this,&QMainWindow::showMaximized);
restor = new QAction("恢复窗体",this);
QIcon icon_restor(":/Tray/photo/TrayShow.png");
restor->setIcon(icon_restor);
connect(restor,&QAction::triggered,this,&QMainWindow::showNormal);
quit = new QAction("退出",this);
QIcon icon_quit(":/Tray/photo/TrayExit.png");
quit->setIcon(icon_quit);
connect(quit,&QAction::triggered,qApp,&QApplication::quit);
//当用户点击此系统托盘之后 会触发的事件
connect(SysIcon,&QSystemTrayIcon::activated,this,&foryouos::on_activateSysTrayIcon);
menu->addAction(min);
menu->addAction(max);
menu->addAction(restor);
menu->addSeparator(); //添加分割符
menu->addAction(quit);
SysIcon->setContextMenu(menu); //添加菜单
SysIcon->show();
this->Set_SysTray_Visible(true);
// 启动定时器
// m_iTimer = startTimer(500);
}else
{
qDebug()<<"系统通盘不可用";
}
}
void foryouos::on_activateSysTrayIcon(QSystemTrayIcon::ActivationReason reason)
{
switch (reason){
case QSystemTrayIcon::Trigger: //系统托盘被点击
{
break;
}
case QSystemTrayIcon::DoubleClick: //双击 --> 呈现窗体
{
this->show();
break;
}
case QSystemTrayIcon::MiddleClick: // 中间按钮
{
break;
}
case QSystemTrayIcon::Context: // 请求系统托盘的上下文菜单 鼠标右键,会呈现Menu菜单
{
// this->showTrayMessage();
break;
}
case QSystemTrayIcon::Unknown:
{
qDebug()<<"未知的系统托盘";
break;
}
default:
break;
}
}
void foryouos::Set_SysTray_Visible(bool visible)
{
if(SysIcon!=nullptr)
{
SysIcon->setVisible(visible);
}
}
void foryouos::closeEvent(QCloseEvent *event)
{
try {
if(SysIcon->isVisible())
{
this->hide();
event->ignore();
}
else
{
event->accept();
}
} catch (_exception e) {
qDebug()<<"foryouos函数 closeEvent 异常"<<e.name;
}
}
void foryouos::timerEvent(QTimerEvent *event)
{
if(SysIcon !=nullptr)
{
this->Set_Tray_twinkle();
}
}
void foryouos::showTrayMessage()
{
QSystemTrayIcon::MessageIcon msgIcon = QSystemTrayIcon::Information;
SysIcon->showMessage("托盘测试", "托盘测试信息", msgIcon,
5 * 1000);
}
// 实现 系统 托盘 闪烁 功能
void foryouos::Set_Tray_twinkle()
{
static bool twinkle_state = true;
if(twinkle_state)
{
SysIcon->setIcon(QIcon(":/null.png"));
twinkle_state = false;
}
else
{
SysIcon->setIcon(QIcon(":/photo/Tools.png"));
twinkle_state = true;
}
}