From 65c61cf5ef74ef4be386e0e6a9bc056f34bc6adc Mon Sep 17 00:00:00 2001 From: Arno Date: Sat, 3 Feb 2018 04:19:54 +0100 Subject: Add keyboard shortcuts in SearchDialog CTRL+F: search filename CTRL+L: select all and focus search CTRL+M: search actor CTRL+T: search title CTRL+X: hide Unfortunately, it's surprisingly hard to capture CTRL+A, so I chose CTRL +M (m for model) for actor search. CTRL+A is consumed by some other Widget and never reaches SearchDialog. Maybe an EventFilter in the parent or the MainWindow would work, but that's not worth it. --- filewidget.cpp | 1 + searchdialog.cpp | 22 ++++++++++++++++++++-- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/filewidget.cpp b/filewidget.cpp index 51426a4..a56d1fa 100644 --- a/filewidget.cpp +++ b/filewidget.cpp @@ -924,6 +924,7 @@ void FileWidget::keyPressEvent(QKeyEvent *e){ if(e->key() == Qt::Key_S && (e->modifiers() & Qt::ControlModifier)){ mSearchDlg->show(); mSearchDlg->raise(); + mSearchDlg->setFocus(); goto exit; } if(e->key() == Qt::Key_D && (e->modifiers() & Qt::ControlModifier)){ diff --git a/searchdialog.cpp b/searchdialog.cpp index 0cb442c..04fbf18 100644 --- a/searchdialog.cpp +++ b/searchdialog.cpp @@ -22,10 +22,11 @@ SearchDialog::SearchDialog(QWidget *parent, Qt::WindowFlags f) : QDialog(parent, //search bar QLabel *typeL = new QLabel(tr("Search by:")); mTypeSel = new QComboBox; - mTypeSel->addItem(tr("Title"), Title); - mTypeSel->addItem(tr("Filename"), Filename); mTypeSel->addItem(tr("Actor"), Actors); + mTypeSel->addItem(tr("Filename"), Filename); + mTypeSel->addItem(tr("Title"), Title); connect(mTypeSel, QOverload::of(&QComboBox::activated), this, &SearchDialog::doSearch); + connect(mTypeSel, QOverload::of(&QComboBox::currentIndexChanged), this, &SearchDialog::doSearch); mSearch = new QLineEdit; QPushButton *goB = new QPushButton(tr("Go!")); connect(goB, &QPushButton::clicked, this, &SearchDialog::doSearch); @@ -321,6 +322,23 @@ void SearchDialog::keyPressEvent(QKeyEvent *e){ hide(); goto exit; } + if(e->key() == Qt::Key_L && (e->modifiers() & Qt::ControlModifier)){ + mSearch->selectAll(); + mSearch->setFocus(); + goto exit; + } + if(e->key() == Qt::Key_M && (e->modifiers() & Qt::ControlModifier)){ + mTypeSel->setCurrentIndex(0); + goto exit; + } + if(e->key() == Qt::Key_F && (e->modifiers() & Qt::ControlModifier)){ + mTypeSel->setCurrentIndex(1); + goto exit; + } + if(e->key() == Qt::Key_T && (e->modifiers() & Qt::ControlModifier)){ + mTypeSel->setCurrentIndex(2); + goto exit; + } return QDialog::keyPressEvent(e); exit: -- cgit v1.2.3-70-g09d2