From 13e24130112bcb1b9752993956b25fa0647a8229 Mon Sep 17 00:00:00 2001 From: Jean-Francois Dockes Date: Wed, 3 Feb 2010 15:04:22 +0100 Subject: [PATCH] QT GUI: added shortcut to return focus to the search entry --- src/qtgui/rclmain_w.cpp | 44 +++++++++++++++++++++++++++++++++-------- src/qtgui/rclmain_w.h | 1 + 2 files changed, 37 insertions(+), 8 deletions(-) diff --git a/src/qtgui/rclmain_w.cpp b/src/qtgui/rclmain_w.cpp index acb74ddd..2af8f1ec 100644 --- a/src/qtgui/rclmain_w.cpp +++ b/src/qtgui/rclmain_w.cpp @@ -40,6 +40,13 @@ using std::pair; #include #include #include +#include +#undef RCLQT4 +#define RCLQT3 1 +#else +#undef RCLQT3 +#define RCLQT4 1 +#include #endif #include @@ -58,7 +65,6 @@ using std::pair; #include #include #include - #include "recoll.h" #include "debuglog.h" #include "mimehandler.h" @@ -87,7 +93,7 @@ extern "C" int XFlush(void *); QString g_stringAllStem, g_stringNoStem; // Taken from qt designer. Don't know why it's needed. -#if (QT_VERSION < 0x040000) +#if RCLQT3 static QIconSet createIconSet(const QString &name) { QIconSet ic(QPixmap::fromMimeSource(name)); @@ -167,13 +173,25 @@ void RclMain::init() } preferencesMenu->setItemChecked(curid, true); + // A shortcut to get the focus back to the search entry. + QKeySequence seq("Ctrl+Shift+s"); +#if RCLQT4 + QShortcut *sc = new QShortcut(seq, this); + connect(sc, SIGNAL (activated()), this, SLOT (focusToSearch())); +#else + QAccel *sc = new QAccel(this); + sc->insertItem(seq); + connect(sc, SIGNAL (activated(int)), this, SLOT (focusToSearch())); +#endif + + // Toolbar+combobox version of the category selector QComboBox *catgCMB = 0; if (prefs.catgToolBar) { QToolBar *catgToolBar = new QToolBar(this); catgCMB = new QComboBox(FALSE, catgToolBar, "catCMB"); catgCMB->insertItem(tr("All")); -#if (QT_VERSION >= 0x040000) +#if RCLQT4 catgToolBar->setObjectName(QString::fromUtf8("catgToolBar")); catgCMB->setToolTip(tr("Document category filter")); catgToolBar->addWidget(catgCMB); @@ -182,7 +200,7 @@ void RclMain::init() } // Document categories buttons -#if (QT_VERSION < 0x040000) +#if RCLQT3 catgBGRP->setColumnLayout(1, Qt::Vertical); connect(catgBGRP, SIGNAL(clicked(int)), this, SLOT(catgFilter(int))); #else @@ -206,12 +224,12 @@ void RclMain::init() but->setText(tr(catgnm)); if (prefs.catgToolBar && catgCMB) catgCMB->insertItem(tr(catgnm)); -#if (QT_VERSION >= 0x040000) +#if RCLQT4 bgrphbox->addWidget(but); bgrp->addButton(but, bgrpid++); #endif } -#if (QT_VERSION < 0x040000) +#if RCLQT3 catgBGRP->setButton(0); #else catgBGRP->setLayout(bgrphbox); @@ -222,7 +240,7 @@ void RclMain::init() // Connections connect(sSearch, SIGNAL(startSearch(RefCntr)), this, SLOT(startSearch(RefCntr))); -#if QT_VERSION >= 0x040000 +#if RCLQT4 sSearch->queryText->installEventFilter(this); #else sSearch->queryText->lineEdit()->installEventFilter(this); @@ -291,7 +309,7 @@ void RclMain::init() // speeded up during indexing periodictimer->start(1000); -#if (QT_VERSION < 0x040000) +#if RCLQT3 nextPageAction->setIconSet(createIconSet("nextpage.png")); prevPageAction->setIconSet(createIconSet("prevpage.png")); firstPageAction->setIconSet(createIconSet("firstpage.png")); @@ -369,6 +387,16 @@ void RclMain::initDbOpen() } } +void RclMain::focusToSearch() +{ + LOGDEB(("Giving focus to sSearch\n")); + sSearch->queryText->setFocus( +#if RCLQT4 + Qt::ShortcutFocusReason +#endif + ); +} + void RclMain::setStemLang(int id) { LOGDEB(("RclMain::setStemLang(%d)\n", id)); diff --git a/src/qtgui/rclmain_w.h b/src/qtgui/rclmain_w.h index c5648120..029b6ed6 100644 --- a/src/qtgui/rclmain_w.h +++ b/src/qtgui/rclmain_w.h @@ -112,6 +112,7 @@ public slots: virtual void catgFilter(int); virtual void initDbOpen(); virtual void toggleFullScreen(); + virtual void focusToSearch(); signals: void stemLangChanged(const QString& lang);