diff options
author | Andy Shaw <andy.shaw@digia.com> | 2013-01-01 01:33:42 +0100 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2013-02-11 17:50:56 +0100 |
commit | 83e6d1fe6006ad8e3cf37d5ca412aedae5aab9a4 (patch) | |
tree | 3d0bce6a62c444f4655292084530c9cfe1561f76 /src/printsupport | |
parent | 78d4c949a4556255303cb3fc2ce0d91900167f43 (diff) |
Add support for getting the paper names available for the printer
Task-number: QTBUG-27714
Change-Id: I9bc6f1188f262e43f581add058d7895e1b5bd9e3
Reviewed-by: Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@digia.com>
Diffstat (limited to 'src/printsupport')
-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/qplatformprintersupport.cpp | 5 | ||||
-rw-r--r-- | src/printsupport/kernel/qplatformprintersupport.h | 2 | ||||
-rw-r--r-- | src/printsupport/kernel/qprintengine_win.cpp | 32 | ||||
-rw-r--r-- | src/printsupport/kernel/qprintengine_win_p.h | 1 | ||||
-rw-r--r-- | src/printsupport/kernel/qprinterinfo.cpp | 19 | ||||
-rw-r--r-- | src/printsupport/kernel/qprinterinfo.h | 3 | ||||
-rw-r--r-- | src/printsupport/kernel/qprinterinfo_p.h | 6 |
9 files changed, 87 insertions, 3 deletions
diff --git a/src/printsupport/kernel/qcups.cpp b/src/printsupport/kernel/qcups.cpp index 30de3d301c..47447b21a1 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(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/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 5cb3b805fd..c4ffcffd1e 100644 --- a/src/printsupport/kernel/qplatformprintersupport.h +++ b/src/printsupport/kernel/qplatformprintersupport.h @@ -72,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); diff --git a/src/printsupport/kernel/qprintengine_win.cpp b/src/printsupport/kernel/qprintengine_win.cpp index 97453f2e0e..f5690c12f3 100644 --- a/src/printsupport/kernel/qprintengine_win.cpp +++ b/src/printsupport/kernel/qprintengine_win.cpp @@ -1596,6 +1596,38 @@ 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 != -1) { + 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 != -1) { + POINT *points = new POINT[size2*sizeof(POINT)]; + + size2 = DeviceCapabilities(reinterpret_cast<const wchar_t*>(printerInfo.printerName().utf16()), + NULL, DC_PAPERSIZE, (wchar_t *)points, NULL); + wchar_t copyOfPaper[65]; + for (int i=0;i<(int)size;i++) { + wcscpy_s(copyOfPaper, 64, papers + (i * 64)); + copyOfPaper[64] = '\0'; + QString str = QString::fromWCharArray(copyOfPaper); + 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..ffeebb0704 100644 --- a/src/printsupport/kernel/qprintengine_win_p.h +++ b/src/printsupport/kernel/qprintengine_win_p.h @@ -104,6 +104,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/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 b831898632..0dc19c1da7 100644 --- a/src/printsupport/kernel/qprinterinfo.h +++ b/src/printsupport/kernel/qprinterinfo.h @@ -43,7 +43,7 @@ #define QPRINTERINFO_H #include <QtCore/QList> - +#include <QtCore/QPair> #include <QtPrintSupport/QPrinter> QT_BEGIN_NAMESPACE @@ -71,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(); 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; }; |