diff options
Diffstat (limited to 'src/gui')
-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 | ||||
-rw-r--r-- | src/gui/text/qtextcontrol.cpp | 6 | ||||
-rw-r--r-- | src/gui/text/qtextdocument.cpp | 21 |
8 files changed, 157 insertions, 16 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; diff --git a/src/gui/text/qtextcontrol.cpp b/src/gui/text/qtextcontrol.cpp index 03845deb38..d280a67a1b 100644 --- a/src/gui/text/qtextcontrol.cpp +++ b/src/gui/text/qtextcontrol.cpp @@ -60,6 +60,7 @@ #include "qtextdocumentwriter.h" #include "private/qtextcursor_p.h" #include "qpagedpaintdevice.h" +#include "private/qpagedpaintdevice_p.h" #include <qtextformat.h> #include <qdatetime.h> @@ -2237,9 +2238,7 @@ void QTextControl::print(QPagedPaintDevice *printer) const return; QTextDocument *tempDoc = 0; const QTextDocument *doc = d->doc; - // #### -#if 0 - if (printer->printRange() == QPrinter::Selection) { + if (QPagedPaintDevicePrivate::get(printer)->printSelectionOnly) { if (!d->cursor.hasSelection()) return; tempDoc = new QTextDocument(const_cast<QTextDocument *>(doc)); @@ -2253,7 +2252,6 @@ void QTextControl::print(QPagedPaintDevice *printer) const // copy the custom object handlers doc->documentLayout()->d_func()->handlers = d->doc->documentLayout()->d_func()->handlers; } -#endif doc->print(printer); delete tempDoc; } diff --git a/src/gui/text/qtextdocument.cpp b/src/gui/text/qtextdocument.cpp index 6e3d5286e0..c1714edb0c 100644 --- a/src/gui/text/qtextdocument.cpp +++ b/src/gui/text/qtextdocument.cpp @@ -64,6 +64,7 @@ #include "qtextdocument_p.h" #include <private/qabstracttextdocumentlayout_p.h> #include "qpagedpaintdevice.h" +#include "private/qpagedpaintdevice_p.h" #include <limits.h> @@ -1717,16 +1718,18 @@ void QTextDocument::print(QPagedPaintDevice *printer) const if (!printer) return; - // ### -// if (!d->title.isEmpty()) -// printer->setDocName(d->title); - bool documentPaginated = d->pageSize.isValid() && !d->pageSize.isNull() && d->pageSize.height() != INT_MAX; + QPagedPaintDevicePrivate *pd = QPagedPaintDevicePrivate::get(printer); + // ### set page size to paginated size? -// if (!documentPaginated && !printer->fullPage() && !printer->d_func()->hasCustomPageMargins) -// printer->setPageMargins(23.53, 23.53, 23.53, 23.53, QPrinter::Millimeter); + QPagedPaintDevice::Margins m = printer->margins(); + if (!documentPaginated && m.left == 0. && m.right == 0. && m.top == 0. && m.bottom == 0.) { + m.left = m.right = m.top = m.bottom = 2.; + printer->setMargins(m); + } + // ### use the margins correctly QPainter p(printer); @@ -1796,10 +1799,8 @@ void QTextDocument::print(QPagedPaintDevice *printer) const clonedDoc->setPageSize(body.size()); } - int fromPage = 0; - int toPage = 0; -// int fromPage = printer->fromPage(); -// int toPage = printer->toPage(); + int fromPage = pd->fromPage; + int toPage = pd->toPage; bool ascending = true; if (fromPage == 0 && toPage == 0) { |