Fix instruction preview dialog (#714)

This commit is contained in:
Adam Zambrzycki 2018-09-21 23:44:14 +02:00 committed by xarkes
parent f6955e4eab
commit 6fe3681871
2 changed files with 3 additions and 24 deletions

View File

@ -10,7 +10,7 @@ EditInstructionDialog::EditInstructionDialog(QWidget *parent, bool isEditingByte
ui->setupUi(this); ui->setupUi(this);
setWindowFlags(windowFlags() & (~Qt::WindowContextHelpButtonHint)); setWindowFlags(windowFlags() & (~Qt::WindowContextHelpButtonHint));
ui->lineEdit->installEventFilter(this); connect(ui->lineEdit, SIGNAL(textEdited(const QString &)), this, SLOT(updatePreview(const QString &)));
} }
EditInstructionDialog::~EditInstructionDialog() {} EditInstructionDialog::~EditInstructionDialog() {}
@ -51,22 +51,3 @@ void EditInstructionDialog::updatePreview(const QString &input)
ui->instructionLabel->setText(result); ui->instructionLabel->setText(result);
} }
} }
bool EditInstructionDialog::eventFilter(QObject *obj, QEvent *event)
{
Q_UNUSED(obj);
if (event->type() == QEvent::KeyPress) {
QKeyEvent *keyEvent = static_cast <QKeyEvent *>(event);
// 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());
}
}
return false;
}

View File

@ -20,18 +20,16 @@ public:
QString getInstruction(); QString getInstruction();
void setInstruction(const QString &instruction); void setInstruction(const QString &instruction);
void updatePreview(const QString &input);
private slots: private slots:
void on_buttonBox_accepted(); void on_buttonBox_accepted();
void on_buttonBox_rejected(); void on_buttonBox_rejected();
void updatePreview(const QString &input);
private: private:
std::unique_ptr<Ui::EditInstructionDialog> ui; std::unique_ptr<Ui::EditInstructionDialog> ui;
bool isEditingBytes; // true if editing intruction **bytes**; false if editing instruction **text** bool isEditingBytes; // true if editing intruction **bytes**; false if editing instruction **text**
bool eventFilter(QObject *obj, QEvent *event);
}; };
#endif // EDITINSTRUCTIONDIALOG_H #endif // EDITINSTRUCTIONDIALOG_H