Add instruction preview to the bytes edit dialog (#696)

This commit is contained in:
Rune Tynan 2018-09-09 13:55:13 -04:00 committed by xarkes
parent e3896dd01f
commit a6a8d5a760
3 changed files with 77 additions and 4 deletions

View File

@ -1,5 +1,6 @@
#include "EditInstructionDialog.h" #include "EditInstructionDialog.h"
#include "ui_EditInstructionDialog.h" #include "ui_EditInstructionDialog.h"
#include "Cutter.h"
EditInstructionDialog::EditInstructionDialog(QWidget *parent) : EditInstructionDialog::EditInstructionDialog(QWidget *parent) :
QDialog(parent), QDialog(parent),
@ -32,6 +33,16 @@ QString EditInstructionDialog::getInstruction()
void EditInstructionDialog::setInstruction(const QString &instruction) void EditInstructionDialog::setInstruction(const QString &instruction)
{ {
ui->lineEdit->setText(instruction); ui->lineEdit->setText(instruction);
updatePreview(instruction);
}
void EditInstructionDialog::updatePreview(const QString &hex) {
QString result = Core()->disassemble(hex).trimmed();
if (result.isEmpty() || result.contains("\n")) {
ui->instructionLabel->setText("Unknown Instruction");
} else {
ui->instructionLabel->setText(result);
}
} }
bool EditInstructionDialog::eventFilter(QObject *obj, QEvent *event) bool EditInstructionDialog::eventFilter(QObject *obj, QEvent *event)
@ -47,6 +58,14 @@ bool EditInstructionDialog::eventFilter(QObject *obj, QEvent *event)
this->accept(); this->accept();
return true; return true;
} }
// Update instruction preview
QString lineText = ui->lineEdit->text();
if (keyEvent -> key() == Qt::Key_Backspace) {
updatePreview(lineText.left(lineText.size() - 1));
} else {
updatePreview(lineText + keyEvent->text());
}
} }

View File

@ -20,6 +20,8 @@ public:
QString getInstruction(); QString getInstruction();
void setInstruction(const QString &instruction); void setInstruction(const QString &instruction);
void updatePreview(const QString &hex);
private slots: private slots:
void on_buttonBox_accepted(); void on_buttonBox_accepted();

View File

@ -13,6 +13,9 @@
<property name="windowTitle"> <property name="windowTitle">
<string>Edit Instruction</string> <string>Edit Instruction</string>
</property> </property>
<property name="sizeGripEnabled">
<bool>false</bool>
</property>
<layout class="QVBoxLayout" name="verticalLayout_2"> <layout class="QVBoxLayout" name="verticalLayout_2">
<property name="spacing"> <property name="spacing">
<number>2</number> <number>2</number>
@ -30,13 +33,62 @@
<number>2</number> <number>2</number>
</property> </property>
<item> <item>
<layout class="QHBoxLayout" name="horizontalLayout"> <layout class="QVBoxLayout" name="verticalLayout">
<property name="topMargin"> <item>
<number>0</number> <spacer name="verticalSpacer">
</property> <property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
<item> <item>
<widget class="QLineEdit" name="lineEdit"/> <widget class="QLineEdit" name="lineEdit"/>
</item> </item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<property name="leftMargin">
<number>5</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<item>
<widget class="QLabel" name="instructionLabel">
<property name="baseSize">
<size>
<width>1000</width>
<height>10</height>
</size>
</property>
<property name="layoutDirection">
<enum>Qt::RightToLeft</enum>
</property>
<property name="text">
<string>Unknown Instruction</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<spacer name="verticalSpacer_1">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
</layout> </layout>
</item> </item>
<item> <item>