qpagelayout.cpp

Absolute File Name:/home/qt/qt5_coco/qt5/qtbase/src/gui/painting/qpagelayout.cpp
Source codeSwitch to Preprocessed file
LineSourceCount
1/****************************************************************************-
2**-
3** Copyright (C) 2014 John Layt <jlayt@kde.org>-
4** Contact: http://www.qt.io/licensing/-
5**-
6** This file is part of the QtGui module of the Qt Toolkit.-
7**-
8** $QT_BEGIN_LICENSE:LGPL21$-
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 http://www.qt.io/terms-conditions. For further-
15** information use the contact form at http://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 2.1 or version 3 as published by the Free-
20** Software Foundation and appearing in the file LICENSE.LGPLv21 and-
21** LICENSE.LGPLv3 included in the packaging of this file. Please review the-
22** following information to ensure the GNU Lesser General Public License-
23** requirements will be met: https://www.gnu.org/licenses/lgpl.html and-
24** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.-
25**-
26** As a special exception, The Qt Company gives you certain additional-
27** rights. These rights are described in The Qt Company LGPL Exception-
28** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.-
29**-
30** $QT_END_LICENSE$-
31**-
32****************************************************************************/-
33-
34-
35#include "qpagelayout.h"-
36-
37#include <QtCore/qpoint.h>-
38#include <QtCore/qrect.h>-
39#include <QtCore/qsize.h>-
40-
41#include <qdebug.h>-
42-
43QT_BEGIN_NAMESPACE-
44-
45// Multiplier for converting units to points.-
46Q_GUI_EXPORT qreal qt_pointMultiplier(QPageLayout::Unit unit)-
47{-
48 switch (unit) {-
49 case QPageLayout::Millimeter:
never executed: case QPageLayout::Millimeter:
0
50 return 2.83464566929;
never executed: return 2.83464566929;
0
51 case QPageLayout::Point:
never executed: case QPageLayout::Point:
0
52 return 1.0;
never executed: return 1.0;
0
53 case QPageLayout::Inch:
never executed: case QPageLayout::Inch:
0
54 return 72.0;
never executed: return 72.0;
0
55 case QPageLayout::Pica:
never executed: case QPageLayout::Pica:
0
56 return 12;
never executed: return 12;
0
57 case QPageLayout::Didot:
never executed: case QPageLayout::Didot:
0
58 return 1.065826771;
never executed: return 1.065826771;
0
59 case QPageLayout::Cicero:
never executed: case QPageLayout::Cicero:
0
60 return 12.789921252;
never executed: return 12.789921252;
0
61 }-
62 return 1.0;
never executed: return 1.0;
0
63}-
64-
65// Multiplier for converting pixels to points.-
66extern qreal qt_pixelMultiplier(int resolution);-
67-
68QPointF qt_convertPoint(const QPointF &xy, QPageLayout::Unit fromUnits, QPageLayout::Unit toUnits)-
69{-
70 // If the size have the same units, or are all 0, then don't need to convert-
71 if (fromUnits == toUnits || xy.isNull())
fromUnits == toUnitsDescription
TRUEnever evaluated
FALSEnever evaluated
xy.isNull()Description
TRUEnever evaluated
FALSEnever evaluated
0
72 return xy;
never executed: return xy;
0
73-
74 // If converting to points then convert and round to 0 decimal places-
75 if (toUnits == QPageLayout::Point) {
toUnits == QPageLayout::PointDescription
TRUEnever evaluated
FALSEnever evaluated
0
76 const qreal multiplier = qt_pointMultiplier(fromUnits);-
77 return QPointF(qRound(xy.x() * multiplier),
never executed: return QPointF(qRound(xy.x() * multiplier), qRound(xy.y() * multiplier));
0
78 qRound(xy.y() * multiplier));
never executed: return QPointF(qRound(xy.x() * multiplier), qRound(xy.y() * multiplier));
0
79 }-
80-
81 // If converting to other units, need to convert to unrounded points first-
82 QPointF pointXy = (fromUnits == QPageLayout::Point) ? xy : xy * qt_pointMultiplier(fromUnits);
(fromUnits == ...Layout::Point)Description
TRUEnever evaluated
FALSEnever evaluated
0
83-
84 // Then convert from points to required units rounded to 2 decimal places-
85 const qreal multiplier = qt_pointMultiplier(toUnits);-
86 return QPointF(qRound(pointXy.x() * 100 / multiplier) / 100.0,
never executed: return QPointF(qRound(pointXy.x() * 100 / multiplier) / 100.0, qRound(pointXy.y() * 100 / multiplier) / 100.0);
0
87 qRound(pointXy.y() * 100 / multiplier) / 100.0);
never executed: return QPointF(qRound(pointXy.x() * 100 / multiplier) / 100.0, qRound(pointXy.y() * 100 / multiplier) / 100.0);
0
88}-
89-
90Q_GUI_EXPORT QMarginsF qt_convertMargins(const QMarginsF &margins, QPageLayout::Unit fromUnits, QPageLayout::Unit toUnits)-
91{-
92 // If the margins have the same units, or are all 0, then don't need to convert-
93 if (fromUnits == toUnits || margins.isNull())
fromUnits == toUnitsDescription
TRUEnever evaluated
FALSEnever evaluated
margins.isNull()Description
TRUEnever evaluated
FALSEnever evaluated
0
94 return margins;
never executed: return margins;
0
95-
96 // If converting to points then convert and round to 0 decimal places-
97 if (toUnits == QPageLayout::Point) {
toUnits == QPageLayout::PointDescription
TRUEnever evaluated
FALSEnever evaluated
0
98 const qreal multiplier = qt_pointMultiplier(fromUnits);-
99 return QMarginsF(qRound(margins.left() * multiplier),
never executed: return QMarginsF(qRound(margins.left() * multiplier), qRound(margins.top() * multiplier), qRound(margins.right() * multiplier), qRound(margins.bottom() * multiplier));
0
100 qRound(margins.top() * multiplier),
never executed: return QMarginsF(qRound(margins.left() * multiplier), qRound(margins.top() * multiplier), qRound(margins.right() * multiplier), qRound(margins.bottom() * multiplier));
0
101 qRound(margins.right() * multiplier),
never executed: return QMarginsF(qRound(margins.left() * multiplier), qRound(margins.top() * multiplier), qRound(margins.right() * multiplier), qRound(margins.bottom() * multiplier));
0
102 qRound(margins.bottom() * multiplier));
never executed: return QMarginsF(qRound(margins.left() * multiplier), qRound(margins.top() * multiplier), qRound(margins.right() * multiplier), qRound(margins.bottom() * multiplier));
0
103 }-
104-
105 // If converting to other units, need to convert to unrounded points first-
106 QMarginsF pointMargins = fromUnits == QPageLayout::Point ? margins : margins * qt_pointMultiplier(fromUnits);
fromUnits == Q...eLayout::PointDescription
TRUEnever evaluated
FALSEnever evaluated
0
107-
108 // Then convert from points to required units rounded to 2 decimal places-
109 const qreal multiplier = qt_pointMultiplier(toUnits);-
110 return QMarginsF(qRound(pointMargins.left() * 100 / multiplier) / 100.0,
never executed: return QMarginsF(qRound(pointMargins.left() * 100 / multiplier) / 100.0, qRound(pointMargins.top() * 100 / multiplier) / 100.0, qRound(pointMargins.right() * 100 / multiplier) / 100.0, qRound(pointMargins.bottom() * 100 / multiplier) / 100.0);
0
111 qRound(pointMargins.top() * 100 / multiplier) / 100.0,
never executed: return QMarginsF(qRound(pointMargins.left() * 100 / multiplier) / 100.0, qRound(pointMargins.top() * 100 / multiplier) / 100.0, qRound(pointMargins.right() * 100 / multiplier) / 100.0, qRound(pointMargins.bottom() * 100 / multiplier) / 100.0);
0
112 qRound(pointMargins.right() * 100 / multiplier) / 100.0,
never executed: return QMarginsF(qRound(pointMargins.left() * 100 / multiplier) / 100.0, qRound(pointMargins.top() * 100 / multiplier) / 100.0, qRound(pointMargins.right() * 100 / multiplier) / 100.0, qRound(pointMargins.bottom() * 100 / multiplier) / 100.0);
0
113 qRound(pointMargins.bottom() * 100 / multiplier) / 100.0);
never executed: return QMarginsF(qRound(pointMargins.left() * 100 / multiplier) / 100.0, qRound(pointMargins.top() * 100 / multiplier) / 100.0, qRound(pointMargins.right() * 100 / multiplier) / 100.0, qRound(pointMargins.bottom() * 100 / multiplier) / 100.0);
0
114}-
115-
116class QPageLayoutPrivate : public QSharedData-
117{-
118public:-
119-
120 QPageLayoutPrivate();-
121 QPageLayoutPrivate(const QPageSize &pageSize, QPageLayout::Orientation orientation,-
122 const QMarginsF &margins, QPageLayout::Unit units,-
123 const QMarginsF &minMargins);-
124 ~QPageLayoutPrivate();-
125-
126 bool operator==(const QPageLayoutPrivate &other) const;-
127 bool isEquivalentTo(const QPageLayoutPrivate &other) const;-
128-
129 bool isValid() const;-
130-
131 void clampMargins(const QMarginsF &margins);-
132-
133 QMarginsF margins(QPageLayout::Unit units) const;-
134 QMargins marginsPoints() const;-
135 QMargins marginsPixels(int resolution) const;-
136-
137 void setDefaultMargins(const QMarginsF &minMargins);-
138-
139 QSizeF paintSize() const;-
140-
141 QRectF fullRect() const;-
142 QRectF fullRect(QPageLayout::Unit units) const;-
143 QRect fullRectPoints() const;-
144 QRect fullRectPixels(int resolution) const;-
145-
146 QRectF paintRect() const;-
147-
148private:-
149 friend class QPageLayout;-
150-
151 QSizeF fullSizeUnits(QPageLayout::Unit units) const;-
152-
153 QPageSize m_pageSize;-
154 QPageLayout::Orientation m_orientation;-
155 QPageLayout::Mode m_mode;-
156 QPageLayout::Unit m_units;-
157 QSizeF m_fullSize;-
158 QMarginsF m_margins;-
159 QMarginsF m_minMargins;-
160 QMarginsF m_maxMargins;-
161};-
162-
163QPageLayoutPrivate::QPageLayoutPrivate()-
164 : m_orientation(QPageLayout::Landscape),-
165 m_mode(QPageLayout::StandardMode)-
166{-
167}
never executed: end of block
0
168-
169QPageLayoutPrivate::QPageLayoutPrivate(const QPageSize &pageSize, QPageLayout::Orientation orientation,-
170 const QMarginsF &margins, QPageLayout::Unit units,-
171 const QMarginsF &minMargins)-
172 : m_pageSize(pageSize),-
173 m_orientation(orientation),-
174 m_mode(QPageLayout::StandardMode),-
175 m_units(units),-
176 m_margins(margins)-
177{-
178 m_fullSize = fullSizeUnits(m_units);-
179 setDefaultMargins(minMargins);-
180}
never executed: end of block
0
181-
182QPageLayoutPrivate::~QPageLayoutPrivate()-
183{-
184}-
185-
186bool QPageLayoutPrivate::operator==(const QPageLayoutPrivate &other) const-
187{-
188 return m_pageSize == other.m_pageSize
never executed: return m_pageSize == other.m_pageSize && m_orientation == other.m_orientation && m_units == other.m_units && m_margins == other.m_margins && m_minMargins == other.m_minMargins && m_maxMargins == other.m_maxMargins;
m_pageSize == other.m_pageSizeDescription
TRUEnever evaluated
FALSEnever evaluated
0
189 && m_orientation == other.m_orientation
never executed: return m_pageSize == other.m_pageSize && m_orientation == other.m_orientation && m_units == other.m_units && m_margins == other.m_margins && m_minMargins == other.m_minMargins && m_maxMargins == other.m_maxMargins;
m_orientation ....m_orientationDescription
TRUEnever evaluated
FALSEnever evaluated
0
190 && m_units == other.m_units
never executed: return m_pageSize == other.m_pageSize && m_orientation == other.m_orientation && m_units == other.m_units && m_margins == other.m_margins && m_minMargins == other.m_minMargins && m_maxMargins == other.m_maxMargins;
m_units == other.m_unitsDescription
TRUEnever evaluated
FALSEnever evaluated
0
191 && m_margins == other.m_margins
never executed: return m_pageSize == other.m_pageSize && m_orientation == other.m_orientation && m_units == other.m_units && m_margins == other.m_margins && m_minMargins == other.m_minMargins && m_maxMargins == other.m_maxMargins;
m_margins == other.m_marginsDescription
TRUEnever evaluated
FALSEnever evaluated
0
192 && m_minMargins == other.m_minMargins
never executed: return m_pageSize == other.m_pageSize && m_orientation == other.m_orientation && m_units == other.m_units && m_margins == other.m_margins && m_minMargins == other.m_minMargins && m_maxMargins == other.m_maxMargins;
m_minMargins =...r.m_minMarginsDescription
TRUEnever evaluated
FALSEnever evaluated
0
193 && m_maxMargins == other.m_maxMargins;
never executed: return m_pageSize == other.m_pageSize && m_orientation == other.m_orientation && m_units == other.m_units && m_margins == other.m_margins && m_minMargins == other.m_minMargins && m_maxMargins == other.m_maxMargins;
m_maxMargins =...r.m_maxMarginsDescription
TRUEnever evaluated
FALSEnever evaluated
0
194}-
195-
196bool QPageLayoutPrivate::isEquivalentTo(const QPageLayoutPrivate &other) const-
197{-
198 return m_pageSize.isEquivalentTo(other.m_pageSize)
never executed: return m_pageSize.isEquivalentTo(other.m_pageSize) && m_orientation == other.m_orientation && qt_convertMargins(m_margins, m_units, QPageLayout::Point) == qt_convertMargins(other.m_margins, other.m_units, QPageLayout::Point);
m_pageSize.isE...er.m_pageSize)Description
TRUEnever evaluated
FALSEnever evaluated
0
199 && m_orientation == other.m_orientation
never executed: return m_pageSize.isEquivalentTo(other.m_pageSize) && m_orientation == other.m_orientation && qt_convertMargins(m_margins, m_units, QPageLayout::Point) == qt_convertMargins(other.m_margins, other.m_units, QPageLayout::Point);
m_orientation ....m_orientationDescription
TRUEnever evaluated
FALSEnever evaluated
0
200 && qt_convertMargins(m_margins, m_units, QPageLayout::Point)
never executed: return m_pageSize.isEquivalentTo(other.m_pageSize) && m_orientation == other.m_orientation && qt_convertMargins(m_margins, m_units, QPageLayout::Point) == qt_convertMargins(other.m_margins, other.m_units, QPageLayout::Point);
qt_convertMarg...Layout::Point)Description
TRUEnever evaluated
FALSEnever evaluated
0
201 == qt_convertMargins(other.m_margins, other.m_units, QPageLayout::Point);
never executed: return m_pageSize.isEquivalentTo(other.m_pageSize) && m_orientation == other.m_orientation && qt_convertMargins(m_margins, m_units, QPageLayout::Point) == qt_convertMargins(other.m_margins, other.m_units, QPageLayout::Point);
qt_convertMarg...Layout::Point)Description
TRUEnever evaluated
FALSEnever evaluated
0
202}-
203-
204bool QPageLayoutPrivate::isValid() const-
205{-
206 return m_pageSize.isValid();
never executed: return m_pageSize.isValid();
0
207}-
208-
209void QPageLayoutPrivate::clampMargins(const QMarginsF &margins)-
210{-
211 m_margins = QMarginsF(qBound(m_minMargins.left(), margins.left(), m_maxMargins.left()),-
212 qBound(m_minMargins.top(), margins.top(), m_maxMargins.top()),-
213 qBound(m_minMargins.right(), margins.right(), m_maxMargins.right()),-
214 qBound(m_minMargins.bottom(), margins.bottom(), m_maxMargins.bottom()));-
215}
never executed: end of block
0
216-
217QMarginsF QPageLayoutPrivate::margins(QPageLayout::Unit units) const-
218{-
219 return qt_convertMargins(m_margins, m_units, units);
never executed: return qt_convertMargins(m_margins, m_units, units);
0
220}-
221-
222QMargins QPageLayoutPrivate::marginsPoints() const-
223{-
224 return qt_convertMargins(m_margins, m_units, QPageLayout::Point).toMargins();
never executed: return qt_convertMargins(m_margins, m_units, QPageLayout::Point).toMargins();
0
225}-
226-
227QMargins QPageLayoutPrivate::marginsPixels(int resolution) const-
228{-
229 return marginsPoints() / qt_pixelMultiplier(resolution);
never executed: return marginsPoints() / qt_pixelMultiplier(resolution);
0
230}-
231-
232void QPageLayoutPrivate::setDefaultMargins(const QMarginsF &minMargins)-
233{-
234 m_minMargins = minMargins;-
235 m_maxMargins = QMarginsF(m_fullSize.width() - m_minMargins.right(),-
236 m_fullSize.height() - m_minMargins.bottom(),-
237 m_fullSize.width() - m_minMargins.left(),-
238 m_fullSize.height() - m_minMargins.top());-
239 if (m_mode == QPageLayout::StandardMode)
m_mode == QPag...::StandardModeDescription
TRUEnever evaluated
FALSEnever evaluated
0
240 clampMargins(m_margins);
never executed: clampMargins(m_margins);
0
241}
never executed: end of block
0
242-
243QSizeF QPageLayoutPrivate::fullSizeUnits(QPageLayout::Unit units) const-
244{-
245 QSizeF fullPageSize = m_pageSize.size(QPageSize::Unit(units));-
246 return m_orientation == QPageLayout::Landscape ? fullPageSize.transposed() : fullPageSize;
never executed: return m_orientation == QPageLayout::Landscape ? fullPageSize.transposed() : fullPageSize;
m_orientation ...out::LandscapeDescription
TRUEnever evaluated
FALSEnever evaluated
0
247}-
248-
249QRectF QPageLayoutPrivate::fullRect() const-
250{-
251 return QRectF(QPointF(0, 0), m_fullSize);
never executed: return QRectF(QPointF(0, 0), m_fullSize);
0
252}-
253-
254QRectF QPageLayoutPrivate::fullRect(QPageLayout::Unit units) const-
255{-
256 return units == m_units ? fullRect() : QRectF(QPointF(0, 0), fullSizeUnits(units));
never executed: return units == m_units ? fullRect() : QRectF(QPointF(0, 0), fullSizeUnits(units));
units == m_unitsDescription
TRUEnever evaluated
FALSEnever evaluated
0
257}-
258-
259QRect QPageLayoutPrivate::fullRectPoints() const-
260{-
261 if (m_orientation == QPageLayout::Landscape)
m_orientation ...out::LandscapeDescription
TRUEnever evaluated
FALSEnever evaluated
0
262 return QRect(QPoint(0, 0), m_pageSize.sizePoints().transposed());
never executed: return QRect(QPoint(0, 0), m_pageSize.sizePoints().transposed());
0
263 else-
264 return QRect(QPoint(0, 0), m_pageSize.sizePoints());
never executed: return QRect(QPoint(0, 0), m_pageSize.sizePoints());
0
265}-
266-
267QRect QPageLayoutPrivate::fullRectPixels(int resolution) const-
268{-
269 if (m_orientation == QPageLayout::Landscape)
m_orientation ...out::LandscapeDescription
TRUEnever evaluated
FALSEnever evaluated
0
270 return QRect(QPoint(0, 0), m_pageSize.sizePixels(resolution).transposed());
never executed: return QRect(QPoint(0, 0), m_pageSize.sizePixels(resolution).transposed());
0
271 else-
272 return QRect(QPoint(0, 0), m_pageSize.sizePixels(resolution));
never executed: return QRect(QPoint(0, 0), m_pageSize.sizePixels(resolution));
0
273}-
274-
275QRectF QPageLayoutPrivate::paintRect() const-
276{-
277 return m_mode == QPageLayout::FullPageMode ? fullRect() : fullRect() - m_margins;
never executed: return m_mode == QPageLayout::FullPageMode ? fullRect() : fullRect() - m_margins;
m_mode == QPag...::FullPageModeDescription
TRUEnever evaluated
FALSEnever evaluated
0
278}-
279-
280-
281/*!-
282 \class QPageLayout-
283 \inmodule QtGui-
284 \since 5.3-
285 \brief Describes the size, orientation and margins of a page.-
286-
287 The QPageLayout class defines the layout of a page in a paged document, with the-
288 page size, orientation and margins able to be set and the full page and paintable-
289 page rectangles defined by those attributes able to be queried in a variety of units.-
290-
291 The page size is defined by the QPageSize class which can be queried for page size-
292 attributes. Note that the QPageSize itself is always defined in a Portrait-
293 orientation.-
294-
295 The minimum margins can be defined for the layout but normally default to 0.-
296 When used in conjunction with Qt's printing support the minimum margins-
297 will reflect the minimum printable area defined by the printer.-
298-
299 In the default StandardMode the current margins and minimum margins are-
300 always taken into account. The paintable rectangle is the full page-
301 rectangle less the current margins, and the current margins can only be set-
302 to values between the minimum margins and the maximum margins allowed by-
303 the full page size.-
304-
305 In FullPageMode the current margins and minimum margins are not taken-
306 into account. The paintable rectangle is the full page rectangle, and the-
307 current margins can be set to any values regardless of the minimum margins-
308 and page size.-
309-
310 \sa QPageSize-
311*/-
312-
313/*!-
314 \enum QPageLayout::Unit-
315-
316 This enum type is used to specify the measurement unit for page layout and margins.-
317-
318 \value Millimeter-
319 \value Point 1/72th of an inch-
320 \value Inch-
321 \value Pica 1/72th of a foot, 1/6th of an inch, 12 Points-
322 \value Didot 1/72th of a French inch, 0.375 mm-
323 \value Cicero 1/6th of a French inch, 12 Didot, 4.5mm-
324*/-
325-
326/*!-
327 \enum QPageLayout::Orientation-
328-
329 This enum type defines the page orientation-
330-
331 \value Portrait The page size is used in its default orientation-
332 \value Landscape The page size is rotated through 90 degrees-
333-
334 Note that some standard page sizes are defined with a width larger than-
335 their height, hence the orientation is defined relative to the standard-
336 page size and not using the relative page dimensions.-
337*/-
338-
339/*!-
340 \enum QPageLayout::Mode-
341-
342 Defines the page layout mode-
343-
344 \value StandardMode Paint Rect includes margins, margins must fall between the minimum and maximum.-
345 \value FullPageMode Paint Rect excludes margins, margins can be any value and must be managed manually.-
346*/-
347-
348/*!-
349 Creates an invalid QPageLayout.-
350*/-
351-
352QPageLayout::QPageLayout()-
353 : d(new QPageLayoutPrivate())-
354{-
355}
never executed: end of block
0
356-
357/*!-
358 Creates a QPageLayout with the given \a pageSize, \a orientation and-
359 \a margins in the given \a units.-
360-
361 Optionally define the minimum allowed margins \a minMargins, e.g. the minimum-
362 margins able to be printed by a physical print device.-
363-
364 The constructed QPageLayout will be in StandardMode.-
365-
366 The \a margins given will be clamped to the minimum margins and the maximum-
367 margins allowed by the page size.-
368*/-
369-
370QPageLayout::QPageLayout(const QPageSize &pageSize, Orientation orientation,-
371 const QMarginsF &margins, Unit units,-
372 const QMarginsF &minMargins)-
373 : d(new QPageLayoutPrivate(pageSize, orientation, margins, units, minMargins))-
374{-
375}
never executed: end of block
0
376-
377/*!-
378 Copy constructor, copies \a other to this.-
379*/-
380-
381QPageLayout::QPageLayout(const QPageLayout &other)-
382 : d(other.d)-
383{-
384}
never executed: end of block
0
385-
386/*!-
387 Destroys the page layout.-
388*/-
389-
390QPageLayout::~QPageLayout()-
391{-
392}-
393-
394/*!-
395 Assignment operator, assigns \a other to this.-
396*/-
397-
398QPageLayout &QPageLayout::operator=(const QPageLayout &other)-
399{-
400 d = other.d;-
401 return *this;
never executed: return *this;
0
402}-
403-
404/*!-
405 \fn void QPageLayout::swap(QPageLayout &other)-
406-
407 Swaps this page layout with \a other. This function is very fast and-
408 never fails.-
409*/-
410-
411/*!-
412 \fn QPageLayout &QPageLayout::operator=(QPageLayout &&other)-
413-
414 Move-assigns \a other to this QPageLayout instance, transferring the-
415 ownership of the managed pointer to this instance.-
416*/-
417-
418/*!-
419 \relates QPageLayout-
420-
421 Returns \c true if page layout \a lhs is equal to page layout \a rhs,-
422 i.e. if all the attributes are exactly equal.-
423-
424 Note that this is a strict equality, especially for page size where the-
425 QPageSize ID, name and size must exactly match, and the margins where the-
426 units must match.-
427-
428 \sa QPageLayout::isEquivalentTo()-
429*/-
430-
431bool operator==(const QPageLayout &lhs, const QPageLayout &rhs)-
432{-
433 return lhs.d == rhs.d || *lhs.d == *rhs.d;
never executed: return lhs.d == rhs.d || *lhs.d == *rhs.d;
lhs.d == rhs.dDescription
TRUEnever evaluated
FALSEnever evaluated
*lhs.d == *rhs.dDescription
TRUEnever evaluated
FALSEnever evaluated
0
434}-
435-
436/*!-
437 \fn bool operator!=(const QPageLayout &lhs, const QPageLayout &rhs)-
438 \relates QPageLayout-
439-
440 Returns \c true if page layout \a lhs is not equal to page layout \a rhs,-
441 i.e. if any of the attributes differ.-
442-
443 Note that this is a strict equality, especially for page size where the-
444 QPageSize ID, name and size must exactly match, and the margins where the-
445 units must match.-
446-
447 \sa QPageLayout::isEquivalentTo()-
448*/-
449-
450/*!-
451 Returns \c true if this page layout is equivalent to the \a other page layout,-
452 i.e. if the page has the same size, margins and orientation.-
453*/-
454-
455bool QPageLayout::isEquivalentTo(const QPageLayout &other) const-
456{-
457 return d && other.d && d->isEquivalentTo(*other.d);
never executed: return d && other.d && d->isEquivalentTo(*other.d);
dDescription
TRUEnever evaluated
FALSEnever evaluated
other.dDescription
TRUEnever evaluated
FALSEnever evaluated
d->isEquivalentTo(*other.d)Description
TRUEnever evaluated
FALSEnever evaluated
0
458}-
459-
460/*!-
461 Returns \c true if this page layout is valid.-
462*/-
463-
464bool QPageLayout::isValid() const-
465{-
466 return d->isValid();
never executed: return d->isValid();
0
467}-
468-
469/*!-
470 Sets a page layout mode to \a mode.-
471*/-
472-
473void QPageLayout::setMode(Mode mode)-
474{-
475 d.detach();-
476 d->m_mode = mode;-
477}
never executed: end of block
0
478-
479/*!-
480 Returns the page layout mode.-
481*/-
482-
483QPageLayout::Mode QPageLayout::mode() const-
484{-
485 return d->m_mode;
never executed: return d->m_mode;
0
486}-
487-
488/*!-
489 Sets the page size of the page layout to \a pageSize.-
490-
491 Optionally define the minimum allowed margins \a minMargins, e.g. the minimum-
492 margins able to be printed by a physical print device, otherwise the-
493 minimum margins will default to 0.-
494-
495 If StandardMode is set then the existing margins will be clamped-
496 to the new minimum margins and the maximum margins allowed by the page size.-
497 If FullPageMode is set then the existing margins will be unchanged.-
498*/-
499-
500void QPageLayout::setPageSize(const QPageSize &pageSize, const QMarginsF &minMargins)-
501{-
502 if (!pageSize.isValid())
!pageSize.isValid()Description
TRUEnever evaluated
FALSEnever evaluated
0
503 return;
never executed: return;
0
504 d.detach();-
505 d->m_pageSize = pageSize;-
506 d->m_fullSize = d->fullSizeUnits(d->m_units);-
507 d->setDefaultMargins(minMargins);-
508}
never executed: end of block
0
509-
510/*!-
511 Returns the page size of the page layout.-
512-
513 Note that the QPageSize is always defined in a Portrait orientation. To-
514 obtain a size that takes the set orientation into account you must use-
515 fullRect().-
516*/-
517-
518QPageSize QPageLayout::pageSize() const-
519{-
520 return d->m_pageSize;
never executed: return d->m_pageSize;
0
521}-
522-
523/*!-
524 Sets the page orientation of the page layout to \a orientation.-
525-
526 Changing the orientation does not affect the current margins or-
527 the minimum margins.-
528*/-
529-
530void QPageLayout::setOrientation(Orientation orientation)-
531{-
532 if (orientation != d->m_orientation) {
orientation !=...>m_orientationDescription
TRUEnever evaluated
FALSEnever evaluated
0
533 d.detach();-
534 d->m_orientation = orientation;-
535 d->m_fullSize = d->fullSizeUnits(d->m_units);-
536 // Adust the max margins to reflect change in max page size-
537 const qreal change = d->m_fullSize.width() - d->m_fullSize.height();-
538 d->m_maxMargins.setLeft(d->m_maxMargins.left() + change);-
539 d->m_maxMargins.setRight(d->m_maxMargins.right() + change);-
540 d->m_maxMargins.setTop(d->m_maxMargins.top() - change);-
541 d->m_maxMargins.setBottom(d->m_maxMargins.bottom() - change);-
542 }
never executed: end of block
0
543}
never executed: end of block
0
544-
545/*!-
546 Returns the page orientation of the page layout.-
547*/-
548-
549QPageLayout::Orientation QPageLayout::orientation() const-
550{-
551 return d->m_orientation;
never executed: return d->m_orientation;
0
552}-
553-
554/*!-
555 Sets the \a units used to define the page layout.-
556*/-
557-
558void QPageLayout::setUnits(Unit units)-
559{-
560 if (units != d->m_units) {
units != d->m_unitsDescription
TRUEnever evaluated
FALSEnever evaluated
0
561 d.detach();-
562 d->m_margins = qt_convertMargins(d->m_margins, d->m_units, units);-
563 d->m_minMargins = qt_convertMargins(d->m_minMargins, d->m_units, units);-
564 d->m_maxMargins = qt_convertMargins(d->m_maxMargins, d->m_units, units);-
565 d->m_units = units;-
566 d->m_fullSize = d->fullSizeUnits(d->m_units);-
567 }
never executed: end of block
0
568}
never executed: end of block
0
569-
570/*!-
571 Returns the units the page layout is currently defined in.-
572*/-
573-
574QPageLayout::Unit QPageLayout::units() const-
575{-
576 return d->m_units;
never executed: return d->m_units;
0
577}-
578-
579/*!-
580 Sets the page margins of the page layout to \a margins-
581 Returns true if the margins were successfully set.-
582-
583 The units used are those currently defined for the layout. To use different-
584 units then call setUnits() first.-
585-
586 If in the default StandardMode then all the new margins must fall between the-
587 minimum margins set and the maximum margins allowed by the page size,-
588 otherwise the margins will not be set.-
589-
590 If in FullPageMode then any margin values will be accepted.-
591-
592 \sa margins(), units()-
593*/-
594-
595bool QPageLayout::setMargins(const QMarginsF &margins)-
596{-
597 if (d->m_mode == FullPageMode) {
d->m_mode == FullPageModeDescription
TRUEnever evaluated
FALSEnever evaluated
0
598 d.detach();-
599 d->m_margins = margins;-
600 return true;
never executed: return true;
0
601 } else if (margins.left() >= d->m_minMargins.left()
margins.left()...Margins.left()Description
TRUEnever evaluated
FALSEnever evaluated
0
602 && margins.right() >= d->m_minMargins.right()
margins.right(...argins.right()Description
TRUEnever evaluated
FALSEnever evaluated
0
603 && margins.top() >= d->m_minMargins.top()
margins.top() ...nMargins.top()Description
TRUEnever evaluated
FALSEnever evaluated
0
604 && margins.bottom() >= d->m_minMargins.bottom()
margins.bottom...rgins.bottom()Description
TRUEnever evaluated
FALSEnever evaluated
0
605 && margins.left() <= d->m_maxMargins.left()
margins.left()...Margins.left()Description
TRUEnever evaluated
FALSEnever evaluated
0
606 && margins.right() <= d->m_maxMargins.right()
margins.right(...argins.right()Description
TRUEnever evaluated
FALSEnever evaluated
0
607 && margins.top() <= d->m_maxMargins.top()
margins.top() ...xMargins.top()Description
TRUEnever evaluated
FALSEnever evaluated
0
608 && margins.bottom() <= d->m_maxMargins.bottom()) {
margins.bottom...rgins.bottom()Description
TRUEnever evaluated
FALSEnever evaluated
0
609 d.detach();-
610 d->m_margins = margins;-
611 return true;
never executed: return true;
0
612 }-
613 return false;
never executed: return false;
0
614}-
615-
616/*!-
617 Sets the left page margin of the page layout to \a leftMargin.-
618 Returns true if the margin was successfully set.-
619-
620 The units used are those currently defined for the layout. To use different-
621 units call setUnits() first.-
622-
623 If in the default StandardMode then the new margin must fall between the-
624 minimum margin set and the maximum margin allowed by the page size,-
625 otherwise the margin will not be set.-
626-
627 If in FullPageMode then any margin values will be accepted.-
628-
629 \sa setMargins(), margins()-
630*/-
631-
632bool QPageLayout::setLeftMargin(qreal leftMargin)-
633{-
634 if (d->m_mode == FullPageMode
d->m_mode == FullPageModeDescription
TRUEnever evaluated
FALSEnever evaluated
0
635 || (leftMargin >= d->m_minMargins.left() && leftMargin <= d->m_maxMargins.left())) {
leftMargin >= ...Margins.left()Description
TRUEnever evaluated
FALSEnever evaluated
leftMargin <= ...Margins.left()Description
TRUEnever evaluated
FALSEnever evaluated
0
636 d.detach();-
637 d->m_margins.setLeft(leftMargin);-
638 return true;
never executed: return true;
0
639 }-
640 return false;
never executed: return false;
0
641}-
642-
643/*!-
644 Sets the right page margin of the page layout to \a rightMargin.-
645 Returns true if the margin was successfully set.-
646-
647 The units used are those currently defined for the layout. To use different-
648 units call setUnits() first.-
649-
650 If in the default StandardMode then the new margin must fall between the-
651 minimum margin set and the maximum margin allowed by the page size,-
652 otherwise the margin will not be set.-
653-
654 If in FullPageMode then any margin values will be accepted.-
655-
656 \sa setMargins(), margins()-
657*/-
658-
659bool QPageLayout::setRightMargin(qreal rightMargin)-
660{-
661 if (d->m_mode == FullPageMode
d->m_mode == FullPageModeDescription
TRUEnever evaluated
FALSEnever evaluated
0
662 || (rightMargin >= d->m_minMargins.right() && rightMargin <= d->m_maxMargins.right())) {
rightMargin >=...argins.right()Description
TRUEnever evaluated
FALSEnever evaluated
rightMargin <=...argins.right()Description
TRUEnever evaluated
FALSEnever evaluated
0
663 d.detach();-
664 d->m_margins.setRight(rightMargin);-
665 return true;
never executed: return true;
0
666 }-
667 return false;
never executed: return false;
0
668}-
669-
670/*!-
671 Sets the top page margin of the page layout to \a topMargin.-
672 Returns true if the margin was successfully set.-
673-
674 The units used are those currently defined for the layout. To use different-
675 units call setUnits() first.-
676-
677 If in the default StandardMode then the new margin must fall between the-
678 minimum margin set and the maximum margin allowed by the page size,-
679 otherwise the margin will not be set.-
680-
681 If in FullPageMode then any margin values will be accepted.-
682-
683 \sa setMargins(), margins()-
684*/-
685-
686bool QPageLayout::setTopMargin(qreal topMargin)-
687{-
688 if (d->m_mode == FullPageMode
d->m_mode == FullPageModeDescription
TRUEnever evaluated
FALSEnever evaluated
0
689 || (topMargin >= d->m_minMargins.top() && topMargin <= d->m_maxMargins.top())) {
topMargin >= d...nMargins.top()Description
TRUEnever evaluated
FALSEnever evaluated
topMargin <= d...xMargins.top()Description
TRUEnever evaluated
FALSEnever evaluated
0
690 d.detach();-
691 d->m_margins.setTop(topMargin);-
692 return true;
never executed: return true;
0
693 }-
694 return false;
never executed: return false;
0
695}-
696-
697/*!-
698 Sets the bottom page margin of the page layout to \a bottomMargin.-
699 Returns true if the margin was successfully set.-
700-
701 The units used are those currently defined for the layout. To use different-
702 units call setUnits() first.-
703-
704 If in the default StandardMode then the new margin must fall between the-
705 minimum margin set and the maximum margin allowed by the page size,-
706 otherwise the margin will not be set.-
707-
708 If in FullPageMode then any margin values will be accepted.-
709-
710 \sa setMargins(), margins()-
711*/-
712-
713bool QPageLayout::setBottomMargin(qreal bottomMargin)-
714{-
715 if (d->m_mode == FullPageMode
d->m_mode == FullPageModeDescription
TRUEnever evaluated
FALSEnever evaluated
0
716 || (bottomMargin >= d->m_minMargins.bottom() && bottomMargin <= d->m_maxMargins.bottom())) {
bottomMargin >...rgins.bottom()Description
TRUEnever evaluated
FALSEnever evaluated
bottomMargin <...rgins.bottom()Description
TRUEnever evaluated
FALSEnever evaluated
0
717 d.detach();-
718 d->m_margins.setBottom(bottomMargin);-
719 return true;
never executed: return true;
0
720 }-
721 return false;
never executed: return false;
0
722}-
723-
724/*!-
725 Returns the margins of the page layout using the currently set units.-
726-
727 \sa setMargins(), units()-
728*/-
729-
730QMarginsF QPageLayout::margins() const-
731{-
732 return d->m_margins;
never executed: return d->m_margins;
0
733}-
734-
735/*!-
736 Returns the margins of the page layout using the requested \a units.-
737-
738 \sa setMargins(), margins()-
739*/-
740-
741QMarginsF QPageLayout::margins(Unit units) const-
742{-
743 return d->margins(units);
never executed: return d->margins(units);
0
744}-
745-
746/*!-
747 Returns the margins of the page layout in Postscript Points (1/72 of an inch).-
748-
749 \sa setMargins(), margins()-
750*/-
751-
752QMargins QPageLayout::marginsPoints() const-
753{-
754 return d->marginsPoints();
never executed: return d->marginsPoints();
0
755}-
756-
757/*!-
758 Returns the margins of the page layout in device pixels for the given \a resolution.-
759-
760 \sa setMargins()-
761*/-
762-
763QMargins QPageLayout::marginsPixels(int resolution) const-
764{-
765 return d->marginsPixels(resolution);
never executed: return d->marginsPixels(resolution);
0
766}-
767-
768/*!-
769 Sets the minimum page margins of the page layout to \a minMargins.-
770-
771 It is not recommended to override the default values set for a page size-
772 as this may be the minimum printable area for a physical print device.-
773-
774 If the StandardMode mode is set then the existing margins will be clamped-
775 to the new \a minMargins and the maximum allowed by the page size. If the-
776 FullPageMode is set then the existing margins will be unchanged.-
777-
778 \sa minimumMargins(), setMargins()-
779*/-
780-
781void QPageLayout::setMinimumMargins(const QMarginsF &minMargins)-
782{-
783 d.detach();-
784 d->setDefaultMargins(minMargins);-
785}
never executed: end of block
0
786-
787/*!-
788 Returns the minimum margins of the page layout.-
789-
790 \sa setMinimumMargins(), maximumMargins()-
791*/-
792-
793QMarginsF QPageLayout::minimumMargins() const-
794{-
795 return d->m_minMargins;
never executed: return d->m_minMargins;
0
796}-
797-
798/*!-
799 Returns the maximum margins that would be applied if the page layout was-
800 in StandardMode.-
801-
802 The maximum margins allowed are calculated as the full size of the page-
803 minus the minimum margins set. For example, if the page width is 100 points-
804 and the minimum right margin is 10 points, then the maximum left margin-
805 will be 90 points.-
806-
807 \sa setMinimumMargins(), minimumMargins()-
808*/-
809-
810QMarginsF QPageLayout::maximumMargins() const-
811{-
812 return d->m_maxMargins;
never executed: return d->m_maxMargins;
0
813}-
814-
815/*!-
816 Returns the full page rectangle in the current layout units.-
817-
818 The page rectangle takes into account the page size and page orientation,-
819 but not the page margins.-
820-
821 \sa paintRect(), units()-
822*/-
823-
824QRectF QPageLayout::fullRect() const-
825{-
826 return isValid() ? d->fullRect() : QRect();
never executed: return isValid() ? d->fullRect() : QRect();
isValid()Description
TRUEnever evaluated
FALSEnever evaluated
0
827}-
828-
829/*!-
830 Returns the full page rectangle in the required \a units.-
831-
832 The page rectangle takes into account the page size and page orientation,-
833 but not the page margins.-
834-
835 \sa paintRect()-
836*/-
837-
838QRectF QPageLayout::fullRect(Unit units) const-
839{-
840 return isValid() ? d->fullRect(units) : QRect();
never executed: return isValid() ? d->fullRect(units) : QRect();
isValid()Description
TRUEnever evaluated
FALSEnever evaluated
0
841}-
842-
843/*!-
844 Returns the full page rectangle in Postscript Points (1/72 of an inch).-
845-
846 The page rectangle takes into account the page size and page orientation,-
847 but not the page margins.-
848-
849 \sa paintRect()-
850*/-
851-
852QRect QPageLayout::fullRectPoints() const-
853{-
854 return isValid() ? d->fullRectPoints() : QRect();
never executed: return isValid() ? d->fullRectPoints() : QRect();
isValid()Description
TRUEnever evaluated
FALSEnever evaluated
0
855}-
856-
857/*!-
858 Returns the full page rectangle in device pixels for the given \a resolution.-
859-
860 The page rectangle takes into account the page size and page orientation,-
861 but not the page margins.-
862-
863 \sa paintRect()-
864*/-
865-
866QRect QPageLayout::fullRectPixels(int resolution) const-
867{-
868 return isValid() ? d->fullRectPixels(resolution) : QRect();
never executed: return isValid() ? d->fullRectPixels(resolution) : QRect();
isValid()Description
TRUEnever evaluated
FALSEnever evaluated
0
869}-
870-
871/*!-
872 Returns the page rectangle in the current layout units.-
873-
874 The paintable rectangle takes into account the page size, orientation-
875 and margins.-
876-
877 If the FullPageMode mode is set then the fullRect() is returned and-
878 the margins must be manually managed.-
879*/-
880-
881QRectF QPageLayout::paintRect() const-
882{-
883 return isValid() ? d->paintRect() : QRectF();
never executed: return isValid() ? d->paintRect() : QRectF();
isValid()Description
TRUEnever evaluated
FALSEnever evaluated
0
884}-
885-
886/*!-
887 Returns the page rectangle in the required \a units.-
888-
889 The paintable rectangle takes into account the page size, orientation-
890 and margins.-
891-
892 If the FullPageMode mode is set then the fullRect() is returned and-
893 the margins must be manually managed.-
894*/-
895-
896QRectF QPageLayout::paintRect(Unit units) const-
897{-
898 if (!isValid())
!isValid()Description
TRUEnever evaluated
FALSEnever evaluated
0
899 return QRectF();
never executed: return QRectF();
0
900 if (units == d->m_units)
units == d->m_unitsDescription
TRUEnever evaluated
FALSEnever evaluated
0
901 return d->paintRect();
never executed: return d->paintRect();
0
902 return d->m_mode == FullPageMode ? d->fullRect(units)
never executed: return d->m_mode == FullPageMode ? d->fullRect(units) : d->fullRect(units) - d->margins(units);
d->m_mode == FullPageModeDescription
TRUEnever evaluated
FALSEnever evaluated
0
903 : d->fullRect(units) - d->margins(units);
never executed: return d->m_mode == FullPageMode ? d->fullRect(units) : d->fullRect(units) - d->margins(units);
0
904}-
905-
906/*!-
907 Returns the paintable rectangle in rounded Postscript Points (1/72 of an inch).-
908-
909 The paintable rectangle takes into account the page size, orientation-
910 and margins.-
911-
912 If the FullPageMode mode is set then the fullRect() is returned and-
913 the margins must be manually managed.-
914*/-
915-
916QRect QPageLayout::paintRectPoints() const-
917{-
918 if (!isValid())
!isValid()Description
TRUEnever evaluated
FALSEnever evaluated
0
919 return QRect();
never executed: return QRect();
0
920 return d->m_mode == FullPageMode ? d->fullRectPoints()
never executed: return d->m_mode == FullPageMode ? d->fullRectPoints() : d->fullRectPoints() - d->marginsPoints();
d->m_mode == FullPageModeDescription
TRUEnever evaluated
FALSEnever evaluated
0
921 : d->fullRectPoints() - d->marginsPoints();
never executed: return d->m_mode == FullPageMode ? d->fullRectPoints() : d->fullRectPoints() - d->marginsPoints();
0
922}-
923-
924/*!-
925 Returns the paintable rectangle in rounded device pixels for the given \a resolution.-
926-
927 The paintable rectangle takes into account the page size, orientation-
928 and margins.-
929-
930 If the FullPageMode mode is set then the fullRect() is returned and-
931 the margins must be manually managed.-
932*/-
933-
934QRect QPageLayout::paintRectPixels(int resolution) const-
935{-
936 if (!isValid())
!isValid()Description
TRUEnever evaluated
FALSEnever evaluated
0
937 return QRect();
never executed: return QRect();
0
938 return d->m_mode == FullPageMode ? d->fullRectPixels(resolution)
never executed: return d->m_mode == FullPageMode ? d->fullRectPixels(resolution) : d->fullRectPixels(resolution) - d->marginsPixels(resolution);
d->m_mode == FullPageModeDescription
TRUEnever evaluated
FALSEnever evaluated
0
939 : d->fullRectPixels(resolution) - d->marginsPixels(resolution);
never executed: return d->m_mode == FullPageMode ? d->fullRectPixels(resolution) : d->fullRectPixels(resolution) - d->marginsPixels(resolution);
0
940}-
941-
942#ifndef QT_NO_DEBUG_STREAM-
943QDebug operator<<(QDebug dbg, const QPageLayout &layout)-
944{-
945 QDebugStateSaver saver(dbg);-
946 dbg.nospace();-
947 dbg.noquote();-
948 dbg << "QPageLayout(";-
949 if (layout.isValid()) {
layout.isValid()Description
TRUEnever evaluated
FALSEnever evaluated
0
950 const QMarginsF margins = layout.margins();-
951 dbg << '"' << layout.pageSize().name() << "\", "-
952 << (layout.orientation() == QPageLayout::Portrait ? "Portrait" : "Landscape")-
953 << ", l:" << margins.left() << " r:" << margins.right() << " t:"-
954 << margins.top() << " b:" << margins.bottom() << ' ';-
955 switch (layout.units()) {-
956 case QPageLayout::Millimeter:
never executed: case QPageLayout::Millimeter:
0
957 dbg << "mm";-
958 break;
never executed: break;
0
959 case QPageLayout::Point:
never executed: case QPageLayout::Point:
0
960 dbg << "pt";-
961 break;
never executed: break;
0
962 case QPageLayout::Inch:
never executed: case QPageLayout::Inch:
0
963 dbg << "in";-
964 break;
never executed: break;
0
965 case QPageLayout::Pica:
never executed: case QPageLayout::Pica:
0
966 dbg << "pc";-
967 break;
never executed: break;
0
968 case QPageLayout::Didot:
never executed: case QPageLayout::Didot:
0
969 dbg << "DD";-
970 break;
never executed: break;
0
971 case QPageLayout::Cicero:
never executed: case QPageLayout::Cicero:
0
972 dbg << "CC";-
973 break;
never executed: break;
0
974 }-
975 }
never executed: end of block
0
976 dbg << ')';-
977 return dbg;
never executed: return dbg;
0
978}-
979#endif-
980-
981QT_END_NAMESPACE-
Source codeSwitch to Preprocessed file

Generated by Squish Coco Non-Commercial 4.3.0-BETA-master-30-08-2018-4cb69e9