Made changes to web browser + several new classes.
This commit is contained in:
parent
b5922526e0
commit
b525d64592
@ -170,6 +170,8 @@ set(APP_SOURCES
|
|||||||
src/gui/webbrowser.cpp
|
src/gui/webbrowser.cpp
|
||||||
src/gui/basewebview.cpp
|
src/gui/basewebview.cpp
|
||||||
src/gui/basewebpage.cpp
|
src/gui/basewebpage.cpp
|
||||||
|
src/gui/baselineedit.cpp
|
||||||
|
src/gui/locationlineedit.cpp
|
||||||
|
|
||||||
# CORE sources.
|
# CORE sources.
|
||||||
src/core/debugging.cpp
|
src/core/debugging.cpp
|
||||||
@ -205,6 +207,8 @@ set(APP_HEADERS
|
|||||||
src/gui/webbrowser.h
|
src/gui/webbrowser.h
|
||||||
src/gui/basewebview.h
|
src/gui/basewebview.h
|
||||||
src/gui/basewebpage.h
|
src/gui/basewebpage.h
|
||||||
|
src/gui/baselineedit.h
|
||||||
|
src/gui/locationlineedit.h
|
||||||
|
|
||||||
# CORE headers.
|
# CORE headers.
|
||||||
src/core/basenetworkaccessmanager.h
|
src/core/basenetworkaccessmanager.h
|
||||||
|
19
src/gui/baselineedit.cpp
Normal file
19
src/gui/baselineedit.cpp
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
#include <QKeyEvent>
|
||||||
|
|
||||||
|
#include "gui/baselineedit.h"
|
||||||
|
|
||||||
|
|
||||||
|
BaseLineEdit::BaseLineEdit(QWidget *parent) : QLineEdit(parent) {
|
||||||
|
}
|
||||||
|
|
||||||
|
BaseLineEdit::~BaseLineEdit() {
|
||||||
|
}
|
||||||
|
|
||||||
|
void BaseLineEdit::keyPressEvent(QKeyEvent *event) {
|
||||||
|
if (event->key() == Qt::Key_Enter || event->key() == Qt::Key_Return) {
|
||||||
|
emit submitted(text());
|
||||||
|
event->accept();
|
||||||
|
}
|
||||||
|
|
||||||
|
QLineEdit::keyPressEvent(event);
|
||||||
|
}
|
23
src/gui/baselineedit.h
Normal file
23
src/gui/baselineedit.h
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
#ifndef BASELINEEDIT_H
|
||||||
|
#define BASELINEEDIT_H
|
||||||
|
|
||||||
|
#include <QLineEdit>
|
||||||
|
|
||||||
|
|
||||||
|
class BaseLineEdit : public QLineEdit {
|
||||||
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
explicit BaseLineEdit(QWidget *parent = 0);
|
||||||
|
virtual ~BaseLineEdit();
|
||||||
|
|
||||||
|
protected:
|
||||||
|
void keyPressEvent(QKeyEvent *event);
|
||||||
|
|
||||||
|
signals:
|
||||||
|
void submitted(const QString &text);
|
||||||
|
|
||||||
|
public slots:
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // BASELINEEDIT_H
|
@ -12,5 +12,18 @@ BaseWebView::BaseWebView(QWidget *parent)
|
|||||||
void BaseWebView::paintEvent(QPaintEvent *event) {
|
void BaseWebView::paintEvent(QPaintEvent *event) {
|
||||||
QWebView::paintEvent(event);
|
QWebView::paintEvent(event);
|
||||||
|
|
||||||
// TODO: Add frame, inspire from QFrame source code - paint event.
|
// Draw additional frame.
|
||||||
|
QPainter painter(this);
|
||||||
|
QStyleOptionFrameV3 style_option;
|
||||||
|
int frame_shape = QFrame::Sunken & QFrame::Shape_Mask;
|
||||||
|
|
||||||
|
style_option.init(this);
|
||||||
|
style_option.frameShape = QFrame::Shape(int(style_option.frameShape) |
|
||||||
|
QFrame::StyledPanel |
|
||||||
|
frame_shape);
|
||||||
|
style_option.rect = rect();
|
||||||
|
style_option.lineWidth = 1;
|
||||||
|
style_option.midLineWidth = 0;
|
||||||
|
|
||||||
|
style()->drawControl(QStyle::CE_ShapedFrame, &style_option, &painter, this);
|
||||||
}
|
}
|
||||||
|
@ -39,6 +39,8 @@ FormSettings::FormSettings(QWidget *parent) : QDialog(parent), m_ui(new Ui::Form
|
|||||||
connect(this, &FormSettings::accepted, this, &FormSettings::saveSettings);
|
connect(this, &FormSettings::accepted, this, &FormSettings::saveSettings);
|
||||||
connect(m_ui->m_cmbProxyType, static_cast<void (QComboBox::*)(int index)>(&QComboBox::currentIndexChanged),
|
connect(m_ui->m_cmbProxyType, static_cast<void (QComboBox::*)(int index)>(&QComboBox::currentIndexChanged),
|
||||||
this, &FormSettings::onProxyTypeChanged);
|
this, &FormSettings::onProxyTypeChanged);
|
||||||
|
connect(m_ui->m_checkShowPassword, &QCheckBox::stateChanged,
|
||||||
|
this, &FormSettings::displayProxyPassword);
|
||||||
|
|
||||||
// Load all settings.
|
// Load all settings.
|
||||||
loadGeneral();
|
loadGeneral();
|
||||||
@ -52,6 +54,15 @@ FormSettings::~FormSettings() {
|
|||||||
delete m_ui;
|
delete m_ui;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void FormSettings::displayProxyPassword(int state) {
|
||||||
|
if (state == Qt::Checked) {
|
||||||
|
m_ui->m_txtProxyPassword->setEchoMode(QLineEdit::Normal);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
m_ui->m_txtProxyPassword->setEchoMode(QLineEdit::PasswordEchoOnEdit);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void FormSettings::saveSettings() {
|
void FormSettings::saveSettings() {
|
||||||
// Save all settings.
|
// Save all settings.
|
||||||
saveGeneral();
|
saveGeneral();
|
||||||
@ -78,10 +89,33 @@ void FormSettings::loadProxy() {
|
|||||||
m_ui->m_cmbProxyType->addItem(tr("No proxy"), QNetworkProxy::NoProxy);
|
m_ui->m_cmbProxyType->addItem(tr("No proxy"), QNetworkProxy::NoProxy);
|
||||||
m_ui->m_cmbProxyType->addItem(tr("Socks5"), QNetworkProxy::Socks5Proxy);
|
m_ui->m_cmbProxyType->addItem(tr("Socks5"), QNetworkProxy::Socks5Proxy);
|
||||||
m_ui->m_cmbProxyType->addItem(tr("Http"), QNetworkProxy::HttpProxy);
|
m_ui->m_cmbProxyType->addItem(tr("Http"), QNetworkProxy::HttpProxy);
|
||||||
|
|
||||||
|
// Load the settings.
|
||||||
|
QNetworkProxy::ProxyType selected_proxy_type = static_cast<QNetworkProxy::ProxyType>(Settings::getInstance()->value(APP_CFG_PROXY,
|
||||||
|
"proxy_type",
|
||||||
|
QNetworkProxy::NoProxy).toInt());
|
||||||
|
m_ui->m_cmbProxyType->setCurrentIndex(m_ui->m_cmbProxyType->findData(selected_proxy_type));
|
||||||
|
m_ui->m_txtProxyHost->setText(Settings::getInstance()->value(APP_CFG_PROXY,
|
||||||
|
"host").toString());
|
||||||
|
m_ui->m_txtProxyUsername->setText(Settings::getInstance()->value(APP_CFG_PROXY,
|
||||||
|
"username").toString());
|
||||||
|
m_ui->m_txtProxyPassword->setText(Settings::getInstance()->value(APP_CFG_PROXY,
|
||||||
|
"password").toString());
|
||||||
|
m_ui->m_spinProxyPort->setValue(Settings::getInstance()->value(APP_CFG_PROXY,
|
||||||
|
"port", 80).toInt());
|
||||||
}
|
}
|
||||||
|
|
||||||
void FormSettings::saveProxy() {
|
void FormSettings::saveProxy() {
|
||||||
|
Settings::getInstance()->setValue(APP_CFG_PROXY, "proxy_type",
|
||||||
|
m_ui->m_cmbProxyType->itemData(m_ui->m_cmbProxyType->currentIndex()));
|
||||||
|
Settings::getInstance()->setValue(APP_CFG_PROXY, "host",
|
||||||
|
m_ui->m_txtProxyHost->text());
|
||||||
|
Settings::getInstance()->setValue(APP_CFG_PROXY, "username",
|
||||||
|
m_ui->m_txtProxyUsername->text());
|
||||||
|
Settings::getInstance()->setValue(APP_CFG_PROXY, "password",
|
||||||
|
m_ui->m_txtProxyPassword->text());
|
||||||
|
Settings::getInstance()->setValue(APP_CFG_PROXY, "port",
|
||||||
|
m_ui->m_spinProxyPort->value());
|
||||||
}
|
}
|
||||||
|
|
||||||
void FormSettings::loadLanguage() {
|
void FormSettings::loadLanguage() {
|
||||||
|
@ -36,6 +36,7 @@ class FormSettings : public QDialog {
|
|||||||
|
|
||||||
void loadProxy();
|
void loadProxy();
|
||||||
void saveProxy();
|
void saveProxy();
|
||||||
|
void displayProxyPassword(int state);
|
||||||
|
|
||||||
void onProxyTypeChanged(int index);
|
void onProxyTypeChanged(int index);
|
||||||
|
|
||||||
|
@ -117,8 +117,8 @@
|
|||||||
<rect>
|
<rect>
|
||||||
<x>0</x>
|
<x>0</x>
|
||||||
<y>0</y>
|
<y>0</y>
|
||||||
<width>506</width>
|
<width>100</width>
|
||||||
<height>368</height>
|
<height>30</height>
|
||||||
</rect>
|
</rect>
|
||||||
</property>
|
</property>
|
||||||
<layout class="QHBoxLayout" name="horizontalLayout_4">
|
<layout class="QHBoxLayout" name="horizontalLayout_4">
|
||||||
@ -423,7 +423,7 @@
|
|||||||
<bool>true</bool>
|
<bool>true</bool>
|
||||||
</property>
|
</property>
|
||||||
<property name="echoMode">
|
<property name="echoMode">
|
||||||
<enum>QLineEdit::Password</enum>
|
<enum>QLineEdit::PasswordEchoOnEdit</enum>
|
||||||
</property>
|
</property>
|
||||||
<property name="placeholderText">
|
<property name="placeholderText">
|
||||||
<string>Your password for proxy server authentication</string>
|
<string>Your password for proxy server authentication</string>
|
||||||
|
40
src/gui/locationlineedit.cpp
Normal file
40
src/gui/locationlineedit.cpp
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
#include <QPaintEvent>
|
||||||
|
|
||||||
|
#include "gui/locationlineedit.h"
|
||||||
|
|
||||||
|
|
||||||
|
LocationLineEdit::LocationLineEdit(QWidget *parent)
|
||||||
|
: BaseLineEdit(parent), m_progress(0), m_mouseSelectsAllText(true) {
|
||||||
|
}
|
||||||
|
|
||||||
|
LocationLineEdit::~LocationLineEdit() {
|
||||||
|
}
|
||||||
|
|
||||||
|
void LocationLineEdit::setProgress(int progress) {
|
||||||
|
m_progress = progress;
|
||||||
|
}
|
||||||
|
|
||||||
|
void LocationLineEdit::focusOutEvent(QFocusEvent *event) {
|
||||||
|
BaseLineEdit::focusOutEvent(event);
|
||||||
|
|
||||||
|
// User now left text box, when he enters it again and clicks,
|
||||||
|
// then all text should be selected.
|
||||||
|
m_mouseSelectsAllText = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void LocationLineEdit::mousePressEvent(QMouseEvent *event) {
|
||||||
|
if (m_mouseSelectsAllText) {
|
||||||
|
event->ignore();
|
||||||
|
selectAll();
|
||||||
|
|
||||||
|
// User clicked and all text was selected.
|
||||||
|
m_mouseSelectsAllText = false;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
BaseLineEdit::mousePressEvent(event);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void LocationLineEdit::paintEvent(QPaintEvent *event) {
|
||||||
|
BaseLineEdit::paintEvent(event);
|
||||||
|
}
|
29
src/gui/locationlineedit.h
Normal file
29
src/gui/locationlineedit.h
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
#ifndef LOCATIONLINEEDIT_H
|
||||||
|
#define LOCATIONLINEEDIT_H
|
||||||
|
|
||||||
|
#include "gui/baselineedit.h"
|
||||||
|
|
||||||
|
|
||||||
|
class WebBrowser;
|
||||||
|
|
||||||
|
class LocationLineEdit : public BaseLineEdit {
|
||||||
|
public:
|
||||||
|
explicit LocationLineEdit(QWidget *parent = 0);
|
||||||
|
virtual ~LocationLineEdit();
|
||||||
|
|
||||||
|
public slots:
|
||||||
|
// Sets percentual value of web page loading action.
|
||||||
|
// NOTE: Number ranging from 0 to 100 is expected.
|
||||||
|
void setProgress(int progress);
|
||||||
|
|
||||||
|
protected:
|
||||||
|
void focusOutEvent(QFocusEvent *event);
|
||||||
|
void mousePressEvent(QMouseEvent *event);
|
||||||
|
void paintEvent(QPaintEvent *event);
|
||||||
|
|
||||||
|
private:
|
||||||
|
int m_progress;
|
||||||
|
bool m_mouseSelectsAllText;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // LOCATIONLINEEDIT_H
|
@ -2,11 +2,13 @@
|
|||||||
#include <QToolBar>
|
#include <QToolBar>
|
||||||
#include <QAction>
|
#include <QAction>
|
||||||
#include <QPointer>
|
#include <QPointer>
|
||||||
#include <QLineEdit>
|
|
||||||
|
#include <QMessageBox>
|
||||||
|
|
||||||
#include "core/basenetworkaccessmanager.h"
|
#include "core/basenetworkaccessmanager.h"
|
||||||
#include "gui/basewebview.h"
|
#include "gui/basewebview.h"
|
||||||
#include "gui/webbrowser.h"
|
#include "gui/webbrowser.h"
|
||||||
|
#include "gui/locationlineedit.h"
|
||||||
#include "gui/themefactory.h"
|
#include "gui/themefactory.h"
|
||||||
|
|
||||||
|
|
||||||
@ -17,6 +19,7 @@ WebBrowser::WebBrowser(QWidget *parent)
|
|||||||
: QWidget(parent), m_layout(new QVBoxLayout(this)),
|
: QWidget(parent), m_layout(new QVBoxLayout(this)),
|
||||||
m_toolBar(new QToolBar(tr("Navigation panel"), this)),
|
m_toolBar(new QToolBar(tr("Navigation panel"), this)),
|
||||||
m_webView(new BaseWebView(this)),
|
m_webView(new BaseWebView(this)),
|
||||||
|
m_txtLocation(new LocationLineEdit(this)),
|
||||||
m_actionBack(m_webView->pageAction(QWebPage::Back)),
|
m_actionBack(m_webView->pageAction(QWebPage::Back)),
|
||||||
m_actionForward(m_webView->pageAction(QWebPage::Forward)),
|
m_actionForward(m_webView->pageAction(QWebPage::Forward)),
|
||||||
m_actionReload(m_webView->pageAction(QWebPage::Reload)),
|
m_actionReload(m_webView->pageAction(QWebPage::Reload)),
|
||||||
@ -31,27 +34,60 @@ WebBrowser::WebBrowser(QWidget *parent)
|
|||||||
// and main window will be responsible for reloading
|
// and main window will be responsible for reloading
|
||||||
// icons on all web browsers.
|
// icons on all web browsers.
|
||||||
|
|
||||||
// Set toolbar properties.
|
// Set properties of some components.
|
||||||
m_toolBar->layout()->setMargin(0);
|
m_toolBar->layout()->setMargin(0);
|
||||||
m_toolBar->setFloatable(false);
|
m_toolBar->setFloatable(false);
|
||||||
m_toolBar->setMovable(false);
|
m_toolBar->setMovable(false);
|
||||||
|
|
||||||
|
// Modify action texts.
|
||||||
|
m_actionBack->setText(tr("Back"));
|
||||||
|
m_actionBack->setToolTip(tr("Go back"));
|
||||||
|
m_actionForward->setText(tr("Forward"));
|
||||||
|
m_actionForward->setToolTip(tr("Go forward"));
|
||||||
|
m_actionReload->setText(tr("Reload"));
|
||||||
|
m_actionReload->setToolTip(tr("Reload current web page"));
|
||||||
|
m_actionStop->setText(tr("Stop"));
|
||||||
|
m_actionStop->setToolTip(tr("Stop web page loading"));
|
||||||
|
|
||||||
// Add needed actions into toolbar.
|
// Add needed actions into toolbar.
|
||||||
m_toolBar->addAction(m_actionBack);
|
m_toolBar->addAction(m_actionBack);
|
||||||
m_toolBar->addAction(m_actionForward);
|
m_toolBar->addAction(m_actionForward);
|
||||||
m_toolBar->addSeparator();
|
m_toolBar->addSeparator();
|
||||||
m_toolBar->addAction(m_actionReload);
|
m_toolBar->addAction(m_actionReload);
|
||||||
m_toolBar->addAction(m_actionStop);
|
m_toolBar->addAction(m_actionStop);
|
||||||
|
m_toolBar->addWidget(m_txtLocation);
|
||||||
QLineEdit *ed = new QLineEdit(this);
|
|
||||||
m_toolBar->addWidget(ed);
|
|
||||||
|
|
||||||
// Setup layout.
|
// Setup layout.
|
||||||
m_layout->addWidget(m_toolBar);
|
m_layout->addWidget(m_toolBar);
|
||||||
m_layout->addWidget(m_webView);
|
m_layout->addWidget(m_webView);
|
||||||
m_layout->setMargin(0);
|
m_layout->setMargin(0);
|
||||||
|
|
||||||
m_webView->load(QUrl("http://www.seznam.cz"));
|
createConnections();
|
||||||
|
}
|
||||||
|
|
||||||
|
void WebBrowser::createConnections() {
|
||||||
|
// When user confirms new url, then redirect to it.
|
||||||
|
connect(m_txtLocation, &LocationLineEdit::submitted,
|
||||||
|
this, &WebBrowser::navigateToUrl);
|
||||||
|
// If new page loads, then update current url.
|
||||||
|
connect(m_webView, &BaseWebView::urlChanged,
|
||||||
|
this, &WebBrowser::updateUrl);
|
||||||
|
|
||||||
|
// Change location textbox status according to webpage status.
|
||||||
|
connect(m_webView, &BaseWebView::loadProgress,
|
||||||
|
m_txtLocation, &LocationLineEdit::setProgress);
|
||||||
|
}
|
||||||
|
|
||||||
|
void WebBrowser::updateUrl(const QUrl &url) {
|
||||||
|
m_txtLocation->setText(url.toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
void WebBrowser::navigateToUrl(const QString &textual_url) {
|
||||||
|
QUrl extracted_url = QUrl::fromUserInput(textual_url);
|
||||||
|
|
||||||
|
if (extracted_url.isValid()) {
|
||||||
|
m_webView->setUrl(extracted_url);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
WebBrowser::~WebBrowser() {
|
WebBrowser::~WebBrowser() {
|
||||||
|
@ -6,6 +6,7 @@
|
|||||||
|
|
||||||
class QToolBar;
|
class QToolBar;
|
||||||
class QVBoxLayout;
|
class QVBoxLayout;
|
||||||
|
class LocationLineEdit;
|
||||||
class BaseWebView;
|
class BaseWebView;
|
||||||
class BaseNetworkAccessManager;
|
class BaseNetworkAccessManager;
|
||||||
|
|
||||||
@ -21,10 +22,18 @@ class WebBrowser : public QWidget {
|
|||||||
static BaseNetworkAccessManager *globalNetworkManager();
|
static BaseNetworkAccessManager *globalNetworkManager();
|
||||||
static QList<WebBrowser*> runningWebBrowsers();
|
static QList<WebBrowser*> runningWebBrowsers();
|
||||||
|
|
||||||
|
protected:
|
||||||
|
void createConnections();
|
||||||
|
|
||||||
|
protected slots:
|
||||||
|
void updateUrl(const QUrl &url);
|
||||||
|
void navigateToUrl(const QString &url);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QToolBar *m_toolBar;
|
|
||||||
QVBoxLayout *m_layout;
|
QVBoxLayout *m_layout;
|
||||||
|
QToolBar *m_toolBar;
|
||||||
BaseWebView *m_webView;
|
BaseWebView *m_webView;
|
||||||
|
LocationLineEdit *m_txtLocation;
|
||||||
|
|
||||||
QAction *m_actionBack;
|
QAction *m_actionBack;
|
||||||
QAction *m_actionForward;
|
QAction *m_actionForward;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user