Skip to content

Commit

Permalink
Printing support #1525: add print preview dialog
Browse files Browse the repository at this point in the history
This adds a print preview step before printing in the Database Structure
tab.

This is nice to have, but it also aims to work around the problem found in
Windows, reported at issue #760.
  • Loading branch information
mgrojo committed Sep 27, 2018
1 parent ab991c5 commit 54cf4cf
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/MainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
#include <QUrlQuery>
#include <QDataStream> // This include seems to only be necessary for the Windows build
#include <QPrinter>
#include <QPrintDialog>
#include <QPrintPreviewDialog>

#ifdef Q_OS_MACX //Needed only on macOS
#include <QOpenGLWidget>
Expand Down Expand Up @@ -3484,10 +3484,14 @@ void MainWindow::printDbStructure ()
document->setHtml(strStream);

QPrinter printer;
printer.setDocName(treeView->windowTitle());

QPrintDialog *dialog = new QPrintDialog(&printer);
if (dialog->exec() == QDialog::Accepted)
document->print(&printer);
QPrintPreviewDialog *dialog = new QPrintPreviewDialog(&printer);
connect(dialog, &QPrintPreviewDialog::paintRequested, [&](QPrinter *previewPrinter) {
document->print(previewPrinter);
});

dialog->exec();

delete dialog;
delete document;
Expand Down

0 comments on commit 54cf4cf

Please sign in to comment.