/
testdialog.cpp
105 lines (84 loc) · 2.21 KB
/
testdialog.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
#include "testdialog.h"
#include "ui_testdialog.h"
#include <QDebug>
TestDialog::TestDialog(QVector<QString> vGlobal, bool flag, QWidget *parent) :
QDialog(parent),
ui(new Ui::TestDialog)
{
dGlobal = vGlobal;
ui->setupUi(this);
siteA = flag;
testSize = dGlobal.size()/2;
startTest();
this->setFixedSize(this->width(),this->height());
}
TestDialog::~TestDialog()
{
delete ui;
}
void TestDialog::startTest()
{
ui->lblCorrectWord->setText("");
ui->lblCorrectCount->setText("Correct: 0" );
ui->lblWrongCount->setText("Wrong: 0" );
ui->btnNext->setEnabled(true);
ui->edtAnswer->setEnabled(true);
correct = 0;
wrong = 0;
count = 0;
testCount = 1;
ui->lblCount->setText("Word: 1/" + QString::number(testSize));
showQuestion();
}
void TestDialog::checkAnswer(QString str){
QString answer = ui->edtAnswer->text();
int x = QString::compare(str, answer, Qt::CaseInsensitive);
if(x == 0)
{
++correct;
ui->lblCorrectCount->setText("Correct: " + QString::number(correct));
}
else
{
++wrong;
ui->lblWrongCount->setText("Wrong: " + QString::number(wrong));
ui->lblCorrectWord->setText(str);
ui->lblCorrectWord->setStyleSheet("QLabel { color : red; }");
}
ui->edtAnswer->clear();
}
void TestDialog::on_btnNext_clicked()
{
if(siteA == true)
checkAnswer(dGlobal.at(count+1));
else
checkAnswer(dGlobal.at(count));
if(testCount != testSize)
{
testCount++;
count = count+2;
ui->lblCount->setText("Word: " + QString::number(testCount) + "/" + QString::number(testSize));
showQuestion();
}
else
{
ui->btnNext->setEnabled(false);
ui->edtAnswer->setEnabled(false);
}
}
void TestDialog::showQuestion(){
if(siteA == true)
{
ui->lblQuestion->setText(dGlobal.at(count));
this->setWindowTitle("Site A");
}
else
{
ui->lblQuestion->setText(dGlobal.at(count+1));
this->setWindowTitle("Site B");
}
}
void TestDialog::on_pushButton_clicked()
{
startTest();
}