diff options
Diffstat (limited to 'src/printsupport/kernel')
-rw-r--r-- | src/printsupport/kernel/qcups.cpp | 20 | ||||
-rw-r--r-- | src/printsupport/kernel/qcups_p.h | 5 | ||||
-rw-r--r-- | src/printsupport/kernel/qplatformprintdevice.cpp | 21 | ||||
-rw-r--r-- | src/printsupport/kernel/qplatformprintdevice.h | 14 | ||||
-rw-r--r-- | src/printsupport/kernel/qprintengine_pdf.cpp | 10 | ||||
-rw-r--r-- | src/printsupport/kernel/qprintengine_pdf_p.h | 1 | ||||
-rw-r--r-- | src/printsupport/kernel/qprinter.cpp | 43 | ||||
-rw-r--r-- | src/printsupport/kernel/qprinter_p.h | 4 |
8 files changed, 58 insertions, 60 deletions
diff --git a/src/printsupport/kernel/qcups.cpp b/src/printsupport/kernel/qcups.cpp index 7e8e1707b2..8505e8356c 100644 --- a/src/printsupport/kernel/qcups.cpp +++ b/src/printsupport/kernel/qcups.cpp @@ -39,6 +39,7 @@ #include "qcups_p.h" +#include "qprintdevice_p.h" #include "qprintengine.h" QT_BEGIN_NAMESPACE @@ -146,6 +147,25 @@ QCUPSSupport::JobHoldUntilWithTime QCUPSSupport::parseJobHoldUntil(const QString return { QCUPSSupport::NoHold, QTime() }; } +ppd_option_t *QCUPSSupport::findPpdOption(const char *optionName, QPrintDevice *printDevice) +{ + ppd_file_t *ppd = printDevice->property(PDPK_PpdFile).value<ppd_file_t*>(); + + if (ppd) { + for (int i = 0; i < ppd->num_groups; ++i) { + ppd_group_t *group = &ppd->groups[i]; + + for (int i = 0; i < group->num_options; ++i) { + ppd_option_t *option = &group->options[i]; + + if (qstrcmp(option->keyword, optionName) == 0) + return option; + } + } + } + + return nullptr; +} void QCUPSSupport::setJobHold(QPrinter *printer, const JobHoldUntil jobHold, const QTime &holdUntilTime) { diff --git a/src/printsupport/kernel/qcups_p.h b/src/printsupport/kernel/qcups_p.h index 9a71483bb9..57ec281383 100644 --- a/src/printsupport/kernel/qcups_p.h +++ b/src/printsupport/kernel/qcups_p.h @@ -52,6 +52,7 @@ // #include <QtPrintSupport/private/qtprintsupportglobal_p.h> +#include <QtPrintSupport/private/qprint_p.h> #include "QtCore/qstring.h" #include "QtCore/qstringlist.h" #include "QtPrintSupport/qprinter.h" @@ -61,6 +62,8 @@ QT_REQUIRE_CONFIG(cups); QT_BEGIN_NAMESPACE +class QPrintDevice; + // HACK! Define these here temporarily so they can be used in the dialogs // without a circular reference to QCupsPrintEngine in the plugin. // Move back to qcupsprintengine_p.h in the plugin once all usage @@ -163,6 +166,8 @@ public: QTime time; }; static JobHoldUntilWithTime parseJobHoldUntil(const QString &jobHoldUntil); + + static ppd_option_t *findPpdOption(const char *optionName, QPrintDevice *printDevice); }; Q_DECLARE_TYPEINFO(QCUPSSupport::JobHoldUntil, Q_PRIMITIVE_TYPE); Q_DECLARE_TYPEINFO(QCUPSSupport::BannerPage, Q_PRIMITIVE_TYPE); diff --git a/src/printsupport/kernel/qplatformprintdevice.cpp b/src/printsupport/kernel/qplatformprintdevice.cpp index 8dba402a6e..23a92fc2a1 100644 --- a/src/printsupport/kernel/qplatformprintdevice.cpp +++ b/src/printsupport/kernel/qplatformprintdevice.cpp @@ -50,23 +50,6 @@ QT_BEGIN_NAMESPACE #ifndef QT_NO_PRINTER -QPlatformPrintDevice::QPlatformPrintDevice() - : m_isRemote(false), - m_supportsMultipleCopies(false), - m_supportsCollateCopies(false), - m_havePageSizes(false), - m_supportsCustomPageSizes(false), - m_haveResolutions(false), - m_haveInputSlots(false), - m_haveOutputBins(false), - m_haveDuplexModes(false), - m_haveColorModes(false) -#ifndef QT_NO_MIMETYPE - , m_haveMimeTypes(false) -#endif -{ -} - QPlatformPrintDevice::QPlatformPrintDevice(const QString &id) : m_id(id), m_isRemote(false), @@ -247,6 +230,10 @@ QPageSize QPlatformPrintDevice::supportedPageSize(const QSizeF &size, QPageSize: QPageSize QPlatformPrintDevice::supportedPageSizeMatch(const QPageSize &pageSize) const { + // If it's a known page size, just return itself + if (m_pageSizes.contains(pageSize)) + return pageSize; + // Try to find a supported page size based on point size for (const QPageSize &ps : m_pageSizes) { if (ps.sizePoints() == pageSize.sizePoints()) diff --git a/src/printsupport/kernel/qplatformprintdevice.h b/src/printsupport/kernel/qplatformprintdevice.h index a988518547..d95a5add9b 100644 --- a/src/printsupport/kernel/qplatformprintdevice.h +++ b/src/printsupport/kernel/qplatformprintdevice.h @@ -1,6 +1,7 @@ /**************************************************************************** ** ** Copyright (C) 2014 John Layt <jlayt@kde.org> +** Copyright (C) 2018 The Qt Company Ltd. ** Contact: https://www.qt.io/licensing/ ** ** This file is part of the QtPrintSupport module of the Qt Toolkit. @@ -69,8 +70,7 @@ class Q_PRINTSUPPORT_EXPORT QPlatformPrintDevice { Q_DISABLE_COPY(QPlatformPrintDevice) public: - QPlatformPrintDevice(); - explicit QPlatformPrintDevice(const QString &id); + explicit QPlatformPrintDevice(const QString &id = QString()); virtual ~QPlatformPrintDevice(); virtual QString id() const; @@ -152,16 +152,16 @@ protected: bool m_isRemote; - bool m_supportsMultipleCopies; - bool m_supportsCollateCopies; + mutable bool m_supportsMultipleCopies; + mutable bool m_supportsCollateCopies; mutable bool m_havePageSizes; mutable QList<QPageSize> m_pageSizes; - bool m_supportsCustomPageSizes; + mutable bool m_supportsCustomPageSizes; - QSize m_minimumPhysicalPageSize; - QSize m_maximumPhysicalPageSize; + mutable QSize m_minimumPhysicalPageSize; + mutable QSize m_maximumPhysicalPageSize; mutable bool m_haveResolutions; mutable QList<int> m_resolutions; diff --git a/src/printsupport/kernel/qprintengine_pdf.cpp b/src/printsupport/kernel/qprintengine_pdf.cpp index 0230ebddc8..3c24e5ac69 100644 --- a/src/printsupport/kernel/qprintengine_pdf.cpp +++ b/src/printsupport/kernel/qprintengine_pdf.cpp @@ -132,6 +132,8 @@ void QPdfPrintEngine::setProperty(PrintEnginePropertyKey key, const QVariant &va // The following keys are settings that are unsupported by the PDF PrintEngine case PPK_CustomBase: break; + case PPK_Duplex: + break; // The following keys are properties and settings that are supported by the PDF PrintEngine case PPK_CollateCopies: @@ -203,9 +205,6 @@ void QPdfPrintEngine::setProperty(PrintEnginePropertyKey key, const QVariant &va case PPK_FontEmbedding: d->embedFonts = value.toBool(); break; - case PPK_Duplex: - d->duplex = static_cast<QPrint::DuplexMode>(value.toInt()); - break; case PPK_CustomPaperSize: d->m_pageLayout.setPageSize(QPageSize(value.toSizeF(), QPageSize::Point)); break; @@ -249,6 +248,7 @@ QVariant QPdfPrintEngine::property(PrintEnginePropertyKey key) const // The following keys are settings that are unsupported by the PDF PrintEngine // Return sensible default values to ensure consistent behavior across platforms case PPK_CustomBase: + case PPK_Duplex: // Special case, leave null break; @@ -322,9 +322,6 @@ QVariant QPdfPrintEngine::property(PrintEnginePropertyKey key) const case PPK_FontEmbedding: ret = d->embedFonts; break; - case PPK_Duplex: - ret = d->duplex; - break; case PPK_CustomPaperSize: ret = d->m_pageLayout.fullRectPoints().size(); break; @@ -389,7 +386,6 @@ void QPdfPrintEnginePrivate::closePrintDevice() QPdfPrintEnginePrivate::QPdfPrintEnginePrivate(QPrinter::PrinterMode m) : QPdfEnginePrivate(), - duplex(QPrint::DuplexNone), collate(true), copies(1), pageOrder(QPrinter::FirstPageFirst), diff --git a/src/printsupport/kernel/qprintengine_pdf_p.h b/src/printsupport/kernel/qprintengine_pdf_p.h index bb01a2e9e1..e7ae21f260 100644 --- a/src/printsupport/kernel/qprintengine_pdf_p.h +++ b/src/printsupport/kernel/qprintengine_pdf_p.h @@ -130,7 +130,6 @@ private: QString printProgram; QString selectionOption; - QPrint::DuplexMode duplex; bool collate; int copies; QPrinter::PageOrder pageOrder; diff --git a/src/printsupport/kernel/qprinter.cpp b/src/printsupport/kernel/qprinter.cpp index 8a2cdcb34f..ed4292ff3d 100644 --- a/src/printsupport/kernel/qprinter.cpp +++ b/src/printsupport/kernel/qprinter.cpp @@ -224,8 +224,8 @@ void QPrinterPrivate::setProperty(QPrintEngine::PrintEnginePropertyKey key, cons class QPrinterPagedPaintDevicePrivate : public QPagedPaintDevicePrivate { public: - QPrinterPagedPaintDevicePrivate(QPrinterPrivate *d) - : QPagedPaintDevicePrivate(), pd(d) + QPrinterPagedPaintDevicePrivate(QPrinter *p) + : QPagedPaintDevicePrivate(), m_printer(p) {} virtual ~QPrinterPagedPaintDevicePrivate() @@ -233,6 +233,8 @@ public: bool setPageLayout(const QPageLayout &newPageLayout) override { + QPrinterPrivate *pd = QPrinterPrivate::get(m_printer); + if (pd->paintEngine->type() != QPaintEngine::Pdf && pd->printEngine->printerState() == QPrinter::Active) { qWarning("QPrinter::setPageLayout: Cannot be changed while printer is active"); @@ -242,14 +244,13 @@ public: // Try to set the print engine page layout pd->setProperty(QPrintEngine::PPK_QPageLayout, QVariant::fromValue(newPageLayout)); - // Set QPagedPaintDevice layout to match the current print engine value - m_pageLayout = pageLayout(); - return pageLayout().isEquivalentTo(newPageLayout); } bool setPageSize(const QPageSize &pageSize) override { + QPrinterPrivate *pd = QPrinterPrivate::get(m_printer); + if (pd->paintEngine->type() != QPaintEngine::Pdf && pd->printEngine->printerState() == QPrinter::Active) { qWarning("QPrinter::setPageLayout: Cannot be changed while printer is active"); @@ -260,46 +261,38 @@ public: // Try to set the print engine page size pd->setProperty(QPrintEngine::PPK_QPageSize, QVariant::fromValue(pageSize)); - // Set QPagedPaintDevice layout to match the current print engine value - m_pageLayout = pageLayout(); - return pageLayout().pageSize().isEquivalentTo(pageSize); } bool setPageOrientation(QPageLayout::Orientation orientation) override { + QPrinterPrivate *pd = QPrinterPrivate::get(m_printer); + // Set the print engine value pd->setProperty(QPrintEngine::PPK_Orientation, orientation); - // Set QPagedPaintDevice layout to match the current print engine value - m_pageLayout = pageLayout(); - return pageLayout().orientation() == orientation; } - bool setPageMargins(const QMarginsF &margins) override - { - return setPageMargins(margins, pageLayout().units()); - } - bool setPageMargins(const QMarginsF &margins, QPageLayout::Unit units) override { + QPrinterPrivate *pd = QPrinterPrivate::get(m_printer); + // Try to set print engine margins QPair<QMarginsF, QPageLayout::Unit> pair = qMakePair(margins, units); pd->setProperty(QPrintEngine::PPK_QPageMargins, QVariant::fromValue(pair)); - // Set QPagedPaintDevice layout to match the current print engine value - m_pageLayout = pageLayout(); - return pageLayout().margins() == margins && pageLayout().units() == units; } QPageLayout pageLayout() const override { + QPrinterPrivate *pd = QPrinterPrivate::get(m_printer); + return pd->printEngine->property(QPrintEngine::PPK_QPageLayout).value<QPageLayout>(); } - QPrinterPrivate *pd; + QPrinter *m_printer; }; @@ -554,11 +547,9 @@ public: Creates a new printer object with the given \a mode. */ QPrinter::QPrinter(PrinterMode mode) - : QPagedPaintDevice(), + : QPagedPaintDevice(new QPrinterPagedPaintDevicePrivate(this)), d_ptr(new QPrinterPrivate(this)) { - delete d; - d = new QPrinterPagedPaintDevicePrivate(d_func()); d_ptr->init(QPrinterInfo(), mode); } @@ -568,11 +559,9 @@ QPrinter::QPrinter(PrinterMode mode) Creates a new printer object with the given \a printer and \a mode. */ QPrinter::QPrinter(const QPrinterInfo& printer, PrinterMode mode) - : QPagedPaintDevice(), + : QPagedPaintDevice(new QPrinterPagedPaintDevicePrivate(this)), d_ptr(new QPrinterPrivate(this)) { - delete d; - d = new QPrinterPagedPaintDevicePrivate(d_func()); d_ptr->init(printer, mode); } @@ -1469,8 +1458,6 @@ void QPrinter::setFullPage(bool fp) Q_D(QPrinter); // Set the print engine d->setProperty(QPrintEngine::PPK_FullPage, fp); - // Set QPagedPaintDevice layout to match the current print engine value - devicePageLayout() = pageLayout(); } diff --git a/src/printsupport/kernel/qprinter_p.h b/src/printsupport/kernel/qprinter_p.h index 6ced466236..37c9702c17 100644 --- a/src/printsupport/kernel/qprinter_p.h +++ b/src/printsupport/kernel/qprinter_p.h @@ -94,6 +94,10 @@ public: } + static QPrinterPrivate *get(QPrinter *printer) { + return printer->d_ptr.get(); + } + void init(const QPrinterInfo &printer, QPrinter::PrinterMode mode); QPrinterInfo findValidPrinter(const QPrinterInfo &printer = QPrinterInfo()); |