keysequenceeditor: override backspace and esc behavior

Fixes #1455
This commit is contained in:
itsmattkc
2021-03-21 23:26:33 +11:00
parent 5b04d84bfb
commit 62332eb216
2 changed files with 32 additions and 1 deletions
+26 -1
View File
@@ -21,11 +21,14 @@
#include "keysequenceeditor.h"
#include <QAction>
#include <QKeyEvent>
namespace olive {
#define super QKeySequenceEdit
KeySequenceEditor::KeySequenceEditor(QWidget* parent, QAction* a)
: QKeySequenceEdit(parent), action(a) {
: super(parent), action(a) {
setKeySequence(action->shortcut());
}
@@ -49,4 +52,26 @@ QString KeySequenceEditor::export_shortcut() {
return nullptr;
}
void KeySequenceEditor::keyPressEvent(QKeyEvent *e)
{
if (e->key() == Qt::Key_Backspace) {
clear();
} else if (e->key() == Qt::Key_Escape) {
e->ignore();
} else{
super::keyPressEvent(e);
}
}
void KeySequenceEditor::keyReleaseEvent(QKeyEvent *e)
{
if (e->key() == Qt::Key_Backspace) {
// Do nothing
} else if (e->key() == Qt::Key_Escape) {
e->ignore();
} else {
super::keyReleaseEvent(e);
}
}
}
@@ -94,6 +94,12 @@ public:
* because a default shortcut does not need to be saved to a file.
*/
QString export_shortcut();
protected:
virtual void keyPressEvent(QKeyEvent *e) override;
virtual void keyReleaseEvent(QKeyEvent *e) override;
private:
/**
* @brief Internal reference to the linked QAction