Qt 6.x
The Qt SDK
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
5
6#include "qprintdevice_p.h"
7
8#include <QtCore/qcoreapplication.h>
9#include <QtGui/qpagelayout.h>
10
12
13#ifndef QT_NO_PRINTER
14
16 : m_id(id),
17 m_isRemote(false),
18 m_supportsMultipleCopies(false),
19 m_supportsCollateCopies(false),
20 m_havePageSizes(false),
21 m_supportsCustomPageSizes(false),
22 m_haveResolutions(false),
23 m_haveInputSlots(false),
24 m_haveOutputBins(false),
25 m_haveDuplexModes(false),
26 m_haveColorModes(false)
27#if QT_CONFIG(mimetype)
28 , m_haveMimeTypes(false)
29#endif
30{
31}
32
34{
35}
36
38{
39 return m_id;
40}
41
43{
44 return m_name;
45}
46
48{
49 return m_location;
50}
51
53{
54 return m_makeAndModel;
55}
56
58{
59 return false;
60}
61
63{
64 return false;
65}
66
68{
69 return m_isRemote;
70}
71
73{
74 // Check the page size is supported
75 if (!supportedPageSize(layout.pageSize()).isValid())
76 return false;
77
78 // Check the margins are valid
79 QMarginsF pointMargins = layout.margins(QPageLayout::Point);
80 QMarginsF printMargins = printableMargins(layout.pageSize(), layout.orientation(), resolution);
81 return pointMargins.left() >= printMargins.left()
82 && pointMargins.right() >= printMargins.right()
83 && pointMargins.top() >= printMargins.top()
84 && pointMargins.bottom() >= printMargins.bottom();
85}
86
88{
89 return QPrint::Error;
90}
91
93{
95}
96
98{
100}
101
103{
104}
105
107{
108 return QPageSize();
109}
110
112{
113 if (!m_havePageSizes)
115 return m_pageSizes;
116}
117
119{
120 if (!pageSize.isValid())
121 return QPageSize();
122
123 if (!m_havePageSizes)
125
126 // First try match on name and id for case where printer defines same size twice with different names
127 // e.g. Windows defines DMPAPER_11X17 and DMPAPER_TABLOID with names "11x17" and "Tabloid", but both
128 // map to QPageSize::Tabloid / PPD Key "Tabloid" / ANSI B Tabloid
129 if (pageSize.id() != QPageSize::Custom) {
130 for (const QPageSize &ps : std::as_const(m_pageSizes)) {
131 if (ps.id() == pageSize.id() && ps.name() == pageSize.name())
132 return ps;
133 }
134 }
135
136 // Next try match on id only if not custom
137 if (pageSize.id() != QPageSize::Custom) {
138 for (const QPageSize &ps : std::as_const(m_pageSizes)) {
139 if (ps.id() == pageSize.id())
140 return ps;
141 }
142 }
143
144 // Next try a match on size, in case it's a custom with a different name
145 return supportedPageSizeMatch(pageSize);
146}
147
149{
150 if (!m_havePageSizes)
152
153 for (const QPageSize &ps : std::as_const(m_pageSizes)) {
154 if (ps.id() == pageSizeId)
155 return ps;
156 }
157
158 // If no supported page size found, try use a custom size instead if supported
159 return supportedPageSizeMatch(QPageSize(pageSizeId));
160}
161
163{
164 if (!m_havePageSizes)
166
167 for (const QPageSize &ps : std::as_const(m_pageSizes)) {
168 if (ps.name() == pageName)
169 return ps;
170 }
171
172 return QPageSize();
173}
174
176{
177 if (!m_havePageSizes)
179
180 // Try to find a supported page size based on fuzzy-matched point size
181 return supportedPageSizeMatch(QPageSize(sizePoints));
182}
183
185{
186 if (!m_havePageSizes)
188
189 // Try to find a supported page size based on fuzzy-matched unit size
191}
192
194{
195 // If it's a known page size, just return itself
196 if (m_pageSizes.contains(pageSize))
197 return pageSize;
198
199 // Try to find a supported page size based on point size
200 for (const QPageSize &ps : std::as_const(m_pageSizes)) {
201 if (ps.sizePoints() == pageSize.sizePoints())
202 return ps;
203 }
204 return QPageSize();
205}
206
208{
210}
211
213{
215}
216
218{
220}
221
223 QPageLayout::Orientation orientation,
224 int resolution) const
225{
226 Q_UNUSED(pageSize);
227 Q_UNUSED(orientation);
228 Q_UNUSED(resolution);
229 return QMarginsF(0, 0, 0, 0);
230}
231
233{
234}
235
237{
238 return 0;
239}
240
242{
245 return m_resolutions;
246}
247
249{
250}
251
253{
255 input.key = QByteArrayLiteral("Auto");
256 input.name = QCoreApplication::translate("Print Device Input Slot", "Automatic");
257 input.id = QPrint::Auto;
258 return input;
259}
260
262{
263 if (!m_haveInputSlots)
265 return m_inputSlots;
266}
267
269{
270}
271
273{
275 output.key = QByteArrayLiteral("Auto");
276 output.name = QCoreApplication::translate("Print Device Output Bin", "Automatic");
278 return output;
279}
280
282{
283 if (!m_haveOutputBins)
285 return m_outputBins;
286}
287
289{
290}
291
293{
294 return QPrint::DuplexNone;
295}
296
298{
301 return m_duplexModes;
302}
303
305{
306}
307
309{
310 return QPrint::GrayScale;
311}
312
314{
315 if (!m_haveColorModes)
317 return m_colorModes;
318}
319
320#if QT_CONFIG(mimetype)
321void QPlatformPrintDevice::loadMimeTypes() const
322{
323}
324#endif // mimetype
325
327{
328 Q_UNUSED(key);
329
330 return QVariant();
331}
332
334{
335 Q_UNUSED(key);
337
338 return false;
339}
340
342{
343 Q_UNUSED(key);
345
346 return false;
347}
348
349#if QT_CONFIG(mimetype)
350QList<QMimeType> QPlatformPrintDevice::supportedMimeTypes() const
351{
352 if (!m_haveMimeTypes)
353 loadMimeTypes();
354 return m_mimeTypes;
355}
356#endif // mimetype
357
359{
360 return QPageSize(key, size, localizedName);
361}
362
363QPageSize QPlatformPrintDevice::createPageSize(int windowsId, const QSize &size, const QString &localizedName)
364{
365 return QPageSize(windowsId, size, localizedName);
366}
367
368#endif // QT_NO_PRINTER
369
static QString translate(const char *context, const char *key, const char *disambiguation=nullptr, int n=-1)
\threadsafe
Definition qlist.h:74
\inmodule QtCore
Definition qmargins.h:274
constexpr qreal right() const noexcept
Returns the right margin.
Definition qmargins.h:370
constexpr qreal left() const noexcept
Returns the left margin.
Definition qmargins.h:364
constexpr qreal top() const noexcept
Returns the top margin.
Definition qmargins.h:367
constexpr qreal bottom() const noexcept
Returns the bottom margin.
Definition qmargins.h:373
\inmodule QtGui
Definition qpagelayout.h:20
Orientation
This enum type defines the page orientation.
Definition qpagelayout.h:33
\inmodule QtGui
Definition qpagesize.h:22
bool isValid() const
Returns true if this page size is valid.
Unit
This enum type is used to specify the measurement unit for page sizes.
Definition qpagesize.h:175
QString name() const
Returns a localized human-readable name for the page size.
QSize sizePoints() const
Returns the size of the page in Postscript Points (1/72 of an inch).
PageSizeId id() const
Returns the standard QPageSize::PageSizeId of the page, or QPageSize::Custom.
PageSizeId
This enum type lists the available page sizes as defined in the Postscript PPD standard.
Definition qpagesize.h:25
virtual QString id() const
virtual bool supportsCollateCopies() const
virtual bool isFeatureAvailable(QPrintDevice::PrintDevicePropertyKey key, const QVariant &params) const
virtual QPrint::ColorMode defaultColorMode() const
virtual void loadColorModes() const
static QPageSize createPageSize(const QString &key, const QSize &size, const QString &localizedName)
virtual QSize maximumPhysicalPageSize() const
virtual QPageSize supportedPageSize(const QPageSize &pageSize) const
virtual void loadInputSlots() const
virtual QList< QPrint::OutputBin > supportedOutputBins() const
virtual bool isDefault() const
virtual void loadDuplexModes() const
QPlatformPrintDevice(const QString &id=QString())
virtual QList< QPrint::InputSlot > supportedInputSlots() const
virtual bool supportsCustomPageSizes() const
virtual QList< QPrint::ColorMode > supportedColorModes() const
QPageSize supportedPageSizeMatch(const QPageSize &pageSize) const
QList< QPrint::InputSlot > m_inputSlots
virtual void loadResolutions() const
virtual bool isValid() const
virtual int defaultResolution() const
virtual bool isRemote() const
virtual QVariant property(QPrintDevice::PrintDevicePropertyKey key) const
virtual QPageSize defaultPageSize() const
QList< QPrint::ColorMode > m_colorModes
virtual bool supportsMultipleCopies() const
virtual void loadOutputBins() const
virtual bool setProperty(QPrintDevice::PrintDevicePropertyKey key, const QVariant &value)
QList< QPageSize > m_pageSizes
virtual bool isValidPageLayout(const QPageLayout &layout, int resolution) const
virtual QList< QPageSize > supportedPageSizes() const
virtual QPrint::DeviceState state() const
virtual void loadPageSizes() const
virtual QString name() const
virtual QPrint::InputSlot defaultInputSlot() const
QList< QPrint::OutputBin > m_outputBins
virtual QList< int > supportedResolutions() const
virtual QList< QPrint::DuplexMode > supportedDuplexModes() const
virtual QPrint::DuplexMode defaultDuplexMode() const
virtual QMarginsF printableMargins(const QPageSize &pageSize, QPageLayout::Orientation orientation, int resolution) const
virtual QString makeAndModel() const
QList< QPrint::DuplexMode > m_duplexModes
virtual QString location() const
virtual QSize minimumPhysicalPageSize() const
virtual QPrint::OutputBin defaultOutputBin() const
\inmodule QtCore
Definition qsize.h:207
\inmodule QtCore
Definition qsize.h:25
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:127
\inmodule QtCore
Definition qvariant.h:64
ColorMode
Definition qprint_p.h:71
@ GrayScale
Definition qprint_p.h:72
DuplexMode
Definition qprint_p.h:64
@ DuplexNone
Definition qprint_p.h:65
@ Auto
Definition qprint_p.h:85
@ AutoOutputBin
Definition qprint_p.h:106
DeviceState
Definition qprint_p.h:56
@ Error
Definition qprint_p.h:60
Combined button and popup list for selecting options.
#define QByteArrayLiteral(str)
Definition qbytearray.h:52
EGLOutputLayerEXT EGLint EGLAttrib value
[5]
GLuint64 key
GLenum GLuint GLintptr GLsizeiptr size
[1]
GLenum GLuint id
[7]
GLfloat units
void ** params
GLenum GLenum GLenum input
#define QT_CONFIG(feature)
#define Q_UNUSED(x)
QT_BEGIN_NAMESPACE typedef uchar * output
if(qFloatDistance(a, b)<(1<< 7))
[0]
QVBoxLayout * layout
bool contains(const AT &t) const noexcept
Definition qlist.h:44