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
45QT_BEGIN_NAMESPACE
46
47#ifndef QT_NO_PRINTER
48
49QPrintDevice::QPrintDevice()
50 : d(new QPlatformPrintDevice())
51{
52}
53
54QPrintDevice::QPrintDevice(const QString &id)
55 : d(new QPlatformPrintDevice(id))
56{
57}
58
59QPrintDevice::QPrintDevice(QPlatformPrintDevice *dd)
60 : d(dd)
61{
62}
63
64QPrintDevice::QPrintDevice(const QPrintDevice &other)
65 : d(other.d)
66{
67}
68
69QPrintDevice::~QPrintDevice()
70{
71}
72
73QPrintDevice &QPrintDevice::operator=(const QPrintDevice &other)
74{
75 d = other.d;
76 return *this;
77}
78
79bool 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
86QString QPrintDevice::id() const
87{
88 return isValid() ? d->id() : QString();
89}
90
91QString QPrintDevice::name() const
92{
93 return isValid() ? d->name() : QString();
94}
95
96QString QPrintDevice::location() const
97{
98 return isValid() ? d->location() : QString();
99}
100
101QString QPrintDevice::makeAndModel() const
102{
103 return isValid() ? d->makeAndModel() : QString();
104}
105
106bool QPrintDevice::isValid() const
107{
108 return d && d->isValid();
109}
110
111bool QPrintDevice::isDefault() const
112{
113 return isValid() && d->isDefault();
114}
115
116bool QPrintDevice::isRemote() const
117{
118 return isValid() && d->isRemote();
119}
120
121QPrint::DeviceState QPrintDevice::state() const
122{
123 return isValid() ? d->state() : QPrint::Error;
124}
125
126bool QPrintDevice::isValidPageLayout(const QPageLayout &layout, int resolution) const
127{
128 return isValid() && d->isValidPageLayout(layout, resolution);
129}
130
131bool QPrintDevice::supportsMultipleCopies() const
132{
133 return isValid() && d->supportsMultipleCopies();
134}
135
136bool QPrintDevice::supportsCollateCopies() const
137{
138 return isValid() && d->supportsCollateCopies();
139}
140
141QPageSize QPrintDevice::defaultPageSize() const
142{
143 return isValid() ? d->defaultPageSize() : QPageSize();
144}
145
146QList<QPageSize> QPrintDevice::supportedPageSizes() const
147{
148 return isValid() ? d->supportedPageSizes() : QList<QPageSize>();
149}
150
151QPageSize QPrintDevice::supportedPageSize(const QPageSize &pageSize) const
152{
153 return isValid() ? d->supportedPageSize(pageSize) : QPageSize();
154}
155
156QPageSize QPrintDevice::supportedPageSize(QPageSize::PageSizeId pageSizeId) const
157{
158 return isValid() ? d->supportedPageSize(pageSizeId) : QPageSize();
159}
160
161QPageSize QPrintDevice::supportedPageSize(const QString &pageName) const
162{
163 return isValid() ? d->supportedPageSize(pageName) : QPageSize();
164}
165
166QPageSize QPrintDevice::supportedPageSize(const QSize &pointSize) const
167{
168 return isValid() ? d->supportedPageSize(pointSize) : QPageSize();
169}
170
171QPageSize QPrintDevice::supportedPageSize(const QSizeF &size, QPageSize::Unit units) const
172{
173 return isValid() ? d->supportedPageSize(size, units) : QPageSize();
174}
175
176bool QPrintDevice::supportsCustomPageSizes() const
177{
178 return isValid() && d->supportsCustomPageSizes();
179}
180
181QSize QPrintDevice::minimumPhysicalPageSize() const
182{
183 return isValid() ? d->minimumPhysicalPageSize() : QSize();
184}
185
186QSize QPrintDevice::maximumPhysicalPageSize() const
187{
188 return isValid() ? d->maximumPhysicalPageSize() : QSize();
189}
190
191QMarginsF 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
198int QPrintDevice::defaultResolution() const
199{
200 return isValid() ? d->defaultResolution() : 0;
201}
202
203QList<int> QPrintDevice::supportedResolutions() const
204{
205 return isValid() ? d->supportedResolutions() : QList<int>();
206}
207
208QPrint::InputSlot QPrintDevice::defaultInputSlot() const
209{
210 return isValid() ? d->defaultInputSlot() : QPrint::InputSlot();
211}
212
213QVector<QPrint::InputSlot> QPrintDevice::supportedInputSlots() const
214{
215 return isValid() ? d->supportedInputSlots() : QVector<QPrint::InputSlot>{};
216}
217
218QPrint::OutputBin QPrintDevice::defaultOutputBin() const
219{
220 return isValid() ? d->defaultOutputBin() : QPrint::OutputBin();
221}
222
223QVector<QPrint::OutputBin> QPrintDevice::supportedOutputBins() const
224{
225 return isValid() ? d->supportedOutputBins() : QVector<QPrint::OutputBin>{};
226}
227
228QPrint::DuplexMode QPrintDevice::defaultDuplexMode() const
229{
230 return isValid() ? d->defaultDuplexMode() : QPrint::DuplexNone;
231}
232
233QVector<QPrint::DuplexMode> QPrintDevice::supportedDuplexModes() const
234{
235 return isValid() ? d->supportedDuplexModes() : QVector<QPrint::DuplexMode>{};
236}
237
238QPrint::ColorMode QPrintDevice::defaultColorMode() const
239{
240 return isValid() ? d->defaultColorMode() : QPrint::GrayScale;
241}
242
243QVector<QPrint::ColorMode> QPrintDevice::supportedColorModes() const
244{
245 return isValid() ? d->supportedColorModes() : QVector<QPrint::ColorMode>{};
246}
247
248QVariant QPrintDevice::property(PrintDevicePropertyKey key) const
249{
250 return isValid() ? d->property(key) : QVariant();
251}
252
253bool QPrintDevice::setProperty(PrintDevicePropertyKey key, const QVariant &value)
254{
255 return isValid() ? d->setProperty(key, value) : false;
256}
257
258bool QPrintDevice::isFeatureAvailable(PrintDevicePropertyKey key, const QVariant &params) const
259{
260 return isValid() ? d->isFeatureAvailable(key, params) : false;
261}
262
263#if QT_CONFIG(mimetype)
264QList<QMimeType> QPrintDevice::supportedMimeTypes() const
265{
266 return isValid() ? d->supportedMimeTypes() : QList<QMimeType>();
267}
268#endif // mimetype
269
270# ifndef QT_NO_DEBUG_STREAM
271void 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, size: minimumPhysicalPageSize());
294 debug << ")..(";
295 QtDebugUtils::formatQSize(debug, size: 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
313QDebug 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
325QT_END_NAMESPACE
326

source code of qtbase/src/printsupport/kernel/qprintdevice.cpp