From f602408dcd9036c67e603558b42079cbfbca084b Mon Sep 17 00:00:00 2001 From: "Lubomir I. Ivanov" Date: Fri, 14 Nov 2014 13:42:22 +0200 Subject: 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 Signed-off-by: Robert C. Helling Signed-off-by: Dirk Hohndel --- qt-ui/printdialog.cpp | 31 +++++++++++++++++++++++++++---- 1 file changed, 27 insertions(+), 4 deletions(-) (limited to 'qt-ui/printdialog.cpp') diff --git a/qt-ui/printdialog.cpp b/qt-ui/printdialog.cpp index 204f8a5c0..df3b2f5b7 100644 --- a/qt-ui/printdialog.cpp +++ b/qt-ui/printdialog.cpp @@ -14,7 +14,10 @@ #include #include #include + +#if QT_VERSION >= 0x050300 #include +#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) -- cgit v1.2.3-70-g09d2