1/****************************************************************************
2**
3** Copyright (C) 2016 The Qt Company Ltd.
4** Contact: https://www.qt.io/licensing/
5**
6** This file is part of the QtCore module of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:LGPL$
9** Commercial License Usage
10** Licensees holding valid commercial Qt licenses may use this file in
11** accordance with the commercial license agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and The Qt Company. For licensing terms
14** and conditions see https://www.qt.io/terms-conditions. For further
15** information use the contact form at https://www.qt.io/contact-us.
16**
17** GNU Lesser General Public License Usage
18** Alternatively, this file may be used under the terms of the GNU Lesser
19** General Public License version 3 as published by the Free Software
20** Foundation and appearing in the file LICENSE.LGPL3 included in the
21** packaging of this file. Please review the following information to
22** ensure the GNU Lesser General Public License version 3 requirements
23** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
24**
25** GNU General Public License Usage
26** Alternatively, this file may be used under the terms of the GNU
27** General Public License version 2.0 or (at your option) the GNU General
28** Public license version 3 or any later version approved by the KDE Free
29** Qt Foundation. The licenses are as published by the Free Software
30** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
31** included in the packaging of this file. Please review the following
32** information to ensure the GNU General Public License requirements will
33** be met: https://www.gnu.org/licenses/gpl-2.0.html and
34** https://www.gnu.org/licenses/gpl-3.0.html.
35**
36** $QT_END_LICENSE$
37**
38****************************************************************************/
39
40#ifndef QRECT_H
41#define QRECT_H
42
43#include <QtCore/qmargins.h>
44#include <QtCore/qsize.h>
45#include <QtCore/qpoint.h>
46
47#ifdef topLeft
48#error qrect.h must be included before any header file that defines topLeft
49#endif
50
51#if defined(Q_OS_DARWIN) || defined(Q_QDOC)
52struct CGRect;
53#endif
54
55QT_BEGIN_NAMESPACE
56
57class Q_CORE_EXPORT QRect
58{
59public:
60 Q_DECL_CONSTEXPR QRect() Q_DECL_NOTHROW : x1(0), y1(0), x2(-1), y2(-1) {}
61 Q_DECL_CONSTEXPR QRect(const QPoint &topleft, const QPoint &bottomright) Q_DECL_NOTHROW;
62 Q_DECL_CONSTEXPR QRect(const QPoint &topleft, const QSize &size) Q_DECL_NOTHROW;
63 Q_DECL_CONSTEXPR QRect(int left, int top, int width, int height) Q_DECL_NOTHROW;
64
65 Q_DECL_CONSTEXPR inline bool isNull() const Q_DECL_NOTHROW;
66 Q_DECL_CONSTEXPR inline bool isEmpty() const Q_DECL_NOTHROW;
67 Q_DECL_CONSTEXPR inline bool isValid() const Q_DECL_NOTHROW;
68
69 Q_DECL_CONSTEXPR inline int left() const Q_DECL_NOTHROW;
70 Q_DECL_CONSTEXPR inline int top() const Q_DECL_NOTHROW;
71 Q_DECL_CONSTEXPR inline int right() const Q_DECL_NOTHROW;
72 Q_DECL_CONSTEXPR inline int bottom() const Q_DECL_NOTHROW;
73 Q_REQUIRED_RESULT QRect normalized() const Q_DECL_NOTHROW;
74
75 Q_DECL_CONSTEXPR inline int x() const Q_DECL_NOTHROW;
76 Q_DECL_CONSTEXPR inline int y() const Q_DECL_NOTHROW;
77 Q_DECL_RELAXED_CONSTEXPR inline void setLeft(int pos) Q_DECL_NOTHROW;
78 Q_DECL_RELAXED_CONSTEXPR inline void setTop(int pos) Q_DECL_NOTHROW;
79 Q_DECL_RELAXED_CONSTEXPR inline void setRight(int pos) Q_DECL_NOTHROW;
80 Q_DECL_RELAXED_CONSTEXPR inline void setBottom(int pos) Q_DECL_NOTHROW;
81 Q_DECL_RELAXED_CONSTEXPR inline void setX(int x) Q_DECL_NOTHROW;
82 Q_DECL_RELAXED_CONSTEXPR inline void setY(int y) Q_DECL_NOTHROW;
83
84 Q_DECL_RELAXED_CONSTEXPR inline void setTopLeft(const QPoint &p) Q_DECL_NOTHROW;
85 Q_DECL_RELAXED_CONSTEXPR inline void setBottomRight(const QPoint &p) Q_DECL_NOTHROW;
86 Q_DECL_RELAXED_CONSTEXPR inline void setTopRight(const QPoint &p) Q_DECL_NOTHROW;
87 Q_DECL_RELAXED_CONSTEXPR inline void setBottomLeft(const QPoint &p) Q_DECL_NOTHROW;
88
89 Q_DECL_CONSTEXPR inline QPoint topLeft() const Q_DECL_NOTHROW;
90 Q_DECL_CONSTEXPR inline QPoint bottomRight() const Q_DECL_NOTHROW;
91 Q_DECL_CONSTEXPR inline QPoint topRight() const Q_DECL_NOTHROW;
92 Q_DECL_CONSTEXPR inline QPoint bottomLeft() const Q_DECL_NOTHROW;
93 Q_DECL_CONSTEXPR inline QPoint center() const Q_DECL_NOTHROW;
94
95 Q_DECL_RELAXED_CONSTEXPR inline void moveLeft(int pos) Q_DECL_NOTHROW;
96 Q_DECL_RELAXED_CONSTEXPR inline void moveTop(int pos) Q_DECL_NOTHROW;
97 Q_DECL_RELAXED_CONSTEXPR inline void moveRight(int pos) Q_DECL_NOTHROW;
98 Q_DECL_RELAXED_CONSTEXPR inline void moveBottom(int pos) Q_DECL_NOTHROW;
99 Q_DECL_RELAXED_CONSTEXPR inline void moveTopLeft(const QPoint &p) Q_DECL_NOTHROW;
100 Q_DECL_RELAXED_CONSTEXPR inline void moveBottomRight(const QPoint &p) Q_DECL_NOTHROW;
101 Q_DECL_RELAXED_CONSTEXPR inline void moveTopRight(const QPoint &p) Q_DECL_NOTHROW;
102 Q_DECL_RELAXED_CONSTEXPR inline void moveBottomLeft(const QPoint &p) Q_DECL_NOTHROW;
103 Q_DECL_RELAXED_CONSTEXPR inline void moveCenter(const QPoint &p) Q_DECL_NOTHROW;
104
105 Q_DECL_RELAXED_CONSTEXPR inline void translate(int dx, int dy) Q_DECL_NOTHROW;
106 Q_DECL_RELAXED_CONSTEXPR inline void translate(const QPoint &p) Q_DECL_NOTHROW;
107 Q_REQUIRED_RESULT Q_DECL_CONSTEXPR inline QRect translated(int dx, int dy) const Q_DECL_NOTHROW;
108 Q_REQUIRED_RESULT Q_DECL_CONSTEXPR inline QRect translated(const QPoint &p) const Q_DECL_NOTHROW;
109 Q_REQUIRED_RESULT Q_DECL_CONSTEXPR inline QRect transposed() const Q_DECL_NOTHROW;
110
111 Q_DECL_RELAXED_CONSTEXPR inline void moveTo(int x, int t) Q_DECL_NOTHROW;
112 Q_DECL_RELAXED_CONSTEXPR inline void moveTo(const QPoint &p) Q_DECL_NOTHROW;
113
114 Q_DECL_RELAXED_CONSTEXPR inline void setRect(int x, int y, int w, int h) Q_DECL_NOTHROW;
115 Q_DECL_RELAXED_CONSTEXPR inline void getRect(int *x, int *y, int *w, int *h) const;
116
117 Q_DECL_RELAXED_CONSTEXPR inline void setCoords(int x1, int y1, int x2, int y2) Q_DECL_NOTHROW;
118 Q_DECL_RELAXED_CONSTEXPR inline void getCoords(int *x1, int *y1, int *x2, int *y2) const;
119
120 Q_DECL_RELAXED_CONSTEXPR inline void adjust(int x1, int y1, int x2, int y2) Q_DECL_NOTHROW;
121 Q_REQUIRED_RESULT Q_DECL_CONSTEXPR inline QRect adjusted(int x1, int y1, int x2, int y2) const Q_DECL_NOTHROW;
122
123 Q_DECL_CONSTEXPR inline QSize size() const Q_DECL_NOTHROW;
124 Q_DECL_CONSTEXPR inline int width() const Q_DECL_NOTHROW;
125 Q_DECL_CONSTEXPR inline int height() const Q_DECL_NOTHROW;
126 Q_DECL_RELAXED_CONSTEXPR inline void setWidth(int w) Q_DECL_NOTHROW;
127 Q_DECL_RELAXED_CONSTEXPR inline void setHeight(int h) Q_DECL_NOTHROW;
128 Q_DECL_RELAXED_CONSTEXPR inline void setSize(const QSize &s) Q_DECL_NOTHROW;
129
130 QRect operator|(const QRect &r) const Q_DECL_NOTHROW;
131 QRect operator&(const QRect &r) const Q_DECL_NOTHROW;
132 inline QRect& operator|=(const QRect &r) Q_DECL_NOTHROW;
133 inline QRect& operator&=(const QRect &r) Q_DECL_NOTHROW;
134
135 bool contains(const QRect &r, bool proper = false) const Q_DECL_NOTHROW;
136 bool contains(const QPoint &p, bool proper=false) const Q_DECL_NOTHROW;
137 inline bool contains(int x, int y) const Q_DECL_NOTHROW;
138 inline bool contains(int x, int y, bool proper) const Q_DECL_NOTHROW;
139 Q_REQUIRED_RESULT inline QRect united(const QRect &other) const Q_DECL_NOTHROW;
140 Q_REQUIRED_RESULT inline QRect intersected(const QRect &other) const Q_DECL_NOTHROW;
141 bool intersects(const QRect &r) const Q_DECL_NOTHROW;
142
143 Q_DECL_CONSTEXPR inline QRect marginsAdded(const QMargins &margins) const Q_DECL_NOTHROW;
144 Q_DECL_CONSTEXPR inline QRect marginsRemoved(const QMargins &margins) const Q_DECL_NOTHROW;
145 Q_DECL_RELAXED_CONSTEXPR inline QRect &operator+=(const QMargins &margins) Q_DECL_NOTHROW;
146 Q_DECL_RELAXED_CONSTEXPR inline QRect &operator-=(const QMargins &margins) Q_DECL_NOTHROW;
147
148#if QT_DEPRECATED_SINCE(5, 0)
149 Q_REQUIRED_RESULT QT_DEPRECATED QRect unite(const QRect &r) const Q_DECL_NOTHROW { return united(r); }
150 Q_REQUIRED_RESULT QT_DEPRECATED QRect intersect(const QRect &r) const Q_DECL_NOTHROW { return intersected(r); }
151#endif
152
153 friend Q_DECL_CONSTEXPR inline bool operator==(const QRect &, const QRect &) Q_DECL_NOTHROW;
154 friend Q_DECL_CONSTEXPR inline bool operator!=(const QRect &, const QRect &) Q_DECL_NOTHROW;
155
156#if defined(Q_OS_DARWIN) || defined(Q_QDOC)
157 Q_REQUIRED_RESULT CGRect toCGRect() const Q_DECL_NOTHROW;
158#endif
159
160private:
161 int x1;
162 int y1;
163 int x2;
164 int y2;
165};
166Q_DECLARE_TYPEINFO(QRect, Q_MOVABLE_TYPE);
167
168Q_DECL_CONSTEXPR inline bool operator==(const QRect &, const QRect &) Q_DECL_NOTHROW;
169Q_DECL_CONSTEXPR inline bool operator!=(const QRect &, const QRect &) Q_DECL_NOTHROW;
170
171
172/*****************************************************************************
173 QRect stream functions
174 *****************************************************************************/
175#ifndef QT_NO_DATASTREAM
176Q_CORE_EXPORT QDataStream &operator<<(QDataStream &, const QRect &);
177Q_CORE_EXPORT QDataStream &operator>>(QDataStream &, QRect &);
178#endif
179
180/*****************************************************************************
181 QRect inline member functions
182 *****************************************************************************/
183
184Q_DECL_CONSTEXPR inline QRect::QRect(int aleft, int atop, int awidth, int aheight) Q_DECL_NOTHROW
185 : x1(aleft), y1(atop), x2(aleft + awidth - 1), y2(atop + aheight - 1) {}
186
187Q_DECL_CONSTEXPR inline QRect::QRect(const QPoint &atopLeft, const QPoint &abottomRight) Q_DECL_NOTHROW
188 : x1(atopLeft.x()), y1(atopLeft.y()), x2(abottomRight.x()), y2(abottomRight.y()) {}
189
190Q_DECL_CONSTEXPR inline QRect::QRect(const QPoint &atopLeft, const QSize &asize) Q_DECL_NOTHROW
191 : x1(atopLeft.x()), y1(atopLeft.y()), x2(atopLeft.x()+asize.width() - 1), y2(atopLeft.y()+asize.height() - 1) {}
192
193Q_DECL_CONSTEXPR inline bool QRect::isNull() const Q_DECL_NOTHROW
194{ return x2 == x1 - 1 && y2 == y1 - 1; }
195
196Q_DECL_CONSTEXPR inline bool QRect::isEmpty() const Q_DECL_NOTHROW
197{ return x1 > x2 || y1 > y2; }
198
199Q_DECL_CONSTEXPR inline bool QRect::isValid() const Q_DECL_NOTHROW
200{ return x1 <= x2 && y1 <= y2; }
201
202Q_DECL_CONSTEXPR inline int QRect::left() const Q_DECL_NOTHROW
203{ return x1; }
204
205Q_DECL_CONSTEXPR inline int QRect::top() const Q_DECL_NOTHROW
206{ return y1; }
207
208Q_DECL_CONSTEXPR inline int QRect::right() const Q_DECL_NOTHROW
209{ return x2; }
210
211Q_DECL_CONSTEXPR inline int QRect::bottom() const Q_DECL_NOTHROW
212{ return y2; }
213
214Q_DECL_CONSTEXPR inline int QRect::x() const Q_DECL_NOTHROW
215{ return x1; }
216
217Q_DECL_CONSTEXPR inline int QRect::y() const Q_DECL_NOTHROW
218{ return y1; }
219
220Q_DECL_RELAXED_CONSTEXPR inline void QRect::setLeft(int pos) Q_DECL_NOTHROW
221{ x1 = pos; }
222
223Q_DECL_RELAXED_CONSTEXPR inline void QRect::setTop(int pos) Q_DECL_NOTHROW
224{ y1 = pos; }
225
226Q_DECL_RELAXED_CONSTEXPR inline void QRect::setRight(int pos) Q_DECL_NOTHROW
227{ x2 = pos; }
228
229Q_DECL_RELAXED_CONSTEXPR inline void QRect::setBottom(int pos) Q_DECL_NOTHROW
230{ y2 = pos; }
231
232Q_DECL_RELAXED_CONSTEXPR inline void QRect::setTopLeft(const QPoint &p) Q_DECL_NOTHROW
233{ x1 = p.x(); y1 = p.y(); }
234
235Q_DECL_RELAXED_CONSTEXPR inline void QRect::setBottomRight(const QPoint &p) Q_DECL_NOTHROW
236{ x2 = p.x(); y2 = p.y(); }
237
238Q_DECL_RELAXED_CONSTEXPR inline void QRect::setTopRight(const QPoint &p) Q_DECL_NOTHROW
239{ x2 = p.x(); y1 = p.y(); }
240
241Q_DECL_RELAXED_CONSTEXPR inline void QRect::setBottomLeft(const QPoint &p) Q_DECL_NOTHROW
242{ x1 = p.x(); y2 = p.y(); }
243
244Q_DECL_RELAXED_CONSTEXPR inline void QRect::setX(int ax) Q_DECL_NOTHROW
245{ x1 = ax; }
246
247Q_DECL_RELAXED_CONSTEXPR inline void QRect::setY(int ay) Q_DECL_NOTHROW
248{ y1 = ay; }
249
250Q_DECL_CONSTEXPR inline QPoint QRect::topLeft() const Q_DECL_NOTHROW
251{ return QPoint(x1, y1); }
252
253Q_DECL_CONSTEXPR inline QPoint QRect::bottomRight() const Q_DECL_NOTHROW
254{ return QPoint(x2, y2); }
255
256Q_DECL_CONSTEXPR inline QPoint QRect::topRight() const Q_DECL_NOTHROW
257{ return QPoint(x2, y1); }
258
259Q_DECL_CONSTEXPR inline QPoint QRect::bottomLeft() const Q_DECL_NOTHROW
260{ return QPoint(x1, y2); }
261
262Q_DECL_CONSTEXPR inline QPoint QRect::center() const Q_DECL_NOTHROW
263{ return QPoint(int((qint64(x1)+x2)/2), int((qint64(y1)+y2)/2)); } // cast avoids overflow on addition
264
265Q_DECL_CONSTEXPR inline int QRect::width() const Q_DECL_NOTHROW
266{ return x2 - x1 + 1; }
267
268Q_DECL_CONSTEXPR inline int QRect::height() const Q_DECL_NOTHROW
269{ return y2 - y1 + 1; }
270
271Q_DECL_CONSTEXPR inline QSize QRect::size() const Q_DECL_NOTHROW
272{ return QSize(width(), height()); }
273
274Q_DECL_RELAXED_CONSTEXPR inline void QRect::translate(int dx, int dy) Q_DECL_NOTHROW
275{
276 x1 += dx;
277 y1 += dy;
278 x2 += dx;
279 y2 += dy;
280}
281
282Q_DECL_RELAXED_CONSTEXPR inline void QRect::translate(const QPoint &p) Q_DECL_NOTHROW
283{
284 x1 += p.x();
285 y1 += p.y();
286 x2 += p.x();
287 y2 += p.y();
288}
289
290Q_DECL_CONSTEXPR inline QRect QRect::translated(int dx, int dy) const Q_DECL_NOTHROW
291{ return QRect(QPoint(x1 + dx, y1 + dy), QPoint(x2 + dx, y2 + dy)); }
292
293Q_DECL_CONSTEXPR inline QRect QRect::translated(const QPoint &p) const Q_DECL_NOTHROW
294{ return QRect(QPoint(x1 + p.x(), y1 + p.y()), QPoint(x2 + p.x(), y2 + p.y())); }
295
296Q_DECL_CONSTEXPR inline QRect QRect::transposed() const Q_DECL_NOTHROW
297{ return QRect(topLeft(), size().transposed()); }
298
299Q_DECL_RELAXED_CONSTEXPR inline void QRect::moveTo(int ax, int ay) Q_DECL_NOTHROW
300{
301 x2 += ax - x1;
302 y2 += ay - y1;
303 x1 = ax;
304 y1 = ay;
305}
306
307Q_DECL_RELAXED_CONSTEXPR inline void QRect::moveTo(const QPoint &p) Q_DECL_NOTHROW
308{
309 x2 += p.x() - x1;
310 y2 += p.y() - y1;
311 x1 = p.x();
312 y1 = p.y();
313}
314
315Q_DECL_RELAXED_CONSTEXPR inline void QRect::moveLeft(int pos) Q_DECL_NOTHROW
316{ x2 += (pos - x1); x1 = pos; }
317
318Q_DECL_RELAXED_CONSTEXPR inline void QRect::moveTop(int pos) Q_DECL_NOTHROW
319{ y2 += (pos - y1); y1 = pos; }
320
321Q_DECL_RELAXED_CONSTEXPR inline void QRect::moveRight(int pos) Q_DECL_NOTHROW
322{
323 x1 += (pos - x2);
324 x2 = pos;
325}
326
327Q_DECL_RELAXED_CONSTEXPR inline void QRect::moveBottom(int pos) Q_DECL_NOTHROW
328{
329 y1 += (pos - y2);
330 y2 = pos;
331}
332
333Q_DECL_RELAXED_CONSTEXPR inline void QRect::moveTopLeft(const QPoint &p) Q_DECL_NOTHROW
334{
335 moveLeft(p.x());
336 moveTop(p.y());
337}
338
339Q_DECL_RELAXED_CONSTEXPR inline void QRect::moveBottomRight(const QPoint &p) Q_DECL_NOTHROW
340{
341 moveRight(p.x());
342 moveBottom(p.y());
343}
344
345Q_DECL_RELAXED_CONSTEXPR inline void QRect::moveTopRight(const QPoint &p) Q_DECL_NOTHROW
346{
347 moveRight(p.x());
348 moveTop(p.y());
349}
350
351Q_DECL_RELAXED_CONSTEXPR inline void QRect::moveBottomLeft(const QPoint &p) Q_DECL_NOTHROW
352{
353 moveLeft(p.x());
354 moveBottom(p.y());
355}
356
357Q_DECL_RELAXED_CONSTEXPR inline void QRect::moveCenter(const QPoint &p) Q_DECL_NOTHROW
358{
359 int w = x2 - x1;
360 int h = y2 - y1;
361 x1 = p.x() - w/2;
362 y1 = p.y() - h/2;
363 x2 = x1 + w;
364 y2 = y1 + h;
365}
366
367Q_DECL_RELAXED_CONSTEXPR inline void QRect::getRect(int *ax, int *ay, int *aw, int *ah) const
368{
369 *ax = x1;
370 *ay = y1;
371 *aw = x2 - x1 + 1;
372 *ah = y2 - y1 + 1;
373}
374
375Q_DECL_RELAXED_CONSTEXPR inline void QRect::setRect(int ax, int ay, int aw, int ah) Q_DECL_NOTHROW
376{
377 x1 = ax;
378 y1 = ay;
379 x2 = (ax + aw - 1);
380 y2 = (ay + ah - 1);
381}
382
383Q_DECL_RELAXED_CONSTEXPR inline void QRect::getCoords(int *xp1, int *yp1, int *xp2, int *yp2) const
384{
385 *xp1 = x1;
386 *yp1 = y1;
387 *xp2 = x2;
388 *yp2 = y2;
389}
390
391Q_DECL_RELAXED_CONSTEXPR inline void QRect::setCoords(int xp1, int yp1, int xp2, int yp2) Q_DECL_NOTHROW
392{
393 x1 = xp1;
394 y1 = yp1;
395 x2 = xp2;
396 y2 = yp2;
397}
398
399Q_DECL_CONSTEXPR inline QRect QRect::adjusted(int xp1, int yp1, int xp2, int yp2) const Q_DECL_NOTHROW
400{ return QRect(QPoint(x1 + xp1, y1 + yp1), QPoint(x2 + xp2, y2 + yp2)); }
401
402Q_DECL_RELAXED_CONSTEXPR inline void QRect::adjust(int dx1, int dy1, int dx2, int dy2) Q_DECL_NOTHROW
403{
404 x1 += dx1;
405 y1 += dy1;
406 x2 += dx2;
407 y2 += dy2;
408}
409
410Q_DECL_RELAXED_CONSTEXPR inline void QRect::setWidth(int w) Q_DECL_NOTHROW
411{ x2 = (x1 + w - 1); }
412
413Q_DECL_RELAXED_CONSTEXPR inline void QRect::setHeight(int h) Q_DECL_NOTHROW
414{ y2 = (y1 + h - 1); }
415
416Q_DECL_RELAXED_CONSTEXPR inline void QRect::setSize(const QSize &s) Q_DECL_NOTHROW
417{
418 x2 = (s.width() + x1 - 1);
419 y2 = (s.height() + y1 - 1);
420}
421
422inline bool QRect::contains(int ax, int ay, bool aproper) const Q_DECL_NOTHROW
423{
424 return contains(QPoint(ax, ay), aproper);
425}
426
427inline bool QRect::contains(int ax, int ay) const Q_DECL_NOTHROW
428{
429 return contains(QPoint(ax, ay), false);
430}
431
432inline QRect& QRect::operator|=(const QRect &r) Q_DECL_NOTHROW
433{
434 *this = *this | r;
435 return *this;
436}
437
438inline QRect& QRect::operator&=(const QRect &r) Q_DECL_NOTHROW
439{
440 *this = *this & r;
441 return *this;
442}
443
444inline QRect QRect::intersected(const QRect &other) const Q_DECL_NOTHROW
445{
446 return *this & other;
447}
448
449inline QRect QRect::united(const QRect &r) const Q_DECL_NOTHROW
450{
451 return *this | r;
452}
453
454Q_DECL_CONSTEXPR inline bool operator==(const QRect &r1, const QRect &r2) Q_DECL_NOTHROW
455{
456 return r1.x1==r2.x1 && r1.x2==r2.x2 && r1.y1==r2.y1 && r1.y2==r2.y2;
457}
458
459Q_DECL_CONSTEXPR inline bool operator!=(const QRect &r1, const QRect &r2) Q_DECL_NOTHROW
460{
461 return r1.x1!=r2.x1 || r1.x2!=r2.x2 || r1.y1!=r2.y1 || r1.y2!=r2.y2;
462}
463
464Q_DECL_CONSTEXPR inline QRect operator+(const QRect &rectangle, const QMargins &margins) Q_DECL_NOTHROW
465{
466 return QRect(QPoint(rectangle.left() - margins.left(), rectangle.top() - margins.top()),
467 QPoint(rectangle.right() + margins.right(), rectangle.bottom() + margins.bottom()));
468}
469
470Q_DECL_CONSTEXPR inline QRect operator+(const QMargins &margins, const QRect &rectangle) Q_DECL_NOTHROW
471{
472 return QRect(QPoint(rectangle.left() - margins.left(), rectangle.top() - margins.top()),
473 QPoint(rectangle.right() + margins.right(), rectangle.bottom() + margins.bottom()));
474}
475
476Q_DECL_CONSTEXPR inline QRect operator-(const QRect &lhs, const QMargins &rhs) Q_DECL_NOTHROW
477{
478 return QRect(QPoint(lhs.left() + rhs.left(), lhs.top() + rhs.top()),
479 QPoint(lhs.right() - rhs.right(), lhs.bottom() - rhs.bottom()));
480}
481
482Q_DECL_CONSTEXPR inline QRect QRect::marginsAdded(const QMargins &margins) const Q_DECL_NOTHROW
483{
484 return QRect(QPoint(x1 - margins.left(), y1 - margins.top()),
485 QPoint(x2 + margins.right(), y2 + margins.bottom()));
486}
487
488Q_DECL_CONSTEXPR inline QRect QRect::marginsRemoved(const QMargins &margins) const Q_DECL_NOTHROW
489{
490 return QRect(QPoint(x1 + margins.left(), y1 + margins.top()),
491 QPoint(x2 - margins.right(), y2 - margins.bottom()));
492}
493
494Q_DECL_RELAXED_CONSTEXPR inline QRect &QRect::operator+=(const QMargins &margins) Q_DECL_NOTHROW
495{
496 *this = marginsAdded(margins);
497 return *this;
498}
499
500Q_DECL_RELAXED_CONSTEXPR inline QRect &QRect::operator-=(const QMargins &margins) Q_DECL_NOTHROW
501{
502 *this = marginsRemoved(margins);
503 return *this;
504}
505
506#ifndef QT_NO_DEBUG_STREAM
507Q_CORE_EXPORT QDebug operator<<(QDebug, const QRect &);
508#endif
509
510
511class Q_CORE_EXPORT QRectF
512{
513public:
514 Q_DECL_CONSTEXPR QRectF() Q_DECL_NOTHROW : xp(0.), yp(0.), w(0.), h(0.) {}
515 Q_DECL_CONSTEXPR QRectF(const QPointF &topleft, const QSizeF &size) Q_DECL_NOTHROW;
516 Q_DECL_CONSTEXPR QRectF(const QPointF &topleft, const QPointF &bottomRight) Q_DECL_NOTHROW;
517 Q_DECL_CONSTEXPR QRectF(qreal left, qreal top, qreal width, qreal height) Q_DECL_NOTHROW;
518 Q_DECL_CONSTEXPR QRectF(const QRect &rect) Q_DECL_NOTHROW;
519
520 Q_DECL_CONSTEXPR inline bool isNull() const Q_DECL_NOTHROW;
521 Q_DECL_CONSTEXPR inline bool isEmpty() const Q_DECL_NOTHROW;
522 Q_DECL_CONSTEXPR inline bool isValid() const Q_DECL_NOTHROW;
523 Q_REQUIRED_RESULT QRectF normalized() const Q_DECL_NOTHROW;
524
525 Q_DECL_CONSTEXPR inline qreal left() const Q_DECL_NOTHROW { return xp; }
526 Q_DECL_CONSTEXPR inline qreal top() const Q_DECL_NOTHROW { return yp; }
527 Q_DECL_CONSTEXPR inline qreal right() const Q_DECL_NOTHROW { return xp + w; }
528 Q_DECL_CONSTEXPR inline qreal bottom() const Q_DECL_NOTHROW { return yp + h; }
529
530 Q_DECL_CONSTEXPR inline qreal x() const Q_DECL_NOTHROW;
531 Q_DECL_CONSTEXPR inline qreal y() const Q_DECL_NOTHROW;
532 Q_DECL_RELAXED_CONSTEXPR inline void setLeft(qreal pos) Q_DECL_NOTHROW;
533 Q_DECL_RELAXED_CONSTEXPR inline void setTop(qreal pos) Q_DECL_NOTHROW;
534 Q_DECL_RELAXED_CONSTEXPR inline void setRight(qreal pos) Q_DECL_NOTHROW;
535 Q_DECL_RELAXED_CONSTEXPR inline void setBottom(qreal pos) Q_DECL_NOTHROW;
536 Q_DECL_RELAXED_CONSTEXPR inline void setX(qreal pos) Q_DECL_NOTHROW { setLeft(pos); }
537 Q_DECL_RELAXED_CONSTEXPR inline void setY(qreal pos) Q_DECL_NOTHROW { setTop(pos); }
538
539 Q_DECL_CONSTEXPR inline QPointF topLeft() const Q_DECL_NOTHROW { return QPointF(xp, yp); }
540 Q_DECL_CONSTEXPR inline QPointF bottomRight() const Q_DECL_NOTHROW { return QPointF(xp+w, yp+h); }
541 Q_DECL_CONSTEXPR inline QPointF topRight() const Q_DECL_NOTHROW { return QPointF(xp+w, yp); }
542 Q_DECL_CONSTEXPR inline QPointF bottomLeft() const Q_DECL_NOTHROW { return QPointF(xp, yp+h); }
543 Q_DECL_CONSTEXPR inline QPointF center() const Q_DECL_NOTHROW;
544
545 Q_DECL_RELAXED_CONSTEXPR inline void setTopLeft(const QPointF &p) Q_DECL_NOTHROW;
546 Q_DECL_RELAXED_CONSTEXPR inline void setBottomRight(const QPointF &p) Q_DECL_NOTHROW;
547 Q_DECL_RELAXED_CONSTEXPR inline void setTopRight(const QPointF &p) Q_DECL_NOTHROW;
548 Q_DECL_RELAXED_CONSTEXPR inline void setBottomLeft(const QPointF &p) Q_DECL_NOTHROW;
549
550 Q_DECL_RELAXED_CONSTEXPR inline void moveLeft(qreal pos) Q_DECL_NOTHROW;
551 Q_DECL_RELAXED_CONSTEXPR inline void moveTop(qreal pos) Q_DECL_NOTHROW;
552 Q_DECL_RELAXED_CONSTEXPR inline void moveRight(qreal pos) Q_DECL_NOTHROW;
553 Q_DECL_RELAXED_CONSTEXPR inline void moveBottom(qreal pos) Q_DECL_NOTHROW;
554 Q_DECL_RELAXED_CONSTEXPR inline void moveTopLeft(const QPointF &p) Q_DECL_NOTHROW;
555 Q_DECL_RELAXED_CONSTEXPR inline void moveBottomRight(const QPointF &p) Q_DECL_NOTHROW;
556 Q_DECL_RELAXED_CONSTEXPR inline void moveTopRight(const QPointF &p) Q_DECL_NOTHROW;
557 Q_DECL_RELAXED_CONSTEXPR inline void moveBottomLeft(const QPointF &p) Q_DECL_NOTHROW;
558 Q_DECL_RELAXED_CONSTEXPR inline void moveCenter(const QPointF &p) Q_DECL_NOTHROW;
559
560 Q_DECL_RELAXED_CONSTEXPR inline void translate(qreal dx, qreal dy) Q_DECL_NOTHROW;
561 Q_DECL_RELAXED_CONSTEXPR inline void translate(const QPointF &p) Q_DECL_NOTHROW;
562
563 Q_REQUIRED_RESULT Q_DECL_CONSTEXPR inline QRectF translated(qreal dx, qreal dy) const Q_DECL_NOTHROW;
564 Q_REQUIRED_RESULT Q_DECL_CONSTEXPR inline QRectF translated(const QPointF &p) const Q_DECL_NOTHROW;
565
566 Q_REQUIRED_RESULT Q_DECL_CONSTEXPR inline QRectF transposed() const Q_DECL_NOTHROW;
567
568 Q_DECL_RELAXED_CONSTEXPR inline void moveTo(qreal x, qreal y) Q_DECL_NOTHROW;
569 Q_DECL_RELAXED_CONSTEXPR inline void moveTo(const QPointF &p) Q_DECL_NOTHROW;
570
571 Q_DECL_RELAXED_CONSTEXPR inline void setRect(qreal x, qreal y, qreal w, qreal h) Q_DECL_NOTHROW;
572 Q_DECL_RELAXED_CONSTEXPR inline void getRect(qreal *x, qreal *y, qreal *w, qreal *h) const;
573
574 Q_DECL_RELAXED_CONSTEXPR inline void setCoords(qreal x1, qreal y1, qreal x2, qreal y2) Q_DECL_NOTHROW;
575 Q_DECL_RELAXED_CONSTEXPR inline void getCoords(qreal *x1, qreal *y1, qreal *x2, qreal *y2) const;
576
577 Q_DECL_RELAXED_CONSTEXPR inline void adjust(qreal x1, qreal y1, qreal x2, qreal y2) Q_DECL_NOTHROW;
578 Q_REQUIRED_RESULT Q_DECL_CONSTEXPR inline QRectF adjusted(qreal x1, qreal y1, qreal x2, qreal y2) const Q_DECL_NOTHROW;
579
580 Q_DECL_CONSTEXPR inline QSizeF size() const Q_DECL_NOTHROW;
581 Q_DECL_CONSTEXPR inline qreal width() const Q_DECL_NOTHROW;
582 Q_DECL_CONSTEXPR inline qreal height() const Q_DECL_NOTHROW;
583 Q_DECL_RELAXED_CONSTEXPR inline void setWidth(qreal w) Q_DECL_NOTHROW;
584 Q_DECL_RELAXED_CONSTEXPR inline void setHeight(qreal h) Q_DECL_NOTHROW;
585 Q_DECL_RELAXED_CONSTEXPR inline void setSize(const QSizeF &s) Q_DECL_NOTHROW;
586
587 QRectF operator|(const QRectF &r) const Q_DECL_NOTHROW;
588 QRectF operator&(const QRectF &r) const Q_DECL_NOTHROW;
589 inline QRectF& operator|=(const QRectF &r) Q_DECL_NOTHROW;
590 inline QRectF& operator&=(const QRectF &r) Q_DECL_NOTHROW;
591
592 bool contains(const QRectF &r) const Q_DECL_NOTHROW;
593 bool contains(const QPointF &p) const Q_DECL_NOTHROW;
594 inline bool contains(qreal x, qreal y) const Q_DECL_NOTHROW;
595 Q_REQUIRED_RESULT inline QRectF united(const QRectF &other) const Q_DECL_NOTHROW;
596 Q_REQUIRED_RESULT inline QRectF intersected(const QRectF &other) const Q_DECL_NOTHROW;
597 bool intersects(const QRectF &r) const Q_DECL_NOTHROW;
598
599 Q_DECL_CONSTEXPR inline QRectF marginsAdded(const QMarginsF &margins) const Q_DECL_NOTHROW;
600 Q_DECL_CONSTEXPR inline QRectF marginsRemoved(const QMarginsF &margins) const Q_DECL_NOTHROW;
601 Q_DECL_RELAXED_CONSTEXPR inline QRectF &operator+=(const QMarginsF &margins) Q_DECL_NOTHROW;
602 Q_DECL_RELAXED_CONSTEXPR inline QRectF &operator-=(const QMarginsF &margins) Q_DECL_NOTHROW;
603
604#if QT_DEPRECATED_SINCE(5, 0)
605 Q_REQUIRED_RESULT QT_DEPRECATED QRectF unite(const QRectF &r) const Q_DECL_NOTHROW { return united(r); }
606 Q_REQUIRED_RESULT QT_DEPRECATED QRectF intersect(const QRectF &r) const Q_DECL_NOTHROW { return intersected(r); }
607#endif
608
609 friend Q_DECL_CONSTEXPR inline bool operator==(const QRectF &, const QRectF &) Q_DECL_NOTHROW;
610 friend Q_DECL_CONSTEXPR inline bool operator!=(const QRectF &, const QRectF &) Q_DECL_NOTHROW;
611
612 Q_REQUIRED_RESULT Q_DECL_CONSTEXPR inline QRect toRect() const Q_DECL_NOTHROW;
613 Q_REQUIRED_RESULT QRect toAlignedRect() const Q_DECL_NOTHROW;
614
615#if defined(Q_OS_DARWIN) || defined(Q_QDOC)
616 Q_REQUIRED_RESULT static QRectF fromCGRect(CGRect rect) Q_DECL_NOTHROW;
617 Q_REQUIRED_RESULT CGRect toCGRect() const Q_DECL_NOTHROW;
618#endif
619
620private:
621 qreal xp;
622 qreal yp;
623 qreal w;
624 qreal h;
625};
626Q_DECLARE_TYPEINFO(QRectF, Q_MOVABLE_TYPE);
627
628Q_DECL_CONSTEXPR inline bool operator==(const QRectF &, const QRectF &) Q_DECL_NOTHROW;
629Q_DECL_CONSTEXPR inline bool operator!=(const QRectF &, const QRectF &) Q_DECL_NOTHROW;
630
631
632/*****************************************************************************
633 QRectF stream functions
634 *****************************************************************************/
635#ifndef QT_NO_DATASTREAM
636Q_CORE_EXPORT QDataStream &operator<<(QDataStream &, const QRectF &);
637Q_CORE_EXPORT QDataStream &operator>>(QDataStream &, QRectF &);
638#endif
639
640/*****************************************************************************
641 QRectF inline member functions
642 *****************************************************************************/
643
644Q_DECL_CONSTEXPR inline QRectF::QRectF(qreal aleft, qreal atop, qreal awidth, qreal aheight) Q_DECL_NOTHROW
645 : xp(aleft), yp(atop), w(awidth), h(aheight)
646{
647}
648
649Q_DECL_CONSTEXPR inline QRectF::QRectF(const QPointF &atopLeft, const QSizeF &asize) Q_DECL_NOTHROW
650 : xp(atopLeft.x()), yp(atopLeft.y()), w(asize.width()), h(asize.height())
651{
652}
653
654
655Q_DECL_CONSTEXPR inline QRectF::QRectF(const QPointF &atopLeft, const QPointF &abottomRight) Q_DECL_NOTHROW
656 : xp(atopLeft.x()), yp(atopLeft.y()), w(abottomRight.x() - atopLeft.x()), h(abottomRight.y() - atopLeft.y())
657{
658}
659
660Q_DECL_CONSTEXPR inline QRectF::QRectF(const QRect &r) Q_DECL_NOTHROW
661 : xp(r.x()), yp(r.y()), w(r.width()), h(r.height())
662{
663}
664
665QT_WARNING_PUSH
666QT_WARNING_DISABLE_CLANG("-Wfloat-equal")
667QT_WARNING_DISABLE_GCC("-Wfloat-equal")
668
669Q_DECL_CONSTEXPR inline bool QRectF::isNull() const Q_DECL_NOTHROW
670{ return w == 0. && h == 0.; }
671
672Q_DECL_CONSTEXPR inline bool QRectF::isEmpty() const Q_DECL_NOTHROW
673{ return w <= 0. || h <= 0.; }
674
675QT_WARNING_POP
676
677Q_DECL_CONSTEXPR inline bool QRectF::isValid() const Q_DECL_NOTHROW
678{ return w > 0. && h > 0.; }
679
680Q_DECL_CONSTEXPR inline qreal QRectF::x() const Q_DECL_NOTHROW
681{ return xp; }
682
683Q_DECL_CONSTEXPR inline qreal QRectF::y() const Q_DECL_NOTHROW
684{ return yp; }
685
686Q_DECL_RELAXED_CONSTEXPR inline void QRectF::setLeft(qreal pos) Q_DECL_NOTHROW
687{ qreal diff = pos - xp; xp += diff; w -= diff; }
688
689Q_DECL_RELAXED_CONSTEXPR inline void QRectF::setRight(qreal pos) Q_DECL_NOTHROW
690{ w = pos - xp; }
691
692Q_DECL_RELAXED_CONSTEXPR inline void QRectF::setTop(qreal pos) Q_DECL_NOTHROW
693{ qreal diff = pos - yp; yp += diff; h -= diff; }
694
695Q_DECL_RELAXED_CONSTEXPR inline void QRectF::setBottom(qreal pos) Q_DECL_NOTHROW
696{ h = pos - yp; }
697
698Q_DECL_RELAXED_CONSTEXPR inline void QRectF::setTopLeft(const QPointF &p) Q_DECL_NOTHROW
699{ setLeft(p.x()); setTop(p.y()); }
700
701Q_DECL_RELAXED_CONSTEXPR inline void QRectF::setTopRight(const QPointF &p) Q_DECL_NOTHROW
702{ setRight(p.x()); setTop(p.y()); }
703
704Q_DECL_RELAXED_CONSTEXPR inline void QRectF::setBottomLeft(const QPointF &p) Q_DECL_NOTHROW
705{ setLeft(p.x()); setBottom(p.y()); }
706
707Q_DECL_RELAXED_CONSTEXPR inline void QRectF::setBottomRight(const QPointF &p) Q_DECL_NOTHROW
708{ setRight(p.x()); setBottom(p.y()); }
709
710Q_DECL_CONSTEXPR inline QPointF QRectF::center() const Q_DECL_NOTHROW
711{ return QPointF(xp + w/2, yp + h/2); }
712
713Q_DECL_RELAXED_CONSTEXPR inline void QRectF::moveLeft(qreal pos) Q_DECL_NOTHROW
714{ xp = pos; }
715
716Q_DECL_RELAXED_CONSTEXPR inline void QRectF::moveTop(qreal pos) Q_DECL_NOTHROW
717{ yp = pos; }
718
719Q_DECL_RELAXED_CONSTEXPR inline void QRectF::moveRight(qreal pos) Q_DECL_NOTHROW
720{ xp = pos - w; }
721
722Q_DECL_RELAXED_CONSTEXPR inline void QRectF::moveBottom(qreal pos) Q_DECL_NOTHROW
723{ yp = pos - h; }
724
725Q_DECL_RELAXED_CONSTEXPR inline void QRectF::moveTopLeft(const QPointF &p) Q_DECL_NOTHROW
726{ moveLeft(p.x()); moveTop(p.y()); }
727
728Q_DECL_RELAXED_CONSTEXPR inline void QRectF::moveTopRight(const QPointF &p) Q_DECL_NOTHROW
729{ moveRight(p.x()); moveTop(p.y()); }
730
731Q_DECL_RELAXED_CONSTEXPR inline void QRectF::moveBottomLeft(const QPointF &p) Q_DECL_NOTHROW
732{ moveLeft(p.x()); moveBottom(p.y()); }
733
734Q_DECL_RELAXED_CONSTEXPR inline void QRectF::moveBottomRight(const QPointF &p) Q_DECL_NOTHROW
735{ moveRight(p.x()); moveBottom(p.y()); }
736
737Q_DECL_RELAXED_CONSTEXPR inline void QRectF::moveCenter(const QPointF &p) Q_DECL_NOTHROW
738{ xp = p.x() - w/2; yp = p.y() - h/2; }
739
740Q_DECL_CONSTEXPR inline qreal QRectF::width() const Q_DECL_NOTHROW
741{ return w; }
742
743Q_DECL_CONSTEXPR inline qreal QRectF::height() const Q_DECL_NOTHROW
744{ return h; }
745
746Q_DECL_CONSTEXPR inline QSizeF QRectF::size() const Q_DECL_NOTHROW
747{ return QSizeF(w, h); }
748
749Q_DECL_RELAXED_CONSTEXPR inline void QRectF::translate(qreal dx, qreal dy) Q_DECL_NOTHROW
750{
751 xp += dx;
752 yp += dy;
753}
754
755Q_DECL_RELAXED_CONSTEXPR inline void QRectF::translate(const QPointF &p) Q_DECL_NOTHROW
756{
757 xp += p.x();
758 yp += p.y();
759}
760
761Q_DECL_RELAXED_CONSTEXPR inline void QRectF::moveTo(qreal ax, qreal ay) Q_DECL_NOTHROW
762{
763 xp = ax;
764 yp = ay;
765}
766
767Q_DECL_RELAXED_CONSTEXPR inline void QRectF::moveTo(const QPointF &p) Q_DECL_NOTHROW
768{
769 xp = p.x();
770 yp = p.y();
771}
772
773Q_DECL_CONSTEXPR inline QRectF QRectF::translated(qreal dx, qreal dy) const Q_DECL_NOTHROW
774{ return QRectF(xp + dx, yp + dy, w, h); }
775
776Q_DECL_CONSTEXPR inline QRectF QRectF::translated(const QPointF &p) const Q_DECL_NOTHROW
777{ return QRectF(xp + p.x(), yp + p.y(), w, h); }
778
779Q_DECL_CONSTEXPR inline QRectF QRectF::transposed() const Q_DECL_NOTHROW
780{ return QRectF(topLeft(), size().transposed()); }
781
782Q_DECL_RELAXED_CONSTEXPR inline void QRectF::getRect(qreal *ax, qreal *ay, qreal *aaw, qreal *aah) const
783{
784 *ax = this->xp;
785 *ay = this->yp;
786 *aaw = this->w;
787 *aah = this->h;
788}
789
790Q_DECL_RELAXED_CONSTEXPR inline void QRectF::setRect(qreal ax, qreal ay, qreal aaw, qreal aah) Q_DECL_NOTHROW
791{
792 this->xp = ax;
793 this->yp = ay;
794 this->w = aaw;
795 this->h = aah;
796}
797
798Q_DECL_RELAXED_CONSTEXPR inline void QRectF::getCoords(qreal *xp1, qreal *yp1, qreal *xp2, qreal *yp2) const
799{
800 *xp1 = xp;
801 *yp1 = yp;
802 *xp2 = xp + w;
803 *yp2 = yp + h;
804}
805
806Q_DECL_RELAXED_CONSTEXPR inline void QRectF::setCoords(qreal xp1, qreal yp1, qreal xp2, qreal yp2) Q_DECL_NOTHROW
807{
808 xp = xp1;
809 yp = yp1;
810 w = xp2 - xp1;
811 h = yp2 - yp1;
812}
813
814Q_DECL_RELAXED_CONSTEXPR inline void QRectF::adjust(qreal xp1, qreal yp1, qreal xp2, qreal yp2) Q_DECL_NOTHROW
815{ xp += xp1; yp += yp1; w += xp2 - xp1; h += yp2 - yp1; }
816
817Q_DECL_CONSTEXPR inline QRectF QRectF::adjusted(qreal xp1, qreal yp1, qreal xp2, qreal yp2) const Q_DECL_NOTHROW
818{ return QRectF(xp + xp1, yp + yp1, w + xp2 - xp1, h + yp2 - yp1); }
819
820Q_DECL_RELAXED_CONSTEXPR inline void QRectF::setWidth(qreal aw) Q_DECL_NOTHROW
821{ this->w = aw; }
822
823Q_DECL_RELAXED_CONSTEXPR inline void QRectF::setHeight(qreal ah) Q_DECL_NOTHROW
824{ this->h = ah; }
825
826Q_DECL_RELAXED_CONSTEXPR inline void QRectF::setSize(const QSizeF &s) Q_DECL_NOTHROW
827{
828 w = s.width();
829 h = s.height();
830}
831
832inline bool QRectF::contains(qreal ax, qreal ay) const Q_DECL_NOTHROW
833{
834 return contains(QPointF(ax, ay));
835}
836
837inline QRectF& QRectF::operator|=(const QRectF &r) Q_DECL_NOTHROW
838{
839 *this = *this | r;
840 return *this;
841}
842
843inline QRectF& QRectF::operator&=(const QRectF &r) Q_DECL_NOTHROW
844{
845 *this = *this & r;
846 return *this;
847}
848
849inline QRectF QRectF::intersected(const QRectF &r) const Q_DECL_NOTHROW
850{
851 return *this & r;
852}
853
854inline QRectF QRectF::united(const QRectF &r) const Q_DECL_NOTHROW
855{
856 return *this | r;
857}
858
859Q_DECL_CONSTEXPR inline bool operator==(const QRectF &r1, const QRectF &r2) Q_DECL_NOTHROW
860{
861 return qFuzzyCompare(r1.xp, r2.xp) && qFuzzyCompare(r1.yp, r2.yp)
862 && qFuzzyCompare(r1.w, r2.w) && qFuzzyCompare(r1.h, r2.h);
863}
864
865Q_DECL_CONSTEXPR inline bool operator!=(const QRectF &r1, const QRectF &r2) Q_DECL_NOTHROW
866{
867 return !qFuzzyCompare(r1.xp, r2.xp) || !qFuzzyCompare(r1.yp, r2.yp)
868 || !qFuzzyCompare(r1.w, r2.w) || !qFuzzyCompare(r1.h, r2.h);
869}
870
871Q_DECL_CONSTEXPR inline QRect QRectF::toRect() const Q_DECL_NOTHROW
872{
873 return QRect(QPoint(qRound(xp), qRound(yp)), QPoint(qRound(xp + w) - 1, qRound(yp + h) - 1));
874}
875
876Q_DECL_CONSTEXPR inline QRectF operator+(const QRectF &lhs, const QMarginsF &rhs) Q_DECL_NOTHROW
877{
878 return QRectF(QPointF(lhs.left() - rhs.left(), lhs.top() - rhs.top()),
879 QSizeF(lhs.width() + rhs.left() + rhs.right(), lhs.height() + rhs.top() + rhs.bottom()));
880}
881
882Q_DECL_CONSTEXPR inline QRectF operator+(const QMarginsF &lhs, const QRectF &rhs) Q_DECL_NOTHROW
883{
884 return QRectF(QPointF(rhs.left() - lhs.left(), rhs.top() - lhs.top()),
885 QSizeF(rhs.width() + lhs.left() + lhs.right(), rhs.height() + lhs.top() + lhs.bottom()));
886}
887
888Q_DECL_CONSTEXPR inline QRectF operator-(const QRectF &lhs, const QMarginsF &rhs) Q_DECL_NOTHROW
889{
890 return QRectF(QPointF(lhs.left() + rhs.left(), lhs.top() + rhs.top()),
891 QSizeF(lhs.width() - rhs.left() - rhs.right(), lhs.height() - rhs.top() - rhs.bottom()));
892}
893
894Q_DECL_CONSTEXPR inline QRectF QRectF::marginsAdded(const QMarginsF &margins) const Q_DECL_NOTHROW
895{
896 return QRectF(QPointF(xp - margins.left(), yp - margins.top()),
897 QSizeF(w + margins.left() + margins.right(), h + margins.top() + margins.bottom()));
898}
899
900Q_DECL_CONSTEXPR inline QRectF QRectF::marginsRemoved(const QMarginsF &margins) const Q_DECL_NOTHROW
901{
902 return QRectF(QPointF(xp + margins.left(), yp + margins.top()),
903 QSizeF(w - margins.left() - margins.right(), h - margins.top() - margins.bottom()));
904}
905
906Q_DECL_RELAXED_CONSTEXPR inline QRectF &QRectF::operator+=(const QMarginsF &margins) Q_DECL_NOTHROW
907{
908 *this = marginsAdded(margins);
909 return *this;
910}
911
912Q_DECL_RELAXED_CONSTEXPR inline QRectF &QRectF::operator-=(const QMarginsF &margins) Q_DECL_NOTHROW
913{
914 *this = marginsRemoved(margins);
915 return *this;
916}
917
918#ifndef QT_NO_DEBUG_STREAM
919Q_CORE_EXPORT QDebug operator<<(QDebug, const QRectF &);
920#endif
921
922QT_END_NAMESPACE
923
924#endif // QRECT_H
925