Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
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
36
38{
39 return m_id;
40}
41
43{
44 return m_name;
45}
46
51
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 // In fullpage mode, margins outside the printable area are valid
80 return true;
81
82 // Check the margins are valid
83 QMarginsF pointMargins = layout.margins(QPageLayout::Point);
84 QMarginsF printMargins = printableMargins(layout.pageSize(), layout.orientation(), resolution);
85 return pointMargins.left() >= printMargins.left()
86 && pointMargins.right() >= printMargins.right()
87 && pointMargins.top() >= printMargins.top()
88 && pointMargins.bottom() >= printMargins.bottom();
89}
90
95
100
105
109
114
116{
117 if (!m_havePageSizes)
119 return m_pageSizes;
120}
121
123{
124 if (!pageSize.isValid())
125 return QPageSize();
126
127 if (!m_havePageSizes)
129
130 // First try match on name and id for case where printer defines same size twice with different names
131 // e.g. Windows defines DMPAPER_11X17 and DMPAPER_TABLOID with names "11x17" and "Tabloid", but both
132 // map to QPageSize::Tabloid / PPD Key "Tabloid" / ANSI B Tabloid
133 if (pageSize.id() != QPageSize::Custom) {
134 for (const QPageSize &ps : std::as_const(m_pageSizes)) {
135 if (ps.id() == pageSize.id() && ps.name() == pageSize.name())
136 return ps;
137 }
138 }
139
140 // Next try match on id only if not custom
141 if (pageSize.id() != QPageSize::Custom) {
142 for (const QPageSize &ps : std::as_const(m_pageSizes)) {
143 if (ps.id() == pageSize.id())
144 return ps;
145 }
146 }
147
148 // Next try a match on size, in case it's a custom with a different name
149 return supportedPageSizeMatch(pageSize);
150}
151
153{
154 if (!m_havePageSizes)
156
157 for (const QPageSize &ps : std::as_const(m_pageSizes)) {
158 if (ps.id() == pageSizeId)
159 return ps;
160 }
161
162 // If no supported page size found, try use a custom size instead if supported
163 return supportedPageSizeMatch(QPageSize(pageSizeId));
164}
165
167{
168 if (!m_havePageSizes)
170
171 for (const QPageSize &ps : std::as_const(m_pageSizes)) {
172 if (ps.name() == pageName)
173 return ps;
174 }
175
176 return QPageSize();
177}
178
180{
181 if (!m_havePageSizes)
183
184 // Try to find a supported page size based on fuzzy-matched point size
185 return supportedPageSizeMatch(QPageSize(sizePoints));
186}
187
189{
190 if (!m_havePageSizes)
192
193 // Try to find a supported page size based on fuzzy-matched unit size
195}
196
198{
199 // If it's a known page size, just return itself
200 if (m_pageSizes.contains(pageSize))
201 return pageSize;
202
203 // Try to find a supported page size based on point size
204 for (const QPageSize &ps : std::as_const(m_pageSizes)) {
205 if (ps.sizePoints() == pageSize.sizePoints())
206 return ps;
207 }
208 return QPageSize();
209}
210
215
220
225
227 QPageLayout::Orientation orientation,
228 int resolution) const
229{
230 Q_UNUSED(pageSize);
231 Q_UNUSED(orientation);
232 Q_UNUSED(resolution);
233 return QMarginsF(0, 0, 0, 0);
234}
235
239
241{
242 return 0;
243}
244
246{
249 return m_resolutions;
250}
251
255
257{
259 input.key = QByteArrayLiteral("Auto");
260 input.name = QCoreApplication::translate("Print Device Input Slot", "Automatic");
261 input.id = QPrint::Auto;
262 return input;
263}
264
265QList<QPrint::InputSlot> QPlatformPrintDevice::supportedInputSlots() const
266{
267 if (!m_haveInputSlots)
269 return m_inputSlots;
270}
271
275
277{
279 output.key = QByteArrayLiteral("Auto");
280 output.name = QCoreApplication::translate("Print Device Output Bin", "Automatic");
282 return output;
283}
284
285QList<QPrint::OutputBin> QPlatformPrintDevice::supportedOutputBins() const
286{
287 if (!m_haveOutputBins)
289 return m_outputBins;
290}
291
295
300
301QList<QPrint::DuplexMode> QPlatformPrintDevice::supportedDuplexModes() const
302{
305 return m_duplexModes;
306}
307
311
316
317QList<QPrint::ColorMode> QPlatformPrintDevice::supportedColorModes() const
318{
319 if (!m_haveColorModes)
321 return m_colorModes;
322}
323
324#if QT_CONFIG(mimetype)
325void QPlatformPrintDevice::loadMimeTypes() const
326{
327}
328#endif // mimetype
329
336
344
352
353#if QT_CONFIG(mimetype)
354QList<QMimeType> QPlatformPrintDevice::supportedMimeTypes() const
355{
356 if (!m_haveMimeTypes)
357 loadMimeTypes();
358 return m_mimeTypes;
359}
360#endif // mimetype
361
363{
364 return QPageSize(key, size, localizedName);
365}
366
367QPageSize QPlatformPrintDevice::createPageSize(int windowsId, const QSize &size, const QString &localizedName)
368{
369 return QPageSize(windowsId, size, localizedName);
370}
371
372#endif // QT_NO_PRINTER
373
static QString translate(const char *context, const char *key, const char *disambiguation=nullptr, int n=-1)
\threadsafe
\inmodule QtCore
Definition qmargins.h:270
\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:208
\inmodule QtCore
Definition qsize.h:25
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:129
\inmodule QtCore
Definition qvariant.h:65
ColorMode
Definition qprint_p.h:72
@ GrayScale
Definition qprint_p.h:73
DuplexMode
Definition qprint_p.h:64
@ DuplexNone
Definition qprint_p.h:65
@ Auto
Definition qprint_p.h:86
@ AutoOutputBin
Definition qprint_p.h:107
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:45
QByteArray key
Definition qprint_p.h:100