-
Notifications
You must be signed in to change notification settings - Fork 0
/
testwindow.cpp
122 lines (114 loc) · 3.07 KB
/
testwindow.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
#include "testwindow.h"
#include "ui_testwindow.h"
#include <QFile>
#include <QFileDialog>
#include <QMessageBox>
#include <QDebug>
TestWindow::TestWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::TestWindow)
{
ui->setupUi(this);
initConnection();
}
void TestWindow::initConnection()
{
connect(ui->openFileBtn,SIGNAL(clicked()),this,SLOT(slotOpenFile()));
}
TestWindow::~TestWindow()
{
delete ui;
}
void TestWindow::slotOpenFile()
{
qDebug() << "slotOpen";
nameFile = QFileDialog::getOpenFileName(this,tr("Open file"));
QFile *file;
if(!nameFile.isEmpty())
{
file = new QFile(nameFile);
if(!file->open(QIODevice::ReadOnly))
{
QMessageBox::critical(this, tr("Error"), tr("Could not open file"));
return;
}
if(_dictionery.fillDictionery(*file))
{
ui->layoutTest->setEnabled(true);
updateWord();
}
file->close();
}
}
void TestWindow::setEngToUkrMode()
{
_MODE = modes::ENGTOUKR;
connect(ui->chekBtn,SIGNAL(clicked()),this,SLOT(slotChekEngToUkr()));
connect(ui->translatedWordET,SIGNAL(editingFinished()),this,SLOT(slotChekEngToUkr()));
}
void TestWindow::setUkrToEngMode()
{
_MODE = modes::UKRTOENG;
connect(ui->chekBtn,SIGNAL(clicked()),this,SLOT(slotChekUkrToEng()));
connect(ui->translatedWordET,SIGNAL(editingFinished()),this,SLOT(slotChekUkrToEng()));
}
void TestWindow::slotChekUkrToEng()
{
if(ui->translatedWordET->text()==_dictionery.getENGWord(ui->wordForTranslate->text()))
{
ui->answer->setText("Correct!");
}else
{
ui->answer->setText("Incorrect!\n Correct answer: "+
_dictionery.getENGWord(ui->wordForTranslate->text()));
}
ui->translatedWordET->clear();
QString engWord = _dictionery.getRandomPair().second;
ui->wordForTranslate->setText(engWord);
}
void TestWindow::slotChekEngToUkr()
{
if(ui->translatedWordET->text()==_dictionery.getUkrWord(ui->wordForTranslate->text()))
{
ui->answer->setText("Correct!");
if(ui->checkBox->isChecked())
delMode();
}else
{
ui->answer->setText("Incorrect!\n Correct answer: "+
_dictionery.getUkrWord(ui->wordForTranslate->text()));
}
ui->translatedWordET->clear();
QString engWord = _dictionery.getRandomPair().first;
ui->wordForTranslate->setText(engWord);
}
void TestWindow::updateWord()
{
QString engWord;
if(_MODE==modes::ENGTOUKR)
{
engWord = _dictionery.getRandomPair().first;
}else
{
engWord = _dictionery.getRandomPair().second;
}
ui->wordForTranslate->setText(engWord);
}
void TestWindow::slotClear()
{
_dictionery.clear();
ui->wordForTranslate->clear();
ui->answer->clear();
}
void TestWindow::delMode()
{
QString temp_data;
if(_MODE == modes::ENGTOUKR)
{
temp_data = ui->wordForTranslate->text();
}else
{
temp_data = _dictionery.getENGWord(ui->wordForTranslate->text());
}
_dictionery.deleteWord(temp_data);
}