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
|
|
|
|
2022-06-22 23:44:25 +00:00
|
|
|
#include <QCheckBox>
|
|
|
|
|
2021-01-24 14:50:13 +00:00
|
|
|
EditInstructionDialog::EditInstructionDialog(InstructionEditMode editMode, QWidget *parent)
|
|
|
|
: QDialog(parent), ui(new Ui::EditInstructionDialog), editMode(editMode)
|
2018-02-12 20:12:13 +00:00
|
|
|
{
|
|
|
|
ui->setupUi(this);
|
2020-01-02 08:03:04 +00:00
|
|
|
ui->lineEdit->setMinimumWidth(400);
|
|
|
|
ui->instructionLabel->setWordWrap(true);
|
2022-06-22 23:44:25 +00:00
|
|
|
if (editMode == EDIT_TEXT) {
|
|
|
|
ui->fillWithNops->setVisible(true);
|
|
|
|
ui->fillWithNops->setCheckState(Qt::Checked);
|
|
|
|
} else {
|
|
|
|
ui->fillWithNops->setVisible(false);
|
|
|
|
}
|
2018-02-12 20:12:13 +00:00
|
|
|
setWindowFlags(windowFlags() & (~Qt::WindowContextHelpButtonHint));
|
|
|
|
|
2020-08-03 09:13:39 +00:00
|
|
|
connect(ui->lineEdit, &QLineEdit::textEdited, this, &EditInstructionDialog::updatePreview);
|
2018-02-12 20:12:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
EditInstructionDialog::~EditInstructionDialog() {}
|
|
|
|
|
2021-01-24 14:50:13 +00:00
|
|
|
void EditInstructionDialog::on_buttonBox_accepted() {}
|
2018-02-12 20:12:13 +00:00
|
|
|
|
|
|
|
void EditInstructionDialog::on_buttonBox_rejected()
|
|
|
|
{
|
|
|
|
close();
|
|
|
|
}
|
|
|
|
|
2022-06-22 23:44:25 +00:00
|
|
|
bool EditInstructionDialog::needsNops() const
|
|
|
|
{
|
|
|
|
if (editMode != EDIT_TEXT) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ui->fillWithNops->checkState() == Qt::Checked;
|
|
|
|
}
|
|
|
|
|
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-02 08:03:04 +00:00
|
|
|
result = Core()->disassemble(data).replace('\n', "; ");
|
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
|
|
|
}
|