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

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