#include <iostream>
#include <QtGui>
#include <QLocale>
#include <QFile>
#include <QByteArray>
#include <QChar>
#include "sifrator.h"
using namespace std;
EncrypterBody
::EncrypterBody(QWidget *parent
){
// Zadavani klicu
keyPublic->setMinimumWidth(TEXT_W);
keyPublic->setMaximumWidth(TEXT_W);
keyPublic->setMaxLength(50);
keyPublic->setText(trUtf8("Veřejný klÃ*č"));
// Name Label souboru
openFileName->setFrameStyle(LABEL_STYLE);
openFileName->setText(trUtf8("Cesta k otevřenému souboru"));
// Textarea
text->setText(trUtf8("Text"));
text->canPaste();
text->setTabStopWidth(500);
text->setMinimumSize(TEXT_W - BUTT_W - 5, TEXT_H);
text->setMaximumSize(TEXT_W - BUTT_W - 5, TEXT_H);
// Buttónky
buttonTranslate
= new QPushButton(trUtf8
("Přeložit"));
buttonTranslate->setMinimumSize(BUTT_W, BUTT_H);
buttonTranslate->setMaximumSize(BUTT_W, BUTT_H);
connect(buttonTranslate, SIGNAL(clicked()), this, SLOT(textEncryption()));
buttonSave->setMinimumSize(BUTT_W, BUTT_H);
buttonSave->setMaximumSize(BUTT_W, BUTT_H);
connect(buttonSave, SIGNAL(clicked()), this, SLOT(saveFile()));
buttonOpen->setMinimumSize(BUTT_W, BUTT_H);
buttonOpen->setMaximumSize(BUTT_W, BUTT_H);
connect(buttonOpen, SIGNAL(clicked()), this, SLOT(openFile()));
// UspořádánÃ* layoutu
texts_buttons->addWidget(openFileName, 0, 0);
texts_buttons->addWidget(text, 1, 0, 4, 1);
texts_buttons->addWidget(buttonTranslate, 1, 1);
texts_buttons->addWidget(buttonSave, 2, 1);
texts_buttons->addWidget(buttonOpen, 3, 1);
texts_buttons->setRowMinimumHeight(4, TEXT_H - (3 * BUTT_H + 8));
layout->addWidget(keyPublic);
layout->addLayout(texts_buttons);
layout
->setSizeConstraint
(QLayout::SetFixedSize);
setLayout(layout);
}
////////////
// FUNKCE //
////////////
// Načte jméno souboru do text()u QLabelu
void EncrypterBody::openFile()
{
QString fileName
= QFileDialog::getOpenFileName(this, trUtf8
("Vyber textový soubor"), openFileName
->text
(), trUtf8
("Textové soubory (*.txt)"));
if (!fileName.isEmpty())
{
if (fileName != openFileName->text())
{
openFileName->setText(fileName);
}
readFile();
}
}
void EncrypterBody::readFile()
{
text->clear();
QFile file(openFileName
->text
());
while (!file.atEnd())
{
text->append(line);
}
file.close();
}
void EncrypterBody::saveFile()
{
QString fileName
= QFileDialog::getSaveFileName(this, trUtf8
("Vyber textový soubor"), openFileName
->text
(), trUtf8
("Textové soubory (*.txt)"));
openFileName->setText(fileName);
out << text->toPlainText();
file.close();
}
//clicked() SIGNAL is connected to this SLOT which is emmiting another SIGNAL
void EncrypterBody::textEncryption()
{
QString textNormal
= text
->toPlainText
();
textNormal = textNormal.simplified();
for (int o = 0; o < textNormal.size(); o++)
{
QChar cChar
= textNormal.
data()[o
];
short cNumber = cChar.unicode();
for (int i = 1; i < 3; i++)
{
if (cNumber < pow(10, i))
{
textEncrypted.append('0');
}
}
out << cNumber;
}
emit clickedTranslate(textEncrypted);
}
void EncrypterBody
::setText(QString string
) {
text->setText(string);
}
#include <iostream>
#include <QtGui>
#include <QLocale>
#include <QFile>
#include <QByteArray>
#include <QChar>
#include "sifrator.h"
using namespace std;
EncrypterBody::EncrypterBody(QWidget *parent)
: QWidget(parent)
{
int LABEL_STYLE = QFrame::Sunken | QFrame::Panel;
// Zadavani klicu
QLineEdit *keyPublic = new QLineEdit();
keyPublic->setMinimumWidth(TEXT_W);
keyPublic->setMaximumWidth(TEXT_W);
keyPublic->setMaxLength(50);
keyPublic->setText(trUtf8("Veřejný klÃ*č"));
// Name Label souboru
openFileName = new QLabel;
openFileName->setFrameStyle(LABEL_STYLE);
openFileName->setText(trUtf8("Cesta k otevřenému souboru"));
// Textarea
text = new QTextEdit();
text->setText(trUtf8("Text"));
text->canPaste();
text->setTabStopWidth(500);
text->setMinimumSize(TEXT_W - BUTT_W - 5, TEXT_H);
text->setMaximumSize(TEXT_W - BUTT_W - 5, TEXT_H);
// Buttónky
buttonTranslate = new QPushButton(trUtf8("Přeložit"));
buttonTranslate->setMinimumSize(BUTT_W, BUTT_H);
buttonTranslate->setMaximumSize(BUTT_W, BUTT_H);
connect(buttonTranslate, SIGNAL(clicked()), this, SLOT(textEncryption()));
QPushButton *buttonSave = new QPushButton(trUtf8("Uložit"));
buttonSave->setMinimumSize(BUTT_W, BUTT_H);
buttonSave->setMaximumSize(BUTT_W, BUTT_H);
connect(buttonSave, SIGNAL(clicked()), this, SLOT(saveFile()));
QPushButton *buttonOpen = new QPushButton(trUtf8("NačÃ*st"));
buttonOpen->setMinimumSize(BUTT_W, BUTT_H);
buttonOpen->setMaximumSize(BUTT_W, BUTT_H);
connect(buttonOpen, SIGNAL(clicked()), this, SLOT(openFile()));
// UspořádánÃ* layoutu
QGridLayout *texts_buttons = new QGridLayout;
texts_buttons->addWidget(openFileName, 0, 0);
texts_buttons->addWidget(text, 1, 0, 4, 1);
texts_buttons->addWidget(buttonTranslate, 1, 1);
texts_buttons->addWidget(buttonSave, 2, 1);
texts_buttons->addWidget(buttonOpen, 3, 1);
texts_buttons->setRowMinimumHeight(4, TEXT_H - (3 * BUTT_H + 8));
QVBoxLayout *layout = new QVBoxLayout;
layout->addWidget(keyPublic);
layout->addLayout(texts_buttons);
layout->setSizeConstraint(QLayout::SetFixedSize);
setLayout(layout);
}
////////////
// FUNKCE //
////////////
// Načte jméno souboru do text()u QLabelu
void EncrypterBody::openFile()
{
QFileDialog::Options options;
QString selectedFilter;
QString fileName = QFileDialog::getOpenFileName(this, trUtf8("Vyber textový soubor"), openFileName->text(), trUtf8("Textové soubory (*.txt)"));
if (!fileName.isEmpty())
{
if (fileName != openFileName->text())
{
openFileName->setText(fileName);
}
readFile();
}
}
void EncrypterBody::readFile()
{
text->clear();
QFile file(openFileName->text());
file.open(QIODevice::ReadOnly | QIODevice::Text);
while (!file.atEnd())
{
QString line = QString::fromUtf8(file.readLine());
text->append(line);
}
file.close();
}
void EncrypterBody::saveFile()
{
QString fileName = QFileDialog::getSaveFileName(this, trUtf8("Vyber textový soubor"), openFileName->text(), trUtf8("Textové soubory (*.txt)"));
openFileName->setText(fileName);
QFile file(fileName);
file.open(QIODevice::WriteOnly | QIODevice::Text);
QTextStream out(&file);
out << text->toPlainText();
file.close();
}
//clicked() SIGNAL is connected to this SLOT which is emmiting another SIGNAL
void EncrypterBody::textEncryption()
{
QString textNormal = text->toPlainText();
textNormal = textNormal.simplified();
QString textEncrypted;
QTextStream out(&textEncrypted);
for (int o = 0; o < textNormal.size(); o++)
{
QChar cChar = textNormal.data()[o];
short cNumber = cChar.unicode();
for (int i = 1; i < 3; i++)
{
if (cNumber < pow(10, i))
{
textEncrypted.append('0');
}
}
out << cNumber;
}
emit clickedTranslate(textEncrypted);
}
void EncrypterBody::setText(QString string)
{
text->setText(string);
}
To copy to clipboard, switch view to plain text mode
#include <QApplication>
#include "sifrator.h"
int main(int argc, char *argv[])
{
// Here I created two instances of Encrypter body
EncrypterBody partEncryption;
EncrypterBody partDecryption;
// Here I am trying to achieve this: When I click buttonTranslate in partEncryption part I want change text in text (QTextEdit) in partDecription instance, however this does not seem to work.
QObject::connect(&partEncryption,
SIGNAL(clickedTrasnlate
(QString)),
&partDecryption,
SLOT(setText
(QString)));
partEncryption.show();
partDecryption.show();
return sifrator.exec();
}
#include <QApplication>
#include "sifrator.h"
int main(int argc, char *argv[])
{
QApplication sifrator(argc, argv);
// Here I created two instances of Encrypter body
EncrypterBody partEncryption;
EncrypterBody partDecryption;
// Here I am trying to achieve this: When I click buttonTranslate in partEncryption part I want change text in text (QTextEdit) in partDecription instance, however this does not seem to work.
QObject::connect(&partEncryption, SIGNAL(clickedTrasnlate(QString)), &partDecryption, SLOT(setText(QString)));
partEncryption.show();
partDecryption.show();
return sifrator.exec();
}
To copy to clipboard, switch view to plain text mode
Bookmarks