-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathabstractcipherview.cpp
More file actions
131 lines (119 loc) · 3.21 KB
/
abstractcipherview.cpp
File metadata and controls
131 lines (119 loc) · 3.21 KB
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
#include "abstractcipherview.h"
#include "ui_abstractcipherview.h"
AbstractCipherView::AbstractCipherView(QWidget *parent) :
QWidget(parent),
ui(new Ui::AbstractCipherView)
{
ui->setupUi(this);
CELL_SIZE = 30;
m_cellRect.setX(10);
m_cellRect.setY(10);
m_cellRect.setWidth(CELL_SIZE);
m_cellRect.setHeight(CELL_SIZE);
ui->backButton->setEnabled(false);
m_draw = false;
connect(ui->nextButton, SIGNAL(clicked()), this, SLOT(onNextButtonClick()));
connect(ui->backButton, SIGNAL(clicked()), this, SLOT(onBackButtonClick()));
connect(&m_timer, SIGNAL(timeout()), this, SLOT(onNextButtonClick()));
}
AbstractCipherView::~AbstractCipherView()
{
delete ui;
}
void AbstractCipherView::resetChars()
{
m_currentChar = 0;
}
void AbstractCipherView::highlightChar(int index)
{
QString text = m_text;
text.insert(index + m_token, "</font>");
text.insert(index, "<font color = \"green\">");
ui->inTextEdit->setText(text);
text = m_encryptedText;
text.insert(index + m_token, "</font>");
text.insert(index, "<font color = \"red\">");
ui->outTextEdit->setText(text);
}
void AbstractCipherView::setResults(QString inText, QString outText)
{
m_text = inText;
m_encryptedText = outText;
if(m_text.length() == 0 || m_text.length() == m_token)
{
ui->nextButton->setEnabled(false);
ui->backButton->setEnabled(false);
ui->autoButton->setEnabled(false);
if(m_text.length())
m_draw = true;
else
m_draw = false;
}
else
{
ui->nextButton->setEnabled(true);
ui->backButton->setEnabled(false);
ui->autoButton->setEnabled(true);
m_draw = true;
}
ui->inTextEdit->setText(inText);
ui->outTextEdit->setText(outText);
if(m_isShow)
show();
resetChars();
update();
}
void AbstractCipherView::setResults(QString alphabet, QString inText, QString outText)
{
m_table1 = alphabet;
setResults(inText, outText);
}
void AbstractCipherView::setResults(QString table1, QString table2, QString inText, QString outText)
{
m_table2 = table2;
setResults(table1, inText, outText);
}
void AbstractCipherView::setResults(QVector<int> square, QString inText, QString outText)
{
m_square = square;
setResults(inText, outText);
}
void AbstractCipherView::setIsShow(int a)
{
m_isShow = a;
}
void AbstractCipherView::onNextButtonClick()
{
m_currentChar += m_token;
ui->backButton->setEnabled(true);
if(m_currentChar + m_token / 2 == m_text.length() - 1)
{
ui->nextButton->setEnabled(false);
if(m_timer.isActive())
on_autoButton_clicked();
ui->autoButton->setEnabled(false);
}
update();
}
void AbstractCipherView::onBackButtonClick()
{
m_currentChar -= m_token;
if(m_currentChar == 0)
ui->backButton->setEnabled(false);
ui->nextButton->setEnabled(true);
ui->autoButton->setEnabled(true);
update();
}
void AbstractCipherView::on_autoButton_clicked()
{
if(m_timer.isActive())
{
m_timer.stop();
ui->autoButton->setText(tr("Auto"));
}
else
{
m_timer.start(CryptoHelper::interval);
ui->autoButton->setText(tr("Stop"));
}
}