HexTool/mainwindow.cpp
2018-05-30 22:44:36 +08:00

125 lines
2.3 KiB
C++

#include "mainwindow.h"
#include "ui_mainwindow.h"
const int maxlen = 65536;
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
this->bpl = 16;
this->fmt = Data::prefix;
ui->setupUi(this);
setWindowIcon(QIcon("hex.ico"));
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::unify_rand(QPlainTextEdit *to)
{
int len = ui->ln_rand_byte->text().toInt();
if (len > maxlen) return;
Data d(len, ui->cb_cap->isChecked());
to->setPlainText(d.get(this->bpl, this->fmt));
}
void MainWindow::unify_trns(QPlainTextEdit *from, QPlainTextEdit *to)
{
QString get = from->toPlainText();
Data d(get, ui->cb_cap->isChecked());
if (ui->rb_trans_hex->isChecked()) {
d.to_hex();
to->setPlainText(d.get(this->bpl, this->fmt));
} else {
to->setPlainText(d.get_ascii());
}
}
void MainWindow::unify_fmt(QPlainTextEdit *from, QPlainTextEdit *to)
{
QString get = from->toPlainText();
Data d(get, ui->cb_cap->isChecked());
d.clean();
to->setPlainText(d.get(this->bpl, this->fmt));
}
void MainWindow::on_rb_bl_set_clicked()
{
this->bpl = ui->ln_bl_byte->text().toInt();
ui->ln_bl_byte->setEnabled(true);
}
void MainWindow::on_rb_bl_none_clicked()
{
this->bpl = 0;
ui->ln_bl_byte->setDisabled(true);
}
void MainWindow::on_rb_bl_keep_clicked()
{
this->bpl = -1;
ui->ln_bl_byte->setDisabled(true);
}
void MainWindow::on_rb_fmt_prfx_clicked()
{
this->fmt = Data::prefix;
}
void MainWindow::on_rb_fmt_space_clicked()
{
this->fmt = Data::space;
}
void MainWindow::on_rb_fmt_seq_clicked()
{
this->fmt = Data::seq;
}
void MainWindow::on_btn_fmt_left_clicked()
{
unify_fmt(ui->txt_right, ui->txt_left);
}
void MainWindow::on_btn_fmt_right_clicked()
{
unify_fmt(ui->txt_left, ui->txt_right);
}
void MainWindow::on_btn_trans_left_clicked()
{
unify_trns(ui->txt_right, ui->txt_left);
}
void MainWindow::on_btn_trans_right_clicked()
{
unify_trns(ui->txt_left, ui->txt_right);
}
void MainWindow::on_btn_rand_left_clicked()
{
unify_rand(ui->txt_left);
}
void MainWindow::on_btn_rand_right_clicked()
{
unify_rand(ui->txt_right);
}
void MainWindow::on_ln_bl_byte_editingFinished()
{
this->bpl = ui->ln_bl_byte->text().toInt();
}