diff --git a/src/lib/navigation/completer/locationcompleter.cpp b/src/lib/navigation/completer/locationcompleter.cpp index 37de7ea28..91c142dbc 100644 --- a/src/lib/navigation/completer/locationcompleter.cpp +++ b/src/lib/navigation/completer/locationcompleter.cpp @@ -141,6 +141,7 @@ void LocationCompleter::slotPopupClosed() disconnect(s_view, SIGNAL(indexCtrlActivated(QModelIndex)), this, SLOT(indexCtrlActivated(QModelIndex))); disconnect(s_view, SIGNAL(indexShiftActivated(QModelIndex)), this, SLOT(indexShiftActivated(QModelIndex))); disconnect(s_view, SIGNAL(indexDeleteRequested(QModelIndex)), this, SLOT(indexDeleteRequested(QModelIndex))); + disconnect(s_view, &LocationCompleterView::loadRequested, this, &LocationCompleter::loadRequested); disconnect(s_view->selectionModel(), SIGNAL(currentChanged(QModelIndex,QModelIndex)), this, SLOT(currentChanged(QModelIndex))); emit popupClosed(); @@ -365,6 +366,7 @@ void LocationCompleter::showPopup() connect(s_view, SIGNAL(indexCtrlActivated(QModelIndex)), this, SLOT(indexCtrlActivated(QModelIndex))); connect(s_view, SIGNAL(indexShiftActivated(QModelIndex)), this, SLOT(indexShiftActivated(QModelIndex))); connect(s_view, SIGNAL(indexDeleteRequested(QModelIndex)), this, SLOT(indexDeleteRequested(QModelIndex))); + connect(s_view, &LocationCompleterView::loadRequested, this, &LocationCompleter::loadRequested); connect(s_view->selectionModel(), SIGNAL(currentChanged(QModelIndex,QModelIndex)), this, SLOT(currentChanged(QModelIndex))); s_view->createWinId(); diff --git a/src/lib/navigation/completer/locationcompleter.h b/src/lib/navigation/completer/locationcompleter.h index 6d60ec2ad..c54c92ab9 100644 --- a/src/lib/navigation/completer/locationcompleter.h +++ b/src/lib/navigation/completer/locationcompleter.h @@ -1,6 +1,6 @@ /* ============================================================ * Falkon - Qt web browser -* Copyright (C) 2010-2017 David Rosca +* Copyright (C) 2010-2018 David Rosca * * 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 @@ -26,6 +26,7 @@ class QUrl; class QModelIndex; class LocationBar; +class LoadRequest; class BrowserWindow; class OpenSearchEngine; class LocationCompleterModel; @@ -53,6 +54,7 @@ signals: void clearCompletion(); void popupClosed(); void cancelRefreshJob(); + void loadRequested(const LoadRequest &request); private slots: void refreshJobFinished(); diff --git a/src/lib/navigation/completer/locationcompleterview.cpp b/src/lib/navigation/completer/locationcompleterview.cpp index c19f79c56..00b61f0e5 100644 --- a/src/lib/navigation/completer/locationcompleterview.cpp +++ b/src/lib/navigation/completer/locationcompleterview.cpp @@ -20,16 +20,20 @@ #include "locationcompleterdelegate.h" #include "toolbutton.h" #include "iconprovider.h" +#include "mainapplication.h" #include "searchenginesdialog.h" +#include "searchenginesmanager.h" +#include "loadrequest.h" #include #include #include #include +#include +#include LocationCompleterView::LocationCompleterView() : QWidget(nullptr) - , m_ignoreNextMouseMove(false) { setAttribute(Qt::WA_ShowWithoutActivating); setAttribute(Qt::WA_X11NetWmWindowTypeCombo); @@ -43,7 +47,6 @@ LocationCompleterView::LocationCompleterView() QVBoxLayout *layout = new QVBoxLayout(this); layout->setContentsMargins(0, 0, 0, 0); layout->setSpacing(0); - setLayout(layout); m_view = new QListView(this); layout->addWidget(m_view); @@ -63,15 +66,23 @@ LocationCompleterView::LocationCompleterView() QWidget *searchWidget = new QWidget(this); QHBoxLayout *searchLayout = new QHBoxLayout(searchWidget); - searchLayout->setContentsMargins(2, 2, 2, 2); - searchWidget->setLayout(searchLayout); + searchLayout->setContentsMargins(10, 4, 4, 4); ToolButton *searchSettingsButton = new ToolButton(this); + searchSettingsButton->setIcon(IconProvider::settingsIcon()); searchSettingsButton->setToolTip(tr("Manage Search Engines")); searchSettingsButton->setAutoRaise(true); - searchSettingsButton->setIcon(IconProvider::settingsIcon()); + searchSettingsButton->setIconSize(QSize(16, 16)); connect(searchSettingsButton, &ToolButton::clicked, this, &LocationCompleterView::openSearchEnginesDialog); + QLabel *searchLabel = new QLabel(tr("Search with:")); + m_searchEnginesLayout = new QHBoxLayout(); + + setupSearchEngines(); + connect(mApp->searchEnginesManager(), &SearchEnginesManager::enginesChanged, this, &LocationCompleterView::setupSearchEngines); + + searchLayout->addWidget(searchLabel); + searchLayout->addLayout(m_searchEnginesLayout); searchLayout->addStretch(); searchLayout->addWidget(searchSettingsButton); @@ -105,6 +116,7 @@ QItemSelectionModel *LocationCompleterView::selectionModel() const void LocationCompleterView::setOriginalText(const QString &originalText) { + m_originalText = originalText; m_delegate->setOriginalText(originalText); } @@ -298,11 +310,6 @@ bool LocationCompleterView::eventFilter(QObject* object, QEvent* event) break; } - case QEvent::Show: - // Don't hover item when showing completer and mouse is currently in rect - m_ignoreNextMouseMove = true; - break; - case QEvent::Wheel: case QEvent::MouseButtonPress: if (!underMouse()) { @@ -345,6 +352,26 @@ void LocationCompleterView::close() emit closed(); } +void LocationCompleterView::setupSearchEngines() +{ + while (m_searchEnginesLayout->count() != 0) { + delete m_searchEnginesLayout->takeAt(0); + } + + const auto engines = mApp->searchEnginesManager()->allEngines(); + for (const SearchEngine &engine : engines) { + ToolButton *button = new ToolButton(this); + button->setIcon(engine.icon); + button->setToolTip(engine.name); + button->setAutoRaise(true); + button->setIconSize(QSize(16, 16)); + connect(button, &ToolButton::clicked, this, [=]() { + emit loadRequested(mApp->searchEnginesManager()->searchResult(engine, m_originalText)); + }); + m_searchEnginesLayout->addWidget(button); + } +} + void LocationCompleterView::openSearchEnginesDialog() { SearchEnginesDialog *dialog = new SearchEnginesDialog(focusProxy()); diff --git a/src/lib/navigation/completer/locationcompleterview.h b/src/lib/navigation/completer/locationcompleterview.h index abaa59b1b..783240800 100644 --- a/src/lib/navigation/completer/locationcompleterview.h +++ b/src/lib/navigation/completer/locationcompleterview.h @@ -22,8 +22,11 @@ #include "qzcommon.h" +class LoadRequest; class LocationCompleterDelegate; +class QHBoxLayout; + class FALKON_EXPORT LocationCompleterView : public QWidget { Q_OBJECT @@ -46,6 +49,7 @@ public: signals: void closed(); + void loadRequested(const LoadRequest &request); void indexActivated(const QModelIndex &index); void indexCtrlActivated(const QModelIndex &index); @@ -56,12 +60,13 @@ public slots: void close(); private: + void setupSearchEngines(); void openSearchEnginesDialog(); - bool m_ignoreNextMouseMove; - QListView *m_view; LocationCompleterDelegate *m_delegate; + QHBoxLayout *m_searchEnginesLayout; + QString m_originalText; }; #endif // LOCATIONCOMPLETERVIEW_H diff --git a/src/lib/navigation/locationbar.cpp b/src/lib/navigation/locationbar.cpp index 3c4afc06b..72e390f44 100644 --- a/src/lib/navigation/locationbar.cpp +++ b/src/lib/navigation/locationbar.cpp @@ -77,6 +77,7 @@ LocationBar::LocationBar(BrowserWindow* window) connect(m_completer, SIGNAL(showDomainCompletion(QString)), this, SLOT(showDomainCompletion(QString))); connect(m_completer, SIGNAL(loadCompletion()), this, SLOT(requestLoadUrl())); connect(m_completer, SIGNAL(clearCompletion()), this, SLOT(clearCompletion())); + connect(m_completer, &LocationCompleter::loadRequested, this, &LocationBar::loadRequest); m_domainCompleterModel = new QStringListModel(this); QCompleter* domainCompleter = new QCompleter(this); @@ -294,17 +295,7 @@ void LocationBar::refreshTextFormat() void LocationBar::requestLoadUrl() { - const LoadRequest req = createLoadRequest(); - const QString urlString = convertUrlToText(req.url()); - - m_completer->closePopup(); - m_webView->setFocus(); - - if (urlString != text()) { - setText(urlString); - } - - m_webView->userLoadAction(req); + loadRequest(createLoadRequest()); } void LocationBar::textEdited(const QString &text) @@ -362,6 +353,20 @@ void LocationBar::showUrl(const QUrl &url) m_bookmarkIcon->checkBookmark(url); } +void LocationBar::loadRequest(const LoadRequest &request) +{ + const QString urlString = convertUrlToText(request.url()); + + m_completer->closePopup(); + m_webView->setFocus(); + + if (urlString != text()) { + setText(urlString); + } + + m_webView->userLoadAction(request); +} + void LocationBar::updateSiteIcon() { QIcon icon = m_webView ? m_webView->icon() : IconProvider::emptyWebIcon(); diff --git a/src/lib/navigation/locationbar.h b/src/lib/navigation/locationbar.h index e09b2e907..1295dd8e7 100644 --- a/src/lib/navigation/locationbar.h +++ b/src/lib/navigation/locationbar.h @@ -1,6 +1,6 @@ /* ============================================================ * Falkon - Qt web browser -* Copyright (C) 2010-2017 David Rosca +* Copyright (C) 2010-2018 David Rosca * * 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 @@ -50,6 +50,7 @@ public: public slots: void setText(const QString &text); void showUrl(const QUrl &url); + void loadRequest(const LoadRequest &request); private slots: void textEdited(const QString &text);