-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwait4answerdialog.cpp
117 lines (94 loc) · 2.42 KB
/
wait4answerdialog.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
#include "wait4answerdialog.h"
#include "ui_wait4answerdialog.h"
#include <QTimer>
#include <QtDebug>
Wait4AnswerDialog::Wait4AnswerDialog(int defH, QWidget *parent) :
QDialog(parent),
ui(new Ui::Wait4AnswerDialog)
{
ui->setupUi(this);
maxH = defH * 3;
QTimer *timer = new QTimer;
timer->setInterval(1000);
connect(timer, SIGNAL(timeout()), this, SLOT(onTimerTo()) );
connect(this,SIGNAL(stopTimer()), timer,SLOT(stop()) );
connect(this, SIGNAL(startTimr()), timer, SLOT(start()) );
connect(this,SIGNAL(rejected()), timer, SLOT(stop()) );
}
Wait4AnswerDialog::~Wait4AnswerDialog()
{
delete ui;
}
void Wait4AnswerDialog::showAnimation(int count)
{
ui->progressBar->hide();
ui->progressBar->setValue(0);
rotateCounter = 0;
emit stopTimer();
defCount = count;
counter = count;
counter2 = 0;
ui->lblWait->setText(tr("Wait %1 s. %2").arg(QString::number(counter) ).arg(rotateStr()));
ui->lblRotate->setVisible(true);
ui->pushButton->setEnabled(true);
emit startTimr();
this->exec();
}
void Wait4AnswerDialog::hideAnimation()
{
emit stopTimer();
if(isVisible())
reject();
else
setVisible(false);
QTimer::singleShot(5, this, SLOT(reject()) );
QTimer::singleShot(5, this, SLOT(close()) );
}
void Wait4AnswerDialog::uploadProgress(int val, QString txt)
{
if(val > 100)
val = 100;
emit stopTimer();
counter++;
if(!isVisible())
this->exec();
if(!ui->progressBar->isVisible())
ui->progressBar->setVisible(true);
ui->progressBar->setValue(val);
ui->lblWait->setText(txt + rotateStr());
}
void Wait4AnswerDialog::resetCounter()
{
counter = defCount;
}
void Wait4AnswerDialog::onTimerTo()
{
counter2++;
if(counter2 > 0){
counter--;
if(counter < 1){
if(!isVisible())
return;
hideAnimation();
emit noAnswerFromDev();
}
counter2 = 0;
ui->lblWait->setText(tr("Wait %1 s. %2").arg(QString::number(counter) ).arg(rotateStr()));
}
}
QString Wait4AnswerDialog::rotateStr()
{
rotateCounter++;
switch( rotateCounter ){
case 1: return " / ";
case 2: return " - ";
case 3: return " \\ ";
default: rotateCounter = 0; return " | ";
}
return "";
}
void Wait4AnswerDialog::on_pushButton_clicked()
{
ui->pushButton->setEnabled(false);
emit stopNow();
}