diff options
Diffstat (limited to 'src/gui')
-rw-r--r-- | src/gui/painting/qpagedpaintdevice.cpp | 146 | ||||
-rw-r--r-- | src/gui/painting/qpagedpaintdevice.h | 12 | ||||
-rw-r--r-- | src/gui/painting/qpagedpaintdevice_p.h | 42 | ||||
-rw-r--r-- | src/gui/painting/qpdfwriter.cpp | 129 | ||||
-rw-r--r-- | src/gui/painting/qpdfwriter.h | 5 |
5 files changed, 273 insertions, 61 deletions
diff --git a/src/gui/painting/qpagedpaintdevice.cpp b/src/gui/painting/qpagedpaintdevice.cpp index 18ba964a26..e102b7fae3 100644 --- a/src/gui/painting/qpagedpaintdevice.cpp +++ b/src/gui/painting/qpagedpaintdevice.cpp @@ -66,6 +66,15 @@ QPagedPaintDevice::QPagedPaintDevice() } /*! + \internal + Constructs a new paged paint device with the derived private class. +*/ +QPagedPaintDevice::QPagedPaintDevice(QPagedPaintDevicePrivate *dd) + : d(dd) +{ +} + +/*! Destroys the object. */ QPagedPaintDevice::~QPagedPaintDevice() @@ -74,6 +83,15 @@ QPagedPaintDevice::~QPagedPaintDevice() } /*! + \internal + Returns the QPagedPaintDevicePrivate. +*/ +QPagedPaintDevicePrivate *QPagedPaintDevice::dd() +{ + return d; +} + +/*! \enum QPagedPaintDevice::PageSize This enum type lists the available page sizes as defined in the Postscript @@ -296,6 +314,134 @@ QPagedPaintDevice::Margins QPagedPaintDevice::margins() const } /*! + \since 5.3 + + Sets the page layout to \a newPageLayout. + + You should call this before calling QPainter::begin(), or immediately + before calling newPage() to apply the new page layout to a new page. + You should not call any painting methods between a call to setPageLayout() + and newPage() as the wrong paint metrics may be used. + + Returns true if the page layout was successfully set to \a newPageLayout. + + \sa pageLayout() +*/ + +bool QPagedPaintDevice::setPageLayout(const QPageLayout &newPageLayout) +{ + return d->setPageLayout(newPageLayout); +} + +/*! + \since 5.3 + + Sets the page size to \a pageSize. + + To get the current QPageSize use pageLayout().pageSize(). + + You should call this before calling QPainter::begin(), or immediately + before calling newPage() to apply the new page size to a new page. + You should not call any painting methods between a call to setPageSize() + and newPage() as the wrong paint metrics may be used. + + Returns true if the page size was successfully set to \a pageSize. + + \sa pageLayout() +*/ + +bool QPagedPaintDevice::setPageSize(const QPageSize &pageSize) +{ + return d->setPageSize(pageSize); +} + +/*! + \since 5.3 + + Sets the page \a orientation. + + The page orientation is used to define the orientation of the + page size when obtaining the page rect. + + You should call this before calling QPainter::begin(), or immediately + before calling newPage() to apply the new orientation to a new page. + You should not call any painting methods between a call to setPageOrientation() + and newPage() as the wrong paint metrics may be used. + + To get the current QPageLayout::Orientation use pageLayout().pageOrientation(). + + Returns true if the page orientation was successfully set to \a orientation. + + \sa pageLayout() +*/ + +bool QPagedPaintDevice::setPageOrientation(QPageLayout::Orientation orientation) +{ + return d->setPageOrientation(orientation); +} + +/*! + \since 5.3 + + Set the page \a margins in the current page layout units. + + You should call this before calling QPainter::begin(), or immediately + before calling newPage() to apply the new margins to a new page. + You should not call any painting methods between a call to setPageMargins() + and newPage() as the wrong paint metrics may be used. + + To get the current page margins use pageLayout().pageMargins(). + + Returns true if the page margins were successfully set to \a margins. + + \sa pageLayout() +*/ + +bool QPagedPaintDevice::setPageMargins(const QMarginsF &margins) +{ + return d->setPageMargins(margins); +} + +/*! + \since 5.3 + + Set the page \a margins defined in the given \a units. + + You should call this before calling QPainter::begin(), or immediately + before calling newPage() to apply the new margins to a new page. + You should not call any painting methods between a call to setPageMargins() + and newPage() as the wrong paint metrics may be used. + + To get the current page margins use pageLayout().pageMargins(). + + Returns true if the page margins were successfully set to \a margins. + + \sa pageLayout() +*/ + +bool QPagedPaintDevice::setPageMargins(const QMarginsF &margins, QPageLayout::Unit units) +{ + return d->setPageMargins(margins, units); +} + +/*! + \since 5.3 + + Returns the current page layout. Use this method to access the current + QPageSize, QPageLayout::Orientation, QMarginsF, fullRect() and paintRect(). + + Note that you cannot use the setters on the returned object, you must either + call the individual QPagedPaintDevice setters or use setPageLayout(). + + \sa setPageLayout(), setPageSize(), setPageOrientation(), setPageMargins() +*/ + +QPageLayout QPagedPaintDevice::pageLayout() const +{ + return d->pageLayout(); +} + +/*! \internal Returns the internal device page layout. diff --git a/src/gui/painting/qpagedpaintdevice.h b/src/gui/painting/qpagedpaintdevice.h index 6d4c422a95..dec56f9ce8 100644 --- a/src/gui/painting/qpagedpaintdevice.h +++ b/src/gui/painting/qpagedpaintdevice.h @@ -43,6 +43,7 @@ #define QPAGEDPAINTDEVICE_H #include <QtGui/qpaintdevice.h> +#include <QtGui/qpagelayout.h> QT_BEGIN_NAMESPACE @@ -51,7 +52,6 @@ QT_BEGIN_NAMESPACE #endif class QPagedPaintDevicePrivate; -class QPageLayout; class Q_GUI_EXPORT QPagedPaintDevice : public QPaintDevice { @@ -214,6 +214,14 @@ public: Envelope10 = Comm10E }; + // ### Qt6 Make these virtual + bool setPageLayout(const QPageLayout &pageLayout); + bool setPageSize(const QPageSize &pageSize); + bool setPageOrientation(QPageLayout::Orientation orientation); + bool setPageMargins(const QMarginsF &margins); + bool setPageMargins(const QMarginsF &margins, QPageLayout::Unit units); + QPageLayout pageLayout() const; + virtual void setPageSize(PageSize size); PageSize pageSize() const; @@ -232,6 +240,8 @@ public: Margins margins() const; protected: + QPagedPaintDevice(QPagedPaintDevicePrivate *dd); + QPagedPaintDevicePrivate *dd(); QPageLayout devicePageLayout() const; QPageLayout &devicePageLayout(); friend class QPagedPaintDevicePrivate; diff --git a/src/gui/painting/qpagedpaintdevice_p.h b/src/gui/painting/qpagedpaintdevice_p.h index da58951dc7..2321494779 100644 --- a/src/gui/painting/qpagedpaintdevice_p.h +++ b/src/gui/painting/qpagedpaintdevice_p.h @@ -55,8 +55,6 @@ #include <qpagedpaintdevice.h> -#include "qpagelayout.h" - QT_BEGIN_NAMESPACE class Q_GUI_EXPORT QPagedPaintDevicePrivate @@ -71,6 +69,46 @@ public: { } + virtual ~QPagedPaintDevicePrivate() + { + } + + // ### Qt6 Remove these and make public class methods virtual + virtual bool setPageLayout(const QPageLayout &newPageLayout) + { + m_pageLayout = newPageLayout; + return m_pageLayout.isEquivalentTo(newPageLayout);; + } + + virtual bool setPageSize(const QPageSize &pageSize) + { + m_pageLayout.setPageSize(pageSize); + return m_pageLayout.pageSize().isEquivalentTo(pageSize); + } + + virtual bool setPageOrientation(QPageLayout::Orientation orientation) + { + m_pageLayout.setOrientation(orientation); + return m_pageLayout.orientation() == orientation; + } + + virtual bool setPageMargins(const QMarginsF &margins) + { + return setPageMargins(margins, m_pageLayout.units()); + } + + virtual bool setPageMargins(const QMarginsF &margins, QPageLayout::Unit units) + { + m_pageLayout.setUnits(units); + m_pageLayout.setMargins(margins); + return m_pageLayout.margins() == margins && m_pageLayout.units() == units; + } + + virtual QPageLayout pageLayout() const + { + return m_pageLayout; + } + static inline QPagedPaintDevicePrivate *get(QPagedPaintDevice *pd) { return pd->d; } QPageLayout m_pageLayout; diff --git a/src/gui/painting/qpdfwriter.cpp b/src/gui/painting/qpdfwriter.cpp index 08c8f42fd9..b856d6625c 100644 --- a/src/gui/painting/qpdfwriter.cpp +++ b/src/gui/painting/qpdfwriter.cpp @@ -43,6 +43,7 @@ #ifndef QT_NO_PDF +#include "qpagedpaintdevice_p.h" #include <QtCore/private/qobject_p.h> #include "private/qpdf_p.h" #include <QtCore/qfile.h> @@ -68,6 +69,64 @@ public: QFile *output; }; +class QPdfPagedPaintDevicePrivate : public QPagedPaintDevicePrivate +{ +public: + QPdfPagedPaintDevicePrivate(QPdfWriterPrivate *d) + : QPagedPaintDevicePrivate(), pd(d) + {} + + virtual ~QPdfPagedPaintDevicePrivate() + {} + + bool setPageLayout(const QPageLayout &newPageLayout) Q_DECL_OVERRIDE + { + // Try to set the paint engine page layout + pd->engine->setPageLayout(newPageLayout); + // Set QPagedPaintDevice layout to match the current paint engine layout + m_pageLayout = pd->engine->pageLayout(); + return m_pageLayout.isEquivalentTo(newPageLayout); + } + + bool setPageSize(const QPageSize &pageSize) Q_DECL_OVERRIDE + { + // Try to set the paint engine page size + pd->engine->setPageSize(pageSize); + // Set QPagedPaintDevice layout to match the current paint engine layout + m_pageLayout = pd->engine->pageLayout(); + return m_pageLayout.pageSize().isEquivalentTo(pageSize); + } + + bool setPageOrientation(QPageLayout::Orientation orientation) Q_DECL_OVERRIDE + { + // Set the print engine value + pd->engine->setPageOrientation(orientation); + // Set QPagedPaintDevice layout to match the current paint engine layout + m_pageLayout = pd->engine->pageLayout(); + return m_pageLayout.orientation() == orientation; + } + + bool setPageMargins(const QMarginsF &margins) Q_DECL_OVERRIDE + { + return setPageMargins(margins, pageLayout().units()); + } + + bool setPageMargins(const QMarginsF &margins, QPageLayout::Unit units) Q_DECL_OVERRIDE + { + // Try to set engine margins + pd->engine->setPageMargins(margins, units); + // Set QPagedPaintDevice layout to match the current paint engine layout + m_pageLayout = pd->engine->pageLayout(); + return m_pageLayout.margins() == margins && m_pageLayout.units() == units; + } + + QPageLayout pageLayout() const Q_DECL_OVERRIDE + { + return pd->engine->pageLayout(); + } + + QPdfWriterPrivate *pd; +}; /*! \class QPdfWriter \inmodule QtGui @@ -85,7 +144,8 @@ public: Constructs a PDF writer that will write the pdf to \a filename. */ QPdfWriter::QPdfWriter(const QString &filename) - : QObject(*new QPdfWriterPrivate) + : QObject(*new QPdfWriterPrivate), + QPagedPaintDevice(new QPdfPagedPaintDevicePrivate(d_func())) { Q_D(QPdfWriter); @@ -195,7 +255,10 @@ int QPdfWriter::resolution() const return d->engine->resolution(); } +// Defined in QPagedPaintDevice but non-virtual, add QPdfWriter specific doc here +#ifdef Q_QDOC /*! + \fn bool QPdfWriter::setPageLayout(const QPageLayout &newPageLayout) \since 5.3 Sets the PDF page layout to \a newPageLayout. @@ -210,17 +273,8 @@ int QPdfWriter::resolution() const \sa pageLayout() */ -bool QPdfWriter::setPageLayout(const QPageLayout &newPageLayout) -{ - Q_D(const QPdfWriter); - // Try to set the paint engine page layout - d->engine->setPageLayout(newPageLayout); - // Set QPagedPaintDevice layout to match the current paint engine layout - devicePageLayout() = d->engine->pageLayout(); - return pageLayout().isEquivalentTo(newPageLayout); -} - /*! + \fn bool QPdfWriter::setPageSize(const QPageSize &pageSize) \since 5.3 Sets the PDF page size to \a pageSize. @@ -237,17 +291,8 @@ bool QPdfWriter::setPageLayout(const QPageLayout &newPageLayout) \sa pageLayout() */ -bool QPdfWriter::setPageSize(const QPageSize &pageSize) -{ - Q_D(const QPdfWriter); - // Try to set the paint engine page size - d->engine->setPageSize(pageSize); - // Set QPagedPaintDevice layout to match the current paint engine layout - devicePageLayout() = d->engine->pageLayout(); - return pageLayout().pageSize().isEquivalentTo(pageSize); -} - /*! + \fn bool QPdfWriter::setPageOrientation(QPageLayout::Orientation orientation) \since 5.3 Sets the PDF page \a orientation. @@ -267,17 +312,8 @@ bool QPdfWriter::setPageSize(const QPageSize &pageSize) \sa pageLayout() */ -bool QPdfWriter::setPageOrientation(QPageLayout::Orientation orientation) -{ - Q_D(const QPdfWriter); - // Set the print engine value - d->engine->setPageOrientation(orientation); - // Set QPagedPaintDevice layout to match the current paint engine layout - devicePageLayout() = d->engine->pageLayout(); - return pageLayout().orientation() == orientation; -} - /*! + \fn bool QPdfWriter::setPageMargins(const QMarginsF &margins) \since 5.3 Set the PDF page \a margins in the current page layout units. @@ -294,17 +330,8 @@ bool QPdfWriter::setPageOrientation(QPageLayout::Orientation orientation) \sa pageLayout() */ -bool QPdfWriter::setPageMargins(const QMarginsF &margins) -{ - Q_D(const QPdfWriter); - // Try to set engine margins - d->engine->setPageMargins(margins, pageLayout().units()); - // Set QPagedPaintDevice layout to match the current paint engine layout - devicePageLayout() = d->engine->pageLayout(); - return pageLayout().margins() == margins; -} - /*! + \fn bool QPdfWriter::setPageMargins(const QMarginsF &margins, QPageLayout::Unit units) \since 5.3 Set the PDF page \a margins defined in the given \a units. @@ -321,17 +348,10 @@ bool QPdfWriter::setPageMargins(const QMarginsF &margins) \sa pageLayout() */ -bool QPdfWriter::setPageMargins(const QMarginsF &margins, QPageLayout::Unit units) -{ - Q_D(const QPdfWriter); - // Try to set engine margins - d->engine->setPageMargins(margins, units); - // Set QPagedPaintDevice layout to match the current paint engine layout - devicePageLayout() = d->engine->pageLayout(); - return pageLayout().margins() == margins && pageLayout().units() == units; -} - /*! + \fn QPageLayout QPdfWriter::pageLayout() const + \since 5.3 + Returns the current page layout. Use this method to access the current QPageSize, QPageLayout::Orientation, QMarginsF, fullRect() and paintRect(). @@ -340,12 +360,7 @@ bool QPdfWriter::setPageMargins(const QMarginsF &margins, QPageLayout::Unit unit \sa setPageLayout(), setPageSize(), setPageOrientation(), setPageMargins() */ - -QPageLayout QPdfWriter::pageLayout() const -{ - Q_D(const QPdfWriter); - return d->engine->pageLayout(); -} +#endif /*! \reimp diff --git a/src/gui/painting/qpdfwriter.h b/src/gui/painting/qpdfwriter.h index fce0b88ea8..747ce380e7 100644 --- a/src/gui/painting/qpdfwriter.h +++ b/src/gui/painting/qpdfwriter.h @@ -74,13 +74,16 @@ public: void setResolution(int resolution); int resolution() const; +#ifdef Q_QDOC bool setPageLayout(const QPageLayout &pageLayout); bool setPageSize(const QPageSize &pageSize); bool setPageOrientation(QPageLayout::Orientation orientation); bool setPageMargins(const QMarginsF &margins); bool setPageMargins(const QMarginsF &margins, QPageLayout::Unit units); - QPageLayout pageLayout() const; +#else + using QPagedPaintDevice::setPageSize; +#endif void setPageSize(PageSize size); void setPageSizeMM(const QSizeF &size); |