qpagesize.h 8.0 KB

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