-
Notifications
You must be signed in to change notification settings - Fork 5
/
TextHexDumpEdit.cpp
37 lines (33 loc) · 963 Bytes
/
TextHexDumpEdit.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
#include "TextHexDumpEdit.h"
#include "ui_TextHexDumpEdit.h"
#include "global.h"
#include <QMessageBox>
TextHexDumpEdit::TextHexDumpEdit(QWidget *parent) :
QWidget(parent),
ui(new Ui::TextHexDumpEdit)
{
ui->setupUi(this);
}
TextHexDumpEdit::~TextHexDumpEdit()
{
delete ui;
}
void TextHexDumpEdit::on_pushButton_clicked()
{
QTextCursor cursor = ui->textEdit->textCursor();
QString hexText = cursor.selectedText();
if(hexText.isEmpty())
hexText = ui->textEdit->toPlainText();
if(!QRegExp("^\\s*([0-9a-fA-F]{2}\\s+)+$").exactMatch(hexText+' '))
{
QMessageBox::critical(this, tr("Failed to parse hex dump"), tr("Hex dump must be a sequence of pairs of hexadecimal digits separated by white space."));
return;
}
QTemporaryFile file;
if(file.open())
{
file.write(QByteArray::fromHex(hexText.toLocal8Bit()));
file.close();
emit hexDumpLoaded(file.fileName());
}
}