More work on context menus etc.
This commit is contained in:
parent
8120ff6467
commit
888b55b00d
5 changed files with 24 additions and 108 deletions
|
|
@ -201,15 +201,14 @@ void WebBrowser::createConnections() {
|
||||||
|
|
||||||
// Forward title/icon changes.
|
// Forward title/icon changes.
|
||||||
connect(m_webView, SIGNAL(titleChanged(QString)), this, SLOT(onTitleChanged(QString)));
|
connect(m_webView, SIGNAL(titleChanged(QString)), this, SLOT(onTitleChanged(QString)));
|
||||||
connect(m_webView, SIGNAL(iconChanged()), this, SLOT(onIconChanged()));
|
connect(m_webView, SIGNAL(iconUrlChanged(QUrl)), this, SLOT(onIconChanged()));
|
||||||
|
|
||||||
// Misc connections.
|
// Misc connections.
|
||||||
connect(m_webView, SIGNAL(zoomFactorChanged()), this, SLOT(updateZoomGui()));
|
connect(m_webView, SIGNAL(zoomFactorChanged()), this, SLOT(updateZoomGui()));
|
||||||
}
|
}
|
||||||
|
|
||||||
void WebBrowser::onIconChanged() {
|
void WebBrowser::onIconChanged() {
|
||||||
// TODO: todo
|
emit iconChanged(m_index, icon());
|
||||||
//emit iconChanged(m_index, m_webView->icon());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void WebBrowser::onTitleChanged(const QString &new_title) {
|
void WebBrowser::onTitleChanged(const QString &new_title) {
|
||||||
|
|
@ -321,9 +320,16 @@ void WebBrowser::setupIcons() {
|
||||||
}
|
}
|
||||||
|
|
||||||
QIcon WebBrowser::icon() const {
|
QIcon WebBrowser::icon() const {
|
||||||
|
QUrl url = m_webView->iconUrl();
|
||||||
|
|
||||||
|
if (url.isValid()) {
|
||||||
|
QByteArray output;
|
||||||
|
if (NetworkFactory::downloadFile(url.toString(), DOWNLOAD_TIMEOUT, output).first == QNetworkReply::NoError) {
|
||||||
|
QPixmap icon_pixmap;
|
||||||
|
icon_pixmap.loadFromData(output);
|
||||||
|
return QIcon(icon_pixmap);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return QIcon();
|
return QIcon();
|
||||||
|
|
||||||
// TODO: TODO.
|
|
||||||
//return m_webView->iconUrl();
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -17,28 +17,9 @@
|
||||||
|
|
||||||
#include "network-web/webpage.h"
|
#include "network-web/webpage.h"
|
||||||
|
|
||||||
#include "network-web/webbrowser.h"
|
|
||||||
#include "miscellaneous/application.h"
|
|
||||||
|
|
||||||
|
WebPage::WebPage(QObject *parent) : QWebEnginePage(parent) {
|
||||||
WebPage::WebPage(QObject *parent)
|
|
||||||
: QWebEnginePage(parent), m_loadProgress(-1) {
|
|
||||||
connect(this, SIGNAL(loadProgress(int)), this, SLOT(progress(int)));
|
|
||||||
connect(this, SIGNAL(loadFinished(bool)), this, SLOT(finished()));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
WebPage::~WebPage() {
|
WebPage::~WebPage() {
|
||||||
}
|
}
|
||||||
|
|
||||||
bool WebPage::isLoading() const {
|
|
||||||
// TODO: nepouzivany?
|
|
||||||
return m_loadProgress < 100;
|
|
||||||
}
|
|
||||||
|
|
||||||
void WebPage::progress(int prog) {
|
|
||||||
m_loadProgress = prog;
|
|
||||||
}
|
|
||||||
|
|
||||||
void WebPage::finished() {
|
|
||||||
progress(100);
|
|
||||||
}
|
|
||||||
|
|
|
||||||
|
|
@ -19,7 +19,6 @@
|
||||||
#define WEBPAGE_H
|
#define WEBPAGE_H
|
||||||
|
|
||||||
#include <QWebEnginePage>
|
#include <QWebEnginePage>
|
||||||
#include <QNetworkAccessManager>
|
|
||||||
|
|
||||||
|
|
||||||
class WebPage : public QWebEnginePage {
|
class WebPage : public QWebEnginePage {
|
||||||
|
|
@ -29,17 +28,6 @@ class WebPage : public QWebEnginePage {
|
||||||
// Constructors and destructors.
|
// Constructors and destructors.
|
||||||
explicit WebPage(QObject *parent = 0);
|
explicit WebPage(QObject *parent = 0);
|
||||||
virtual ~WebPage();
|
virtual ~WebPage();
|
||||||
|
|
||||||
bool isLoading() const;
|
|
||||||
|
|
||||||
private slots:
|
|
||||||
void progress(int prog);
|
|
||||||
void finished();
|
|
||||||
|
|
||||||
private:
|
|
||||||
int m_loadProgress;
|
|
||||||
|
|
||||||
static QList<WebPage*> s_livingPages;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // WEBPAGE_H
|
#endif // WEBPAGE_H
|
||||||
|
|
|
||||||
|
|
@ -43,7 +43,6 @@
|
||||||
WebView::WebView(QWidget *parent)
|
WebView::WebView(QWidget *parent)
|
||||||
: QWebEngineView(parent), m_page(new WebPage(this)) {
|
: QWebEngineView(parent), m_page(new WebPage(this)) {
|
||||||
setPage(m_page);
|
setPage(m_page);
|
||||||
setContextMenuPolicy(Qt::CustomContextMenu);
|
|
||||||
initializeActions();
|
initializeActions();
|
||||||
createConnections();
|
createConnections();
|
||||||
}
|
}
|
||||||
|
|
@ -52,13 +51,6 @@ WebView::~WebView() {
|
||||||
qDebug("Destroying WebView.");
|
qDebug("Destroying WebView.");
|
||||||
}
|
}
|
||||||
|
|
||||||
void WebView::onLoadFinished(bool ok) {
|
|
||||||
// If page was not loaded, then display custom error page.
|
|
||||||
if (!ok) {
|
|
||||||
displayErrorPage();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void WebView::copySelectedText() {
|
void WebView::copySelectedText() {
|
||||||
Application::clipboard()->setText(selectedText());
|
Application::clipboard()->setText(selectedText());
|
||||||
}
|
}
|
||||||
|
|
@ -158,7 +150,6 @@ void WebView::createConnections() {
|
||||||
|
|
||||||
void WebView::setupIcons() {
|
void WebView::setupIcons() {
|
||||||
m_actionPrint->setIcon(qApp->icons()->fromTheme(QSL("print-web-page")));
|
m_actionPrint->setIcon(qApp->icons()->fromTheme(QSL("print-web-page")));
|
||||||
m_actionReload->setIcon(qApp->icons()->fromTheme(QSL("go-refresh")));
|
|
||||||
m_actionCopySelectedItem->setIcon(qApp->icons()->fromTheme(QSL("edit-copy")));
|
m_actionCopySelectedItem->setIcon(qApp->icons()->fromTheme(QSL("edit-copy")));
|
||||||
m_actionCopyLink->setIcon(qApp->icons()->fromTheme(QSL("edit-copy")));
|
m_actionCopyLink->setIcon(qApp->icons()->fromTheme(QSL("edit-copy")));
|
||||||
m_actionCopyImage->setIcon(qApp->icons()->fromTheme(QSL("edit-copy-image")));
|
m_actionCopyImage->setIcon(qApp->icons()->fromTheme(QSL("edit-copy-image")));
|
||||||
|
|
@ -173,11 +164,7 @@ void WebView::setupIcons() {
|
||||||
m_actionLookupText->setIcon(qApp->icons()->fromTheme(QSL("item-search-google")));
|
m_actionLookupText->setIcon(qApp->icons()->fromTheme(QSL("item-search-google")));
|
||||||
}
|
}
|
||||||
|
|
||||||
void WebView::initializeActions() {
|
void WebView::initializeActions() {
|
||||||
// Create needed actions.
|
|
||||||
m_actionReload = pageAction(QWebEnginePage::Reload);
|
|
||||||
m_actionReload->setParent(this);
|
|
||||||
|
|
||||||
m_actionPrint = new QAction(tr("Print"), this);
|
m_actionPrint = new QAction(tr("Print"), this);
|
||||||
m_actionPrint->setToolTip(tr("Print current web page."));
|
m_actionPrint->setToolTip(tr("Print current web page."));
|
||||||
|
|
||||||
|
|
@ -216,8 +203,6 @@ void WebView::initializeActions() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void WebView::setActionTexts() {
|
void WebView::setActionTexts() {
|
||||||
m_actionReload->setText(tr("Reload web page"));
|
|
||||||
m_actionReload->setToolTip(tr("Reload current web page."));
|
|
||||||
m_actionCopySelectedItem->setText(tr("Copy selection"));
|
m_actionCopySelectedItem->setText(tr("Copy selection"));
|
||||||
m_actionCopySelectedItem->setToolTip(tr("Copies current selection into the clipboard."));
|
m_actionCopySelectedItem->setToolTip(tr("Copies current selection into the clipboard."));
|
||||||
m_actionSaveHyperlinkAs->setText(tr("Save target as..."));
|
m_actionSaveHyperlinkAs->setText(tr("Save target as..."));
|
||||||
|
|
@ -241,28 +226,6 @@ void WebView::setActionTexts() {
|
||||||
m_actionOpenImageNewTab->setToolTip(tr("Open this image in this tab."));
|
m_actionOpenImageNewTab->setToolTip(tr("Open this image in this tab."));
|
||||||
}
|
}
|
||||||
|
|
||||||
void WebView::displayErrorPage() {
|
|
||||||
/*
|
|
||||||
setHtml(qApp->skins()->currentMarkupLayout().arg(
|
|
||||||
tr("Error page"),
|
|
||||||
qApp->skins()->currentMarkup().arg(tr("Page not found"),
|
|
||||||
tr("Check your internet connection or website address"),
|
|
||||||
QString(),
|
|
||||||
tr("This failure can be caused by:<br><ul>"
|
|
||||||
"<li>non-functional internet connection,</li>"
|
|
||||||
"<li>incorrect website address,</li>"
|
|
||||||
"<li>bad proxy server settings,</li>"
|
|
||||||
"<li>target destination outage,</li>"
|
|
||||||
"<li>many other things.</li>"
|
|
||||||
"</ul>"),
|
|
||||||
QDateTime::currentDateTime().toString(Qt::DefaultLocaleShortDate))));
|
|
||||||
*/
|
|
||||||
}
|
|
||||||
|
|
||||||
void WebView::popupContextMenu(const QPoint &pos) {
|
|
||||||
page()->createStandardContextMenu()->exec(mapToGlobal(pos));
|
|
||||||
}
|
|
||||||
|
|
||||||
void WebView::printCurrentPage() {
|
void WebView::printCurrentPage() {
|
||||||
QScopedPointer<QPrintPreviewDialog> print_preview(new QPrintPreviewDialog(this));
|
QScopedPointer<QPrintPreviewDialog> print_preview(new QPrintPreviewDialog(this));
|
||||||
connect(print_preview.data(), SIGNAL(paintRequested(QPrinter*)), this, SLOT(print(QPrinter*)));
|
connect(print_preview.data(), SIGNAL(paintRequested(QPrinter*)), this, SLOT(print(QPrinter*)));
|
||||||
|
|
@ -274,30 +237,12 @@ void WebView::downloadLink(const QNetworkRequest &request) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void WebView::mousePressEvent(QMouseEvent *event) {
|
void WebView::mousePressEvent(QMouseEvent *event) {
|
||||||
// TODO: TODO
|
if (event->button() & Qt::MiddleButton) {
|
||||||
/*if (event->button() & Qt::LeftButton && event->modifiers() & Qt::ControlModifier) {
|
|
||||||
QWebHitTestResult hit_result = page()->mainFrame()->hitTestContent(event->pos());
|
|
||||||
|
|
||||||
// Check if user clicked with middle mouse button on some
|
|
||||||
// hyperlink.
|
|
||||||
const QUrl link_url = hit_result.linkUrl();
|
|
||||||
const QUrl image_url = hit_result.imageUrl();
|
|
||||||
|
|
||||||
if (link_url.isValid()) {
|
|
||||||
emit linkMiddleClicked(link_url);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
else if (image_url.isValid()) {
|
|
||||||
emit linkMiddleClicked(image_url);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else */if (event->button() & Qt::MiddleButton) {
|
|
||||||
m_gestureOrigin = event->pos();
|
m_gestureOrigin = event->pos();
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
QWebEngineView::mousePressEvent(event);
|
QWebEngineView::mousePressEvent(event);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void WebView::mouseReleaseEvent(QMouseEvent *event) {
|
void WebView::mouseReleaseEvent(QMouseEvent *event) {
|
||||||
|
|
@ -330,6 +275,10 @@ void WebView::mouseReleaseEvent(QMouseEvent *event) {
|
||||||
QWebEngineView::mouseReleaseEvent(event);
|
QWebEngineView::mouseReleaseEvent(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void WebView::contextMenuEvent(QContextMenuEvent *event) {
|
||||||
|
QWebEngineView::contextMenuEvent(event);
|
||||||
|
}
|
||||||
|
|
||||||
void WebView::wheelEvent(QWheelEvent *event) {
|
void WebView::wheelEvent(QWheelEvent *event) {
|
||||||
if (event->modifiers() & Qt::ControlModifier) {
|
if (event->modifiers() & Qt::ControlModifier) {
|
||||||
if (event->delta() > 0) {
|
if (event->delta() > 0) {
|
||||||
|
|
|
||||||
|
|
@ -57,9 +57,6 @@ class WebView : public QWebEngineView {
|
||||||
bool decreaseWebPageZoom();
|
bool decreaseWebPageZoom();
|
||||||
bool resetWebPageZoom();
|
bool resetWebPageZoom();
|
||||||
|
|
||||||
// Executes if loading of any page is done.
|
|
||||||
void onLoadFinished(bool ok);
|
|
||||||
|
|
||||||
void copySelectedText();
|
void copySelectedText();
|
||||||
void openLinkInNewTab();
|
void openLinkInNewTab();
|
||||||
void openLinkExternally();
|
void openLinkExternally();
|
||||||
|
|
@ -68,9 +65,6 @@ class WebView : public QWebEngineView {
|
||||||
void saveCurrentPageToFile();
|
void saveCurrentPageToFile();
|
||||||
void printCurrentPage();
|
void printCurrentPage();
|
||||||
|
|
||||||
// Provides custom context menu.
|
|
||||||
void popupContextMenu(const QPoint &pos);
|
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void downloadLink(const QNetworkRequest &request);
|
void downloadLink(const QNetworkRequest &request);
|
||||||
|
|
||||||
|
|
@ -83,9 +77,6 @@ class WebView : public QWebEngineView {
|
||||||
// Creates necessary connections.
|
// Creates necessary connections.
|
||||||
void createConnections();
|
void createConnections();
|
||||||
|
|
||||||
// Displays custom error page.
|
|
||||||
void displayErrorPage();
|
|
||||||
|
|
||||||
// Customize mouse wheeling.
|
// Customize mouse wheeling.
|
||||||
void wheelEvent(QWheelEvent *event);
|
void wheelEvent(QWheelEvent *event);
|
||||||
|
|
||||||
|
|
@ -93,10 +84,11 @@ class WebView : public QWebEngineView {
|
||||||
void mousePressEvent(QMouseEvent *event);
|
void mousePressEvent(QMouseEvent *event);
|
||||||
void mouseReleaseEvent(QMouseEvent *event);
|
void mouseReleaseEvent(QMouseEvent *event);
|
||||||
|
|
||||||
|
void contextMenuEvent(QContextMenuEvent *event);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
WebPage *m_page;
|
WebPage *m_page;
|
||||||
|
|
||||||
QAction *m_actionReload;
|
|
||||||
QAction *m_actionPrint;
|
QAction *m_actionPrint;
|
||||||
QAction *m_actionCopySelectedItem;
|
QAction *m_actionCopySelectedItem;
|
||||||
QAction *m_actionCopyLink;
|
QAction *m_actionCopyLink;
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue