cutter/src/dialogs/EditInstructionDialog.cpp

61 lines
1.6 KiB
C++
Raw Normal View History

#include "EditInstructionDialog.h"
#include "ui_EditInstructionDialog.h"
#include "core/Cutter.h"
EditInstructionDialog::EditInstructionDialog(InstructionEditMode editMode, QWidget *parent) :
QDialog(parent),
ui(new Ui::EditInstructionDialog),
editMode(editMode)
{
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 &)));
}
EditInstructionDialog::~EditInstructionDialog() {}
void EditInstructionDialog::on_buttonBox_accepted()
{
}
void EditInstructionDialog::on_buttonBox_rejected()
{
close();
}
QString EditInstructionDialog::getInstruction()
{
QString ret = ui->lineEdit->text();
return ret;
}
void EditInstructionDialog::setInstruction(const QString &instruction)
{
ui->lineEdit->setText(instruction);
updatePreview(instruction);
}
void EditInstructionDialog::updatePreview(const QString &input)
{
QString result;
if (editMode == EDIT_NONE) {
ui->instructionLabel->setText("");
return;
} else if (editMode == EDIT_BYTES) {
QByteArray data = CutterCore::hexStringToBytes(input);
result = Core()->disassemble(data).trimmed();
} else if (editMode == EDIT_TEXT) {
QByteArray data = Core()->assemble(input);
result = CutterCore::bytesToHexString(data).trimmed();
}
2019-03-23 10:54:34 +00:00
if (result.isEmpty() || result.contains(QLatin1Char('\n'))) {
ui->instructionLabel->setText("Unknown Instruction");
} else {
ui->instructionLabel->setText(result);
}
}