Print: support margin saving for older Qt versions

Seems like QMarginsF and QPageLayout were added quite
recently - in Qt5.3!

We attempt to support older versions by using something
found in the Qt4.7 documentation.

Patch also fixes small ordering issue where top / left
margins were swapped.

Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com>
Signed-off-by: Robert C. Helling <helling@atdotde.de>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
Lubomir I. Ivanov 2014-11-14 13:42:22 +02:00 committed by Dirk Hohndel
parent 406ad7786e
commit f602408dcd

View file

@ -14,7 +14,10 @@
#include <QPrinterInfo>
#include <QMessageBox>
#include <QSettings>
#if QT_VERSION >= 0x050300
#include <QMarginsF>
#endif
#define SETTINGS_GROUP "PrintDialog"
@ -42,12 +45,22 @@ PrintDialog::PrintDialog(QWidget *parent, Qt::WindowFlags f) : QDialog(parent, f
printOptions.margins[2] = s.value("margin_right").toInt();
printOptions.margins[3] = s.value("margin_bottom").toInt();
printer.setOrientation((QPrinter::Orientation)printOptions.landscape);
#if QT_VERSION >= 0x050300
QMarginsF margins;
margins.setLeft(printOptions.margins[0]);
margins.setRight(printOptions.margins[1]);
margins.setTop(printOptions.margins[2]);
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
@ -108,12 +121,22 @@ void PrintDialog::onFinished()
s.setValue("print_selected", printOptions.print_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_right", margins.top());
s.setValue("margin_top", margins.right());
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)