diff --git a/HexTool.pro b/HexTool.pro index e5d10fd..2d4f0ea 100644 --- a/HexTool.pro +++ b/HexTool.pro @@ -1,39 +1,39 @@ -#------------------------------------------------- -# -# Project created by QtCreator 2018-01-16T08:53:27 -# -#------------------------------------------------- - -QT += core gui - -greaterThan(QT_MAJOR_VERSION, 4): QT += widgets - -TARGET = HexTool -TEMPLATE = app - -# The following define makes your compiler emit warnings if you use -# any feature of Qt which as been marked as deprecated (the exact warnings -# depend on your compiler). Please consult the documentation of the -# deprecated API in order to know how to port your code away from it. -DEFINES += QT_DEPRECATED_WARNINGS - -# You can also make your code fail to compile if you use deprecated APIs. -# In order to do so, uncomment the following line. -# You can also select to disable deprecated APIs only up to a certain version of Qt. -#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 - - -SOURCES += main.cpp\ - mainwindow.cpp \ - data.cpp - -HEADERS += mainwindow.h \ - data.h - -FORMS += mainwindow.ui - -DISTFILES += - -RESOURCES += \ - icon.qrc -RC_FILE = icon.rc +#------------------------------------------------- +# +# Project created by QtCreator 2018-01-16T08:53:27 +# +#------------------------------------------------- + +QT += core gui + +greaterThan(QT_MAJOR_VERSION, 4): QT += widgets + +TARGET = HexTool +TEMPLATE = app + +# The following define makes your compiler emit warnings if you use +# any feature of Qt which as been marked as deprecated (the exact warnings +# depend on your compiler). Please consult the documentation of the +# deprecated API in order to know how to port your code away from it. +DEFINES += QT_DEPRECATED_WARNINGS + +# You can also make your code fail to compile if you use deprecated APIs. +# In order to do so, uncomment the following line. +# You can also select to disable deprecated APIs only up to a certain version of Qt. +#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 + + +SOURCES += main.cpp\ + mainwindow.cpp \ + data.cpp + +HEADERS += mainwindow.h \ + data.h + +FORMS += mainwindow.ui + +DISTFILES += + +RESOURCES += \ + icon.qrc +RC_FILE = icon.rc diff --git a/data.cpp b/data.cpp index 9c04d90..ddaf766 100644 --- a/data.cpp +++ b/data.cpp @@ -1,88 +1,88 @@ -#include "data.h" - -#include -#include - - -Data::Data(QString &in, bool cap) -{ - this->txt = in; - this->cap = cap; -} - - -Data::Data(int len, bool cap) -{ - QByteArray rand; - QTime cur = QTime::currentTime(); - qsrand(cur.second() * 1000 + cur.msec()); - while (len--) rand.append(qrand() % 256); - this->txt = QString(rand.toHex()); - this->cap = cap; -} - - -void Data::to_hex() -{ - this->txt = QString(this->txt.toLocal8Bit().toHex()); -} - - -void Data::clean() -{ - this->txt = this->txt.toLower().replace(QRegExp("(0x)|[^0-9a-fA-F\n]"), ""); -} - - -QString Data::get_ascii() -{ - return QString(QByteArray::fromHex(this->txt.toLocal8Bit())); -} - - -QString Data::get(int unit, enum format fmt) -{ - QStringList work; - - if (this->cap) this->txt = this->txt.toUpper(); - - if (0 > unit) { - work = this->txt.split('\n'); - } else { - this->txt.replace("\n", ""); - - if (unit) { - unit *= 2; - for (int i = 0; i < this->txt.size(); i += unit) { - work << this->txt.mid(i, unit); - } - } else { - work << this->txt; - } - } - - QString st; - - switch (fmt) { - case Data::seq: - return work.join('\n'); - case Data::space: - st = "\\1 "; - break; - case Data::prefix: - st = "0x\\1, "; - break; - default: - return ""; - } - - QStringList::iterator pick; - for (pick = work.begin(); pick != work.end(); pick++) { - if ((*pick).size() & 1) (*pick) += "0"; - (*pick).replace(QRegExp("([0-9a-fA-F]{2})"), st); - (*pick).replace(QRegExp(" +$"), ""); - } - - return work.join('\n'); -} - +#include "data.h" + +#include +#include + + +Data::Data(QString &in, bool cap) +{ + this->txt = in; + this->cap = cap; +} + + +Data::Data(int len, bool cap) +{ + QByteArray rand; + QTime cur = QTime::currentTime(); + qsrand(cur.second() * 1000 + cur.msec()); + while (len--) rand.append(qrand() % 256); + this->txt = QString(rand.toHex()); + this->cap = cap; +} + + +void Data::to_hex() +{ + this->txt = QString(this->txt.toLocal8Bit().toHex()); +} + + +void Data::clean() +{ + this->txt = this->txt.toLower().replace(QRegExp("(0x)|[^0-9a-fA-F\n]"), ""); +} + + +QString Data::get_ascii() +{ + return QString(QByteArray::fromHex(this->txt.toLocal8Bit())); +} + + +QString Data::get(int unit, enum format fmt) +{ + QStringList work; + + if (this->cap) this->txt = this->txt.toUpper(); + + if (0 > unit) { + work = this->txt.split('\n'); + } else { + this->txt.replace("\n", ""); + + if (unit) { + unit *= 2; + for (int i = 0; i < this->txt.size(); i += unit) { + work << this->txt.mid(i, unit); + } + } else { + work << this->txt; + } + } + + QString st; + + switch (fmt) { + case Data::seq: + return work.join('\n'); + case Data::space: + st = "\\1 "; + break; + case Data::prefix: + st = "0x\\1, "; + break; + default: + return ""; + } + + QStringList::iterator pick; + for (pick = work.begin(); pick != work.end(); pick++) { + if ((*pick).size() & 1) (*pick) += "0"; + (*pick).replace(QRegExp("([0-9a-fA-F]{2})"), st); + (*pick).replace(QRegExp(" +$"), ""); + } + + return work.join('\n'); +} + diff --git a/data.h b/data.h index 52950f9..918ec2d 100644 --- a/data.h +++ b/data.h @@ -1,23 +1,23 @@ -#ifndef DATA_H -#define DATA_H - -#include - -class Data -{ - public: - enum format { seq, space, prefix }; - bool cap; - - Data(QString &in, bool cap); - Data(int len, bool cap); - void clean(); - void to_hex(); - QString get_ascii(); - QString get(int unit, enum format fmt); - - private: - QString txt; -}; - -#endif // DATA_H +#ifndef DATA_H +#define DATA_H + +#include + +class Data +{ + public: + enum format { seq, space, prefix }; + bool cap; + + Data(QString &in, bool cap); + Data(int len, bool cap); + void clean(); + void to_hex(); + QString get_ascii(); + QString get(int unit, enum format fmt); + + private: + QString txt; +}; + +#endif // DATA_H diff --git a/icon.qrc b/icon.qrc index f94aa9d..c9b549d 100644 --- a/icon.qrc +++ b/icon.qrc @@ -1,5 +1,5 @@ - - - hex.ico - - + + + hex.ico + + diff --git a/main.cpp b/main.cpp index 6ad6845..5b24a36 100644 --- a/main.cpp +++ b/main.cpp @@ -1,13 +1,13 @@ -#include "mainwindow.h" -#include - -#include - -int main(int argc, char *argv[]) -{ - QApplication a(argc, argv); - MainWindow w; - w.show(); - - return a.exec(); -} +#include "mainwindow.h" +#include + +#include + +int main(int argc, char *argv[]) +{ + QApplication a(argc, argv); + MainWindow w; + w.show(); + + return a.exec(); +} diff --git a/mainwindow.cpp b/mainwindow.cpp index 4478b3b..39a3f01 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -1,124 +1,124 @@ -#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(); -} +#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(); +} diff --git a/mainwindow.h b/mainwindow.h index 9ec3b96..93bfc55 100644 --- a/mainwindow.h +++ b/mainwindow.h @@ -1,57 +1,45 @@ -#ifndef MAINWINDOW_H -#define MAINWINDOW_H - -#include -#include -#include "data.h" - -namespace Ui { -class MainWindow; -} - -class MainWindow : public QMainWindow -{ - Q_OBJECT - - public: - explicit MainWindow(QWidget *parent = 0); - ~MainWindow(); - - private slots: - void on_rb_bl_set_clicked(); - - void on_rb_bl_none_clicked(); - - void on_rb_bl_keep_clicked(); - - void on_rb_fmt_prfx_clicked(); - - void on_rb_fmt_space_clicked(); - - void on_rb_fmt_seq_clicked(); - - void on_btn_fmt_left_clicked(); - - void on_btn_fmt_right_clicked(); - - void on_btn_trans_left_clicked(); - - void on_btn_trans_right_clicked(); - - void on_btn_rand_left_clicked(); - - void on_btn_rand_right_clicked(); - - void on_ln_bl_byte_editingFinished(); - - private: - Ui::MainWindow *ui; - int bpl; - bool cap; - Data::format fmt; - void unify_rand(QPlainTextEdit *to); - void unify_trns(QPlainTextEdit *from, QPlainTextEdit *to); - void unify_fmt(QPlainTextEdit *from, QPlainTextEdit *to); -}; - -#endif // MAINWINDOW_H +#ifndef MAINWINDOW_H +#define MAINWINDOW_H + +#include +#include +#include "data.h" + +namespace Ui { + class MainWindow; +} + +class MainWindow : public QMainWindow +{ + Q_OBJECT + + public: + explicit MainWindow(QWidget *parent = 0); + ~MainWindow(); + + private slots: + void on_rb_bl_set_clicked(); + void on_rb_bl_none_clicked(); + void on_rb_bl_keep_clicked(); + void on_rb_fmt_prfx_clicked(); + void on_rb_fmt_space_clicked(); + void on_rb_fmt_seq_clicked(); + void on_btn_fmt_left_clicked(); + void on_btn_fmt_right_clicked(); + void on_btn_trans_left_clicked(); + void on_btn_trans_right_clicked(); + void on_btn_rand_left_clicked(); + void on_btn_rand_right_clicked(); + void on_ln_bl_byte_editingFinished(); + + private: + Ui::MainWindow *ui; + int bpl; + bool cap; + Data::format fmt; + void unify_rand(QPlainTextEdit *to); + void unify_trns(QPlainTextEdit *from, QPlainTextEdit *to); + void unify_fmt(QPlainTextEdit *from, QPlainTextEdit *to); +}; + +#endif // MAINWINDOW_H diff --git a/mainwindow.ui b/mainwindow.ui index fbf88c8..ac9f329 100644 --- a/mainwindow.ui +++ b/mainwindow.ui @@ -1,422 +1,422 @@ - - - MainWindow - - - - 0 - 0 - 1120 - 700 - - - - - 1120 - 700 - - - - - 1120 - 700 - - - - 十六进制数据整理工具 - - - - - - 10 - 10 - 350 - 680 - - - - - - - 500 - 10 - 610 - 680 - - - - - - - - - - 370 - 570 - 120 - 111 - - - - 生成随机数 - - - - - 10 - 50 - 75 - 23 - - - - ←生成 - - - - - - 20 - 20 - 91 - 22 - - - - - - - - 0 - 0 - - - - - 50 - 16777215 - - - - 100 - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - - - - - 字节 - - - - - - - - - 40 - 80 - 75 - 23 - - - - 生成→ - - - - - - - 370 - 160 - 120 - 131 - - - - 格式选项 - - - - - 10 - 20 - 109 - 71 - - - - - - - 每字节带前导0x - - - true - - - - - - - 每字节空格 - - - - - - - 每行连续输出 - - - - - - - - - 10 - 110 - 71 - 16 - - - - 输出大写 - - - true - - - - - - - 370 - 410 - 120 - 141 - - - - ASCII转换 - - - - - 10 - 20 - 101 - 41 - - - - - - - 转为十六进制 - - - true - - - - - - - 转为ASCII - - - - - - - - - 10 - 80 - 75 - 23 - - - - ←转换 - - - - - - 40 - 110 - 75 - 23 - - - - 转换→ - - - - - - - 370 - 20 - 120 - 121 - - - - 换行选项 - - - false - - - - - 10 - 20 - 103 - 91 - - - - - - - 增加换行 - - - true - - - - - - - - - Qt::DefaultContextMenu - - - false - - - QFrame::Plain - - - - - - - - - - true - - - - 0 - 0 - - - - - 27 - 16777215 - - - - 16 - - - 128 - - - Qt::AlignCenter - - - - - - - false - - - 字节换行 - - - false - - - - - - - - - 不换行 - - - - - - - 保留原行 - - - - - - - - - - 370 - 310 - 120 - 80 - - - - 格式整理 - - - - - 40 - 50 - 75 - 23 - - - - 整理→ - - - - - - 10 - 20 - 75 - 23 - - - - ←整理 - - - - - - - - - + + + MainWindow + + + + 0 + 0 + 1120 + 700 + + + + + 1120 + 700 + + + + + 1120 + 700 + + + + 十六进制数据整理工具 + + + + + + 10 + 10 + 350 + 680 + + + + + + + 500 + 10 + 610 + 680 + + + + + + + + + + 370 + 570 + 120 + 111 + + + + 生成随机数 + + + + + 10 + 50 + 75 + 23 + + + + ←生成 + + + + + + 20 + 20 + 91 + 22 + + + + + + + + 0 + 0 + + + + + 50 + 16777215 + + + + 100 + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + 字节 + + + + + + + + + 40 + 80 + 75 + 23 + + + + 生成→ + + + + + + + 370 + 160 + 120 + 131 + + + + 格式选项 + + + + + 10 + 20 + 109 + 71 + + + + + + + 每字节带前导0x + + + true + + + + + + + 每字节空格 + + + + + + + 每行连续输出 + + + + + + + + + 10 + 110 + 71 + 16 + + + + 输出大写 + + + true + + + + + + + 370 + 410 + 120 + 141 + + + + ASCII转换 + + + + + 10 + 20 + 101 + 41 + + + + + + + 转为十六进制 + + + true + + + + + + + 转为ASCII + + + + + + + + + 10 + 80 + 75 + 23 + + + + ←转换 + + + + + + 40 + 110 + 75 + 23 + + + + 转换→ + + + + + + + 370 + 20 + 120 + 121 + + + + 换行选项 + + + false + + + + + 10 + 20 + 103 + 91 + + + + + + + 增加换行 + + + true + + + + + + + + + Qt::DefaultContextMenu + + + false + + + QFrame::Plain + + + + + + + + + + true + + + + 0 + 0 + + + + + 27 + 16777215 + + + + 16 + + + 128 + + + Qt::AlignCenter + + + + + + + false + + + 字节换行 + + + false + + + + + + + + + 不换行 + + + + + + + 保留原行 + + + + + + + + + + 370 + 310 + 120 + 80 + + + + 格式整理 + + + + + 40 + 50 + 75 + 23 + + + + 整理→ + + + + + + 10 + 20 + 75 + 23 + + + + ←整理 + + + + + + + + +