From a49e574f835331090be47692dfddc1376890eab6 Mon Sep 17 00:00:00 2001 From: nowrep Date: Thu, 21 Nov 2013 18:23:11 +0100 Subject: [PATCH] [WebSearchBar] Ctrl+Up/Down for changing search engines. Closes #1090 --- CHANGELOG | 1 + src/lib/navigation/websearchbar.cpp | 12 ++++++++++++ src/lib/tools/buttonwithmenu.cpp | 23 +++++++++++++++++++++++ src/lib/tools/buttonwithmenu.h | 4 ++++ 4 files changed, 40 insertions(+) diff --git a/CHANGELOG b/CHANGELOG index 3f9e24058..67dc5f670 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -15,6 +15,7 @@ Version 1.5.0 * pagescreen can now save output into number of formats, including PDF * proxy exceptions now supports wildcards (*, ?) * cancel upload when trying to upload non-readable files + * select previous / next engines with ctrl+up/down in websearchbar * GreaseMonkey: added icon in statusbar * GreaseMonkey: added support for GM_Settings * GreaseMonkey: fixed userscripts when first loading plugin diff --git a/src/lib/navigation/websearchbar.cpp b/src/lib/navigation/websearchbar.cpp index bdf998a66..34d12b770 100644 --- a/src/lib/navigation/websearchbar.cpp +++ b/src/lib/navigation/websearchbar.cpp @@ -377,6 +377,18 @@ void WebSearchBar::keyPressEvent(QKeyEvent* event) } break; + case Qt::Key_Up: + if (event->modifiers() == Qt::ControlModifier) { + m_boxSearchType->selectPreviousItem(); + } + break; + + case Qt::Key_Down: + if (event->modifiers() == Qt::ControlModifier) { + m_boxSearchType->selectNextItem(); + } + break; + default: break; } diff --git a/src/lib/tools/buttonwithmenu.cpp b/src/lib/tools/buttonwithmenu.cpp index e9c3109be..6362ce249 100644 --- a/src/lib/tools/buttonwithmenu.cpp +++ b/src/lib/tools/buttonwithmenu.cpp @@ -45,6 +45,24 @@ void ButtonWithMenu::clearItems() m_items.clear(); } +void ButtonWithMenu::selectNextItem() +{ + int index = m_items.indexOf(m_currentItem) + 1; + + if (index < m_items.size()) { + setCurrentIndex(index); + } +} + +void ButtonWithMenu::selectPreviousItem() +{ + int index = m_items.indexOf(m_currentItem) - 1; + + if (index > 0) { + setCurrentIndex(index); + } +} + void ButtonWithMenu::addItem(const Item &item) { m_items.append(item); @@ -99,6 +117,11 @@ void ButtonWithMenu::setCurrentItem(const Item &item, bool emitSignal) } } +void ButtonWithMenu::setCurrentIndex(int index, bool emitSignal) +{ + setCurrentItem(m_items.at(index), emitSignal); +} + void ButtonWithMenu::wheelEvent(QWheelEvent* event) { int currItemIndex = m_items.indexOf(m_currentItem); diff --git a/src/lib/tools/buttonwithmenu.h b/src/lib/tools/buttonwithmenu.h index a478ff3eb..8b78215a2 100644 --- a/src/lib/tools/buttonwithmenu.h +++ b/src/lib/tools/buttonwithmenu.h @@ -57,6 +57,7 @@ public: void addItems(const QVector &items); void removeItem(const Item &item); void setCurrentItem(const Item &item, bool emitSignal = true); + void setCurrentIndex(int index, bool emitSignal = true); Item currentItem(); QVector allItems() { return m_items; } @@ -70,6 +71,9 @@ signals: public slots: void clearItems(); + void selectNextItem(); + void selectPreviousItem(); + private slots: void setCurrentItem(); void generateMenu();