Work on web browser.
This commit is contained in:
parent
d779e74557
commit
93a191058e
@ -169,7 +169,6 @@ set(APP_SOURCES
|
||||
src/gui/dynamicshortcutswidget.cpp
|
||||
src/gui/webbrowser.cpp
|
||||
src/gui/basewebview.cpp
|
||||
src/gui/basewebpage.cpp
|
||||
src/gui/baselineedit.cpp
|
||||
src/gui/locationlineedit.cpp
|
||||
|
||||
@ -181,6 +180,7 @@ set(APP_SOURCES
|
||||
src/core/localization.cpp
|
||||
src/core/dynamicshortcuts.cpp
|
||||
src/core/basenetworkaccessmanager.cpp
|
||||
src/core/basewebpage.cpp
|
||||
src/core/webBrowsernetworkaccessmanager.cpp
|
||||
|
||||
# Basic application sources.
|
||||
@ -207,13 +207,13 @@ set(APP_HEADERS
|
||||
src/gui/dynamicshortcutswidget.h
|
||||
src/gui/webbrowser.h
|
||||
src/gui/basewebview.h
|
||||
src/gui/basewebpage.h
|
||||
src/gui/baselineedit.h
|
||||
src/gui/locationlineedit.h
|
||||
|
||||
# CORE headers.
|
||||
src/core/basenetworkaccessmanager.h
|
||||
src/core/webBrowsernetworkaccessmanager.h
|
||||
src/core/basewebpage.h
|
||||
)
|
||||
|
||||
# Add form files.
|
||||
|
@ -4,13 +4,18 @@
|
||||
#include <QNetworkAccessManager>
|
||||
|
||||
|
||||
// This is base class for all network access managers.
|
||||
class BaseNetworkAccessManager : public QNetworkAccessManager {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
// Constructors and desctructors.
|
||||
explicit BaseNetworkAccessManager(QObject *parent = 0);
|
||||
virtual ~BaseNetworkAccessManager();
|
||||
|
||||
public slots:
|
||||
// Loads network settings for this instance.
|
||||
// NOTE: This sets up proxy settings.
|
||||
virtual void loadSettings();
|
||||
|
||||
protected:
|
||||
|
16
src/core/basewebpage.cpp
Normal file
16
src/core/basewebpage.cpp
Normal file
@ -0,0 +1,16 @@
|
||||
#include <QNetworkReply>
|
||||
#include <QWebFrame>
|
||||
|
||||
#include "core/webbrowsernetworkaccessmanager.h"
|
||||
#include "core/basewebpage.h"
|
||||
#include "gui/webbrowser.h"
|
||||
|
||||
|
||||
BaseWebPage::BaseWebPage(QObject *parent) : QWebPage(parent) {
|
||||
// Setup global network access manager.
|
||||
// NOTE: This makes network settings easy for all web browsers.
|
||||
setNetworkAccessManager(WebBrowser::globalNetworkManager());
|
||||
}
|
||||
|
||||
BaseWebPage::~BaseWebPage() {
|
||||
}
|
@ -6,13 +6,11 @@
|
||||
|
||||
class BaseWebPage : public QWebPage {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
// Constructors and destructors.
|
||||
explicit BaseWebPage(QObject *parent = 0);
|
||||
|
||||
signals:
|
||||
|
||||
public slots:
|
||||
|
||||
virtual ~BaseWebPage();
|
||||
};
|
||||
|
||||
#endif // BASEWEBPAGE_H
|
@ -4,9 +4,12 @@
|
||||
#include "core/basenetworkaccessmanager.h"
|
||||
|
||||
|
||||
// This is custom network access manager for web browsers.
|
||||
class WebBrowserNetworkAccessManager : public BaseNetworkAccessManager {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
// Constructors and destructors.
|
||||
explicit WebBrowserNetworkAccessManager(QObject *parent = 0);
|
||||
virtual ~WebBrowserNetworkAccessManager();
|
||||
|
||||
|
@ -7,6 +7,7 @@
|
||||
class BaseLineEdit : public QLineEdit {
|
||||
Q_OBJECT
|
||||
public:
|
||||
// Constructors and destructors.
|
||||
explicit BaseLineEdit(QWidget *parent = 0);
|
||||
virtual ~BaseLineEdit();
|
||||
|
||||
@ -14,10 +15,8 @@ class BaseLineEdit : public QLineEdit {
|
||||
void keyPressEvent(QKeyEvent *event);
|
||||
|
||||
signals:
|
||||
// Emitted if user hits ENTER button.
|
||||
void submitted(const QString &text);
|
||||
|
||||
public slots:
|
||||
|
||||
};
|
||||
|
||||
#endif // BASELINEEDIT_H
|
||||
|
@ -1,8 +0,0 @@
|
||||
#include "core/webbrowsernetworkaccessmanager.h"
|
||||
#include "gui/basewebpage.h"
|
||||
#include "gui/webbrowser.h"
|
||||
|
||||
|
||||
BaseWebPage::BaseWebPage(QObject *parent) : QWebPage(parent) {
|
||||
setNetworkAccessManager(WebBrowser::globalNetworkManager());
|
||||
}
|
@ -1,12 +1,33 @@
|
||||
#include <QStyleOptionFrameV3>
|
||||
|
||||
#include "core/basewebpage.h"
|
||||
#include "gui/basewebview.h"
|
||||
#include "gui/basewebpage.h"
|
||||
|
||||
|
||||
BaseWebView::BaseWebView(QWidget *parent)
|
||||
: QWebView(parent), m_page(new BaseWebPage(this)) {
|
||||
setPage(m_page);
|
||||
createConnections();
|
||||
}
|
||||
|
||||
BaseWebView::~BaseWebView() {
|
||||
}
|
||||
|
||||
void BaseWebView::onLoadFinished(bool ok) {
|
||||
// If page was not loaded, then display custom error page.
|
||||
if (!ok) {
|
||||
displayErrorPage();
|
||||
}
|
||||
}
|
||||
|
||||
void BaseWebView::createConnections() {
|
||||
connect(this, &BaseWebView::loadFinished,
|
||||
this, &BaseWebView::onLoadFinished);
|
||||
}
|
||||
|
||||
void BaseWebView::displayErrorPage() {
|
||||
// TODO: Add better custom error page.
|
||||
setHtml("error", url());
|
||||
}
|
||||
|
||||
void BaseWebView::paintEvent(QPaintEvent *event) {
|
||||
@ -15,7 +36,7 @@ void BaseWebView::paintEvent(QPaintEvent *event) {
|
||||
// Draw additional frame.
|
||||
QPainter painter(this);
|
||||
QStyleOptionFrameV3 style_option;
|
||||
int frame_shape = QFrame::Sunken & QFrame::Shape_Mask;
|
||||
int frame_shape = QFrame::Sunken & QFrame::Shape_Mask;
|
||||
|
||||
style_option.init(this);
|
||||
style_option.frameShape = QFrame::Shape(int(style_option.frameShape) |
|
||||
|
@ -9,10 +9,24 @@ class BaseWebPage;
|
||||
|
||||
class BaseWebView : public QWebView {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
// Constructors and destructors.
|
||||
explicit BaseWebView(QWidget *parent = 0);
|
||||
|
||||
virtual ~BaseWebView();
|
||||
|
||||
protected slots:
|
||||
// Executes if loading of any page is done.
|
||||
void onLoadFinished(bool ok);
|
||||
|
||||
protected:
|
||||
// Creates necessary connections.
|
||||
void createConnections();
|
||||
|
||||
// Displays custom error page.
|
||||
void displayErrorPage();
|
||||
|
||||
// Does additional painting.
|
||||
void paintEvent(QPaintEvent *event);
|
||||
|
||||
private:
|
||||
|
@ -13,6 +13,7 @@ class DynamicShortcutsWidget : public QWidget {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
// Constructors and destructors.
|
||||
explicit DynamicShortcutsWidget(QWidget *parent = 0);
|
||||
virtual ~DynamicShortcutsWidget();
|
||||
|
||||
|
@ -1,10 +1,16 @@
|
||||
#include <QPaintEvent>
|
||||
#include <QStyleOptionFrameV2>
|
||||
#include <QPainter>
|
||||
#include <QApplication>
|
||||
|
||||
#include "gui/locationlineedit.h"
|
||||
|
||||
|
||||
LocationLineEdit::LocationLineEdit(QWidget *parent)
|
||||
: BaseLineEdit(parent), m_progress(0), m_mouseSelectsAllText(true) {
|
||||
: BaseLineEdit(parent),
|
||||
m_progress(0),
|
||||
m_defaultPalette(palette()),
|
||||
m_mouseSelectsAllText(true) {
|
||||
}
|
||||
|
||||
LocationLineEdit::~LocationLineEdit() {
|
||||
@ -12,6 +18,11 @@ LocationLineEdit::~LocationLineEdit() {
|
||||
|
||||
void LocationLineEdit::setProgress(int progress) {
|
||||
m_progress = progress;
|
||||
update();
|
||||
}
|
||||
|
||||
void LocationLineEdit::clearProgress() {
|
||||
setProgress(0);
|
||||
}
|
||||
|
||||
void LocationLineEdit::focusOutEvent(QFocusEvent *event) {
|
||||
@ -36,5 +47,26 @@ void LocationLineEdit::mousePressEvent(QMouseEvent *event) {
|
||||
}
|
||||
|
||||
void LocationLineEdit::paintEvent(QPaintEvent *event) {
|
||||
// Draw "progress bar" if needed.
|
||||
if (m_progress > 0) {
|
||||
QPalette current_palette = palette();
|
||||
QColor loadingColor = QColor(0, 255, 0, 100);
|
||||
QLinearGradient gradient(0, 0, width(), 0);
|
||||
qreal percentage_border = m_progress / 100.0;
|
||||
|
||||
gradient.setColorAt(0, loadingColor);
|
||||
gradient.setColorAt(percentage_border - 0.01, loadingColor);
|
||||
gradient.setColorAt(percentage_border - 0.008, loadingColor.lighter(130));
|
||||
//gradient.setColorAt(percentage_border - 0.002, loadingColor);
|
||||
gradient.setColorAt(percentage_border, QApplication::palette().color(QPalette::Base));
|
||||
current_palette.setBrush(QPalette::Base, gradient);
|
||||
|
||||
setPalette(current_palette);
|
||||
}
|
||||
// No "progress bar" is needed, restore default palette.
|
||||
else {
|
||||
setPalette(m_defaultPalette);
|
||||
}
|
||||
|
||||
BaseLineEdit::paintEvent(event);
|
||||
}
|
||||
|
@ -15,6 +15,7 @@ class LocationLineEdit : public BaseLineEdit {
|
||||
// Sets percentual value of web page loading action.
|
||||
// NOTE: Number ranging from 0 to 100 is expected.
|
||||
void setProgress(int progress);
|
||||
void clearProgress();
|
||||
|
||||
protected:
|
||||
void focusOutEvent(QFocusEvent *event);
|
||||
@ -23,6 +24,7 @@ class LocationLineEdit : public BaseLineEdit {
|
||||
|
||||
private:
|
||||
int m_progress;
|
||||
QPalette m_defaultPalette;
|
||||
bool m_mouseSelectsAllText;
|
||||
};
|
||||
|
||||
|
@ -8,8 +8,8 @@
|
||||
|
||||
#include "core/basenetworkaccessmanager.h"
|
||||
#include "core/webbrowsernetworkaccessmanager.h"
|
||||
#include "core/basewebpage.h"
|
||||
#include "gui/basewebview.h"
|
||||
#include "gui/basewebpage.h"
|
||||
#include "gui/webbrowser.h"
|
||||
#include "gui/locationlineedit.h"
|
||||
#include "gui/themefactory.h"
|
||||
@ -77,8 +77,10 @@ void WebBrowser::createConnections() {
|
||||
this, &WebBrowser::updateUrl);
|
||||
|
||||
// Change location textbox status according to webpage status.
|
||||
connect(m_webView->page(), &BaseWebPage::loadProgress,
|
||||
connect(m_webView, &BaseWebView::loadProgress,
|
||||
m_txtLocation, &LocationLineEdit::setProgress);
|
||||
connect(m_webView, &BaseWebView::loadFinished,
|
||||
m_txtLocation, &LocationLineEdit::clearProgress);
|
||||
}
|
||||
|
||||
void WebBrowser::updateUrl(const QUrl &url) {
|
||||
|
@ -14,19 +14,31 @@ class WebBrowser : public QWidget {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
// Constructors and destructors.
|
||||
explicit WebBrowser(QWidget *parent = 0);
|
||||
~WebBrowser();
|
||||
|
||||
// Reloads icons for all buttons.
|
||||
void setupIcons();
|
||||
|
||||
// Returns pointer to global network access manager
|
||||
// for web browsers.
|
||||
// NOTE: All web browsers use shared network access manager,
|
||||
// which makes setting of custom network settings easy.
|
||||
static WebBrowserNetworkAccessManager *globalNetworkManager();
|
||||
|
||||
// Returns list of all running web browsers.
|
||||
static QList<WebBrowser*> runningWebBrowsers();
|
||||
|
||||
protected:
|
||||
// Creates necessary connections.
|
||||
void createConnections();
|
||||
|
||||
protected slots:
|
||||
// Updates url (for example on location text box).
|
||||
void updateUrl(const QUrl &url);
|
||||
|
||||
// Loads new url into the web browser.
|
||||
void navigateToUrl(const QString &url);
|
||||
|
||||
private:
|
||||
|
Loading…
x
Reference in New Issue
Block a user