summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJohn Layt <jlayt@kde.org>2014-01-28 15:05:17 +0100
committerThe Qt Project <gerrit-noreply@qt-project.org>2014-03-17 13:46:13 +0100
commit1ffd79bfb7261268ea4b56d29122a48334a115a1 (patch)
tree122ab42a54d4c0d8db030690887d9a5bbcae8446
parentdbc50e06df8465e6de02ac0b4458e1a3f3f8568c (diff)
QPrinter - Fix winPageSize() on Mac and Linux
Using QPageSize internally provides the Windows ID on all platforms so remove the conditional compile on the QPrinter api and add support to the print engines. Change-Id: I31e23d5090a9b6ceb087c29dead050b0ee1855a5 Reviewed-by: Lars Knoll <lars.knoll@digia.com>
-rw-r--r--src/plugins/platforms/cocoa/qprintengine_mac.mm11
-rw-r--r--src/plugins/printsupport/cups/qcupsprintengine.cpp3
-rw-r--r--src/printsupport/kernel/qprintengine_pdf.cpp11
-rw-r--r--src/printsupport/kernel/qprinter.cpp8
-rw-r--r--src/printsupport/kernel/qprinter.h2
-rw-r--r--tests/auto/printsupport/kernel/qprinter/tst_qprinter.cpp30
6 files changed, 32 insertions, 33 deletions
diff --git a/src/plugins/platforms/cocoa/qprintengine_mac.mm b/src/plugins/platforms/cocoa/qprintengine_mac.mm
index 95713eba59..fb968f31e9 100644
--- a/src/plugins/platforms/cocoa/qprintengine_mac.mm
+++ b/src/plugins/platforms/cocoa/qprintengine_mac.mm
@@ -472,8 +472,6 @@ void QMacPrintEngine::setProperty(PrintEnginePropertyKey key, const QVariant &va
break;
case PPK_SelectionOption:
break;
- case PPK_WindowsPageSize:
- break;
// The following keys are properties and settings that are supported by the Mac PrintEngine
case PPK_Resolution: {
@@ -535,6 +533,9 @@ void QMacPrintEngine::setProperty(PrintEnginePropertyKey key, const QVariant &va
// Get the named page size from the printer if supported
d->setPageSize(d->m_printDevice->supportedPageSize(value.toString()));
break;
+ case PPK_WindowsPageSize:
+ d->setPageSize(QPageSize(QPageSize::id(value.toInt())));
+ break;
case PPK_PrinterName: {
QString id = value.toString();
if (id.isEmpty())
@@ -629,9 +630,6 @@ QVariant QMacPrintEngine::property(PrintEnginePropertyKey key) const
case PPK_SelectionOption:
ret = QString();
break;
- case PPK_WindowsPageSize:
- // Special case, leave null
- break;
// The following keys are properties and settings that are supported by the Mac PrintEngine
case PPK_CollateCopies: {
@@ -680,6 +678,9 @@ QVariant QMacPrintEngine::property(PrintEnginePropertyKey key) const
case PPK_PaperName:
ret = d->m_pageLayout.pageSize().name();
break;
+ case PPK_WindowsPageSize:
+ ret = d->m_pageLayout.pageSize().windowsId();
+ break;
case PPK_PaperRect:
// PaperRect is returned in device pixels
ret = d->m_pageLayout.fullRectPixels(d->resolution.hRes);
diff --git a/src/plugins/printsupport/cups/qcupsprintengine.cpp b/src/plugins/printsupport/cups/qcupsprintengine.cpp
index 90de1a2a8b..ec9963197c 100644
--- a/src/plugins/printsupport/cups/qcupsprintengine.cpp
+++ b/src/plugins/printsupport/cups/qcupsprintengine.cpp
@@ -83,6 +83,9 @@ void QCupsPrintEngine::setProperty(PrintEnginePropertyKey key, const QVariant &v
case PPK_PageSize:
d->setPageSize(QPageSize(QPageSize::PageSizeId(value.toInt())));
break;
+ case PPK_WindowsPageSize:
+ d->setPageSize(QPageSize(QPageSize::id(value.toInt())));
+ break;
case PPK_CustomPaperSize:
d->setPageSize(QPageSize(value.toSizeF(), QPageSize::Point));
break;
diff --git a/src/printsupport/kernel/qprintengine_pdf.cpp b/src/printsupport/kernel/qprintengine_pdf.cpp
index d62da0e1d6..a2ab68a96d 100644
--- a/src/printsupport/kernel/qprintengine_pdf.cpp
+++ b/src/printsupport/kernel/qprintengine_pdf.cpp
@@ -136,8 +136,6 @@ void QPdfPrintEngine::setProperty(PrintEnginePropertyKey key, const QVariant &va
// The following keys are settings that are unsupported by the PDF PrintEngine
case PPK_CustomBase:
break;
- case PPK_WindowsPageSize:
- break;
// The following keys are properties and settings that are supported by the PDF PrintEngine
case PPK_CollateCopies:
@@ -188,6 +186,9 @@ void QPdfPrintEngine::setProperty(PrintEnginePropertyKey key, const QVariant &va
}
break;
}
+ case PPK_WindowsPageSize:
+ d->m_pageLayout.setPageSize(QPageSize(QPageSize::id(value.toInt())));
+ break;
case PPK_PaperSource:
d->paperSource = QPrinter::PaperSource(value.toInt());
break;
@@ -254,9 +255,6 @@ QVariant QPdfPrintEngine::property(PrintEnginePropertyKey key) const
case PPK_CustomBase:
// Special case, leave null
break;
- case PPK_WindowsPageSize:
- // Special case, leave null
- break;
// The following keys are properties and settings that are supported by the PDF PrintEngine
case PPK_CollateCopies:
@@ -298,6 +296,9 @@ QVariant QPdfPrintEngine::property(PrintEnginePropertyKey key) const
case PPK_PaperName:
ret = d->m_pageLayout.pageSize().name();
break;
+ case PPK_WindowsPageSize:
+ ret = d->m_pageLayout.pageSize().windowsId();
+ break;
case PPK_PaperSource:
ret = d->paperSource;
break;
diff --git a/src/printsupport/kernel/qprinter.cpp b/src/printsupport/kernel/qprinter.cpp
index f72a0ae0fb..65dcf515b7 100644
--- a/src/printsupport/kernel/qprinter.cpp
+++ b/src/printsupport/kernel/qprinter.cpp
@@ -1882,16 +1882,12 @@ QPrintEngine *QPrinter::printEngine() const
return d->printEngine;
}
-#if defined (Q_OS_WIN)
/*!
\obsolete Use QPageSize::id(windowsId) and setPageLayout(QPageSize) instead.
Sets the page size to be used by the printer under Windows to \a
pageSize.
- \warning This function is not portable so you may prefer to use
- setPaperSize() instead.
-
\sa pageLayout()
*/
void QPrinter::setWinPageSize(int pageSize)
@@ -1906,9 +1902,6 @@ void QPrinter::setWinPageSize(int pageSize)
Returns the page size used by the printer under Windows.
- \warning This function is not portable so you may prefer to use
- paperSize() instead.
-
\sa pageLayout()
*/
int QPrinter::winPageSize() const
@@ -1916,7 +1909,6 @@ int QPrinter::winPageSize() const
Q_D(const QPrinter);
return d->printEngine->property(QPrintEngine::PPK_WindowsPageSize).toInt();
}
-#endif // Q_OS_WIN
/*!
Returns a list of the resolutions (a list of dots-per-inch
diff --git a/src/printsupport/kernel/qprinter.h b/src/printsupport/kernel/qprinter.h
index 709d77d4e3..1f0639d81f 100644
--- a/src/printsupport/kernel/qprinter.h
+++ b/src/printsupport/kernel/qprinter.h
@@ -372,10 +372,8 @@ public:
void setDoubleSidedPrinting(bool enable);
bool doubleSidedPrinting() const;
-#ifdef Q_OS_WIN
void setWinPageSize(int winPageSize);
int winPageSize() const;
-#endif
QRect paperRect() const;
QRect pageRect() const;
diff --git a/tests/auto/printsupport/kernel/qprinter/tst_qprinter.cpp b/tests/auto/printsupport/kernel/qprinter/tst_qprinter.cpp
index 1211c75a3d..613623759c 100644
--- a/tests/auto/printsupport/kernel/qprinter/tst_qprinter.cpp
+++ b/tests/auto/printsupport/kernel/qprinter/tst_qprinter.cpp
@@ -1687,42 +1687,46 @@ void tst_QPrinter::supportedResolutions()
void tst_QPrinter::windowsPageSize()
{
// winPageSize() / setWinPageSize() / PPK_WindowsPageSize
- // PdfFormat: ifdef'd out TODO remove ifdef
- // NativeFormat, Cups: ifdef'd out TODO remove ifdef
+ // PdfFormat: Supported, defaults to printer default
+ // NativeFormat, Cups: Supported, defaults to printer default
// NativeFormat, Win: Supported, defaults to printer default
- // NativeFormat, Mac: ifdef'd out TODO remove ifdef
+ // NativeFormat, Mac: Supported, defaults to printer default
+
+ QPrinter pdf;
+ pdf.setOutputFormat(QPrinter::PdfFormat);
+ QCOMPARE(pdf.winPageSize(), 9); // DMPAPER_A4
+ pdf.setWinPageSize(1); // DMPAPER_LETTER
+ QCOMPARE(pdf.winPageSize(), 1);
-#ifdef Q_OS_WIN
QPrinter native;
if (native.outputFormat() == QPrinter::NativeFormat) {
// Test set/get
native.setPaperSize(QPrinter::A4);
QCOMPARE(native.pageSize(), QPrinter::A4);
- QCOMPARE(native.winPageSize(), DMPAPER_A4);
+ QCOMPARE(native.winPageSize(), 9); // DMPAPER_A4
native.setPaperSize(QPrinter::Letter);
QCOMPARE(native.pageSize(), QPrinter::Letter);
- QCOMPARE(native.winPageSize(), DMPAPER_LETTER);
+ QCOMPARE(native.winPageSize(), 1); // DMPAPER_LETTER
- native.setWinPageSize(DMPAPER_A4);
+ native.setWinPageSize(9); // DMPAPER_A4
QCOMPARE(native.pageSize(), QPrinter::A4);
- QCOMPARE(native.winPageSize(), DMPAPER_A4);
+ QCOMPARE(native.winPageSize(), 9); // DMPAPER_A4
- native.setWinPageSize(DMPAPER_LETTER);
+ native.setWinPageSize(1); // DMPAPER_LETTER
QCOMPARE(native.pageSize(), QPrinter::Letter);
- QCOMPARE(native.winPageSize(), DMPAPER_LETTER);
+ QCOMPARE(native.winPageSize(), 1); // DMPAPER_LETTER
// Test value preservation
native.setOutputFormat(QPrinter::PdfFormat);
QCOMPARE(native.pageSize(), QPrinter::Letter);
- QCOMPARE(native.winPageSize(), DMPAPER_LETTER);
+ QCOMPARE(native.winPageSize(), 1); // DMPAPER_LETTER
native.setOutputFormat(QPrinter::NativeFormat);
QCOMPARE(native.pageSize(), QPrinter::Letter);
- QCOMPARE(native.winPageSize(), DMPAPER_LETTER);
+ QCOMPARE(native.winPageSize(), 1); // DMPAPER_LETTER
} else {
QSKIP("No printers installed, cannot test NativeFormat, please install printers to test");
}
-#endif // Q_OS_WIN
}
// Test QPrinter setters/getters for non-QPrintEngine options