summaryrefslogtreecommitdiffstats
path: root/src/gui/painting/qpagedpaintdevice.cpp
blob: e5b2c0716e9870e4493e35beefdcd93c70ee3d33 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
/****************************************************************************
**
** 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 <qpagedpaintdevice.h>

class QPagedPaintDevicePrivate
{
public:
    QPagedPaintDevice::PageSize pageSize;
    QSizeF pageSizeMM;
    QPagedPaintDevice::Margins margins;
};

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)
{
}

/*!
  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;
}

/*!
  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;
}