1// Copyright (C) 2014 John Layt <jlayt@kde.org>
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4#ifndef QPAGESIZE_H
5#define QPAGESIZE_H
6
7#include <QtGui/qtguiglobal.h>
8#include <QtCore/qsharedpointer.h>
9
10QT_BEGIN_NAMESPACE
11
12#if defined(B0)
13#undef B0 // Terminal hang-up. We assume that you do not want that.
14#endif
15
16class QPageSizePrivate;
17class QString;
18class QSize;
19class QSizeF;
20
21class Q_GUI_EXPORT QPageSize
22{
23public:
24
25 enum PageSizeId {
26 // Old Qt sizes
27 Letter,
28 Legal,
29 Executive,
30 A0,
31 A1,
32 A2,
33 A3,
34 A4,
35 A5,
36 A6,
37 A7,
38 A8,
39 A9,
40 A10,
41 B0,
42 B1,
43 B2,
44 B3,
45 B4,
46 B5,
47 B6,
48 B7,
49 B8,
50 B9,
51 B10,
52 C5E,
53 Comm10E,
54 DLE,
55 Folio,
56 Ledger,
57 Tabloid,
58 Custom,
59
60 // New values derived from PPD standard
61 A3Extra,
62 A4Extra,
63 A4Plus,
64 A4Small,
65 A5Extra,
66 B5Extra,
67
68 JisB0,
69 JisB1,
70 JisB2,
71 JisB3,
72 JisB4,
73 JisB5,
74 JisB6,
75 JisB7,
76 JisB8,
77 JisB9,
78 JisB10,
79
80 // AnsiA = Letter,
81 // AnsiB = Ledger,
82 AnsiC,
83 AnsiD,
84 AnsiE,
85 LegalExtra,
86 LetterExtra,
87 LetterPlus,
88 LetterSmall,
89 TabloidExtra,
90
91 ArchA,
92 ArchB,
93 ArchC,
94 ArchD,
95 ArchE,
96
97 Imperial7x9,
98 Imperial8x10,
99 Imperial9x11,
100 Imperial9x12,
101 Imperial10x11,
102 Imperial10x13,
103 Imperial10x14,
104 Imperial12x11,
105 Imperial15x11,
106
107 ExecutiveStandard,
108 Note,
109 Quarto,
110 Statement,
111 SuperA,
112 SuperB,
113 Postcard,
114 DoublePostcard,
115 Prc16K,
116 Prc32K,
117 Prc32KBig,
118
119 FanFoldUS,
120 FanFoldGerman,
121 FanFoldGermanLegal,
122
123 EnvelopeB4,
124 EnvelopeB5,
125 EnvelopeB6,
126 EnvelopeC0,
127 EnvelopeC1,
128 EnvelopeC2,
129 EnvelopeC3,
130 EnvelopeC4,
131 // EnvelopeC5 = C5E,
132 EnvelopeC6,
133 EnvelopeC65,
134 EnvelopeC7,
135 // EnvelopeDL = DLE,
136
137 Envelope9,
138 // Envelope10 = Comm10E,
139 Envelope11,
140 Envelope12,
141 Envelope14,
142 EnvelopeMonarch,
143 EnvelopePersonal,
144
145 EnvelopeChou3,
146 EnvelopeChou4,
147 EnvelopeInvite,
148 EnvelopeItalian,
149 EnvelopeKaku2,
150 EnvelopeKaku3,
151 EnvelopePrc1,
152 EnvelopePrc2,
153 EnvelopePrc3,
154 EnvelopePrc4,
155 EnvelopePrc5,
156 EnvelopePrc6,
157 EnvelopePrc7,
158 EnvelopePrc8,
159 EnvelopePrc9,
160 EnvelopePrc10,
161 EnvelopeYou4,
162
163 // Last item
164 LastPageSize = EnvelopeYou4,
165
166 // Convenience overloads for naming consistency
167 AnsiA = Letter,
168 AnsiB = Ledger,
169 EnvelopeC5 = C5E,
170 EnvelopeDL = DLE,
171 Envelope10 = Comm10E
172 };
173
174 // NOTE: Must keep in sync with QPageLayout::Unit and QPrinter::Unit
175 enum Unit {
176 Millimeter,
177 Point,
178 Inch,
179 Pica,
180 Didot,
181 Cicero
182 };
183
184 enum SizeMatchPolicy {
185 FuzzyMatch,
186 FuzzyOrientationMatch,
187 ExactMatch
188 };
189
190 QPageSize();
191 Q_IMPLICIT QPageSize(PageSizeId pageSizeId);
192 explicit QPageSize(const QSize &pointSize,
193 const QString &name = QString(),
194 SizeMatchPolicy matchPolicy = FuzzyMatch);
195 explicit QPageSize(const QSizeF &size, Unit units,
196 const QString &name = QString(),
197 SizeMatchPolicy matchPolicy = FuzzyMatch);
198 QPageSize(const QPageSize &other);
199 QT_MOVE_ASSIGNMENT_OPERATOR_IMPL_VIA_PURE_SWAP(QPageSize)
200 QPageSize &operator=(const QPageSize &other);
201 ~QPageSize();
202
203
204 void swap(QPageSize &other) noexcept { d.swap(other&: other.d); }
205
206 friend Q_GUI_EXPORT bool operator==(const QPageSize &lhs, const QPageSize &rhs);
207 bool isEquivalentTo(const QPageSize &other) const;
208
209 bool isValid() const;
210
211 QString key() const;
212 QString name() const;
213
214 PageSizeId id() const;
215
216 int windowsId() const;
217
218 QSizeF definitionSize() const;
219 Unit definitionUnits() const;
220
221 QSizeF size(Unit units) const;
222 QSize sizePoints() const;
223 QSize sizePixels(int resolution) const;
224
225 QRectF rect(Unit units) const;
226 QRect rectPoints() const;
227 QRect rectPixels(int resolution) const;
228
229 static QString key(PageSizeId pageSizeId);
230 static QString name(PageSizeId pageSizeId);
231
232 static PageSizeId id(const QSize &pointSize,
233 SizeMatchPolicy matchPolicy = FuzzyMatch);
234 static PageSizeId id(const QSizeF &size, Unit units,
235 SizeMatchPolicy matchPolicy = FuzzyMatch);
236
237 static PageSizeId id(int windowsId);
238 static int windowsId(PageSizeId pageSizeId);
239
240 static QSizeF definitionSize(PageSizeId pageSizeId);
241 static Unit definitionUnits(PageSizeId pageSizeId);
242
243 static QSizeF size(PageSizeId pageSizeId, Unit units);
244 static QSize sizePoints(PageSizeId pageSizeId);
245 static QSize sizePixels(PageSizeId pageSizeId, int resolution);
246
247private:
248 friend class QPageSizePrivate;
249 friend class QPlatformPrintDevice;
250
251 bool equals(const QPageSize &other) const;
252 friend inline bool operator==(const QPageSize &lhs, const QPageSize &rhs)
253 { return lhs.equals(other: rhs); }
254 friend inline bool operator!=(const QPageSize &lhs, const QPageSize &rhs)
255 { return !(lhs == rhs); }
256
257 QPageSize(const QString &key, const QSize &pointSize, const QString &name);
258 QPageSize(int windowsId, const QSize &pointSize, const QString &name);
259 QPageSize(QPageSizePrivate &dd);
260 QSharedDataPointer<QPageSizePrivate> d;
261};
262
263Q_DECLARE_SHARED(QPageSize)
264
265#ifndef QT_NO_DEBUG_STREAM
266Q_GUI_EXPORT QDebug operator<<(QDebug dbg, const QPageSize &pageSize);
267#endif
268
269QT_END_NAMESPACE
270
271QT_DECL_METATYPE_EXTERN(QPageSize, Q_GUI_EXPORT)
272QT_DECL_METATYPE_EXTERN_TAGGED(QPageSize::PageSizeId, QPageSize__PageSizeId, Q_GUI_EXPORT)
273QT_DECL_METATYPE_EXTERN_TAGGED(QPageSize::Unit, QPageSize__Unit, Q_GUI_EXPORT)
274
275#endif // QPAGESIZE_H
276

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