aboutsummaryrefslogtreecommitdiff
path: root/src/addressbar
diff options
context:
space:
mode:
authorAqua-sama <aqua@iserlohn-fortress.net>2018-04-17 13:36:08 +0200
committerAqua-sama <aqua@iserlohn-fortress.net>2018-04-17 13:36:08 +0200
commit1e99b19616f102b57f52dfc01ea3ccdb6a24a607 (patch)
tree120672a1635e3bc2110b780d93afbfe0a9f30216 /src/addressbar
parentAddress bar searches work again (diff)
downloadsmolbote-1e99b19616f102b57f52dfc01ea3ccdb6a24a607.tar.xz
Add loading progess bar to the address bar
Diffstat (limited to 'src/addressbar')
-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
6 files changed, 100 insertions, 35 deletions
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;