145 lines
3.1 KiB
C++
145 lines
3.1 KiB
C++
#include "mainwindow.h"
|
|
#include "ui_mainwindow.h"
|
|
#include "data.h"
|
|
|
|
const int maxlen = 1024 * 1024;
|
|
|
|
MainWindow::MainWindow(QWidget *parent) :
|
|
QMainWindow(parent),
|
|
ui(new Ui::MainWindow)
|
|
{
|
|
this->bpl = 16;
|
|
this->from_type = t_hex;
|
|
this->to_type = t_hex;
|
|
this->format = cprefix;
|
|
|
|
ui->setupUi(this);
|
|
setWindowIcon(QIcon("hex.ico"));
|
|
}
|
|
|
|
MainWindow::~MainWindow()
|
|
{
|
|
delete ui;
|
|
}
|
|
|
|
void MainWindow::trans(QPlainTextEdit *from, QPlainTextEdit *to)
|
|
{
|
|
QString origin = from->toPlainText();
|
|
if (!origin.length()) return;
|
|
Data d;
|
|
d.set(origin, this->from_type);
|
|
d.cap = ui->cb_fmt_cap->isChecked();
|
|
to->setPlainText(d.get(this->bpl, this->to_type, this->format));
|
|
}
|
|
|
|
void MainWindow::gen_rand(QPlainTextEdit *to)
|
|
{
|
|
int len = ui->ln_rand_byte->text().toInt();
|
|
if (len < 1) return;
|
|
Data d(len);
|
|
d.cap = ui->cb_fmt_cap->isChecked();
|
|
to->setPlainText(d.get(this->bpl, this->to_type, this->format));
|
|
}
|
|
|
|
void MainWindow::alter_format_stat(bool enabled)
|
|
{
|
|
ui->cb_fmt_cap->setEnabled(enabled);
|
|
ui->rb_fmt_cont->setEnabled(enabled);
|
|
ui->rb_fmt_sepa->setEnabled(enabled);
|
|
ui->rb_fmt_cpre->setEnabled(enabled);
|
|
}
|
|
|
|
void MainWindow::on_rb_bl_set_toggled(bool checked)
|
|
{
|
|
ui->ln_bl_byte->setEnabled(checked);
|
|
ui->lbl_blset_1->setEnabled(checked);
|
|
ui->lbl_blset_1->setEnabled(checked);
|
|
if (checked) this->bpl = ui->ln_bl_byte->text().toInt();
|
|
}
|
|
|
|
void MainWindow::on_rb_bl_none_toggled(bool checked)
|
|
{
|
|
if (checked) this->bpl = 0;
|
|
}
|
|
|
|
void MainWindow::on_rb_bl_keep_toggled(bool checked)
|
|
{
|
|
if (checked) this->bpl = -1;
|
|
}
|
|
|
|
void MainWindow::on_ln_bl_byte_textChanged(const QString &arg)
|
|
{
|
|
this->bpl = arg.toInt();
|
|
if (this->bpl < 0) ui->ln_bl_byte->setText("16");
|
|
}
|
|
|
|
void MainWindow::on_rb_fmt_cpre_toggled(bool checked)
|
|
{
|
|
if (checked) this->format = cprefix;
|
|
}
|
|
|
|
void MainWindow::on_rb_fmt_sepa_toggled(bool checked)
|
|
{
|
|
if (checked) this->format = separate;
|
|
}
|
|
|
|
void MainWindow::on_rb_fmt_cont_toggled(bool checked)
|
|
{
|
|
if (checked) this->format = continous;
|
|
}
|
|
|
|
void MainWindow::on_rb_hex2hex_clicked()
|
|
{
|
|
this->from_type = t_hex;
|
|
this->to_type = t_hex;
|
|
this->alter_format_stat(true);
|
|
}
|
|
|
|
void MainWindow::on_rb_ascii2hex_clicked()
|
|
{
|
|
this->from_type = t_ascii;
|
|
this->to_type = t_hex;
|
|
this->alter_format_stat(true);
|
|
}
|
|
|
|
void MainWindow::on_rb_hex2ascii_clicked()
|
|
{
|
|
this->from_type = t_hex;
|
|
this->to_type = t_ascii;
|
|
this->alter_format_stat(false);
|
|
}
|
|
|
|
void MainWindow::on_rb_base2hex_clicked()
|
|
{
|
|
this->from_type = t_base64;
|
|
this->to_type = t_hex;
|
|
this->alter_format_stat(true);
|
|
}
|
|
|
|
void MainWindow::on_rb_hex2base_clicked()
|
|
{
|
|
this->from_type = t_hex;
|
|
this->to_type = t_base64;
|
|
this->alter_format_stat(false);
|
|
}
|
|
|
|
void MainWindow::on_btn_trans_left_clicked()
|
|
{
|
|
this->trans(ui->txt_right, ui->txt_left);
|
|
}
|
|
|
|
void MainWindow::on_btn_trans_right_clicked()
|
|
{
|
|
this->trans(ui->txt_left, ui->txt_right);
|
|
}
|
|
|
|
void MainWindow::on_btn_rand_left_clicked()
|
|
{
|
|
this->gen_rand(ui->txt_left);
|
|
}
|
|
|
|
void MainWindow::on_btn_rand_right_clicked()
|
|
{
|
|
this->gen_rand(ui->txt_right);
|
|
}
|