1
mirror of https://invent.kde.org/network/falkon.git synced 2024-12-20 10:46:35 +01:00

LocationCompleterView: Add buttons with all search engines

This commit is contained in:
David Rosca 2018-01-25 14:07:19 +01:00
parent fe8eb7f122
commit 4140aae6d2
No known key found for this signature in database
GPG Key ID: EBC3FC294452C6D8
6 changed files with 67 additions and 25 deletions

View File

@ -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();

View File

@ -1,6 +1,6 @@
/* ============================================================
* Falkon - Qt web browser
* Copyright (C) 2010-2017 David Rosca <nowrep@gmail.com>
* Copyright (C) 2010-2018 David Rosca <nowrep@gmail.com>
*
* 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();

View File

@ -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 <QKeyEvent>
#include <QApplication>
#include <QScrollBar>
#include <QVBoxLayout>
#include <QHBoxLayout>
#include <QLabel>
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());

View File

@ -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

View File

@ -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();

View File

@ -1,6 +1,6 @@
/* ============================================================
* Falkon - Qt web browser
* Copyright (C) 2010-2017 David Rosca <nowrep@gmail.com>
* Copyright (C) 2010-2018 David Rosca <nowrep@gmail.com>
*
* 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);