summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Lubomir I. Ivanov <neolit123@gmail.com>2014-11-14 13:42:22 +0200
committerGravatar Dirk Hohndel <dirk@hohndel.org>2014-11-14 08:49:53 -0800
commitf602408dcd9036c67e603558b42079cbfbca084b (patch)
tree65a3f809a658abad27411f6e6f37f764b27472ad
parent406ad7786ea4a6d45878251b0145f0404b1f540a (diff)
downloadsubsurface-f602408dcd9036c67e603558b42079cbfbca084b.tar.gz
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>
-rw-r--r--qt-ui/printdialog.cpp31
1 files changed, 27 insertions, 4 deletions
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 <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)