summaryrefslogtreecommitdiffstats
path: root/tests/auto/printsupport
diff options
context:
space:
mode:
authorAndy Shaw <andy.shaw@digia.com>2012-10-25 06:43:01 +0200
committerThe Qt Project <gerrit-noreply@qt-project.org>2012-10-30 12:53:46 +0100
commit50ec06da2c8a1c680d48b84f8c1267fe78a86b6a (patch)
treec31c6015dd0ba3cad1fe194ee5e77a19e5798fc5 /tests/auto/printsupport
parentbf722c1ab387e8892242dcaacd8afd36d592ebb6 (diff)
Only use the user set page margins for custom paper
When the QPrinter is initalized then it will set up page margins based on the default paper size. If the paper size is changed to be a custom one then it should disregard the margins for the default paper size. If the page margins are set explicitly beforehand then it will use these page margins. Change-Id: Ic535c3a80b8b217dbd5eb5f4fb2cbc0ab1354563 Reviewed-by: Titta Heikkala <titta.heikkala@digia.com> Reviewed-by: Friedemann Kleint <Friedemann.Kleint@digia.com> Reviewed-by: Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@digia.com>
Diffstat (limited to 'tests/auto/printsupport')
-rw-r--r--tests/auto/printsupport/kernel/qprinter/tst_qprinter.cpp59
1 files changed, 59 insertions, 0 deletions
diff --git a/tests/auto/printsupport/kernel/qprinter/tst_qprinter.cpp b/tests/auto/printsupport/kernel/qprinter/tst_qprinter.cpp
index 0f7c7f7a84..b01f311f4f 100644
--- a/tests/auto/printsupport/kernel/qprinter/tst_qprinter.cpp
+++ b/tests/auto/printsupport/kernel/qprinter/tst_qprinter.cpp
@@ -109,6 +109,8 @@ private slots:
void valuePreservation();
void errorReporting();
void testCustomPageSizes();
+ void customPaperSizeAndMargins_data();
+ void customPaperSizeAndMargins();
#if !defined(QT_NO_COMPLETER) && !defined(QT_NO_FILEDIALOG)
void printDialogCompleter();
#endif
@@ -933,6 +935,63 @@ void tst_QPrinter::testCustomPageSizes()
QCOMPARE(paperSize, customSize);
}
+void tst_QPrinter::customPaperSizeAndMargins_data()
+{
+ QTest::addColumn<bool>("pdf");
+ QTest::addColumn<bool>("before");
+ QTest::addColumn<qreal>("left");
+ QTest::addColumn<qreal>("top");
+ QTest::addColumn<qreal>("right");
+ QTest::addColumn<qreal>("bottom");
+
+ QTest::newRow("beforeNoPDF") << false << true << qreal(2) << qreal(2) << qreal(2) << qreal(2);
+ QTest::newRow("beforePDF") << true << true << qreal(2) << qreal(2) << qreal(2) << qreal(2);
+ QTest::newRow("afterNoPDF") << false << false << qreal(2) << qreal(2) << qreal(2) << qreal(2);
+ QTest::newRow("afterAfterPDF") << true << false << qreal(2) << qreal(2) << qreal(2) << qreal(2);
+}
+
+void tst_QPrinter::customPaperSizeAndMargins()
+{
+ QFETCH(bool, pdf);
+ QFETCH(bool, before);
+ QFETCH(qreal, left);
+ QFETCH(qreal, top);
+ QFETCH(qreal, right);
+ QFETCH(qreal, bottom);
+
+ qreal tolerance = 0.05;
+ qreal getLeft = 0;
+ qreal getRight = 0;
+ qreal getTop = 0;
+ qreal getBottom = 0;
+ QSizeF customSize(8.5, 11.0);
+
+ QPrinter p;
+ if (pdf)
+ p.setOutputFormat(QPrinter::PdfFormat);
+ if (before)
+ p.setPageMargins(left, top, right, bottom, QPrinter::Millimeter);
+ p.setPaperSize(customSize, QPrinter::Millimeter);
+ p.getPageMargins(&getLeft, &getTop, &getRight, &getBottom, QPrinter::Millimeter);
+ if (before) {
+ QVERIFY(fabs(left - getLeft) < tolerance);
+ QVERIFY(fabs(left - getTop) < tolerance);
+ QVERIFY(fabs(left - getRight) < tolerance);
+ QVERIFY(fabs(left - getBottom) < tolerance);
+ } else {
+ QVERIFY(getLeft == 0);
+ QVERIFY(getTop == 0);
+ QVERIFY(getRight == 0);
+ QVERIFY(getBottom == 0);
+ p.setPageMargins(left, top, right, bottom, QPrinter::Millimeter);
+ p.getPageMargins(&getLeft, &getTop, &getRight, &getBottom, QPrinter::Millimeter);
+ QVERIFY(fabs(left - getLeft) < tolerance);
+ QVERIFY(fabs(left - getTop) < tolerance);
+ QVERIFY(fabs(left - getRight) < tolerance);
+ QVERIFY(fabs(left - getBottom) < tolerance);
+ }
+}
+
#if !defined(QT_NO_COMPLETER) && !defined(QT_NO_FILEDIALOG)
void tst_QPrinter::printDialogCompleter()
{