aboutsummaryrefslogtreecommitdiff
path: root/lib/addressbar
diff options
context:
space:
mode:
Diffstat (limited to 'lib/addressbar')
-rw-r--r--lib/addressbar/CMakeLists.txt5
-rw-r--r--lib/addressbar/addressbar.cpp57
-rw-r--r--lib/addressbar/addressbar.h12
-rw-r--r--lib/addressbar/urllineedit.cpp9
-rw-r--r--lib/addressbar/urllineedit.h5
5 files changed, 34 insertions, 54 deletions
diff --git a/lib/addressbar/CMakeLists.txt b/lib/addressbar/CMakeLists.txt
index 1122bc3..63cf2bc 100644
--- a/lib/addressbar/CMakeLists.txt
+++ b/lib/addressbar/CMakeLists.txt
@@ -15,7 +15,4 @@ add_library(addressbar
urllineedit.h
)
-#target_include_directories(addressbar
-# PRIVATE ${Boost_INCLUDE_DIRS})
-
-target_link_libraries(addressbar Qt5::Widgets Qt5::WebEngineWidgets)
+target_link_libraries(addressbar Qt5::Widgets)
diff --git a/lib/addressbar/addressbar.cpp b/lib/addressbar/addressbar.cpp
index 2409cb9..7d17462 100644
--- a/lib/addressbar/addressbar.cpp
+++ b/lib/addressbar/addressbar.cpp
@@ -8,7 +8,6 @@
#include "addressbar.h"
#include "urllineedit.h"
-#include <QWebEngineView>
#include <QProgressBar>
#include <QShortcut>
#include <QVBoxLayout>
@@ -35,6 +34,19 @@ AddressBar::AddressBar(const QHash<QString, QString> &config, QWidget *parent)
emit complete(text, callback);
});
+ connect(urlBar, &UrlLineEdit::returnPressed, [=]() {
+ const QUrl url = QUrl::fromUserInput(urlBar->text());
+
+ // check if url contains \w+:// (matches protocol://) or contains a '.' (matches site.domain)
+ // this is because single words are valid URLs for QUrl (searchterm becomes http://searchterm)
+ // check for protocol://site because \. wouldn't match it (localhost is a search term; http://localhost is an address)
+ if(urlBar->text().contains(QRegularExpression("\\w+://|\\.")) && url.isValid()) {
+ emit load(url);
+ } else {
+ emit search(urlBar->text());
+ }
+ });
+
progressBar = new QProgressBar(this);
progressBar->setObjectName("LoadingBar");
progressBar->setMaximumHeight(5);
@@ -44,46 +56,19 @@ AddressBar::AddressBar(const QHash<QString, QString> &config, QWidget *parent)
AddressBar::~AddressBar()
{
- disconnect(urlChangedConnection);
- disconnect(loadUrlConnection);
- disconnect(progressBarConnection);
- disconnect(focusConnection);
+ disconnect(this);
}
-void AddressBar::setView(QWebEngineView *view)
+void AddressBar::setUrl(const QUrl &url)
{
- disconnect(urlChangedConnection);
- disconnect(loadUrlConnection);
- disconnect(progressBarConnection);
- disconnect(focusConnection);
-
- progressBar->setValue(100);
-
- if(view == nullptr) {
+ if(url.isEmpty())
urlBar->clear();
- urlBar->pageMenu = nullptr;
- urlBar->toolsMenu = nullptr;
- return;
- }
-
- urlBar->setUrl(view->url());
- urlChangedConnection = connect(view, &QWebEngineView::urlChanged, urlBar, &UrlLineEdit::setUrl);
- loadUrlConnection = connect(urlBar, &UrlLineEdit::returnPressed, [=]() {
- const QUrl url = QUrl::fromUserInput(urlBar->text());
- if(url.isValid()) {
- view->load(url);
- } else {
- emit search(urlBar->text());
- }
- view->setFocus();
- });
-
- progressBar->setValue(100);
- progressBarConnection = connect(view, &QWebEngineView::loadProgress, progressBar, &QProgressBar::setValue);
+ else
+ urlBar->setUrl(url);
+}
- focusConnection = connect(urlBar, &UrlLineEdit::focusView, view, [view]() {
- view->setFocus();
- });
+void AddressBar::setProgress(int value) {
+ progressBar->setValue(std::min(value, 100));
}
void AddressBar::setPageMenu(QMenu *menu)
diff --git a/lib/addressbar/addressbar.h b/lib/addressbar/addressbar.h
index d035d8d..e87f72e 100644
--- a/lib/addressbar/addressbar.h
+++ b/lib/addressbar/addressbar.h
@@ -12,7 +12,6 @@
#include <QWidget>
#include <functional>
-class QWebEngineView;
class UrlLineEdit;
class QProgressBar;
class QMenu;
@@ -26,20 +25,21 @@ public:
signals:
void complete(const QString &term, std::function<void(QStringList &)> callback);
+
void search(const QString &term);
+ void load(const QUrl &url);
+ void giveFocus();
public slots:
- void setView(QWebEngineView *view);
+ void setUrl(const QUrl &url);
+ void setProgress(int value);
+
void setPageMenu(QMenu *menu);
void setToolsMenu(QMenu *menu);
private:
UrlLineEdit *urlBar;
QProgressBar *progressBar;
-
- QMetaObject::Connection urlChangedConnection, loadUrlConnection;
- QMetaObject::Connection progressBarConnection;
- QMetaObject::Connection focusConnection;
};
#endif // SMOLBOTE_ADDRESSBAR_H
diff --git a/lib/addressbar/urllineedit.cpp b/lib/addressbar/urllineedit.cpp
index 33bc9dc..29a14cd 100644
--- a/lib/addressbar/urllineedit.cpp
+++ b/lib/addressbar/urllineedit.cpp
@@ -24,7 +24,7 @@ UrlLineEdit::UrlLineEdit(QWidget *parent)
m_listView->setVisible(false);
connect(m_listView, &Completer::completionActivated, this, &UrlLineEdit::setText);
- auto *addressbar = qobject_cast<AddressBar *>(parent);
+ addressbar = qobject_cast<AddressBar *>(parent);
Q_CHECK_PTR(addressbar);
auto *copyAction = new QAction(tr("Copy URL"), this);
@@ -41,9 +41,8 @@ UrlLineEdit::UrlLineEdit(QWidget *parent)
actions.append(pasteAction);
auto *loadAction = new QAction(tr("Paste and load"), this);
- connect(loadAction, &QAction::triggered, this, [this]() {
- this->setText(qApp->clipboard()->text());
- emit returnPressed();
+ connect(loadAction, &QAction::triggered, this, [=]() {
+ emit addressbar->load(QUrl::fromUserInput(qApp->clipboard()->text()));
});
actions.append(loadAction);
@@ -115,7 +114,7 @@ void UrlLineEdit::focusOutEvent(QFocusEvent *event)
if(url.isValid())
setUrl(url);
- emit focusView();
+ emit addressbar->giveFocus();
QLineEdit::focusOutEvent(event);
}
diff --git a/lib/addressbar/urllineedit.h b/lib/addressbar/urllineedit.h
index 2198a0e..56914c4 100644
--- a/lib/addressbar/urllineedit.h
+++ b/lib/addressbar/urllineedit.h
@@ -10,6 +10,7 @@
#define SMOLBOTE_URLLINEEDIT_H
#include "completer.h"
+#include "addressbar.h"
#include <QAction>
#include <QLineEdit>
#include <QTextLayout>
@@ -27,9 +28,6 @@ public slots:
void updateCompleter(const QStringList &l);
-signals:
- void focusView();
-
public:
QAction *menuAction = nullptr;
// pageMenu action: zoom, print
@@ -52,6 +50,7 @@ private:
// completer
Completer *m_listView;
+ AddressBar *addressbar;
};
#endif // SMOLBOTE_URLLINEEDIT_H