From 8f48ede957b1f52b00c45d561b115ed568ba31af Mon Sep 17 00:00:00 2001 From: Matt Signorini Date: Sat, 7 Oct 2017 17:19:55 +1100 Subject: [PATCH] Add keypress handler to the password generator widget so that esc quits in standalone mode. --- src/gui/PasswordGeneratorWidget.cpp | 15 +++++++++++++++ src/gui/PasswordGeneratorWidget.h | 3 +++ 2 files changed, 18 insertions(+) diff --git a/src/gui/PasswordGeneratorWidget.cpp b/src/gui/PasswordGeneratorWidget.cpp index d77634415..dd3cd5802 100644 --- a/src/gui/PasswordGeneratorWidget.cpp +++ b/src/gui/PasswordGeneratorWidget.cpp @@ -21,6 +21,7 @@ #include #include +#include #include "core/Config.h" #include "core/PasswordGenerator.h" @@ -149,6 +150,20 @@ void PasswordGeneratorWidget::setStandaloneMode(bool standalone) } } +void PasswordGeneratorWidget::keyPressEvent(QKeyEvent* e) +{ + if (!e->modifiers() || (e->modifiers() & Qt::KeypadModifier && e->key() == Qt::Key_Enter)) { + if (e->key() == Qt::Key_Escape && m_standalone == true) { + emit dialogTerminated(); + } else { + e->ignore(); + } + } + else { + e->ignore(); + } +} + void PasswordGeneratorWidget::regeneratePassword() { if (m_ui->tabWidget->currentIndex() == Password) { diff --git a/src/gui/PasswordGeneratorWidget.h b/src/gui/PasswordGeneratorWidget.h index 130106461..3d6d27a55 100644 --- a/src/gui/PasswordGeneratorWidget.h +++ b/src/gui/PasswordGeneratorWidget.h @@ -81,6 +81,9 @@ private: const QScopedPointer m_passwordGenerator; const QScopedPointer m_dicewareGenerator; const QScopedPointer m_ui; + +protected: + void keyPressEvent(QKeyEvent* e) override; }; #endif // KEEPASSX_PASSWORDGENERATORWIDGET_H