Make QRegion not need to be friends with QVector
[profile/ivi/qtbase.git] / src / gui / painting / qpdfwriter.cpp
1 /****************************************************************************
2 **
3 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/
5 **
6 ** This file is part of the QtGui module of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** GNU Lesser General Public License Usage
10 ** This file may be used under the terms of the GNU Lesser General Public
11 ** License version 2.1 as published by the Free Software Foundation and
12 ** appearing in the file LICENSE.LGPL included in the packaging of this
13 ** file. Please review the following information to ensure the GNU Lesser
14 ** General Public License version 2.1 requirements will be met:
15 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
16 **
17 ** In addition, as a special exception, Nokia gives you certain additional
18 ** rights. These rights are described in the Nokia Qt LGPL Exception
19 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
20 **
21 ** GNU General Public License Usage
22 ** Alternatively, this file may be used under the terms of the GNU General
23 ** Public License version 3.0 as published by the Free Software Foundation
24 ** and appearing in the file LICENSE.GPL included in the packaging of this
25 ** file. Please review the following information to ensure the GNU General
26 ** Public License version 3.0 requirements will be met:
27 ** http://www.gnu.org/copyleft/gpl.html.
28 **
29 ** Other Usage
30 ** Alternatively, this file may be used in accordance with the terms and
31 ** conditions contained in a signed written agreement between you and Nokia.
32 **
33 **
34 **
35 **
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41
42 #include <qpdfwriter.h>
43 #include <QtCore/private/qobject_p.h>
44 #include "private/qpdf_p.h"
45 #include <QtCore/qfile.h>
46
47 QT_BEGIN_NAMESPACE
48
49 class QPdfWriterPrivate : public QObjectPrivate
50 {
51 public:
52     QPdfWriterPrivate()
53         : QObjectPrivate()
54     {
55         engine = new QPdfEngine();
56         output = 0;
57     }
58     ~QPdfWriterPrivate()
59     {
60         delete engine;
61         delete output;
62     }
63
64     QPdfEngine *engine;
65     QFile *output;
66 };
67
68
69 /*! \class QPdfWriter
70
71     \brief The QPdfWriter class is a class to generate PDFs
72     that can be used as a paint device.
73
74     \ingroup painting
75
76     QPdfWriter generates PDF out of a series of drawing commands using QPainter.
77     The newPage() method can be used to create several pages.
78   */
79
80 /*!
81   Constructs a PDF writer that will write the pdf to \a filename.
82   */
83 QPdfWriter::QPdfWriter(const QString &filename)
84     : QObject(*new QPdfWriterPrivate)
85 {
86     Q_D(QPdfWriter);
87
88     d->engine->setOutputFilename(filename);
89 }
90
91 /*!
92   Constructs a PDF writer that will write the pdf to \a device.
93   */
94 QPdfWriter::QPdfWriter(QIODevice *device)
95     : QObject(*new QPdfWriterPrivate)
96 {
97     Q_D(QPdfWriter);
98
99     d->engine->d_func()->outDevice = device;
100 }
101
102 /*!
103   Destroys the pdf writer.
104   */
105 QPdfWriter::~QPdfWriter()
106 {
107
108 }
109
110 /*!
111   Returns the title of the document.
112   */
113 QString QPdfWriter::title() const
114 {
115     Q_D(const QPdfWriter);
116     return d->engine->d_func()->title;
117 }
118
119 /*!
120   Sets the title of the document being created.
121   */
122 void QPdfWriter::setTitle(const QString &title)
123 {
124     Q_D(QPdfWriter);
125     d->engine->d_func()->title = title;
126 }
127
128 /*!
129   Returns the creator of the document.
130   */
131 QString QPdfWriter::creator() const
132 {
133     Q_D(const QPdfWriter);
134     return d->engine->d_func()->creator;
135 }
136
137 /*!
138   Sets the creator of the document.
139   */
140 void QPdfWriter::setCreator(const QString &creator)
141 {
142     Q_D(QPdfWriter);
143     d->engine->d_func()->creator = creator;
144 }
145
146
147 /*!
148   \reimp
149   */
150 QPaintEngine *QPdfWriter::paintEngine() const
151 {
152     Q_D(const QPdfWriter);
153
154     return d->engine;
155 }
156
157 /*!
158   \reimp
159   */
160 void QPdfWriter::setPageSize(PageSize size)
161 {
162     Q_D(const QPdfWriter);
163
164     QPagedPaintDevice::setPageSize(size);
165     d->engine->d_func()->paperSize = pageSizeMM() * 25.4/72.;
166 }
167
168 /*!
169   \reimp
170   */
171 void QPdfWriter::setPageSizeMM(const QSizeF &size)
172 {
173     Q_D(const QPdfWriter);
174
175     QPagedPaintDevice::setPageSizeMM(size);
176     d->engine->d_func()->paperSize = pageSizeMM() * 25.4/72.;
177 }
178
179 /*!
180     \internal
181
182     Returns the metric for the given \a id.
183 */
184 int QPdfWriter::metric(PaintDeviceMetric id) const
185 {
186     Q_D(const QPdfWriter);
187     return d->engine->metric(id);
188 }
189
190 /*!
191   \reimp
192 */
193 bool QPdfWriter::newPage()
194 {
195     Q_D(QPdfWriter);
196
197     return d->engine->newPage();
198 }
199
200
201 /*!
202   \reimp
203   */
204 void QPdfWriter::setMargins(const Margins &m)
205 {
206     Q_D(QPdfWriter);
207
208     const qreal multiplier = 72./25.4;
209     d->engine->d_func()->leftMargin = m.left*multiplier;
210     d->engine->d_func()->rightMargin = m.right*multiplier;
211     d->engine->d_func()->topMargin = m.top*multiplier;
212     d->engine->d_func()->bottomMargin = m.bottom*multiplier;
213 }
214
215 QT_END_NAMESPACE