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>
bb10
John Layt 2014-01-28 15:05:17 +01:00 committed by The Qt Project
parent dbc50e06df
commit 1ffd79bfb7
6 changed files with 32 additions and 33 deletions

View File

@ -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);

View File

@ -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;

View File

@ -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;

View File

@ -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

View File

@ -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;

View File

@ -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