summaryrefslogtreecommitdiffstats
path: root/examples/webenginewidgets/demobrowser/browsermainwindow.cpp
diff options
context:
space:
mode:
authorMichael Bruning <michael.bruning@theqtcompany.com>2016-04-28 19:26:17 +0200
committerMichael BrĂ¼ning <michael.bruning@theqtcompany.com>2016-05-02 08:34:16 +0000
commitc59e577a18ea20283a3267b9400de5f812056f93 (patch)
treea14b125e21bb6ffc1ff88af84d0009f14edeed79 /examples/webenginewidgets/demobrowser/browsermainwindow.cpp
parenta0017319c730127cd3a726392fbbb6360c1ad418 (diff)
Replace print dialog with a custom one for printing to pdf.
The standard pdf print dialog does not work on OS X and Windows. Task-number: QTBUG-53016 Change-Id: Ic9dd1a1603e1cdbd82fef095cc660814bcd8c98e Reviewed-by: Kai Koehne <kai.koehne@qt.io>
Diffstat (limited to 'examples/webenginewidgets/demobrowser/browsermainwindow.cpp')
-rw-r--r--examples/webenginewidgets/demobrowser/browsermainwindow.cpp22
1 files changed, 9 insertions, 13 deletions
diff --git a/examples/webenginewidgets/demobrowser/browsermainwindow.cpp b/examples/webenginewidgets/demobrowser/browsermainwindow.cpp
index 0f24de707..fbee934db 100644
--- a/examples/webenginewidgets/demobrowser/browsermainwindow.cpp
+++ b/examples/webenginewidgets/demobrowser/browsermainwindow.cpp
@@ -56,6 +56,7 @@
#include "chasewidget.h"
#include "downloadmanager.h"
#include "history.h"
+#include "printtopdfdialog.h"
#include "settings.h"
#include "tabwidget.h"
#include "toolbarsearch.h"
@@ -313,9 +314,7 @@ void BrowserMainWindow::setupMenu()
fileMenu->addAction(tr("P&rint Preview..."), this, SLOT(slotFilePrintPreview()));
fileMenu->addAction(tr("&Print..."), this, SLOT(slotFilePrint()), QKeySequence::Print);
#endif
-#ifndef QT_NO_PRINTER
fileMenu->addAction(tr("&Print to PDF..."), this, SLOT(slotFilePrintToPDF()));
-#endif // ifndef QT_NO_PRINTER
fileMenu->addSeparator();
QAction *action = fileMenu->addAction(tr("Private &Browsing..."), this, SLOT(slotPrivateBrowsing()));
@@ -718,20 +717,17 @@ void BrowserMainWindow::slotHandlePdfPrinted(const QByteArray& result)
void BrowserMainWindow::slotFilePrintToPDF()
{
-#ifndef QT_NO_PRINTER
- if (!currentTab())
+ if (!currentTab() || !m_printerOutputFileName.isEmpty())
return;
- QPrinter printer;
- QPrintDialog *dialog = new QPrintDialog(&printer, this);
- dialog->setWindowTitle(tr("Print Document"));
- if (dialog->exec() != QDialog::Accepted || printer.outputFileName().isEmpty() || !m_printerOutputFileName.isEmpty())
- return;
-
- m_printerOutputFileName = printer.outputFileName();
- currentTab()->page()->printToPdf(invoke(this, &BrowserMainWindow::slotHandlePdfPrinted), printer.pageLayout());
+ QFileInfo info(QStringLiteral("printout.pdf"));
+ PrintToPdfDialog *dialog = new PrintToPdfDialog(info.absoluteFilePath(), this);
+ dialog->setWindowTitle(tr("Print to PDF"));
+ if (dialog->exec() != QDialog::Accepted || dialog->filePath().isEmpty())
+ return;
-#endif // QT_NO_PRINTER
+ m_printerOutputFileName = dialog->filePath();
+ currentTab()->page()->printToPdf(invoke(this, &BrowserMainWindow::slotHandlePdfPrinted), dialog->pageLayout());
}
#if defined(QWEBENGINEPAGE_PRINT)