-
Notifications
You must be signed in to change notification settings - Fork 0
/
mainwindow.cpp
124 lines (112 loc) · 4.33 KB
/
mainwindow.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
122
123
124
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QTextEdit>
#include <QTextStream>
#include "cryptohelper.h"
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
m_visualization = 0;
move(QApplication::desktop()->geometry().width() / 2 - this->geometry().width() / 2,
QApplication::desktop()->geometry().height() / 2 - this->geometry().height() / 2);
connect(ui->action_saveToFile, SIGNAL(triggered()), this, SLOT(saveToFile()));
connect(ui->action_aboutQt, SIGNAL(triggered()), qApp, SLOT(aboutQt()));
connect(ui->action_Exit, SIGNAL(triggered()), qApp, SLOT(quit()));
connect(ui->action_settings, SIGNAL(triggered()), &m_settings, SLOT(show()));
connect(&m_settings, SIGNAL(alphabetChanged()), this, SLOT(reloadCipher()));
connect(ui->action_aboutProgram, SIGNAL(triggered()), &m_about, SLOT(show()));
connect(ui->encryptPushButton, SIGNAL(clicked()), ui->codeOutTextEdit, SLOT(clear()));
on_ciphiersComboBox_currentIndexChanged(ui->ciphiersComboBox->currentIndex());
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::on_ciphiersComboBox_currentIndexChanged(int index)
{
if(ui->codeInputLayout->itemAt(0) != 0)
delete ui->codeInputLayout->takeAt(0)->widget();
if(m_visualization != 0)
delete m_visualization;
switch(index)
{
case 0:
{
m_cipher = new MagicSquareCipher(0, m_text);
m_visualization = new MagicSquareCipherView(0, int(ui->trainingModeCheckBox->checkState()));
break;
}
case 1:
{
m_cipher = new CaesarCipher(0, m_text);
m_visualization = new CaesarCipherView(0, int(ui->trainingModeCheckBox->checkState()));
break;
}
case 2:
{
m_cipher = new CaesarAfCipher(0, m_text);
m_visualization = new CaesarCipherView(0, int(ui->trainingModeCheckBox->checkState()));
break;
}
case 3:
{
m_cipher = new CaesarKWCipher(0, m_text);
m_visualization = new CaesarKWCipherView(0, int(ui->trainingModeCheckBox->checkState()));
break;
}
case 4:
{
m_cipher = new TrithemiusCipher(0, m_text);
m_visualization = new TrithemiusCipherView(0, int(ui->trainingModeCheckBox->checkState()));
break;
}
case 5:
{
m_cipher = new PlayfairCipher(0, m_text);
m_visualization = new PlayfairCipherView(0, int(ui->trainingModeCheckBox->checkState()));
break;
}
case 6:
{
m_cipher = new VigenereCipher(0, m_text);
m_visualization = new VigenereCipherView(0, int(ui->trainingModeCheckBox->checkState()));
break;
}
case 7:
{
m_cipher = new WheatstoneCipher(0, m_text);
m_visualization = new WheatstoneCipherView(0, int(ui->trainingModeCheckBox->checkState()));
break;
}
}
connect(m_cipher, SIGNAL(encryptedText(QString)), ui->codeOutTextEdit, SLOT(setText(QString)));
connect(ui->encryptPushButton, SIGNAL(clicked()), m_cipher, SLOT(encryptText()));
connect(m_cipher, SIGNAL(text(QString)), this, SLOT(textBuffer(QString)));
connect(m_cipher, SIGNAL(results(QString,QString)), m_visualization, SLOT(setResults(QString,QString)));
connect(m_cipher, SIGNAL(results(QString,QString,QString)), m_visualization, SLOT(setResults(QString,QString,QString)));
connect(m_cipher, SIGNAL(results(QVector<int>,QString,QString)), m_visualization, SLOT(setResults(QVector<int>,QString,QString)));
connect(m_cipher, SIGNAL(results(QString,QString,QString,QString)), m_visualization, SLOT(setResults(QString,QString,QString,QString)));
connect(ui->trainingModeCheckBox, SIGNAL(stateChanged(int)), m_visualization, SLOT(setIsShow(int)));
ui->codeInputLayout->addWidget(m_cipher);
}
void MainWindow::textBuffer(QString text)
{
m_text = text;
}
void MainWindow::saveToFile()
{
QString filename = QFileDialog::getSaveFileName(this, tr("Save to..."), "",
QString("Text files (*.txt)"));
QFile file;
file.setFileName(filename);
file.open(QIODevice::WriteOnly | QIODevice::Text);
QTextStream stream(&file);
stream << ui->codeOutTextEdit->toPlainText();
file.close();
}
void MainWindow::reloadCipher()
{
on_ciphiersComboBox_currentIndexChanged(ui->ciphiersComboBox->currentIndex());
}