mirror of
https://github.com/rizinorg/cutter.git
synced 2024-12-21 20:36:09 +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 "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());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -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();
|
||||||
|
|
||||||
|
@ -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>
|
||||||
@ -29,13 +32,62 @@
|
|||||||
<property name="bottomMargin">
|
<property name="bottomMargin">
|
||||||
<number>2</number>
|
<number>2</number>
|
||||||
</property>
|
</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>
|
<item>
|
||||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||||
|
<property name="leftMargin">
|
||||||
|
<number>5</number>
|
||||||
|
</property>
|
||||||
<property name="topMargin">
|
<property name="topMargin">
|
||||||
<number>0</number>
|
<number>0</number>
|
||||||
</property>
|
</property>
|
||||||
<item>
|
<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>
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
</item>
|
</item>
|
||||||
|
Loading…
Reference in New Issue
Block a user