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 
40 #ifndef QPAGELAYOUT_H
41 #define QPAGELAYOUT_H
42 
43 #include <QtGui/qtguiglobal.h>
44 #include <QtCore/qsharedpointer.h>
45 #include <QtCore/qstring.h>
46 #include <QtCore/qmargins.h>
47 
48 #include <QtGui/qpagesize.h>
49 
50 QT_BEGIN_NAMESPACE
51 
52 class QPageLayoutPrivate;
53 class QMarginsF;
54 
55 class Q_GUI_EXPORT QPageLayout
56 {
57 public:
58 
59     // NOTE: Must keep in sync with QPageSize::Unit and QPrinter::Unit
60     enum Unit {
61         Millimeter,
62         Point,
63         Inch,
64         Pica,
65         Didot,
66         Cicero
67     };
68 
69     // NOTE: Must keep in sync with QPrinter::Orientation
70     enum Orientation {
71         Portrait,
72         Landscape
73     };
74 
75     enum Mode {
76         StandardMode,  // Paint Rect includes margins
77         FullPageMode   // Paint Rect excludes margins
78     };
79 
80     QPageLayout();
81     QPageLayout(const QPageSize &pageSize, Orientation orientation,
82                 const QMarginsF &margins, Unit units = Point,
83                 const QMarginsF &minMargins = QMarginsF(0, 0, 0, 0));
84     QPageLayout(const QPageLayout &other);
85     QPageLayout &operator=(QPageLayout &&other) noexcept { swap(other); return *this; }
86     QPageLayout &operator=(const QPageLayout &other);
87     ~QPageLayout();
88 
swap(QPageLayout & other)89     void swap(QPageLayout &other) noexcept { qSwap(d, other.d); }
90 
91     friend Q_GUI_EXPORT bool operator==(const QPageLayout &lhs, const QPageLayout &rhs);
92     bool isEquivalentTo(const QPageLayout &other) const;
93 
94     bool isValid() const;
95 
96     void setMode(Mode mode);
97     Mode mode() const;
98 
99     void setPageSize(const QPageSize &pageSize,
100                      const QMarginsF &minMargins = QMarginsF(0, 0, 0, 0));
101     QPageSize pageSize() const;
102 
103     void setOrientation(Orientation orientation);
104     Orientation orientation() const;
105 
106     void setUnits(Unit units);
107     Unit units() const;
108 
109     bool setMargins(const QMarginsF &margins);
110     bool setLeftMargin(qreal leftMargin);
111     bool setRightMargin(qreal rightMargin);
112     bool setTopMargin(qreal topMargin);
113     bool setBottomMargin(qreal bottomMargin);
114 
115     QMarginsF margins() const;
116     QMarginsF margins(Unit units) const;
117     QMargins marginsPoints() const;
118     QMargins marginsPixels(int resolution) const;
119 
120     void setMinimumMargins(const QMarginsF &minMargins);
121     QMarginsF minimumMargins() const;
122     QMarginsF maximumMargins() const;
123 
124     QRectF fullRect() const;
125     QRectF fullRect(Unit units) const;
126     QRect fullRectPoints() const;
127     QRect fullRectPixels(int resolution) const;
128 
129     QRectF paintRect() const;
130     QRectF paintRect(Unit units) const;
131     QRect paintRectPoints() const;
132     QRect paintRectPixels(int resolution) const;
133 
134 private:
135     friend class QPageLayoutPrivate;
136     QExplicitlySharedDataPointer<QPageLayoutPrivate> d;
137 };
138 
139 Q_DECLARE_SHARED(QPageLayout)
140 
141 Q_GUI_EXPORT bool operator==(const QPageLayout &lhs, const QPageLayout &rhs);
142 inline bool operator!=(const QPageLayout &lhs, const QPageLayout &rhs)
143 { return !operator==(lhs, rhs); }
144 
145 #ifndef QT_NO_DEBUG_STREAM
146 Q_GUI_EXPORT QDebug operator<<(QDebug dbg, const QPageLayout &pageLayout);
147 #endif
148 
149 QT_END_NAMESPACE
150 
151 Q_DECLARE_METATYPE(QPageLayout)
152 Q_DECLARE_METATYPE(QPageLayout::Unit)
153 Q_DECLARE_METATYPE(QPageLayout::Orientation)
154 
155 #endif // QPAGELAYOUT_H
156