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 QPAGELAYOUT_H |
5 | #define QPAGELAYOUT_H |
6 | |
7 | #include <QtGui/qtguiglobal.h> |
8 | #include <QtCore/qshareddata.h> |
9 | #include <QtCore/qstring.h> |
10 | #include <QtCore/qmargins.h> |
11 | |
12 | #include <QtGui/qpagesize.h> |
13 | |
14 | QT_BEGIN_NAMESPACE |
15 | |
16 | class QPageLayoutPrivate; |
17 | class QMarginsF; |
18 | |
19 | class Q_GUI_EXPORT QPageLayout |
20 | { |
21 | public: |
22 | |
23 | // NOTE: Must keep in sync with QPageSize::Unit and QPrinter::Unit |
24 | enum Unit { |
25 | Millimeter, |
26 | Point, |
27 | Inch, |
28 | Pica, |
29 | Didot, |
30 | Cicero |
31 | }; |
32 | |
33 | enum Orientation { |
34 | Portrait, |
35 | Landscape |
36 | }; |
37 | |
38 | enum Mode { |
39 | StandardMode, // Paint Rect includes margins |
40 | FullPageMode // Paint Rect excludes margins |
41 | }; |
42 | |
43 | enum class OutOfBoundsPolicy { |
44 | Reject, |
45 | Clamp, |
46 | }; |
47 | |
48 | QPageLayout(); |
49 | QPageLayout(const QPageSize &pageSize, Orientation orientation, |
50 | const QMarginsF &margins, Unit units = Point, |
51 | const QMarginsF &minMargins = QMarginsF(0, 0, 0, 0)); |
52 | QPageLayout(const QPageLayout &other); |
53 | QT_MOVE_ASSIGNMENT_OPERATOR_IMPL_VIA_PURE_SWAP(QPageLayout) |
54 | QPageLayout &operator=(const QPageLayout &other); |
55 | ~QPageLayout(); |
56 | |
57 | void swap(QPageLayout &other) noexcept { d.swap(other&: other.d); } |
58 | |
59 | bool isEquivalentTo(const QPageLayout &other) const; |
60 | |
61 | bool isValid() const; |
62 | |
63 | void setMode(Mode mode); |
64 | Mode mode() const; |
65 | |
66 | void setPageSize(const QPageSize &pageSize, |
67 | const QMarginsF &minMargins = QMarginsF(0, 0, 0, 0)); |
68 | QPageSize pageSize() const; |
69 | |
70 | void setOrientation(Orientation orientation); |
71 | Orientation orientation() const; |
72 | |
73 | void setUnits(Unit units); |
74 | Unit units() const; |
75 | |
76 | #if QT_GUI_REMOVED_SINCE(6, 8) |
77 | bool setMargins(const QMarginsF &margins); |
78 | bool setLeftMargin(qreal leftMargin); |
79 | bool setRightMargin(qreal rightMargin); |
80 | bool setTopMargin(qreal topMargin); |
81 | bool setBottomMargin(qreal bottomMargin); |
82 | #endif |
83 | |
84 | bool setMargins(const QMarginsF &margins, OutOfBoundsPolicy outOfBoundsPolicy = OutOfBoundsPolicy::Reject); |
85 | bool setLeftMargin(qreal leftMargin, OutOfBoundsPolicy outOfBoundsPolicy = OutOfBoundsPolicy::Reject); |
86 | bool setRightMargin(qreal rightMargin, OutOfBoundsPolicy outOfBoundsPolicy = OutOfBoundsPolicy::Reject); |
87 | bool setTopMargin(qreal topMargin, OutOfBoundsPolicy outOfBoundsPolicy = OutOfBoundsPolicy::Reject); |
88 | bool setBottomMargin(qreal bottomMargin, OutOfBoundsPolicy outOfBoundsPolicy = OutOfBoundsPolicy::Reject); |
89 | |
90 | QMarginsF margins() const; |
91 | QMarginsF margins(Unit units) const; |
92 | QMargins marginsPoints() const; |
93 | QMargins marginsPixels(int resolution) const; |
94 | |
95 | void setMinimumMargins(const QMarginsF &minMargins); |
96 | QMarginsF minimumMargins() const; |
97 | QMarginsF maximumMargins() const; |
98 | |
99 | QRectF fullRect() const; |
100 | QRectF fullRect(Unit units) const; |
101 | QRect fullRectPoints() const; |
102 | QRect fullRectPixels(int resolution) const; |
103 | |
104 | QRectF paintRect() const; |
105 | QRectF paintRect(Unit units) const; |
106 | QRect paintRectPoints() const; |
107 | QRect paintRectPixels(int resolution) const; |
108 | |
109 | private: |
110 | friend class QPageLayoutPrivate; |
111 | bool equals(const QPageLayout &other) const; |
112 | |
113 | friend inline bool operator==(const QPageLayout &lhs, const QPageLayout &rhs) |
114 | { return lhs.equals(other: rhs); } |
115 | friend inline bool operator!=(const QPageLayout &lhs, const QPageLayout &rhs) |
116 | { return !lhs.equals(other: rhs); } |
117 | |
118 | QExplicitlySharedDataPointer<QPageLayoutPrivate> d; |
119 | }; |
120 | |
121 | Q_DECLARE_SHARED(QPageLayout) |
122 | |
123 | #ifndef QT_NO_DEBUG_STREAM |
124 | Q_GUI_EXPORT QDebug operator<<(QDebug dbg, const QPageLayout &pageLayout); |
125 | #endif |
126 | |
127 | QT_END_NAMESPACE |
128 | |
129 | QT_DECL_METATYPE_EXTERN(QPageLayout, Q_GUI_EXPORT) |
130 | QT_DECL_METATYPE_EXTERN_TAGGED(QPageLayout::Unit, QPageLayout__Unit, Q_GUI_EXPORT) |
131 | QT_DECL_METATYPE_EXTERN_TAGGED(QPageLayout::Orientation, QPageLayout__Orientation, Q_GUI_EXPORT) |
132 | |
133 | #endif // QPAGELAYOUT_H |
134 | |