From 56c55a949854f9dd73b60e353be35bd31407cee0 Mon Sep 17 00:00:00 2001 From: Keshav Bhatt Date: Fri, 27 Jan 2023 02:13:28 +0530 Subject: chore: escape key to close child windows --- src/about.cpp | 8 ++++++++ src/about.h | 3 +++ src/downloadmanagerwidget.cpp | 8 ++++++++ src/downloadmanagerwidget.h | 2 ++ 4 files changed, 21 insertions(+) (limited to 'src') diff --git a/src/about.cpp b/src/about.cpp index ba54a7e..81657e8 100644 --- a/src/about.cpp +++ b/src/about.cpp @@ -92,6 +92,14 @@ void About::on_debugInfoButton_clicked() { } } +void About::keyPressEvent(QKeyEvent *e) +{ + if (e->key() == Qt::Key_Escape) + this->close(); + + QWidget::keyPressEvent(e); +} + void About::on_donate_2_clicked() { QDesktopServices::openUrl(QUrl("https://opencollective.com/whatsie")); } diff --git a/src/about.h b/src/about.h index 74bfe0d..cd9e978 100644 --- a/src/about.h +++ b/src/about.h @@ -2,6 +2,7 @@ #define ABOUT_H #include +#include namespace Ui { class About; @@ -15,6 +16,8 @@ public: explicit About(QWidget *parent = nullptr); ~About(); +protected slots: + void keyPressEvent(QKeyEvent *e); private slots: void on_debugInfoButton_clicked(); diff --git a/src/downloadmanagerwidget.cpp b/src/downloadmanagerwidget.cpp index 2d75287..e9865c8 100644 --- a/src/downloadmanagerwidget.cpp +++ b/src/downloadmanagerwidget.cpp @@ -56,3 +56,11 @@ void DownloadManagerWidget::on_open_download_dir_clicked() { QApplication::applicationName()) .toString()); } + +void DownloadManagerWidget::keyPressEvent(QKeyEvent *e) +{ + if (e->key() == Qt::Key_Escape) + this->close(); + + QWidget::keyPressEvent(e); +} diff --git a/src/downloadmanagerwidget.h b/src/downloadmanagerwidget.h index 7fa0950..4a8d059 100644 --- a/src/downloadmanagerwidget.h +++ b/src/downloadmanagerwidget.h @@ -75,6 +75,8 @@ public: // will be shown on the screen. void downloadRequested(QWebEngineDownloadItem *webItem); +protected slots: + void keyPressEvent(QKeyEvent *e); private slots: void on_open_download_dir_clicked(); -- cgit v1.2.3