From 4b3b862e111a41f265c169a8165e7a46ccef7ba9 Mon Sep 17 00:00:00 2001 From: Albert S Date: Sat, 29 Dec 2018 20:21:13 +0100 Subject: [PATCH] gui: handle ESC (to quit) and CTRL+L (focus on searchbar and select content) --- gui/mainwindow.cpp | 20 ++++++++++++++++++++ gui/mainwindow.h | 4 +++- gui/mainwindow.ui | 4 ++-- 3 files changed, 25 insertions(+), 3 deletions(-) diff --git a/gui/mainwindow.cpp b/gui/mainwindow.cpp index 8a1669a..a647561 100644 --- a/gui/mainwindow.cpp +++ b/gui/mainwindow.cpp @@ -58,6 +58,26 @@ bool MainWindow::pdfTabActive() return ui->tabWidget->currentIndex() == 1; } +void MainWindow::keyPressEvent(QKeyEvent *event) +{ + bool quit = ((event->modifiers() & Qt::ControlModifier && event->key() == Qt::Key_Q) || event->key() == Qt::Key_Escape); + if(quit) + { + qApp->quit(); + } + + if(event->modifiers() & Qt::ControlModifier) + { + + if(event->key() == Qt::Key_L) + { + ui->txtSearch->setFocus(); + ui->txtSearch->selectAll(); + } + } + QWidget::keyPressEvent(event); +} + void MainWindow::tabChanged() { if(pdfTabActive()) diff --git a/gui/mainwindow.h b/gui/mainwindow.h index 7ac1b4c..6ac5b4e 100644 --- a/gui/mainwindow.h +++ b/gui/mainwindow.h @@ -5,7 +5,7 @@ #include #include #include - +#include #include "searchworker.h" #include "pdfworker.h" namespace Ui { @@ -35,6 +35,7 @@ private: void connectSignals(); void makePdfPreview(); bool pdfTabActive(); + void keyPressEvent(QKeyEvent *event) override; unsigned int processedPdfPreviews; private slots: void lineEditReturnPressed(); @@ -46,6 +47,7 @@ private slots: void tabChanged(); void pdfPreviewReceived(PdfPreview preview); void comboScaleChanged(QString text); + }; #endif // MAINWINDOW_H diff --git a/gui/mainwindow.ui b/gui/mainwindow.ui index 69af7e1..8de1fd7 100644 --- a/gui/mainwindow.ui +++ b/gui/mainwindow.ui @@ -101,7 +101,7 @@ - 75% + 25% @@ -157,7 +157,7 @@ - TextLabel +