summaryrefslogtreecommitdiffstats
path: root/src/webenginewidgets
diff options
context:
space:
mode:
authorMichael Bruning <michael.bruning@theqtcompany.com>2016-02-25 13:40:01 +0100
committerMichael BrĂ¼ning <michael.bruning@theqtcompany.com>2016-03-16 21:21:41 +0000
commitdf222f8ccb2151e519b92d3d2046ee74f221902e (patch)
treede0e9af4a11878399698e383f0162feee48d0aa6 /src/webenginewidgets
parentec9a8753a7b17bbbf886c155ed884c581c547913 (diff)
Add callback to printing API
Also corrects and updates the printToPDF docs to reflect recent changes. Change-Id: Iffe276a1046d6d55923939f9d72b97cd533017ff Reviewed-by: Joerg Bornemann <joerg.bornemann@theqtcompany.com>
Diffstat (limited to 'src/webenginewidgets')
-rw-r--r--src/webenginewidgets/api/qwebenginepage.cpp33
-rw-r--r--src/webenginewidgets/api/qwebenginepage.h8
-rw-r--r--src/webenginewidgets/api/qwebenginepage_p.h1
-rw-r--r--src/webenginewidgets/doc/src/qwebengineview_lgpl.qdoc9
4 files changed, 39 insertions, 12 deletions
diff --git a/src/webenginewidgets/api/qwebenginepage.cpp b/src/webenginewidgets/api/qwebenginepage.cpp
index 3115340ef..27ed7fca6 100644
--- a/src/webenginewidgets/api/qwebenginepage.cpp
+++ b/src/webenginewidgets/api/qwebenginepage.cpp
@@ -314,6 +314,11 @@ void QWebEnginePagePrivate::didFindText(quint64 requestId, int matchCount)
m_callbacks.invoke(requestId, matchCount > 0);
}
+void QWebEnginePagePrivate::didPrintPage(quint64 requestId, const QByteArray &result)
+{
+ m_callbacks.invoke(requestId, result);
+}
+
void QWebEnginePagePrivate::passOnFocus(bool reverse)
{
if (view)
@@ -1633,12 +1638,38 @@ QSizeF QWebEnginePage::contentsSize() const
return d->adapter->lastContentsSize();
}
-void QWebEnginePage::printToPDF(const QString &filePath, const QPageLayout &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.
+
+ If a file already exists at the provided file path, it will be overwritten.
+ \since 5.7
+*/
+void QWebEnginePage::printToPdf(const QString &filePath, const QPageLayout &pageLayout)
{
Q_D(const QWebEnginePage);
d->adapter->printToPDF(pageLayout, filePath);
}
+
+/*!
+ \fn void QWebEnginePage::printToPdf(const QPageLayout &pageLayout, FunctorOrLambda resultCallback)
+ Renders the current content of the page into a PDF document and returns a byte array containing the PDF data
+ as parameter to \a resultCallback.
+ The page size and orientation of the produced PDF document are taken from the values specified in \a pageLayout.
+
+ The \a resultCallback must take a const reference to a QByteArray as parameter. If printing was successful, this byte array
+ will contain the PDF data, otherwise, the byte array will be empty.
+
+ \since 5.7
+*/
+void QWebEnginePage::printToPdf(const QPageLayout &pageLayout, const QWebEngineCallback<const QByteArray&> &resultCallback)
+{
+ Q_D(QWebEnginePage);
+ quint64 requestId = d->adapter->printToPDFCallbackResult(pageLayout);
+ d->m_callbacks.registerCallback(requestId, resultCallback);
+}
+
QT_END_NAMESPACE
#include "moc_qwebenginepage.cpp"
diff --git a/src/webenginewidgets/api/qwebenginepage.h b/src/webenginewidgets/api/qwebenginepage.h
index 20fff3ab4..ad399a7a5 100644
--- a/src/webenginewidgets/api/qwebenginepage.h
+++ b/src/webenginewidgets/api/qwebenginepage.h
@@ -268,8 +268,12 @@ public:
void setAudioMuted(bool muted);
bool wasRecentlyAudible();
- void printToPDF(const QString &filePath, const QPageLayout &layout = QPageLayout());
-
+ void printToPdf(const QString &filePath, const QPageLayout &layout);
+#ifdef Q_QDOC
+ void printToPdf(const QPageLayout &layout, FunctorOrLambda resultCallback);
+#else
+ void printToPdf(const QPageLayout &layout, const QWebEngineCallback<const QByteArray&> &resultCallback);
+#endif
Q_SIGNALS:
void loadStarted();
void loadProgress(int progress);
diff --git a/src/webenginewidgets/api/qwebenginepage_p.h b/src/webenginewidgets/api/qwebenginepage_p.h
index 6d4b857eb..b08c19821 100644
--- a/src/webenginewidgets/api/qwebenginepage_p.h
+++ b/src/webenginewidgets/api/qwebenginepage_p.h
@@ -112,6 +112,7 @@ public:
virtual void didFetchDocumentMarkup(quint64 requestId, const QString& result) Q_DECL_OVERRIDE;
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;
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;
diff --git a/src/webenginewidgets/doc/src/qwebengineview_lgpl.qdoc b/src/webenginewidgets/doc/src/qwebengineview_lgpl.qdoc
index 624381a42..07fb5f1cd 100644
--- a/src/webenginewidgets/doc/src/qwebengineview_lgpl.qdoc
+++ b/src/webenginewidgets/doc/src/qwebengineview_lgpl.qdoc
@@ -255,15 +255,6 @@
*/
/*!
- \fn void QWebEngineView::printToPDF(const QString &filePath, const QPageLayout &layout)
- \since 5.7
- Renders the current contents of the view 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 layout.
-
- If a file already exists at the provided file path, it will be overwritten.
-*/
-
-/*!
\fn void QWebEngineView::stop()
Convenience slot that stops loading the document.