aboutsummaryrefslogtreecommitdiff
path: root/src/addressbar
diff options
context:
space:
mode:
Diffstat (limited to 'src/addressbar')
-rw-r--r--src/addressbar/addressbar.cpp39
-rw-r--r--src/addressbar/addressbar.h1
-rw-r--r--src/addressbar/urllineedit.cpp59
-rw-r--r--src/addressbar/urllineedit.h19
4 files changed, 51 insertions, 67 deletions
diff --git a/src/addressbar/addressbar.cpp b/src/addressbar/addressbar.cpp
index 4f2ae6a..1c10d69 100644
--- a/src/addressbar/addressbar.cpp
+++ b/src/addressbar/addressbar.cpp
@@ -8,6 +8,7 @@
#include "addressbar.h"
#include "urllineedit.h"
+#include "webengine/webview.h"
#include <QProgressBar>
#include <QVBoxLayout>
#include <QShortcut>
@@ -27,6 +28,13 @@ AddressBar::AddressBar(const QHash<QString, QString> &config, QWidget *parent)
urlBar->setFocus();
urlBar->selectAll();
});
+
+ urlBar->pageMenu_action->setShortcut(QKeySequence(config.value("addressbar.shortcuts.pageMenu")));
+ urlBar->pageMenu_action->setToolTip(tr("Page Actions (%1)").arg(urlBar->pageMenu_action->shortcut().toString()));
+
+ urlBar->toolsMenu_action->setShortcut(QKeySequence(config.value("addressbar.shortcuts.toolsMenu")));
+ urlBar->toolsMenu_action->setToolTip(tr("Tools (%1)").arg(urlBar->toolsMenu_action->shortcut().toString()));
+
connect(urlBar, &UrlLineEdit::textEdited, [=](const QString &text) {
std::function<void(QStringList&)> callback = std::bind(&UrlLineEdit::updateCompleter, urlBar, std::placeholders::_1);
emit complete(text, callback);
@@ -40,16 +48,39 @@ AddressBar::AddressBar(const QHash<QString, QString> &config, QWidget *parent)
AddressBar::~AddressBar()
{
+ disconnect(urlChangedConnection);
+ disconnect(loadUrlConnection);
disconnect(progressBarConnection);
}
void AddressBar::connectWebView(WebView* view)
{
+ disconnect(urlChangedConnection);
+ disconnect(loadUrlConnection);
disconnect(progressBarConnection);
- urlBar->connectWebView(view);
- if(view != nullptr) {
- progressBar->setValue(view->loadProgress());
- progressBarConnection = connect(view, &QWebEngineView::loadProgress, progressBar, &QProgressBar::setValue);
+ if(view == nullptr) {
+ urlBar->clear();
+ urlBar->pageMenu_action->setMenu(nullptr);
+ urlBar->toolsMenu_action->setMenu(nullptr);
+
+ progressBar->setValue(100);
+ return;
}
+
+ urlBar->setUrl(view->url());
+ urlBar->pageMenu_action->setMenu(view->pageMenu());
+ urlBar->toolsMenu_action->setMenu(view->toolsMenu());
+ urlChangedConnection = connect(view, &WebView::urlChanged, urlBar, &UrlLineEdit::setUrl);
+ loadUrlConnection = connect(urlBar, &UrlLineEdit::returnPressed, [=]() {
+ if(urlBar->text().startsWith('#')) {;
+ view->search(urlBar->text().mid(1));
+ } else {
+ view->load(QUrl::fromUserInput(urlBar->text()));
+ }
+ view->setFocus();
+ });
+
+ progressBar->setValue(view->loadProgress());
+ progressBarConnection = connect(view, &QWebEngineView::loadProgress, progressBar, &QProgressBar::setValue);
}
diff --git a/src/addressbar/addressbar.h b/src/addressbar/addressbar.h
index 0010bfe..224fb9b 100644
--- a/src/addressbar/addressbar.h
+++ b/src/addressbar/addressbar.h
@@ -33,6 +33,7 @@ private:
UrlLineEdit *urlBar;
QProgressBar *progressBar;
+ QMetaObject::Connection urlChangedConnection, loadUrlConnection;
QMetaObject::Connection progressBarConnection;
};
diff --git a/src/addressbar/urllineedit.cpp b/src/addressbar/urllineedit.cpp
index 4e8d930..fa65e5b 100644
--- a/src/addressbar/urllineedit.cpp
+++ b/src/addressbar/urllineedit.cpp
@@ -7,7 +7,6 @@
*/
#include "urllineedit.h"
-#include "webengine/webview.h"
#include <QLabel>
#include <QMenu>
#include <QShortcut>
@@ -23,65 +22,23 @@ UrlLineEdit::UrlLineEdit(QWidget *parent)
m_listView->setVisible(false);
- m_pageMenuAction = addAction(style()->standardIcon(QStyle::SP_DriveNetIcon), QLineEdit::LeadingPosition);
- m_pageMenuAction->setShortcut(QKeySequence("F2"));
- m_pageMenuAction->setToolTip(tr("Page Actions (%1)").arg(m_pageMenuAction->shortcut().toString()));
- connect(m_pageMenuAction, &QAction::triggered, m_pageMenuAction, [&]() {
- if(m_pageMenuAction->menu()) {
- m_pageMenuAction->menu()->exec(this->mapToGlobal(QPoint(0, height())));
+ pageMenu_action = addAction(style()->standardIcon(QStyle::SP_DriveNetIcon), QLineEdit::LeadingPosition);
+ connect(pageMenu_action, &QAction::triggered, pageMenu_action, [&]() {
+ if(pageMenu_action->menu()) {
+ pageMenu_action->menu()->exec(this->mapToGlobal(QPoint(0, height())));
}
});
- m_toolsMenuAction = addAction(style()->standardIcon(QStyle::SP_FileIcon), QLineEdit::TrailingPosition);
- m_toolsMenuAction->setShortcut(QKeySequence("F10"));
- m_toolsMenuAction->setToolTip(tr("Tools (%1)").arg(m_toolsMenuAction->shortcut().toString()));
- connect(m_toolsMenuAction, &QAction::triggered, m_toolsMenuAction, [&]() {
- if(m_toolsMenuAction->menu()) {
- m_toolsMenuAction->menu()->exec(this->mapToGlobal(QPoint(width(), height())));
+ toolsMenu_action = addAction(style()->standardIcon(QStyle::SP_FileIcon), QLineEdit::TrailingPosition);
+ connect(toolsMenu_action, &QAction::triggered, toolsMenu_action, [&]() {
+ if(toolsMenu_action->menu()) {
+ toolsMenu_action->menu()->exec(this->mapToGlobal(QPoint(width(), height())));
}
});
QTextCharFormat hostnameFormat;
hostnameFormat.setFontWeight(QFont::Bold);
m_hostFormat.format = hostnameFormat;
-
- // connect signals
- connect(this, &QLineEdit::returnPressed, [this]() {
- if(this->text().startsWith('#')) {;
- m_view->search(this->text().mid(1));
- } else {
- if(m_view) {
- m_view->load(QUrl::fromUserInput(this->text()));
- } else {
- this->clear();
- }
- }
- this->clearFocus();
- });
-}
-
-UrlLineEdit::~UrlLineEdit()
-{
-}
-
-void UrlLineEdit::connectWebView(WebView *view)
-{
- disconnect(urlChangedConnection);
-
- if(view == nullptr) {
- clear();
- m_pageMenuAction->setMenu(nullptr);
- m_toolsMenuAction->setMenu(nullptr);
- return;
- }
-
- m_view = view;
-
- setUrl(view->url());
- m_pageMenuAction->setMenu(view->pageMenu());
- m_toolsMenuAction->setMenu(view->toolsMenu());
-
- urlChangedConnection = connect(view, &WebView::urlChanged, this, &UrlLineEdit::setUrl);
}
void UrlLineEdit::setUrl(const QUrl &url)
diff --git a/src/addressbar/urllineedit.h b/src/addressbar/urllineedit.h
index 8f77357..bc23f58 100644
--- a/src/addressbar/urllineedit.h
+++ b/src/addressbar/urllineedit.h
@@ -10,7 +10,6 @@
#define SMOLBOTE_URLLINEEDIT_H
#include "completer.h"
-#include "webengine/webview.h"
#include <QAction>
#include <QLineEdit>
#include <QTextLayout>
@@ -22,14 +21,19 @@ class UrlLineEdit : public QLineEdit
Q_OBJECT
public:
explicit UrlLineEdit(QWidget *parent = nullptr);
- ~UrlLineEdit() override;
public slots:
- void connectWebView(WebView *view);
void setUrl(const QUrl &url);
void updateCompleter(const QStringList &l);
+public:
+ // pageMenu action: zoom, print
+ QAction *pageMenu_action = nullptr;
+ // devMenu action: scripts, etc
+ QAction *toolsMenu_action = nullptr;
+
+
protected:
void focusInEvent(QFocusEvent *event) override;
void focusOutEvent(QFocusEvent *event) override;
@@ -39,19 +43,10 @@ private:
void setTextFormat(const QTextLayout::FormatRange &format);
void clearTextFormat();
- WebView *m_view = nullptr;
-
QTextLayout::FormatRange m_hostFormat;
- // pageMenu action: zoom, print
- QAction *m_pageMenuAction = nullptr;
- // devMenu action: scripts, etc
- QAction *m_toolsMenuAction = nullptr;
-
// completer
Completer *m_listView;
-
- QMetaObject::Connection urlChangedConnection;
};
#endif // SMOLBOTE_URLLINEEDIT_H