diff options
author | Andy Shaw <andy.shaw@digia.com> | 2012-12-29 17:08:12 +0100 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2013-03-12 09:16:42 +0100 |
commit | 39a902c0081f442141353c466ada09d62036c04e (patch) | |
tree | 6a203f89bd6a4b781acfb27ea7672c6d68471e94 /src/plugins/platforms | |
parent | 62fe32b37c173f9dc82f4f95ae50b2e95a719d77 (diff) |
Add support for setting/getting the paper name on the QPrinter
This adds support for specifying a paper name which will be set on
the printer if it is available for the driver.
Change-Id: Id7fd0c8cf68745db3d7a8de7e2ac98d3e2ba9b79
Reviewed-by: Pierre Rossi <pierre.rossi@gmail.com>
Diffstat (limited to 'src/plugins/platforms')
-rw-r--r-- | src/plugins/platforms/cocoa/qprintengine_mac.mm | 38 | ||||
-rw-r--r-- | src/plugins/platforms/cocoa/qprintengine_mac_p.h | 1 |
2 files changed, 39 insertions, 0 deletions
diff --git a/src/plugins/platforms/cocoa/qprintengine_mac.mm b/src/plugins/platforms/cocoa/qprintengine_mac.mm index 4570a663f6..4748005f1a 100644 --- a/src/plugins/platforms/cocoa/qprintengine_mac.mm +++ b/src/plugins/platforms/cocoa/qprintengine_mac.mm @@ -180,6 +180,38 @@ QPrinter::PaperSize QMacPrintEnginePrivate::paperSize() const return QPlatformPrinterSupport::convertQSizeFToPaperSize(sizef); } +void QMacPrintEnginePrivate::setPaperName(const QString &name) +{ + Q_Q(QMacPrintEngine); + PMPrinter printer; + + if (PMSessionGetCurrentPrinter(session(), &printer) == noErr) { + CFArrayRef array; + if (PMPrinterGetPaperList(printer, &array) != noErr) { + PMRelease(printer); + return; + } + int count = CFArrayGetCount(array); + for (int i = 0; i < count; ++i) { + PMPaper paper = static_cast<PMPaper>(const_cast<void *>(CFArrayGetValueAtIndex(array, i))); + QCFString paperName; + if (PMPaperCreateLocalizedName(paper, printer, &paperName) == noErr) { + if (QString(paperName) == name) { + PMPageFormat tmp; + PMCreatePageFormatWithPMPaper(&tmp, paper); + PMCopyPageFormat(tmp, format()); + q->setProperty(QPrintEngine::PPK_Orientation, orient); + if (PMSessionValidatePageFormat(session(), format(), kPMDontWantBoolean) != noErr) { + // Don't know, warn for the moment. + qWarning("QMacPrintEngine, problem setting paper name"); + } + } + } + } + PMRelease(printer); + } +} + QList<QVariant> QMacPrintEnginePrivate::supportedResolutions() const { Q_ASSERT_X(printInfo, "QMacPrinterEngine::supportedResolutions", @@ -601,6 +633,9 @@ void QMacPrintEngine::setProperty(PrintEnginePropertyKey key, const QVariant &va case PPK_PaperSize: d->setPaperSize(QPrinter::PaperSize(value.toInt())); break; + case PPK_PaperName: + d->setPaperName(value.toString()); + break; case PPK_PrinterName: { bool printerNameSet = false; OSStatus status = noErr; @@ -739,6 +774,9 @@ QVariant QMacPrintEngine::property(PrintEnginePropertyKey key) const case PPK_PaperSize: ret = d->paperSize(); break; + case PPK_PaperName: + ret = QCFString::toQString([d->printInfo localizedPaperName]); + break; case PPK_PaperRect: { QRect r; PMRect macrect; diff --git a/src/plugins/platforms/cocoa/qprintengine_mac_p.h b/src/plugins/platforms/cocoa/qprintengine_mac_p.h index e122cc5822..fd1b60a9ad 100644 --- a/src/plugins/platforms/cocoa/qprintengine_mac_p.h +++ b/src/plugins/platforms/cocoa/qprintengine_mac_p.h @@ -142,6 +142,7 @@ public: bool newPage_helper(); void setPaperSize(QPrinter::PaperSize ps); QPrinter::PaperSize paperSize() const; + void setPaperName(const QString &name); QList<QVariant> supportedResolutions() const; inline bool isPrintSessionInitialized() const { |