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:
parent
fe8eb7f122
commit
4140aae6d2
@ -141,6 +141,7 @@ void LocationCompleter::slotPopupClosed()
|
|||||||
disconnect(s_view, SIGNAL(indexCtrlActivated(QModelIndex)), this, SLOT(indexCtrlActivated(QModelIndex)));
|
disconnect(s_view, SIGNAL(indexCtrlActivated(QModelIndex)), this, SLOT(indexCtrlActivated(QModelIndex)));
|
||||||
disconnect(s_view, SIGNAL(indexShiftActivated(QModelIndex)), this, SLOT(indexShiftActivated(QModelIndex)));
|
disconnect(s_view, SIGNAL(indexShiftActivated(QModelIndex)), this, SLOT(indexShiftActivated(QModelIndex)));
|
||||||
disconnect(s_view, SIGNAL(indexDeleteRequested(QModelIndex)), this, SLOT(indexDeleteRequested(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)));
|
disconnect(s_view->selectionModel(), SIGNAL(currentChanged(QModelIndex,QModelIndex)), this, SLOT(currentChanged(QModelIndex)));
|
||||||
|
|
||||||
emit popupClosed();
|
emit popupClosed();
|
||||||
@ -365,6 +366,7 @@ void LocationCompleter::showPopup()
|
|||||||
connect(s_view, SIGNAL(indexCtrlActivated(QModelIndex)), this, SLOT(indexCtrlActivated(QModelIndex)));
|
connect(s_view, SIGNAL(indexCtrlActivated(QModelIndex)), this, SLOT(indexCtrlActivated(QModelIndex)));
|
||||||
connect(s_view, SIGNAL(indexShiftActivated(QModelIndex)), this, SLOT(indexShiftActivated(QModelIndex)));
|
connect(s_view, SIGNAL(indexShiftActivated(QModelIndex)), this, SLOT(indexShiftActivated(QModelIndex)));
|
||||||
connect(s_view, SIGNAL(indexDeleteRequested(QModelIndex)), this, SLOT(indexDeleteRequested(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)));
|
connect(s_view->selectionModel(), SIGNAL(currentChanged(QModelIndex,QModelIndex)), this, SLOT(currentChanged(QModelIndex)));
|
||||||
|
|
||||||
s_view->createWinId();
|
s_view->createWinId();
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
/* ============================================================
|
/* ============================================================
|
||||||
* Falkon - Qt web browser
|
* 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
|
* 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
|
* it under the terms of the GNU General Public License as published by
|
||||||
@ -26,6 +26,7 @@ class QUrl;
|
|||||||
class QModelIndex;
|
class QModelIndex;
|
||||||
|
|
||||||
class LocationBar;
|
class LocationBar;
|
||||||
|
class LoadRequest;
|
||||||
class BrowserWindow;
|
class BrowserWindow;
|
||||||
class OpenSearchEngine;
|
class OpenSearchEngine;
|
||||||
class LocationCompleterModel;
|
class LocationCompleterModel;
|
||||||
@ -53,6 +54,7 @@ signals:
|
|||||||
void clearCompletion();
|
void clearCompletion();
|
||||||
void popupClosed();
|
void popupClosed();
|
||||||
void cancelRefreshJob();
|
void cancelRefreshJob();
|
||||||
|
void loadRequested(const LoadRequest &request);
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void refreshJobFinished();
|
void refreshJobFinished();
|
||||||
|
@ -20,16 +20,20 @@
|
|||||||
#include "locationcompleterdelegate.h"
|
#include "locationcompleterdelegate.h"
|
||||||
#include "toolbutton.h"
|
#include "toolbutton.h"
|
||||||
#include "iconprovider.h"
|
#include "iconprovider.h"
|
||||||
|
#include "mainapplication.h"
|
||||||
#include "searchenginesdialog.h"
|
#include "searchenginesdialog.h"
|
||||||
|
#include "searchenginesmanager.h"
|
||||||
|
#include "loadrequest.h"
|
||||||
|
|
||||||
#include <QKeyEvent>
|
#include <QKeyEvent>
|
||||||
#include <QApplication>
|
#include <QApplication>
|
||||||
#include <QScrollBar>
|
#include <QScrollBar>
|
||||||
#include <QVBoxLayout>
|
#include <QVBoxLayout>
|
||||||
|
#include <QHBoxLayout>
|
||||||
|
#include <QLabel>
|
||||||
|
|
||||||
LocationCompleterView::LocationCompleterView()
|
LocationCompleterView::LocationCompleterView()
|
||||||
: QWidget(nullptr)
|
: QWidget(nullptr)
|
||||||
, m_ignoreNextMouseMove(false)
|
|
||||||
{
|
{
|
||||||
setAttribute(Qt::WA_ShowWithoutActivating);
|
setAttribute(Qt::WA_ShowWithoutActivating);
|
||||||
setAttribute(Qt::WA_X11NetWmWindowTypeCombo);
|
setAttribute(Qt::WA_X11NetWmWindowTypeCombo);
|
||||||
@ -43,7 +47,6 @@ LocationCompleterView::LocationCompleterView()
|
|||||||
QVBoxLayout *layout = new QVBoxLayout(this);
|
QVBoxLayout *layout = new QVBoxLayout(this);
|
||||||
layout->setContentsMargins(0, 0, 0, 0);
|
layout->setContentsMargins(0, 0, 0, 0);
|
||||||
layout->setSpacing(0);
|
layout->setSpacing(0);
|
||||||
setLayout(layout);
|
|
||||||
|
|
||||||
m_view = new QListView(this);
|
m_view = new QListView(this);
|
||||||
layout->addWidget(m_view);
|
layout->addWidget(m_view);
|
||||||
@ -63,15 +66,23 @@ LocationCompleterView::LocationCompleterView()
|
|||||||
|
|
||||||
QWidget *searchWidget = new QWidget(this);
|
QWidget *searchWidget = new QWidget(this);
|
||||||
QHBoxLayout *searchLayout = new QHBoxLayout(searchWidget);
|
QHBoxLayout *searchLayout = new QHBoxLayout(searchWidget);
|
||||||
searchLayout->setContentsMargins(2, 2, 2, 2);
|
searchLayout->setContentsMargins(10, 4, 4, 4);
|
||||||
searchWidget->setLayout(searchLayout);
|
|
||||||
|
|
||||||
ToolButton *searchSettingsButton = new ToolButton(this);
|
ToolButton *searchSettingsButton = new ToolButton(this);
|
||||||
|
searchSettingsButton->setIcon(IconProvider::settingsIcon());
|
||||||
searchSettingsButton->setToolTip(tr("Manage Search Engines"));
|
searchSettingsButton->setToolTip(tr("Manage Search Engines"));
|
||||||
searchSettingsButton->setAutoRaise(true);
|
searchSettingsButton->setAutoRaise(true);
|
||||||
searchSettingsButton->setIcon(IconProvider::settingsIcon());
|
searchSettingsButton->setIconSize(QSize(16, 16));
|
||||||
connect(searchSettingsButton, &ToolButton::clicked, this, &LocationCompleterView::openSearchEnginesDialog);
|
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->addStretch();
|
||||||
searchLayout->addWidget(searchSettingsButton);
|
searchLayout->addWidget(searchSettingsButton);
|
||||||
|
|
||||||
@ -105,6 +116,7 @@ QItemSelectionModel *LocationCompleterView::selectionModel() const
|
|||||||
|
|
||||||
void LocationCompleterView::setOriginalText(const QString &originalText)
|
void LocationCompleterView::setOriginalText(const QString &originalText)
|
||||||
{
|
{
|
||||||
|
m_originalText = originalText;
|
||||||
m_delegate->setOriginalText(originalText);
|
m_delegate->setOriginalText(originalText);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -298,11 +310,6 @@ bool LocationCompleterView::eventFilter(QObject* object, QEvent* event)
|
|||||||
break;
|
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::Wheel:
|
||||||
case QEvent::MouseButtonPress:
|
case QEvent::MouseButtonPress:
|
||||||
if (!underMouse()) {
|
if (!underMouse()) {
|
||||||
@ -345,6 +352,26 @@ void LocationCompleterView::close()
|
|||||||
emit closed();
|
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()
|
void LocationCompleterView::openSearchEnginesDialog()
|
||||||
{
|
{
|
||||||
SearchEnginesDialog *dialog = new SearchEnginesDialog(focusProxy());
|
SearchEnginesDialog *dialog = new SearchEnginesDialog(focusProxy());
|
||||||
|
@ -22,8 +22,11 @@
|
|||||||
|
|
||||||
#include "qzcommon.h"
|
#include "qzcommon.h"
|
||||||
|
|
||||||
|
class LoadRequest;
|
||||||
class LocationCompleterDelegate;
|
class LocationCompleterDelegate;
|
||||||
|
|
||||||
|
class QHBoxLayout;
|
||||||
|
|
||||||
class FALKON_EXPORT LocationCompleterView : public QWidget
|
class FALKON_EXPORT LocationCompleterView : public QWidget
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
@ -46,6 +49,7 @@ public:
|
|||||||
|
|
||||||
signals:
|
signals:
|
||||||
void closed();
|
void closed();
|
||||||
|
void loadRequested(const LoadRequest &request);
|
||||||
|
|
||||||
void indexActivated(const QModelIndex &index);
|
void indexActivated(const QModelIndex &index);
|
||||||
void indexCtrlActivated(const QModelIndex &index);
|
void indexCtrlActivated(const QModelIndex &index);
|
||||||
@ -56,12 +60,13 @@ public slots:
|
|||||||
void close();
|
void close();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
void setupSearchEngines();
|
||||||
void openSearchEnginesDialog();
|
void openSearchEnginesDialog();
|
||||||
|
|
||||||
bool m_ignoreNextMouseMove;
|
|
||||||
|
|
||||||
QListView *m_view;
|
QListView *m_view;
|
||||||
LocationCompleterDelegate *m_delegate;
|
LocationCompleterDelegate *m_delegate;
|
||||||
|
QHBoxLayout *m_searchEnginesLayout;
|
||||||
|
QString m_originalText;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // LOCATIONCOMPLETERVIEW_H
|
#endif // LOCATIONCOMPLETERVIEW_H
|
||||||
|
@ -77,6 +77,7 @@ LocationBar::LocationBar(BrowserWindow* window)
|
|||||||
connect(m_completer, SIGNAL(showDomainCompletion(QString)), this, SLOT(showDomainCompletion(QString)));
|
connect(m_completer, SIGNAL(showDomainCompletion(QString)), this, SLOT(showDomainCompletion(QString)));
|
||||||
connect(m_completer, SIGNAL(loadCompletion()), this, SLOT(requestLoadUrl()));
|
connect(m_completer, SIGNAL(loadCompletion()), this, SLOT(requestLoadUrl()));
|
||||||
connect(m_completer, SIGNAL(clearCompletion()), this, SLOT(clearCompletion()));
|
connect(m_completer, SIGNAL(clearCompletion()), this, SLOT(clearCompletion()));
|
||||||
|
connect(m_completer, &LocationCompleter::loadRequested, this, &LocationBar::loadRequest);
|
||||||
|
|
||||||
m_domainCompleterModel = new QStringListModel(this);
|
m_domainCompleterModel = new QStringListModel(this);
|
||||||
QCompleter* domainCompleter = new QCompleter(this);
|
QCompleter* domainCompleter = new QCompleter(this);
|
||||||
@ -294,17 +295,7 @@ void LocationBar::refreshTextFormat()
|
|||||||
|
|
||||||
void LocationBar::requestLoadUrl()
|
void LocationBar::requestLoadUrl()
|
||||||
{
|
{
|
||||||
const LoadRequest req = createLoadRequest();
|
loadRequest(createLoadRequest());
|
||||||
const QString urlString = convertUrlToText(req.url());
|
|
||||||
|
|
||||||
m_completer->closePopup();
|
|
||||||
m_webView->setFocus();
|
|
||||||
|
|
||||||
if (urlString != text()) {
|
|
||||||
setText(urlString);
|
|
||||||
}
|
|
||||||
|
|
||||||
m_webView->userLoadAction(req);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void LocationBar::textEdited(const QString &text)
|
void LocationBar::textEdited(const QString &text)
|
||||||
@ -362,6 +353,20 @@ void LocationBar::showUrl(const QUrl &url)
|
|||||||
m_bookmarkIcon->checkBookmark(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()
|
void LocationBar::updateSiteIcon()
|
||||||
{
|
{
|
||||||
QIcon icon = m_webView ? m_webView->icon() : IconProvider::emptyWebIcon();
|
QIcon icon = m_webView ? m_webView->icon() : IconProvider::emptyWebIcon();
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
/* ============================================================
|
/* ============================================================
|
||||||
* Falkon - Qt web browser
|
* 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
|
* 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
|
* it under the terms of the GNU General Public License as published by
|
||||||
@ -50,6 +50,7 @@ public:
|
|||||||
public slots:
|
public slots:
|
||||||
void setText(const QString &text);
|
void setText(const QString &text);
|
||||||
void showUrl(const QUrl &url);
|
void showUrl(const QUrl &url);
|
||||||
|
void loadRequest(const LoadRequest &request);
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void textEdited(const QString &text);
|
void textEdited(const QString &text);
|
||||||
|
Loading…
Reference in New Issue
Block a user