summaryrefslogtreecommitdiffstats
path: root/src/printsupport/kernel
diff options
context:
space:
mode:
Diffstat (limited to 'src/printsupport/kernel')
-rw-r--r--src/printsupport/kernel/qcups.cpp12
-rw-r--r--src/printsupport/kernel/qpaintengine_alpha.cpp6
-rw-r--r--src/printsupport/kernel/qplatformprintdevice.cpp14
-rw-r--r--src/printsupport/kernel/qplatformprintplugin.cpp8
-rw-r--r--src/printsupport/kernel/qprint.cpp159
-rw-r--r--src/printsupport/kernel/qprint_p.h150
-rw-r--r--src/printsupport/kernel/qprintengine_pdf.cpp32
-rw-r--r--src/printsupport/kernel/qprintengine_pdf_p.h2
-rw-r--r--src/printsupport/kernel/qprinter.cpp12
-rw-r--r--src/printsupport/kernel/qprinter.h2
-rw-r--r--src/printsupport/kernel/qprinter_p.h1
-rw-r--r--src/printsupport/kernel/qprinterinfo.cpp4
-rw-r--r--src/printsupport/kernel/qprinterinfo.h1
13 files changed, 244 insertions, 159 deletions
diff --git a/src/printsupport/kernel/qcups.cpp b/src/printsupport/kernel/qcups.cpp
index 5d1d4e5c98..231b816499 100644
--- a/src/printsupport/kernel/qcups.cpp
+++ b/src/printsupport/kernel/qcups.cpp
@@ -89,8 +89,7 @@ static inline QString jobHoldToString(const QCUPSSupport::JobHoldUntil jobHold,
case QCUPSSupport::NoHold:
return QString();
}
- Q_UNREACHABLE();
- return QString();
+ Q_UNREACHABLE_RETURN(QString());
}
QCUPSSupport::JobHoldUntilWithTime QCUPSSupport::parseJobHoldUntil(const QString &jobHoldUntil)
@@ -110,9 +109,9 @@ QCUPSSupport::JobHoldUntilWithTime QCUPSSupport::parseJobHoldUntil(const QString
}
- QTime parsedTime = QTime::fromString(jobHoldUntil, QStringLiteral("h:m:s"));
+ QTime parsedTime = QTime::fromString(jobHoldUntil, u"h:m:s");
if (!parsedTime.isValid())
- parsedTime = QTime::fromString(jobHoldUntil, QStringLiteral("h:m"));
+ parsedTime = QTime::fromString(jobHoldUntil, u"h:m");
if (parsedTime.isValid()) {
// CUPS time is in UTC, user expects local time, so get the equivalent
QDateTime dateTimeUtc = QDateTime::currentDateTimeUtc();
@@ -176,8 +175,7 @@ static inline QString bannerPageToString(const QCUPSSupport::BannerPage bannerPa
case QCUPSSupport::Secret: return QStringLiteral("secret");
case QCUPSSupport::TopSecret: return QStringLiteral("topsecret");
}
- Q_UNREACHABLE();
- return QString();
+ Q_UNREACHABLE_RETURN(QString());
}
static inline QCUPSSupport::BannerPage stringToBannerPage(const QString &bannerPage)
@@ -198,7 +196,7 @@ QCUPSSupport::JobSheets QCUPSSupport::parseJobSheets(const QString &jobSheets)
JobSheets result;
const QStringList parts = jobSheets.split(u',');
- if (parts.count() == 2) {
+ if (parts.size() == 2) {
result.startBannerPage = stringToBannerPage(parts[0]);
result.endBannerPage = stringToBannerPage(parts[1]);
}
diff --git a/src/printsupport/kernel/qpaintengine_alpha.cpp b/src/printsupport/kernel/qpaintengine_alpha.cpp
index 0334f7a27c..4c34457570 100644
--- a/src/printsupport/kernel/qpaintengine_alpha.cpp
+++ b/src/printsupport/kernel/qpaintengine_alpha.cpp
@@ -401,9 +401,9 @@ void QAlphaPaintEnginePrivate::addAlphaRect(const QRectF &rect)
bool QAlphaPaintEnginePrivate::canSeeTroughBackground(bool somethingInRectHasAlpha, const QRectF &rect) const
{
if (somethingInRectHasAlpha) {
- if (m_dirtyRects.count() != m_numberOfCachedRects) {
- m_cachedDirtyRgn.setRects(m_dirtyRects.constData(), m_dirtyRects.count());
- m_numberOfCachedRects = m_dirtyRects.count();
+ if (m_dirtyRects.size() != m_numberOfCachedRects) {
+ m_cachedDirtyRgn.setRects(m_dirtyRects.constData(), m_dirtyRects.size());
+ m_numberOfCachedRects = m_dirtyRects.size();
}
return m_cachedDirtyRgn.intersects(rect.toAlignedRect());
}
diff --git a/src/printsupport/kernel/qplatformprintdevice.cpp b/src/printsupport/kernel/qplatformprintdevice.cpp
index ac8628685d..a2ee51f887 100644
--- a/src/printsupport/kernel/qplatformprintdevice.cpp
+++ b/src/printsupport/kernel/qplatformprintdevice.cpp
@@ -75,6 +75,10 @@ bool QPlatformPrintDevice::isValidPageLayout(const QPageLayout &layout, int reso
if (!supportedPageSize(layout.pageSize()).isValid())
return false;
+ // In fullpage mode, margins outside the printable area are valid
+ if (layout.mode() == QPageLayout::FullPageMode)
+ return true;
+
// Check the margins are valid
QMarginsF pointMargins = layout.margins(QPageLayout::Point);
QMarginsF printMargins = printableMargins(layout.pageSize(), layout.orientation(), resolution);
@@ -127,7 +131,7 @@ QPageSize QPlatformPrintDevice::supportedPageSize(const QPageSize &pageSize) con
// e.g. Windows defines DMPAPER_11X17 and DMPAPER_TABLOID with names "11x17" and "Tabloid", but both
// map to QPageSize::Tabloid / PPD Key "Tabloid" / ANSI B Tabloid
if (pageSize.id() != QPageSize::Custom) {
- for (const QPageSize &ps : qAsConst(m_pageSizes)) {
+ for (const QPageSize &ps : std::as_const(m_pageSizes)) {
if (ps.id() == pageSize.id() && ps.name() == pageSize.name())
return ps;
}
@@ -135,7 +139,7 @@ QPageSize QPlatformPrintDevice::supportedPageSize(const QPageSize &pageSize) con
// Next try match on id only if not custom
if (pageSize.id() != QPageSize::Custom) {
- for (const QPageSize &ps : qAsConst(m_pageSizes)) {
+ for (const QPageSize &ps : std::as_const(m_pageSizes)) {
if (ps.id() == pageSize.id())
return ps;
}
@@ -150,7 +154,7 @@ QPageSize QPlatformPrintDevice::supportedPageSize(QPageSize::PageSizeId pageSize
if (!m_havePageSizes)
loadPageSizes();
- for (const QPageSize &ps : qAsConst(m_pageSizes)) {
+ for (const QPageSize &ps : std::as_const(m_pageSizes)) {
if (ps.id() == pageSizeId)
return ps;
}
@@ -164,7 +168,7 @@ QPageSize QPlatformPrintDevice::supportedPageSize(const QString &pageName) const
if (!m_havePageSizes)
loadPageSizes();
- for (const QPageSize &ps : qAsConst(m_pageSizes)) {
+ for (const QPageSize &ps : std::as_const(m_pageSizes)) {
if (ps.name() == pageName)
return ps;
}
@@ -197,7 +201,7 @@ QPageSize QPlatformPrintDevice::supportedPageSizeMatch(const QPageSize &pageSize
return pageSize;
// Try to find a supported page size based on point size
- for (const QPageSize &ps : qAsConst(m_pageSizes)) {
+ for (const QPageSize &ps : std::as_const(m_pageSizes)) {
if (ps.sizePoints() == pageSize.sizePoints())
return ps;
}
diff --git a/src/printsupport/kernel/qplatformprintplugin.cpp b/src/printsupport/kernel/qplatformprintplugin.cpp
index 79aaa5bb3c..c48e5f65bf 100644
--- a/src/printsupport/kernel/qplatformprintplugin.cpp
+++ b/src/printsupport/kernel/qplatformprintplugin.cpp
@@ -10,16 +10,16 @@
#ifndef QT_NO_PRINTER
-QT_BEGIN_NAMESPACE
-
-using namespace Qt::StringLiterals;
-
#if defined(Q_OS_MACOS)
Q_IMPORT_PLUGIN(QCocoaPrinterSupportPlugin)
#elif defined(Q_OS_WIN)
Q_IMPORT_PLUGIN(QWindowsPrinterSupportPlugin)
#endif
+QT_BEGIN_NAMESPACE
+
+using namespace Qt::StringLiterals;
+
Q_GLOBAL_STATIC_WITH_ARGS(QFactoryLoader, loader,
(QPlatformPrinterSupportFactoryInterface_iid, "/printsupport"_L1, Qt::CaseInsensitive))
diff --git a/src/printsupport/kernel/qprint.cpp b/src/printsupport/kernel/qprint.cpp
new file mode 100644
index 0000000000..755da40a08
--- /dev/null
+++ b/src/printsupport/kernel/qprint.cpp
@@ -0,0 +1,159 @@
+// Copyright (C) 2022 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#include "qprint_p.h"
+
+QT_BEGIN_NAMESPACE
+
+#ifndef QT_NO_PRINTER
+
+// Note: PPD standard does not define a standard set of InputSlot keywords,
+// it is a free form text field left to the PPD writer to decide,
+// but it does suggest some names for consistency with the Windows enum.
+static const InputSlotMap inputSlotMap[] = {
+ { QPrint::Upper, DMBIN_UPPER, "Upper" },
+ { QPrint::Lower, DMBIN_LOWER, "Lower" },
+ { QPrint::Middle, DMBIN_MIDDLE, "Middle" },
+ { QPrint::Manual, DMBIN_MANUAL, "Manual" },
+ { QPrint::Envelope, DMBIN_ENVELOPE, "Envelope" },
+ { QPrint::EnvelopeManual, DMBIN_ENVMANUAL, "EnvelopeManual" },
+ { QPrint::Auto, DMBIN_AUTO, "Auto" },
+ { QPrint::Tractor, DMBIN_TRACTOR, "Tractor" },
+ { QPrint::SmallFormat, DMBIN_SMALLFMT, "AnySmallFormat" },
+ { QPrint::LargeFormat, DMBIN_LARGEFMT, "AnyLargeFormat" },
+ { QPrint::LargeCapacity, DMBIN_LARGECAPACITY, "LargeCapacity" },
+ { QPrint::Cassette, DMBIN_CASSETTE, "Cassette" },
+ { QPrint::FormSource, DMBIN_FORMSOURCE, "FormSource" },
+ { QPrint::Manual, DMBIN_MANUAL, "ManualFeed" },
+ { QPrint::OnlyOne, DMBIN_ONLYONE, "OnlyOne" }, // = QPrint::Upper
+ { QPrint::CustomInputSlot, DMBIN_USER, "" } // Must always be last row
+};
+
+static const OutputBinMap outputBinMap[] = {
+ { QPrint::AutoOutputBin, "" }, // Not a PPD defined value, internal use only
+ { QPrint::UpperBin, "Upper" },
+ { QPrint::LowerBin, "Lower" },
+ { QPrint::RearBin, "Rear" },
+ { QPrint::CustomOutputBin, "" } // Must always be last row
+};
+
+namespace QPrintUtils {
+
+QPrint::InputSlotId inputSlotKeyToInputSlotId(const QByteArray &key)
+{
+ for (int i = 0; inputSlotMap[i].id != QPrint::CustomInputSlot; ++i) {
+ if (inputSlotMap[i].key == key)
+ return inputSlotMap[i].id;
+ }
+ return QPrint::CustomInputSlot;
+}
+
+QByteArray inputSlotIdToInputSlotKey(QPrint::InputSlotId id)
+{
+ for (int i = 0; inputSlotMap[i].id != QPrint::CustomInputSlot; ++i) {
+ if (inputSlotMap[i].id == id)
+ return QByteArray(inputSlotMap[i].key);
+ }
+ return QByteArray();
+}
+
+int inputSlotIdToWindowsId(QPrint::InputSlotId id)
+{
+ for (int i = 0; inputSlotMap[i].id != QPrint::CustomInputSlot; ++i) {
+ if (inputSlotMap[i].id == id)
+ return inputSlotMap[i].windowsId;
+ }
+ return 0;
+}
+
+QPrint::OutputBinId outputBinKeyToOutputBinId(const QByteArray &key)
+{
+ for (int i = 0; outputBinMap[i].id != QPrint::CustomOutputBin; ++i) {
+ if (outputBinMap[i].key == key)
+ return outputBinMap[i].id;
+ }
+ return QPrint::CustomOutputBin;
+}
+
+QByteArray outputBinIdToOutputBinKey(QPrint::OutputBinId id)
+{
+ for (int i = 0; outputBinMap[i].id != QPrint::CustomOutputBin; ++i) {
+ if (outputBinMap[i].id == id)
+ return QByteArray(outputBinMap[i].key);
+ }
+ return QByteArray();
+}
+
+QPrint::InputSlot paperBinToInputSlot(int windowsId, const QString &name)
+{
+ QPrint::InputSlot slot;
+ slot.name = name;
+ int i;
+ for (i = 0; inputSlotMap[i].id != QPrint::CustomInputSlot; ++i) {
+ if (inputSlotMap[i].windowsId == windowsId) {
+ slot.key = inputSlotMap[i].key;
+ slot.id = inputSlotMap[i].id;
+ slot.windowsId = inputSlotMap[i].windowsId;
+ return slot;
+ }
+ }
+ slot.key = inputSlotMap[i].key;
+ slot.id = inputSlotMap[i].id;
+ slot.windowsId = windowsId;
+ return slot;
+}
+
+#if (defined Q_OS_MACOS) || (defined Q_OS_UNIX && QT_CONFIG(cups))
+
+// PPD utilities shared by CUPS and Mac plugins requiring CUPS headers
+// May turn into a proper internal QPpd class if enough shared between Mac and CUPS,
+// but where would it live? Not in base module as don't want to link to CUPS.
+// May have to have two copies in plugins to keep in sync.
+
+QPrint::InputSlot ppdChoiceToInputSlot(const ppd_choice_t &choice)
+{
+ QPrint::InputSlot input;
+ input.key = choice.choice;
+ input.name = QString::fromUtf8(choice.text);
+ input.id = inputSlotKeyToInputSlotId(input.key);
+ input.windowsId = inputSlotMap[input.id].windowsId;
+ return input;
+}
+
+QPrint::OutputBin ppdChoiceToOutputBin(const ppd_choice_t &choice)
+{
+ QPrint::OutputBin output;
+ output.key = choice.choice;
+ output.name = QString::fromUtf8(choice.text);
+ output.id = outputBinKeyToOutputBinId(output.key);
+ return output;
+}
+
+int parsePpdResolution(const QByteArray &value)
+{
+ if (value.isEmpty())
+ return -1;
+ // value can be in form 600dpi or 600x600dpi
+ QByteArray result = value.split('x').at(0);
+ if (result.endsWith("dpi"))
+ result.chop(3);
+ return result.toInt();
+}
+
+QPrint::DuplexMode ppdChoiceToDuplexMode(const QByteArray &choice)
+{
+ if (choice == "DuplexTumble")
+ return QPrint::DuplexShortSide;
+ else if (choice == "DuplexNoTumble")
+ return QPrint::DuplexLongSide;
+ else // None or SimplexTumble or SimplexNoTumble
+ return QPrint::DuplexNone;
+}
+
+#endif // Mac and CUPS PPD Utilities
+
+}
+
+#endif // QT_NO_PRINTER
+
+QT_END_NAMESPACE
diff --git a/src/printsupport/kernel/qprint_p.h b/src/printsupport/kernel/qprint_p.h
index 6e07c27c64..0a94aa8db3 100644
--- a/src/printsupport/kernel/qprint_p.h
+++ b/src/printsupport/kernel/qprint_p.h
@@ -1,3 +1,4 @@
+// Copyright (C) 2022 The Qt Company Ltd.
// Copyright (C) 2014 John Layt <jlayt@kde.org>
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
@@ -67,6 +68,7 @@ namespace QPrint {
DuplexShortSide
};
+ // Note: Keep in sync with QPrinter::ColorMode
enum ColorMode {
GrayScale,
Color
@@ -124,142 +126,32 @@ struct InputSlotMap {
const char *key;
};
-// Note: PPD standard does not define a standard set of InputSlot keywords,
-// it is a free form text field left to the PPD writer to decide,
-// but it does suggest some names for consistency with the Windows enum.
-static const InputSlotMap inputSlotMap[] = {
- { QPrint::Upper, DMBIN_UPPER, "Upper" },
- { QPrint::Lower, DMBIN_LOWER, "Lower" },
- { QPrint::Middle, DMBIN_MIDDLE, "Middle" },
- { QPrint::Manual, DMBIN_MANUAL, "Manual" },
- { QPrint::Envelope, DMBIN_ENVELOPE, "Envelope" },
- { QPrint::EnvelopeManual, DMBIN_ENVMANUAL, "EnvelopeManual" },
- { QPrint::Auto, DMBIN_AUTO, "Auto" },
- { QPrint::Tractor, DMBIN_TRACTOR, "Tractor" },
- { QPrint::SmallFormat, DMBIN_SMALLFMT, "AnySmallFormat" },
- { QPrint::LargeFormat, DMBIN_LARGEFMT, "AnyLargeFormat" },
- { QPrint::LargeCapacity, DMBIN_LARGECAPACITY, "LargeCapacity" },
- { QPrint::Cassette, DMBIN_CASSETTE, "Cassette" },
- { QPrint::FormSource, DMBIN_FORMSOURCE, "FormSource" },
- { QPrint::Manual, DMBIN_MANUAL, "ManualFeed" },
- { QPrint::OnlyOne, DMBIN_ONLYONE, "OnlyOne" }, // = QPrint::Upper
- { QPrint::CustomInputSlot, DMBIN_USER, "" } // Must always be last row
-};
-
struct OutputBinMap {
QPrint::OutputBinId id;
const char *key;
};
-static const OutputBinMap outputBinMap[] = {
- { QPrint::AutoOutputBin, "" }, // Not a PPD defined value, internal use only
- { QPrint::UpperBin, "Upper" },
- { QPrint::LowerBin, "Lower" },
- { QPrint::RearBin, "Rear" },
- { QPrint::CustomOutputBin, "" } // Must always be last row
-};
-
// Print utilities shared by print plugins
-class QPrintUtils
-{
-
-public:
-
- static QPrint::InputSlotId inputSlotKeyToInputSlotId(const QByteArray &key)
- {
- for (int i = 0; inputSlotMap[i].id != QPrint::CustomInputSlot; ++i) {
- if (inputSlotMap[i].key == key)
- return inputSlotMap[i].id;
- }
- return QPrint::CustomInputSlot;
- }
-
- static QByteArray inputSlotIdToInputSlotKey(QPrint::InputSlotId id)
- {
- for (int i = 0; inputSlotMap[i].id != QPrint::CustomInputSlot; ++i) {
- if (inputSlotMap[i].id == id)
- return QByteArray(inputSlotMap[i].key);
- }
- return QByteArray();
- }
-
- static int inputSlotIdToWindowsId(QPrint::InputSlotId id)
- {
- for (int i = 0; inputSlotMap[i].id != QPrint::CustomInputSlot; ++i) {
- if (inputSlotMap[i].id == id)
- return inputSlotMap[i].windowsId;
- }
- return 0;
- }
-
- static QPrint::OutputBinId outputBinKeyToOutputBinId(const QByteArray &key)
- {
- for (int i = 0; outputBinMap[i].id != QPrint::CustomOutputBin; ++i) {
- if (outputBinMap[i].key == key)
- return outputBinMap[i].id;
- }
- return QPrint::CustomOutputBin;
- }
-
- static QByteArray outputBinIdToOutputBinKey(QPrint::OutputBinId id)
- {
- for (int i = 0; outputBinMap[i].id != QPrint::CustomOutputBin; ++i) {
- if (outputBinMap[i].id == id)
- return QByteArray(outputBinMap[i].key);
- }
- return QByteArray();
- }
-
-#if (defined Q_OS_MACOS) || (defined Q_OS_UNIX && QT_CONFIG(cups))
-
- // PPD utilities shared by CUPS and Mac plugins requiring CUPS headers
- // May turn into a proper internal QPpd class if enough shared between Mac and CUPS,
- // but where would it live? Not in base module as don't want to link to CUPS.
- // May have to have two copies in plugins to keep in sync.
-
- static QPrint::InputSlot ppdChoiceToInputSlot(const ppd_choice_t &choice)
- {
- QPrint::InputSlot input;
- input.key = choice.choice;
- input.name = QString::fromUtf8(choice.text);
- input.id = inputSlotKeyToInputSlotId(input.key);
- input.windowsId = inputSlotMap[input.id].windowsId;
- return input;
- }
-
- static QPrint::OutputBin ppdChoiceToOutputBin(const ppd_choice_t &choice)
- {
- QPrint::OutputBin output;
- output.key = choice.choice;
- output.name = QString::fromUtf8(choice.text);
- output.id = outputBinKeyToOutputBinId(output.key);
- return output;
- }
-
- static int parsePpdResolution(const QByteArray &value)
- {
- if (value.isEmpty())
- return -1;
- // value can be in form 600dpi or 600x600dpi
- QByteArray result = value.split('x').at(0);
- if (result.endsWith("dpi"))
- result.chop(3);
- return result.toInt();
- }
-
- static QPrint::DuplexMode ppdChoiceToDuplexMode(const QByteArray &choice)
- {
- if (choice == "DuplexTumble")
- return QPrint::DuplexShortSide;
- else if (choice == "DuplexNoTumble")
- return QPrint::DuplexLongSide;
- else // None or SimplexTumble or SimplexNoTumble
- return QPrint::DuplexNone;
- }
-
-#endif // Mac and CUPS PPD Utilities
-
+namespace QPrintUtils {
+
+Q_PRINTSUPPORT_EXPORT QPrint::InputSlotId inputSlotKeyToInputSlotId(const QByteArray &key);
+Q_PRINTSUPPORT_EXPORT QByteArray inputSlotIdToInputSlotKey(QPrint::InputSlotId id);
+Q_PRINTSUPPORT_EXPORT int inputSlotIdToWindowsId(QPrint::InputSlotId id);
+Q_PRINTSUPPORT_EXPORT QPrint::OutputBinId outputBinKeyToOutputBinId(const QByteArray &key);
+Q_PRINTSUPPORT_EXPORT QByteArray outputBinIdToOutputBinKey(QPrint::OutputBinId id);
+Q_PRINTSUPPORT_EXPORT QPrint::InputSlot paperBinToInputSlot(int windowsId, const QString &name);
+
+# if (defined Q_OS_MACOS) || (defined Q_OS_UNIX && QT_CONFIG(cups))
+// PPD utilities shared by CUPS and Mac plugins requiring CUPS headers
+// May turn into a proper internal QPpd class if enough shared between Mac and CUPS,
+// but where would it live? Not in base module as don't want to link to CUPS.
+// May have to have two copies in plugins to keep in sync.
+Q_PRINTSUPPORT_EXPORT QPrint::InputSlot ppdChoiceToInputSlot(const ppd_choice_t &choice);
+Q_PRINTSUPPORT_EXPORT QPrint::OutputBin ppdChoiceToOutputBin(const ppd_choice_t &choice);
+Q_PRINTSUPPORT_EXPORT int parsePpdResolution(const QByteArray &value);
+Q_PRINTSUPPORT_EXPORT QPrint::DuplexMode ppdChoiceToDuplexMode(const QByteArray &choice);
+# endif // Mac and CUPS PPD Utilities
};
#endif // QT_NO_PRINTER
diff --git a/src/printsupport/kernel/qprintengine_pdf.cpp b/src/printsupport/kernel/qprintengine_pdf.cpp
index daf5010feb..3e50247186 100644
--- a/src/printsupport/kernel/qprintengine_pdf.cpp
+++ b/src/printsupport/kernel/qprintengine_pdf.cpp
@@ -104,7 +104,14 @@ void QPdfPrintEngine::setProperty(PrintEnginePropertyKey key, const QVariant &va
d->collate = value.toBool();
break;
case PPK_ColorMode:
- d->grayscale = (QPrinter::ColorMode(value.toInt()) == QPrinter::GrayScale);
+ switch (QPrinter::ColorMode(value.toInt())) {
+ case QPrinter::GrayScale:
+ d->colorModel = QPdfEngine::ColorModel::Grayscale;
+ break;
+ case QPrinter::Color:
+ d->colorModel = QPdfEngine::ColorModel::Auto;
+ break;
+ }
break;
case PPK_Creator:
d->creator = value.toString();
@@ -177,7 +184,8 @@ void QPdfPrintEngine::setProperty(PrintEnginePropertyKey key, const QVariant &va
Q_ASSERT(margins.size() == 4);
d->m_pageLayout.setUnits(QPageLayout::Point);
d->m_pageLayout.setMargins(QMarginsF(margins.at(0).toReal(), margins.at(1).toReal(),
- margins.at(2).toReal(), margins.at(3).toReal()));
+ margins.at(2).toReal(), margins.at(3).toReal()),
+ QPageLayout::OutOfBoundsPolicy::Clamp);
break;
}
case PPK_QPageSize: {
@@ -189,7 +197,7 @@ void QPdfPrintEngine::setProperty(PrintEnginePropertyKey key, const QVariant &va
case PPK_QPageMargins: {
QPair<QMarginsF, QPageLayout::Unit> pair = qvariant_cast<QPair<QMarginsF, QPageLayout::Unit> >(value);
d->m_pageLayout.setUnits(pair.second);
- d->m_pageLayout.setMargins(pair.first);
+ d->m_pageLayout.setMargins(pair.first, QPageLayout::OutOfBoundsPolicy::Clamp);
break;
}
case PPK_QPageLayout: {
@@ -221,7 +229,7 @@ QVariant QPdfPrintEngine::property(PrintEnginePropertyKey key) const
ret = d->collate;
break;
case PPK_ColorMode:
- ret = d->grayscale ? QPrinter::GrayScale : QPrinter::Color;
+ ret = d->printerColorMode();
break;
case PPK_Creator:
ret = d->creator;
@@ -367,6 +375,22 @@ QPdfPrintEnginePrivate::~QPdfPrintEnginePrivate()
{
}
+QPrinter::ColorMode QPdfPrintEnginePrivate::printerColorMode() const
+{
+ switch (colorModel) {
+ case QPdfEngine::ColorModel::RGB:
+ case QPdfEngine::ColorModel::CMYK:
+ case QPdfEngine::ColorModel::Auto:
+ return QPrinter::Color;
+ case QPdfEngine::ColorModel::Grayscale:
+ return QPrinter::GrayScale;
+ }
+
+ Q_UNREACHABLE();
+ return QPrinter::Color;
+}
+
+
QT_END_NAMESPACE
#endif // QT_NO_PRINTER
diff --git a/src/printsupport/kernel/qprintengine_pdf_p.h b/src/printsupport/kernel/qprintengine_pdf_p.h
index ccef8215e1..dbf50080a4 100644
--- a/src/printsupport/kernel/qprintengine_pdf_p.h
+++ b/src/printsupport/kernel/qprintengine_pdf_p.h
@@ -79,6 +79,8 @@ public:
QPdfPrintEnginePrivate(QPrinter::PrinterMode m);
~QPdfPrintEnginePrivate();
+ QPrinter::ColorMode printerColorMode() const;
+
virtual bool openPrintDevice();
virtual void closePrintDevice();
diff --git a/src/printsupport/kernel/qprinter.cpp b/src/printsupport/kernel/qprinter.cpp
index dba2d77b8d..10c4c681ba 100644
--- a/src/printsupport/kernel/qprinter.cpp
+++ b/src/printsupport/kernel/qprinter.cpp
@@ -129,6 +129,11 @@ QList<const QPicture *> QPrinterPrivate::previewPages() const
return QList<const QPicture *>();
}
+bool QPrinterPrivate::previewMode() const
+{
+ return (previewEngine != nullptr) && (previewEngine == printEngine);
+}
+
void QPrinterPrivate::setPreviewMode(bool enable)
{
Q_Q(QPrinter);
@@ -431,7 +436,7 @@ public:
Note the difference between Point and DevicePixel. The Point unit is
defined to be 1/72th of an inch, while the DevicePixel unit is
- resolution dependant and is based on the actual pixels, or dots, on
+ resolution dependent and is based on the actual pixels, or dots, on
the printer.
*/
@@ -1272,7 +1277,7 @@ QPrinter::PrinterState QPrinter::printerState() const
return d->printEngine->printerState();
}
-#if defined(Q_OS_WIN) || defined(Q_CLANG_QDOC)
+#if defined(Q_OS_WIN) || defined(Q_QDOC)
/*!
Returns the supported paper sizes for this printer.
@@ -1410,7 +1415,8 @@ int QPrinter::toPage() const
void QPrinter::setFromTo(int from, int to)
{
d->pageRanges.clear();
- d->pageRanges.addRange(from, to);
+ if (from && to)
+ d->pageRanges.addRange(from, to);
}
/*!
diff --git a/src/printsupport/kernel/qprinter.h b/src/printsupport/kernel/qprinter.h
index 8a3f7a4539..c60f0eea1f 100644
--- a/src/printsupport/kernel/qprinter.h
+++ b/src/printsupport/kernel/qprinter.h
@@ -138,7 +138,7 @@ public:
QList<int> supportedResolutions() const;
-#if defined(Q_OS_WIN) || defined(Q_CLANG_QDOC)
+#if defined(Q_OS_WIN) || defined(Q_QDOC)
QList<PaperSource> supportedPaperSources() const;
#endif
diff --git a/src/printsupport/kernel/qprinter_p.h b/src/printsupport/kernel/qprinter_p.h
index 3c6cf711b0..77dd5fb4bc 100644
--- a/src/printsupport/kernel/qprinter_p.h
+++ b/src/printsupport/kernel/qprinter_p.h
@@ -70,6 +70,7 @@ public:
#if QT_CONFIG(printpreviewwidget)
QList<const QPicture *> previewPages() const;
void setPreviewMode(bool);
+ bool previewMode() const;
#endif
void setProperty(QPrintEngine::PrintEnginePropertyKey key, const QVariant &value);
diff --git a/src/printsupport/kernel/qprinterinfo.cpp b/src/printsupport/kernel/qprinterinfo.cpp
index 176c6d6428..59078b4df4 100644
--- a/src/printsupport/kernel/qprinterinfo.cpp
+++ b/src/printsupport/kernel/qprinterinfo.cpp
@@ -21,7 +21,7 @@ class QPrinterInfoPrivateDeleter
public:
static inline void cleanup(QPrinterInfoPrivate *d)
{
- if (d != shared_null)
+ if (d != &*shared_null)
delete d;
}
};
@@ -70,7 +70,7 @@ QPrinterInfo::QPrinterInfo()
Constructs a copy of \a other.
*/
QPrinterInfo::QPrinterInfo(const QPrinterInfo &other)
- : d_ptr((other.d_ptr.data() == shared_null) ? shared_null : new QPrinterInfoPrivate(*other.d_ptr))
+ : d_ptr((other.d_ptr.data() == shared_null) ? &*shared_null : new QPrinterInfoPrivate(*other.d_ptr))
{
}
diff --git a/src/printsupport/kernel/qprinterinfo.h b/src/printsupport/kernel/qprinterinfo.h
index 98b9f2940e..f1b16e7ccb 100644
--- a/src/printsupport/kernel/qprinterinfo.h
+++ b/src/printsupport/kernel/qprinterinfo.h
@@ -8,7 +8,6 @@
#include <QtPrintSupport/qprinter.h>
#include <QtCore/QList>
-#include <QtCore/QPair>
#include <QtGui/qpagesize.h>
QT_BEGIN_NAMESPACE