diff options
Diffstat (limited to 'src/printsupport/kernel')
-rw-r--r-- | src/printsupport/kernel/qcups.cpp | 21 | ||||
-rw-r--r-- | src/printsupport/kernel/qcups_p.h | 1 | ||||
-rw-r--r-- | src/printsupport/kernel/qpaintengine_alpha_p.h | 2 | ||||
-rw-r--r-- | src/printsupport/kernel/qplatformprintersupport.cpp | 5 | ||||
-rw-r--r-- | src/printsupport/kernel/qplatformprintersupport.h | 6 | ||||
-rw-r--r-- | src/printsupport/kernel/qplatformprintplugin.h | 4 | ||||
-rw-r--r-- | src/printsupport/kernel/qprintengine.h | 5 | ||||
-rw-r--r-- | src/printsupport/kernel/qprintengine_win.cpp | 107 | ||||
-rw-r--r-- | src/printsupport/kernel/qprintengine_win_p.h | 3 | ||||
-rw-r--r-- | src/printsupport/kernel/qprinter.cpp | 33 | ||||
-rw-r--r-- | src/printsupport/kernel/qprinter.h | 7 | ||||
-rw-r--r-- | src/printsupport/kernel/qprinterinfo.cpp | 19 | ||||
-rw-r--r-- | src/printsupport/kernel/qprinterinfo.h | 7 | ||||
-rw-r--r-- | src/printsupport/kernel/qprinterinfo_p.h | 6 | ||||
-rw-r--r-- | src/printsupport/kernel/qtprintsupportglobal.h | 4 |
15 files changed, 202 insertions, 28 deletions
diff --git a/src/printsupport/kernel/qcups.cpp b/src/printsupport/kernel/qcups.cpp index 30de3d301c..d2deee1db3 100644 --- a/src/printsupport/kernel/qcups.cpp +++ b/src/printsupport/kernel/qcups.cpp @@ -52,6 +52,8 @@ QT_BEGIN_NAMESPACE +extern double qt_multiplierForUnit(QPrinter::Unit unit, int resolution); + typedef int (*CupsGetDests)(cups_dest_t **dests); typedef void (*CupsFreeDests)(int num_dests, cups_dest_t *dests); typedef const char* (*CupsGetPPD)(const char *printer); @@ -500,6 +502,25 @@ QList<QPrinter::PaperSize> QCUPSSupport::getCupsPrinterPaperSizes(int cupsPrinte return result; } +QList<QPair<QString, QSizeF> > QCUPSSupport::getCupsPrinterPaperSizesWithNames(int cupsPrinterIndex) +{ + QList<QPair<QString, QSizeF> > result; + if (!QCUPSSupport::isAvailable() || cupsPrinterIndex < 0) + return result; + // Find paper sizes from CUPS. + QCUPSSupport cups; + cups.setCurrentPrinter(cupsPrinterIndex); + if (const ppd_option_t* size = cups.pageSizes()) { + for (int j = 0; j < size->num_choices; ++j) { + double multiplier = qt_multiplierForUnit(QPrinter::Millimeter, 0); // resolution is not needed here + QSize sz = cups.paperRect(size->choices[j].choice).size(); + result.append(qMakePair(QString::fromUtf8(size->choices[j].text), QSizeF(sz.width() / multiplier, sz.height() / multiplier))); + } + } + return result; +} + + QT_END_NAMESPACE #endif // QT_NO_CUPS diff --git a/src/printsupport/kernel/qcups_p.h b/src/printsupport/kernel/qcups_p.h index 67a8955d93..0828f582a3 100644 --- a/src/printsupport/kernel/qcups_p.h +++ b/src/printsupport/kernel/qcups_p.h @@ -121,6 +121,7 @@ public: static QList<Printer> availableUnixPrinters(); static QList<QPrinter::PaperSize> getCupsPrinterPaperSizes(int cupsPrinterIndex); + static QList<QPair<QString, QSizeF> > getCupsPrinterPaperSizesWithNames(int cupsPrinterIndex); private: void collectMarkedOptions(QStringList& list, const ppd_group_t* group = 0) const; diff --git a/src/printsupport/kernel/qpaintengine_alpha_p.h b/src/printsupport/kernel/qpaintengine_alpha_p.h index 99b9b930e9..8a0781d0d3 100644 --- a/src/printsupport/kernel/qpaintengine_alpha_p.h +++ b/src/printsupport/kernel/qpaintengine_alpha_p.h @@ -53,6 +53,8 @@ // We mean it. // +#include <QtCore/qglobal.h> + #ifndef QT_NO_PRINTER #include "private/qpaintengine_p.h" #include <QtPrintSupport/qtprintsupportglobal.h> diff --git a/src/printsupport/kernel/qplatformprintersupport.cpp b/src/printsupport/kernel/qplatformprintersupport.cpp index f20ac5d177..4d80e55ab6 100644 --- a/src/printsupport/kernel/qplatformprintersupport.cpp +++ b/src/printsupport/kernel/qplatformprintersupport.cpp @@ -82,6 +82,11 @@ QList<QPrinter::PaperSize> QPlatformPrinterSupport::supportedPaperSizes(const QP return QList<QPrinter::PaperSize>(); } +QList<QPair<QString, QSizeF> > QPlatformPrinterSupport::supportedSizesWithNames(const QPrinterInfo &) const +{ + return QList<QPair<QString, QSizeF> >(); +} + QList<QPrinterInfo> QPlatformPrinterSupport::availablePrinters() { return m_printers; diff --git a/src/printsupport/kernel/qplatformprintersupport.h b/src/printsupport/kernel/qplatformprintersupport.h index 5d3c7d0aa6..c4ffcffd1e 100644 --- a/src/printsupport/kernel/qplatformprintersupport.h +++ b/src/printsupport/kernel/qplatformprintersupport.h @@ -55,8 +55,6 @@ #include <QtCore/qlist.h> #include <QtCore/qhash.h> -QT_BEGIN_HEADER - QT_BEGIN_NAMESPACE #ifndef QT_NO_PRINTER @@ -74,7 +72,7 @@ public: virtual QPrintEngine *createNativePrintEngine(QPrinter::PrinterMode printerMode); virtual QPaintEngine *createPaintEngine(QPrintEngine *, QPrinter::PrinterMode printerMode); virtual QList<QPrinter::PaperSize> supportedPaperSizes(const QPrinterInfo &) const; - + virtual QList<QPair<QString, QSizeF> > supportedSizesWithNames(const QPrinterInfo &printerInfo) const; virtual QList<QPrinterInfo> availablePrinters(); virtual QPrinterInfo defaultPrinter(); virtual QPrinterInfo printerInfo(const QString &printerName); @@ -98,6 +96,4 @@ protected: QT_END_NAMESPACE -QT_END_HEADER - #endif // QPLATFORMPRINTERSUPPORT_H diff --git a/src/printsupport/kernel/qplatformprintplugin.h b/src/printsupport/kernel/qplatformprintplugin.h index 67af44cd68..4a5a94616a 100644 --- a/src/printsupport/kernel/qplatformprintplugin.h +++ b/src/printsupport/kernel/qplatformprintplugin.h @@ -55,8 +55,6 @@ #include <QtCore/qfactoryinterface.h> #include <QtPrintSupport/qtprintsupportglobal.h> -QT_BEGIN_HEADER - QT_BEGIN_NAMESPACE @@ -78,6 +76,4 @@ public: QT_END_NAMESPACE -QT_END_HEADER - #endif // QPLATFORMPRINTPLUGIN_H diff --git a/src/printsupport/kernel/qprintengine.h b/src/printsupport/kernel/qprintengine.h index 2abf3dda74..3993a22bef 100644 --- a/src/printsupport/kernel/qprintengine.h +++ b/src/printsupport/kernel/qprintengine.h @@ -45,8 +45,6 @@ #include <QtCore/qvariant.h> #include <QtPrintSupport/qprinter.h> -QT_BEGIN_HEADER - QT_BEGIN_NAMESPACE @@ -86,6 +84,7 @@ public: PPK_PageMargins, PPK_CopyCount, PPK_SupportsMultipleCopies, + PPK_PaperName, PPK_PaperSize = PPK_PageSize, PPK_CustomBase = 0xff00 @@ -106,6 +105,4 @@ public: QT_END_NAMESPACE -QT_END_HEADER - #endif // QPRINTENGINE_H diff --git a/src/printsupport/kernel/qprintengine_win.cpp b/src/printsupport/kernel/qprintengine_win.cpp index 97453f2e0e..c798ac0c7f 100644 --- a/src/printsupport/kernel/qprintengine_win.cpp +++ b/src/printsupport/kernel/qprintengine_win.cpp @@ -167,6 +167,16 @@ static int mapPaperSourceDevmode(QPrinter::PaperSource s) return sources[i].winSourceName ? sources[i].winSourceName : s; } +static inline uint qwcsnlen(const wchar_t *str, uint maxlen) +{ + uint length = 0; + if (str) { + while (length < maxlen && *str++) + length++; + } + return length; +} + QWin32PrintEngine::QWin32PrintEngine(QPrinter::PrinterMode mode) : QAlphaPaintEngine(*(new QWin32PrintEnginePrivate), PaintEngineFeatures(PrimitiveTransform @@ -1285,7 +1295,39 @@ void QWin32PrintEngine::setProperty(PrintEnginePropertyKey key, const QVariant & d->has_custom_paper_size = (QPrinter::PaperSize(value.toInt()) == QPrinter::Custom); d->doReinit(); break; - + case PPK_PaperName: + { + if (!d->devMode) + break; + DWORD size = DeviceCapabilities(reinterpret_cast<const wchar_t*>(d->name.utf16()), + NULL, DC_PAPERNAMES, NULL, NULL); + if ((int)size > 0) { + wchar_t *paperNames = new wchar_t[size*64]; + size = DeviceCapabilities(reinterpret_cast<const wchar_t*>(d->name.utf16()), + NULL, DC_PAPERNAMES, paperNames, NULL); + int paperPos = -1; + for (int i=0;i<(int)size;i++) { + wchar_t *copyOfPaper = paperNames + (i * 64); + if (value.toString() == QString::fromWCharArray(copyOfPaper, qwcsnlen(copyOfPaper, 64))) { + paperPos = i; + break; + } + } + delete [] paperNames; + size = DeviceCapabilities(reinterpret_cast<const wchar_t*>(d->name.utf16()), + NULL, DC_PAPERS, NULL, NULL); + if ((int)size > 0) { + wchar_t *papers = new wchar_t[size]; + size = DeviceCapabilities(reinterpret_cast<const wchar_t*>(d->name.utf16()), + NULL, DC_PAPERS, papers, NULL); + d->has_custom_paper_size = false; + d->devMode->dmPaperSize = papers[paperPos]; + d->doReinit(); + delete [] papers; + } + } + } + break; case PPK_PaperSource: { if (!d->devMode) @@ -1479,7 +1521,40 @@ QVariant QWin32PrintEngine::property(PrintEnginePropertyKey key) const value = QTransform(1/d->stretch_x, 0, 0, 1/d->stretch_y, 0, 0).mapRect(d->devPaperRect); } break; + case PPK_PaperName: + if (!d->devMode) { + value = QLatin1String("A4"); + } else { + DWORD size = DeviceCapabilities(reinterpret_cast<const wchar_t*>(d->name.utf16()), + NULL, DC_PAPERS, NULL, NULL); + int paperSizePos = -1; + if ((int)size > 0) { + wchar_t *papers = new wchar_t[size]; + size = DeviceCapabilities(reinterpret_cast<const wchar_t*>(d->name.utf16()), + NULL, DC_PAPERS, papers, NULL); + for (int i=0;i<(int)size;i++) { + if (papers[i] == d->devMode->dmPaperSize) { + paperSizePos = i; + break; + } + } + delete [] papers; + } + if (paperSizePos != -1) { + size = DeviceCapabilities(reinterpret_cast<const wchar_t*>(d->name.utf16()), + NULL, DC_PAPERNAMES, NULL, NULL); + if ((int)size > 0) { + wchar_t *papers = new wchar_t[size*64]; + size = DeviceCapabilities(reinterpret_cast<const wchar_t*>(d->name.utf16()), + NULL, DC_PAPERNAMES, papers, NULL); + wchar_t *copyOfPaper = papers + (paperSizePos * 64); + value = QString::fromWCharArray(copyOfPaper, qwcsnlen(copyOfPaper, 64)); + delete [] papers; + } + } + } + break; case PPK_PaperSource: if (!d->devMode) { value = QPrinter::Auto; @@ -1596,6 +1671,36 @@ QList<QPrinter::PaperSize> QWin32PrintEngine::supportedPaperSizes(const QPrinter return returnList; } +QList<QPair<QString, QSizeF> > QWin32PrintEngine::supportedSizesWithNames(const QPrinterInfo &printerInfo) +{ + QList<QPair<QString, QSizeF> > paperSizes; + if (printerInfo.isNull()) + return paperSizes; + DWORD size = DeviceCapabilities(reinterpret_cast<const wchar_t*>(printerInfo.printerName().utf16()), + NULL, DC_PAPERNAMES, NULL, NULL); + if ((int)size > 0) { + wchar_t *papers = new wchar_t[size*64]; + size = DeviceCapabilities(reinterpret_cast<const wchar_t*>(printerInfo.printerName().utf16()), + NULL, DC_PAPERNAMES, papers, NULL); + DWORD size2 = DeviceCapabilities(reinterpret_cast<const wchar_t*>(printerInfo.printerName().utf16()), + NULL, DC_PAPERSIZE, NULL, NULL); + if ((int)size2 > 0) { + POINT *points = new POINT[size2*sizeof(POINT)]; + + size2 = DeviceCapabilities(reinterpret_cast<const wchar_t*>(printerInfo.printerName().utf16()), + NULL, DC_PAPERSIZE, (wchar_t *)points, NULL); + for (int i=0;i<(int)size;i++) { + wchar_t *paper = papers + (i * 64); + QString str = QString::fromWCharArray(paper, qwcsnlen(paper, 64)); + paperSizes << qMakePair(str, QSizeF(points[i].x / 10, points[i].y / 10)); + } + delete [] points; + } + delete [] papers; + } + return paperSizes; +} + void QWin32PrintEngine::queryDefaultPrinter(QString &name, QString &program, QString &port) { /* Read the default printer name, driver and port with the intuitive function diff --git a/src/printsupport/kernel/qprintengine_win_p.h b/src/printsupport/kernel/qprintengine_win_p.h index 5197918710..93fe993088 100644 --- a/src/printsupport/kernel/qprintengine_win_p.h +++ b/src/printsupport/kernel/qprintengine_win_p.h @@ -53,6 +53,8 @@ // We mean it. // +#include <QtCore/qglobal.h> + #ifndef QT_NO_PRINTER #include <QtGui/qpaintengine.h> @@ -104,6 +106,7 @@ public: void releaseDC(HDC) const; static QList<QPrinter::PaperSize> supportedPaperSizes(const QPrinterInfo &printerInfo); + static QList<QPair<QString, QSizeF> > supportedSizesWithNames(const QPrinterInfo &printerInfo); static void queryDefaultPrinter(QString &name, QString &program, QString &port); private: diff --git a/src/printsupport/kernel/qprinter.cpp b/src/printsupport/kernel/qprinter.cpp index c1a2483f24..387101dc9b 100644 --- a/src/printsupport/kernel/qprinter.cpp +++ b/src/printsupport/kernel/qprinter.cpp @@ -1023,6 +1023,37 @@ QSizeF QPrinter::paperSize(Unit unit) const } /*! + \since 5.1 + + Sets the paper used by the printer to \a paperName. + + \sa paperName() +*/ + +void QPrinter::setPaperName(const QString &paperName) +{ + Q_D(QPrinter); + if (d->paintEngine->type() != QPaintEngine::Pdf) + ABORT_IF_ACTIVE("QPrinter::setPaperName"); + d->printEngine->setProperty(QPrintEngine::PPK_PaperName, paperName); + d->addToManualSetList(QPrintEngine::PPK_PaperName); +} + +/*! + \since 5.1 + + Returns the paper name of the paper set on the printer. + + The default value for this is driver-dependent. +*/ + +QString QPrinter::paperName() const +{ + Q_D(const QPrinter); + return d->printEngine->property(QPrintEngine::PPK_PaperName).toString(); +} + +/*! Sets the page order to \a pageOrder. The page order can be QPrinter::FirstPageFirst or @@ -1959,6 +1990,8 @@ QPrinter::PrintRange QPrinter::printRange() const \value PPK_PaperSources Specifies more than one QPrinter::PaperSource value. + \value PPK_PaperName A string specifying the name of the paper. + \value PPK_PaperSize Specifies a QPrinter::PaperSize value. \value PPK_PrinterName A string specifying the name of the printer. diff --git a/src/printsupport/kernel/qprinter.h b/src/printsupport/kernel/qprinter.h index 23ccb0c2d0..2528157532 100644 --- a/src/printsupport/kernel/qprinter.h +++ b/src/printsupport/kernel/qprinter.h @@ -47,8 +47,6 @@ #include <QtGui/qpagedpaintdevice.h> #include <QtPrintSupport/qtprintsupportglobal.h> -QT_BEGIN_HEADER - QT_BEGIN_NAMESPACE @@ -169,6 +167,9 @@ public: void setPaperSize(const QSizeF &paperSize, Unit unit); QSizeF paperSize(Unit unit) const; + void setPaperName(const QString &paperName); + QString paperName() const; + void setPageOrder(PageOrder); PageOrder pageOrder() const; @@ -267,6 +268,4 @@ private: QT_END_NAMESPACE -QT_END_HEADER - #endif // QPRINTER_H diff --git a/src/printsupport/kernel/qprinterinfo.cpp b/src/printsupport/kernel/qprinterinfo.cpp index 32ed4fa5af..f863b23e34 100644 --- a/src/printsupport/kernel/qprinterinfo.cpp +++ b/src/printsupport/kernel/qprinterinfo.cpp @@ -222,6 +222,25 @@ QList<QPrinter::PaperSize> QPrinterInfo::supportedPaperSizes() const return d->paperSizes; } +/*! + Returns a list of all the paper names supported by the driver with the + corresponding size in millimeters. + + Not all printer drivers support this query, so the list may be empty. + + \since 5.1 +*/ + +QList<QPair<QString, QSizeF> > QPrinterInfo::supportedSizesWithNames() const +{ + Q_D(const QPrinterInfo); + if (!isNull() && !d->hasPaperNames) { + d->paperNames = QPlatformPrinterSupportPlugin::get()->supportedSizesWithNames(*this); + d->hasPaperNames = true; + } + return d->paperNames; +} + QList<QPrinterInfo> QPrinterInfo::availablePrinters() { QPlatformPrinterSupport *ps = QPlatformPrinterSupportPlugin::get(); diff --git a/src/printsupport/kernel/qprinterinfo.h b/src/printsupport/kernel/qprinterinfo.h index 528423a635..0dc19c1da7 100644 --- a/src/printsupport/kernel/qprinterinfo.h +++ b/src/printsupport/kernel/qprinterinfo.h @@ -43,11 +43,9 @@ #define QPRINTERINFO_H #include <QtCore/QList> - +#include <QtCore/QPair> #include <QtPrintSupport/QPrinter> -QT_BEGIN_HEADER - QT_BEGIN_NAMESPACE @@ -73,6 +71,7 @@ public: bool isDefault() const; QList<QPrinter::PaperSize> supportedPaperSizes() const; + QList<QPair<QString, QSizeF> > supportedSizesWithNames() const; static QList<QPrinterInfo> availablePrinters(); static QPrinterInfo defaultPrinter(); @@ -91,6 +90,4 @@ private: QT_END_NAMESPACE -QT_END_HEADER - #endif // QPRINTERINFO_H diff --git a/src/printsupport/kernel/qprinterinfo_p.h b/src/printsupport/kernel/qprinterinfo_p.h index 97f4fd8a56..d4bb08f1f5 100644 --- a/src/printsupport/kernel/qprinterinfo_p.h +++ b/src/printsupport/kernel/qprinterinfo_p.h @@ -58,6 +58,7 @@ #ifndef QT_NO_PRINTER #include "QtCore/qlist.h" +#include "QtCore/qpair.h" QT_BEGIN_NAMESPACE @@ -65,7 +66,8 @@ class QPrinterInfoPrivate { public: QPrinterInfoPrivate(const QString& name = QString()) : - name(name), isDefault(false), index(-1), hasPaperSizes(false) + name(name), isDefault(false), index(-1), hasPaperSizes(false), + hasPaperNames(false) {} ~QPrinterInfoPrivate() {} @@ -81,6 +83,8 @@ public: mutable bool hasPaperSizes; mutable QList<QPrinter::PaperSize> paperSizes; + mutable bool hasPaperNames; + mutable QList<QPair<QString, QSizeF> > paperNames; }; diff --git a/src/printsupport/kernel/qtprintsupportglobal.h b/src/printsupport/kernel/qtprintsupportglobal.h index 1927252433..0fdb306e8d 100644 --- a/src/printsupport/kernel/qtprintsupportglobal.h +++ b/src/printsupport/kernel/qtprintsupportglobal.h @@ -44,8 +44,6 @@ #include <QtCore/qglobal.h> -QT_BEGIN_HEADER - QT_BEGIN_NAMESPACE #ifndef QT_STATIC @@ -60,6 +58,4 @@ QT_BEGIN_NAMESPACE QT_END_NAMESPACE -QT_END_HEADER - #endif // QTPRINTSUPPORTGLOBAL_H |