From d90cca5c4ed8d98704aaf24e59ba00160cb7dc4e Mon Sep 17 00:00:00 2001 From: "Lubomir I. Ivanov" Date: Wed, 4 Dec 2013 13:51:34 +0200 Subject: PrintDialog: add separate Preview/Print buttons We rename our old 'Print' button to 'Preview' (as it did just that), and add a new one called 'Print' which does the direct printing, by creating a QPrintDialog instance. Both buttons are located on top of the dialog for now in a QHBoxLayout. Signed-off-by: Lubomir I. Ivanov --- qt-ui/printdialog.cpp | 23 +++++++++++++++++++---- qt-ui/printdialog.h | 1 + 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/qt-ui/printdialog.cpp b/qt-ui/printdialog.cpp index 7836cd0f0..ac2513917 100644 --- a/qt-ui/printdialog.cpp +++ b/qt-ui/printdialog.cpp @@ -7,6 +7,7 @@ #include #include #include +#include PrintDialog *PrintDialog::instance() { @@ -30,9 +31,16 @@ PrintDialog::PrintDialog(QWidget *parent, Qt::WindowFlags f) QVBoxLayout *layout = new QVBoxLayout(this); setLayout(layout); + QHBoxLayout *hLayout = new QHBoxLayout(); + layout->addLayout(hLayout); + + QPushButton *previewButton = new QPushButton(tr("&Preview")); + connect(previewButton, SIGNAL(clicked(bool)), this, SLOT(previewClicked())); + hLayout->addWidget(previewButton); + QPushButton *printButton = new QPushButton(tr("&Print")); connect(printButton, SIGNAL(clicked(bool)), this, SLOT(printClicked())); - layout->addWidget(printButton); + hLayout->addWidget(printButton); QProgressBar *progressBar = new QProgressBar(); connect(printLayout, SIGNAL(signalProgress(int)), progressBar, SLOT(setValue(int))); @@ -53,11 +61,18 @@ void PrintDialog::runDialog() exec(); } -void PrintDialog::printClicked(void) +void PrintDialog::previewClicked(void) { QPrintPreviewDialog previewDialog(&printer, this); - QObject::connect(&previewDialog, SIGNAL(paintRequested(QPrinter *)), this, SLOT(onPaintRequested(QPrinter *))); - previewDialog.exec(); + QObject::connect(&previewDialog, SIGNAL(paintRequested(QPrinter *)), this, SLOT(onPaintRequested(QPrinter *))); + previewDialog.exec(); +} + +void PrintDialog::printClicked(void) +{ + QPrintDialog printDialog(&printer, this); + if (printDialog.exec() == QDialog::Accepted) + printLayout->print(); } void PrintDialog::onPaintRequested(QPrinter *printerPtr) diff --git a/qt-ui/printdialog.h b/qt-ui/printdialog.h index 097de9531..5c5c1fbf6 100644 --- a/qt-ui/printdialog.h +++ b/qt-ui/printdialog.h @@ -23,6 +23,7 @@ private: QPrinter printer; private slots: + void previewClicked(); void printClicked(); void onPaintRequested(QPrinter *); }; -- cgit v1.2.3-70-g09d2