More work on context menus etc.

This commit is contained in:
Martin Rotter 2016-03-23 10:29:59 +01:00
parent 8120ff6467
commit 888b55b00d
5 changed files with 24 additions and 108 deletions

View File

@ -201,15 +201,14 @@ void WebBrowser::createConnections() {
// Forward title/icon changes.
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.
connect(m_webView, SIGNAL(zoomFactorChanged()), this, SLOT(updateZoomGui()));
}
void WebBrowser::onIconChanged() {
// TODO: todo
//emit iconChanged(m_index, m_webView->icon());
emit iconChanged(m_index, icon());
}
void WebBrowser::onTitleChanged(const QString &new_title) {
@ -321,9 +320,16 @@ void WebBrowser::setupIcons() {
}
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();
// TODO: TODO.
//return m_webView->iconUrl();
}

View File

@ -17,28 +17,9 @@
#include "network-web/webpage.h"
#include "network-web/webbrowser.h"
#include "miscellaneous/application.h"
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(QObject *parent) : QWebEnginePage(parent) {
}
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);
}

View File

@ -19,7 +19,6 @@
#define WEBPAGE_H
#include <QWebEnginePage>
#include <QNetworkAccessManager>
class WebPage : public QWebEnginePage {
@ -29,17 +28,6 @@ class WebPage : public QWebEnginePage {
// Constructors and destructors.
explicit WebPage(QObject *parent = 0);
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

View File

@ -43,7 +43,6 @@
WebView::WebView(QWidget *parent)
: QWebEngineView(parent), m_page(new WebPage(this)) {
setPage(m_page);
setContextMenuPolicy(Qt::CustomContextMenu);
initializeActions();
createConnections();
}
@ -52,13 +51,6 @@ WebView::~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() {
Application::clipboard()->setText(selectedText());
}
@ -158,7 +150,6 @@ void WebView::createConnections() {
void WebView::setupIcons() {
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_actionCopyLink->setIcon(qApp->icons()->fromTheme(QSL("edit-copy")));
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")));
}
void WebView::initializeActions() {
// Create needed actions.
m_actionReload = pageAction(QWebEnginePage::Reload);
m_actionReload->setParent(this);
void WebView::initializeActions() {
m_actionPrint = new QAction(tr("Print"), this);
m_actionPrint->setToolTip(tr("Print current web page."));
@ -216,8 +203,6 @@ void WebView::initializeActions() {
}
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->setToolTip(tr("Copies current selection into the clipboard."));
m_actionSaveHyperlinkAs->setText(tr("Save target as..."));
@ -241,28 +226,6 @@ void WebView::setActionTexts() {
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() {
QScopedPointer<QPrintPreviewDialog> print_preview(new QPrintPreviewDialog(this));
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) {
// TODO: TODO
/*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) {
if (event->button() & Qt::MiddleButton) {
m_gestureOrigin = event->pos();
return;
}
QWebEngineView::mousePressEvent(event);
else {
QWebEngineView::mousePressEvent(event);
}
}
void WebView::mouseReleaseEvent(QMouseEvent *event) {
@ -330,6 +275,10 @@ void WebView::mouseReleaseEvent(QMouseEvent *event) {
QWebEngineView::mouseReleaseEvent(event);
}
void WebView::contextMenuEvent(QContextMenuEvent *event) {
QWebEngineView::contextMenuEvent(event);
}
void WebView::wheelEvent(QWheelEvent *event) {
if (event->modifiers() & Qt::ControlModifier) {
if (event->delta() > 0) {

View File

@ -57,9 +57,6 @@ class WebView : public QWebEngineView {
bool decreaseWebPageZoom();
bool resetWebPageZoom();
// Executes if loading of any page is done.
void onLoadFinished(bool ok);
void copySelectedText();
void openLinkInNewTab();
void openLinkExternally();
@ -68,9 +65,6 @@ class WebView : public QWebEngineView {
void saveCurrentPageToFile();
void printCurrentPage();
// Provides custom context menu.
void popupContextMenu(const QPoint &pos);
private slots:
void downloadLink(const QNetworkRequest &request);
@ -83,9 +77,6 @@ class WebView : public QWebEngineView {
// Creates necessary connections.
void createConnections();
// Displays custom error page.
void displayErrorPage();
// Customize mouse wheeling.
void wheelEvent(QWheelEvent *event);
@ -93,10 +84,11 @@ class WebView : public QWebEngineView {
void mousePressEvent(QMouseEvent *event);
void mouseReleaseEvent(QMouseEvent *event);
void contextMenuEvent(QContextMenuEvent *event);
private:
WebPage *m_page;
QAction *m_actionReload;
QAction *m_actionPrint;
QAction *m_actionCopySelectedItem;
QAction *m_actionCopyLink;