6#include <qpa/qplatformprintplugin.h>
7#include <qpa/qplatformprintersupport.h>
13#include "private/qcups_p.h"
14#include <QtGui/qpagelayout.h>
18#include "private/qcore_unix_p.h"
28 d->changePrinter(deviceId);
52 d->setPageSize(
d->m_printDevice.supportedPageSize(
value.toString()));
56 if (
d->m_printDevice.supportedDuplexModes().contains(
mode)) {
58 d->duplexRequestedExplicitly =
true;
63 d->changePrinter(
value.toString());
66 d->cupsOptions =
value.toStringList();
69 d->setPageSize(qvariant_cast<QPageSize>(
value));
74 ||
d->m_printDevice.supportsCustomPageSizes()
75 ||
d->m_printDevice.supportedPageSizes().isEmpty())) {
103 ret =
d->cupsOptions;
118 , duplex(
QPrint::DuplexNone)
140 fd = cupsTempFd(filename, 512);
142 qWarning(
"QPdfPrinter: Could not open temporary file to print");
148 qWarning(
"QPdfPrinter: Could not open CUPS temporary file descriptor: %s",
153#if defined(Q_OS_WIN) && defined(Q_CC_MSVC)
172 cupsTempFile.
clear();
175 if (printerName.isEmpty()) {
176 qWarning(
"Could not determine printer to print to");
182 QList<QPair<QByteArray, QByteArray> > options;
183 QList<cups_option_t> cupsOptStruct;
190 if (copies > 1 && collate)
191 options.append(QPair<QByteArray, QByteArray>(
"Collate",
"True"));
195 options.append(QPair<QByteArray, QByteArray>(
"sides",
"one-sided"));
199 options.append(QPair<QByteArray, QByteArray>(
"sides",
"two-sided-long-edge"));
201 options.append(QPair<QByteArray, QByteArray>(
"sides",
"two-sided-short-edge"));
204 options.append(QPair<QByteArray, QByteArray>(
"sides",
"two-sided-long-edge"));
207 options.append(QPair<QByteArray, QByteArray>(
"sides",
"two-sided-short-edge"));
212 options.append(QPair<QByteArray, QByteArray>(
"landscape",
""));
214 QStringList::const_iterator
it = cupsOptions.constBegin();
215 while (
it != cupsOptions.constEnd()) {
216 options.append(QPair<QByteArray, QByteArray>((*it).toLocal8Bit(), (*(
it+1)).toLocal8Bit()));
220 const int numOptions = options.size();
221 cupsOptStruct.reserve(numOptions);
222 for (
int c = 0;
c < numOptions; ++
c) {
224 opt.name = options[
c].first.data();
225 opt.value = options[
c].second.data();
226 cupsOptStruct.append(
opt);
232 const auto printerOriginalName = parts.at(0);
233 cups_option_t* optPtr = cupsOptStruct.size() ? &cupsOptStruct.first() : 0;
234 cupsPrintFile(printerOriginalName.toLocal8Bit().constData(),
tempFile.toLocal8Bit().constData(),
241void QCupsPrintEnginePrivate::changePrinter(
const QString &newPrinter)
244 if (newPrinter == printerName)
254 if (!printDevice.isValid())
256 m_printDevice.
swap(printDevice);
257 printerName = m_printDevice.
id();
263 duplexRequestedExplicitly =
false;
279void QCupsPrintEnginePrivate::setPageSize(
const QPageSize &pageSize)
284 QPageSize usePageSize = printerPageSize.
isValid() ? printerPageSize : pageSize;
const char * constData() const noexcept
Returns a pointer to the const data stored in the byte array.
~QCupsPrintEnginePrivate()
bool openPrintDevice() override
void closePrintDevice() override
QVariant property(PrintEnginePropertyKey key) const override
Returns the print engine's property specified by key.
virtual ~QCupsPrintEngine()
QCupsPrintEngine(QPrinter::PrinterMode m, const QString &deviceId)
void setProperty(PrintEnginePropertyKey key, const QVariant &value) override
Sets the print engine's property specified by key to the given value.
QFILE_MAYBE_NODISCARD bool open(OpenMode flags) override
Opens the file using OpenMode mode, returning true if successful; otherwise false.
bool remove()
Removes the file specified by fileName().
QString errorString() const
Returns a human-readable description of the last device error that occurred.
Unit units() const
Returns the units the page layout is currently defined in.
bool isValid() const
Returns true if this page layout is valid.
Unit
This enum type is used to specify the measurement unit for page layout and margins.
Orientation orientation() const
Returns the page orientation of the page layout.
void setPageSize(const QPageSize &pageSize, const QMarginsF &minMargins=QMarginsF(0, 0, 0, 0))
Sets the page size of the page layout to pageSize.
QPageSize pageSize() const
Returns the page size of the page layout.
bool isValid() const
Returns true if this page size is valid.
QString key() const
Returns the unique key of the page size.
QSizeF size(Unit units) const
Returns the size of the page in the required units.
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.
QPdfEngine::ColorModel colorModel
QPageLayout pageLayout() const
friend class QCupsPrintEnginePrivate
QPrinter::ColorMode printerColorMode() const
virtual void closePrintDevice()
QPrinter::PrinterState state
virtual void setProperty(PrintEnginePropertyKey key, const QVariant &value) override
Sets the print engine's property specified by key to the given value.
virtual QVariant property(PrintEnginePropertyKey key) const override
Returns the print engine's property specified by key.
QPageSize supportedPageSize(const QPageSize &pageSize) const
void swap(QPrintDevice &other)
QList< QPrint::DuplexMode > supportedDuplexModes() const
QPrint::DuplexMode defaultDuplexMode() const
QList< QPrint::ColorMode > supportedColorModes() const
QPrint::ColorMode defaultColorMode() const
QMarginsF printableMargins(const QPageSize &pageSize, QPageLayout::Orientation orientation, int resolution) const
PrintEnginePropertyKey
This enum is used to communicate properties between the print engine and QPrinter.
@ PPK_SupportsMultipleCopies
PrinterMode
This enum describes the mode the printer should work in.
Q_CORE_EXPORT QList< QStringView > split(QStringView sep, Qt::SplitBehavior behavior=Qt::KeepEmptyParts, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Splits the view into substring views wherever sep occurs, and returns the list of those string views.
\macro QT_RESTRICTED_CAST_FROM_ASCII
static QString fromLocal8Bit(QByteArrayView ba)
This is an overloaded member function, provided for convenience. It differs from the above function o...
bool isEmpty() const noexcept
Returns true if the string has no characters; otherwise returns false.
void clear()
Clears the contents of the string and makes it null.
QByteArray toLocal8Bit() const &
static QString number(int, int base=10)
This is an overloaded member function, provided for convenience. It differs from the above function o...
QSet< QString >::iterator it
Combined button and popup list for selecting options.
static QT_BEGIN_NAMESPACE const char tempFile[]
QT_BEGIN_NAMESPACE QMarginsF qt_convertMargins(const QMarginsF &margins, QPageLayout::Unit fromUnits, QPageLayout::Unit toUnits)
EGLOutputLayerEXT EGLint EGLAttrib value
[5]
Q_GUI_EXPORT QMarginsF qt_convertMargins(const QMarginsF &margins, QPageLayout::Unit fromUnits, QPageLayout::Unit toUnits)
#define qPrintable(string)
static char * toLocal8Bit(char *out, QStringView in, QStringConverter::State *state)
file open(QIODevice::ReadOnly)
bool contains(const AT &t) const noexcept