aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAqua-sama <aqua@iserlohn-fortress.net>2017-02-02 14:13:14 +0100
committerAqua-sama <aqua@iserlohn-fortress.net>2017-02-02 14:13:14 +0100
commitf875ad5313b86275c3fd48884063aefb8849235d (patch)
tree9c7933aacc895ab6a52045abc7fe8fb1dccb6c20 /src
parentAStyle pass (diff)
downloadsmolbote-f875ad5313b86275c3fd48884063aefb8849235d.tar.xz
Added loading bar to status bar
Hovered links now display in status bar
Diffstat (limited to 'src')
-rw-r--r--src/mainwindow.cpp23
-rw-r--r--src/mainwindow.h4
-rw-r--r--src/smolbote.qbs4
-rw-r--r--src/webengine/webview.cpp39
-rw-r--r--src/webengine/webview.h40
-rw-r--r--src/widgets/loadingbar.cpp48
-rw-r--r--src/widgets/loadingbar.h41
-rw-r--r--src/widgets/urllineedit.cpp6
-rw-r--r--src/widgets/webviewtabbar.cpp8
-rw-r--r--src/widgets/webviewtabbar.h10
10 files changed, 209 insertions, 14 deletions
diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp
index cc7003d..4cd8975 100644
--- a/src/mainwindow.cpp
+++ b/src/mainwindow.cpp
@@ -30,6 +30,7 @@
#include <QApplication>
#include <QInputDialog>
#include <QWebEngineDownloadItem>
+#include <QStatusBar>
MainWindow::MainWindow(Browser *instance, QUrl defaultUrl, QWidget *parent) :
QMainWindow(parent),
@@ -39,7 +40,8 @@ MainWindow::MainWindow(Browser *instance, QUrl defaultUrl, QWidget *parent) :
navigationToolBar(new QToolBar(tr("Navigation"), this)),
tabToolBar(new QToolBar(tr("Tab bar"), this)),
tabBar(new WebViewTabBar(this)),
- urlLineEdit(new UrlLineEdit(navigationToolBar))
+ urlLineEdit(new UrlLineEdit(navigationToolBar)),
+ progressBar(new LoadingBar(this))
{
browserInstance = instance;
Settings settings;
@@ -82,7 +84,9 @@ MainWindow::MainWindow(Browser *instance, QUrl defaultUrl, QWidget *parent) :
connect(urlLineEdit, SIGNAL(returnPressed()), this, SLOT(handleUrlChanged()));
tabToolBar->addWidget(tabBar);
- connect(tabBar, SIGNAL(currentTabChanged(QWebEngineView*)), this, SLOT(handleTabChanged(QWebEngineView*)));
+ connect(tabBar, SIGNAL(currentTabChanged(WebView*)), this, SLOT(handleTabChanged(WebView*)));
+
+ ui->statusBar->addPermanentWidget(progressBar);
if(!defaultUrl.isEmpty()) {
createNewTab(defaultUrl);
@@ -160,16 +164,27 @@ void MainWindow::handleNewWindow(const QUrl &url)
browserInstance->addWindow(new MainWindow(browserInstance, url));
}
-void MainWindow::handleTabChanged(QWebEngineView *view)
+void MainWindow::handleTabChanged(WebView *view)
{
+ // clear the parent of the central widget so it doesn't get deleted
centralWidget()->setParent(0);
+
+ // disconnect signals
disconnect(centralWidget());
+
+ // set new central widget
setCentralWidget(view);
+
+ // connect signals
connect(view, SIGNAL(urlChanged(QUrl)), urlLineEdit, SLOT(setUrl(QUrl)));
connect(view, SIGNAL(titleChanged(QString)), this, SLOT(handleTitleUpdated(QString)));
+ connect(view, SIGNAL(linkHovered(QString)), ui->statusBar, SLOT(showMessage(QString)));
+
+ progressBar->connectWebView(view);
+
+ // update UI
urlLineEdit->setUrl(view->url());
this->handleTitleUpdated(view->title());
-
centralWidget()->setFocus();
}
diff --git a/src/mainwindow.h b/src/mainwindow.h
index a9446be..e217c1f 100644
--- a/src/mainwindow.h
+++ b/src/mainwindow.h
@@ -31,6 +31,7 @@
#include "forms/downloaddialog.h"
#include "webengine/urlinterceptor.h"
#include "forms/blockerdialog.h"
+#include "widgets/loadingbar.h"
namespace Ui {
class MainWindow;
@@ -59,7 +60,7 @@ private slots:
void execProfileEditor();
void handleNewWindow(const QUrl &url = QUrl(""));
- void handleTabChanged(QWebEngineView *view);
+ void handleTabChanged(WebView *view);
void handleUrlChanged();
void handleTitleUpdated(const QString &title);
@@ -75,6 +76,7 @@ private:
QToolBar *navigationToolBar, *tabToolBar;
WebViewTabBar *tabBar;
UrlLineEdit *urlLineEdit;
+ LoadingBar *progressBar;
};
#endif // MAINWINDOW_H
diff --git a/src/smolbote.qbs b/src/smolbote.qbs
index c8ecb24..e3b9d44 100644
--- a/src/smolbote.qbs
+++ b/src/smolbote.qbs
@@ -57,6 +57,10 @@ Project {
"webengine/urlinterceptor.h",
"webengine/webengineprofile.cpp",
"webengine/webengineprofile.h",
+ "webengine/webview.cpp",
+ "webengine/webview.h",
+ "widgets/loadingbar.cpp",
+ "widgets/loadingbar.h",
"widgets/urllineedit.cpp",
"widgets/urllineedit.h",
"widgets/webviewtabbar.cpp",
diff --git a/src/webengine/webview.cpp b/src/webengine/webview.cpp
new file mode 100644
index 0000000..71708b7
--- /dev/null
+++ b/src/webengine/webview.cpp
@@ -0,0 +1,39 @@
+/** LICENSE ********************************************************************
+ **
+ ** 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 "webview.h"
+#include <QWebEnginePage>
+
+WebView::WebView(QWidget *parent) :
+ QWebEngineView(parent)
+{
+}
+
+void WebView::setPage(QWebEnginePage *page)
+{
+ disconnect(this->page(), SIGNAL(linkHovered(QString)), this, SLOT(handleLinkHovered(QString)));
+ connect(page, SIGNAL(linkHovered(QString)), this, SLOT(handleLinkHovered(QString)));
+ QWebEngineView::setPage(page);
+}
+
+void WebView::handleLinkHovered(const QString &url)
+{
+ emit linkHovered(url);
+}
diff --git a/src/webengine/webview.h b/src/webengine/webview.h
new file mode 100644
index 0000000..c833067
--- /dev/null
+++ b/src/webengine/webview.h
@@ -0,0 +1,40 @@
+/** LICENSE ********************************************************************
+ **
+ ** 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 WEBVIEW_H
+#define WEBVIEW_H
+
+#include <QWebEngineView>
+
+class WebView : public QWebEngineView
+{
+ Q_OBJECT
+public:
+ explicit WebView(QWidget *parent = 0);
+ void setPage(QWebEnginePage *page);
+
+signals:
+ void linkHovered(const QString &url);
+
+private slots:
+ void handleLinkHovered(const QString &url);
+};
+
+#endif // WEBVIEW_H
diff --git a/src/widgets/loadingbar.cpp b/src/widgets/loadingbar.cpp
new file mode 100644
index 0000000..31208b8
--- /dev/null
+++ b/src/widgets/loadingbar.cpp
@@ -0,0 +1,48 @@
+/** LICENSE ********************************************************************
+ **
+ ** 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 "loadingbar.h"
+#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()));
+}
+
+void LoadingBar::loadStarted()
+{
+ show();
+ setValue(0);
+}
+
+void LoadingBar::loadFinished()
+{
+ hide();
+}
diff --git a/src/widgets/loadingbar.h b/src/widgets/loadingbar.h
new file mode 100644
index 0000000..938549f
--- /dev/null
+++ b/src/widgets/loadingbar.h
@@ -0,0 +1,41 @@
+/** LICENSE ********************************************************************
+ **
+ ** 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 LOADINGBAR_H
+#define LOADINGBAR_H
+
+#include <QProgressBar>
+
+class QWebEngineView;
+class LoadingBar : public QProgressBar
+{
+ Q_OBJECT
+public:
+ explicit LoadingBar(QWidget *parent = 0);
+ void connectWebView(QWebEngineView *view);
+
+signals:
+
+public slots:
+ void loadStarted();
+ void loadFinished();
+};
+
+#endif // LOADINGBAR_H
diff --git a/src/widgets/urllineedit.cpp b/src/widgets/urllineedit.cpp
index 5c1f5c4..6f07a4a 100644
--- a/src/widgets/urllineedit.cpp
+++ b/src/widgets/urllineedit.cpp
@@ -20,6 +20,7 @@
#include "urllineedit.h"
#include <QUrl>
+#include <QTimer>
UrlLineEdit::UrlLineEdit(QWidget *parent) :
QLineEdit(parent)
@@ -54,6 +55,11 @@ void UrlLineEdit::focusInEvent(QFocusEvent *event)
{
clearTextFormat();
QLineEdit::focusInEvent(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()));
}
void UrlLineEdit::focusOutEvent(QFocusEvent *event)
diff --git a/src/widgets/webviewtabbar.cpp b/src/widgets/webviewtabbar.cpp
index aef2bd8..c091e56 100644
--- a/src/widgets/webviewtabbar.cpp
+++ b/src/widgets/webviewtabbar.cpp
@@ -37,7 +37,7 @@ WebViewTabBar::~WebViewTabBar()
int WebViewTabBar::addTab(QWebEngineProfile *profile, const QUrl &url)
{
- QWebEngineView *view = new QWebEngineView(0);
+ WebView *view = new WebView(0);
QWebEnginePage *page = new QWebEnginePage(profile);
view->setPage(page);
page->load(url);
@@ -65,7 +65,7 @@ void WebViewTabBar::setProfile(QWebEngineProfile *profile)
}
}
-QWebEngineView *WebViewTabBar::currentView()
+WebView *WebViewTabBar::currentView()
{
return m_views.at(currentIndex());
}
@@ -78,7 +78,7 @@ QSize WebViewTabBar::tabSizeHint(int index) const
void WebViewTabBar::handleCurrentChanged(int index)
{
- emit(currentTabChanged(m_views.at(index)));
+ emit currentTabChanged(m_views.at(index));
}
void WebViewTabBar::handleTabClose(int index)
@@ -88,7 +88,7 @@ void WebViewTabBar::handleTabClose(int index)
m_views.remove(index);
}
-void WebViewTabBar::updateTabText(QWebEngineView *view, const QString &text)
+void WebViewTabBar::updateTabText(WebView *view, const QString &text)
{
int index = m_views.indexOf(view);
setTabText(index, text);
diff --git a/src/widgets/webviewtabbar.h b/src/widgets/webviewtabbar.h
index bf7edb2..260100b 100644
--- a/src/widgets/webviewtabbar.h
+++ b/src/widgets/webviewtabbar.h
@@ -22,7 +22,7 @@
#define WEBVIEWTABBAR_H
#include <QTabBar>
-#include <QWebEngineView>
+#include "webengine/webview.h"
class WebViewTabBar : public QTabBar
{
@@ -35,10 +35,10 @@ public:
int addTab(QWebEngineProfile *profile, const QUrl &url);
void setProfile(QWebEngineProfile *profile);
- QWebEngineView *currentView();
+ WebView *currentView();
signals:
- void currentTabChanged(QWebEngineView *view);
+ void currentTabChanged(WebView *view);
protected:
QSize tabSizeHint(int index) const;
@@ -47,10 +47,10 @@ private slots:
void handleCurrentChanged(int index);
void handleTabClose(int index);
- void updateTabText(QWebEngineView *view, const QString &text);
+ void updateTabText(WebView *view, const QString &text);
private:
- QVector<QWebEngineView*> m_views;
+ QVector<WebView*> m_views;
};
#endif // WEBVIEWTABBAR_H