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
14QT_BEGIN_NAMESPACE
15
16class QPageLayoutPrivate;
17class QMarginsF;
18
19class Q_GUI_EXPORT QPageLayout
20{
21public:
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 QPageLayout();
44 QPageLayout(const QPageSize &pageSize, Orientation orientation,
45 const QMarginsF &margins, Unit units = Point,
46 const QMarginsF &minMargins = QMarginsF(0, 0, 0, 0));
47 QPageLayout(const QPageLayout &other);
48 QT_MOVE_ASSIGNMENT_OPERATOR_IMPL_VIA_PURE_SWAP(QPageLayout)
49 QPageLayout &operator=(const QPageLayout &other);
50 ~QPageLayout();
51
52 void swap(QPageLayout &other) noexcept { d.swap(other&: other.d); }
53
54 bool isEquivalentTo(const QPageLayout &other) const;
55
56 bool isValid() const;
57
58 void setMode(Mode mode);
59 Mode mode() const;
60
61 void setPageSize(const QPageSize &pageSize,
62 const QMarginsF &minMargins = QMarginsF(0, 0, 0, 0));
63 QPageSize pageSize() const;
64
65 void setOrientation(Orientation orientation);
66 Orientation orientation() const;
67
68 void setUnits(Unit units);
69 Unit units() const;
70
71 bool setMargins(const QMarginsF &margins);
72 bool setLeftMargin(qreal leftMargin);
73 bool setRightMargin(qreal rightMargin);
74 bool setTopMargin(qreal topMargin);
75 bool setBottomMargin(qreal bottomMargin);
76
77 QMarginsF margins() const;
78 QMarginsF margins(Unit units) const;
79 QMargins marginsPoints() const;
80 QMargins marginsPixels(int resolution) const;
81
82 void setMinimumMargins(const QMarginsF &minMargins);
83 QMarginsF minimumMargins() const;
84 QMarginsF maximumMargins() const;
85
86 QRectF fullRect() const;
87 QRectF fullRect(Unit units) const;
88 QRect fullRectPoints() const;
89 QRect fullRectPixels(int resolution) const;
90
91 QRectF paintRect() const;
92 QRectF paintRect(Unit units) const;
93 QRect paintRectPoints() const;
94 QRect paintRectPixels(int resolution) const;
95
96private:
97 friend class QPageLayoutPrivate;
98 bool equals(const QPageLayout &other) const;
99
100 friend inline bool operator==(const QPageLayout &lhs, const QPageLayout &rhs)
101 { return lhs.equals(other: rhs); }
102 friend inline bool operator!=(const QPageLayout &lhs, const QPageLayout &rhs)
103 { return !lhs.equals(other: rhs); }
104
105 QExplicitlySharedDataPointer<QPageLayoutPrivate> d;
106};
107
108Q_DECLARE_SHARED(QPageLayout)
109
110#ifndef QT_NO_DEBUG_STREAM
111Q_GUI_EXPORT QDebug operator<<(QDebug dbg, const QPageLayout &pageLayout);
112#endif
113
114QT_END_NAMESPACE
115
116QT_DECL_METATYPE_EXTERN(QPageLayout, Q_GUI_EXPORT)
117QT_DECL_METATYPE_EXTERN_TAGGED(QPageLayout::Unit, QPageLayout__Unit, Q_GUI_EXPORT)
118QT_DECL_METATYPE_EXTERN_TAGGED(QPageLayout::Orientation, QPageLayout__Orientation, Q_GUI_EXPORT)
119
120#endif // QPAGELAYOUT_H
121

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