diff options
author | John Layt <jlayt@kde.org> | 2013-12-30 18:04:40 +0100 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2014-03-17 13:46:10 +0100 |
commit | dbc50e06df8465e6de02ac0b4458e1a3f3f8568c (patch) | |
tree | 58375129a608575a7b99e6a3167baa668c9d7c25 /src/printsupport/kernel/qprintengine_win.cpp | |
parent | 70081096a152d6973d85a1c1466bbc058fe0b24b (diff) |
QPrinter - Use QPageSize and QPageLayout
Use QPageSize and QPageMargins to get/set values in the print engines,
add api to directly set the values, and rewrite the docs to make the
paper-based api obsolete instead of the page-based api.
Add new PPK keys to pass QPageSize, QPageMargins and QPageLayout to the
print engines to ensure no level of detail is lost, e.g. for custom
sizes passed to QPrinter.
[ChangeLog][QtPrintSupport][QPrinter] QPrinter can now use QPageSize
and QPageLayout in the public api to control the page layout for a
print job.
Change-Id: Iee39a4042bcd6141d29b0a82b49066d7a7a78120
Reviewed-by: Lars Knoll <lars.knoll@digia.com>
Diffstat (limited to 'src/printsupport/kernel/qprintengine_win.cpp')
-rw-r--r-- | src/printsupport/kernel/qprintengine_win.cpp | 60 |
1 files changed, 58 insertions, 2 deletions
diff --git a/src/printsupport/kernel/qprintengine_win.cpp b/src/printsupport/kernel/qprintengine_win.cpp index 78532f50dd..52b67d162b 100644 --- a/src/printsupport/kernel/qprintengine_win.cpp +++ b/src/printsupport/kernel/qprintengine_win.cpp @@ -62,6 +62,7 @@ #include <private/qpixmap_raster_p.h> #include <QtCore/QMetaType> #include <QtCore/qt_windows.h> +#include <QtGui/qpagelayout.h> Q_DECLARE_METATYPE(HFONT) Q_DECLARE_METATYPE(LOGFONT) @@ -1195,8 +1196,50 @@ void QWin32PrintEngine::setProperty(PrintEnginePropertyKey key, const QVariant & break; } - // No default so that compiler will complain if new keys added and not handled in this engine + case PPK_QPageSize: { + // Get the page size from the printer if supported + const QPageSize pageSize = value.value<QPageSize>(); + if (pageSize.isValid()) { + d->setPageSize(pageSize); + d->doReinit(); +#ifdef QT_DEBUG_METRICS + qDebug() << "QWin32PrintEngine::setProperty(PPK_QPageSize," << pageSize << ")"; + d->debugMetrics(); +#endif // QT_DEBUG_METRICS + } + break; + } + case PPK_QPageMargins: { + QPair<QMarginsF, QPageLayout::Unit> pair = value.value<QPair<QMarginsF, QPageLayout::Unit> >(); + d->m_pageLayout.setUnits(pair.second); + d->m_pageLayout.setMargins(pair.first); + d->updateMetrics(); +#ifdef QT_DEBUG_METRICS + qDebug() << "QWin32PrintEngine::setProperty(PPK_QPageMargins," << pair.first << pair.second << ")"; + d->debugMetrics(); +#endif // QT_DEBUG_METRICS + break; + } + + case PPK_QPageLayout: { + QPageLayout pageLayout = value.value<QPageLayout>(); + if (pageLayout.isValid() && d->m_printDevice.isValidPageLayout(pageLayout, d->resolution)) { + setProperty(PPK_QPageSize, QVariant::fromValue(pageLayout.pageSize())); + setProperty(PPK_FullPage, pageLayout.mode() == QPageLayout::FullPageMode); + setProperty(PPK_Orientation, QVariant::fromValue(pageLayout.orientation())); + d->m_pageLayout.setUnits(pageLayout.units()); + d->m_pageLayout.setMargins(pageLayout.margins()); + d->updateMetrics(); +#ifdef QT_DEBUG_METRICS + qDebug() << "QWin32PrintEngine::setProperty(PPK_QPageLayout," << pageLayout << ")"; + d->debugMetrics(); +#endif // QT_DEBUG_METRICS + } + break; + } + + // No default so that compiler will complain if new keys added and not handled in this engine } } @@ -1345,8 +1388,21 @@ QVariant QWin32PrintEngine::property(PrintEnginePropertyKey key) const break; } - // No default so that compiler will complain if new keys added and not handled in this engine + case PPK_QPageSize: + value.setValue(d->m_pageLayout.pageSize()); + break; + + case PPK_QPageMargins: { + QPair<QMarginsF, QPageLayout::Unit> pair = qMakePair(d->m_pageLayout.margins(), d->m_pageLayout.units()); + value.setValue(pair); + break; + } + + case PPK_QPageLayout: + value.setValue(d->m_pageLayout); + break; + // No default so that compiler will complain if new keys added and not handled in this engine } return value; } |