Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Toggle main menu visibility
Loading...
Searching...
No Matches
qplatformprintdevice.cpp
Go to the documentation of this file.
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
// Qt-Security score:significant reason:default
4
5
#
include
"qplatformprintdevice.h"
6
7
#
include
"qprintdevice_p.h"
8
9
#
include
<
QtCore
/
qcoreapplication
.
h
>
10
#
include
<
QtGui
/
qpagelayout
.
h
>
11
12
QT_BEGIN_NAMESPACE
13
14
#
ifndef
QT_NO_PRINTER
15
16
QPlatformPrintDevice::QPlatformPrintDevice(
const
QString &id)
17
: m_id(id),
18
m_isRemote(
false
),
19
m_supportsMultipleCopies(
false
),
20
m_supportsCollateCopies(
false
),
21
m_havePageSizes(
false
),
22
m_supportsCustomPageSizes(
false
),
23
m_haveResolutions(
false
),
24
m_haveInputSlots(
false
),
25
m_haveOutputBins(
false
),
26
m_haveDuplexModes(
false
),
27
m_haveColorModes(
false
)
28
#
if
QT_CONFIG
(
mimetype
)
29
, m_haveMimeTypes(
false
)
30
#
endif
31
{
32
}
33
34
QPlatformPrintDevice::~QPlatformPrintDevice()
35
{
36
}
37
38
QString QPlatformPrintDevice::id()
const
39
{
40
return
m_id;
41
}
42
43
QString QPlatformPrintDevice::name()
const
44
{
45
return
m_name;
46
}
47
48
QString QPlatformPrintDevice::location()
const
49
{
50
return
m_location;
51
}
52
53
QString QPlatformPrintDevice::makeAndModel()
const
54
{
55
return
m_makeAndModel;
56
}
57
58
bool
QPlatformPrintDevice::isValid()
const
59
{
60
return
false
;
61
}
62
63
bool
QPlatformPrintDevice::isDefault()
const
64
{
65
return
false
;
66
}
67
68
bool
QPlatformPrintDevice::isRemote()
const
69
{
70
return
m_isRemote;
71
}
72
73
bool
QPlatformPrintDevice::isValidPageLayout(
const
QPageLayout &layout,
int
resolution)
const
74
{
75
// Check the page size is supported
76
if
(!supportedPageSize(layout.pageSize()).isValid())
77
return
false
;
78
79
// In fullpage mode, margins outside the printable area are valid
80
if
(layout.mode() == QPageLayout::FullPageMode)
81
return
true
;
82
83
// Check the margins are valid
84
QMarginsF pointMargins = layout.margins(QPageLayout::Point);
85
QMarginsF printMargins = printableMargins(layout.pageSize(), layout.orientation(), resolution);
86
return
pointMargins.left() >= printMargins.left()
87
&& pointMargins.right() >= printMargins.right()
88
&& pointMargins.top() >= printMargins.top()
89
&& pointMargins.bottom() >= printMargins.bottom();
90
}
91
92
QPrint::DeviceState QPlatformPrintDevice::state()
const
93
{
94
return
QPrint::Error;
95
}
96
97
bool
QPlatformPrintDevice::supportsMultipleCopies()
const
98
{
99
return
m_supportsMultipleCopies;
100
}
101
102
bool
QPlatformPrintDevice::supportsCollateCopies()
const
103
{
104
return
m_supportsCollateCopies;
105
}
106
107
void
QPlatformPrintDevice::loadPageSizes()
const
108
{
109
}
110
111
QPageSize QPlatformPrintDevice::defaultPageSize()
const
112
{
113
return
QPageSize();
114
}
115
116
QList<QPageSize> QPlatformPrintDevice::supportedPageSizes()
const
117
{
118
if
(!m_havePageSizes)
119
loadPageSizes();
120
return
m_pageSizes;
121
}
122
123
QPageSize QPlatformPrintDevice::supportedPageSize(
const
QPageSize &pageSize)
const
124
{
125
if
(!pageSize.isValid())
126
return
QPageSize();
127
128
if
(!m_havePageSizes)
129
loadPageSizes();
130
131
// First try match on name and id for case where printer defines same size twice with different names
132
// e.g. Windows defines DMPAPER_11X17 and DMPAPER_TABLOID with names "11x17" and "Tabloid", but both
133
// map to QPageSize::Tabloid / PPD Key "Tabloid" / ANSI B Tabloid
134
if
(pageSize.id() != QPageSize::Custom) {
135
for
(
const
QPageSize &ps : std::as_const(m_pageSizes)) {
136
if
(ps.id() == pageSize.id() && ps.name() == pageSize.name())
137
return
ps;
138
}
139
}
140
141
// Next try match on id only if not custom
142
if
(pageSize.id() != QPageSize::Custom) {
143
for
(
const
QPageSize &ps : std::as_const(m_pageSizes)) {
144
if
(ps.id() == pageSize.id())
145
return
ps;
146
}
147
}
148
149
// Next try a match on size, in case it's a custom with a different name
150
return
supportedPageSizeMatch(pageSize);
151
}
152
153
QPageSize QPlatformPrintDevice::supportedPageSize(QPageSize::PageSizeId pageSizeId)
const
154
{
155
if
(!m_havePageSizes)
156
loadPageSizes();
157
158
for
(
const
QPageSize &ps : std::as_const(m_pageSizes)) {
159
if
(ps.id() == pageSizeId)
160
return
ps;
161
}
162
163
// If no supported page size found, try use a custom size instead if supported
164
return
supportedPageSizeMatch(QPageSize(pageSizeId));
165
}
166
167
QPageSize QPlatformPrintDevice::supportedPageSize(
const
QString &pageName)
const
168
{
169
if
(!m_havePageSizes)
170
loadPageSizes();
171
172
for
(
const
QPageSize &ps : std::as_const(m_pageSizes)) {
173
if
(ps.name() == pageName)
174
return
ps;
175
}
176
177
return
QPageSize();
178
}
179
180
QPageSize QPlatformPrintDevice::supportedPageSize(
const
QSize &sizePoints)
const
181
{
182
if
(!m_havePageSizes)
183
loadPageSizes();
184
185
// Try to find a supported page size based on fuzzy-matched point size
186
return
supportedPageSizeMatch(QPageSize(sizePoints));
187
}
188
189
QPageSize QPlatformPrintDevice::supportedPageSize(
const
QSizeF &size, QPageSize::Unit units)
const
190
{
191
if
(!m_havePageSizes)
192
loadPageSizes();
193
194
// Try to find a supported page size based on fuzzy-matched unit size
195
return
supportedPageSizeMatch(QPageSize(size, units));
196
}
197
198
QPageSize QPlatformPrintDevice::supportedPageSizeMatch(
const
QPageSize &pageSize)
const
199
{
200
// If it's a known page size, just return itself
201
if
(m_pageSizes.contains(pageSize))
202
return
pageSize;
203
204
// Try to find a supported page size based on point size
205
for
(
const
QPageSize &ps : std::as_const(m_pageSizes)) {
206
if
(ps.sizePoints() == pageSize.sizePoints())
207
return
ps;
208
}
209
return
QPageSize();
210
}
211
212
bool
QPlatformPrintDevice::supportsCustomPageSizes()
const
213
{
214
return
m_supportsCustomPageSizes;
215
}
216
217
QSize QPlatformPrintDevice::minimumPhysicalPageSize()
const
218
{
219
return
m_minimumPhysicalPageSize;
220
}
221
222
QSize QPlatformPrintDevice::maximumPhysicalPageSize()
const
223
{
224
return
m_maximumPhysicalPageSize;
225
}
226
227
QMarginsF QPlatformPrintDevice::printableMargins(
const
QPageSize &pageSize,
228
QPageLayout::Orientation orientation,
229
int
resolution)
const
230
{
231
Q_UNUSED(pageSize);
232
Q_UNUSED(orientation);
233
Q_UNUSED(resolution);
234
return
QMarginsF(0, 0, 0, 0);
235
}
236
237
void
QPlatformPrintDevice::loadResolutions()
const
238
{
239
}
240
241
int
QPlatformPrintDevice::defaultResolution()
const
242
{
243
return
0;
244
}
245
246
QList<
int
> QPlatformPrintDevice::supportedResolutions()
const
247
{
248
if
(!m_haveResolutions)
249
loadResolutions();
250
return
m_resolutions;
251
}
252
253
void
QPlatformPrintDevice::loadInputSlots()
const
254
{
255
}
256
257
QPrint::InputSlot QPlatformPrintDevice::defaultInputSlot()
const
258
{
259
QPrint::InputSlot input;
260
input.key = QByteArrayLiteral(
"Auto"
);
261
input.name = QCoreApplication::translate(
"Print Device Input Slot"
,
"Automatic"
);
262
input.id = QPrint::Auto;
263
return
input;
264
}
265
266
QList<QPrint::InputSlot> QPlatformPrintDevice::supportedInputSlots()
const
267
{
268
if
(!m_haveInputSlots)
269
loadInputSlots();
270
return
m_inputSlots;
271
}
272
273
void
QPlatformPrintDevice::loadOutputBins()
const
274
{
275
}
276
277
QPrint::OutputBin QPlatformPrintDevice::defaultOutputBin()
const
278
{
279
QPrint::OutputBin output;
280
output.key = QByteArrayLiteral(
"Auto"
);
281
output.name = QCoreApplication::translate(
"Print Device Output Bin"
,
"Automatic"
);
282
output.id = QPrint::AutoOutputBin;
283
return
output;
284
}
285
286
QList<QPrint::OutputBin> QPlatformPrintDevice::supportedOutputBins()
const
287
{
288
if
(!m_haveOutputBins)
289
loadOutputBins();
290
return
m_outputBins;
291
}
292
293
void
QPlatformPrintDevice::loadDuplexModes()
const
294
{
295
}
296
297
QPrint::DuplexMode QPlatformPrintDevice::defaultDuplexMode()
const
298
{
299
return
QPrint::DuplexNone;
300
}
301
302
QList<QPrint::DuplexMode> QPlatformPrintDevice::supportedDuplexModes()
const
303
{
304
if
(!m_haveDuplexModes)
305
loadDuplexModes();
306
return
m_duplexModes;
307
}
308
309
void
QPlatformPrintDevice::loadColorModes()
const
310
{
311
}
312
313
QPrint::ColorMode QPlatformPrintDevice::defaultColorMode()
const
314
{
315
return
QPrint::GrayScale;
316
}
317
318
QList<QPrint::ColorMode> QPlatformPrintDevice::supportedColorModes()
const
319
{
320
if
(!m_haveColorModes)
321
loadColorModes();
322
return
m_colorModes;
323
}
324
325
#
if
QT_CONFIG
(
mimetype
)
326
void
QPlatformPrintDevice::loadMimeTypes()
const
327
{
328
}
329
#
endif
// mimetype
330
331
QVariant QPlatformPrintDevice::property(QPrintDevice::PrintDevicePropertyKey key,
332
const
QVariant ¶ms)
const
333
{
334
Q_UNUSED(key);
335
Q_UNUSED(params);
336
337
return
QVariant();
338
}
339
340
bool
QPlatformPrintDevice::setProperty(QPrintDevice::PrintDevicePropertyKey key,
const
QVariant &value)
341
{
342
Q_UNUSED(key);
343
Q_UNUSED(value);
344
345
return
false
;
346
}
347
348
bool
QPlatformPrintDevice::isFeatureAvailable(QPrintDevice::PrintDevicePropertyKey key,
const
QVariant ¶ms)
const
349
{
350
Q_UNUSED(key);
351
Q_UNUSED(params);
352
353
return
false
;
354
}
355
356
#
if
QT_CONFIG
(
mimetype
)
357
QList<QMimeType> QPlatformPrintDevice::supportedMimeTypes()
const
358
{
359
if
(!m_haveMimeTypes)
360
loadMimeTypes();
361
return
m_mimeTypes;
362
}
363
#
endif
// mimetype
364
365
QPageSize QPlatformPrintDevice::createPageSize(
const
QString &key,
const
QSize &size,
const
QString &localizedName)
366
{
367
return
QPageSize(key, size, localizedName);
368
}
369
370
QPageSize QPlatformPrintDevice::createPageSize(
int
windowsId,
const
QSize &size,
const
QString &localizedName)
371
{
372
return
QPageSize(windowsId, size, localizedName);
373
}
374
375
#
endif
// QT_NO_PRINTER
376
377
QT_END_NAMESPACE
QT_BEGIN_NAMESPACE
Combined button and popup list for selecting options.
Definition
qsequentialanimationgroup.cpp:47
qtbase
src
printsupport
kernel
qplatformprintdevice.cpp
Generated on
for Qt by
1.18.0