Merge remote branch 'gerrit/master' into refactor
[profile/ivi/qtbase.git] / src / gui / painting / qpagedpaintdevice.cpp
1 /****************************************************************************
2 **
3 ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
4 ** All rights reserved.
5 ** Contact: Nokia Corporation (qt-info@nokia.com)
6 **
7 ** This file is part of the QtGui module of the Qt Toolkit.
8 **
9 ** $QT_BEGIN_LICENSE:LGPL$
10 ** GNU Lesser General Public License Usage
11 ** This file may be used under the terms of the GNU Lesser General Public
12 ** License version 2.1 as published by the Free Software Foundation and
13 ** appearing in the file LICENSE.LGPL included in the packaging of this
14 ** file. Please review the following information to ensure the GNU Lesser
15 ** General Public License version 2.1 requirements will be met:
16 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
17 **
18 ** In addition, as a special exception, Nokia gives you certain additional
19 ** rights. These rights are described in the Nokia Qt LGPL Exception
20 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
21 **
22 ** GNU General Public License Usage
23 ** Alternatively, this file may be used under the terms of the GNU General
24 ** Public License version 3.0 as published by the Free Software Foundation
25 ** and appearing in the file LICENSE.GPL included in the packaging of this
26 ** file. Please review the following information to ensure the GNU General
27 ** Public License version 3.0 requirements will be met:
28 ** http://www.gnu.org/copyleft/gpl.html.
29 **
30 ** Other Usage
31 ** Alternatively, this file may be used in accordance with the terms and
32 ** conditions contained in a signed written agreement between you and Nokia.
33 **
34 **
35 **
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41
42 #include <qpagedpaintdevice.h>
43
44 class QPagedPaintDevicePrivate
45 {
46 public:
47     QPagedPaintDevice::PageSize pageSize;
48     QSizeF pageSizeMM;
49     QPagedPaintDevice::Margins margins;
50 };
51
52 static const struct {
53     float width;
54     float height;
55 } pageSizes[] = {
56     {210, 297}, // A4
57     {176, 250}, // B5
58     {215.9f, 279.4f}, // Letter
59     {215.9f, 355.6f}, // Legal
60     {190.5f, 254}, // Executive
61     {841, 1189}, // A0
62     {594, 841}, // A1
63     {420, 594}, // A2
64     {297, 420}, // A3
65     {148, 210}, // A5
66     {105, 148}, // A6
67     {74, 105}, // A7
68     {52, 74}, // A8
69     {37, 52}, // A8
70     {1000, 1414}, // B0
71     {707, 1000}, // B1
72     {31, 44}, // B10
73     {500, 707}, // B2
74     {353, 500}, // B3
75     {250, 353}, // B4
76     {125, 176}, // B6
77     {88, 125}, // B7
78     {62, 88}, // B8
79     {33, 62}, // B9
80     {163, 229}, // C5E
81     {105, 241}, // US Common
82     {110, 220}, // DLE
83     {210, 330}, // Folio
84     {431.8f, 279.4f}, // Ledger
85     {279.4f, 431.8f} // Tabloid
86 };
87
88 /*!
89     \class QPagedPaintDevice
90
91     \brief The QPagedPaintDevice class is a represents a paintdevice that supports
92     multiple pages.
93
94     \ingroup painting
95
96     Paged paint devices are used to generate output for printing or for formats like PDF.
97     QPdfWriter and QPrinter inherit from it.
98   */
99
100 /*!
101   Constructs a new paged paint device.
102   */
103 QPagedPaintDevice::QPagedPaintDevice()
104     : d(new QPagedPaintDevicePrivate)
105 {
106 }
107
108 /*!
109   Destroys the object.
110   */
111 QPagedPaintDevice::~QPagedPaintDevice()
112 {
113     delete d;
114 }
115
116 /*!
117   \enum QPagedPaintDevice::PageSize
118
119   This enum type specifies the page size of the paint device.
120
121   \value A0 841 x 1189 mm
122   \value A1 594 x 841 mm
123   \value A2 420 x 594 mm
124   \value A3 297 x 420 mm
125   \value A4 210 x 297 mm, 8.26 x 11.69 inches
126   \value A5 148 x 210 mm
127   \value A6 105 x 148 mm
128   \value A7 74 x 105 mm
129   \value A8 52 x 74 mm
130   \value A9 37 x 52 mm
131   \value B0 1000 x 1414 mm
132   \value B1 707 x 1000 mm
133   \value B2 500 x 707 mm
134   \value B3 353 x 500 mm
135   \value B4 250 x 353 mm
136   \value B5 176 x 250 mm, 6.93 x 9.84 inches
137   \value B6 125 x 176 mm
138   \value B7 88 x 125 mm
139   \value B8 62 x 88 mm
140   \value B9 33 x 62 mm
141   \value B10 31 x 44 mm
142   \value C5E 163 x 229 mm
143   \value Comm10E 105 x 241 mm, U.S. Common 10 Envelope
144   \value DLE 110 x 220 mm
145   \value Executive 7.5 x 10 inches, 190.5 x 254 mm
146   \value Folio 210 x 330 mm
147   \value Ledger 431.8 x 279.4 mm
148   \value Legal 8.5 x 14 inches, 215.9 x 355.6 mm
149   \value Letter 8.5 x 11 inches, 215.9 x 279.4 mm
150   \value Tabloid 279.4 x 431.8 mm
151   \value Custom Unknown, or a user defined size.
152
153   \omitvalue NPageSize
154
155   The page size can also be specified in millimeters using setPageSizeMM(). In this case the
156   page size enum is set to Custom.
157 */
158
159 /*!
160   \fn bool QPagedPaintDevice::newPage()
161
162   Starts a new page.
163 */
164
165
166 /*!
167   Sets the size of the a page to \a size.
168
169   \sa setPageSizeMM
170   */
171 void QPagedPaintDevice::setPageSize(PageSize size)
172 {
173     if (size >= Custom)
174         return;
175     d->pageSize = size;
176     d->pageSizeMM = QSizeF(pageSizes[A4].width, pageSizes[A4].height);
177 }
178
179 /*!
180   Returns the currently used page size.
181   */
182 QPagedPaintDevice::PageSize QPagedPaintDevice::pageSize() const
183 {
184     return d->pageSize;
185 }
186
187 /*!
188   Sets the page size to \a size. \a size is specified in millimeters.
189   */
190 void QPagedPaintDevice::setPageSizeMM(const QSizeF &size)
191 {
192     d->pageSize = Custom;
193     d->pageSizeMM = size;
194 }
195
196 /*!
197   Returns the page size in millimeters.
198   */
199 QSizeF QPagedPaintDevice::pageSizeMM() const
200 {
201     return d->pageSizeMM;
202 }
203
204 /*!
205   Sets the margins to be used to \a margins.
206
207   Margins are specified in millimeters.
208
209   The margins are purely a hint to the drawing method. They don't affect the
210   coordinate system or clipping.
211
212   \sa margins
213   */
214 void QPagedPaintDevice::setMargins(const Margins &margins)
215 {
216     d->margins = margins;
217 }
218
219 /*!
220   returns the current margins of the paint device. The default is 0.
221
222   /sa setMargins
223   */
224 QPagedPaintDevice::Margins QPagedPaintDevice::margins() const
225 {
226     return d->margins;
227 }