2018-02-12 20:12:13 +00:00
|
|
|
#include "EditInstructionDialog.h"
|
|
|
|
#include "ui_EditInstructionDialog.h"
|
2019-02-22 16:50:45 +00:00
|
|
|
#include "core/Cutter.h"
|
2018-02-12 20:12:13 +00:00
|
|
|
|
2019-03-23 06:32:31 +00:00
|
|
|
EditInstructionDialog::EditInstructionDialog(InstructionEditMode editMode, QWidget *parent) :
|
2018-02-12 20:12:13 +00:00
|
|
|
QDialog(parent),
|
2018-09-14 17:20:54 +00:00
|
|
|
ui(new Ui::EditInstructionDialog),
|
2018-10-23 05:06:26 +00:00
|
|
|
editMode(editMode)
|
2018-02-12 20:12:13 +00:00
|
|
|
{
|
|
|
|
ui->setupUi(this);
|
|
|
|
setWindowFlags(windowFlags() & (~Qt::WindowContextHelpButtonHint));
|
|
|
|
|
2018-09-30 20:00:53 +00:00
|
|
|
connect(ui->lineEdit, SIGNAL(textEdited(const QString &)), this,
|
|
|
|
SLOT(updatePreview(const QString &)));
|
2018-02-12 20:12:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
EditInstructionDialog::~EditInstructionDialog() {}
|
|
|
|
|
|
|
|
void EditInstructionDialog::on_buttonBox_accepted()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void EditInstructionDialog::on_buttonBox_rejected()
|
|
|
|
{
|
|
|
|
close();
|
|
|
|
}
|
|
|
|
|
2019-04-06 12:04:55 +00:00
|
|
|
QString EditInstructionDialog::getInstruction() const
|
2018-02-12 20:12:13 +00:00
|
|
|
{
|
2019-04-06 12:04:55 +00:00
|
|
|
return ui->lineEdit->text();
|
2018-02-12 20:12:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void EditInstructionDialog::setInstruction(const QString &instruction)
|
|
|
|
{
|
|
|
|
ui->lineEdit->setText(instruction);
|
2019-12-06 17:04:29 +00:00
|
|
|
ui->lineEdit->selectAll();
|
2018-09-09 17:55:13 +00:00
|
|
|
updatePreview(instruction);
|
|
|
|
}
|
|
|
|
|
2018-09-14 17:20:54 +00:00
|
|
|
void EditInstructionDialog::updatePreview(const QString &input)
|
|
|
|
{
|
|
|
|
QString result;
|
2018-10-23 05:06:26 +00:00
|
|
|
|
|
|
|
if (editMode == EDIT_NONE) {
|
|
|
|
ui->instructionLabel->setText("");
|
|
|
|
return;
|
|
|
|
} else if (editMode == EDIT_BYTES) {
|
2019-03-29 17:11:41 +00:00
|
|
|
QByteArray data = CutterCore::hexStringToBytes(input);
|
2020-01-01 13:39:27 +00:00
|
|
|
result = Core()->disassemble(data).simplified();
|
2018-10-23 05:06:26 +00:00
|
|
|
} else if (editMode == EDIT_TEXT) {
|
2019-03-29 17:11:41 +00:00
|
|
|
QByteArray data = Core()->assemble(input);
|
|
|
|
result = CutterCore::bytesToHexString(data).trimmed();
|
2018-09-14 17:20:54 +00:00
|
|
|
}
|
|
|
|
|
2020-01-01 13:39:27 +00:00
|
|
|
if (result.isEmpty() || result.contains("invalid")) {
|
2018-09-09 17:55:13 +00:00
|
|
|
ui->instructionLabel->setText("Unknown Instruction");
|
|
|
|
} else {
|
|
|
|
ui->instructionLabel->setText(result);
|
|
|
|
}
|
2018-02-12 20:12:13 +00:00
|
|
|
}
|