1 #include "EditInstructionDialog.h" 2 #include "ui_EditInstructionDialog.h" 3 #include "core/Cutter.h" 4 EditInstructionDialog(InstructionEditMode editMode,QWidget * parent)5EditInstructionDialog::EditInstructionDialog(InstructionEditMode editMode, QWidget *parent) : 6 QDialog(parent), 7 ui(new Ui::EditInstructionDialog), 8 editMode(editMode) 9 { 10 ui->setupUi(this); 11 ui->lineEdit->setMinimumWidth(400); 12 ui->instructionLabel->setWordWrap(true); 13 setWindowFlags(windowFlags() & (~Qt::WindowContextHelpButtonHint)); 14 15 connect(ui->lineEdit, &QLineEdit::textEdited, this, &EditInstructionDialog::updatePreview); 16 } 17 ~EditInstructionDialog()18EditInstructionDialog::~EditInstructionDialog() {} 19 on_buttonBox_accepted()20void EditInstructionDialog::on_buttonBox_accepted() 21 { 22 } 23 on_buttonBox_rejected()24void EditInstructionDialog::on_buttonBox_rejected() 25 { 26 close(); 27 } 28 getInstruction() const29QString EditInstructionDialog::getInstruction() const 30 { 31 return ui->lineEdit->text(); 32 } 33 setInstruction(const QString & instruction)34void EditInstructionDialog::setInstruction(const QString &instruction) 35 { 36 ui->lineEdit->setText(instruction); 37 ui->lineEdit->selectAll(); 38 updatePreview(instruction); 39 } 40 updatePreview(const QString & input)41void EditInstructionDialog::updatePreview(const QString &input) 42 { 43 QString result; 44 45 if (editMode == EDIT_NONE) { 46 ui->instructionLabel->setText(""); 47 return; 48 } else if (editMode == EDIT_BYTES) { 49 QByteArray data = CutterCore::hexStringToBytes(input); 50 result = Core()->disassemble(data).replace('\n', "; "); 51 } else if (editMode == EDIT_TEXT) { 52 QByteArray data = Core()->assemble(input); 53 result = CutterCore::bytesToHexString(data).trimmed(); 54 } 55 56 if (result.isEmpty() || result.contains("invalid")) { 57 ui->instructionLabel->setText("Unknown Instruction"); 58 } else { 59 ui->instructionLabel->setText(result); 60 } 61 } 62