diff options
author | Lars Knoll <lars.knoll@nokia.com> | 2011-08-18 11:04:06 +0200 |
---|---|---|
committer | Lars Knoll <lars.knoll@nokia.com> | 2011-08-19 09:17:03 +0200 |
commit | 28f1c1b9ef10fc3a49a64a535c7747a009939453 (patch) | |
tree | 7b8211a4130804ccf7f1210da003eb2792e15fde /src/gui/painting | |
parent | 6d2c5d9ffe255410c34edbb1c1228e68c9d745bd (diff) |
Restore feature compatibility with QPrinter in QTextDocument::print
Add a margin method to QPagedPaintDevice. The other variables
required are stored in QPagedPaintDevicePrivate without a
public API for now. This needs cleaning up once we have a new
printing system.
Change-Id: Id3f2d7ac7f3cbce8619072a897d91f3a588add64
Reviewed-on: http://codereview.qt.nokia.com/3211
Reviewed-by: Qt Sanity Bot <qt_sanity_bot@ovi.com>
Reviewed-by: Gunnar Sletta <gunnar.sletta@nokia.com>
Diffstat (limited to 'src/gui/painting')
-rw-r--r-- | src/gui/painting/painting.pri | 1 | ||||
-rw-r--r-- | src/gui/painting/qpagedpaintdevice.cpp | 26 | ||||
-rw-r--r-- | src/gui/painting/qpagedpaintdevice.h | 13 | ||||
-rw-r--r-- | src/gui/painting/qpagedpaintdevice_p.h | 89 | ||||
-rw-r--r-- | src/gui/painting/qpdfwriter.cpp | 15 | ||||
-rw-r--r-- | src/gui/painting/qpdfwriter.h | 2 |
6 files changed, 144 insertions, 2 deletions
diff --git a/src/gui/painting/painting.pri b/src/gui/painting/painting.pri index 530bdb36df..c059e96c86 100644 --- a/src/gui/painting/painting.pri +++ b/src/gui/painting/painting.pri @@ -12,6 +12,7 @@ HEADERS += \ painting/qmemrotate_p.h \ painting/qoutlinemapper_p.h \ painting/qpagedpaintdevice.h \ + painting/qpagedpaintdevice_p.h \ painting/qpaintdevice.h \ painting/qpaintengine.h \ painting/qpaintengine_p.h \ diff --git a/src/gui/painting/qpagedpaintdevice.cpp b/src/gui/painting/qpagedpaintdevice.cpp index dd756db023..e5b2c0716e 100644 --- a/src/gui/painting/qpagedpaintdevice.cpp +++ b/src/gui/painting/qpagedpaintdevice.cpp @@ -46,6 +46,7 @@ class QPagedPaintDevicePrivate public: QPagedPaintDevice::PageSize pageSize; QSizeF pageSizeMM; + QPagedPaintDevice::Margins margins; }; static const struct { @@ -102,7 +103,6 @@ static const struct { QPagedPaintDevice::QPagedPaintDevice() : d(new QPagedPaintDevicePrivate) { - setPageSize(A4); } /*! @@ -201,3 +201,27 @@ QSizeF QPagedPaintDevice::pageSizeMM() const return d->pageSizeMM; } +/*! + Sets the margins to be used to \a margins. + + Margins are specified in millimeters. + + The margins are purely a hint to the drawing method. They don't affect the + coordinate system or clipping. + + \sa margins + */ +void QPagedPaintDevice::setMargins(const Margins &margins) +{ + d->margins = margins; +} + +/*! + returns the current margins of the paint device. The default is 0. + + /sa setMargins + */ +QPagedPaintDevice::Margins QPagedPaintDevice::margins() const +{ + return d->margins; +} diff --git a/src/gui/painting/qpagedpaintdevice.h b/src/gui/painting/qpagedpaintdevice.h index faba555adf..f3a133a8d9 100644 --- a/src/gui/painting/qpagedpaintdevice.h +++ b/src/gui/painting/qpagedpaintdevice.h @@ -31,7 +31,18 @@ public: virtual void setPageSizeMM(const QSizeF &size); QSizeF pageSizeMM() const; -private: + struct Margins { + qreal left; + qreal right; + qreal top; + qreal bottom; + }; + + virtual void setMargins(const Margins &margins); + Margins margins() const; + +protected: + friend class QPagedPaintDevicePrivate; QPagedPaintDevicePrivate *d; }; diff --git a/src/gui/painting/qpagedpaintdevice_p.h b/src/gui/painting/qpagedpaintdevice_p.h new file mode 100644 index 0000000000..55f78d54c5 --- /dev/null +++ b/src/gui/painting/qpagedpaintdevice_p.h @@ -0,0 +1,89 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtGui module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QPAGEDPAINTDEVICE_P_H +#define QPAGEDPAINTDEVICE_P_H + +// +// W A R N I N G +// ------------- +// +// This file is not part of the Qt API. It exists purely as an +// implementation detail. This header file may change from version to +// version without notice, or even be removed. +// +// We mean it. +// + +#include <qpagedpaintdevice.h> + +QT_BEGIN_NAMESPACE + +class Q_GUI_EXPORT QPagedPaintDevicePrivate +{ +public: + QPagedPaintDevicePrivate() + : pageSize(QPagedPaintDevice::A4), + pageSizeMM(210, 297), + fromPage(0), + toPage(0), + pageOrderAscending(true), + printSelectionOnly(false) + { + margins.left = margins.right = margins.top = margins.bottom = 0; + } + + static inline QPagedPaintDevicePrivate *get(QPagedPaintDevice *pd) { return pd->d; } + + QPagedPaintDevice::PageSize pageSize; + QSizeF pageSizeMM; + QPagedPaintDevice::Margins margins; + + // These are currently required to keep QPrinter functionality working in QTextDocument::print() + int fromPage; + int toPage; + bool pageOrderAscending; + bool printSelectionOnly; +}; + +QT_END_NAMESPACE + +#endif diff --git a/src/gui/painting/qpdfwriter.cpp b/src/gui/painting/qpdfwriter.cpp index e36caf568f..9da5491d19 100644 --- a/src/gui/painting/qpdfwriter.cpp +++ b/src/gui/painting/qpdfwriter.cpp @@ -195,3 +195,18 @@ bool QPdfWriter::newPage() return d->engine->newPage(); } + + +/*! + \reimp + */ +void QPdfWriter::setMargins(const Margins &m) +{ + Q_D(QPdfWriter); + + const qreal multiplier = 72./25.4; + d->engine->d_func()->leftMargin = m.left*multiplier; + d->engine->d_func()->rightMargin = m.right*multiplier; + d->engine->d_func()->topMargin = m.top*multiplier; + d->engine->d_func()->bottomMargin = m.bottom*multiplier; +} diff --git a/src/gui/painting/qpdfwriter.h b/src/gui/painting/qpdfwriter.h index 4e617aa617..b224c12ed7 100644 --- a/src/gui/painting/qpdfwriter.h +++ b/src/gui/painting/qpdfwriter.h @@ -72,6 +72,8 @@ public: void setPageSize(PageSize size); void setPageSizeMM(const QSizeF &size); + void setMargins(const Margins &m); + protected: QPaintEngine *paintEngine() const; int metric(PaintDeviceMetric id) const; |