summaryrefslogtreecommitdiffstats
path: root/src/webenginewidgets/api/qwebenginepage.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/webenginewidgets/api/qwebenginepage.cpp')
-rw-r--r--src/webenginewidgets/api/qwebenginepage.cpp73
1 files changed, 58 insertions, 15 deletions
diff --git a/src/webenginewidgets/api/qwebenginepage.cpp b/src/webenginewidgets/api/qwebenginepage.cpp
index eeb5524a0..8908af3c4 100644
--- a/src/webenginewidgets/api/qwebenginepage.cpp
+++ b/src/webenginewidgets/api/qwebenginepage.cpp
@@ -80,9 +80,11 @@
#include <QMenu>
#include <QMessageBox>
#include <QMimeData>
+#if defined(QT_PRINTSUPPORT_LIB)
#ifndef QT_NO_PRINTER
#include <QPrinter>
-#endif
+#endif //QT_NO_PRINTER
+#endif //QT_PRINTSUPPORT_LIB
#include <QStandardPaths>
#include <QStyle>
#include <QTimer>
@@ -96,8 +98,7 @@ using namespace QtWebEngineCore;
static const int MaxTooltipLength = 1024;
-#ifndef QT_NO_PRINTER
-#if defined(ENABLE_PDF)
+#if defined(ENABLE_PRINTING) && defined(ENABLE_PDF)
static bool printPdfDataOnPrinter(const QByteArray& data, QPrinter& printer)
{
QRect printerPageRect = printer.pageRect();
@@ -174,8 +175,7 @@ static bool printPdfDataOnPrinter(const QByteArray& data, QPrinter& printer)
return true;
}
-#endif // defined(ENABLE_PDF)
-#endif // QT_NO_PRINTER
+#endif // defined(ENABLE_PRINTING) && defined(ENABLE_PDF)
static QWebEnginePage::WebWindowType toWindowType(WebContentsAdapterClient::WindowOpenDisposition disposition)
{
@@ -227,7 +227,7 @@ QWebEnginePagePrivate::QWebEnginePagePrivate(QWebEngineProfile *_profile)
, fullscreenMode(false)
, webChannel(nullptr)
, webChannelWorldId(QWebEngineScript::MainWorld)
-#ifndef QT_NO_PRINTER
+#if defined(ENABLE_PRINTING)
, currentPrinter(nullptr)
#endif
{
@@ -359,6 +359,12 @@ void QWebEnginePagePrivate::loadFinished(bool success, const QUrl &url, bool isE
updateNavigationActions();
}
+void QWebEnginePagePrivate::didPrintPageToPdf(const QString &filePath, bool success)
+{
+ Q_Q(QWebEnginePage);
+ Q_EMIT q->pdfPrintingFinished(filePath, success);
+}
+
void QWebEnginePagePrivate::focusContainer()
{
if (view)
@@ -478,7 +484,7 @@ void QWebEnginePagePrivate::didFindText(quint64 requestId, int matchCount)
void QWebEnginePagePrivate::didPrintPage(quint64 requestId, const QByteArray &result)
{
#if defined(ENABLE_PDF)
-#ifndef QT_NO_PRINTER
+#if defined(ENABLE_PRINTING)
// If no currentPrinter is set that means that were printing to PDF only.
if (!currentPrinter) {
m_callbacks.invoke(requestId, result);
@@ -491,7 +497,7 @@ void QWebEnginePagePrivate::didPrintPage(quint64 requestId, const QByteArray &re
currentPrinter = nullptr;
#else // If print support is disabled, only PDF printing is available.
m_callbacks.invoke(requestId, result);
-#endif // ifndef QT_NO_PRINTER
+#endif // defined(ENABLE_PRINTING)
#else // defined(ENABLE_PDF)
// we should never enter this branch, but just for safe-keeping...
Q_UNUSED(result);
@@ -729,6 +735,19 @@ QWebEnginePage::QWebEnginePage(QObject* parent)
*/
/*!
+ \fn void QWebEnginePage::pdfPrintingFinished(const QString &filePath, bool success)
+ \since 5.9
+
+ This signal is emitted when printing the web page into a PDF file has
+ finished.
+ \a filePath will contain the path the file was requested to be created
+ at, and \a success will be \c true if the file was successfully created and
+ \c false otherwise.
+
+ \sa printToPdf()
+*/
+
+/*!
\property QWebEnginePage::scrollPosition
\since 5.7
@@ -1688,6 +1707,18 @@ void QWebEnginePage::load(const QUrl& url)
d->adapter->load(url);
}
+/*!
+ \since 5.9
+ Issues the specified \a request and loads the response.
+
+ \sa load(), setUrl(), url(), urlChanged(), QUrl::fromUserInput()
+*/
+void QWebEnginePage::load(const QWebEngineHttpRequest& request)
+{
+ Q_D(QWebEnginePage);
+ d->adapter->load(request);
+}
+
void QWebEnginePage::toHtml(const QWebEngineCallback<const QString &> &resultCallback) const
{
Q_D(const QWebEnginePage);
@@ -1940,17 +1971,25 @@ QSizeF QWebEnginePage::contentsSize() const
}
/*!
- Renders the current content of the page into a PDF document and saves it in the location specified in \a filePath.
- The page size and orientation of the produced PDF document are taken from the values specified in \a pageLayout.
+ Renders the current content of the page into a PDF document and saves it
+ in the location specified in \a filePath.
+ The page size and orientation of the produced PDF document are taken from
+ the values specified in \a pageLayout.
+
+ This method issues an asynchronous request for printing the web page into
+ a PDF and returns immediately.
+ To be informed about the result of the request, connect to the signal
+ pdfPrintingFinished().
If a file already exists at the provided file path, it will be overwritten.
\since 5.7
+ \sa pdfPrintingFinished()
*/
void QWebEnginePage::printToPdf(const QString &filePath, const QPageLayout &pageLayout)
{
#if defined(ENABLE_PDF)
Q_D(const QWebEnginePage);
-#ifndef QT_NO_PRINTER
+#if defined(ENABLE_PRINTING)
if (d->currentPrinter) {
#if QT_VERSION >= QT_VERSION_CHECK(5, 7, 0)
qWarning("Cannot print to PDF while at the same time printing on printer %ls", qUtf16Printable(d->currentPrinter->printerName()));
@@ -1959,7 +1998,7 @@ void QWebEnginePage::printToPdf(const QString &filePath, const QPageLayout &page
#endif
return;
}
-#endif
+#endif // ENABLE_PRINTING
d->adapter->printToPDF(pageLayout, filePath);
#else
Q_UNUSED(filePath);
@@ -1983,7 +2022,7 @@ void QWebEnginePage::printToPdf(const QWebEngineCallback<const QByteArray&> &res
{
Q_D(QWebEnginePage);
#if defined(ENABLE_PDF)
-#ifndef QT_NO_PRINTER
+#if defined(ENABLE_PRINTING)
if (d->currentPrinter) {
#if QT_VERSION >= QT_VERSION_CHECK(5, 7, 0)
qWarning("Cannot print to PDF while at the same time printing on printer %ls", qUtf16Printable(d->currentPrinter->printerName()));
@@ -1993,7 +2032,7 @@ void QWebEnginePage::printToPdf(const QWebEngineCallback<const QByteArray&> &res
d->m_callbacks.invokeEmpty(resultCallback);
return;
}
-#endif // ifndef QT_NO_PRINTER
+#endif // ENABLE_PRINTING
quint64 requestId = d->adapter->printToPDFCallbackResult(pageLayout);
d->m_callbacks.registerCallback(requestId, resultCallback);
#else // if defined(ENABLE_PDF)
@@ -2002,6 +2041,7 @@ void QWebEnginePage::printToPdf(const QWebEngineCallback<const QByteArray&> &res
#endif // if defined(ENABLE_PDF)
}
+#if defined(QT_PRINTSUPPORT_LIB)
#ifndef QT_NO_PRINTER
/*!
\fn void QWebEnginePage::print(QPrinter *printer, FunctorOrLambda resultCallback)
@@ -2020,6 +2060,7 @@ void QWebEnginePage::print(QPrinter *printer, const QWebEngineCallback<bool> &re
{
Q_D(QWebEnginePage);
#if defined(ENABLE_PDF)
+#if defined(ENABLE_PRINTING)
if (d->currentPrinter) {
#if QT_VERSION >= QT_VERSION_CHECK(5, 7, 0)
qWarning("Cannot print page on printer %ls: Already printing on %ls.", qUtf16Printable(printer->printerName()), qUtf16Printable(d->currentPrinter->printerName()));
@@ -2030,6 +2071,7 @@ void QWebEnginePage::print(QPrinter *printer, const QWebEngineCallback<bool> &re
return;
}
d->currentPrinter = printer;
+#endif // ENABLE_PRINTING
quint64 requestId = d->adapter->printToPDFCallbackResult(printer->pageLayout(), printer->colorMode() == QPrinter::Color);
d->m_callbacks.registerCallback(requestId, resultCallback);
#else // if defined(ENABLE_PDF)
@@ -2037,7 +2079,8 @@ void QWebEnginePage::print(QPrinter *printer, const QWebEngineCallback<bool> &re
d->m_callbacks.invokeDirectly(resultCallback, false);
#endif // if defined(ENABLE_PDF)
}
-#endif // QT_NO_PRINTER
+#endif // if defined(QT_NO_PRINTER)
+#endif // if defined(QT_PRINTSUPPORT_LIB)
/*!
\since 5.7