qprinter.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431
  1. /****************************************************************************
  2. **
  3. ** Copyright (C) 2016 The Qt Company Ltd.
  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 QPRINTER_H
  40. #define QPRINTER_H
  41. #include <QtCore/qstring.h>
  42. #include <QtCore/qscopedpointer.h>
  43. #include <QtGui/qpagedpaintdevice.h>
  44. #include <QtGui/qpagelayout.h>
  45. #include <QtPrintSupport/qtprintsupportglobal.h>
  46. QT_BEGIN_NAMESPACE
  47. #ifndef QT_NO_PRINTER
  48. #if defined(B0)
  49. #undef B0 // Terminal hang-up. We assume that you do not want that.
  50. #endif
  51. class QPrinterPrivate;
  52. class QPaintEngine;
  53. class QPrintEngine;
  54. class QPrinterInfo;
  55. class QPageSize;
  56. class QPageMargins;
  57. class Q_PRINTSUPPORT_EXPORT QPrinter : public QPagedPaintDevice
  58. {
  59. Q_DECLARE_PRIVATE(QPrinter)
  60. public:
  61. enum PrinterMode { ScreenResolution, PrinterResolution, HighResolution };
  62. explicit QPrinter(PrinterMode mode = ScreenResolution);
  63. explicit QPrinter(const QPrinterInfo& printer, PrinterMode mode = ScreenResolution);
  64. ~QPrinter();
  65. int devType() const Q_DECL_OVERRIDE;
  66. enum Orientation { Portrait, Landscape };
  67. // ### Qt6 Remove in favor of QPage::PageSize
  68. // NOTE: Must keep in sync with QPageSize and QPagedPaintDevice
  69. #ifndef Q_QDOC
  70. typedef PageSize PaperSize;
  71. #else
  72. enum PaperSize {
  73. // Existing Qt sizes
  74. A4,
  75. B5,
  76. Letter,
  77. Legal,
  78. Executive,
  79. A0,
  80. A1,
  81. A2,
  82. A3,
  83. A5,
  84. A6,
  85. A7,
  86. A8,
  87. A9,
  88. B0,
  89. B1,
  90. B10,
  91. B2,
  92. B3,
  93. B4,
  94. B6,
  95. B7,
  96. B8,
  97. B9,
  98. C5E,
  99. Comm10E,
  100. DLE,
  101. Folio,
  102. Ledger,
  103. Tabloid,
  104. Custom,
  105. // New values derived from PPD standard
  106. A10,
  107. A3Extra,
  108. A4Extra,
  109. A4Plus,
  110. A4Small,
  111. A5Extra,
  112. B5Extra,
  113. JisB0,
  114. JisB1,
  115. JisB2,
  116. JisB3,
  117. JisB4,
  118. JisB5,
  119. JisB6,
  120. JisB7,
  121. JisB8,
  122. JisB9,
  123. JisB10,
  124. // AnsiA = Letter,
  125. // AnsiB = Ledger,
  126. AnsiC,
  127. AnsiD,
  128. AnsiE,
  129. LegalExtra,
  130. LetterExtra,
  131. LetterPlus,
  132. LetterSmall,
  133. TabloidExtra,
  134. ArchA,
  135. ArchB,
  136. ArchC,
  137. ArchD,
  138. ArchE,
  139. Imperial7x9,
  140. Imperial8x10,
  141. Imperial9x11,
  142. Imperial9x12,
  143. Imperial10x11,
  144. Imperial10x13,
  145. Imperial10x14,
  146. Imperial12x11,
  147. Imperial15x11,
  148. ExecutiveStandard,
  149. Note,
  150. Quarto,
  151. Statement,
  152. SuperA,
  153. SuperB,
  154. Postcard,
  155. DoublePostcard,
  156. Prc16K,
  157. Prc32K,
  158. Prc32KBig,
  159. FanFoldUS,
  160. FanFoldGerman,
  161. FanFoldGermanLegal,
  162. EnvelopeB4,
  163. EnvelopeB5,
  164. EnvelopeB6,
  165. EnvelopeC0,
  166. EnvelopeC1,
  167. EnvelopeC2,
  168. EnvelopeC3,
  169. EnvelopeC4,
  170. // EnvelopeC5 = C5E,
  171. EnvelopeC6,
  172. EnvelopeC65,
  173. EnvelopeC7,
  174. // EnvelopeDL = DLE,
  175. Envelope9,
  176. // Envelope10 = Comm10E,
  177. Envelope11,
  178. Envelope12,
  179. Envelope14,
  180. EnvelopeMonarch,
  181. EnvelopePersonal,
  182. EnvelopeChou3,
  183. EnvelopeChou4,
  184. EnvelopeInvite,
  185. EnvelopeItalian,
  186. EnvelopeKaku2,
  187. EnvelopeKaku3,
  188. EnvelopePrc1,
  189. EnvelopePrc2,
  190. EnvelopePrc3,
  191. EnvelopePrc4,
  192. EnvelopePrc5,
  193. EnvelopePrc6,
  194. EnvelopePrc7,
  195. EnvelopePrc8,
  196. EnvelopePrc9,
  197. EnvelopePrc10,
  198. EnvelopeYou4,
  199. // Last item, with commonly used synynoms from QPagedPrintEngine / QPrinter
  200. LastPageSize = EnvelopeYou4,
  201. NPageSize = LastPageSize,
  202. NPaperSize = LastPageSize,
  203. // Convenience overloads for naming consistency
  204. AnsiA = Letter,
  205. AnsiB = Ledger,
  206. EnvelopeC5 = C5E,
  207. EnvelopeDL = DLE,
  208. Envelope10 = Comm10E
  209. };
  210. #endif
  211. enum PageOrder { FirstPageFirst,
  212. LastPageFirst };
  213. enum ColorMode { GrayScale,
  214. Color };
  215. enum PaperSource { OnlyOne,
  216. Lower,
  217. Middle,
  218. Manual,
  219. Envelope,
  220. EnvelopeManual,
  221. Auto,
  222. Tractor,
  223. SmallFormat,
  224. LargeFormat,
  225. LargeCapacity,
  226. Cassette,
  227. FormSource,
  228. MaxPageSource, // Deprecated
  229. CustomSource,
  230. LastPaperSource = CustomSource,
  231. Upper = OnlyOne // As defined in Windows
  232. };
  233. enum PrinterState { Idle,
  234. Active,
  235. Aborted,
  236. Error };
  237. enum OutputFormat { NativeFormat, PdfFormat };
  238. // Keep in sync with QAbstractPrintDialog::PrintRange
  239. enum PrintRange { AllPages, Selection, PageRange, CurrentPage };
  240. enum Unit {
  241. Millimeter,
  242. Point,
  243. Inch,
  244. Pica,
  245. Didot,
  246. Cicero,
  247. DevicePixel
  248. };
  249. enum DuplexMode {
  250. DuplexNone = 0,
  251. DuplexAuto,
  252. DuplexLongSide,
  253. DuplexShortSide
  254. };
  255. void setOutputFormat(OutputFormat format);
  256. OutputFormat outputFormat() const;
  257. void setPrinterName(const QString &);
  258. QString printerName() const;
  259. bool isValid() const;
  260. void setOutputFileName(const QString &);
  261. QString outputFileName()const;
  262. void setPrintProgram(const QString &);
  263. QString printProgram() const;
  264. void setDocName(const QString &);
  265. QString docName() const;
  266. void setCreator(const QString &);
  267. QString creator() const;
  268. #ifdef Q_QDOC
  269. bool setPageLayout(const QPageLayout &pageLayout);
  270. bool setPageSize(const QPageSize &pageSize);
  271. bool setPageOrientation(QPageLayout::Orientation orientation);
  272. bool setPageMargins(const QMarginsF &margins);
  273. bool setPageMargins(const QMarginsF &margins, QPageLayout::Unit units);
  274. QPageLayout pageLayout() const;
  275. #else
  276. using QPagedPaintDevice::setPageSize;
  277. using QPagedPaintDevice::setPageMargins;
  278. #endif
  279. void setOrientation(Orientation);
  280. Orientation orientation() const;
  281. void setPageSize(PageSize) Q_DECL_OVERRIDE;
  282. PageSize pageSize() const;
  283. void setPageSizeMM(const QSizeF &size) Q_DECL_OVERRIDE;
  284. void setPaperSize(PaperSize);
  285. PaperSize paperSize() const;
  286. void setPaperSize(const QSizeF &paperSize, Unit unit);
  287. QSizeF paperSize(Unit unit) const;
  288. void setPaperName(const QString &paperName);
  289. QString paperName() const;
  290. void setPageOrder(PageOrder);
  291. PageOrder pageOrder() const;
  292. void setResolution(int);
  293. int resolution() const;
  294. void setColorMode(ColorMode);
  295. ColorMode colorMode() const;
  296. void setCollateCopies(bool collate);
  297. bool collateCopies() const;
  298. void setFullPage(bool);
  299. bool fullPage() const;
  300. void setNumCopies(int);
  301. int numCopies() const;
  302. int actualNumCopies() const;
  303. void setCopyCount(int);
  304. int copyCount() const;
  305. bool supportsMultipleCopies() const;
  306. void setPaperSource(PaperSource);
  307. PaperSource paperSource() const;
  308. void setDuplex(DuplexMode duplex);
  309. DuplexMode duplex() const;
  310. QList<int> supportedResolutions() const;
  311. #ifdef Q_OS_WIN
  312. QList<PaperSource> supportedPaperSources() const;
  313. #endif
  314. void setFontEmbeddingEnabled(bool enable);
  315. bool fontEmbeddingEnabled() const;
  316. void setDoubleSidedPrinting(bool enable);
  317. bool doubleSidedPrinting() const;
  318. void setWinPageSize(int winPageSize);
  319. int winPageSize() const;
  320. QRect paperRect() const;
  321. QRect pageRect() const;
  322. QRectF paperRect(Unit) const;
  323. QRectF pageRect(Unit) const;
  324. QString printerSelectionOption() const;
  325. void setPrinterSelectionOption(const QString &);
  326. bool newPage() Q_DECL_OVERRIDE;
  327. bool abort();
  328. PrinterState printerState() const;
  329. QPaintEngine *paintEngine() const Q_DECL_OVERRIDE;
  330. QPrintEngine *printEngine() const;
  331. void setFromTo(int fromPage, int toPage);
  332. int fromPage() const;
  333. int toPage() const;
  334. void setPrintRange(PrintRange range);
  335. PrintRange printRange() const;
  336. void setMargins(const Margins &m) Q_DECL_OVERRIDE;
  337. void setPageMargins(qreal left, qreal top, qreal right, qreal bottom, Unit unit);
  338. void getPageMargins(qreal *left, qreal *top, qreal *right, qreal *bottom, Unit unit) const;
  339. protected:
  340. int metric(PaintDeviceMetric) const Q_DECL_OVERRIDE;
  341. void setEngines(QPrintEngine *printEngine, QPaintEngine *paintEngine);
  342. private:
  343. Q_DISABLE_COPY(QPrinter)
  344. QScopedPointer<QPrinterPrivate> d_ptr;
  345. friend class QPrintDialogPrivate;
  346. friend class QAbstractPrintDialog;
  347. friend class QAbstractPrintDialogPrivate;
  348. friend class QPrintPreviewWidgetPrivate;
  349. friend class QTextDocument;
  350. friend class QPageSetupWidget;
  351. };
  352. #endif // QT_NO_PRINTER
  353. QT_END_NAMESPACE
  354. #endif // QPRINTER_H