1 /****************************************************************************
2 **
3 ** Copyright (C) 2014 John Layt <jlayt@kde.org>
4 ** Contact: https://www.qt.io/licensing/
5 **
6 ** This file is part of the QtPrintSupport module of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and The Qt Company. For licensing terms
14 ** and conditions see https://www.qt.io/terms-conditions. For further
15 ** information use the contact form at https://www.qt.io/contact-us.
16 **
17 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 3 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL3 included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 3 requirements
23 ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
24 **
25 ** GNU General Public License Usage
26 ** Alternatively, this file may be used under the terms of the GNU
27 ** General Public License version 2.0 or (at your option) the GNU General
28 ** Public license version 3 or any later version approved by the KDE Free
29 ** Qt Foundation. The licenses are as published by the Free Software
30 ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
31 ** included in the packaging of this file. Please review the following
32 ** information to ensure the GNU General Public License requirements will
33 ** be met: https://www.gnu.org/licenses/gpl-2.0.html and
34 ** https://www.gnu.org/licenses/gpl-3.0.html.
35 **
36 ** $QT_END_LICENSE$
37 **
38 ****************************************************************************/
39 
40 #include "qprintdevice_p.h"
41 #include "qplatformprintdevice.h"
42 
43 #include <private/qdebug_p.h>
44 
45 QT_BEGIN_NAMESPACE
46 
47 #ifndef QT_NO_PRINTER
48 
QPrintDevice()49 QPrintDevice::QPrintDevice()
50     : d(new QPlatformPrintDevice())
51 {
52 }
53 
QPrintDevice(const QString & id)54 QPrintDevice::QPrintDevice(const QString &id)
55     : d(new QPlatformPrintDevice(id))
56 {
57 }
58 
QPrintDevice(QPlatformPrintDevice * dd)59 QPrintDevice::QPrintDevice(QPlatformPrintDevice *dd)
60     : d(dd)
61 {
62 }
63 
QPrintDevice(const QPrintDevice & other)64 QPrintDevice::QPrintDevice(const QPrintDevice &other)
65     : d(other.d)
66 {
67 }
68 
~QPrintDevice()69 QPrintDevice::~QPrintDevice()
70 {
71 }
72 
operator =(const QPrintDevice & other)73 QPrintDevice &QPrintDevice::operator=(const QPrintDevice &other)
74 {
75     d = other.d;
76     return *this;
77 }
78 
operator ==(const QPrintDevice & other) const79 bool QPrintDevice::operator==(const QPrintDevice &other) const
80 {
81     if (d && other.d)
82         return d->id() == other.d->id();
83     return d == other.d;
84 }
85 
id() const86 QString QPrintDevice::id() const
87 {
88     return isValid() ? d->id() : QString();
89 }
90 
name() const91 QString QPrintDevice::name() const
92 {
93     return isValid() ? d->name() : QString();
94 }
95 
location() const96 QString QPrintDevice::location() const
97 {
98     return isValid() ? d->location() : QString();
99 }
100 
makeAndModel() const101 QString QPrintDevice::makeAndModel() const
102 {
103     return isValid() ? d->makeAndModel() : QString();
104 }
105 
isValid() const106 bool QPrintDevice::isValid() const
107 {
108     return d && d->isValid();
109 }
110 
isDefault() const111 bool QPrintDevice::isDefault() const
112 {
113     return isValid() && d->isDefault();
114 }
115 
isRemote() const116 bool QPrintDevice::isRemote() const
117 {
118     return isValid() && d->isRemote();
119 }
120 
state() const121 QPrint::DeviceState QPrintDevice::state() const
122 {
123     return isValid() ? d->state() : QPrint::Error;
124 }
125 
isValidPageLayout(const QPageLayout & layout,int resolution) const126 bool QPrintDevice::isValidPageLayout(const QPageLayout &layout, int resolution) const
127 {
128     return isValid() && d->isValidPageLayout(layout, resolution);
129 }
130 
supportsMultipleCopies() const131 bool QPrintDevice::supportsMultipleCopies() const
132 {
133     return isValid() && d->supportsMultipleCopies();
134 }
135 
supportsCollateCopies() const136 bool QPrintDevice::supportsCollateCopies() const
137 {
138     return isValid() && d->supportsCollateCopies();
139 }
140 
defaultPageSize() const141 QPageSize QPrintDevice::defaultPageSize() const
142 {
143     return isValid() ? d->defaultPageSize() : QPageSize();
144 }
145 
supportedPageSizes() const146 QList<QPageSize> QPrintDevice::supportedPageSizes() const
147 {
148     return isValid() ? d->supportedPageSizes() : QList<QPageSize>();
149 }
150 
supportedPageSize(const QPageSize & pageSize) const151 QPageSize QPrintDevice::supportedPageSize(const QPageSize &pageSize) const
152 {
153     return isValid() ? d->supportedPageSize(pageSize) : QPageSize();
154 }
155 
supportedPageSize(QPageSize::PageSizeId pageSizeId) const156 QPageSize QPrintDevice::supportedPageSize(QPageSize::PageSizeId pageSizeId) const
157 {
158     return isValid() ? d->supportedPageSize(pageSizeId) : QPageSize();
159 }
160 
supportedPageSize(const QString & pageName) const161 QPageSize QPrintDevice::supportedPageSize(const QString &pageName) const
162 {
163     return isValid() ? d->supportedPageSize(pageName) : QPageSize();
164 }
165 
supportedPageSize(const QSize & pointSize) const166 QPageSize QPrintDevice::supportedPageSize(const QSize &pointSize) const
167 {
168     return isValid() ? d->supportedPageSize(pointSize) : QPageSize();
169 }
170 
supportedPageSize(const QSizeF & size,QPageSize::Unit units) const171 QPageSize QPrintDevice::supportedPageSize(const QSizeF &size, QPageSize::Unit units) const
172 {
173     return isValid() ? d->supportedPageSize(size, units) : QPageSize();
174 }
175 
supportsCustomPageSizes() const176 bool QPrintDevice::supportsCustomPageSizes() const
177 {
178     return isValid() && d->supportsCustomPageSizes();
179 }
180 
minimumPhysicalPageSize() const181 QSize QPrintDevice::minimumPhysicalPageSize() const
182 {
183     return isValid() ? d->minimumPhysicalPageSize() : QSize();
184 }
185 
maximumPhysicalPageSize() const186 QSize QPrintDevice::maximumPhysicalPageSize() const
187 {
188     return isValid() ? d->maximumPhysicalPageSize() : QSize();
189 }
190 
printableMargins(const QPageSize & pageSize,QPageLayout::Orientation orientation,int resolution) const191 QMarginsF QPrintDevice::printableMargins(const QPageSize &pageSize,
192                                          QPageLayout::Orientation orientation,
193                                          int resolution) const
194 {
195     return isValid() ? d->printableMargins(pageSize, orientation, resolution) : QMarginsF();
196 }
197 
defaultResolution() const198 int QPrintDevice::defaultResolution() const
199 {
200     return isValid() ? d->defaultResolution() : 0;
201 }
202 
supportedResolutions() const203 QList<int> QPrintDevice::supportedResolutions() const
204 {
205     return isValid() ? d->supportedResolutions() : QList<int>();
206 }
207 
defaultInputSlot() const208 QPrint::InputSlot QPrintDevice::defaultInputSlot() const
209 {
210     return isValid() ? d->defaultInputSlot() : QPrint::InputSlot();
211 }
212 
supportedInputSlots() const213 QVector<QPrint::InputSlot> QPrintDevice::supportedInputSlots() const
214 {
215     return isValid() ? d->supportedInputSlots() : QVector<QPrint::InputSlot>{};
216 }
217 
defaultOutputBin() const218 QPrint::OutputBin QPrintDevice::defaultOutputBin() const
219 {
220     return isValid() ? d->defaultOutputBin() : QPrint::OutputBin();
221 }
222 
supportedOutputBins() const223 QVector<QPrint::OutputBin> QPrintDevice::supportedOutputBins() const
224 {
225     return isValid() ? d->supportedOutputBins() : QVector<QPrint::OutputBin>{};
226 }
227 
defaultDuplexMode() const228 QPrint::DuplexMode QPrintDevice::defaultDuplexMode() const
229 {
230     return isValid() ? d->defaultDuplexMode() : QPrint::DuplexNone;
231 }
232 
supportedDuplexModes() const233 QVector<QPrint::DuplexMode> QPrintDevice::supportedDuplexModes() const
234 {
235     return isValid() ? d->supportedDuplexModes() : QVector<QPrint::DuplexMode>{};
236 }
237 
defaultColorMode() const238 QPrint::ColorMode QPrintDevice::defaultColorMode() const
239 {
240     return isValid() ? d->defaultColorMode() : QPrint::GrayScale;
241 }
242 
supportedColorModes() const243 QVector<QPrint::ColorMode> QPrintDevice::supportedColorModes() const
244 {
245     return isValid() ? d->supportedColorModes() : QVector<QPrint::ColorMode>{};
246 }
247 
property(PrintDevicePropertyKey key) const248 QVariant QPrintDevice::property(PrintDevicePropertyKey key) const
249 {
250     return isValid() ? d->property(key) : QVariant();
251 }
252 
setProperty(PrintDevicePropertyKey key,const QVariant & value)253 bool QPrintDevice::setProperty(PrintDevicePropertyKey key, const QVariant &value)
254 {
255     return isValid() ? d->setProperty(key, value) : false;
256 }
257 
isFeatureAvailable(PrintDevicePropertyKey key,const QVariant & params) const258 bool QPrintDevice::isFeatureAvailable(PrintDevicePropertyKey key, const QVariant &params) const
259 {
260     return isValid() ? d->isFeatureAvailable(key, params) : false;
261 }
262 
263 #if QT_CONFIG(mimetype)
supportedMimeTypes() const264 QList<QMimeType> QPrintDevice::supportedMimeTypes() const
265 {
266     return isValid() ? d->supportedMimeTypes() : QList<QMimeType>();
267 }
268 #endif // mimetype
269 
270 #  ifndef QT_NO_DEBUG_STREAM
format(QDebug debug) const271 void QPrintDevice::format(QDebug debug) const
272 {
273     QDebugStateSaver saver(debug);
274     debug.noquote();
275     debug.nospace();
276     if (isValid()) {
277         const QString deviceId = id();
278         const QString deviceName = name();
279         debug << "id=\"" << deviceId << "\", state=" << state();
280         if (!deviceName.isEmpty() && deviceName != deviceId)
281             debug << ", name=\"" << deviceName << '"';
282         if (!location().isEmpty())
283             debug << ", location=\"" << location() << '"';
284         debug << ", makeAndModel=\"" << makeAndModel() << '"';
285         if (isDefault())
286             debug << ", default";
287         if (isRemote())
288             debug << ", remote";
289         debug << ", defaultPageSize=" << defaultPageSize();
290         if (supportsCustomPageSizes())
291             debug << ", supportsCustomPageSizes";
292         debug << ", physicalPageSize=(";
293         QtDebugUtils::formatQSize(debug, minimumPhysicalPageSize());
294         debug << ")..(";
295         QtDebugUtils::formatQSize(debug, maximumPhysicalPageSize());
296         debug << "), defaultResolution=" << defaultResolution()
297               << ", defaultDuplexMode=" << defaultDuplexMode()
298               << ", defaultColorMode="<< defaultColorMode();
299 #    if QT_CONFIG(mimetype)
300         const QList<QMimeType> mimeTypes = supportedMimeTypes();
301         if (!mimeTypes.isEmpty()) {
302             debug << ", supportedMimeTypes=(";
303             for (const auto &mimeType : mimeTypes)
304                 debug << " \"" << mimeType.name() << '"';
305             debug << ')';
306         }
307 #    endif // mimetype
308     } else {
309         debug << "null";
310     }
311 }
312 
operator <<(QDebug debug,const QPrintDevice & p)313 QDebug operator<<(QDebug debug, const QPrintDevice &p)
314 {
315     QDebugStateSaver saver(debug);
316     debug.nospace();
317     debug << "QPrintDevice(";
318     p.format(debug);
319     debug << ')';
320     return debug;
321 }
322 #  endif // QT_NO_DEBUG_STREAM
323 #endif // QT_NO_PRINTER
324 
325 QT_END_NAMESPACE
326