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