aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/browser.cpp2
-rw-r--r--src/forms/searchform.cpp2
-rw-r--r--src/main.cpp2
-rw-r--r--src/mainwindow/mainwindow.cpp (renamed from src/mainwindow.cpp)22
-rw-r--r--src/mainwindow/mainwindow.h (renamed from src/mainwindow.h)6
-rw-r--r--src/mainwindow/mainwindow.ui (renamed from src/mainwindow.ui)0
-rw-r--r--src/mainwindow/widgets/loadingbar.cpp50
-rw-r--r--src/mainwindow/widgets/loadingbar.h (renamed from src/widgets/loadingbar.h)13
-rw-r--r--src/mainwindow/widgets/navigationbar.cpp115
-rw-r--r--src/mainwindow/widgets/navigationbar.h55
-rw-r--r--src/webengine/webview.cpp23
-rw-r--r--src/webengine/webview.h7
-rw-r--r--src/widgets/loadingbar.cpp39
-rw-r--r--src/widgets/mainwindowmenubar.cpp2
-rw-r--r--src/widgets/mainwindowtabbar.cpp2
15 files changed, 267 insertions, 73 deletions
diff --git a/src/browser.cpp b/src/browser.cpp
index 1e07a95..3d2bec0 100644
--- a/src/browser.cpp
+++ b/src/browser.cpp
@@ -7,7 +7,7 @@
*/
#include "browser.h"
-#include "mainwindow.h"
+#include "src/mainwindow/mainwindow.h"
#include "webengine/urlinterceptor.h"
#include <QtConcurrent>
#include <bookmarks/bookmarkswidget.h>
diff --git a/src/forms/searchform.cpp b/src/forms/searchform.cpp
index 42e5a1a..bed0dc5 100644
--- a/src/forms/searchform.cpp
+++ b/src/forms/searchform.cpp
@@ -7,7 +7,7 @@
*/
#include "searchform.h"
-#include "../mainwindow.h"
+#include "src/mainwindow/mainwindow.h"
#include "ui_searchform.h"
#include <settings/configuration.h>
diff --git a/src/main.cpp b/src/main.cpp
index 0452fdd..62f6757 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -7,7 +7,7 @@
*/
#include "browser.h"
-#include "mainwindow.h"
+#include "src/mainwindow/mainwindow.h"
#include "version.h"
#include <QCommandLineParser>
#include <QDir>
diff --git a/src/mainwindow.cpp b/src/mainwindow/mainwindow.cpp
index 4306afd..018ff64 100644
--- a/src/mainwindow.cpp
+++ b/src/mainwindow/mainwindow.cpp
@@ -7,7 +7,6 @@
*/
#include "mainwindow.h"
-#include "browser.h"
#include "forms/aboutdialog.h"
#include "forms/searchform.h"
#include "ui_mainwindow.h"
@@ -57,22 +56,9 @@ MainWindow::MainWindow(std::shared_ptr<Configuration> config, QWidget *parent)
insertToolBarBreak(ui->navigationToolBar);
// page actions
- m_backButton = new NavigationButton(NavigationButton::BackButton, this);
+ m_navigationBar = new NavigationBar(this);
+ m_navigationBar->addWidgetsTo(ui->navigationToolBar);
- m_forwardButton = new NavigationButton(NavigationButton::ForwardButton, this);
-
- m_reloadButton = new NavigationButton(NavigationButton::ReloadButton, this);
-
- QToolButton *homepageButton = new QToolButton(this);
- homepageButton->setIcon(style()->standardIcon(QStyle::SP_DirHomeIcon));
- connect(homepageButton, &QToolButton::clicked, this, [&]() {
- tabBar->currentView()->load(m_profile->homepage());
- });
-
- ui->navigationToolBar->addWidget(m_backButton);
- ui->navigationToolBar->addWidget(m_forwardButton);
- ui->navigationToolBar->addWidget(m_reloadButton);
- ui->navigationToolBar->addWidget(homepageButton);
ui->navigationToolBar->addWidget(m_addressBar);
// connect signals
@@ -282,9 +268,7 @@ void MainWindow::handleTabChanged(WebView *view)
setCentralWidget(view);
// connect signals
- m_backButton->setView(view);
- m_forwardButton->setView(view);
- m_reloadButton->setView(view);
+ m_navigationBar->connectWebView(view);
connect(view, &WebView::urlChanged, m_addressBar, &UrlLineEdit::setUrl);
m_addressBar->setUrl(view->url());
diff --git a/src/mainwindow.h b/src/mainwindow/mainwindow.h
index 79773d3..3f2c3a2 100644
--- a/src/mainwindow.h
+++ b/src/mainwindow/mainwindow.h
@@ -10,9 +10,9 @@
#define MAINWINDOW_H
#include "browser.h"
-#include "lib/navigation/navigationbutton.h"
#include "webengine/webengineprofile.h"
#include "widgets/loadingbar.h"
+#include "widgets/navigationbar.h"
#include "widgets/mainwindowtabbar.h"
#include <QMainWindow>
#include <QUrl>
@@ -42,6 +42,8 @@ class MainWindow : public QMainWindow
friend class MainWindowMenuBar;
+ friend class NavigationBar;
+
public:
explicit MainWindow(std::shared_ptr<Configuration> config, QWidget *parent = nullptr);
Q_DISABLE_COPY(MainWindow)
@@ -82,7 +84,7 @@ private:
MainWindowMenuBar *menuBar;
// navigation
- NavigationButton *m_backButton, *m_forwardButton, *m_reloadButton;
+ NavigationBar *m_navigationBar;
UrlLineEdit *m_addressBar;
LoadingBar *m_progressBar;
diff --git a/src/mainwindow.ui b/src/mainwindow/mainwindow.ui
index 12a3a6c..12a3a6c 100644
--- a/src/mainwindow.ui
+++ b/src/mainwindow/mainwindow.ui
diff --git a/src/mainwindow/widgets/loadingbar.cpp b/src/mainwindow/widgets/loadingbar.cpp
new file mode 100644
index 0000000..99f44d2
--- /dev/null
+++ b/src/mainwindow/widgets/loadingbar.cpp
@@ -0,0 +1,50 @@
+/*
+ * 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: git://neueland.iserlohn-fortress.net/smolbote.git
+ *
+ * SPDX-License-Identifier: GPL-3.0
+ */
+
+#include "loadingbar.h"
+#include <QTimer>
+#include "webengine/webview.h"
+
+LoadingBar::LoadingBar(QWidget *parent)
+ : QProgressBar(parent)
+{
+ setMaximum(100);
+}
+
+void LoadingBar::connectWebView(WebView *view)
+{
+ Q_CHECK_PTR(view);
+
+ disconnect(loadStartedConnection);
+ disconnect(loadProgressConnection);
+ disconnect(loadFinishedConnection);
+
+ if(view->isLoaded()) {
+ this->hide();
+ } else {
+ loadStarted();
+ setValue(view->loadProgress());
+ }
+
+ loadStartedConnection = connect(view, &QWebEngineView::loadStarted, this, &LoadingBar::loadStarted);
+ loadProgressConnection = connect(view, &QWebEngineView::loadProgress, this, &QProgressBar::setValue);
+ loadFinishedConnection = connect(view, &QWebEngineView::loadFinished, this, &LoadingBar::loadFinished);
+}
+
+void LoadingBar::loadStarted()
+{
+ resetFormat();
+ show();
+ setValue(0);
+}
+
+void LoadingBar::loadFinished(bool ok)
+{
+ setFormat(QString("%p% %1").arg(ok ? tr("Finished") : tr("Failed")));
+ QTimer::singleShot(2000, this, SLOT(hide()));
+}
diff --git a/src/widgets/loadingbar.h b/src/mainwindow/widgets/loadingbar.h
index e281628..8ae314e 100644
--- a/src/widgets/loadingbar.h
+++ b/src/mainwindow/widgets/loadingbar.h
@@ -11,19 +11,20 @@
#include <QProgressBar>
-class QWebEngineView;
+class WebView;
class LoadingBar : public QProgressBar
{
Q_OBJECT
public:
- explicit LoadingBar(QWidget *parent = 0);
- void connectWebView(QWebEngineView *view);
+ explicit LoadingBar(QWidget *parent = nullptr);
+ void connectWebView(WebView *view);
-signals:
-
-public slots:
+private slots:
void loadStarted();
void loadFinished(bool ok);
+
+private:
+ QMetaObject::Connection loadStartedConnection, loadProgressConnection, loadFinishedConnection;
};
#endif // LOADINGBAR_H
diff --git a/src/mainwindow/widgets/navigationbar.cpp b/src/mainwindow/widgets/navigationbar.cpp
new file mode 100644
index 0000000..648bb23
--- /dev/null
+++ b/src/mainwindow/widgets/navigationbar.cpp
@@ -0,0 +1,115 @@
+/*
+ * 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: git://neueland.iserlohn-fortress.net/smolbote.git
+ *
+ * SPDX-License-Identifier: GPL-3.0
+ */
+
+#include "navigationbar.h"
+#include "mainwindow/mainwindow.h"
+#include "webengine/webview.h"
+#include <QHBoxLayout>
+#include <QStyle>
+#include <QToolBar>
+#include <QToolButton>
+#include <QWebEngineHistory>
+
+NavigationBar::NavigationBar(MainWindow *parent)
+ : QObject(parent)
+{
+ qStyle = parent->style();
+
+ backButton = new QToolButton(parent);
+ backButton->setIcon(qStyle->standardIcon(QStyle::SP_ArrowBack));
+ connect(backButton, &QToolButton::clicked, this, [this]() {
+ m_view->history()->back();
+ });
+
+ auto *backMenu = new QMenu(backButton);
+ backButton->setMenu(backMenu);
+ connect(backMenu, &QMenu::aboutToShow, this, [this, backMenu]() {
+ backMenu->clear();
+ const QList<QWebEngineHistoryItem> items = m_view->history()->backItems(10);
+ for(const QWebEngineHistoryItem &i : items) {
+ QAction *a = backMenu->addAction(i.title());
+ connect(a, &QAction::triggered, this, [i, this]() {
+ m_view->history()->goToItem(i);
+ });
+ }
+ });
+
+ forwardButton = new QToolButton(parent);
+ forwardButton->setIcon(qStyle->standardIcon(QStyle::SP_ArrowForward));
+ connect(forwardButton, &QToolButton::clicked, this, [this]() {
+ m_view->history()->forward();
+ });
+
+ auto *forwardMenu = new QMenu(forwardButton);
+ forwardButton->setMenu(forwardMenu);
+ connect(forwardMenu, &QMenu::aboutToShow, this, [this, forwardMenu]() {
+ forwardMenu->clear();
+ const QList<QWebEngineHistoryItem> items = m_view->history()->forwardItems(10);
+ for(const QWebEngineHistoryItem &i : items) {
+ QAction *a = forwardMenu->addAction(i.title());
+ connect(a, &QAction::triggered, this, [i, this]() {
+ m_view->history()->goToItem(i);
+ });
+ }
+ });
+
+ stopReloadButton = new QToolButton(parent);
+ stopReloadButton->setIcon(qStyle->standardIcon(QStyle::SP_BrowserReload));
+ connect(stopReloadButton, &QToolButton::clicked, this, [this]() {
+ if(m_view->isLoaded())
+ m_view->reload();
+ else
+ m_view->stop();
+ });
+
+ homeButton = new QToolButton(parent);
+ homeButton->setIcon(qStyle->standardIcon(QStyle::SP_DirHomeIcon));
+ connect(homeButton, &QToolButton::clicked, this, [this, parent]() {
+ m_view->load(parent->m_profile->homepage());
+ });
+}
+
+void NavigationBar::addWidgetsTo(QToolBar *toolBar)
+{
+ toolBar->addWidget(backButton);
+ toolBar->addWidget(forwardButton);
+ toolBar->addWidget(stopReloadButton);
+ toolBar->addWidget(homeButton);
+}
+
+void NavigationBar::connectWebView(WebView *view)
+{
+ Q_CHECK_PTR(view);
+ m_view = view;
+
+ disconnect(loadStartedConnection);
+ disconnect(loadFinishedConnection);
+
+ if(view->isLoaded()) {
+ update_loadFinished();
+ } else {
+ update_loadStarted();
+ }
+
+ loadStartedConnection = connect(view, &QWebEngineView::loadStarted, this, &NavigationBar::update_loadStarted);
+ loadFinishedConnection = connect(view, &QWebEngineView::loadFinished, this, &NavigationBar::update_loadFinished);
+}
+
+void NavigationBar::update_loadStarted()
+{
+ backButton->setEnabled(m_view->history()->canGoForward());
+ forwardButton->setEnabled(m_view->history()->canGoForward());
+ stopReloadButton->setIcon(qStyle->standardIcon(QStyle::SP_BrowserStop));
+}
+
+void NavigationBar::update_loadFinished()
+{
+ backButton->setEnabled(m_view->history()->canGoBack());
+ forwardButton->setEnabled(m_view->history()->canGoForward());
+ stopReloadButton->setIcon(qStyle->standardIcon(QStyle::SP_BrowserReload));
+}
diff --git a/src/mainwindow/widgets/navigationbar.h b/src/mainwindow/widgets/navigationbar.h
new file mode 100644
index 0000000..15a9c7b
--- /dev/null
+++ b/src/mainwindow/widgets/navigationbar.h
@@ -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: git://neueland.iserlohn-fortress.net/smolbote.git
+ *
+ * SPDX-License-Identifier: GPL-3.0
+ */
+
+/*
+ * Why is this class a QObject and not a QWidget, and why don't we add the
+ * NavigationBar itself to the toolbar?
+ * That was the original idea: make a NavBar class, friend it from MainWindow
+ * to gain access to the config, but there's a couple of issues:
+ * - adding QToolButtons to a widget that's inside a toolbar makes the buttons
+ * look absolutely hideous: they're smaller and have a border for some reason
+ * - if you stylesheet the border away (which is a pain), they're still not
+ * the same size
+ * And so we ended up having this class only exist to contain all of the logic
+ * for the nav buttons (which cuts down the code in MainWindow).
+ */
+
+#ifndef NAVIGATIONBAR_H
+#define NAVIGATIONBAR_H
+
+#include <QObject>
+
+class QStyle;
+class QToolBar;
+class QToolButton;
+class MainWindow;
+class WebView;
+class NavigationBar : public QObject
+{
+ Q_OBJECT
+public:
+ explicit NavigationBar(MainWindow *parent = nullptr);
+
+ void addWidgetsTo(QToolBar *toolBar);
+ void connectWebView(WebView *view);
+
+private slots:
+ void update_loadStarted();
+ void update_loadFinished();
+
+private:
+ QStyle *qStyle;
+ WebView *m_view;
+ QToolButton *backButton, *forwardButton;
+ QToolButton *stopReloadButton;
+ QToolButton *homeButton;
+
+ QMetaObject::Connection loadStartedConnection, loadFinishedConnection;
+};
+
+#endif //NAVIGATIONBAR_H
diff --git a/src/webengine/webview.cpp b/src/webengine/webview.cpp
index ea0ee26..c924144 100644
--- a/src/webengine/webview.cpp
+++ b/src/webengine/webview.cpp
@@ -26,7 +26,7 @@
#include <QPrinter>
#include <QPrinterInfo>
-#include "mainwindow.h"
+#include "src/mainwindow/mainwindow.h"
#include <QStatusBar>
// ssl errors
@@ -38,6 +38,17 @@ WebView::WebView(MainWindow *parentMainWindow, QWidget *parent)
Q_CHECK_PTR(parentMainWindow);
m_parent = parentMainWindow;
+ // load status and progress
+ connect(this, &QWebEngineView::loadStarted, this, [this]() {
+ m_loaded = false;
+ });
+ connect(this, &QWebEngineView::loadFinished, this, [this]() {
+ m_loaded = true;
+ });
+ connect(this, &QWebEngineView::loadProgress, this, [this](int progress) {
+ m_loadProgress = progress;
+ });
+
m_pageMenu = new QMenu();
m_pageMenu->setMinimumWidth(240);
@@ -137,6 +148,16 @@ void WebView::setPage(WebPage *page)
QWebEngineView::setPage(page);
}
+bool WebView::isLoaded() const
+{
+ return m_loaded;
+}
+
+int WebView::loadProgress() const
+{
+ return m_loadProgress;
+}
+
WebView *WebView::createWindow(QWebEnginePage::WebWindowType type)
{
WebView *view = new WebView(m_parent);
diff --git a/src/webengine/webview.h b/src/webengine/webview.h
index 18a1e02..78b85ce 100644
--- a/src/webengine/webview.h
+++ b/src/webengine/webview.h
@@ -24,12 +24,14 @@ public:
QMenu *pageMenu();
void setPage(WebPage *page);
+ bool isLoaded() const;
+ int loadProgress() const;
signals:
void newBookmark(const QString &title, const QUrl &url);
protected:
- WebView *createWindow(QWebEnginePage::WebWindowType type);
+ WebView *createWindow(QWebEnginePage::WebWindowType type) override;
private slots:
void handleLinkHovered(const QString &url);
@@ -38,6 +40,9 @@ private slots:
private:
MainWindow *m_parent = nullptr;
QMenu *m_pageMenu = nullptr;
+
+ bool m_loaded;
+ int m_loadProgress;
};
#endif // WEBVIEW_H
diff --git a/src/widgets/loadingbar.cpp b/src/widgets/loadingbar.cpp
deleted file mode 100644
index e72c5bb..0000000
--- a/src/widgets/loadingbar.cpp
+++ /dev/null
@@ -1,39 +0,0 @@
-/*
- * 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: git://neueland.iserlohn-fortress.net/smolbote.git
- *
- * SPDX-License-Identifier: GPL-3.0
- */
-
-#include "loadingbar.h"
-#include <QTimer>
-#include <QWebEngineView>
-
-LoadingBar::LoadingBar(QWidget *parent)
- : QProgressBar(parent)
-{
- setMaximum(100);
-}
-
-void LoadingBar::connectWebView(QWebEngineView *view)
-{
- disconnect(this);
-
- connect(view, SIGNAL(loadStarted()), this, SLOT(loadStarted()));
- connect(view, SIGNAL(loadProgress(int)), this, SLOT(setValue(int)));
- connect(view, SIGNAL(loadFinished(bool)), this, SLOT(loadFinished(bool)));
-}
-
-void LoadingBar::loadStarted()
-{
- resetFormat();
- show();
- setValue(0);
-}
-
-void LoadingBar::loadFinished(bool ok)
-{
- setFormat(QString("%p% %1").arg(ok ? tr("Finished") : tr("Failed")));
- QTimer::singleShot(2000, this, SLOT(hide()));
-}
diff --git a/src/widgets/mainwindowmenubar.cpp b/src/widgets/mainwindowmenubar.cpp
index f8275c0..bc86e77 100644
--- a/src/widgets/mainwindowmenubar.cpp
+++ b/src/widgets/mainwindowmenubar.cpp
@@ -8,7 +8,7 @@
#include "mainwindowmenubar.h"
#include "downloads/downloadswidget.h"
-#include "mainwindow.h"
+#include "src/mainwindow/mainwindow.h"
#include <QInputDialog>
MainWindowMenuBar::MainWindowMenuBar(std::shared_ptr<Configuration> config, MainWindow *parent)
diff --git a/src/widgets/mainwindowtabbar.cpp b/src/widgets/mainwindowtabbar.cpp
index 5cf360d..e669bf6 100644
--- a/src/widgets/mainwindowtabbar.cpp
+++ b/src/widgets/mainwindowtabbar.cpp
@@ -11,7 +11,7 @@
#include <QShortcut>
#include <settings/configuration.h>
-#include "mainwindow.h"
+#include "src/mainwindow/mainwindow.h"
MainWindowTabBar::MainWindowTabBar(const std::shared_ptr<Configuration> &config, MainWindow *parent)
: QTabBar(parent)