From f7a553177d4b969956bc04a0140fce34958971f5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Barbosa?= Date: Mon, 30 Jul 2018 22:44:18 +0100 Subject: [PATCH 1/3] gui: Add GUIUtil::ItemDelegate with keyEscapePressed signal --- src/qt/guiutil.cpp | 11 +++++++++++ src/qt/guiutil.h | 13 +++++++++++++ 2 files changed, 24 insertions(+) diff --git a/src/qt/guiutil.cpp b/src/qt/guiutil.cpp index 9dde2c392..955f5cdfe 100644 --- a/src/qt/guiutil.cpp +++ b/src/qt/guiutil.cpp @@ -49,6 +49,7 @@ #include #include #include +#include #include #include #include // for Qt::mightBeRichText @@ -927,4 +928,14 @@ void ClickableProgressBar::mouseReleaseEvent(QMouseEvent *event) Q_EMIT clicked(event->pos()); } +bool ItemDelegate::eventFilter(QObject *object, QEvent *event) +{ + if (event->type() == QEvent::KeyPress) { + if (static_cast(event)->key() == Qt::Key_Escape) { + Q_EMIT keyEscapePressed(); + } + } + return QItemDelegate::eventFilter(object, event); +} + } // namespace GUIUtil diff --git a/src/qt/guiutil.h b/src/qt/guiutil.h index 6aa65369f..5b32f03aa 100644 --- a/src/qt/guiutil.h +++ b/src/qt/guiutil.h @@ -10,6 +10,7 @@ #include #include +#include #include #include #include @@ -232,6 +233,18 @@ namespace GUIUtil typedef ClickableProgressBar ProgressBar; + class ItemDelegate : public QItemDelegate + { + Q_OBJECT + public: + ItemDelegate(QObject* parent) : QItemDelegate(parent) {} + + Q_SIGNALS: + void keyEscapePressed(); + + private: + bool eventFilter(QObject *object, QEvent *event); + }; } // namespace GUIUtil #endif // BITCOIN_QT_GUIUTIL_H From 4a43306a4f643cf0d356d5d5e16913541f1bc893 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Barbosa?= Date: Sat, 28 Jul 2018 23:45:05 +0100 Subject: [PATCH 2/3] gui: Reject edit address dialog when key escape is pressed --- src/qt/editaddressdialog.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/qt/editaddressdialog.cpp b/src/qt/editaddressdialog.cpp index f26a31158..6e7520e01 100644 --- a/src/qt/editaddressdialog.cpp +++ b/src/qt/editaddressdialog.cpp @@ -39,6 +39,10 @@ EditAddressDialog::EditAddressDialog(Mode _mode, QWidget *parent) : mapper = new QDataWidgetMapper(this); mapper->setSubmitPolicy(QDataWidgetMapper::ManualSubmit); + + GUIUtil::ItemDelegate* delegate = new GUIUtil::ItemDelegate(mapper); + connect(delegate, &GUIUtil::ItemDelegate::keyEscapePressed, this, &EditAddressDialog::reject); + mapper->setItemDelegate(delegate); } EditAddressDialog::~EditAddressDialog() From 7bf22bf0c21d13557ec46a67413819ebcabc3df0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Barbosa?= Date: Mon, 30 Jul 2018 22:47:48 +0100 Subject: [PATCH 3/3] gui: Reject options dialog when key escape is pressed --- src/qt/optionsdialog.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/qt/optionsdialog.cpp b/src/qt/optionsdialog.cpp index a57343f03..eea9a882b 100644 --- a/src/qt/optionsdialog.cpp +++ b/src/qt/optionsdialog.cpp @@ -115,6 +115,10 @@ OptionsDialog::OptionsDialog(QWidget *parent, bool enableWallet) : mapper->setSubmitPolicy(QDataWidgetMapper::ManualSubmit); mapper->setOrientation(Qt::Vertical); + GUIUtil::ItemDelegate* delegate = new GUIUtil::ItemDelegate(mapper); + connect(delegate, &GUIUtil::ItemDelegate::keyEscapePressed, this, &OptionsDialog::reject); + mapper->setItemDelegate(delegate); + /* setup/change UI elements when proxy IPs are invalid/valid */ ui->proxyIp->setCheckValidator(new ProxyAddressValidator(parent)); ui->proxyIpTor->setCheckValidator(new ProxyAddressValidator(parent));