Printing: Remove the obsolete code from PrintDialog

We don't need any further calls to printLayout as it will be replaced by
Printer class that handles the new custom printing capability.
Also fix one coding style issue.

Signed-off-by: Gehad elrobey <gehadelrobey@gmail.com>
Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
Gehad elrobey 2015-05-30 10:53:34 +02:00 committed by Dirk Hohndel
parent 0307ae98c2
commit 912606e1c7
2 changed files with 1 additions and 60 deletions

View file

@ -1,6 +1,5 @@
#include "printdialog.h" #include "printdialog.h"
#include "printoptions.h" #include "printoptions.h"
#include "printlayout.h"
#include "mainwindow.h" #include "mainwindow.h"
#include <QProgressBar> #include <QProgressBar>
@ -9,10 +8,6 @@
#include <QShortcut> #include <QShortcut>
#include <QSettings> #include <QSettings>
#if QT_VERSION >= 0x050300
#include <QMarginsF>
#endif
#define SETTINGS_GROUP "PrintDialog" #define SETTINGS_GROUP "PrintDialog"
PrintDialog::PrintDialog(QWidget *parent, Qt::WindowFlags f) : QDialog(parent, f) PrintDialog::PrintDialog(QWidget *parent, Qt::WindowFlags f) : QDialog(parent, f)
@ -21,45 +16,18 @@ PrintDialog::PrintDialog(QWidget *parent, Qt::WindowFlags f) : QDialog(parent, f
QSettings s; QSettings s;
bool stored = s.childGroups().contains(SETTINGS_GROUP); bool stored = s.childGroups().contains(SETTINGS_GROUP);
if (!stored) { if (!stored) {
printOptions.type = print_options::PRETTY;
printOptions.print_selected = true; printOptions.print_selected = true;
printOptions.color_selected = true; printOptions.color_selected = true;
printOptions.notes_up = false;
printOptions.landscape = false; printOptions.landscape = false;
memset(printOptions.margins, 0, sizeof(printOptions.margins));
} else { } else {
s.beginGroup(SETTINGS_GROUP); s.beginGroup(SETTINGS_GROUP);
printOptions.type = (print_options::print_type)s.value("type").toInt(); printOptions.type = (print_options::print_type)s.value("type").toInt();
printOptions.print_selected = s.value("print_selected").toBool(); printOptions.print_selected = s.value("print_selected").toBool();
printOptions.color_selected = s.value("color_selected").toBool(); printOptions.color_selected = s.value("color_selected").toBool();
printOptions.notes_up = s.value("notes_up").toBool();
printOptions.landscape = s.value("landscape").toBool(); printOptions.landscape = s.value("landscape").toBool();
printOptions.margins[0] = s.value("margin_left").toInt();
printOptions.margins[1] = s.value("margin_top").toInt();
printOptions.margins[2] = s.value("margin_right").toInt();
printOptions.margins[3] = s.value("margin_bottom").toInt();
printer.setOrientation((QPrinter::Orientation)printOptions.landscape); printer.setOrientation((QPrinter::Orientation)printOptions.landscape);
#if QT_VERSION >= 0x050300
QMarginsF margins;
margins.setLeft(printOptions.margins[0]);
margins.setTop(printOptions.margins[1]);
margins.setRight(printOptions.margins[2]);
margins.setBottom(printOptions.margins[3]);
printer.setPageMargins(margins, QPageLayout::Millimeter);
#else
printer.setPageMargins(
printOptions.margins[0],
printOptions.margins[1],
printOptions.margins[2],
printOptions.margins[3],
QPrinter::Millimeter
);
#endif
} }
// create a print layout and pass the printer and options
printLayout = new PrintLayout(this, &printer, &printOptions);
// create a print options object and pass our options struct // create a print options object and pass our options struct
optionsWidget = new PrintOptions(this, &printOptions); optionsWidget = new PrintOptions(this, &printOptions);
@ -69,7 +37,6 @@ PrintDialog::PrintDialog(QWidget *parent, Qt::WindowFlags f) : QDialog(parent, f
layout->addWidget(optionsWidget); layout->addWidget(optionsWidget);
progressBar = new QProgressBar(); progressBar = new QProgressBar();
connect(printLayout, SIGNAL(signalProgress(int)), progressBar, SLOT(setValue(int)));
progressBar->setMinimum(0); progressBar->setMinimum(0);
progressBar->setMaximum(100); progressBar->setMaximum(100);
progressBar->setValue(0); progressBar->setValue(0);
@ -114,45 +81,20 @@ void PrintDialog::onFinished()
s.setValue("type", printOptions.type); s.setValue("type", printOptions.type);
s.setValue("print_selected", printOptions.print_selected); s.setValue("print_selected", printOptions.print_selected);
s.setValue("color_selected", printOptions.color_selected); s.setValue("color_selected", printOptions.color_selected);
s.setValue("notes_up", printOptions.notes_up);
#if QT_VERSION >= 0x050300
s.setValue("landscape", (bool)printer.pageLayout().orientation());
QMarginsF margins = printer.pageLayout().margins(QPageLayout::Millimeter);
s.setValue("margin_left", margins.left());
s.setValue("margin_top", margins.top());
s.setValue("margin_right", margins.right());
s.setValue("margin_bottom", margins.bottom());
#else
s.setValue("landscape", (bool)printer.orientation());
qreal left, top, right, bottom;
printer.getPageMargins(&left, &top, &right, &bottom, QPrinter::Millimeter);
s.setValue("margin_left", (int)left);
s.setValue("margin_top", (int)top);
s.setValue("margin_right", (int)right);
s.setValue("margin_bottom", (int)bottom);
#endif
} }
void PrintDialog::previewClicked(void) void PrintDialog::previewClicked(void)
{ {
QPrintPreviewDialog previewDialog(&printer, this, Qt::Window
| Qt::CustomizeWindowHint | Qt::WindowCloseButtonHint
| Qt::WindowTitleHint);
connect(&previewDialog, SIGNAL(paintRequested(QPrinter *)), this, SLOT(onPaintRequested(QPrinter *)));
previewDialog.exec();
} }
void PrintDialog::printClicked(void) void PrintDialog::printClicked(void)
{ {
QPrintDialog printDialog(&printer, this); QPrintDialog printDialog(&printer, this);
if (printDialog.exec() == QDialog::Accepted){ if (printDialog.exec() == QDialog::Accepted) {
printLayout->print();
close(); close();
} }
} }
void PrintDialog::onPaintRequested(QPrinter *printerPtr) void PrintDialog::onPaintRequested(QPrinter *printerPtr)
{ {
printLayout->print();
} }

View file

@ -18,7 +18,6 @@ public:
private: private:
PrintOptions *optionsWidget; PrintOptions *optionsWidget;
PrintLayout *printLayout;
QProgressBar *progressBar; QProgressBar *progressBar;
QPrinter printer; QPrinter printer;
struct print_options printOptions; struct print_options printOptions;