diff options
Diffstat (limited to 'examples/webenginewidgets')
-rw-r--r-- | examples/webenginewidgets/demobrowser/browsermainwindow.cpp | 21 | ||||
-rw-r--r-- | examples/webenginewidgets/demobrowser/browsermainwindow.h | 1 |
2 files changed, 21 insertions, 1 deletions
diff --git a/examples/webenginewidgets/demobrowser/browsermainwindow.cpp b/examples/webenginewidgets/demobrowser/browsermainwindow.cpp index 4b53124da..60b69ddd6 100644 --- a/examples/webenginewidgets/demobrowser/browsermainwindow.cpp +++ b/examples/webenginewidgets/demobrowser/browsermainwindow.cpp @@ -312,8 +312,12 @@ void BrowserMainWindow::setupMenu() #if defined(QWEBENGINEPAGE_PRINT) fileMenu->addAction(tr("P&rint Preview..."), this, SLOT(slotFilePrintPreview())); fileMenu->addAction(tr("&Print..."), this, SLOT(slotFilePrint()), QKeySequence::Print); - fileMenu->addSeparator(); #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())); action->setCheckable(true); action->setChecked(BrowserApplication::instance()->privateBrowsing()); @@ -697,6 +701,21 @@ void BrowserMainWindow::slotFilePrint() #endif } +void BrowserMainWindow::slotFilePrintToPDF() +{ +#ifndef QT_NO_PRINTER + if (!currentTab()) + return; + QPrinter printer; + QPrintDialog *dialog = new QPrintDialog(&printer, this); + dialog->setWindowTitle(tr("Print Document")); + if (dialog->exec() != QDialog::Accepted || printer.outputFileName().isEmpty()) + return; + + currentTab()->printToPDF(printer.outputFileName(), printer.pageLayout()); +#endif // QT_NO_PRINTER +} + #if defined(QWEBENGINEPAGE_PRINT) void BrowserMainWindow::printRequested(QWebEngineFrame *frame) { diff --git a/examples/webenginewidgets/demobrowser/browsermainwindow.h b/examples/webenginewidgets/demobrowser/browsermainwindow.h index 3f939b367..2e1d178d7 100644 --- a/examples/webenginewidgets/demobrowser/browsermainwindow.h +++ b/examples/webenginewidgets/demobrowser/browsermainwindow.h @@ -109,6 +109,7 @@ private slots: void slotFileOpen(); void slotFilePrintPreview(); void slotFilePrint(); + void slotFilePrintToPDF(); void slotPrivateBrowsing(); void slotFileSaveAs(); void slotEditFind(); |