diff options
author | Michael Bruning <michael.bruning@theqtcompany.com> | 2016-02-25 13:40:01 +0100 |
---|---|---|
committer | Michael BrĂ¼ning <michael.bruning@theqtcompany.com> | 2016-03-16 21:21:41 +0000 |
commit | df222f8ccb2151e519b92d3d2046ee74f221902e (patch) | |
tree | de0e9af4a11878399698e383f0162feee48d0aa6 /examples | |
parent | ec9a8753a7b17bbbf886c155ed884c581c547913 (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 'examples')
-rw-r--r-- | examples/webenginewidgets/demobrowser/browsermainwindow.cpp | 22 | ||||
-rw-r--r-- | examples/webenginewidgets/demobrowser/browsermainwindow.h | 2 |
2 files changed, 22 insertions, 2 deletions
diff --git a/examples/webenginewidgets/demobrowser/browsermainwindow.cpp b/examples/webenginewidgets/demobrowser/browsermainwindow.cpp index e3c7c466d..e72a2b5fe 100644 --- a/examples/webenginewidgets/demobrowser/browsermainwindow.cpp +++ b/examples/webenginewidgets/demobrowser/browsermainwindow.cpp @@ -701,6 +701,21 @@ void BrowserMainWindow::slotFilePrint() #endif } +void BrowserMainWindow::slotHandlePdfPrinted(const QByteArray& result) +{ + if (!result.size()) + return; + + QFile file(m_printerOutputFileName); + + m_printerOutputFileName.clear(); + if (!file.open(QFile::WriteOnly)) + return; + + file.write(result.data(), result.size()); + file.close(); +} + void BrowserMainWindow::slotFilePrintToPDF() { #ifndef QT_NO_PRINTER @@ -709,10 +724,13 @@ void BrowserMainWindow::slotFilePrintToPDF() QPrinter printer; QPrintDialog *dialog = new QPrintDialog(&printer, this); dialog->setWindowTitle(tr("Print Document")); - if (dialog->exec() != QDialog::Accepted || printer.outputFileName().isEmpty()) + if (dialog->exec() != QDialog::Accepted || printer.outputFileName().isEmpty() || !m_printerOutputFileName.isEmpty()) return; - currentTab()->page()->printToPDF(printer.outputFileName(), printer.pageLayout()); + m_printerOutputFileName = printer.outputFileName(); + + currentTab()->page()->printToPdf(printer.pageLayout(), invoke(this, &BrowserMainWindow::slotHandlePdfPrinted)); + #endif // QT_NO_PRINTER } diff --git a/examples/webenginewidgets/demobrowser/browsermainwindow.h b/examples/webenginewidgets/demobrowser/browsermainwindow.h index 2e1d178d7..9fb6b0851 100644 --- a/examples/webenginewidgets/demobrowser/browsermainwindow.h +++ b/examples/webenginewidgets/demobrowser/browsermainwindow.h @@ -138,6 +138,7 @@ private slots: void slotOpenActionUrl(QAction *action); void slotShowWindow(); void slotSwapFocus(); + void slotHandlePdfPrinted(const QByteArray&); #if defined(QWEBENGINEPAGE_PRINT) void printRequested(QWebEngineFrame *frame); @@ -180,6 +181,7 @@ private: QIcon m_stopIcon; QString m_lastSearch; + QString m_printerOutputFileName; friend class BrowserApplication; }; |