summaryrefslogtreecommitdiffstats
path: root/src/webenginewidgets/api
diff options
context:
space:
mode:
authorMichael Bruning <michael.bruning@qt.io>2016-08-10 17:22:05 +0200
committerMichal Klocek <michal.klocek@qt.io>2016-08-24 16:19:28 +0000
commitaf2535018b1553e351198f3d9c21538de1c328a1 (patch)
treedc66a94a925477f60aa155b0ba979fadfc560a80 /src/webenginewidgets/api
parenteeac120ec135e2ab0bd02f399afb50b684d00298 (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')
-rw-r--r--src/webenginewidgets/api/qwebenginepage.cpp29
-rw-r--r--src/webenginewidgets/api/qwebenginepage.h11
-rw-r--r--src/webenginewidgets/api/qwebenginepage_p.h3
3 files changed, 43 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
diff --git a/src/webenginewidgets/api/qwebenginepage.h b/src/webenginewidgets/api/qwebenginepage.h
index bb46cd9fb..923c3bb70 100644
--- a/src/webenginewidgets/api/qwebenginepage.h
+++ b/src/webenginewidgets/api/qwebenginepage.h
@@ -54,6 +54,9 @@
QT_BEGIN_NAMESPACE
class QMenu;
+#ifndef QT_NO_PRINTER
+class QPrinter;
+#endif
class QWebChannel;
class QWebEngineContextMenuData;
class QWebEngineFullScreenRequest;
@@ -280,6 +283,14 @@ public:
void printToPdf(const QWebEngineCallback<const QByteArray&> &resultCallback, const QPageLayout &layout = QPageLayout(QPageSize(QPageSize::A4), QPageLayout::Portrait, QMarginsF()));
#endif
+#ifndef QT_NO_PRINTER
+#ifdef Q_QDOC
+ void print(QPrinter *printer, FunctorOrLambda resultCallback)
+#else
+ void print(QPrinter *printer, const QWebEngineCallback<bool> &resultCallback);
+#endif // QDOC
+#endif // QT_NO_PRINTER
+
const QWebEngineContextMenuData &contextMenuData() const;
void viewSource();
bool canViewSource() const;
diff --git a/src/webenginewidgets/api/qwebenginepage_p.h b/src/webenginewidgets/api/qwebenginepage_p.h
index 8d2a86350..93ebdf6e6 100644
--- a/src/webenginewidgets/api/qwebenginepage_p.h
+++ b/src/webenginewidgets/api/qwebenginepage_p.h
@@ -119,6 +119,9 @@ public:
virtual void didFetchDocumentInnerText(quint64 requestId, const QString& result) Q_DECL_OVERRIDE;
virtual void didFindText(quint64 requestId, int matchCount) Q_DECL_OVERRIDE;
virtual void didPrintPage(quint64 requestId, const QByteArray &result) Q_DECL_OVERRIDE;
+#ifndef QT_NO_PRINTER
+ virtual void didPrintPageOnPrinter(quint64 requestId, bool result) Q_DECL_OVERRIDE;
+#endif
virtual void passOnFocus(bool reverse) Q_DECL_OVERRIDE;
virtual void javaScriptConsoleMessage(JavaScriptConsoleMessageLevel level, const QString& message, int lineNumber, const QString& sourceID) Q_DECL_OVERRIDE;
virtual void authenticationRequired(QSharedPointer<QtWebEngineCore::AuthenticationDialogController>) Q_DECL_OVERRIDE;