summaryrefslogtreecommitdiffstats
path: root/src/printsupport
diff options
context:
space:
mode:
Diffstat (limited to 'src/printsupport')
-rw-r--r--src/printsupport/kernel/qplatformprintersupport.cpp89
-rw-r--r--src/printsupport/kernel/qplatformprintersupport.h20
-rw-r--r--src/printsupport/kernel/qprintengine_win.cpp43
-rw-r--r--src/printsupport/kernel/qprintengine_win_p.h8
-rw-r--r--src/printsupport/kernel/qprinterinfo.cpp255
-rw-r--r--src/printsupport/kernel/qprinterinfo.h27
-rw-r--r--src/printsupport/kernel/qprinterinfo_p.h23
7 files changed, 240 insertions, 225 deletions
diff --git a/src/printsupport/kernel/qplatformprintersupport.cpp b/src/printsupport/kernel/qplatformprintersupport.cpp
index cddf979928..1494155302 100644
--- a/src/printsupport/kernel/qplatformprintersupport.cpp
+++ b/src/printsupport/kernel/qplatformprintersupport.cpp
@@ -42,6 +42,7 @@
#include "qplatformprintersupport.h"
#include "qplatformprintdevice.h"
+#include <QtGui/qpagesize.h>
#include <QtPrintSupport/qprinterinfo.h>
#include <private/qprinterinfo_p.h>
@@ -105,90 +106,12 @@ QString QPlatformPrinterSupport::defaultPrintDeviceId() const
return QString();
}
-QList<QPrinter::PaperSize> QPlatformPrinterSupport::supportedPaperSizes(const QPrinterInfo &) const
+QPageSize QPlatformPrinterSupport::createPageSize(const QString &id, QSize size, const QString &localizedName)
{
- 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;
-}
-
-QPrinterInfo QPlatformPrinterSupport::defaultPrinter()
-{
- const QList<QPrinterInfo> printers = availablePrinters();
- foreach (const QPrinterInfo &printerInfo, printers) {
- if (printerInfo.isDefault())
- return printerInfo;
- }
- return QPrinterInfo();
-}
-
-QPrinterInfo QPlatformPrinterSupport::printerInfo(const QString &printerName)
-{
- const QList<QPrinterInfo> printers = availablePrinters();
- foreach (const QPrinterInfo &printerInfo, printers) {
- if (printerInfo.printerName() == printerName)
- return printerInfo;
- }
- return QPrinterInfo();
-}
-
-QString QPlatformPrinterSupport::printerOption(const QPrinterInfo &printer, const QString &key) const
-{
- Q_UNUSED(printer)
- Q_UNUSED(key)
- return QString();
-}
-
-PrinterOptions QPlatformPrinterSupport::printerOptions(const QPrinterInfo &printer) const
-{
- Q_UNUSED(printer)
- return PrinterOptions();
-}
-
-int QPlatformPrinterSupport::printerIndex(const QPrinterInfo &printer)
-{
- return printer.d_func()->index;
-}
-
-QPrinterInfo QPlatformPrinterSupport::createPrinterInfo(const QString &name, const QString &description,
- const QString &location, const QString &makeAndModel,
- bool isDefault, int index)
-{
- QPrinterInfo printer(name);
- printer.d_func()->description = description;
- printer.d_func()->location = location;
- printer.d_func()->makeAndModel = makeAndModel;
- printer.d_func()->isDefault = isDefault;
- printer.d_func()->index = index;
- return printer;
-}
-
-/*
- Converts QSizeF in millimeters to a predefined PaperSize (returns Custom if
- the size isn't a standard size)
-*/
-extern QPrinter::PaperSize qSizeFTopaperSize(const QSizeF &);
-QPrinter::PaperSize QPlatformPrinterSupport::convertQSizeFToPaperSize(const QSizeF &sizef)
-{
- return qSizeFTopaperSize(sizef);
-}
-
-/*
- Converts a predefined PaperSize to a QSizeF in millimeters (returns
- QSizeF(0.0, 0.0) if PaperSize is Custom)
-*/
-extern QSizeF qt_paperSizeToQSizeF(QPrinter::PaperSize size);
-QSizeF QPlatformPrinterSupport::convertPaperSizeToQSizeF(QPrinter::PaperSize paperSize)
-{
- return qt_paperSizeToQSizeF(paperSize);
+ Q_UNUSED(id)
+ Q_UNUSED(size)
+ Q_UNUSED(localizedName)
+ return QPageSize();
}
QT_END_NAMESPACE
diff --git a/src/printsupport/kernel/qplatformprintersupport.h b/src/printsupport/kernel/qplatformprintersupport.h
index 6a4ecc09c8..0efec08f64 100644
--- a/src/printsupport/kernel/qplatformprintersupport.h
+++ b/src/printsupport/kernel/qplatformprintersupport.h
@@ -62,6 +62,7 @@ QT_BEGIN_NAMESPACE
typedef QHash<QString, QString> PrinterOptions;
+class QPageSize;
class QPlatformPrintDevice;
class QPrintDevice;
class QPrintEngine;
@@ -80,26 +81,9 @@ public:
virtual QStringList availablePrintDeviceIds() const;
virtual QString defaultPrintDeviceId() const;
- 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);
-
- virtual QString printerOption(const QPrinterInfo &printer, const QString &key) const;
- virtual PrinterOptions printerOptions(const QPrinterInfo &printer) const;
-
- static QPrinter::PaperSize convertQSizeFToPaperSize(const QSizeF &sizef);
- static QSizeF convertPaperSizeToQSizeF(QPrinter::PaperSize paperSize);
-
protected:
- static int printerIndex(const QPrinterInfo &printer);
- static QPrinterInfo createPrinterInfo(const QString &name, const QString &description,
- const QString &location, const QString &makeAndModel,
- bool isDefault, int index);
static QPrintDevice createPrintDevice(QPlatformPrintDevice *device);
-
- QList<QPrinterInfo> m_printers;
+ static QPageSize createPageSize(const QString &id, QSize size, const QString &localizedName);
};
#endif // QT_NO_PRINTER
diff --git a/src/printsupport/kernel/qprintengine_win.cpp b/src/printsupport/kernel/qprintengine_win.cpp
index 02b5d824f4..c5f5057b14 100644
--- a/src/printsupport/kernel/qprintengine_win.cpp
+++ b/src/printsupport/kernel/qprintengine_win.cpp
@@ -1733,49 +1733,6 @@ void QWin32PrintEngine::releaseDC(HDC) const
}
-QList<QPrinter::PaperSize> QWin32PrintEngine::supportedPaperSizes(const QPrinterInfo &printerInfo)
-{
- QList<QPrinter::PaperSize> returnList;
-
- if (printerInfo.isNull())
- return returnList;
- const wchar_t *name = reinterpret_cast<const wchar_t*>(printerInfo.printerName().utf16());
- DWORD size = DeviceCapabilities(name, NULL, DC_PAPERS, NULL, NULL);
- if ((int)size != -1) {
- QScopedArrayPointer<wchar_t> papers(new wchar_t[size]);
- if (size != DeviceCapabilities(name, NULL, DC_PAPERS, papers.data(), NULL))
- return returnList;
- for (int c = 0; c < (int)size; ++c)
- returnList.append(mapDevmodePaperSize(papers[c]));
- }
- return returnList;
-}
-
-QList<QPair<QString, QSizeF> > QWin32PrintEngine::supportedSizesWithNames(const QPrinterInfo &printerInfo)
-{
- QList<QPair<QString, QSizeF> > paperSizes;
- if (printerInfo.isNull())
- return paperSizes;
- const wchar_t *name = reinterpret_cast<const wchar_t*>(printerInfo.printerName().utf16());
- DWORD size = DeviceCapabilities(name, NULL, DC_PAPERNAMES, NULL, NULL);
- if ((int)size > 0) {
- QScopedArrayPointer<wchar_t> papers(new wchar_t[size*64]);
- if (size != DeviceCapabilities(name, NULL, DC_PAPERNAMES, papers.data(), NULL))
- return paperSizes;
- if (size != DeviceCapabilities(name, NULL, DC_PAPERSIZE, NULL, NULL))
- return paperSizes;
- QScopedArrayPointer<POINT> points(new POINT[size*sizeof(POINT)]);
- if (size != DeviceCapabilities(name, NULL, DC_PAPERSIZE, (wchar_t *)points.data(), NULL))
- return paperSizes;
- for (int i = 0; i < (int)size; ++i) {
- wchar_t *paper = papers.data() + (i * 64);
- QString str = QString::fromWCharArray(paper, qwcsnlen(paper, 64));
- paperSizes << qMakePair(str, QSizeF(points[i].x / 10.0, points[i].y / 10.0));
- }
- }
- return paperSizes;
-}
-
void QWin32PrintEngine::queryDefaultPrinter(QString &name)
{
/* 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 d720561c2a..a749d9be42 100644
--- a/src/printsupport/kernel/qprintengine_win_p.h
+++ b/src/printsupport/kernel/qprintengine_win_p.h
@@ -105,14 +105,6 @@ public:
HDC getDC() const;
void releaseDC(HDC) const;
- static QList<QPrinter::PaperSize> supportedPaperSizes(const QPrinterInfo &printerInfo);
- static QList<QPair<QString, QSizeF> > supportedSizesWithNames(const QPrinterInfo &printerInfo);
-
- /* Used by print/page setup dialogs */
- void setGlobalDevMode(HGLOBAL globalDevNames, HGLOBAL globalDevMode);
- HGLOBAL *createGlobalDevNames();
- HGLOBAL globalDevMode();
-
static void queryDefaultPrinter(QString &name);
private:
diff --git a/src/printsupport/kernel/qprinterinfo.cpp b/src/printsupport/kernel/qprinterinfo.cpp
index e02617fe93..b1321bf57a 100644
--- a/src/printsupport/kernel/qprinterinfo.cpp
+++ b/src/printsupport/kernel/qprinterinfo.cpp
@@ -27,6 +27,7 @@
#include "qprinterinfo.h"
#include "qprinterinfo_p.h"
+#include "qprintdevice_p.h"
#ifndef QT_NO_PRINTER
@@ -47,6 +48,19 @@ public:
}
};
+QPrinterInfoPrivate::QPrinterInfoPrivate(const QString &id)
+{
+ if (!id.isEmpty()) {
+ QPlatformPrinterSupport *ps = QPlatformPrinterSupportPlugin::get();
+ if (ps)
+ m_printDevice = ps->createPrintDevice(id);
+ }
+}
+
+QPrinterInfoPrivate::~QPrinterInfoPrivate()
+{
+}
+
/*!
\class QPrinterInfo
@@ -65,28 +79,6 @@ public:
*/
/*!
- \fn QList<QPrinterInfo> QPrinterInfo::availablePrinters()
-
- Returns a list of available printers on the system.
-*/
-
-/*!
- \fn QPrinterInfo QPrinterInfo::defaultPrinter()
-
- Returns the default printer on the system.
-
- The return value should be checked using isNull() before being
- used, in case there is no default printer.
-
- On some systems it is possible for there to be available printers
- but none of them set to be the default printer.
-
- \sa isNull()
- \sa isDefault()
- \sa availablePrinters()
-*/
-
-/*!
Constructs an empty QPrinterInfo object.
\sa isNull()
@@ -112,7 +104,7 @@ QPrinterInfo::QPrinterInfo(const QPrinter &printer)
{
QPlatformPrinterSupport *ps = QPlatformPrinterSupportPlugin::get();
if (ps) {
- QPrinterInfo pi = ps->printerInfo(printer.printerName());
+ QPrinterInfo pi(printer.printerName());
if (pi.d_ptr.data() == shared_null)
d_ptr.reset(shared_null);
else
@@ -160,7 +152,7 @@ QPrinterInfo &QPrinterInfo::operator=(const QPrinterInfo &other)
QString QPrinterInfo::printerName() const
{
const Q_D(QPrinterInfo);
- return d->name;
+ return d->m_printDevice.id();
}
/*!
@@ -172,7 +164,7 @@ QString QPrinterInfo::printerName() const
QString QPrinterInfo::description() const
{
const Q_D(QPrinterInfo);
- return d->description;
+ return d->m_printDevice.name();
}
/*!
@@ -183,7 +175,7 @@ QString QPrinterInfo::description() const
QString QPrinterInfo::location() const
{
const Q_D(QPrinterInfo);
- return d->location;
+ return d->m_printDevice.location();
}
/*!
@@ -194,7 +186,7 @@ QString QPrinterInfo::location() const
QString QPrinterInfo::makeAndModel() const
{
const Q_D(QPrinterInfo);
- return d->makeAndModel;
+ return d->m_printDevice.makeAndModel();
}
/*!
@@ -206,23 +198,114 @@ QString QPrinterInfo::makeAndModel() const
bool QPrinterInfo::isNull() const
{
Q_D(const QPrinterInfo);
- return d == shared_null || d->name.isEmpty();
+ return d == shared_null || !d->m_printDevice.isValid();
}
/*!
- Returns whether this printer is the default printer.
+ Returns whether this printer is currently the default printer.
*/
bool QPrinterInfo::isDefault() const
{
Q_D(const QPrinterInfo);
- return d->isDefault;
+ return d->m_printDevice.isDefault();
+}
+
+/*!
+ Returns whether this printer is a remote network printer.
+
+ \since 5.3
+*/
+bool QPrinterInfo::isRemote() const
+{
+ Q_D(const QPrinterInfo);
+ return d->m_printDevice.isRemote();
+}
+
+/*!
+ Returns the current state of this printer.
+
+ This state may not always be accurate, depending on the platform, printer
+ driver, or printer itself.
+
+ \since 5.3
+*/
+QPrinter::PrinterState QPrinterInfo::state() const
+{
+ Q_D(const QPrinterInfo);
+ return QPrinter::PrinterState(d->m_printDevice.state());
+}
+
+/*!
+ Returns a list of Page Sizes supported by this printer.
+
+ \since 5.3
+*/
+
+QList<QPageSize> QPrinterInfo::supportedPageSizes() const
+{
+ Q_D(const QPrinterInfo);
+ return d->m_printDevice.supportedPageSizes();
+}
+
+/*!
+ Returns the current default Page Size for this printer.
+
+ \since 5.3
+*/
+
+QPageSize QPrinterInfo::defaultPageSize() const
+{
+ Q_D(const QPrinterInfo);
+ return d->m_printDevice.defaultPageSize();
+}
+
+/*!
+ Returns whether this printer supports custom page sizes.
+
+ \since 5.3
+*/
+
+bool QPrinterInfo::supportsCustomPageSizes() const
+{
+ Q_D(const QPrinterInfo);
+ return d->m_printDevice.supportsCustomPageSizes();
}
/*!
+ Returns the minimum physical page size supported by this printer.
+
+ \sa maximumPhysicalPageSize()
+
+ \since 5.3
+*/
+
+QPageSize QPrinterInfo::minimumPhysicalPageSize() const
+{
+ Q_D(const QPrinterInfo);
+ return QPageSize(d->m_printDevice.minimumPhysicalPageSize(), QString(), QPageSize::ExactMatch);
+}
+
+/*!
+ Returns the maximum physical page size supported by this printer.
+
+ \sa minimumPhysicalPageSize()
+
+ \since 5.3
+*/
+
+QPageSize QPrinterInfo::maximumPhysicalPageSize() const
+{
+ Q_D(const QPrinterInfo);
+ return QPageSize(d->m_printDevice.maximumPhysicalPageSize(), QString(), QPageSize::ExactMatch);
+}
+
+#if QT_DEPRECATED_SINCE(5,3)
+/*!
+ \obsolete Use supportedPageSizes() instead.
+
Returns a list of supported paper sizes by the printer.
Not all printer drivers support this query, so the list may be empty.
- On Mac OS X 10.3, this function always returns an empty list.
\since 4.4
*/
@@ -230,14 +313,15 @@ bool QPrinterInfo::isDefault() const
QList<QPrinter::PaperSize> QPrinterInfo::supportedPaperSizes() const
{
Q_D(const QPrinterInfo);
- if (!isNull() && !d->hasPaperSizes) {
- d->paperSizes = QPlatformPrinterSupportPlugin::get()->supportedPaperSizes(*this);
- d->hasPaperSizes = true;
- }
- return d->paperSizes;
+ QList<QPrinter::PaperSize> list;
+ foreach (const QPageSize &pageSize, d->m_printDevice.supportedPageSizes())
+ list.append(QPrinter::PaperSize(pageSize.id()));
+ return list;
}
/*!
+ \obsolete Use supportedPageSizes() instead.
+
Returns a list of all the paper names supported by the driver with the
corresponding size in millimeters.
@@ -249,27 +333,99 @@ QList<QPrinter::PaperSize> QPrinterInfo::supportedPaperSizes() const
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<QPair<QString, QSizeF> > list;
+ foreach (const QPageSize &pageSize, d->m_printDevice.supportedPageSizes())
+ list.append(qMakePair(pageSize.name(), pageSize.size(QPageSize::Millimeter)));
+ return list;
+}
+#endif // QT_DEPRECATED_SINCE(5,3)
+
+/*!
+ Returns a list of resolutions supported by this printer.
+
+ \since 5.3
+*/
+
+QList<int> QPrinterInfo::supportedResolutions() const
+{
+ Q_D(const QPrinterInfo);
+ return d->m_printDevice.supportedResolutions();
}
+/*!
+ Returns a list of all the available Printer Names on this system.
+
+ It is recommended to use this instead of availablePrinters() as
+ it will be faster on most systems.
+
+ Note that the list may become outdated if changes are made on the local
+ system or remote print server. Only instantiate required QPrinterInfo
+ instances when needed, and always check for validity before calling.
+
+ \since 5.3
+*/
+QStringList QPrinterInfo::availablePrinterNames()
+{
+ QPlatformPrinterSupport *ps = QPlatformPrinterSupportPlugin::get();
+ if (ps)
+ return ps->availablePrintDeviceIds();
+ return QStringList();
+}
+
+/*!
+ Returns a list of QPrinterInfo objects for all the available printers
+ on this system.
+
+ It is NOT recommended to use this as creating each printer instance may
+ take a long time, especially if there are remote networked printers, and
+ retained instances may become outdated if changes are made on the local
+ system or remote print server. Use availablePrinterNames() instead and
+ only instantiate printer instances as you need them.
+*/
QList<QPrinterInfo> QPrinterInfo::availablePrinters()
{
+ QList<QPrinterInfo> list;
+ QPlatformPrinterSupport *ps = QPlatformPrinterSupportPlugin::get();
+ if (ps) {
+ foreach (const QString &id, ps->availablePrintDeviceIds())
+ list.append(QPrinterInfo(id));
+ }
+ return list;
+}
+
+/*!
+ Returns the current default printer name.
+
+ \since 5.3
+*/
+QString QPrinterInfo::defaultPrinterName()
+{
QPlatformPrinterSupport *ps = QPlatformPrinterSupportPlugin::get();
- if (!ps)
- return QList<QPrinterInfo>();
- return ps->availablePrinters();
+ if (ps)
+ return ps->defaultPrintDeviceId();
+ return QString();
}
+/*!
+ Returns the default printer on the system.
+
+ The return value should be checked using isNull() before being
+ used, in case there is no default printer.
+
+ On some systems it is possible for there to be available printers
+ but none of them set to be the default printer.
+
+ \sa isNull()
+ \sa isDefault()
+ \sa availablePrinters()
+*/
+
QPrinterInfo QPrinterInfo::defaultPrinter()
{
QPlatformPrinterSupport *ps = QPlatformPrinterSupportPlugin::get();
- if (!ps)
- return QPrinterInfo();
- return ps->defaultPrinter();
+ if (ps)
+ return QPrinterInfo(ps->defaultPrintDeviceId());
+ return QPrinterInfo();
}
/*!
@@ -283,10 +439,7 @@ QPrinterInfo QPrinterInfo::defaultPrinter()
*/
QPrinterInfo QPrinterInfo::printerInfo(const QString &printerName)
{
- QPlatformPrinterSupport *ps = QPlatformPrinterSupportPlugin::get();
- if (!ps)
- return QPrinterInfo();
- return ps->printerInfo(printerName);
+ return QPrinterInfo(printerName);
}
QT_END_NAMESPACE
diff --git a/src/printsupport/kernel/qprinterinfo.h b/src/printsupport/kernel/qprinterinfo.h
index 0dc19c1da7..73ec48dfe7 100644
--- a/src/printsupport/kernel/qprinterinfo.h
+++ b/src/printsupport/kernel/qprinterinfo.h
@@ -42,9 +42,11 @@
#ifndef QPRINTERINFO_H
#define QPRINTERINFO_H
+#include <QtPrintSupport/qprinter.h>
+
#include <QtCore/QList>
#include <QtCore/QPair>
-#include <QtPrintSupport/QPrinter>
+#include <QtGui/qpagesize.h>
QT_BEGIN_NAMESPACE
@@ -69,12 +71,31 @@ public:
bool isNull() const;
bool isDefault() const;
+ bool isRemote() const;
+
+ QPrinter::PrinterState state() const;
+
+ QList<QPageSize> supportedPageSizes() const;
+ QPageSize defaultPageSize() const;
+
+ bool supportsCustomPageSizes() const;
- QList<QPrinter::PaperSize> supportedPaperSizes() const;
- QList<QPair<QString, QSizeF> > supportedSizesWithNames() const;
+ QPageSize minimumPhysicalPageSize() const;
+ QPageSize maximumPhysicalPageSize() const;
+#if QT_DEPRECATED_SINCE(5,3)
+ QT_DEPRECATED QList<QPrinter::PaperSize> supportedPaperSizes() const;
+ QT_DEPRECATED QList<QPair<QString, QSizeF> > supportedSizesWithNames() const;
+#endif // QT_DEPRECATED_SINCE(5,3)
+
+ QList<int> supportedResolutions() const;
+
+ static QStringList availablePrinterNames();
static QList<QPrinterInfo> availablePrinters();
+
+ static QString defaultPrinterName();
static QPrinterInfo defaultPrinter();
+
static QPrinterInfo printerInfo(const QString &printerName);
private:
diff --git a/src/printsupport/kernel/qprinterinfo_p.h b/src/printsupport/kernel/qprinterinfo_p.h
index 6ae64b5653..7083356e1c 100644
--- a/src/printsupport/kernel/qprinterinfo_p.h
+++ b/src/printsupport/kernel/qprinterinfo_p.h
@@ -57,32 +57,17 @@
#ifndef QT_NO_PRINTER
-#include "QtCore/qlist.h"
-#include "QtCore/qpair.h"
+#include "qprintdevice_p.h"
QT_BEGIN_NAMESPACE
class QPrinterInfoPrivate
{
public:
- QPrinterInfoPrivate(const QString& name = QString()) :
- name(name), isDefault(false), index(-1), hasPaperSizes(false),
- hasPaperNames(false)
- {}
- ~QPrinterInfoPrivate()
- {}
+ QPrinterInfoPrivate(const QString& id = QString());
+ ~QPrinterInfoPrivate();
- QString name;
- QString description;
- QString location;
- QString makeAndModel;
- bool isDefault;
- int index; // Internal printer plugin use only
-
- mutable bool hasPaperSizes;
- mutable QList<QPrinter::PaperSize> paperSizes;
- mutable bool hasPaperNames;
- mutable QList<QPair<QString, QSizeF> > paperNames;
+ QPrintDevice m_printDevice;
};
QT_END_NAMESPACE