diff options
author | Michael Bruning <michael.bruning@qt.io> | 2016-08-10 17:22:05 +0200 |
---|---|---|
committer | Michal Klocek <michal.klocek@qt.io> | 2016-08-24 16:19:28 +0000 |
commit | af2535018b1553e351198f3d9c21538de1c328a1 (patch) | |
tree | dc66a94a925477f60aa155b0ba979fadfc560a80 /src/webenginewidgets/api/qwebenginepage.cpp | |
parent | eeac120ec135e2ab0bd02f399afb50b684d00298 (diff) |
Add widgets API for printing on a QPrinter
Renders the content to a PDF document and then renders this on a
QPrinter-backed QPainter using the PDFium library.
PDFium bitmap to QImage conversion based on work by Paulo Pinheiro
<paulvap.os@gmail.com>.
[ChangeLog][QtWebEngineWidgets][Printing] Enables printing QWebPage
content on a QPrinter. Currently does not support previewing the
document. Widgets only for the moment.
Change-Id: I9a5264433093379aee90f5e4f69bf2aee8814f2b
Reviewed-by: Allan Sandfeld Jensen <allan.jensen@qt.io>
Diffstat (limited to 'src/webenginewidgets/api/qwebenginepage.cpp')
-rw-r--r-- | src/webenginewidgets/api/qwebenginepage.cpp | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/src/webenginewidgets/api/qwebenginepage.cpp b/src/webenginewidgets/api/qwebenginepage.cpp index c180699f3..428cccd9a 100644 --- a/src/webenginewidgets/api/qwebenginepage.cpp +++ b/src/webenginewidgets/api/qwebenginepage.cpp @@ -373,6 +373,13 @@ void QWebEnginePagePrivate::didPrintPage(quint64 requestId, const QByteArray &re m_callbacks.invoke(requestId, result); } +#ifndef QT_NO_PRINTER +void QWebEnginePagePrivate::didPrintPageOnPrinter(quint64 requestId, bool result) +{ + m_callbacks.invoke(requestId, result); +} +#endif + void QWebEnginePagePrivate::passOnFocus(bool reverse) { if (view) @@ -1841,6 +1848,28 @@ void QWebEnginePage::printToPdf(const QWebEngineCallback<const QByteArray&> &res d->m_callbacks.registerCallback(requestId, resultCallback); } +#ifndef QT_NO_PRINTER +/*! + \fn void QWebEnginePage::print(const QPrinter &printer, FunctorOrLambda resultCallback) + Renders the current content of the page into a temporary PDF document, then prints it using \a printer. + + The settings for creating and printing the PDF document will be retrieved from the \a printer + object. + It is the users responsibility to ensure the \a printer remains valid until \a resultCallback + has been called. + + The \a resultCallback must take a boolean as parameter. If printing was successful, this + boolean will have the value \c true, otherwise, its value will be \c false. + \since 5.8 +*/ +void QWebEnginePage::print(QPrinter *printer, const QWebEngineCallback<bool> &resultCallback) +{ + Q_D(QWebEnginePage); + quint64 requestId = d->adapter->printOnPrinterCallbackResult(printer); + d->m_callbacks.registerCallback(requestId, resultCallback); +} +#endif // QT_NO_PRINTER + /*! \since 5.7 |