-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
mainwindow.cpp
403 lines (367 loc) · 12.7 KB
/
mainwindow.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
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
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QDebug>
#include <QString>
#include <QFileDialog>
#include <QProcess>
#include <QPropertyAnimation>
#include <shlwapi.h>
#include "Sandefine.h"
#include <HTTP.h>
bool windowsMoveOn;
bool updaterIsRunning;
bool alldone=false;
QString workPath;
MainWindow *MainWindow::mutualUi = nullptr;/*托管初始化,非常重要*/
QPropertyAnimation * progressBaranimation = nullptr;//进度条动画
QThread tprogressBaranimation;
MainWindow::MainWindow(QWidget *parent, QString pathStr)
: QMainWindow(parent)
, ui(new Ui::MainWindow)
{
//qDebug()<<(pathStr);
ui->setupUi(this);
mutualUi = this;//托管初始化,非常重要
this->setWindowFlag(Qt::FramelessWindowHint); // 无边框窗口
setAttribute(Qt::WA_TranslucentBackground, true); // 背景透明
qDebug()<<mutualUi;
//仙哥版窗口阴影
//设置窗口四周阴影 - label_Shadow实现
QGraphicsDropShadowEffect *shadow = new QGraphicsDropShadowEffect;
shadow->setOffset(0, 0);//设置向哪个方向产生阴影效果(dx,dy),特别地,(0,0)代表向四周发散
shadow->setColor(QColor(0, 0, 0, 50));//设置阴影颜色,也可以setColor(QColor(220,220,220))
shadow->setBlurRadius(15);//设定阴影的模糊半径,数值越大越模糊
ui->label_Shadow->setGraphicsEffect(shadow);
/*初始化logviewer*/
//logViewer *logUI(new logViewer);
logUI = new logViewer(this);
logUI->setModal(false);
logUI->setWindowTitle(_version);
//logUI->show();
connect(this, &MainWindow::moveLogViewer
,logUI, &logViewer::moveLogViewer);
logUI->log(modulemainWindows,"窗口初始化√",NULL);
/*进度条动画*/
progressBaranimation =new QPropertyAnimation(ui->progressBar, "value");
progressBaranimation->setDuration(100);
progressBaranimation->setStartValue(ui->progressBar->value());
progressBaranimation->setEasingCurve(QEasingCurve::InOutQuad);
/*检查传参*/
if(pathStr == nullptr)
{
logUI->log(modulemainWindows,"无传参",NULL);
MainWindow::mutualUi->changeMainPage(1);//无路径传参,显示选择路径按钮
}else{
QFileInfo info(pathStr);
workPath=info.path();
qDebug()<<"workPath:"<<workPath;
logUI->log(modulemainWindows,"传参路径:"+workPath,NULL);
threadWork(workPath);
}
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::changePBText(QString str)
{
ui->pushButton_Start->setText(str);
}
void MainWindow::changeMainPage(int mod,bool done)/*托管修改MainPage*/
{
//cout<<mod<<endl;
ui->MainPage->setCurrentIndex(mod);
if(done)
{
alldone = true;
ui->pushButton_Start->setText("打开地图");
}
//Sleep(10);
}
void MainWindow::Work_Process(int a,int b)
{
ui->progressBar->setValue((int)(100*(float(a)/float(b))));
return;
if(progressBaranimation!=nullptr)
{
int c=(int)(100*(float(a)/float(b)));
//progressBaranimation->stop();
progressBaranimation->setCurrentTime(200);
progressBaranimation->setStartValue(ui->progressBar->value());
progressBaranimation->setEndValue(c);
progressBaranimation->start(QAbstractAnimation::KeepWhenStopped);
}else{
ui->progressBar->setValue((int)(100*(float(a)/float(b))));
}
}
void MainWindow::Work_Dlnow(QString txt)
{
ui->label_Dlnow->setText(txt);
}
void MainWindow::changeProgressBarValue(int a,int b)//修改进度条进度//极容易崩溃!
{
int c=(int)(100*(float(a)/float(b)));
qDebug()<<"进度条"<<ui->progressBar->value()<<"|"<<c;
ui->progressBar->setValue(c);
Sleep(10);
}
void MainWindow::changeProgressBarColor(QString rgba, QString rgbb)
{
QString tem=QString(progressBarColor)
.arg(rgba)
.arg(rgbb)
;
ui->progressBar->setStyleSheet(tem);
//Sleep(10);
}
void MainWindow::changeMainPage0label_Text(QString str="?好像啥都没有发生?")/*托管修改MainPageTXT*/
{
ui->label_Text->setText(str);
//Sleep(10);
}
void MainWindow::mousePressEvent(QMouseEvent *e) // 鼠标按下触发记录当前鼠标位置(全局)
{
if(e->button()==Qt::LeftButton)
{
clickPos=e->pos();
//qDebug()<<e->pos();
windowsMoveOn=true;
}
}
void MainWindow::mouseMoveEvent(QMouseEvent *e) // 移动窗口(根据windowsMoveOn)
{
if(windowsMoveOn)
{
move(this->pos()+e->pos()-clickPos);
emit moveLogViewer(this->pos(),QPoint(this->width(),0));
}
}
void MainWindow::showEvent(QShowEvent *event)
{
qDebug()<<"窗口句柄"<<this->winId();
emit moveLogViewer(this->pos(),QPoint(this->width(),0));
}
void MainWindow::mouseReleaseEvent(QMouseEvent *e)//鼠标任何按键松开
{
if(windowsMoveOn){windowsMoveOn=false;}
}
void MainWindow::on_pushButton_Exit_clicked()//关闭按钮被单击
{
updaterIsRunning = false;
qDebug()<<"关闭按钮被单击";
if(ttstart)
{
disconnect(ttstart,&Start::log,0,0);
ttstart->stopWork();
}
if(logUI)logUI->close();
QApplication* app;
app->exit(0);
}
void MainWindow::keyPressEvent(QKeyEvent *e)
{
if(e->key()==Qt::Key_L && e->modifiers()==Qt::ShiftModifier)
{
if(logUI)logUI->show();
}
if(e->key()==Qt::Key_M && e->modifiers()==Qt::ShiftModifier)
{
if(md5makerUI==nullptr)
{
md5makerUI=new md5maker(this);
md5makerUI->setModal(false);
md5makerUI->setWindowTitle(_version);
}
md5makerUI->show();
}
}
bool MainWindow::nativeEvent(const QByteArray &eventType, void *message, qintptr *result)
{
if (eventType == "windows_generic_MSG")//WINDOWS环境
{
Q_UNUSED(eventType);
MSG *msg = static_cast<MSG*>(message); //类型转换
//qDebug()<<msg->message<<msg->lParam<<msg->wParam;
/*此处的结构也可用switch来代替*/
if(msg->message==WM_COPYDATA)
{
qDebug()<<"妈的终于跑通了";
COPYDATASTRUCT *data = reinterpret_cast<COPYDATASTRUCT*>(msg->lParam);
qDebug()<<"接收到的消息类型"<<data->dwData;
switch (data->dwData)
{
case 0:
//wchar
{
data->lpData;
data->cbData;
QString str;
str=QString((char*)data->lpData);
qDebug()<<"接收到的文本消息"<<str;
}
break;
case 1:
//int
break;
default:
break;
}
*result=233;
return true; //返回值为false表示该事件还会继续向上传递,被其他捕获
}else{
/*others message*/
}
}
if (eventType == "NSEvent")//MacOS环境
{}
if (eventType == "xcb_generic_event_t")//Linux环境
{}
return false;
}
void MainWindow::on_pushButton_Start_clicked() /*选择安装文件夹后file_search(多线程已完成)*/
{
//getExistingDirectory(父对象一般是this,对话框标题,对话框开始目录 一般是"./",默认是只显示目录-https://doc.qt.io/qt-5/qfiledialog.html#Option-enum);
//返回空对象则没选
//选择了目录则返回QString
logUI->log(modulemainWindows,"on_pushButton_Start_clicked()",NULL);
if(alldone)
{
logUI->log(modulemainWindows,"尝试打开空荧地图",NULL);
logUI->log(modulemainWindows,"start "+workPath+"/Map.exe",NULL);
qDebug()<<QString("start "+workPath+"/Map.exe");
QProcess process(NULL);
//QStringList argument;
QString e=workPath+"/Map.exe";
process.setProgram(e);
process.setWorkingDirectory(workPath);
if(process.startDetached())
{
qDebug()<<"start √";
logUI->log(modulemainWindows,"这句日志看不到了",NULL);
QApplication* app = nullptr;
app->exit(0);
}else{
qDebug()<<"start ×";
logUI->log(modulemainWindows,"start ×",NULL);
QMessageBox::information(this,
"出了点问题",
"请手动打开空荧地图\n能搞出这个提示San表示San也不知道怎么回事"
);
}
}else{
QString dir;
string tem;
dir = QFileDialog::getExistingDirectory
(
this,
"空荧酒馆地图安装目录(不会创建子文件夹!)",
"./",
QFileDialog::ShowDirsOnly
);
tem =dir.toStdString();
qDebug()<<"目标路径"<<dir;
logUI->log(modulemainWindows,"目标路径"+dir,NULL);
if(string(tem)==""){
logUI->log(modulemainWindows,"为空路径",NULL);
qDebug()<<"空路径";
MainWindow::changeMainPage0label_Text("?刚才发生了什么?");
}else{
workPath=dir;
threadWork(dir);
};
}
}
void MainWindow::threadWork(QString path)
{
logUI->log(modulemainWindows,"初始化",NULL);
updaterIsRunning = true;
MainWindow::startThread(path);
}
void MainWindow::startThread(QString path)
{
ui->MainPage->setCurrentIndex(0);
//startUpdate(path);
//正经多线程
if (ttstart == nullptr)
{
logUI->log(modulemainWindows,"新建线程",NULL);
ttstart = new Start(path, NULL);
}
//连接工作触发信号
//connect(Start, &Start::workError, this, &MainWindow::Work_Error);
connect(ttstart, &Start::tworkProcess
,this, &MainWindow::Work_Process);
connect(ttstart, &Start::tworkFinished
,this, &MainWindow::Work_Finished);
connect(ttstart, &Start::tworkMessageBox
,this, &MainWindow::Work_MessageBox);
//connect(this,&MainWindow::stopTwork,ttstart,&Start::stopWork,Qt::DirectConnection);
//日志窗口信号
connect(ttstart,&Start::log
,logUI,&logViewer::log
,Qt::BlockingQueuedConnection);
//ui控制信号
connect(ttstart, &Start::changeMainPage
,this, &MainWindow::changeMainPage);
connect(ttstart, &Start::changeMainPage0label_Text
,this, &MainWindow::changeMainPage0label_Text);
connect(ttstart, &Start::changeProgressBarValue
,this, &MainWindow::changeProgressBarValue);
connect(ttstart, &Start::changeProgressBarColor
,this, &MainWindow::changeProgressBarColor);
connect(ttstart, &Start::changePBText
,this, &MainWindow::changePBText);
connect(ttstart, &Start::updataDlingmag
,this, &MainWindow::updataDlingmag);
//开始工作
logUI->log(modulemainWindows,"新建定时器",NULL);
timer1 = startTimer(500);//0.5s定时器
logUI->log(modulemainWindows,"激活任务线程",NULL);
emit ttstart->tstart();
}
void MainWindow::updataDlingmag()
{
if(ttstart)MainWindow::changeMainPage0label_Text(ttstart->tNowWork());
}
void MainWindow::timerEvent(QTimerEvent *event)
{
//qDebug()<<"timerShot:"<<event->timerId();
if(event->timerId()==timer1 && ttstart->isdling)
{
QString tem;
if(ttstart)tem = ttstart->tNowWork();
//if(tem!="")ui->label_Dlnow->setText(tem);
if(tem!="")MainWindow::changeMainPage0label_Text(tem);
}
}
void MainWindow::Work_Finished(bool done)
{
logUI->log(modulemainWindows,"任务线程主动上报完成信号",NULL);
alldone=done;
logUI->log(modulemainWindows,"删除计时器",NULL);
killTimer(timer1);
}
void MainWindow::Work_MessageBox(int tag,QString title,QString txt,bool modal)
{
logUI->log(modulemainWindows,"非模态对话框 "+QString::number(tag),NULL);
QMessageBox *box=new QMessageBox(this);
switch (tag) {
case 0:
//信息
box->setIcon(QMessageBox::Information);
break;
case 1:
//错误
box->setIcon(QMessageBox::Warning);
break;
default:
printf("----------?--------\n");
}
box->setWindowTitle(title);
box->setText(txt);
box->setStandardButtons(QMessageBox::Ok);
box->setAttribute(Qt::WA_DeleteOnClose);
box->setModal(modal);//非模态
box->setTextInteractionFlags(Qt::TextSelectableByMouse);
box->show();
}