1// Copyright (C) 2014 John Layt <jlayt@kde.org>
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4#include "qprintdevice_p.h"
5#include "qplatformprintdevice.h"
6
7#include <private/qdebug_p.h>
8
9QT_BEGIN_NAMESPACE
10
11#ifndef QT_NO_PRINTER
12
13QPrintDevice::QPrintDevice()
14 : d(new QPlatformPrintDevice())
15{
16}
17
18QPrintDevice::QPrintDevice(const QString &id)
19 : d(new QPlatformPrintDevice(id))
20{
21}
22
23QPrintDevice::QPrintDevice(QPlatformPrintDevice *dd)
24 : d(dd)
25{
26}
27
28QPrintDevice::QPrintDevice(const QPrintDevice &other)
29 : d(other.d)
30{
31}
32
33QPrintDevice::~QPrintDevice()
34{
35}
36
37QPrintDevice &QPrintDevice::operator=(const QPrintDevice &other)
38{
39 d = other.d;
40 return *this;
41}
42
43bool QPrintDevice::operator==(const QPrintDevice &other) const
44{
45 if (d && other.d)
46 return d->id() == other.d->id();
47 return d == other.d;
48}
49
50QString QPrintDevice::id() const
51{
52 return isValid() ? d->id() : QString();
53}
54
55QString QPrintDevice::name() const
56{
57 return isValid() ? d->name() : QString();
58}
59
60QString QPrintDevice::location() const
61{
62 return isValid() ? d->location() : QString();
63}
64
65QString QPrintDevice::makeAndModel() const
66{
67 return isValid() ? d->makeAndModel() : QString();
68}
69
70bool QPrintDevice::isValid() const
71{
72 return d && d->isValid();
73}
74
75bool QPrintDevice::isDefault() const
76{
77 return isValid() && d->isDefault();
78}
79
80bool QPrintDevice::isRemote() const
81{
82 return isValid() && d->isRemote();
83}
84
85QPrint::DeviceState QPrintDevice::state() const
86{
87 return isValid() ? d->state() : QPrint::Error;
88}
89
90bool QPrintDevice::isValidPageLayout(const QPageLayout &layout, int resolution) const
91{
92 return isValid() && d->isValidPageLayout(layout, resolution);
93}
94
95bool QPrintDevice::supportsMultipleCopies() const
96{
97 return isValid() && d->supportsMultipleCopies();
98}
99
100bool QPrintDevice::supportsCollateCopies() const
101{
102 return isValid() && d->supportsCollateCopies();
103}
104
105QPageSize QPrintDevice::defaultPageSize() const
106{
107 return isValid() ? d->defaultPageSize() : QPageSize();
108}
109
110QList<QPageSize> QPrintDevice::supportedPageSizes() const
111{
112 return isValid() ? d->supportedPageSizes() : QList<QPageSize>();
113}
114
115QPageSize QPrintDevice::supportedPageSize(const QPageSize &pageSize) const
116{
117 return isValid() ? d->supportedPageSize(pageSize) : QPageSize();
118}
119
120QPageSize QPrintDevice::supportedPageSize(QPageSize::PageSizeId pageSizeId) const
121{
122 return isValid() ? d->supportedPageSize(pageSizeId) : QPageSize();
123}
124
125QPageSize QPrintDevice::supportedPageSize(const QString &pageName) const
126{
127 return isValid() ? d->supportedPageSize(pageName) : QPageSize();
128}
129
130QPageSize QPrintDevice::supportedPageSize(const QSize &pointSize) const
131{
132 return isValid() ? d->supportedPageSize(pointSize) : QPageSize();
133}
134
135QPageSize QPrintDevice::supportedPageSize(const QSizeF &size, QPageSize::Unit units) const
136{
137 return isValid() ? d->supportedPageSize(size, units) : QPageSize();
138}
139
140bool QPrintDevice::supportsCustomPageSizes() const
141{
142 return isValid() && d->supportsCustomPageSizes();
143}
144
145QSize QPrintDevice::minimumPhysicalPageSize() const
146{
147 return isValid() ? d->minimumPhysicalPageSize() : QSize();
148}
149
150QSize QPrintDevice::maximumPhysicalPageSize() const
151{
152 return isValid() ? d->maximumPhysicalPageSize() : QSize();
153}
154
155QMarginsF QPrintDevice::printableMargins(const QPageSize &pageSize,
156 QPageLayout::Orientation orientation,
157 int resolution) const
158{
159 return isValid() ? d->printableMargins(pageSize, orientation, resolution) : QMarginsF();
160}
161
162int QPrintDevice::defaultResolution() const
163{
164 return isValid() ? d->defaultResolution() : 0;
165}
166
167QList<int> QPrintDevice::supportedResolutions() const
168{
169 return isValid() ? d->supportedResolutions() : QList<int>();
170}
171
172QPrint::InputSlot QPrintDevice::defaultInputSlot() const
173{
174 return isValid() ? d->defaultInputSlot() : QPrint::InputSlot();
175}
176
177QList<QPrint::InputSlot> QPrintDevice::supportedInputSlots() const
178{
179 return isValid() ? d->supportedInputSlots() : QList<QPrint::InputSlot>{};
180}
181
182QPrint::OutputBin QPrintDevice::defaultOutputBin() const
183{
184 return isValid() ? d->defaultOutputBin() : QPrint::OutputBin();
185}
186
187QList<QPrint::OutputBin> QPrintDevice::supportedOutputBins() const
188{
189 return isValid() ? d->supportedOutputBins() : QList<QPrint::OutputBin>{};
190}
191
192QPrint::DuplexMode QPrintDevice::defaultDuplexMode() const
193{
194 return isValid() ? d->defaultDuplexMode() : QPrint::DuplexNone;
195}
196
197QList<QPrint::DuplexMode> QPrintDevice::supportedDuplexModes() const
198{
199 return isValid() ? d->supportedDuplexModes() : QList<QPrint::DuplexMode>{};
200}
201
202QPrint::ColorMode QPrintDevice::defaultColorMode() const
203{
204 return isValid() ? d->defaultColorMode() : QPrint::GrayScale;
205}
206
207QList<QPrint::ColorMode> QPrintDevice::supportedColorModes() const
208{
209 return isValid() ? d->supportedColorModes() : QList<QPrint::ColorMode>{};
210}
211
212QVariant QPrintDevice::property(PrintDevicePropertyKey key) const
213{
214 return isValid() ? d->property(key) : QVariant();
215}
216
217bool QPrintDevice::setProperty(PrintDevicePropertyKey key, const QVariant &value)
218{
219 return isValid() ? d->setProperty(key, value) : false;
220}
221
222bool QPrintDevice::isFeatureAvailable(PrintDevicePropertyKey key, const QVariant &params) const
223{
224 return isValid() ? d->isFeatureAvailable(key, params) : false;
225}
226
227#if QT_CONFIG(mimetype)
228QList<QMimeType> QPrintDevice::supportedMimeTypes() const
229{
230 return isValid() ? d->supportedMimeTypes() : QList<QMimeType>();
231}
232#endif // mimetype
233
234# ifndef QT_NO_DEBUG_STREAM
235void QPrintDevice::format(QDebug debug) const
236{
237 QDebugStateSaver saver(debug);
238 debug.noquote();
239 debug.nospace();
240 if (isValid()) {
241 const QString deviceId = id();
242 const QString deviceName = name();
243 debug << "id=\"" << deviceId << "\", state=" << state();
244 if (!deviceName.isEmpty() && deviceName != deviceId)
245 debug << ", name=\"" << deviceName << '"';
246 if (!location().isEmpty())
247 debug << ", location=\"" << location() << '"';
248 debug << ", makeAndModel=\"" << makeAndModel() << '"';
249 if (isDefault())
250 debug << ", default";
251 if (isRemote())
252 debug << ", remote";
253 debug << ", defaultPageSize=" << defaultPageSize();
254 if (supportsCustomPageSizes())
255 debug << ", supportsCustomPageSizes";
256 debug << ", physicalPageSize=(";
257 QtDebugUtils::formatQSize(debug, size: minimumPhysicalPageSize());
258 debug << ")..(";
259 QtDebugUtils::formatQSize(debug, size: maximumPhysicalPageSize());
260 debug << "), defaultResolution=" << defaultResolution()
261 << ", defaultDuplexMode=" << defaultDuplexMode()
262 << ", defaultColorMode="<< defaultColorMode();
263# if QT_CONFIG(mimetype)
264 const QList<QMimeType> mimeTypes = supportedMimeTypes();
265 if (!mimeTypes.isEmpty()) {
266 debug << ", supportedMimeTypes=(";
267 for (const auto &mimeType : mimeTypes)
268 debug << " \"" << mimeType.name() << '"';
269 debug << ')';
270 }
271# endif // mimetype
272 } else {
273 debug << "null";
274 }
275}
276
277QDebug operator<<(QDebug debug, const QPrintDevice &p)
278{
279 QDebugStateSaver saver(debug);
280 debug.nospace();
281 debug << "QPrintDevice(";
282 p.format(debug);
283 debug << ')';
284 return debug;
285}
286# endif // QT_NO_DEBUG_STREAM
287#endif // QT_NO_PRINTER
288
289QT_END_NAMESPACE
290

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