2011-03-03 18:29:20 +01:00
|
|
|
/* ============================================================
|
|
|
|
* QupZilla - WebKit based browser
|
2013-01-25 22:42:20 +01:00
|
|
|
* Copyright (C) 2010-2013 David Rosca <nowrep@gmail.com>
|
2011-03-03 18:29:20 +01:00
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
* ============================================================ */
|
2011-03-02 16:57:41 +01:00
|
|
|
#include "websearchbar.h"
|
|
|
|
#include "qupzilla.h"
|
2012-01-21 23:19:38 +01:00
|
|
|
#include "mainapplication.h"
|
2012-01-21 20:27:45 +01:00
|
|
|
#include "tabbedwebview.h"
|
2011-10-21 23:26:34 +02:00
|
|
|
#include "webpage.h"
|
2012-08-10 10:20:07 +02:00
|
|
|
#include "settings.h"
|
2012-08-10 21:16:43 +02:00
|
|
|
#include "qzsettings.h"
|
2012-01-21 23:19:38 +01:00
|
|
|
#include "tabwidget.h"
|
2011-03-02 16:57:41 +01:00
|
|
|
#include "clickablelabel.h"
|
2011-06-06 19:38:37 +02:00
|
|
|
#include "buttonwithmenu.h"
|
2011-10-21 23:26:34 +02:00
|
|
|
#include "searchenginesmanager.h"
|
|
|
|
#include "searchenginesdialog.h"
|
|
|
|
#include "networkmanager.h"
|
2011-03-02 16:57:41 +01:00
|
|
|
|
2012-12-20 14:45:35 +01:00
|
|
|
#include <QMimeData>
|
|
|
|
#include <QAbstractItemView>
|
2012-02-29 18:33:50 +01:00
|
|
|
#include <QCompleter>
|
|
|
|
#include <QStringListModel>
|
|
|
|
#include <QMenu>
|
|
|
|
#include <QTimer>
|
|
|
|
#include <QWebFrame>
|
|
|
|
#include <QClipboard>
|
2012-08-31 15:19:07 +02:00
|
|
|
#include <QContextMenuEvent>
|
2012-02-29 18:33:50 +01:00
|
|
|
|
2012-03-07 20:01:57 +01:00
|
|
|
WebSearchBar_Button::WebSearchBar_Button(QWidget* parent)
|
2012-03-06 21:27:37 +01:00
|
|
|
: ClickableLabel(parent)
|
|
|
|
{
|
|
|
|
setObjectName("websearchbar-searchbutton");
|
|
|
|
setCursor(QCursor(Qt::PointingHandCursor));
|
|
|
|
setFocusPolicy(Qt::ClickFocus);
|
|
|
|
}
|
|
|
|
|
2012-03-07 20:01:57 +01:00
|
|
|
void WebSearchBar_Button::contextMenuEvent(QContextMenuEvent* event)
|
2012-03-06 21:27:37 +01:00
|
|
|
{
|
|
|
|
event->accept();
|
|
|
|
}
|
|
|
|
|
2012-10-01 11:26:07 +02:00
|
|
|
WebSearchBar::WebSearchBar(QupZilla* mainClass)
|
|
|
|
: LineEdit(mainClass)
|
2011-10-21 23:26:34 +02:00
|
|
|
, p_QupZilla(mainClass)
|
2012-01-24 15:39:20 +01:00
|
|
|
, m_pasteAndGoAction(0)
|
2012-01-24 18:23:43 +01:00
|
|
|
, m_clearAction(0)
|
2012-03-08 13:05:57 +01:00
|
|
|
, m_reloadingEngines(false)
|
2011-03-02 16:57:41 +01:00
|
|
|
{
|
2011-09-11 19:15:06 +02:00
|
|
|
setObjectName("websearchbar");
|
2012-05-27 14:05:28 +02:00
|
|
|
setDragEnabled(true);
|
2012-03-06 21:27:37 +01:00
|
|
|
|
|
|
|
m_buttonSearch = new WebSearchBar_Button(this);
|
2011-03-02 16:57:41 +01:00
|
|
|
|
2011-06-06 19:38:37 +02:00
|
|
|
m_boxSearchType = new ButtonWithMenu(this);
|
2011-09-11 19:15:06 +02:00
|
|
|
m_boxSearchType->setObjectName("websearchbar-searchprovider-comobobox");
|
2013-03-15 11:46:07 +01:00
|
|
|
// RTL Support
|
|
|
|
// If we don't add 'm_boxSearchType' by following code, then we should use suitable padding-left value
|
|
|
|
// but then, when typing RTL text the layout dynamically changed and within RTL layout direction
|
|
|
|
// padding-left is equivalent to padding-right and vice versa, and because style sheet is
|
|
|
|
// not changed dynamically this create padding problems.
|
2012-08-11 13:13:37 +02:00
|
|
|
addWidget(m_boxSearchType, LineEdit::LeftSide);
|
2011-03-02 16:57:41 +01:00
|
|
|
|
|
|
|
addWidget(m_buttonSearch, LineEdit::RightSide);
|
|
|
|
|
|
|
|
connect(m_buttonSearch, SIGNAL(clicked(QPoint)), this, SLOT(search()));
|
2012-01-18 16:52:30 +01:00
|
|
|
connect(m_buttonSearch, SIGNAL(middleClicked(QPoint)), this, SLOT(searchInNewTab()));
|
2011-06-06 19:38:37 +02:00
|
|
|
connect(m_boxSearchType, SIGNAL(activeItemChanged(ButtonWithMenu::Item)), this, SLOT(searchChanged(ButtonWithMenu::Item)));
|
2011-03-02 16:57:41 +01:00
|
|
|
|
|
|
|
setWidgetSpacing(0);
|
2011-10-03 19:39:32 +02:00
|
|
|
|
2011-10-21 23:26:34 +02:00
|
|
|
m_searchManager = mApp->searchEnginesManager();
|
|
|
|
connect(m_boxSearchType->menu(), SIGNAL(aboutToShow()), this, SLOT(aboutToShowMenu()));
|
|
|
|
|
|
|
|
m_completer = new QCompleter(this);
|
|
|
|
m_completer->setCompletionMode(QCompleter::UnfilteredPopupCompletion);
|
|
|
|
m_completerModel = new QStringListModel(this);
|
|
|
|
m_completer->setModel(m_completerModel);
|
|
|
|
m_completer->popup()->setMinimumHeight(90);
|
|
|
|
setCompleter(m_completer);
|
|
|
|
|
|
|
|
m_openSearchEngine = new OpenSearchEngine(this);
|
|
|
|
m_openSearchEngine->setNetworkAccessManager(mApp->networkManager());
|
2013-03-06 09:05:41 +01:00
|
|
|
connect(m_openSearchEngine, SIGNAL(suggestions(QStringList)), this, SLOT(addSuggestions(QStringList)));
|
|
|
|
connect(this, SIGNAL(textEdited(QString)), m_openSearchEngine, SLOT(requestSuggestions(QString)));
|
2011-10-21 23:26:34 +02:00
|
|
|
|
|
|
|
QTimer::singleShot(0, this, SLOT(setupEngines()));
|
|
|
|
}
|
|
|
|
|
|
|
|
void WebSearchBar::aboutToShowMenu()
|
|
|
|
{
|
|
|
|
QMenu* menu = m_boxSearchType->menu();
|
|
|
|
|
|
|
|
menu->addSeparator();
|
|
|
|
completeMenuWithAvailableEngines(menu);
|
|
|
|
menu->addSeparator();
|
|
|
|
menu->addAction(QIcon(":icons/menu/gear.png"), tr("Manage Search Engines"), this, SLOT(openSearchEnginesDialog()));
|
|
|
|
}
|
|
|
|
|
|
|
|
void WebSearchBar::addSuggestions(const QStringList &list)
|
|
|
|
{
|
2012-08-10 21:16:43 +02:00
|
|
|
if (qzSettings->showSearchSuggestions) {
|
2012-08-10 10:20:07 +02:00
|
|
|
QStringList list_ = list.mid(0, 6);
|
|
|
|
m_completerModel->setStringList(list_);
|
|
|
|
}
|
2011-03-02 16:57:41 +01:00
|
|
|
}
|
|
|
|
|
2011-10-21 23:26:34 +02:00
|
|
|
void WebSearchBar::openSearchEnginesDialog()
|
2011-03-02 16:57:41 +01:00
|
|
|
{
|
2012-01-18 18:36:10 +01:00
|
|
|
if (m_searchDialog) {
|
2011-12-09 21:56:01 +01:00
|
|
|
m_searchDialog.data()->raise();
|
|
|
|
m_searchDialog.data()->activateWindow();
|
2011-10-21 23:26:34 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
m_searchDialog = new SearchEnginesDialog(this);
|
2011-12-09 21:56:01 +01:00
|
|
|
m_searchDialog.data()->show();
|
2011-10-21 23:26:34 +02:00
|
|
|
}
|
|
|
|
|
2012-08-10 10:20:07 +02:00
|
|
|
void WebSearchBar::enableSearchSuggestions(bool enable)
|
|
|
|
{
|
|
|
|
Settings settings;
|
|
|
|
settings.beginGroup("SearchEngines");
|
|
|
|
settings.setValue("showSuggestions", enable);
|
|
|
|
settings.endGroup();
|
|
|
|
|
2012-08-10 21:16:43 +02:00
|
|
|
qzSettings->showSearchSuggestions = enable;
|
2012-08-10 10:20:07 +02:00
|
|
|
m_completerModel->setStringList(QStringList());
|
|
|
|
}
|
|
|
|
|
2011-10-21 23:26:34 +02:00
|
|
|
void WebSearchBar::setupEngines()
|
|
|
|
{
|
|
|
|
disconnect(m_searchManager, SIGNAL(enginesChanged()), this, SLOT(setupEngines()));
|
2012-03-08 13:05:57 +01:00
|
|
|
m_reloadingEngines = true;
|
2011-10-21 23:26:34 +02:00
|
|
|
|
|
|
|
QString activeEngine = m_searchManager->startingEngineName();
|
|
|
|
|
2011-11-06 17:01:23 +01:00
|
|
|
if (m_boxSearchType->allItems().count() != 0) {
|
2011-10-21 23:26:34 +02:00
|
|
|
activeEngine = m_activeEngine.name;
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
2011-10-21 23:26:34 +02:00
|
|
|
|
|
|
|
m_boxSearchType->clearItems();
|
|
|
|
|
2013-03-06 09:05:41 +01:00
|
|
|
foreach (const SearchEngine &en, m_searchManager->allEngines()) {
|
2011-10-21 23:26:34 +02:00
|
|
|
ButtonWithMenu::Item item;
|
|
|
|
item.icon = en.icon;
|
|
|
|
item.text = en.name;
|
|
|
|
QVariant v;
|
|
|
|
v.setValue<SearchEngine>(en);
|
|
|
|
item.userData = v;
|
|
|
|
|
|
|
|
m_boxSearchType->addItem(item);
|
|
|
|
|
2011-11-06 17:01:23 +01:00
|
|
|
if (item.text == activeEngine) {
|
2012-02-28 18:57:05 +01:00
|
|
|
m_boxSearchType->setCurrentItem(item, false);
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
2011-10-21 23:26:34 +02:00
|
|
|
}
|
|
|
|
|
2012-03-08 13:05:57 +01:00
|
|
|
searchChanged(m_boxSearchType->currentItem());
|
2012-02-28 18:57:05 +01:00
|
|
|
|
2011-10-21 23:26:34 +02:00
|
|
|
connect(m_searchManager, SIGNAL(enginesChanged()), this, SLOT(setupEngines()));
|
2012-03-08 13:05:57 +01:00
|
|
|
m_reloadingEngines = false;
|
2011-03-02 16:57:41 +01:00
|
|
|
}
|
|
|
|
|
2012-03-08 13:05:57 +01:00
|
|
|
void WebSearchBar::searchChanged(const ButtonWithMenu::Item &item)
|
2011-03-02 16:57:41 +01:00
|
|
|
{
|
2012-12-05 11:53:56 +01:00
|
|
|
selectAll();
|
|
|
|
setFocus();
|
2011-06-06 19:38:37 +02:00
|
|
|
setPlaceholderText(item.text);
|
2011-10-21 23:26:34 +02:00
|
|
|
m_completerModel->setStringList(QStringList());
|
|
|
|
|
|
|
|
m_activeEngine = item.userData.value<SearchEngine>();
|
|
|
|
|
|
|
|
m_openSearchEngine->setSuggestionsUrl(m_activeEngine.suggestionsUrl);
|
|
|
|
m_openSearchEngine->setSuggestionsParameters(m_activeEngine.suggestionsParameters);
|
|
|
|
|
|
|
|
m_searchManager->setActiveEngine(m_activeEngine);
|
2012-02-11 11:38:02 +01:00
|
|
|
|
2012-09-26 15:06:05 +02:00
|
|
|
if (qzSettings->searchOnEngineChange && !m_reloadingEngines && !text().isEmpty()) {
|
2012-02-11 11:38:02 +01:00
|
|
|
search();
|
|
|
|
}
|
2011-03-02 16:57:41 +01:00
|
|
|
}
|
|
|
|
|
2012-09-26 15:06:05 +02:00
|
|
|
void WebSearchBar::instantSearchChanged(bool enable)
|
|
|
|
{
|
|
|
|
Settings settings;
|
|
|
|
settings.beginGroup("SearchEngines");
|
|
|
|
settings.setValue("SearchOnEngineChange", enable);
|
|
|
|
settings.endGroup();
|
|
|
|
qzSettings->searchOnEngineChange = enable;
|
|
|
|
}
|
|
|
|
|
2011-03-02 16:57:41 +01:00
|
|
|
void WebSearchBar::search()
|
|
|
|
{
|
2012-01-18 16:52:30 +01:00
|
|
|
p_QupZilla->weView()->setFocus();
|
2013-11-09 13:32:03 +01:00
|
|
|
|
|
|
|
SearchEnginesManager::SearchResult res = m_searchManager->searchResult(m_activeEngine, text());
|
|
|
|
p_QupZilla->weView()->load(res.request, res.operation, res.data);
|
2012-01-18 16:52:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void WebSearchBar::searchInNewTab()
|
|
|
|
{
|
2011-03-02 16:57:41 +01:00
|
|
|
p_QupZilla->weView()->setFocus();
|
2013-11-09 13:32:03 +01:00
|
|
|
|
|
|
|
int index = p_QupZilla->tabWidget()->addView(QUrl());
|
|
|
|
|
|
|
|
SearchEnginesManager::SearchResult res = m_searchManager->searchResult(m_activeEngine, text());
|
|
|
|
p_QupZilla->weView(index)->load(res.request, res.operation, res.data);
|
2011-03-02 16:57:41 +01:00
|
|
|
}
|
|
|
|
|
2011-11-06 17:01:23 +01:00
|
|
|
void WebSearchBar::completeMenuWithAvailableEngines(QMenu* menu)
|
2011-10-21 23:26:34 +02:00
|
|
|
{
|
|
|
|
WebView* view = p_QupZilla->weView();
|
2012-01-21 20:27:45 +01:00
|
|
|
QWebFrame* frame = view->page()->mainFrame();
|
2011-10-21 23:26:34 +02:00
|
|
|
|
|
|
|
QWebElementCollection elements = frame->documentElement().findAll(QLatin1String("link[rel=search]"));
|
2013-03-06 09:05:41 +01:00
|
|
|
foreach (const QWebElement &element, elements) {
|
2012-09-05 19:57:36 +02:00
|
|
|
if (element.attribute("type") != QLatin1String("application/opensearchdescription+xml")) {
|
2011-10-21 23:26:34 +02:00
|
|
|
continue;
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
2012-01-31 21:10:22 +01:00
|
|
|
QUrl url = view->url().resolved(QUrl::fromEncoded(element.attribute("href").toUtf8()));
|
2011-10-21 23:26:34 +02:00
|
|
|
QString title = element.attribute("title");
|
|
|
|
|
2011-11-06 17:01:23 +01:00
|
|
|
if (url.isEmpty()) {
|
2011-10-21 23:26:34 +02:00
|
|
|
continue;
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
|
|
|
if (title.isEmpty()) {
|
2011-10-21 23:26:34 +02:00
|
|
|
title = view->title();
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
2011-10-21 23:26:34 +02:00
|
|
|
|
|
|
|
menu->addAction(view->icon(), tr("Add %1 ...").arg(title), this, SLOT(addEngineFromAction()))->setData(url);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void WebSearchBar::addEngineFromAction()
|
|
|
|
{
|
|
|
|
if (QAction* action = qobject_cast<QAction*>(sender())) {
|
|
|
|
m_searchManager->addEngine(action->data().toUrl());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-01-24 15:39:20 +01:00
|
|
|
void WebSearchBar::pasteAndGo()
|
|
|
|
{
|
|
|
|
clear();
|
|
|
|
paste();
|
|
|
|
search();
|
|
|
|
}
|
|
|
|
|
|
|
|
void WebSearchBar::contextMenuEvent(QContextMenuEvent* event)
|
|
|
|
{
|
|
|
|
Q_UNUSED(event)
|
|
|
|
|
|
|
|
if (!m_pasteAndGoAction) {
|
2012-01-24 18:23:43 +01:00
|
|
|
m_pasteAndGoAction = new QAction(QIcon::fromTheme("edit-paste"), tr("Paste And &Search"), this);
|
|
|
|
m_pasteAndGoAction->setShortcut(QKeySequence("Ctrl+Shift+V"));
|
2012-01-24 15:39:20 +01:00
|
|
|
connect(m_pasteAndGoAction, SIGNAL(triggered()), this, SLOT(pasteAndGo()));
|
|
|
|
}
|
|
|
|
|
2012-01-24 18:23:43 +01:00
|
|
|
if (!m_clearAction) {
|
|
|
|
m_clearAction = new QAction(QIcon::fromTheme("edit-clear"), tr("Clear All"), this);
|
|
|
|
connect(m_clearAction, SIGNAL(triggered()), this, SLOT(clear()));
|
|
|
|
}
|
|
|
|
|
2012-01-24 15:39:20 +01:00
|
|
|
QMenu* tempMenu = createStandardContextMenu();
|
2012-10-01 11:26:07 +02:00
|
|
|
QMenu menu(this);
|
2012-01-24 15:39:20 +01:00
|
|
|
|
|
|
|
int i = 0;
|
2013-03-06 09:05:41 +01:00
|
|
|
foreach (QAction* act, tempMenu->actions()) {
|
2012-10-01 11:26:07 +02:00
|
|
|
menu.addAction(act);
|
2012-01-24 15:39:20 +01:00
|
|
|
|
2012-01-24 18:23:43 +01:00
|
|
|
switch (i) {
|
|
|
|
case 0:
|
|
|
|
act->setIcon(QIcon::fromTheme("edit-undo"));
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
act->setIcon(QIcon::fromTheme("edit-redo"));
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
act->setIcon(QIcon::fromTheme("edit-cut"));
|
|
|
|
break;
|
|
|
|
case 4:
|
|
|
|
act->setIcon(QIcon::fromTheme("edit-copy"));
|
|
|
|
break;
|
|
|
|
case 5:
|
|
|
|
act->setIcon(QIcon::fromTheme("edit-paste"));
|
2012-10-01 11:26:07 +02:00
|
|
|
menu.addAction(act);
|
|
|
|
menu.addAction(m_pasteAndGoAction);
|
2012-01-24 18:23:43 +01:00
|
|
|
break;
|
|
|
|
case 6:
|
|
|
|
act->setIcon(QIcon::fromTheme("edit-delete"));
|
2012-10-01 11:26:07 +02:00
|
|
|
menu.addAction(act);
|
|
|
|
menu.addAction(m_clearAction);
|
2012-01-24 18:23:43 +01:00
|
|
|
break;
|
|
|
|
case 8:
|
|
|
|
act->setIcon(QIcon::fromTheme("edit-select-all"));
|
|
|
|
break;
|
2012-01-24 15:39:20 +01:00
|
|
|
}
|
|
|
|
++i;
|
|
|
|
}
|
|
|
|
|
2012-10-01 11:26:07 +02:00
|
|
|
menu.addSeparator();
|
|
|
|
QAction* act = menu.addAction(tr("Show suggestions"));
|
2012-08-10 10:20:07 +02:00
|
|
|
act->setCheckable(true);
|
2012-08-10 21:16:43 +02:00
|
|
|
act->setChecked(qzSettings->showSearchSuggestions);
|
2012-08-10 10:20:07 +02:00
|
|
|
connect(act, SIGNAL(triggered(bool)), this, SLOT(enableSearchSuggestions(bool)));
|
|
|
|
|
2012-10-01 11:26:07 +02:00
|
|
|
QAction* instantSearch = menu.addAction(tr("Search when engine changed"));
|
2012-09-26 15:06:05 +02:00
|
|
|
instantSearch->setCheckable(true);
|
|
|
|
instantSearch->setChecked(qzSettings->searchOnEngineChange);
|
|
|
|
connect(instantSearch, SIGNAL(triggered(bool)), this, SLOT(instantSearchChanged(bool)));
|
|
|
|
|
2012-01-24 15:39:20 +01:00
|
|
|
m_pasteAndGoAction->setEnabled(!QApplication::clipboard()->text().isEmpty());
|
|
|
|
|
2012-10-11 19:57:12 +02:00
|
|
|
// Prevent choosing first option with double rightclick
|
2012-03-23 17:29:12 +01:00
|
|
|
QPoint pos = event->globalPos();
|
2012-01-24 15:39:20 +01:00
|
|
|
QPoint p(pos.x(), pos.y() + 1);
|
2012-10-01 11:26:07 +02:00
|
|
|
menu.exec(p);
|
2012-10-11 19:57:12 +02:00
|
|
|
|
|
|
|
tempMenu->deleteLater();
|
2012-01-24 15:39:20 +01:00
|
|
|
}
|
|
|
|
|
2011-03-17 17:03:04 +01:00
|
|
|
void WebSearchBar::focusOutEvent(QFocusEvent* e)
|
2011-03-02 16:57:41 +01:00
|
|
|
{
|
|
|
|
if (text().isEmpty()) {
|
2012-02-28 18:57:05 +01:00
|
|
|
QString search = m_boxSearchType->currentItem().text;
|
2011-03-02 16:57:41 +01:00
|
|
|
setPlaceholderText(search);
|
|
|
|
}
|
|
|
|
|
2013-03-15 11:46:07 +01:00
|
|
|
LineEdit::focusOutEvent(e);
|
2011-03-02 16:57:41 +01:00
|
|
|
}
|
2011-08-27 17:52:44 +02:00
|
|
|
|
|
|
|
void WebSearchBar::dropEvent(QDropEvent* event)
|
|
|
|
{
|
|
|
|
if (event->mimeData()->hasText()) {
|
|
|
|
QString dropText = event->mimeData()->text();
|
|
|
|
setText(dropText);
|
|
|
|
search();
|
2012-03-01 18:32:53 +01:00
|
|
|
|
|
|
|
QFocusEvent event(QFocusEvent::FocusOut);
|
2013-03-15 11:46:07 +01:00
|
|
|
LineEdit::focusOutEvent(&event);
|
2011-08-27 17:52:44 +02:00
|
|
|
return;
|
|
|
|
}
|
2013-03-15 11:46:07 +01:00
|
|
|
|
|
|
|
LineEdit::dropEvent(event);
|
2011-08-27 17:52:44 +02:00
|
|
|
}
|
2012-01-18 16:52:30 +01:00
|
|
|
|
|
|
|
void WebSearchBar::keyPressEvent(QKeyEvent* event)
|
|
|
|
{
|
|
|
|
switch (event->key()) {
|
2012-01-24 20:12:00 +01:00
|
|
|
case Qt::Key_V:
|
|
|
|
if (event->modifiers() == (Qt::ControlModifier | Qt::ShiftModifier)) {
|
|
|
|
pasteAndGo();
|
|
|
|
event->accept();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2012-01-18 16:52:30 +01:00
|
|
|
case Qt::Key_Return:
|
|
|
|
case Qt::Key_Enter:
|
2012-01-21 19:26:47 +01:00
|
|
|
if (event->modifiers() == Qt::AltModifier) {
|
2012-01-18 16:52:30 +01:00
|
|
|
searchInNewTab();
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
search();
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2013-11-21 18:23:11 +01:00
|
|
|
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;
|
|
|
|
|
2012-01-18 16:52:30 +01:00
|
|
|
default:
|
2012-01-31 11:35:03 +01:00
|
|
|
break;
|
2012-01-18 16:52:30 +01:00
|
|
|
}
|
2012-01-31 21:10:22 +01:00
|
|
|
|
2012-01-31 11:35:03 +01:00
|
|
|
LineEdit::keyPressEvent(event);
|
2012-01-18 16:52:30 +01:00
|
|
|
}
|