From dbc50e06df8465e6de02ac0b4458e1a3f3f8568c Mon Sep 17 00:00:00 2001 From: John Layt Date: Mon, 30 Dec 2013 18:04:40 +0100 Subject: QPrinter - Use QPageSize and QPageLayout Use QPageSize and QPageMargins to get/set values in the print engines, add api to directly set the values, and rewrite the docs to make the paper-based api obsolete instead of the page-based api. Add new PPK keys to pass QPageSize, QPageMargins and QPageLayout to the print engines to ensure no level of detail is lost, e.g. for custom sizes passed to QPrinter. [ChangeLog][QtPrintSupport][QPrinter] QPrinter can now use QPageSize and QPageLayout in the public api to control the page layout for a print job. Change-Id: Iee39a4042bcd6141d29b0a82b49066d7a7a78120 Reviewed-by: Lars Knoll --- src/plugins/platforms/cocoa/qprintengine_mac.mm | 32 +++++++++++++++++++++- src/plugins/printsupport/cups/qcupsprintengine.cpp | 12 ++++++++ 2 files changed, 43 insertions(+), 1 deletion(-) (limited to 'src/plugins') diff --git a/src/plugins/platforms/cocoa/qprintengine_mac.mm b/src/plugins/platforms/cocoa/qprintengine_mac.mm index bfe44c7ab3..95713eba59 100644 --- a/src/plugins/platforms/cocoa/qprintengine_mac.mm +++ b/src/plugins/platforms/cocoa/qprintengine_mac.mm @@ -42,7 +42,7 @@ #include "qprintengine_mac_p.h" #include "qcocoaprintersupport.h" #include -#include +#include #include #include @@ -559,6 +559,26 @@ void QMacPrintEngine::setProperty(PrintEnginePropertyKey key, const QVariant &va margins.at(2).toReal(), margins.at(3).toReal())); break; } + case PPK_QPageSize: + d->setPageSize(value.value()); + break; + case PPK_QPageMargins: { + QPair pair = value.value >(); + d->m_pageLayout.setUnits(pair.second); + d->m_pageLayout.setMargins(pair.first); + break; + } + case PPK_QPageLayout: { + QPageLayout pageLayout = value.value(); + if (pageLayout.isValid() && d->m_printDevice->isValidPageLayout(pageLayout, d->resolution.hRes)) { + setProperty(PPK_QPageSize, QVariant::fromValue(pageLayout.pageSize())); + setProperty(PPK_FullPage, pageLayout.mode() == QPageLayout::FullPageMode); + setProperty(PPK_Orientation, QVariant::fromValue(pageLayout.orientation())); + d->m_pageLayout.setUnits(pageLayout.units()); + d->m_pageLayout.setMargins(pageLayout.margins()); + } + break; + } // No default so that compiler will complain if new keys added and not handled in this engine } } @@ -688,6 +708,16 @@ QVariant QMacPrintEngine::property(PrintEnginePropertyKey key) const ret = list; break; } + case PPK_QPageSize: + ret.setValue(d->m_pageLayout.pageSize()); + break; + case PPK_QPageMargins: { + QPair pair = qMakePair(d->m_pageLayout.margins(), d->m_pageLayout.units()); + ret.setValue(pair); + break; + } + case PPK_QPageLayout: + ret.setValue(d->m_pageLayout); // No default so that compiler will complain if new keys added and not handled in this engine } return ret; diff --git a/src/plugins/printsupport/cups/qcupsprintengine.cpp b/src/plugins/printsupport/cups/qcupsprintengine.cpp index 2c05a76084..90de1a2a8b 100644 --- a/src/plugins/printsupport/cups/qcupsprintengine.cpp +++ b/src/plugins/printsupport/cups/qcupsprintengine.cpp @@ -96,6 +96,18 @@ void QCupsPrintEngine::setProperty(PrintEnginePropertyKey key, const QVariant &v case PPK_CupsOptions: d->cupsOptions = value.toStringList(); break; + case PPK_QPageSize: + d->setPageSize(value.value()); + break; + case PPK_QPageLayout: { + QPageLayout pageLayout = value.value(); + if (pageLayout.isValid() && d->m_printDevice.isValidPageLayout(pageLayout, d->resolution)) { + d->m_pageLayout = pageLayout; + // Replace the page size with the CUPS page size + d->setPageSize(d->m_printDevice.supportedPageSize(pageLayout.pageSize())); + } + break; + } default: QPdfPrintEngine::setProperty(key, value); break; -- cgit v1.2.3