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/printsupport | |
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/printsupport')
-rw-r--r-- | src/plugins/printsupport/cups/qcupsprintengine.cpp | 47 | ||||
-rw-r--r-- | src/plugins/printsupport/cups/qcupsprintengine_p.h | 1 |
2 files changed, 46 insertions, 2 deletions
diff --git a/src/plugins/printsupport/cups/qcupsprintengine.cpp b/src/plugins/printsupport/cups/qcupsprintengine.cpp index 21895e9d28..1c86420cb2 100644 --- a/src/plugins/printsupport/cups/qcupsprintengine.cpp +++ b/src/plugins/printsupport/cups/qcupsprintengine.cpp @@ -103,7 +103,9 @@ void QCupsPrintEngine::setProperty(PrintEnginePropertyKey key, const QVariant &v d->cupsOptions = value.toStringList(); break; case PPK_CupsStringPageSize: + case PPK_PaperName: d->cupsStringPageSize = value.toString(); + d->setPaperName(); break; case PPK_PrinterName: // prevent setting the defaults again for the same printer @@ -140,6 +142,7 @@ QVariant QCupsPrintEngine::property(PrintEnginePropertyKey key) const ret = d->cupsOptions; break; case PPK_CupsStringPageSize: + case PPK_PaperName: ret = d->cupsStringPageSize; break; default: @@ -284,6 +287,7 @@ void QCupsPrintEnginePrivate::setPaperSize() QPdf::PaperSize size = QPdf::paperSize(QPrinter::PaperSize(printerPaperSize)); if (cups.currentPPD()) { + cupsStringPageSize = QLatin1String("Custom"); const ppd_option_t* pageSizes = cups.pageSizes(); for (int i = 0; i < pageSizes->num_choices; ++i) { QByteArray cupsPageSize = pageSizes->choices[i].choice; @@ -293,7 +297,7 @@ void QCupsPrintEnginePrivate::setPaperSize() if (qAbs(size.width - tmpCupsPaperRect.width()) < 5 && qAbs(size.height - tmpCupsPaperRect.height()) < 5) { cupsPaperRect = tmpCupsPaperRect; cupsPageRect = tmpCupsPageRect; - + cupsStringPageSize = pageSizes->choices[i].text; leftMargin = cupsPageRect.x() - cupsPaperRect.x(); topMargin = cupsPageRect.y() - cupsPaperRect.y(); rightMargin = cupsPaperRect.right() - cupsPageRect.right(); @@ -307,6 +311,43 @@ void QCupsPrintEnginePrivate::setPaperSize() } } +void QCupsPrintEnginePrivate::setPaperName() +{ + if (QCUPSSupport::isAvailable()) { + QCUPSSupport cups; + if (cups.currentPPD()) { + const ppd_option_t* pageSizes = cups.pageSizes(); + bool foundPaperName = false; + for (int i = 0; i < pageSizes->num_choices; ++i) { + if (cupsStringPageSize == pageSizes->choices[i].text) { + foundPaperName = true; + QByteArray cupsPageSize = pageSizes->choices[i].choice; + cupsPaperRect = cups.paperRect(cupsPageSize); + cupsPageRect = cups.pageRect(cupsPageSize); + leftMargin = cupsPageRect.x() - cupsPaperRect.x(); + topMargin = cupsPageRect.y() - cupsPaperRect.y(); + rightMargin = cupsPaperRect.right() - cupsPageRect.right(); + bottomMargin = cupsPaperRect.bottom() - cupsPageRect.bottom(); + printerPaperSize = QPrinter::Custom; + customPaperSize = cupsPaperRect.size(); + for (int ps = 0; ps < QPrinter::NPageSize; ++ps) { + QPdf::PaperSize size = QPdf::paperSize(QPrinter::PaperSize(ps)); + if (qAbs(size.width - cupsPaperRect.width()) < 5 && qAbs(size.height - cupsPaperRect.height()) < 5) { + printerPaperSize = static_cast<QPrinter::PaperSize>(ps); + customPaperSize = QSize(); + break; + } + } + updatePaperSize(); + break; + } + } + if (!foundPaperName) + cupsStringPageSize = QString(); + } + } +} + void QCupsPrintEnginePrivate::setCupsDefaults() { if (QCUPSSupport::isAvailable()) { @@ -348,8 +389,10 @@ void QCupsPrintEnginePrivate::setCupsDefaults() const ppd_option_t* pageSizes = cups.pageSizes(); QByteArray cupsPageSize; for (int i = 0; i < pageSizes->num_choices; ++i) { - if (static_cast<int>(pageSizes->choices[i].marked) == 1) + if (static_cast<int>(pageSizes->choices[i].marked) == 1) { cupsPageSize = pageSizes->choices[i].choice; + cupsStringPageSize = pageSizes->choices[i].text; + } } cupsOptions = cups.options(); diff --git a/src/plugins/printsupport/cups/qcupsprintengine_p.h b/src/plugins/printsupport/cups/qcupsprintengine_p.h index 31ee6bb256..db947a0232 100644 --- a/src/plugins/printsupport/cups/qcupsprintengine_p.h +++ b/src/plugins/printsupport/cups/qcupsprintengine_p.h @@ -97,6 +97,7 @@ public: void updatePaperSize(); void setPaperSize(); + void setPaperName(); void setCupsDefaults(); private: |