Skip to content

Commit 57f0175

Browse files
committed
Print preview dialog in all cases
Add print preview dialogs to all the cases where we have printable objects. Remaining were table browsers and Scintilla editors.
1 parent 749e7ed commit 57f0175

File tree

2 files changed

+18
-11
lines changed

2 files changed

+18
-11
lines changed

src/ExtendedScintilla.cpp

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
#include <QAction>
1414
#include <QMenu>
1515
#include <QPalette>
16-
#include <QPrintDialog>
16+
#include <QPrintPreviewDialog>
1717
#include <cmath>
1818

1919

@@ -246,11 +246,15 @@ void ExtendedScintilla::showContextMenu(const QPoint &pos)
246246

247247
void ExtendedScintilla::openPrintDialog()
248248
{
249-
QsciPrinter* printer = new QsciPrinter;
249+
QsciPrinter printer;
250+
QPrintPreviewDialog *dialog = new QPrintPreviewDialog(&printer);
250251

251-
QPrintDialog printDialog(printer, this);
252-
if (printDialog.exec() == QDialog::Accepted)
253-
printer->printRange(this);
252+
connect(dialog, &QPrintPreviewDialog::paintRequested, [&](QPrinter *previewPrinter) {
253+
QsciPrinter* sciPrinter = static_cast<QsciPrinter*>(previewPrinter);
254+
sciPrinter->printRange(this);
255+
});
254256

255-
delete printer;
257+
dialog->exec();
258+
259+
delete dialog;
256260
}

src/ExtendedTableWidget.cpp

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
#include <QDateTime>
1818
#include <QLineEdit>
1919
#include <QPrinter>
20-
#include <QPrintDialog>
20+
#include <QPrintPreviewDialog>
2121
#include <QTextDocument>
2222
#include <QCompleter>
2323

@@ -874,12 +874,15 @@ void ExtendedTableWidget::openPrintDialog()
874874
document->setHtml(mimeData->html());
875875

876876
QPrinter printer;
877+
QPrintPreviewDialog *dialog = new QPrintPreviewDialog(&printer);
877878

878-
QPrintDialog *dialog = new QPrintDialog(&printer, nullptr);
879-
if (dialog->exec() == QDialog::Accepted) {
880-
document->print(&printer);
881-
}
879+
connect(dialog, &QPrintPreviewDialog::paintRequested, [&](QPrinter *previewPrinter) {
880+
document->print(previewPrinter);
881+
});
882+
883+
dialog->exec();
882884

885+
delete dialog;
883886
delete document;
884887
delete mimeData;
885888
}

0 commit comments

Comments
 (0)