From 9ebdc333a6a6485fd60a50a742a1d6edec211f53 Mon Sep 17 00:00:00 2001 From: Lars Knoll Date: Wed, 17 Aug 2011 11:26:51 +0200 Subject: Introduce a paged paintdevice and use it Introduce a QPagedPaintDevice class that has a newPage() method and page dimensions. QPdfWriter and QPrinter inherit from it. Add a bit of API to QPdfWriter. Change-Id: Ibf23e7fe741f3a5ed854faf5d249a272acc75f35 Reviewed-on: http://codereview.qt.nokia.com/3206 Reviewed-by: Gunnar Sletta --- src/gui/painting/qpagedpaintdevice.cpp | 203 +++++++++++++++++++++++++++++++++ 1 file changed, 203 insertions(+) create mode 100644 src/gui/painting/qpagedpaintdevice.cpp (limited to 'src/gui/painting/qpagedpaintdevice.cpp') diff --git a/src/gui/painting/qpagedpaintdevice.cpp b/src/gui/painting/qpagedpaintdevice.cpp new file mode 100644 index 0000000000..dd756db023 --- /dev/null +++ b/src/gui/painting/qpagedpaintdevice.cpp @@ -0,0 +1,203 @@ +/**************************************************************************** +** +** 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$ +** +****************************************************************************/ + +#include + +class QPagedPaintDevicePrivate +{ +public: + QPagedPaintDevice::PageSize pageSize; + QSizeF pageSizeMM; +}; + +static const struct { + float width; + float height; +} pageSizes[] = { + {210, 297}, // A4 + {176, 250}, // B5 + {215.9f, 279.4f}, // Letter + {215.9f, 355.6f}, // Legal + {190.5f, 254}, // Executive + {841, 1189}, // A0 + {594, 841}, // A1 + {420, 594}, // A2 + {297, 420}, // A3 + {148, 210}, // A5 + {105, 148}, // A6 + {74, 105}, // A7 + {52, 74}, // A8 + {37, 52}, // A8 + {1000, 1414}, // B0 + {707, 1000}, // B1 + {31, 44}, // B10 + {500, 707}, // B2 + {353, 500}, // B3 + {250, 353}, // B4 + {125, 176}, // B6 + {88, 125}, // B7 + {62, 88}, // B8 + {33, 62}, // B9 + {163, 229}, // C5E + {105, 241}, // US Common + {110, 220}, // DLE + {210, 330}, // Folio + {431.8f, 279.4f}, // Ledger + {279.4f, 431.8f} // Tabloid +}; + +/*! + \class QPagedPaintDevice + + \brief The QPagedPaintDevice class is a represents a paintdevice that supports + multiple pages. + + \ingroup painting + + Paged paint devices are used to generate output for printing or for formats like PDF. + QPdfWriter and QPrinter inherit from it. + */ + +/*! + Constructs a new paged paint device. + */ +QPagedPaintDevice::QPagedPaintDevice() + : d(new QPagedPaintDevicePrivate) +{ + setPageSize(A4); +} + +/*! + Destroys the object. + */ +QPagedPaintDevice::~QPagedPaintDevice() +{ + delete d; +} + +/*! + \enum QPagedPaintDevice::PageSize + + This enum type specifies the page size of the paint device. + + \value A0 841 x 1189 mm + \value A1 594 x 841 mm + \value A2 420 x 594 mm + \value A3 297 x 420 mm + \value A4 210 x 297 mm, 8.26 x 11.69 inches + \value A5 148 x 210 mm + \value A6 105 x 148 mm + \value A7 74 x 105 mm + \value A8 52 x 74 mm + \value A9 37 x 52 mm + \value B0 1000 x 1414 mm + \value B1 707 x 1000 mm + \value B2 500 x 707 mm + \value B3 353 x 500 mm + \value B4 250 x 353 mm + \value B5 176 x 250 mm, 6.93 x 9.84 inches + \value B6 125 x 176 mm + \value B7 88 x 125 mm + \value B8 62 x 88 mm + \value B9 33 x 62 mm + \value B10 31 x 44 mm + \value C5E 163 x 229 mm + \value Comm10E 105 x 241 mm, U.S. Common 10 Envelope + \value DLE 110 x 220 mm + \value Executive 7.5 x 10 inches, 190.5 x 254 mm + \value Folio 210 x 330 mm + \value Ledger 431.8 x 279.4 mm + \value Legal 8.5 x 14 inches, 215.9 x 355.6 mm + \value Letter 8.5 x 11 inches, 215.9 x 279.4 mm + \value Tabloid 279.4 x 431.8 mm + \value Custom Unknown, or a user defined size. + + \omitvalue NPageSize + + The page size can also be specified in millimeters using setPageSizeMM(). In this case the + page size enum is set to Custom. +*/ + +/*! + \fn bool QPagedPaintDevice::newPage() + + Starts a new page. +*/ + + +/*! + Sets the size of the a page to \a size. + + \sa setPageSizeMM + */ +void QPagedPaintDevice::setPageSize(PageSize size) +{ + if (size >= Custom) + return; + d->pageSize = size; + d->pageSizeMM = QSizeF(pageSizes[A4].width, pageSizes[A4].height); +} + +/*! + Returns the currently used page size. + */ +QPagedPaintDevice::PageSize QPagedPaintDevice::pageSize() const +{ + return d->pageSize; +} + +/*! + Sets the page size to \a size. \a size is specified in millimeters. + */ +void QPagedPaintDevice::setPageSizeMM(const QSizeF &size) +{ + d->pageSize = Custom; + d->pageSizeMM = size; +} + +/*! + Returns the page size in millimeters. + */ +QSizeF QPagedPaintDevice::pageSizeMM() const +{ + return d->pageSizeMM; +} + -- cgit v1.2.3