aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAqua-sama <aqua@iserlohn-fortress.net>2017-12-14 11:51:51 +0100
committerAqua-sama <aqua@iserlohn-fortress.net>2017-12-14 11:51:51 +0100
commit783621c89c6c4c9aeae1bcf907c4395b96c5babd (patch)
treebd4f2addc5f8ee9f65fb9d5949b2aa9b82695fa2 /src
parentFixed crash on startup due to missing browser.filterPath (diff)
downloadsmolbote-783621c89c6c4c9aeae1bcf907c4395b96c5babd.tar.xz
Cleaned up UrlLineEdit
Diffstat (limited to 'src')
-rw-r--r--src/lib/navigation/addressbar.cpp50
-rw-r--r--src/lib/navigation/addressbar.h45
-rw-r--r--src/lib/navigation/navigation.qbs2
-rw-r--r--src/lib/navigation/urllineedit.cpp81
-rw-r--r--src/lib/navigation/urllineedit.h18
-rw-r--r--src/mainwindow.cpp22
-rw-r--r--src/mainwindow.h11
-rw-r--r--src/webengine/webview.cpp20
-rw-r--r--src/webengine/webview.h10
9 files changed, 93 insertions, 166 deletions
diff --git a/src/lib/navigation/addressbar.cpp b/src/lib/navigation/addressbar.cpp
deleted file mode 100644
index 909c89a..0000000
--- a/src/lib/navigation/addressbar.cpp
+++ /dev/null
@@ -1,50 +0,0 @@
-/*******************************************************************************
- **
- ** smolbote: yet another qute browser
- ** Copyright (C) 2017 Xian Nox
- **
- ** 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
- ** the Free Software Foundation, either version 3 of the License, or
- ** (at your option) any later version.
- **
- ** This program is distributed in the hope that it will be useful,
- ** but WITHOUT ANY WARRANTY; without even the implied warranty of
- ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- ** GNU General Public License for more details.
- **
- ** You should have received a copy of the GNU General Public License
- ** along with this program. If not, see <http://www.gnu.org/licenses/>.
- **
- ******************************************************************************/
-
-#include "addressbar.h"
-#include <QHBoxLayout>
-
-AddressBar::AddressBar(QWidget *parent) : QWidget(parent)
-{
- QHBoxLayout *_layout = new QHBoxLayout(this);
- _layout->setMargin(0);
- _layout->setSpacing(0);
- setLayout(_layout);
-
- m_urlLineEdit = new UrlLineEdit(this);
- setFocusProxy(m_urlLineEdit);
- _layout->addWidget(m_urlLineEdit);
-
- connect(m_urlLineEdit, &UrlLineEdit::returnPressed, [&]() {
- if(m_urlLineEdit->text().startsWith('#')) {
- QString term = m_urlLineEdit->text().mid(1);
- term.replace(' ', '+');
- emit searchTermEntered(term);
- } else {
- emit addressEntered(QUrl::fromUserInput(m_urlLineEdit->text()));
- }
- });
-}
-
-void AddressBar::setWebView(const WebView *view)
-{
- connect(view, &WebView::urlChanged, m_urlLineEdit, &UrlLineEdit::setUrl);
- m_urlLineEdit->setUrl(view->url());
-}
diff --git a/src/lib/navigation/addressbar.h b/src/lib/navigation/addressbar.h
deleted file mode 100644
index 8b037e1..0000000
--- a/src/lib/navigation/addressbar.h
+++ /dev/null
@@ -1,45 +0,0 @@
-/*******************************************************************************
- **
- ** smolbote: yet another qute browser
- ** Copyright (C) 2017 Xian Nox
- **
- ** 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
- ** the Free Software Foundation, either version 3 of the License, or
- ** (at your option) any later version.
- **
- ** This program is distributed in the hope that it will be useful,
- ** but WITHOUT ANY WARRANTY; without even the implied warranty of
- ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- ** GNU General Public License for more details.
- **
- ** You should have received a copy of the GNU General Public License
- ** along with this program. If not, see <http://www.gnu.org/licenses/>.
- **
- ******************************************************************************/
-
-#ifndef ADDRESSBAR_H
-#define ADDRESSBAR_H
-
-#include <QWidget>
-#include "urllineedit.h"
-#include <webengine/webview.h>
-
-class AddressBar : public QWidget
-{
- Q_OBJECT
-public:
- explicit AddressBar(QWidget *parent = nullptr);
-
-signals:
- void addressEntered(const QUrl &url);
- void searchTermEntered(const QString &term);
-
-public slots:
- void setWebView(const WebView *view);
-
-private:
- UrlLineEdit *m_urlLineEdit;
-};
-
-#endif // ADDRESSBAR_H
diff --git a/src/lib/navigation/navigation.qbs b/src/lib/navigation/navigation.qbs
index ebe2713..d070b7f 100644
--- a/src/lib/navigation/navigation.qbs
+++ b/src/lib/navigation/navigation.qbs
@@ -16,8 +16,6 @@ Project {
}
files: [
- "addressbar.cpp",
- "addressbar.h",
"navigationbutton.cpp",
"navigationbutton.h",
"urllineedit.cpp",
diff --git a/src/lib/navigation/urllineedit.cpp b/src/lib/navigation/urllineedit.cpp
index 5e47223..4244866 100644
--- a/src/lib/navigation/urllineedit.cpp
+++ b/src/lib/navigation/urllineedit.cpp
@@ -21,7 +21,7 @@
#include "urllineedit.h"
#include <QUrl>
#include <QTimer>
-
+#include <QMenu>
#include <QAction>
#include <QStyle>
@@ -31,24 +31,27 @@ UrlLineEdit::UrlLineEdit(QWidget *parent) :
QLineEdit(parent)
{
setPlaceholderText(tr("Enter address"));
- setContextMenuPolicy(Qt::NoContextMenu);
+ // test action
+ m_sslAction = addAction(style()->standardIcon(QStyle::SP_ComputerIcon), QLineEdit::LeadingPosition);
+ m_sslAction->setToolTip(tr("TODO: Display SSL Status popup here"));
+
+ QAction *completerAction = addAction(style()->standardIcon(QStyle::SP_TitleBarMinButton), QLineEdit::TrailingPosition);
+
+ m_pageAction = addAction(style()->standardIcon(QStyle::SP_FileIcon), QLineEdit::TrailingPosition);
+ m_pageAction->setShortcut(QKeySequence("F10"));
+ m_pageAction->setToolTip(tr("Page Actions"));
+ connect(m_pageAction, &QAction::triggered, m_pageAction, [&]() {
+ //this->deselect();
+ if(m_pageAction->menu() != nullptr) {
+ m_pageAction->menu()->exec(this->mapToGlobal(QPoint(width(), height())));
+ }
+ });
QTextCharFormat hostnameFormat;
hostnameFormat.setFontWeight(QFont::Bold);
m_hostFormat.format = hostnameFormat;
- m_contextMenu = new QMenu(this);
- m_contextMenu->addAction("Copy URL", this, SLOT(copyUrl()));
- m_contextMenu->addAction("Paste URL", this, SLOT(pasteUrl()));
- m_contextMenu->addAction("Paste URL and go", this, SLOT(pasteUrlAndGo()));
- m_contextMenu->addSeparator();
- m_contextMenu->addAction("Bookmark this page", this, SLOT(bookmarkUrl()))->setEnabled(false);
-
- QAction *contextAction = addAction(style()->standardIcon(QStyle::SP_TitleBarMinButton), ActionPosition::TrailingPosition);
- contextAction->setShortcut(QKeySequence::fromString("F3"));
- connect(contextAction, SIGNAL(triggered()), this, SLOT(showMenu()));
-
m_menu = new QMenu(this);
m_menu->setWindowFlags(Qt::FramelessWindowHint | Qt::Tool);
@@ -70,14 +73,32 @@ UrlLineEdit::UrlLineEdit(QWidget *parent) :
QAction *closeAction = m_menu->addAction("Close");
connect(closeAction, SIGNAL(triggered()), m_menu, SLOT(hide()));
+ connect(completerAction, &QAction::triggered, this, [this]() {
+ this->showCompleter(this->text());
+ });
+
// connect signals
connect(this, SIGNAL(textEdited(QString)), this, SLOT(showCompleter(QString)));
connect(this, &QLineEdit::returnPressed, [this]() {
+ emit addressEntered(QUrl::fromUserInput(this->text()));
m_menu->hide();
+ this->clearFocus();
});
}
+QAction *UrlLineEdit::sslAction()
+{
+ Q_ASSERT(m_sslAction != nullptr);
+ return m_sslAction;
+}
+
+QAction *UrlLineEdit::pageAction()
+{
+ Q_ASSERT(m_pageAction != nullptr);
+ return m_pageAction;
+}
+
void UrlLineEdit::setUrl(const QUrl &url)
{
QString urlText = url.toString();
@@ -101,7 +122,7 @@ void UrlLineEdit::focusInEvent(QFocusEvent *event)
// select the contents when receiving focus
// http://stackoverflow.com/a/35725950/1054406
// mousePressEvent triggers right after focusInEvent so text selected in focusInEvent unselects by mousePressEvent
- QTimer::singleShot(0, this, SLOT(selectAll()));
+ //QTimer::singleShot(0, this, SLOT(selectAll()));
}
void UrlLineEdit::resizeEvent(QResizeEvent *event)
@@ -159,35 +180,3 @@ void UrlLineEdit::showCompleter(const QString &text)
//listWidget->setCurrentRow(0, QItemSelectionModel::SelectCurrent);
m_menu->exec();
}
-
-// Menu
-
-void UrlLineEdit::showMenu()
-{
- m_contextMenu->exec(mapToGlobal(QPoint(width() - m_contextMenu->width(), height())));
-}
-
-void UrlLineEdit::copyUrl()
-{
- selectAll();
- copy();
- deselect();
-}
-
-void UrlLineEdit::pasteUrl()
-{
- clear();
- paste();
-}
-
-void UrlLineEdit::pasteUrlAndGo()
-{
- clear();
- paste();
- emit returnPressed();
-}
-
-void UrlLineEdit::bookmarkUrl()
-{
- qDebug("TODO: bookmarkUrl()");
-}
diff --git a/src/lib/navigation/urllineedit.h b/src/lib/navigation/urllineedit.h
index 8432f14..fb334ec 100644
--- a/src/lib/navigation/urllineedit.h
+++ b/src/lib/navigation/urllineedit.h
@@ -23,15 +23,18 @@
#include <QLineEdit>
#include <QTextLayout>
-#include <QMenu>
-
#include <QListWidget>
+#include <QAction>
+class QMenu;
class UrlLineEdit : public QLineEdit
{
Q_OBJECT
public:
- explicit UrlLineEdit(QWidget *parent = 0);
+ explicit UrlLineEdit(QWidget *parent = nullptr);
+
+ QAction *sslAction();
+ QAction *pageAction();
signals:
void addressEntered(const QUrl &url);
@@ -47,18 +50,15 @@ protected:
private slots:
void showCompleter(const QString &text);
- void showMenu();
- void copyUrl();
- void pasteUrl();
- void pasteUrlAndGo();
- void bookmarkUrl();
private:
void setTextFormat(const QTextLayout::FormatRange &format);
void clearTextFormat();
QTextLayout::FormatRange m_hostFormat;
- QMenu *m_contextMenu;
+
+ QAction *m_sslAction = nullptr;
+ QAction *m_pageAction = nullptr;
QMenu *m_menu;
QListWidget *listWidget;
diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp
index f48de70..4d3870c 100644
--- a/src/mainwindow.cpp
+++ b/src/mainwindow.cpp
@@ -41,13 +41,15 @@
#include "browser.h"
#include <settings/settingsdialog.h>
+#include <navigation/urllineedit.h>
+
MainWindow::MainWindow(std::shared_ptr<Configuration> config, QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow),
navigationToolBar(new QToolBar(tr("Navigation"), this)),
tabToolBar(new QToolBar(tr("Tab bar"), this)),
tabBar(new WebViewTabBar(nullptr, this)),
- m_addressBar(new AddressBar(navigationToolBar)),
+ m_addressBar(new UrlLineEdit(navigationToolBar)),
m_progressBar(new LoadingBar(this))
{
Q_ASSERT(config);
@@ -109,14 +111,14 @@ MainWindow::MainWindow(std::shared_ptr<Configuration> config, QWidget *parent) :
this->addToolBar(Qt::TopToolBarArea, navigationToolBar);
// connect signals
- connect(m_addressBar, &AddressBar::addressEntered, this, [&](const QUrl &url) {
+ connect(m_addressBar, &UrlLineEdit::addressEntered, this, [&](const QUrl &url) {
tabBar->currentView()->load(url);
});
- connect(m_addressBar, &AddressBar::searchTermEntered, this, [&](const QString &string) {
- QString term = string.mid(1);
- term.replace(' ', '+');
- //tabBar->currentView()->load(QUrl::fromUserInput(browser->settings()->value("general.search").toString().replace("$term", term)));
- });
+// connect(m_addressBar, &AddressBar::searchTermEntered, this, [&](const QString &string) {
+// QString term = string.mid(1);
+// term.replace(' ', '+');
+// //tabBar->currentView()->load(QUrl::fromUserInput(browser->settings()->value("general.search").toString().replace("$term", term)));
+// });
connect(tabBar, SIGNAL(currentTabChanged(WebView*)), this, SLOT(handleTabChanged(WebView*)));
// loading bar
@@ -285,7 +287,11 @@ void MainWindow::handleTabChanged(WebView *view)
m_backButton->setView(view);
m_forwardButton->setView(view);
m_reloadButton->setView(view);
- m_addressBar->setWebView(view);
+
+ connect(view, &WebView::urlChanged, m_addressBar, &UrlLineEdit::setUrl);
+ m_addressBar->setUrl(view->url());
+ m_addressBar->pageAction()->setMenu(view->menu());
+
connect(view, SIGNAL(titleChanged(QString)), this, SLOT(handleTitleUpdated(QString)));
connect(view, SIGNAL(linkHovered(QString)), ui->statusBar, SLOT(showMessage(QString)));
diff --git a/src/mainwindow.h b/src/mainwindow.h
index cc3dfd6..2b94699 100644
--- a/src/mainwindow.h
+++ b/src/mainwindow.h
@@ -23,13 +23,11 @@
#include <QMainWindow>
#include <QToolBar>
-#include <navigation/addressbar.h>
-#include <QWebEngineView>
+
+
#include "webengine/webengineprofile.h"
#include <QUrl>
#include "widgets/webviewtabbar.h"
-#include "webengine/urlinterceptor.h"
-#include "filter/blockermanager.h"
#include "widgets/loadingbar.h"
#include "navigation/navigationbutton.h"
@@ -43,7 +41,10 @@ class MainWindow;
class Configuration;
class BookmarksWidget;
class DownloadsWidget;
+
class MainWindowMenuBar;
+class UrlLineEdit;
+
class MainWindow : public QMainWindow
{
Q_OBJECT
@@ -87,7 +88,7 @@ private:
// navigation
NavigationButton *m_backButton, *m_forwardButton, *m_reloadButton;
- AddressBar *m_addressBar;
+ UrlLineEdit *m_addressBar;
LoadingBar *m_progressBar;
bool m_tabBarAdded = false;
diff --git a/src/webengine/webview.cpp b/src/webengine/webview.cpp
index 6742101..281ccec 100644
--- a/src/webengine/webview.cpp
+++ b/src/webengine/webview.cpp
@@ -24,6 +24,26 @@
WebView::WebView(QWidget *parent) :
QWebEngineView(parent)
{
+ m_pageMenu = new QMenu();
+ m_pageMenu->addAction(tr("TODO: Copy page URL"));
+ m_pageMenu->addAction(tr("TODO: Bookmark page"));
+ m_pageMenu->addSeparator();
+ m_pageMenu->addAction(tr("TODO: Zoom level: 100%"));
+ m_pageMenu->addSeparator();
+ m_pageMenu->addAction(tr("TODO: Save Page"));
+ m_pageMenu->addAction(tr("TODO: Print page"));
+ m_pageMenu->addAction(tr("TODO: Print to PDF"));
+}
+
+WebView::~WebView()
+{
+ delete m_pageMenu;
+}
+
+QMenu *WebView::menu()
+{
+ Q_ASSERT(m_pageMenu != nullptr);
+ return m_pageMenu;
}
void WebView::setPage(QWebEnginePage *page)
diff --git a/src/webengine/webview.h b/src/webengine/webview.h
index 557c5a4..95d12d9 100644
--- a/src/webengine/webview.h
+++ b/src/webengine/webview.h
@@ -22,12 +22,17 @@
#define WEBVIEW_H
#include <QWebEngineView>
+#include <QMenu>
class WebView : public QWebEngineView
{
Q_OBJECT
public:
- explicit WebView(QWidget *parent = 0);
+ explicit WebView(QWidget *parent = nullptr);
+ ~WebView();
+
+ QMenu *menu();
+
void setPage(QWebEnginePage *page);
signals:
@@ -35,6 +40,9 @@ signals:
private slots:
void handleLinkHovered(const QString &url);
+
+private:
+ QMenu *m_pageMenu = nullptr;
};
#endif // WEBVIEW_H