diff --git a/src/network-web/webbrowser.cpp b/src/network-web/webbrowser.cpp index 3eab9fc4e..cff01a927 100755 --- a/src/network-web/webbrowser.cpp +++ b/src/network-web/webbrowser.cpp @@ -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(); } diff --git a/src/network-web/webpage.cpp b/src/network-web/webpage.cpp index c462543ec..fc792a383 100755 --- a/src/network-web/webpage.cpp +++ b/src/network-web/webpage.cpp @@ -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); -} diff --git a/src/network-web/webpage.h b/src/network-web/webpage.h index 2e76039d4..231c8b3df 100755 --- a/src/network-web/webpage.h +++ b/src/network-web/webpage.h @@ -19,7 +19,6 @@ #define WEBPAGE_H #include -#include 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 s_livingPages; }; #endif // WEBPAGE_H diff --git a/src/network-web/webview.cpp b/src/network-web/webview.cpp index baacca247..4da6d6412 100755 --- a/src/network-web/webview.cpp +++ b/src/network-web/webview.cpp @@ -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:
    " - "
  • non-functional internet connection,
  • " - "
  • incorrect website address,
  • " - "
  • bad proxy server settings,
  • " - "
  • target destination outage,
  • " - "
  • many other things.
  • " - "
"), - QDateTime::currentDateTime().toString(Qt::DefaultLocaleShortDate)))); - */ -} - -void WebView::popupContextMenu(const QPoint &pos) { - page()->createStandardContextMenu()->exec(mapToGlobal(pos)); -} - void WebView::printCurrentPage() { QScopedPointer 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) { diff --git a/src/network-web/webview.h b/src/network-web/webview.h index 1630f179b..394528bec 100755 --- a/src/network-web/webview.h +++ b/src/network-web/webview.h @@ -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;