-
Notifications
You must be signed in to change notification settings - Fork 0
/
process_view.cpp
executable file
·93 lines (75 loc) · 2.2 KB
/
process_view.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
#include "process_view.hpp"
#include <QApplication>
ProcessView::ProcessView(QWidget *parent): QDialog(parent) {
setWindowModality(Qt::WindowModal);
radar = new Radar();
cancel = new QPushButton("cancel");
QObject::connect(cancel, &QPushButton::clicked, this, &ProcessView::cancelClicked);
QLabel *description = new QLabel("Program is running, please wait ......");
description->setAlignment(Qt::AlignCenter);
timeLabel = new QLabel();
timeLabel->setAlignment(Qt::AlignCenter);
timer = new QTimer();
connect(timer, &QTimer::timeout, this, &ProcessView::updateTime);
QVBoxLayout *layout = new QVBoxLayout();
layout->addWidget(radar);
layout->addWidget(description);
layout->addWidget(timeLabel);
layout->addWidget(cancel);
setLayout(layout);
// set white background
QPalette pal = palette();
pal.setColor(QPalette::Background, Qt::white);
setAutoFillBackground(true);
setPalette(pal);
setMinimumSize(50, 50);
}
void ProcessView::start() {
// Enable ask flag
closeAskFlag = true;
// Reset the timer
time.setHMS(0,0,0);
timeLabel->setText(time.toString());
// Start timers
radar->start();
timer->start(1000);
// Show this view
show();
}
void ProcessView::stop() {
// Stop timers
radar->stop();
timer->stop();
// Close this view
closeAskFlag = false;
close();
}
QString ProcessView::timeCost() {
return timeLabel->text();
}
void ProcessView::cancelClicked() {
close();
}
void ProcessView::closeEvent(QCloseEvent *event) {
if (!closeAskFlag){
event->accept();
return;
}
QMessageBox msgBox;
msgBox.setText("Are you sure to cancel this process?");
msgBox.setStandardButtons(QMessageBox::Cancel | QMessageBox::Yes);
msgBox.setDefaultButton(QMessageBox::NoButton);
msgBox.setIcon(QMessageBox::Warning);
if (msgBox.exec() == QMessageBox::Yes){
emit stopProcess();
radar->stop();
timer->stop();
event->accept();
}
else
event->ignore();
}
void ProcessView::updateTime() {
time = time.addSecs(1);
timeLabel->setText(time.toString());
}