From f50d46e5eb257528828998a465634d9044cdd17f Mon Sep 17 00:00:00 2001 From: John Layt Date: Tue, 10 Dec 2013 18:42:44 +0100 Subject: QPlatformPrintDevice - New QPA base class Add a new QPA class to abstract Print Devices. Each platform instance will encapsulate all required details about a print device instead of the code being distributed throughout the print engine and print plugin. Change-Id: I7f6a537ad55a6e7f599d83f461b1e2ee62b15094 Reviewed-by: Lars Knoll --- src/gui/painting/qpagesize.h | 1 + src/printsupport/kernel/kernel.pri | 5 + src/printsupport/kernel/qplatformprintdevice.cpp | 389 +++++++++++++++++++++ src/printsupport/kernel/qplatformprintdevice.h | 180 ++++++++++ .../kernel/qplatformprintersupport.cpp | 28 ++ src/printsupport/kernel/qplatformprintersupport.h | 10 + src/printsupport/kernel/qprint_p.h | 304 ++++++++++++++++ src/printsupport/kernel/qprintdevice.cpp | 251 +++++++++++++ src/printsupport/kernel/qprintdevice_p.h | 145 ++++++++ tests/auto/printsupport/kernel/kernel.pro | 1 + .../printsupport/kernel/qprintdevice/.gitignore | 1 + .../kernel/qprintdevice/qprintdevice.pro | 9 + .../kernel/qprintdevice/tst_qprintdevice.cpp | 109 ++++++ tests/manual/qprintdevice_dump/main.cpp | 181 ++++++++++ .../manual/qprintdevice_dump/qprintdevice_dump.pro | 6 + 15 files changed, 1620 insertions(+) create mode 100644 src/printsupport/kernel/qplatformprintdevice.cpp create mode 100644 src/printsupport/kernel/qplatformprintdevice.h create mode 100644 src/printsupport/kernel/qprint_p.h create mode 100644 src/printsupport/kernel/qprintdevice.cpp create mode 100644 src/printsupport/kernel/qprintdevice_p.h create mode 100644 tests/auto/printsupport/kernel/qprintdevice/.gitignore create mode 100644 tests/auto/printsupport/kernel/qprintdevice/qprintdevice.pro create mode 100644 tests/auto/printsupport/kernel/qprintdevice/tst_qprintdevice.cpp create mode 100644 tests/manual/qprintdevice_dump/main.cpp create mode 100644 tests/manual/qprintdevice_dump/qprintdevice_dump.pro diff --git a/src/gui/painting/qpagesize.h b/src/gui/painting/qpagesize.h index af9181355b..c8a472747d 100644 --- a/src/gui/painting/qpagesize.h +++ b/src/gui/painting/qpagesize.h @@ -289,6 +289,7 @@ public: private: friend class QPageSizePrivate; + friend class QPlatformPrintDevice; QPageSize(const QString &key, const QSize &pointSize, const QString &name); QPageSize(int windowsId, const QSize &pointSize, const QString &name); QPageSize(QPageSizePrivate &dd); diff --git a/src/printsupport/kernel/kernel.pri b/src/printsupport/kernel/kernel.pri index 67fcc8597c..cbbb14342a 100644 --- a/src/printsupport/kernel/kernel.pri +++ b/src/printsupport/kernel/kernel.pri @@ -1,11 +1,14 @@ HEADERS += \ $$PWD/qpaintengine_alpha_p.h \ $$PWD/qpaintengine_preview_p.h \ + $$PWD/qprint_p.h \ + $$PWD/qprintdevice_p.h \ $$PWD/qprintengine.h \ $$PWD/qprinter.h \ $$PWD/qprinter_p.h \ $$PWD/qprinterinfo.h \ $$PWD/qprinterinfo_p.h \ + $$PWD/qplatformprintdevice.h \ $$PWD/qplatformprintplugin.h \ $$PWD/qplatformprintersupport.h \ $$PWD/qtprintsupportglobal.h @@ -13,9 +16,11 @@ HEADERS += \ SOURCES += \ $$PWD/qpaintengine_alpha.cpp \ $$PWD/qpaintengine_preview.cpp \ + $$PWD/qprintdevice.cpp \ $$PWD/qprintengine_pdf.cpp \ $$PWD/qprinter.cpp \ $$PWD/qprinterinfo.cpp \ + $$PWD/qplatformprintdevice.cpp \ $$PWD/qplatformprintplugin.cpp \ $$PWD/qplatformprintersupport.cpp diff --git a/src/printsupport/kernel/qplatformprintdevice.cpp b/src/printsupport/kernel/qplatformprintdevice.cpp new file mode 100644 index 0000000000..df0ef3111b --- /dev/null +++ b/src/printsupport/kernel/qplatformprintdevice.cpp @@ -0,0 +1,389 @@ +/**************************************************************************** +** +** Copyright (C) 2014 John Layt +** Contact: http://www.qt-project.org/legal +** +** This file is part of the QtPrintSupport module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qplatformprintdevice.h" + +#include "qprintdevice_p.h" +#include "qprintdialog.h" + +#include + +QT_BEGIN_NAMESPACE + +QPlatformPrintDevice::QPlatformPrintDevice() + : m_isRemote(false), + m_supportsMultipleCopies(false), + m_supportsCollateCopies(false), + m_havePageSizes(false), + m_supportsCustomPageSizes(false), + m_haveResolutions(false), + m_haveInputSlots(false), + m_haveOutputBins(false), + m_haveDuplexModes(false), + m_haveColorModes(false) +{ +} + +QPlatformPrintDevice::QPlatformPrintDevice(const QString &id) + : m_id(id), + m_isRemote(false), + m_supportsMultipleCopies(false), + m_supportsCollateCopies(false), + m_havePageSizes(false), + m_supportsCustomPageSizes(false), + m_haveResolutions(false), + m_haveInputSlots(false), + m_haveOutputBins(false), + m_haveDuplexModes(false), + m_haveColorModes(false) +{ +} + +QPlatformPrintDevice::~QPlatformPrintDevice() +{ +} + +bool QPlatformPrintDevice::operator==(const QPlatformPrintDevice &other) const +{ + return m_id == other.m_id; +} + +QString QPlatformPrintDevice::id() const +{ + return m_id; +} + +QString QPlatformPrintDevice::name() const +{ + return m_name; +} + +QString QPlatformPrintDevice::location() const +{ + return m_location; +} + +QString QPlatformPrintDevice::makeAndModel() const +{ + return m_makeAndModel; +} + +bool QPlatformPrintDevice::isValid() const +{ + return false; +} + +bool QPlatformPrintDevice::isDefault() const +{ + return false; +} + +bool QPlatformPrintDevice::isRemote() const +{ + return m_isRemote; +} + +bool QPlatformPrintDevice::isValidPageLayout(const QPageLayout &layout, int resolution) const +{ + // Check the page size is supported + if (!supportedPageSize(layout.pageSize()).isValid()) + return false; + + // Check the margins are valid + QMarginsF pointMargins = layout.margins(QPageLayout::Point); + QMarginsF printMargins = printableMargins(layout.pageSize(), layout.orientation(), resolution); + return pointMargins.left() >= printMargins.left() + && pointMargins.right() >= printMargins.right() + && pointMargins.top() >= printMargins.top() + && pointMargins.bottom() >= printMargins.bottom(); +} + +QPrint::DeviceState QPlatformPrintDevice::state() const +{ + return QPrint::Error; +} + +bool QPlatformPrintDevice::supportsMultipleCopies() const +{ + return m_supportsMultipleCopies; +} + +bool QPlatformPrintDevice::supportsCollateCopies() const +{ + return m_supportsCollateCopies; +} + +void QPlatformPrintDevice::loadPageSizes() const +{ +} + +QPageSize QPlatformPrintDevice::defaultPageSize() const +{ + return QPageSize(); +} + +QList QPlatformPrintDevice::supportedPageSizes() const +{ + if (!m_havePageSizes) + loadPageSizes(); + return m_pageSizes.toList(); +} + +QPageSize QPlatformPrintDevice::supportedPageSize(const QPageSize &pageSize) const +{ + if (!pageSize.isValid()) + return QPageSize(); + + if (!m_havePageSizes) + loadPageSizes(); + + // First try match on name and id for case where printer defines same size twice with different names + // e.g. Windows defines DMPAPER_11X17 and DMPAPER_TABLOID with names "11x17" and "Tabloid", but both + // map to QPageSize::Tabloid / PPD Key "Tabloid" / ANSI B Tabloid + if (pageSize.id() != QPageSize::Custom) { + foreach (const QPageSize &ps, m_pageSizes) { + if (ps.id() == pageSize.id() && ps.name() == pageSize.name()) + return ps; + } + } + + // Next try match on id only if not custom + if (pageSize.id() != QPageSize::Custom) { + foreach (const QPageSize &ps, m_pageSizes) { + if (ps.id() == pageSize.id()) + return ps; + } + } + + // Next try a match on size, in case it's a custom with a different name + return supportedPageSizeMatch(pageSize); +} + +QPageSize QPlatformPrintDevice::supportedPageSize(QPageSize::PageSizeId pageSizeId) const +{ + if (!m_havePageSizes) + loadPageSizes(); + + foreach (const QPageSize &ps, m_pageSizes) { + if (ps.id() == pageSizeId) + return ps; + } + + // If no supported page size found, try use a custom size instead if supported + return supportedPageSizeMatch(QPageSize(pageSizeId)); +} + +QPageSize QPlatformPrintDevice::supportedPageSize(const QString &pageName) const +{ + if (!m_havePageSizes) + loadPageSizes(); + + foreach (const QPageSize &ps, m_pageSizes) { + if (ps.name() == pageName) + return ps; + } + + return QPageSize(); +} + +QPageSize QPlatformPrintDevice::supportedPageSize(const QSize &sizePoints) const +{ + if (!m_havePageSizes) + loadPageSizes(); + + // Try to find a supported page size based on fuzzy-matched point size + return supportedPageSizeMatch(QPageSize(sizePoints)); +} + +QPageSize QPlatformPrintDevice::supportedPageSize(const QSizeF &size, QPageSize::Unit units) const +{ + if (!m_havePageSizes) + loadPageSizes(); + + // Try to find a supported page size based on fuzzy-matched unit size + return supportedPageSizeMatch(QPageSize(size, units)); +} + +QPageSize QPlatformPrintDevice::supportedPageSizeMatch(const QPageSize &pageSize) const +{ + // Try to find a supported page size based on point size + foreach (const QPageSize &ps, m_pageSizes) { + if (ps.sizePoints() == pageSize.sizePoints()) + return ps; + } + return QPageSize(); +} + +bool QPlatformPrintDevice::supportsCustomPageSizes() const +{ + return m_supportsCustomPageSizes; +} + +QSize QPlatformPrintDevice::minimumPhysicalPageSize() const +{ + return m_minimumPhysicalPageSize; +} + +QSize QPlatformPrintDevice::maximumPhysicalPageSize() const +{ + return m_maximumPhysicalPageSize; +} + +QMarginsF QPlatformPrintDevice::printableMargins(const QPageSize &pageSize, + QPageLayout::Orientation orientation, + int resolution) const +{ + Q_UNUSED(pageSize) + Q_UNUSED(orientation) + Q_UNUSED(resolution) + return QMarginsF(0, 0, 0, 0); +} + +void QPlatformPrintDevice::loadResolutions() const +{ +} + +int QPlatformPrintDevice::defaultResolution() const +{ + return 0; +} + +QList QPlatformPrintDevice::supportedResolutions() const +{ + if (!m_haveResolutions) + loadResolutions(); + return m_resolutions.toList(); +} + +void QPlatformPrintDevice::loadInputSlots() const +{ +} + +QPrint::InputSlot QPlatformPrintDevice::defaultInputSlot() const +{ + QPrint::InputSlot input; + input.key = QByteArrayLiteral("Auto"); + input.name = QPrintDialog::tr("Automatic"); + input.id = QPrint::Auto; + return input; +} + +QList QPlatformPrintDevice::supportedInputSlots() const +{ + if (!m_haveInputSlots) + loadInputSlots(); + return m_inputSlots.toList(); +} + +void QPlatformPrintDevice::loadOutputBins() const +{ +} + +QPrint::OutputBin QPlatformPrintDevice::defaultOutputBin() const +{ + QPrint::OutputBin output; + output.key = QByteArrayLiteral("Auto"); + output.name = QPrintDialog::tr("Automatic"); + output.id = QPrint::AutoOutputBin; + return output; +} + +QList QPlatformPrintDevice::supportedOutputBins() const +{ + if (!m_haveOutputBins) + loadOutputBins(); + return m_outputBins.toList(); +} + +void QPlatformPrintDevice::loadDuplexModes() const +{ +} + +QPrint::DuplexMode QPlatformPrintDevice::defaultDuplexMode() const +{ + return QPrint::DuplexNone; +} + +QList QPlatformPrintDevice::supportedDuplexModes() const +{ + if (!m_haveDuplexModes) + loadDuplexModes(); + return m_duplexModes.toList(); +} + +void QPlatformPrintDevice::loadColorModes() const +{ +} + +QPrint::ColorMode QPlatformPrintDevice::defaultColorMode() const +{ + return QPrint::GrayScale; +} + +QList QPlatformPrintDevice::supportedColorModes() const +{ + if (!m_haveColorModes) + loadColorModes(); + return m_colorModes.toList(); +} + +void QPlatformPrintDevice::loadMimeTypes() const +{ +} + +QList QPlatformPrintDevice::supportedMimeTypes() const +{ + if (!m_haveMimeTypes) + loadMimeTypes(); + return m_mimeTypes.toList(); +} + +QPageSize QPlatformPrintDevice::createPageSize(const QString &key, const QSize &size, const QString &localizedName) +{ + return QPageSize(key, size, localizedName); +} + +QPageSize QPlatformPrintDevice::createPageSize(int windowsId, const QSize &size, const QString &localizedName) +{ + return QPageSize(windowsId, size, localizedName); +} + +QT_END_NAMESPACE diff --git a/src/printsupport/kernel/qplatformprintdevice.h b/src/printsupport/kernel/qplatformprintdevice.h new file mode 100644 index 0000000000..04d614085f --- /dev/null +++ b/src/printsupport/kernel/qplatformprintdevice.h @@ -0,0 +1,180 @@ +/**************************************************************************** +** +** Copyright (C) 2014 John Layt +** Contact: http://www.qt-project.org/legal +** +** This file is part of the QtPrintSupport module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QPLATFORMPRINTDEVICE_H +#define QPLATFORMPRINTDEVICE_H + +// +// W A R N I N G +// ------------- +// +// This file is not part of the Qt API. It exists for the convenience +// of internal files. This header file may change from version to version +// without notice, or even be removed. +// +// We mean it. +// + +#include "qplatformprintdevice.h" + +#include + +#include +#include +#include + +QT_BEGIN_NAMESPACE + +class Q_PRINTSUPPORT_EXPORT QPlatformPrintDevice : public QSharedData +{ +public: + QPlatformPrintDevice(); + explicit QPlatformPrintDevice(const QString &id); + virtual ~QPlatformPrintDevice(); + + QPlatformPrintDevice *clone(); + + bool operator==(const QPlatformPrintDevice &other) const; + + virtual QString id() const; + virtual QString name() const; + virtual QString location() const; + virtual QString makeAndModel() const; + + virtual bool isValid() const; + virtual bool isDefault() const; + virtual bool isRemote() const; + + virtual QPrint::DeviceState state() const; + + virtual bool isValidPageLayout(const QPageLayout &layout, int resolution) const; + + virtual bool supportsMultipleCopies() const; + virtual bool supportsCollateCopies() const; + + virtual QPageSize defaultPageSize() const; + virtual QList supportedPageSizes() const; + + virtual QPageSize supportedPageSize(const QPageSize &pageSize) const; + virtual QPageSize supportedPageSize(QPageSize::PageSizeId pageSizeId) const; + virtual QPageSize supportedPageSize(const QString &pageName) const; + virtual QPageSize supportedPageSize(const QSize &pointSize) const; + virtual QPageSize supportedPageSize(const QSizeF &size, QPageSize::Unit units) const; + + virtual bool supportsCustomPageSizes() const; + + virtual QSize minimumPhysicalPageSize() const; + virtual QSize maximumPhysicalPageSize() const; + + virtual QMarginsF printableMargins(const QPageSize &pageSize, QPageLayout::Orientation orientation, + int resolution) const; + + virtual int defaultResolution() const; + virtual QList supportedResolutions() const; + + virtual QPrint::InputSlot defaultInputSlot() const; + virtual QList supportedInputSlots() const; + + virtual QPrint::OutputBin defaultOutputBin() const; + virtual QList supportedOutputBins() const; + + virtual QPrint::DuplexMode defaultDuplexMode() const; + virtual QList supportedDuplexModes() const; + + virtual QPrint::ColorMode defaultColorMode() const; + virtual QList supportedColorModes() const; + + virtual QList supportedMimeTypes() const; + + static QPageSize createPageSize(const QString &key, const QSize &size, const QString &localizedName); + static QPageSize createPageSize(int windowsId, const QSize &size, const QString &localizedName); + +protected: + virtual void loadPageSizes() const; + virtual void loadResolutions() const; + virtual void loadInputSlots() const; + virtual void loadOutputBins() const; + virtual void loadDuplexModes() const; + virtual void loadColorModes() const; + virtual void loadMimeTypes() const; + + QPageSize supportedPageSizeMatch(const QPageSize &pageSize) const; + + QString m_id; + QString m_name; + QString m_location; + QString m_makeAndModel; + + bool m_isRemote; + + bool m_supportsMultipleCopies; + bool m_supportsCollateCopies; + + mutable bool m_havePageSizes; + mutable QVector m_pageSizes; + + bool m_supportsCustomPageSizes; + + QSize m_minimumPhysicalPageSize; + QSize m_maximumPhysicalPageSize; + + mutable bool m_haveResolutions; + mutable QVector m_resolutions; + + mutable bool m_haveInputSlots; + mutable QVector m_inputSlots; + + mutable bool m_haveOutputBins; + mutable QVector m_outputBins; + + mutable bool m_haveDuplexModes; + mutable QVector m_duplexModes; + + mutable bool m_haveColorModes; + mutable QVector m_colorModes; + + mutable bool m_haveMimeTypes; + mutable QVector m_mimeTypes; +}; + +QT_END_NAMESPACE + +#endif // QPLATFORMPRINTDEVICE_H diff --git a/src/printsupport/kernel/qplatformprintersupport.cpp b/src/printsupport/kernel/qplatformprintersupport.cpp index 4d80e55ab6..cddf979928 100644 --- a/src/printsupport/kernel/qplatformprintersupport.cpp +++ b/src/printsupport/kernel/qplatformprintersupport.cpp @@ -40,10 +40,12 @@ ****************************************************************************/ #include "qplatformprintersupport.h" +#include "qplatformprintdevice.h" #include #include +#include #ifndef QT_NO_PRINTER @@ -77,6 +79,32 @@ QPaintEngine *QPlatformPrinterSupport::createPaintEngine(QPrintEngine *, QPrinte return 0; } +QPrintDevice QPlatformPrinterSupport::createPrintDevice(QPlatformPrintDevice *device) +{ + return QPrintDevice(device); +} + +QPrintDevice QPlatformPrinterSupport::createPrintDevice(const QString &id) +{ + Q_UNUSED(id) + return QPrintDevice(); +} + +QPrintDevice QPlatformPrinterSupport::createDefaultPrintDevice() +{ + return createPrintDevice(defaultPrintDeviceId()); +} + +QStringList QPlatformPrinterSupport::availablePrintDeviceIds() const +{ + return QStringList(); +} + +QString QPlatformPrinterSupport::defaultPrintDeviceId() const +{ + return QString(); +} + QList QPlatformPrinterSupport::supportedPaperSizes(const QPrinterInfo &) const { return QList(); diff --git a/src/printsupport/kernel/qplatformprintersupport.h b/src/printsupport/kernel/qplatformprintersupport.h index c4ffcffd1e..6a4ecc09c8 100644 --- a/src/printsupport/kernel/qplatformprintersupport.h +++ b/src/printsupport/kernel/qplatformprintersupport.h @@ -52,6 +52,7 @@ #include +#include #include #include @@ -61,6 +62,8 @@ QT_BEGIN_NAMESPACE typedef QHash PrinterOptions; +class QPlatformPrintDevice; +class QPrintDevice; class QPrintEngine; class Q_PRINTSUPPORT_EXPORT QPlatformPrinterSupport @@ -71,6 +74,12 @@ public: virtual QPrintEngine *createNativePrintEngine(QPrinter::PrinterMode printerMode); virtual QPaintEngine *createPaintEngine(QPrintEngine *, QPrinter::PrinterMode printerMode); + + virtual QPrintDevice createPrintDevice(const QString &id); + virtual QPrintDevice createDefaultPrintDevice(); + virtual QStringList availablePrintDeviceIds() const; + virtual QString defaultPrintDeviceId() const; + virtual QList supportedPaperSizes(const QPrinterInfo &) const; virtual QList > supportedSizesWithNames(const QPrinterInfo &printerInfo) const; virtual QList availablePrinters(); @@ -88,6 +97,7 @@ protected: 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 m_printers; }; diff --git a/src/printsupport/kernel/qprint_p.h b/src/printsupport/kernel/qprint_p.h new file mode 100644 index 0000000000..30f7c4a65e --- /dev/null +++ b/src/printsupport/kernel/qprint_p.h @@ -0,0 +1,304 @@ +/**************************************************************************** +** +** Copyright (C) 2014 John Layt +** Contact: http://www.qt-project.org/legal +** +** This file is part of the QtPrintSupport module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QPRINT_P_H +#define QPRINT_P_H + +// +// W A R N I N G +// ------------- +// +// This file is not part of the Qt API. It exists purely as an +// implementation detail. This header file may change from version to +// version without notice, or even be removed. +// +// We mean it. +// + +#include + +#include +#include + +#if (defined Q_OS_MAC && !defined Q_OS_IOS) || (defined Q_OS_UNIX && !defined QT_NO_CUPS) +#include // Use for type defs only, don't want to actually link in main module +#endif + +QT_BEGIN_NAMESPACE + +#ifndef QT_NO_PRINTER + +// From windgdi.h +#define DMBIN_UPPER 1 +#define DMBIN_ONLYONE 1 +#define DMBIN_LOWER 2 +#define DMBIN_MIDDLE 3 +#define DMBIN_MANUAL 4 +#define DMBIN_ENVELOPE 5 +#define DMBIN_ENVMANUAL 6 +#define DMBIN_AUTO 7 +#define DMBIN_TRACTOR 8 +#define DMBIN_SMALLFMT 9 +#define DMBIN_LARGEFMT 10 +#define DMBIN_LARGECAPACITY 11 +#define DMBIN_CASSETTE 14 +#define DMBIN_FORMSOURCE 15 +#define DMBIN_USER 256 + +namespace QPrint { + + // Note: Keep in sync with QPrinter::PrinterState for now + // Replace later with more detailed status reporting + enum DeviceState { + Idle, + Active, + Aborted, + Error + }; + + // Note: Keep in sync with QPrinter::DuplexMode + enum DuplexMode { + DuplexNone = 0, + DuplexAuto, + DuplexLongSide, + DuplexShortSide + }; + + enum ColorMode { + GrayScale, + Color + }; + + // Note: Keep in sync with QPrinter::PaperSource for now + // If/when made public, rearrange and rename + enum InputSlotId { + Upper, + Lower, + Middle, + Manual, + Envelope, + EnvelopeManual, + Auto, + Tractor, + SmallFormat, + LargeFormat, + LargeCapacity, + Cassette, + FormSource, + MaxPageSource, // Deprecated, kept for compatibility to QPrinter + CustomInputSlot, + LastInputSlot = CustomInputSlot, + OnlyOne = Upper + }; + + struct InputSlot { + QByteArray key; + QString name; + QPrint::InputSlotId id; + int windowsId; + }; + + enum OutputBinId { + AutoOutputBin, + UpperBin, + LowerBin, + RearBin, + CustomOutputBin, + LastOutputBin = CustomOutputBin + }; + + struct OutputBin { + QByteArray key; + QString name; + QPrint::OutputBinId id; + }; + +}; + +struct InputSlotMap { + QPrint::InputSlotId id; + int windowsId; + const char *key; +}; + +// Note: PPD standard does not define a standard set of InputSlot keywords, +// it is a free form text field left to the PPD writer to decide, +// but it does suggest some names for consistency with the Windows enum. +static const InputSlotMap inputSlotMap[] = { + { QPrint::Upper, DMBIN_UPPER, "Upper" }, + { QPrint::Lower, DMBIN_LOWER, "Lower" }, + { QPrint::Middle, DMBIN_MIDDLE, "Middle" }, + { QPrint::Manual, DMBIN_MANUAL, "Manual" }, + { QPrint::Envelope, DMBIN_ENVELOPE, "Envelope" }, + { QPrint::EnvelopeManual, DMBIN_ENVMANUAL, "EnvelopeManual" }, + { QPrint::Auto, DMBIN_AUTO, "Auto" }, + { QPrint::Tractor, DMBIN_TRACTOR, "Tractor" }, + { QPrint::SmallFormat, DMBIN_SMALLFMT, "AnySmallFormat" }, + { QPrint::LargeFormat, DMBIN_LARGEFMT, "AnyLargeFormat" }, + { QPrint::LargeCapacity, DMBIN_LARGECAPACITY, "LargeCapacity" }, + { QPrint::Cassette, DMBIN_CASSETTE, "Cassette" }, + { QPrint::FormSource, DMBIN_FORMSOURCE, "FormSource" }, + { QPrint::Manual, DMBIN_MANUAL, "ManualFeed" }, + { QPrint::OnlyOne, DMBIN_ONLYONE, "OnlyOne" }, // = QPrint::Upper + { QPrint::CustomInputSlot, DMBIN_USER, "" } // Must always be last row +}; + +struct OutputBinMap { + QPrint::OutputBinId id; + const char *key; +}; + +static const OutputBinMap outputBinMap[] = { + { QPrint::AutoOutputBin, "" }, // Not a PPD defined value, internal use only + { QPrint::UpperBin, "Upper" }, + { QPrint::LowerBin, "Lower" }, + { QPrint::RearBin, "Rear" }, + { QPrint::CustomOutputBin, "" } // Must always be last row +}; + +// Print utilities shared by print plugins + +class QPrintUtils +{ + +public: + + static QPrint::InputSlotId inputSlotKeyToInputSlotId(const QByteArray &key) + { + for (int i = 0; inputSlotMap[i].id != QPrint::CustomInputSlot; ++i) { + if (inputSlotMap[i].key == key) + return inputSlotMap[i].id; + } + return QPrint::CustomInputSlot; + } + + static QByteArray inputSlotIdToInputSlotKey(QPrint::InputSlotId id) + { + for (int i = 0; inputSlotMap[i].id != QPrint::CustomInputSlot; ++i) { + if (inputSlotMap[i].id == id) + return QByteArray(inputSlotMap[i].key); + } + return QByteArray(); + } + + static int inputSlotIdToWindowsId(QPrint::InputSlotId id) + { + for (int i = 0; inputSlotMap[i].id != QPrint::CustomInputSlot; ++i) { + if (inputSlotMap[i].id == id) + return inputSlotMap[i].windowsId; + } + return 0; + } + + static QPrint::OutputBinId outputBinKeyToOutputBinId(const QByteArray &key) + { + for (int i = 0; outputBinMap[i].id != QPrint::CustomOutputBin; ++i) { + if (outputBinMap[i].key == key) + return outputBinMap[i].id; + } + return QPrint::CustomOutputBin; + } + + static QByteArray outputBinIdToOutputBinKey(QPrint::OutputBinId id) + { + for (int i = 0; outputBinMap[i].id != QPrint::CustomOutputBin; ++i) { + if (outputBinMap[i].id == id) + return QByteArray(outputBinMap[i].key); + } + return QByteArray(); + } + +#if (defined Q_OS_MAC && !defined Q_OS_IOS) || (defined Q_OS_UNIX && !defined QT_NO_CUPS) + + // PPD utilities shared by CUPS and Mac plugins requiring CUPS headers + // May turn into a proper internal QPpd class if enough shared between Mac and CUPS, + // but where would it live? Not in base module as don't want to link to CUPS. + // May have to have two copies in plugins to keep in sync. + + static QPrint::InputSlot ppdChoiceToInputSlot(ppd_choice_t choice) + { + QPrint::InputSlot input; + input.key = choice.choice; + input.name = QString::fromUtf8(choice.text); + input.id = inputSlotKeyToInputSlotId(input.key); + input.windowsId = inputSlotMap[input.id].windowsId; + return input; + } + + static QPrint::OutputBin ppdChoiceToOutputBin(ppd_choice_t choice) + { + QPrint::OutputBin output; + output.key = choice.choice; + output.name = QString::fromUtf8(choice.text); + output.id = outputBinKeyToOutputBinId(output.key); + return output; + } + + static int parsePpdResolution(const QByteArray &value) + { + if (value.isEmpty()) + return -1; + // value can be in form 600dpi or 600x600dpi + QByteArray result = value.split('x').at(0); + if (result.endsWith("dpi")) + result.chop(3); + return result.toInt(); + } + + static QPrint::DuplexMode ppdChoiceToDuplexMode(const QByteArray &choice) + { + if (choice == QByteArrayLiteral("DuplexTumble")) + return QPrint::DuplexShortSide; + else if (choice == QByteArrayLiteral("DuplexNoTumble")) + return QPrint::DuplexLongSide; + else // None or SimplexTumble or SimplexNoTumble + return QPrint::DuplexNone; + } + +#endif // Mac and CUPS PPD Utilities + +}; + +#endif // QT_NO_PRINTER + +QT_END_NAMESPACE + +#endif // QPRINT_P_H diff --git a/src/printsupport/kernel/qprintdevice.cpp b/src/printsupport/kernel/qprintdevice.cpp new file mode 100644 index 0000000000..c4ba12e0b0 --- /dev/null +++ b/src/printsupport/kernel/qprintdevice.cpp @@ -0,0 +1,251 @@ +/**************************************************************************** +** +** Copyright (C) 2014 John Layt +** Contact: http://www.qt-project.org/legal +** +** This file is part of the QtPrintSupport module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qprintdevice_p.h" +#include "qplatformprintdevice.h" + +QT_BEGIN_NAMESPACE + +QPrintDevice::QPrintDevice() + : d(new QPlatformPrintDevice()) +{ +} + +QPrintDevice::QPrintDevice(const QString &id) + : d(new QPlatformPrintDevice(id)) +{ +} + +QPrintDevice::QPrintDevice(QPlatformPrintDevice *dd) + : d(dd) +{ +} + +QPrintDevice::QPrintDevice(const QPrintDevice &other) + : d(other.d) +{ +} + +QPrintDevice::~QPrintDevice() +{ +} + +QPrintDevice &QPrintDevice::operator=(const QPrintDevice &other) +{ + d = other.d; + return *this; +} + +bool QPrintDevice::operator==(const QPrintDevice &other) const +{ + if (d && other.d) + return *d == *other.d; + return d == other.d; +} + +QString QPrintDevice::id() const +{ + return isValid() ? d->id() : QString(); +} + +QString QPrintDevice::name() const +{ + return isValid() ? d->name() : QString(); +} + +QString QPrintDevice::location() const +{ + return isValid() ? d->location() : QString(); +} + +QString QPrintDevice::makeAndModel() const +{ + return isValid() ? d->makeAndModel() : QString(); +} + +bool QPrintDevice::isValid() const +{ + return d && d->isValid(); +} + +bool QPrintDevice::isDefault() const +{ + return isValid() && d->isDefault(); +} + +bool QPrintDevice::isRemote() const +{ + return isValid() && d->isRemote(); +} + +QPrint::DeviceState QPrintDevice::state() const +{ + return isValid() ? d->state() : QPrint::Error; +} + +bool QPrintDevice::isValidPageLayout(const QPageLayout &layout, int resolution) const +{ + return isValid() && d->isValidPageLayout(layout, resolution); +} + +bool QPrintDevice::supportsMultipleCopies() const +{ + return isValid() && d->supportsMultipleCopies(); +} + +bool QPrintDevice::supportsCollateCopies() const +{ + return isValid() && d->supportsCollateCopies(); +} + +QPageSize QPrintDevice::defaultPageSize() const +{ + return isValid() ? d->defaultPageSize() : QPageSize(); +} + +QList QPrintDevice::supportedPageSizes() const +{ + return isValid() ? d->supportedPageSizes() : QList(); +} + +QPageSize QPrintDevice::supportedPageSize(const QPageSize &pageSize) const +{ + return isValid() ? d->supportedPageSize(pageSize) : QPageSize(); +} + +QPageSize QPrintDevice::supportedPageSize(QPageSize::PageSizeId pageSizeId) const +{ + return isValid() ? d->supportedPageSize(pageSizeId) : QPageSize(); +} + +QPageSize QPrintDevice::supportedPageSize(const QString &pageName) const +{ + return isValid() ? d->supportedPageSize(pageName) : QPageSize(); +} + +QPageSize QPrintDevice::supportedPageSize(const QSize &pointSize) const +{ + return isValid() ? d->supportedPageSize(pointSize) : QPageSize(); +} + +QPageSize QPrintDevice::supportedPageSize(const QSizeF &size, QPageSize::Unit units) const +{ + return isValid() ? d->supportedPageSize(size, units) : QPageSize(); +} + +bool QPrintDevice::supportsCustomPageSizes() const +{ + return isValid() && d->supportsCustomPageSizes(); +} + +QSize QPrintDevice::minimumPhysicalPageSize() const +{ + return isValid() ? d->minimumPhysicalPageSize() : QSize(); +} + +QSize QPrintDevice::maximumPhysicalPageSize() const +{ + return isValid() ? d->maximumPhysicalPageSize() : QSize(); +} + +QMarginsF QPrintDevice::printableMargins(const QPageSize &pageSize, + QPageLayout::Orientation orientation, + int resolution) const +{ + return isValid() ? d->printableMargins(pageSize, orientation, resolution) : QMarginsF(); +} + +int QPrintDevice::defaultResolution() const +{ + return isValid() ? d->defaultResolution() : 0; +} + +QList QPrintDevice::supportedResolutions() const +{ + return isValid() ? d->supportedResolutions() : QList(); +} + +QPrint::InputSlot QPrintDevice::defaultInputSlot() const +{ + return isValid() ? d->defaultInputSlot() : QPrint::InputSlot(); +} + +QList QPrintDevice::supportedInputSlots() const +{ + return isValid() ? d->supportedInputSlots() : QList(); +} + +QPrint::OutputBin QPrintDevice::defaultOutputBin() const +{ + return isValid() ? d->defaultOutputBin() : QPrint::OutputBin(); +} + +QList QPrintDevice::supportedOutputBins() const +{ + return isValid() ? d->supportedOutputBins() : QList(); +} + +QPrint::DuplexMode QPrintDevice::defaultDuplexMode() const +{ + return isValid() ? d->defaultDuplexMode() : QPrint::DuplexNone; +} + +QList QPrintDevice::supportedDuplexModes() const +{ + return isValid() ? d->supportedDuplexModes() : QList(); +} + +QPrint::ColorMode QPrintDevice::defaultColorMode() const +{ + return isValid() ? d->defaultColorMode() : QPrint::GrayScale; +} + +QList QPrintDevice::supportedColorModes() const +{ + return isValid() ? d->supportedColorModes() : QList(); +} + +QList QPrintDevice::supportedMimeTypes() const +{ + return isValid() ? d->supportedMimeTypes() : QList(); +} + +QT_END_NAMESPACE diff --git a/src/printsupport/kernel/qprintdevice_p.h b/src/printsupport/kernel/qprintdevice_p.h new file mode 100644 index 0000000000..55124c16d4 --- /dev/null +++ b/src/printsupport/kernel/qprintdevice_p.h @@ -0,0 +1,145 @@ +/**************************************************************************** +** +** Copyright (C) 2014 John Layt +** Contact: http://www.qt-project.org/legal +** +** This file is part of the QtPrintSupport module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QPRINTDEVICE_H +#define QPRINTDEVICE_H + +// +// W A R N I N G +// ------------- +// +// This file is not part of the Qt API. It exists for the convenience +// of internal files. This header file may change from version to version +// without notice, or even be removed. +// +// We mean it. +// + +#include "private/qprint_p.h" + +#include +#include + +QT_BEGIN_NAMESPACE + +class QPlatformPrintDevice; +class QMarginsF; +class QMimeType; + +class Q_PRINTSUPPORT_EXPORT QPrintDevice +{ +public: + + QPrintDevice(); + QPrintDevice(const QString & id); + QPrintDevice(const QPrintDevice &other); + ~QPrintDevice(); + + QPrintDevice &operator=(const QPrintDevice &other); + #ifdef Q_COMPILER_RVALUE_REFS + QPrintDevice &operator=(QPrintDevice &&other) { swap(other); return *this; } +#endif + + void swap(QPrintDevice &other) { d.swap(other.d); } + + bool operator==(const QPrintDevice &other) const; + + QString id() const; + QString name() const; + QString location() const; + QString makeAndModel() const; + + bool isValid() const; + bool isDefault() const; + bool isRemote() const; + + QPrint::DeviceState state() const; + + bool isValidPageLayout(const QPageLayout &layout, int resolution) const; + + bool supportsMultipleCopies() const; + bool supportsCollateCopies() const; + + QPageSize defaultPageSize() const; + QList supportedPageSizes() const; + + QPageSize supportedPageSize(const QPageSize &pageSize) const; + QPageSize supportedPageSize(QPageSize::PageSizeId pageSizeId) const; + QPageSize supportedPageSize(const QString &pageName) const; + QPageSize supportedPageSize(const QSize &pointSize) const; + QPageSize supportedPageSize(const QSizeF &size, QPageSize::Unit units = QPageSize::Point) const; + + bool supportsCustomPageSizes() const; + + QSize minimumPhysicalPageSize() const; + QSize maximumPhysicalPageSize() const; + + QMarginsF printableMargins(const QPageSize &pageSize, QPageLayout::Orientation orientation, int resolution) const; + + int defaultResolution() const; + QList supportedResolutions() const; + + QPrint::InputSlot defaultInputSlot() const; + QList supportedInputSlots() const; + + QPrint::OutputBin defaultOutputBin() const; + QList supportedOutputBins() const; + + QPrint::DuplexMode defaultDuplexMode() const; + QList supportedDuplexModes() const; + + QPrint::ColorMode defaultColorMode() const; + QList supportedColorModes() const; + + QList supportedMimeTypes() const; + +private: + friend class QPlatformPrinterSupport; + friend class QPlatformPrintDevice; + QPrintDevice(QPlatformPrintDevice *dd); + QSharedDataPointer d; +}; + +Q_DECLARE_SHARED(QPrintDevice) + +QT_END_NAMESPACE + +#endif // QPLATFORMPRINTDEVICE_H diff --git a/tests/auto/printsupport/kernel/kernel.pro b/tests/auto/printsupport/kernel/kernel.pro index 6f5802bf3e..0566556e01 100644 --- a/tests/auto/printsupport/kernel/kernel.pro +++ b/tests/auto/printsupport/kernel/kernel.pro @@ -1,4 +1,5 @@ TEMPLATE=subdirs SUBDIRS=\ + qprintdevice \ qprinter \ qprinterinfo \ diff --git a/tests/auto/printsupport/kernel/qprintdevice/.gitignore b/tests/auto/printsupport/kernel/qprintdevice/.gitignore new file mode 100644 index 0000000000..fcef7c1997 --- /dev/null +++ b/tests/auto/printsupport/kernel/qprintdevice/.gitignore @@ -0,0 +1 @@ +tst_qprinterinfo diff --git a/tests/auto/printsupport/kernel/qprintdevice/qprintdevice.pro b/tests/auto/printsupport/kernel/qprintdevice/qprintdevice.pro new file mode 100644 index 0000000000..fb11b0361e --- /dev/null +++ b/tests/auto/printsupport/kernel/qprintdevice/qprintdevice.pro @@ -0,0 +1,9 @@ +CONFIG += testcase +CONFIG += parallel_test +TARGET = tst_qprintdevice +SOURCES += tst_qprintdevice.cpp + +QT += printsupport-private network testlib + +DEFINES += QT_USE_USING_NAMESPACE +DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0 diff --git a/tests/auto/printsupport/kernel/qprintdevice/tst_qprintdevice.cpp b/tests/auto/printsupport/kernel/qprintdevice/tst_qprintdevice.cpp new file mode 100644 index 0000000000..6d2fe2cd53 --- /dev/null +++ b/tests/auto/printsupport/kernel/qprintdevice/tst_qprintdevice.cpp @@ -0,0 +1,109 @@ +/**************************************************************************** +** +** Copyright (C) 2014 John Layt +** Contact: http://www.qt-project.org/legal +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include + +#include +#include + +#include + +class tst_QPrintDevice : public QObject +{ + Q_OBJECT + +private slots: + void basics(); +}; + +void tst_QPrintDevice::basics() +{ + QPlatformPrinterSupport *ps = QPlatformPrinterSupportPlugin::get(); + if (!ps) + QSKIP("Could not load platform plugin"); + + QString defaultId = ps->defaultPrintDeviceId(); + if (defaultId.isEmpty()) { + qDebug() << "No default printer found"; + } else { + qDebug() << "Default Printer ID :" << defaultId; + QVERIFY(ps->availablePrintDeviceIds().contains(defaultId)); + } + + qDebug() << "Available Printer IDs :" << ps->availablePrintDeviceIds(); + + // Just exercise the api for now as we don't know what is installed + foreach (const QString id, ps->availablePrintDeviceIds()) { + QPrintDevice printDevice = ps->createPrintDevice(id); + qDebug() << "Created printer" << id; + QCOMPARE(printDevice.isValid(), true); + printDevice.id(); + printDevice.name(); + printDevice.location(); + printDevice.makeAndModel(); + printDevice.isValid(); + printDevice.isDefault(); + printDevice.isRemote(); + printDevice.state(); + printDevice.supportsMultipleCopies(); + printDevice.supportsCollateCopies(); + printDevice.defaultPageSize(); + printDevice.supportedPageSizes(); + printDevice.supportsCustomPageSizes(); + printDevice.minimumPhysicalPageSize(); + printDevice.maximumPhysicalPageSize(); + printDevice.defaultResolution(); + printDevice.supportedResolutions(); + printDevice.defaultInputSlot(); + printDevice.supportedInputSlots(); + printDevice.defaultOutputBin(); + printDevice.supportedOutputBins(); + printDevice.defaultDuplexMode(); + printDevice.supportedDuplexModes(); + printDevice.defaultColorMode(); + printDevice.supportedColorModes(); + printDevice.supportedMimeTypes(); + } +} + +QTEST_MAIN(tst_QPrintDevice) + +#include "tst_qprintdevice.moc" diff --git a/tests/manual/qprintdevice_dump/main.cpp b/tests/manual/qprintdevice_dump/main.cpp new file mode 100644 index 0000000000..930c851d65 --- /dev/null +++ b/tests/manual/qprintdevice_dump/main.cpp @@ -0,0 +1,181 @@ +/**************************************************************************** +** +** Copyright (C) 2014 John Layt +** Contact: http://www.qt-project.org/legal +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include +#include + +#include + +#include +#include +#include + +/* + This test is designed to dump the current printer configuration details + to output, to assist in debugging of print device problems. +*/ + +static QString stateToString(QPrint::DeviceState state) +{ + switch (state) { + case QPrint::Idle: + return QStringLiteral("Idle"); + case QPrint::Active: + return QStringLiteral("Active"); + case QPrint::Aborted: + return QStringLiteral("Aborted"); + case QPrint::Error: + return QStringLiteral("Error"); + } + return QStringLiteral("Invalid DeviceState"); +} + +static QString duplexToString(QPrint::DuplexMode duplex) +{ + switch (duplex) { + case QPrint::DuplexNone: + return QStringLiteral("DuplexNone"); + case QPrint::DuplexAuto: + return QStringLiteral("DuplexAuto"); + case QPrint::DuplexLongSide: + return QStringLiteral("DuplexLongSide"); + case QPrint::DuplexShortSide: + return QStringLiteral("DuplexShortSide"); + } + return QStringLiteral("Invalid DuplexMode"); +} + +static QString colorToString(QPrint::ColorMode color) +{ + switch (color) { + case QPrint::GrayScale: + return QStringLiteral("GrayScale"); + case QPrint::Color: + return QStringLiteral("Color"); + } + return QStringLiteral("Invalid ColorMode"); +} + +int main(int argc, char *argv[]) +{ + QApplication a(argc, argv); + + qDebug() << "\n********************************"; + qDebug() << "***** QPrintDevice Details *****"; + qDebug() << "********************************\n"; + + QPlatformPrinterSupport *ps = QPlatformPrinterSupportPlugin::get(); + if (!ps) { + qDebug() << "Could not load platform plugin!"; + return -1; + } + + QString defaultId = ps->defaultPrintDeviceId(); + if (defaultId.isEmpty()) + qDebug() << "No default printer found"; + else + qDebug() << "Default Printer ID :" << defaultId; + qDebug() << "Available Printer IDs :" << ps->availablePrintDeviceIds() << "\n"; + + foreach (const QString id, ps->availablePrintDeviceIds()) { + QPrintDevice printDevice = ps->createPrintDevice(id); + if (printDevice.isValid()) { + qDebug() << "===" << printDevice.id() << "===\n"; + qDebug() << "Device ID :" << printDevice.id(); + qDebug() << "Device Name :" << printDevice.name(); + qDebug() << "Device Location :" << printDevice.location(); + qDebug() << "Device Make :" << printDevice.makeAndModel(); + qDebug() << ""; + qDebug() << "isValid :" << printDevice.isValid(); + qDebug() << "isDefault :" << printDevice.isDefault(); + qDebug() << "isRemote :" << printDevice.isRemote(); + qDebug() << ""; + qDebug() << "state :" << stateToString(printDevice.state()); + qDebug() << ""; + qDebug() << "supportsMultipleCopies :" << printDevice.supportsMultipleCopies(); + qDebug() << "supportsCollateCopies :" << printDevice.supportsCollateCopies(); + qDebug() << ""; + qDebug() << "defaultPageSize :" << printDevice.defaultPageSize(); + qDebug() << "supportedPageSizes :"; + foreach (const QPageSize &page, printDevice.supportedPageSizes()) + qDebug() << " " << page << printDevice.printableMargins(page, QPageLayout::Portrait, 300); + qDebug() << ""; + qDebug() << "supportsCustomPageSizes :" << printDevice.supportsCustomPageSizes(); + qDebug() << ""; + qDebug() << "minimumPhysicalPageSize :" << printDevice.minimumPhysicalPageSize(); + qDebug() << "maximumPhysicalPageSize :" << printDevice.maximumPhysicalPageSize(); + qDebug() << ""; + qDebug() << "defaultResolution :" << printDevice.defaultResolution(); + qDebug() << "supportedResolutions :" << printDevice.supportedResolutions(); + qDebug() << ""; + qDebug() << "defaultInputSlot :" << printDevice.defaultInputSlot().key + << printDevice.defaultInputSlot().name + << printDevice.defaultInputSlot().id; + qDebug() << "supportedInputSlots :"; + foreach (const QPrint::InputSlot &slot, printDevice.supportedInputSlots()) + qDebug() << " " << slot.key << slot.name << slot.id; + qDebug() << ""; + qDebug() << "defaultOutputBin :" << printDevice.defaultOutputBin().key + << printDevice.defaultOutputBin().name + << printDevice.defaultOutputBin().id; + qDebug() << "supportedOutputBins :"; + foreach (const QPrint::OutputBin &bin, printDevice.supportedOutputBins()) + qDebug() << " " << bin.key << bin.name << bin.id; + qDebug() << ""; + qDebug() << "defaultDuplexMode :" << duplexToString(printDevice.defaultDuplexMode()); + qDebug() << "supportedDuplexModes :"; + foreach (QPrint::DuplexMode mode, printDevice.supportedDuplexModes()) + qDebug() << " " << duplexToString(mode); + qDebug() << ""; + qDebug() << "defaultColorMode :" << colorToString(printDevice.defaultColorMode()); + qDebug() << "supportedColorModes :"; + foreach (QPrint::ColorMode mode, printDevice.supportedColorModes()) + qDebug() << " " << colorToString(mode); + qDebug() << ""; + qDebug() << "supportedMimeTypes :"; + foreach (const QMimeType &type, printDevice.supportedMimeTypes()) + qDebug() << " " << type.name(); + } else { + qDebug() << "Create printer failed" << id; + } + qDebug() << "\n"; + } +} diff --git a/tests/manual/qprintdevice_dump/qprintdevice_dump.pro b/tests/manual/qprintdevice_dump/qprintdevice_dump.pro new file mode 100644 index 0000000000..c9d36d1d1f --- /dev/null +++ b/tests/manual/qprintdevice_dump/qprintdevice_dump.pro @@ -0,0 +1,6 @@ +QT += printsupport-private + +TARGET = qprintdevice_dump +TEMPLATE = app + +SOURCES += main.cpp -- cgit v1.2.3