Messagelib
7 #include "webenginepage.h"
8 #include "webhittest.h"
9 #include "webhittestresult.h"
11 #include <KLocalizedString>
14 #include <QFileDialog>
18 #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
19 #include <QWebEngineDownloadItem>
21 #include <QWebEngineDownloadRequest>
23 #include <QWebEngineProfile>
25 using namespace WebEngineViewer;
28 : QWebEnginePage(new QWebEngineProfile, parent)
44 profile()->setParent(
this);
50 : QWebEnginePage(profile, parent)
55 void WebEnginePage::init()
57 connect(profile(), &QWebEngineProfile::downloadRequested,
this, &WebEnginePage::saveHtml);
62 return new WebHitTest(
this, mapToViewport(pos), pos);
65 QPoint WebEnginePage::mapToViewport(
const QPoint &pos)
const
67 return QPoint(pos.
x() / zoomFactor(), pos.
y() / zoomFactor());
70 #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
71 void WebEnginePage::saveHtml(QWebEngineDownloadItem *download)
73 void WebEnginePage::saveHtml(QWebEngineDownloadRequest *download)
78 #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
79 download->setSavePageFormat(QWebEngineDownloadItem::SingleHtmlSaveFormat);
81 download->setSavePageFormat(QWebEngineDownloadRequest::SingleHtmlSaveFormat);
83 download->setDownloadDirectory(
QFileInfo(fileName).path());
84 download->setDownloadFileName(
QFileInfo(fileName).fileName());
89 bool WebEnginePage::acceptNavigationRequest(
const QUrl &url, NavigationType type,
bool isMainFrame)
91 if (isMainFrame && type == NavigationTypeLinkClicked) {
92 Q_EMIT urlClicked(url);
98 void WebEnginePage::javaScriptConsoleMessage(QWebEnginePage::JavaScriptConsoleMessageLevel level,
106 qDebug() <<
"WebEnginePage::javaScriptConsoleMessage lineNumber: " << lineNumber <<
" message: " <<
message;
107 Q_EMIT showConsoleMessage(
message);
110 bool WebEnginePage::execPrintPreviewPage(
QPrinter *printer,
int timeout)
116 print(printer, [loop, &result](
bool res) {
117 if (loop && loop->isRunning()) {
QAction * print(const QObject *recvr, const char *slot, QObject *parent)
WebEnginePage(QObject *parent=nullptr)
Constructor.
QString i18n(const char *text, const TYPE &arg...)
bool isEmpty() const const
QString getSaveFileName(QWidget *parent, const QString &caption, const QString &dir, const QString &filter, QString *selectedFilter, QFileDialog::Options options)
This file is part of the KDE documentation.
Documentation copyright © 1996-2022 The KDE developers.
Generated on Thu May 19 2022 03:53:26 by
doxygen 1.8.17 written
by
Dimitri van Heesch, © 1997-2006
KDE's Doxygen guidelines are available online.