From f149b7906cafc032aaff9d61a53079981a6ac497 Mon Sep 17 00:00:00 2001 From: Andy Shaw Date: Thu, 19 Jan 2012 20:44:54 +0100 Subject: Fix set/paperSize(QPrinter::PaperSize) on Mac This fixes the paper size setting on Mac as it would not return the same paper size that was set with setPaperSize() when calling paperSize(). Test is included. Task-number: QTBUG-20882 Change-Id: Ib0064dd40de147d6db2424cdb31021e66894cc37 Reviewed-by: Jiang Jiang --- src/gui/painting/qprintengine_mac.mm | 4 ++-- tests/auto/qprinter/tst_qprinter.cpp | 25 ++++++++++++++++--------- 2 files changed, 18 insertions(+), 11 deletions(-) diff --git a/src/gui/painting/qprintengine_mac.mm b/src/gui/painting/qprintengine_mac.mm index 729c87b..ecdba75 100644 --- a/src/gui/painting/qprintengine_mac.mm +++ b/src/gui/painting/qprintengine_mac.mm @@ -148,7 +148,7 @@ QMacPrintEnginePrivate::~QMacPrintEnginePrivate() void QMacPrintEnginePrivate::setPaperSize(QPrinter::PaperSize ps) { Q_Q(QMacPrintEngine); - QSizeF newSize = qt_paperSizeToQSizeF(ps); + QSize newSize = qt_paperSizeToQSizeF(ps).toSize(); QCFType formats; PMPrinter printer; @@ -186,7 +186,7 @@ QPrinter::PaperSize QMacPrintEnginePrivate::paperSize() const int wMM = int((paper.right - paper.left) / 72 * 25.4 + 0.5); int hMM = int((paper.bottom - paper.top) / 72 * 25.4 + 0.5); for (int i = QPrinter::A4; i < QPrinter::NPaperSize; ++i) { - QSizeF s = qt_paperSizeToQSizeF(QPrinter::PaperSize(i)); + QSize s = qt_paperSizeToQSizeF(QPrinter::PaperSize(i)).toSize(); if (s.width() == wMM && s.height() == hMM) return (QPrinter::PaperSize)i; } diff --git a/tests/auto/qprinter/tst_qprinter.cpp b/tests/auto/qprinter/tst_qprinter.cpp index ea13995..09d6b26 100644 --- a/tests/auto/qprinter/tst_qprinter.cpp +++ b/tests/auto/qprinter/tst_qprinter.cpp @@ -577,15 +577,22 @@ void tst_QPrinter::outputFormatFromSuffix() void tst_QPrinter::setGetPaperSize() { - QPrinter p; - p.setOutputFormat(QPrinter::PdfFormat); - QSizeF size(500, 10); - p.setPaperSize(size, QPrinter::Millimeter); - QCOMPARE(p.paperSize(QPrinter::Millimeter), size); - QSizeF ptSize = p.paperSize(QPrinter::Point); - //qDebug() << ptSize; - QVERIFY(qAbs(ptSize.width() - size.width() * (72/25.4)) < 1E-4); - QVERIFY(qAbs(ptSize.height() - size.height() * (72/25.4)) < 1E-4); + { + QPrinter p; + p.setOutputFormat(QPrinter::PdfFormat); + QSizeF size(500, 10); + p.setPaperSize(size, QPrinter::Millimeter); + QCOMPARE(p.paperSize(QPrinter::Millimeter), size); + QSizeF ptSize = p.paperSize(QPrinter::Point); + //qDebug() << ptSize; + QVERIFY(qAbs(ptSize.width() - size.width() * (72/25.4)) < 1E-4); + QVERIFY(qAbs(ptSize.height() - size.height() * (72/25.4)) < 1E-4); + } + { + QPrinter p; + p.setPaperSize(QPrinter::Legal); + QCOMPARE(p.paperSize(), QPrinter::Legal); + } } void tst_QPrinter::testPageMargins_data() -- cgit v0.12