aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/bookmarks/bookmarkswidget.cpp4
-rw-r--r--lib/bookmarks/bookmarkswidget.h2
-rw-r--r--src/CMakeLists.txt2
-rw-r--r--src/addressbar/addressbar.cpp55
-rw-r--r--src/addressbar/addressbar.h39
-rw-r--r--src/addressbar/completer.cpp2
-rw-r--r--src/addressbar/completer.h2
-rw-r--r--src/addressbar/urllineedit.cpp21
-rw-r--r--src/addressbar/urllineedit.h16
-rw-r--r--src/browser.cpp4
-rw-r--r--src/mainwindow/mainwindow.cpp13
-rw-r--r--src/mainwindow/mainwindow.h4
12 files changed, 112 insertions, 52 deletions
diff --git a/lib/bookmarks/bookmarkswidget.cpp b/lib/bookmarks/bookmarkswidget.cpp
index b5bf471..339e913 100644
--- a/lib/bookmarks/bookmarkswidget.cpp
+++ b/lib/bookmarks/bookmarkswidget.cpp
@@ -129,7 +129,7 @@ void BookmarksWidget::save()
}
}
-QStringList BookmarksWidget::search(const QString& term) const
+void BookmarksWidget::search(const QString& term, std::function<void(QStringList&)> callback) const
{
QStringList ret;
const QList<QTreeWidgetItem *> res = ui->treeWidget->findItems(term, Qt::MatchContains | Qt::MatchRecursive, 1);
@@ -138,5 +138,5 @@ QStringList BookmarksWidget::search(const QString& term) const
ret.append(i->text(1));
}
- return ret;
+ callback(ret);
}
diff --git a/lib/bookmarks/bookmarkswidget.h b/lib/bookmarks/bookmarkswidget.h
index f0cd73d..6322918 100644
--- a/lib/bookmarks/bookmarkswidget.h
+++ b/lib/bookmarks/bookmarkswidget.h
@@ -35,7 +35,7 @@ signals:
void openUrl(const QUrl &url);
public slots:
- QStringList search(const QString &term) const;
+ void search(const QString &term, std::function<void(QStringList&)> callback) const;
private:
Ui::BookmarksDialog *ui;
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 8adb1aa..0ffb768 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -33,6 +33,8 @@ add_executable(poi
mainwindow/widgets/tabwidget.h
# address bar
+ addressbar/addressbar.cpp
+ addressbar/addressbar.h
addressbar/completer.cpp
addressbar/completer.h
addressbar/urllineedit.cpp
diff --git a/src/addressbar/addressbar.cpp b/src/addressbar/addressbar.cpp
new file mode 100644
index 0000000..4f2ae6a
--- /dev/null
+++ b/src/addressbar/addressbar.cpp
@@ -0,0 +1,55 @@
+/*
+ * This file is part of smolbote. It's copyrighted by the contributors recorded
+ * in the version control history of the file, available from its original
+ * location: https://neueland.iserlohn-fortress.net/smolbote.hg
+ *
+ * SPDX-License-Identifier: GPL-3.0
+ */
+
+#include "addressbar.h"
+#include "urllineedit.h"
+#include <QProgressBar>
+#include <QVBoxLayout>
+#include <QShortcut>
+
+AddressBar::AddressBar(const QHash<QString, QString> &config, QWidget *parent)
+ : QWidget(parent)
+{
+ setLayout(new QVBoxLayout());
+ layout()->setContentsMargins(0, 0, 0, 0);
+ layout()->setSpacing(0);
+
+ urlBar = new UrlLineEdit(this);
+ layout()->addWidget(urlBar);
+
+ auto *focusShortcut = new QShortcut(QKeySequence(config.value("addressbar.shortcuts.focus")), parent);
+ connect(focusShortcut, &QShortcut::activated, urlBar, [=]() {
+ urlBar->setFocus();
+ urlBar->selectAll();
+ });
+ connect(urlBar, &UrlLineEdit::textEdited, [=](const QString &text) {
+ std::function<void(QStringList&)> callback = std::bind(&UrlLineEdit::updateCompleter, urlBar, std::placeholders::_1);
+ emit complete(text, callback);
+ });
+
+ progressBar = new QProgressBar(this);
+ progressBar->setMaximumHeight(5);
+ progressBar->setTextVisible(false);
+ layout()->addWidget(progressBar);
+}
+
+AddressBar::~AddressBar()
+{
+ disconnect(progressBarConnection);
+}
+
+void AddressBar::connectWebView(WebView* view)
+{
+ disconnect(progressBarConnection);
+ urlBar->connectWebView(view);
+
+ if(view != nullptr) {
+ progressBar->setValue(view->loadProgress());
+ progressBarConnection = connect(view, &QWebEngineView::loadProgress, progressBar, &QProgressBar::setValue);
+ }
+}
diff --git a/src/addressbar/addressbar.h b/src/addressbar/addressbar.h
new file mode 100644
index 0000000..0010bfe
--- /dev/null
+++ b/src/addressbar/addressbar.h
@@ -0,0 +1,39 @@
+/*
+ * This file is part of smolbote. It's copyrighted by the contributors recorded
+ * in the version control history of the file, available from its original
+ * location: https://neueland.iserlohn-fortress.net/smolbote.hg
+ *
+ * SPDX-License-Identifier: GPL-3.0
+ */
+
+#ifndef ADDRESSBAR_H
+#define ADDRESSBAR_H
+
+#include <QWidget>
+#include <functional>
+
+class WebView;
+class UrlLineEdit;
+class QProgressBar;
+class AddressBar : public QWidget
+{
+ Q_OBJECT
+
+public:
+ AddressBar(const QHash<QString, QString> &config, QWidget *parent = nullptr);
+ ~AddressBar() override;
+
+signals:
+ void complete(const QString &term, std::function<void(QStringList&)> callback);
+
+public slots:
+ void connectWebView(WebView *view);
+
+private:
+ UrlLineEdit *urlBar;
+ QProgressBar *progressBar;
+
+ QMetaObject::Connection progressBarConnection;
+};
+
+#endif // ADDRESSBAR_H
diff --git a/src/addressbar/completer.cpp b/src/addressbar/completer.cpp
index e02610a..9b95ac0 100644
--- a/src/addressbar/completer.cpp
+++ b/src/addressbar/completer.cpp
@@ -15,7 +15,7 @@ Completer::Completer(QWidget *parent)
setWindowFlags(Qt::ToolTip);
}
-bool Completer::updateItems(QStringList &list)
+bool Completer::updateItems(const QStringList &list)
{
if(list.isEmpty())
return false;
diff --git a/src/addressbar/completer.h b/src/addressbar/completer.h
index 4e338c8..03ff317 100644
--- a/src/addressbar/completer.h
+++ b/src/addressbar/completer.h
@@ -21,7 +21,7 @@ class Completer : public QListView
public:
explicit Completer(QWidget *parent = nullptr);
- bool updateItems(QStringList &list);
+ bool updateItems(const QStringList &list);
bool keyPressed(QKeyEvent *event);
diff --git a/src/addressbar/urllineedit.cpp b/src/addressbar/urllineedit.cpp
index e2cb7a5..4e8d930 100644
--- a/src/addressbar/urllineedit.cpp
+++ b/src/addressbar/urllineedit.cpp
@@ -15,21 +15,13 @@
#include <QWidgetAction>
#include <bookmarks/bookmarkswidget.h>
-UrlLineEdit::UrlLineEdit(const QHash<QString, QString> &config, QWidget *parent)
+UrlLineEdit::UrlLineEdit(QWidget *parent)
: QLineEdit(parent)
- , suggestionTimer(new QTimer(this))
, m_listView(new Completer(this))
{
setPlaceholderText(tr("Enter address"));
- suggestionTimer->setSingleShot(true);
- connect(suggestionTimer, &QTimer::timeout, this, &UrlLineEdit::search);
m_listView->setVisible(false);
- connect(this, &QLineEdit::textEdited, this, [this]() {
- if(suggestionTimer->isActive())
- suggestionTimer->stop();
- suggestionTimer->start(100);
- });
m_pageMenuAction = addAction(style()->standardIcon(QStyle::SP_DriveNetIcon), QLineEdit::LeadingPosition);
m_pageMenuAction->setShortcut(QKeySequence("F2"));
@@ -70,10 +62,8 @@ UrlLineEdit::UrlLineEdit(const QHash<QString, QString> &config, QWidget *parent)
UrlLineEdit::~UrlLineEdit()
{
- suggestionTimer->stop();
}
-
void UrlLineEdit::connectWebView(WebView *view)
{
disconnect(urlChangedConnection);
@@ -108,14 +98,7 @@ void UrlLineEdit::setUrl(const QUrl &url)
setText(urlText);
}
-void UrlLineEdit::search()
-{
- Q_ASSERT_X(bookmarks != nullptr, "UrlLineEdit::search", "bookmarks is nullptr");
- updateCompleter(bookmarks->search(text()));
-}
-
-
-void UrlLineEdit::updateCompleter(QStringList l)
+void UrlLineEdit::updateCompleter(const QStringList &l)
{
if(!m_listView->updateItems(l)) {
m_listView->hide();
diff --git a/src/addressbar/urllineedit.h b/src/addressbar/urllineedit.h
index d3753f4..8f77357 100644
--- a/src/addressbar/urllineedit.h
+++ b/src/addressbar/urllineedit.h
@@ -16,29 +16,19 @@
#include <QTextLayout>
class QMenu;
-class QTimer;
-class BookmarksWidget;
class WebView;
class UrlLineEdit : public QLineEdit
{
Q_OBJECT
public:
- explicit UrlLineEdit(const QHash<QString, QString> &config, QWidget *parent = nullptr);
+ explicit UrlLineEdit(QWidget *parent = nullptr);
~UrlLineEdit() override;
- void setBookmarksManager(BookmarksWidget *w) {
- bookmarks = w;
- };
-
-signals:
- void complete(const QString &term);
-
public slots:
void connectWebView(WebView *view);
void setUrl(const QUrl &url);
- void search();
- void updateCompleter(QStringList l);
+ void updateCompleter(const QStringList &l);
protected:
void focusInEvent(QFocusEvent *event) override;
@@ -49,7 +39,6 @@ private:
void setTextFormat(const QTextLayout::FormatRange &format);
void clearTextFormat();
- BookmarksWidget *bookmarks = nullptr;
WebView *m_view = nullptr;
QTextLayout::FormatRange m_hostFormat;
@@ -60,7 +49,6 @@ private:
QAction *m_toolsMenuAction = nullptr;
// completer
- QTimer *suggestionTimer;
Completer *m_listView;
QMetaObject::Connection urlChangedConnection;
diff --git a/src/browser.cpp b/src/browser.cpp
index f1336bc..e5e83e8 100644
--- a/src/browser.cpp
+++ b/src/browser.cpp
@@ -16,7 +16,7 @@
#include <downloads/downloadswidget.h>
#include <version.h>
#include "webengine/urlinterceptor.h"
-#include "addressbar/urllineedit.h"
+#include "addressbar/addressbar.h"
Browser::Browser(int &argc, char *argv[])
: SingleApplication(argc, argv)
@@ -97,7 +97,7 @@ MainWindow *Browser::createWindow()
{
// the window will delete itself when it closes, so we don't need to delete it
MainWindow *window = new MainWindow(m_config);
- window->addressBar->setBookmarksManager(m_bookmarks.get());
+ connect(window->addressBar, &AddressBar::complete, m_bookmarks.get(), &BookmarksWidget::search);
window->createSubWindow(WebProfile::defaultProfile()->newtab());
auto *bookmarksAction = new QAction(tr("Bookmarks"), window);
diff --git a/src/mainwindow/mainwindow.cpp b/src/mainwindow/mainwindow.cpp
index 6af530a..df5e1c8 100644
--- a/src/mainwindow/mainwindow.cpp
+++ b/src/mainwindow/mainwindow.cpp
@@ -23,7 +23,7 @@
#include <QUrl>
#include <about/aboutdialog.h>
#include <configuration/configuration.h>
-#include "addressbar/urllineedit.h"
+#include "addressbar/addressbar.h"
MainWindow::MainWindow(std::shared_ptr<Configuration> &config, QWidget *parent)
: QMainWindow(parent)
@@ -48,16 +48,9 @@ MainWindow::MainWindow(std::shared_ptr<Configuration> &config, QWidget *parent)
addToolBar(Qt::TopToolBarArea, navigationToolBar);
navigationToolBar->connectWebView(nullptr);
- QHash<QString, QString> a;
- addressBar = new UrlLineEdit(a, this);
+ addressBar = new AddressBar(config->section("addressbar"), this);
navigationToolBar->addWidget(addressBar);
- auto *focusShortcut = new QShortcut(QKeySequence("F4"), this);
- connect(focusShortcut, &QShortcut::activated, this, [this]() {
- addressBar->setFocus();
- addressBar->selectAll();
- });
-
setCentralWidget(mdiArea);
mdiArea->setFocus();
@@ -74,7 +67,7 @@ MainWindow::MainWindow(std::shared_ptr<Configuration> &config, QWidget *parent)
});
addressBar->connectWebView(w->currentView());
- addressBarConnection = connect(w, &Window::currentViewChanged, addressBar, &UrlLineEdit::connectWebView);
+ addressBarConnection = connect(w, &Window::currentViewChanged, addressBar, &AddressBar::connectWebView);
navigationToolBar->connectWebView(w->currentView());
navigationBarConnection = connect(w, &Window::currentViewChanged, navigationToolBar, &NavigationBar::connectWebView);
}
diff --git a/src/mainwindow/mainwindow.h b/src/mainwindow/mainwindow.h
index ad879c3..38ab746 100644
--- a/src/mainwindow/mainwindow.h
+++ b/src/mainwindow/mainwindow.h
@@ -16,7 +16,7 @@ class Browser;
class QMdiArea;
class Configuration;
class Window;
-class UrlLineEdit;
+class AddressBar;
class MainWindow : public QMainWindow
{
friend class Browser;
@@ -47,7 +47,7 @@ protected:
private:
QString titleSuffix;
QMenu *toolsMenu = nullptr;
- UrlLineEdit *addressBar;
+ AddressBar *addressBar;
QMdiArea *mdiArea;
std::shared_ptr<Configuration> m_config;