diff options
author | Oswald Buddenhagen <oswald.buddenhagen@digia.com> | 2013-03-20 13:46:57 +0100 |
---|---|---|
committer | Oswald Buddenhagen <oswald.buddenhagen@digia.com> | 2013-03-20 13:49:28 +0100 |
commit | 76c0be34cd4ff4564693162fa7528463e23ce9d8 (patch) | |
tree | f165b7bc319548fb0082365411a871028f92e89e /src/plugins/printsupport/cups | |
parent | 27b4fe96b59e9e63d1e570e802c072e9afdfb2d4 (diff) | |
parent | 36cb3f3f655a9090c82de609010cbfb88651a0f3 (diff) |
Merge branch 'dev' into stable
This starts Qt 5.1 release cycle
Conflicts:
src/gui/text/qfontdatabase.cpp
src/gui/text/qharfbuzz_copy_p.h
src/widgets/kernel/qapplication.cpp
src/widgets/kernel/qcoreapplication.cpp
Change-Id: I72fbf83ab3c2206aeea1b089428b0fc2a89bd62b
Diffstat (limited to 'src/plugins/printsupport/cups')
4 files changed, 52 insertions, 4 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: diff --git a/src/plugins/printsupport/cups/qcupsprintersupport.cpp b/src/plugins/printsupport/cups/qcupsprintersupport.cpp index c2e9bd445f..f41d4f5047 100644 --- a/src/plugins/printsupport/cups/qcupsprintersupport.cpp +++ b/src/plugins/printsupport/cups/qcupsprintersupport.cpp @@ -86,6 +86,11 @@ QList<QPrinter::PaperSize> QCupsPrinterSupport::supportedPaperSizes(const QPrint return QCUPSSupport::getCupsPrinterPaperSizes(printerIndex(printerInfo)); } +QList<QPair<QString, QSizeF> > QCupsPrinterSupport::supportedSizesWithNames(const QPrinterInfo &printerInfo) const +{ + return QCUPSSupport::getCupsPrinterPaperSizesWithNames(printerIndex(printerInfo)); +} + void QCupsPrinterSupport::loadCups() { cupsGetDests = (CupsGetDests) m_cups.resolve("cupsGetDests"); diff --git a/src/plugins/printsupport/cups/qcupsprintersupport_p.h b/src/plugins/printsupport/cups/qcupsprintersupport_p.h index 43fe871021..e9fe24203e 100644 --- a/src/plugins/printsupport/cups/qcupsprintersupport_p.h +++ b/src/plugins/printsupport/cups/qcupsprintersupport_p.h @@ -52,7 +52,6 @@ #include <cups/cups.h> -QT_BEGIN_HEADER QT_BEGIN_NAMESPACE typedef int (*CupsGetDests)(cups_dest_t **dests); @@ -68,6 +67,7 @@ public: virtual QPrintEngine *createNativePrintEngine(QPrinter::PrinterMode printerMode); virtual QPaintEngine *createPaintEngine(QPrintEngine *printEngine, QPrinter::PrinterMode); virtual QList<QPrinter::PaperSize> supportedPaperSizes(const QPrinterInfo &) const; + virtual QList<QPair<QString, QSizeF> > supportedSizesWithNames(const QPrinterInfo &) const; virtual QString printerOption(const QPrinterInfo &printer, const QString &key) const; virtual PrinterOptions printerOptions(const QPrinterInfo &printer) const; @@ -86,7 +86,6 @@ private: }; QT_END_NAMESPACE -QT_END_HEADER #endif // QT_NO_PRINTER #endif // QCUPSPRINTERSUPPORT_H |