mirror of
https://github.com/rizinorg/cutter.git
synced 2024-12-21 12:26:11 +00:00
Add instruction preview to the bytes edit dialog (#696)
This commit is contained in:
parent
e3896dd01f
commit
a6a8d5a760
@ -1,5 +1,6 @@
|
||||
#include "EditInstructionDialog.h"
|
||||
#include "ui_EditInstructionDialog.h"
|
||||
#include "Cutter.h"
|
||||
|
||||
EditInstructionDialog::EditInstructionDialog(QWidget *parent) :
|
||||
QDialog(parent),
|
||||
@ -32,6 +33,16 @@ QString EditInstructionDialog::getInstruction()
|
||||
void EditInstructionDialog::setInstruction(const QString &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)
|
||||
@ -47,6 +58,14 @@ bool EditInstructionDialog::eventFilter(QObject *obj, QEvent *event)
|
||||
this->accept();
|
||||
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());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -20,6 +20,8 @@ public:
|
||||
QString getInstruction();
|
||||
void setInstruction(const QString &instruction);
|
||||
|
||||
void updatePreview(const QString &hex);
|
||||
|
||||
private slots:
|
||||
void on_buttonBox_accepted();
|
||||
|
||||
|
@ -13,6 +13,9 @@
|
||||
<property name="windowTitle">
|
||||
<string>Edit Instruction</string>
|
||||
</property>
|
||||
<property name="sizeGripEnabled">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_2">
|
||||
<property name="spacing">
|
||||
<number>2</number>
|
||||
@ -29,13 +32,62 @@
|
||||
<property name="bottomMargin">
|
||||
<number>2</number>
|
||||
</property>
|
||||
<item>
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<item>
|
||||
<spacer name="verticalSpacer">
|
||||
<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>
|
||||
<widget class="QLineEdit" name="lineEdit"/>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||
<property name="leftMargin">
|
||||
<number>5</number>
|
||||
</property>
|
||||
<property name="topMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<item>
|
||||
<widget class="QLineEdit" name="lineEdit"/>
|
||||
<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>
|
||||
</item>
|
||||
|
Loading…
Reference in New Issue
Block a user