1/****************************************************************************
2**
3** Copyright (C) 2014 John Layt <jlayt@kde.org>
4** Contact: https://www.qt.io/licensing/
5**
6** This file is part of the QtGui module of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:LGPL$
9** Commercial License Usage
10** Licensees holding valid commercial Qt licenses may use this file in
11** accordance with the commercial license agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and The Qt Company. For licensing terms
14** and conditions see https://www.qt.io/terms-conditions. For further
15** information use the contact form at https://www.qt.io/contact-us.
16**
17** GNU Lesser General Public License Usage
18** Alternatively, this file may be used under the terms of the GNU Lesser
19** General Public License version 3 as published by the Free Software
20** Foundation and appearing in the file LICENSE.LGPL3 included in the
21** packaging of this file. Please review the following information to
22** ensure the GNU Lesser General Public License version 3 requirements
23** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
24**
25** GNU General Public License Usage
26** Alternatively, this file may be used under the terms of the GNU
27** General Public License version 2.0 or (at your option) the GNU General
28** Public license version 3 or any later version approved by the KDE Free
29** Qt Foundation. The licenses are as published by the Free Software
30** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
31** included in the packaging of this file. Please review the following
32** information to ensure the GNU General Public License requirements will
33** be met: https://www.gnu.org/licenses/gpl-2.0.html and
34** https://www.gnu.org/licenses/gpl-3.0.html.
35**
36** $QT_END_LICENSE$
37**
38****************************************************************************/
39
40#ifndef QPAGESIZE_H
41#define QPAGESIZE_H
42
43#include <QtGui/qtguiglobal.h>
44#include <QtCore/qsharedpointer.h>
45
46QT_BEGIN_NAMESPACE
47
48#if defined(B0)
49#undef B0 // Terminal hang-up. We assume that you do not want that.
50#endif
51
52class QPageSizePrivate;
53class QString;
54class QSize;
55class QSizeF;
56
57class Q_GUI_EXPORT QPageSize
58{
59public:
60
61 // ### Qt6 Re-order and remove duplicates
62 // NOTE: Must keep in sync with QPagedPrintEngine and QPrinter
63 enum PageSizeId {
64 // Existing Qt sizes
65 A4,
66 B5,
67 Letter,
68 Legal,
69 Executive,
70 A0,
71 A1,
72 A2,
73 A3,
74 A5,
75 A6,
76 A7,
77 A8,
78 A9,
79 B0,
80 B1,
81 B10,
82 B2,
83 B3,
84 B4,
85 B6,
86 B7,
87 B8,
88 B9,
89 C5E,
90 Comm10E,
91 DLE,
92 Folio,
93 Ledger,
94 Tabloid,
95 Custom,
96
97 // New values derived from PPD standard
98 A10,
99 A3Extra,
100 A4Extra,
101 A4Plus,
102 A4Small,
103 A5Extra,
104 B5Extra,
105
106 JisB0,
107 JisB1,
108 JisB2,
109 JisB3,
110 JisB4,
111 JisB5,
112 JisB6,
113 JisB7,
114 JisB8,
115 JisB9,
116 JisB10,
117
118 // AnsiA = Letter,
119 // AnsiB = Ledger,
120 AnsiC,
121 AnsiD,
122 AnsiE,
123 LegalExtra,
124 LetterExtra,
125 LetterPlus,
126 LetterSmall,
127 TabloidExtra,
128
129 ArchA,
130 ArchB,
131 ArchC,
132 ArchD,
133 ArchE,
134
135 Imperial7x9,
136 Imperial8x10,
137 Imperial9x11,
138 Imperial9x12,
139 Imperial10x11,
140 Imperial10x13,
141 Imperial10x14,
142 Imperial12x11,
143 Imperial15x11,
144
145 ExecutiveStandard,
146 Note,
147 Quarto,
148 Statement,
149 SuperA,
150 SuperB,
151 Postcard,
152 DoublePostcard,
153 Prc16K,
154 Prc32K,
155 Prc32KBig,
156
157 FanFoldUS,
158 FanFoldGerman,
159 FanFoldGermanLegal,
160
161 EnvelopeB4,
162 EnvelopeB5,
163 EnvelopeB6,
164 EnvelopeC0,
165 EnvelopeC1,
166 EnvelopeC2,
167 EnvelopeC3,
168 EnvelopeC4,
169 // EnvelopeC5 = C5E,
170 EnvelopeC6,
171 EnvelopeC65,
172 EnvelopeC7,
173 // EnvelopeDL = DLE,
174
175 Envelope9,
176 // Envelope10 = Comm10E,
177 Envelope11,
178 Envelope12,
179 Envelope14,
180 EnvelopeMonarch,
181 EnvelopePersonal,
182
183 EnvelopeChou3,
184 EnvelopeChou4,
185 EnvelopeInvite,
186 EnvelopeItalian,
187 EnvelopeKaku2,
188 EnvelopeKaku3,
189 EnvelopePrc1,
190 EnvelopePrc2,
191 EnvelopePrc3,
192 EnvelopePrc4,
193 EnvelopePrc5,
194 EnvelopePrc6,
195 EnvelopePrc7,
196 EnvelopePrc8,
197 EnvelopePrc9,
198 EnvelopePrc10,
199 EnvelopeYou4,
200
201 // Last item, with commonly used synynoms from QPagedPrintEngine / QPrinter
202 LastPageSize = EnvelopeYou4,
203 NPageSize = LastPageSize,
204 NPaperSize = LastPageSize,
205
206 // Convenience overloads for naming consistency
207 AnsiA = Letter,
208 AnsiB = Ledger,
209 EnvelopeC5 = C5E,
210 EnvelopeDL = DLE,
211 Envelope10 = Comm10E
212 };
213
214 // NOTE: Must keep in sync with QPageLayout::Unit and QPrinter::Unit
215 enum Unit {
216 Millimeter,
217 Point,
218 Inch,
219 Pica,
220 Didot,
221 Cicero
222 };
223
224 enum SizeMatchPolicy {
225 FuzzyMatch,
226 FuzzyOrientationMatch,
227 ExactMatch
228 };
229
230 QPageSize();
231 /*implicit*/ QPageSize(PageSizeId pageSizeId);
232 explicit QPageSize(const QSize &pointSize,
233 const QString &name = QString(),
234 SizeMatchPolicy matchPolicy = FuzzyMatch);
235 explicit QPageSize(const QSizeF &size, Unit units,
236 const QString &name = QString(),
237 SizeMatchPolicy matchPolicy = FuzzyMatch);
238 QPageSize(const QPageSize &other);
239 QPageSize &operator=(QPageSize &&other) noexcept { swap(other); return *this; }
240 QPageSize &operator=(const QPageSize &other);
241 ~QPageSize();
242
243
244 void swap(QPageSize &other) noexcept { qSwap(value1&: d, value2&: other.d); }
245
246 friend Q_GUI_EXPORT bool operator==(const QPageSize &lhs, const QPageSize &rhs);
247 bool isEquivalentTo(const QPageSize &other) const;
248
249 bool isValid() const;
250
251 QString key() const;
252 QString name() const;
253
254 PageSizeId id() const;
255
256 int windowsId() const;
257
258 QSizeF definitionSize() const;
259 Unit definitionUnits() const;
260
261 QSizeF size(Unit units) const;
262 QSize sizePoints() const;
263 QSize sizePixels(int resolution) const;
264
265 QRectF rect(Unit units) const;
266 QRect rectPoints() const;
267 QRect rectPixels(int resolution) const;
268
269 static QString key(PageSizeId pageSizeId);
270 static QString name(PageSizeId pageSizeId);
271
272 static PageSizeId id(const QSize &pointSize,
273 SizeMatchPolicy matchPolicy = FuzzyMatch);
274 static PageSizeId id(const QSizeF &size, Unit units,
275 SizeMatchPolicy matchPolicy = FuzzyMatch);
276
277 static PageSizeId id(int windowsId);
278 static int windowsId(PageSizeId pageSizeId);
279
280 static QSizeF definitionSize(PageSizeId pageSizeId);
281 static Unit definitionUnits(PageSizeId pageSizeId);
282
283 static QSizeF size(PageSizeId pageSizeId, Unit units);
284 static QSize sizePoints(PageSizeId pageSizeId);
285 static QSize sizePixels(PageSizeId pageSizeId, int resolution);
286
287private:
288 friend class QPageSizePrivate;
289 friend class QPlatformPrintDevice;
290 QPageSize(const QString &key, const QSize &pointSize, const QString &name);
291 QPageSize(int windowsId, const QSize &pointSize, const QString &name);
292 QPageSize(QPageSizePrivate &dd);
293 QSharedDataPointer<QPageSizePrivate> d;
294};
295
296Q_DECLARE_SHARED(QPageSize)
297
298Q_GUI_EXPORT bool operator==(const QPageSize &lhs, const QPageSize &rhs);
299inline bool operator!=(const QPageSize &lhs, const QPageSize &rhs)
300{ return !operator==(lhs, rhs); }
301
302#ifndef QT_NO_DEBUG_STREAM
303Q_GUI_EXPORT QDebug operator<<(QDebug dbg, const QPageSize &pageSize);
304#endif
305
306QT_END_NAMESPACE
307
308Q_DECLARE_METATYPE(QPageSize)
309Q_DECLARE_METATYPE(QPageSize::PageSizeId)
310Q_DECLARE_METATYPE(QPageSize::Unit)
311
312#endif // QPAGESIZE_H
313

source code of qtbase/src/gui/painting/qpagesize.h