Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-10-14 09:03:13

0001 // Copyright (C) 2022 The Qt Company Ltd.
0002 // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
0003 
0004 #ifndef QRECT_H
0005 #define QRECT_H
0006 
0007 #include <QtCore/qhashfunctions.h>
0008 #include <QtCore/qmargins.h>
0009 #include <QtCore/qsize.h>
0010 #include <QtCore/qpoint.h>
0011 
0012 #ifdef topLeft
0013 #error qrect.h must be included before any header file that defines topLeft
0014 #endif
0015 
0016 #if defined(Q_OS_DARWIN) || defined(Q_QDOC)
0017 struct CGRect;
0018 #endif
0019 #if defined(Q_OS_WASM) || defined(Q_QDOC)
0020 namespace emscripten {
0021 class val;
0022 }
0023 #endif
0024 
0025 QT_BEGIN_NAMESPACE
0026 
0027 class QRectF;
0028 
0029 class Q_CORE_EXPORT QRect
0030 {
0031 public:
0032     constexpr QRect() noexcept : x1(0), y1(0), x2(-1), y2(-1) {}
0033     constexpr QRect(const QPoint &topleft, const QPoint &bottomright) noexcept;
0034     constexpr QRect(const QPoint &topleft, const QSize &size) noexcept;
0035     constexpr QRect(int left, int top, int width, int height) noexcept;
0036 
0037     constexpr inline bool isNull() const noexcept;
0038     constexpr inline bool isEmpty() const noexcept;
0039     constexpr inline bool isValid() const noexcept;
0040 
0041     constexpr inline int left() const noexcept;
0042     constexpr inline int top() const noexcept;
0043     constexpr inline int right() const noexcept;
0044     constexpr inline int bottom() const noexcept;
0045     [[nodiscard]] QRect normalized() const noexcept;
0046 
0047     constexpr inline int x() const noexcept;
0048     constexpr inline int y() const noexcept;
0049     constexpr inline void setLeft(int pos) noexcept;
0050     constexpr inline void setTop(int pos) noexcept;
0051     constexpr inline void setRight(int pos) noexcept;
0052     constexpr inline void setBottom(int pos) noexcept;
0053     constexpr inline void setX(int x) noexcept;
0054     constexpr inline void setY(int y) noexcept;
0055 
0056     constexpr inline void setTopLeft(const QPoint &p) noexcept;
0057     constexpr inline void setBottomRight(const QPoint &p) noexcept;
0058     constexpr inline void setTopRight(const QPoint &p) noexcept;
0059     constexpr inline void setBottomLeft(const QPoint &p) noexcept;
0060 
0061     constexpr inline QPoint topLeft() const noexcept;
0062     constexpr inline QPoint bottomRight() const noexcept;
0063     constexpr inline QPoint topRight() const noexcept;
0064     constexpr inline QPoint bottomLeft() const noexcept;
0065     constexpr inline QPoint center() const noexcept;
0066 
0067     constexpr inline void moveLeft(int pos) noexcept;
0068     constexpr inline void moveTop(int pos) noexcept;
0069     constexpr inline void moveRight(int pos) noexcept;
0070     constexpr inline void moveBottom(int pos) noexcept;
0071     constexpr inline void moveTopLeft(const QPoint &p) noexcept;
0072     constexpr inline void moveBottomRight(const QPoint &p) noexcept;
0073     constexpr inline void moveTopRight(const QPoint &p) noexcept;
0074     constexpr inline void moveBottomLeft(const QPoint &p) noexcept;
0075     constexpr inline void moveCenter(const QPoint &p) noexcept;
0076 
0077     constexpr inline void translate(int dx, int dy) noexcept;
0078     constexpr inline void translate(const QPoint &p) noexcept;
0079     [[nodiscard]] constexpr inline QRect translated(int dx, int dy) const noexcept;
0080     [[nodiscard]] constexpr inline QRect translated(const QPoint &p) const noexcept;
0081     [[nodiscard]] constexpr inline QRect transposed() const noexcept;
0082 
0083     constexpr inline void moveTo(int x, int t) noexcept;
0084     constexpr inline void moveTo(const QPoint &p) noexcept;
0085 
0086     constexpr inline void setRect(int x, int y, int w, int h) noexcept;
0087     constexpr inline void getRect(int *x, int *y, int *w, int *h) const;
0088 
0089     constexpr inline void setCoords(int x1, int y1, int x2, int y2) noexcept;
0090     constexpr inline void getCoords(int *x1, int *y1, int *x2, int *y2) const;
0091 
0092     constexpr inline void adjust(int x1, int y1, int x2, int y2) noexcept;
0093     [[nodiscard]] constexpr inline QRect adjusted(int x1, int y1, int x2, int y2) const noexcept;
0094 
0095     constexpr inline QSize size() const noexcept;
0096     constexpr inline int width() const noexcept;
0097     constexpr inline int height() const noexcept;
0098     constexpr inline void setWidth(int w) noexcept;
0099     constexpr inline void setHeight(int h) noexcept;
0100     constexpr inline void setSize(const QSize &s) noexcept;
0101 
0102     QRect operator|(const QRect &r) const noexcept;
0103     QRect operator&(const QRect &r) const noexcept;
0104     inline QRect &operator|=(const QRect &r) noexcept;
0105     inline QRect &operator&=(const QRect &r) noexcept;
0106 
0107     bool contains(const QRect &r, bool proper = false) const noexcept;
0108     bool contains(const QPoint &p, bool proper = false) const noexcept;
0109     inline bool contains(int x, int y) const noexcept;
0110     inline bool contains(int x, int y, bool proper) const noexcept;
0111     [[nodiscard]] inline QRect united(const QRect &other) const noexcept;
0112     [[nodiscard]] inline QRect intersected(const QRect &other) const noexcept;
0113     bool intersects(const QRect &r) const noexcept;
0114 
0115     constexpr inline QRect marginsAdded(const QMargins &margins) const noexcept;
0116     constexpr inline QRect marginsRemoved(const QMargins &margins) const noexcept;
0117     constexpr inline QRect &operator+=(const QMargins &margins) noexcept;
0118     constexpr inline QRect &operator-=(const QMargins &margins) noexcept;
0119 
0120     [[nodiscard]] static constexpr inline QRect span(const QPoint &p1, const QPoint &p2) noexcept;
0121 
0122 private:
0123     friend constexpr bool comparesEqual(const QRect &r1, const QRect &r2) noexcept
0124     { return r1.x1==r2.x1 && r1.x2==r2.x2 && r1.y1==r2.y1 && r1.y2==r2.y2; }
0125     Q_DECLARE_EQUALITY_COMPARABLE_LITERAL_TYPE(QRect)
0126     friend constexpr inline size_t qHash(const QRect &, size_t) noexcept;
0127 
0128 public:
0129 #if defined(Q_OS_DARWIN) || defined(Q_QDOC)
0130     [[nodiscard]] CGRect toCGRect() const noexcept;
0131 #endif
0132     [[nodiscard]] constexpr inline QRectF toRectF() const noexcept;
0133 
0134 private:
0135     int x1;
0136     int y1;
0137     int x2;
0138     int y2;
0139 };
0140 Q_DECLARE_TYPEINFO(QRect, Q_RELOCATABLE_TYPE);
0141 
0142 
0143 /*****************************************************************************
0144   QRect stream functions
0145  *****************************************************************************/
0146 #ifndef QT_NO_DATASTREAM
0147 Q_CORE_EXPORT QDataStream &operator<<(QDataStream &, const QRect &);
0148 Q_CORE_EXPORT QDataStream &operator>>(QDataStream &, QRect &);
0149 #endif
0150 
0151 /*****************************************************************************
0152   QRect inline member functions
0153  *****************************************************************************/
0154 
0155 constexpr inline QRect::QRect(int aleft, int atop, int awidth, int aheight) noexcept
0156     : x1(aleft), y1(atop), x2(aleft + awidth - 1), y2(atop + aheight - 1) {}
0157 
0158 constexpr inline QRect::QRect(const QPoint &atopLeft, const QPoint &abottomRight) noexcept
0159     : x1(atopLeft.x()), y1(atopLeft.y()), x2(abottomRight.x()), y2(abottomRight.y()) {}
0160 
0161 constexpr inline QRect::QRect(const QPoint &atopLeft, const QSize &asize) noexcept
0162     : x1(atopLeft.x()), y1(atopLeft.y()), x2(atopLeft.x()+asize.width() - 1), y2(atopLeft.y()+asize.height() - 1) {}
0163 
0164 constexpr inline bool QRect::isNull() const noexcept
0165 { return x2 == x1 - 1 && y2 == y1 - 1; }
0166 
0167 constexpr inline bool QRect::isEmpty() const noexcept
0168 { return x1 > x2 || y1 > y2; }
0169 
0170 constexpr inline bool QRect::isValid() const noexcept
0171 { return x1 <= x2 && y1 <= y2; }
0172 
0173 constexpr inline int QRect::left() const noexcept
0174 { return x1; }
0175 
0176 constexpr inline int QRect::top() const noexcept
0177 { return y1; }
0178 
0179 constexpr inline int QRect::right() const noexcept
0180 { return x2; }
0181 
0182 constexpr inline int QRect::bottom() const noexcept
0183 { return y2; }
0184 
0185 constexpr inline int QRect::x() const noexcept
0186 { return x1; }
0187 
0188 constexpr inline int QRect::y() const noexcept
0189 { return y1; }
0190 
0191 constexpr inline void QRect::setLeft(int pos) noexcept
0192 { x1 = pos; }
0193 
0194 constexpr inline void QRect::setTop(int pos) noexcept
0195 { y1 = pos; }
0196 
0197 constexpr inline void QRect::setRight(int pos) noexcept
0198 { x2 = pos; }
0199 
0200 constexpr inline void QRect::setBottom(int pos) noexcept
0201 { y2 = pos; }
0202 
0203 constexpr inline void QRect::setTopLeft(const QPoint &p) noexcept
0204 { x1 = p.x(); y1 = p.y(); }
0205 
0206 constexpr inline void QRect::setBottomRight(const QPoint &p) noexcept
0207 { x2 = p.x(); y2 = p.y(); }
0208 
0209 constexpr inline void QRect::setTopRight(const QPoint &p) noexcept
0210 { x2 = p.x(); y1 = p.y(); }
0211 
0212 constexpr inline void QRect::setBottomLeft(const QPoint &p) noexcept
0213 { x1 = p.x(); y2 = p.y(); }
0214 
0215 constexpr inline void QRect::setX(int ax) noexcept
0216 { x1 = ax; }
0217 
0218 constexpr inline void QRect::setY(int ay) noexcept
0219 { y1 = ay; }
0220 
0221 constexpr inline QPoint QRect::topLeft() const noexcept
0222 { return QPoint(x1, y1); }
0223 
0224 constexpr inline QPoint QRect::bottomRight() const noexcept
0225 { return QPoint(x2, y2); }
0226 
0227 constexpr inline QPoint QRect::topRight() const noexcept
0228 { return QPoint(x2, y1); }
0229 
0230 constexpr inline QPoint QRect::bottomLeft() const noexcept
0231 { return QPoint(x1, y2); }
0232 
0233 constexpr inline QPoint QRect::center() const noexcept
0234 { return QPoint(int((qint64(x1)+x2)/2), int((qint64(y1)+y2)/2)); } // cast avoids overflow on addition
0235 
0236 constexpr inline int QRect::width() const noexcept
0237 { return  x2 - x1 + 1; }
0238 
0239 constexpr inline int QRect::height() const noexcept
0240 { return  y2 - y1 + 1; }
0241 
0242 constexpr inline QSize QRect::size() const noexcept
0243 { return QSize(width(), height()); }
0244 
0245 constexpr inline void QRect::translate(int dx, int dy) noexcept
0246 {
0247     x1 += dx;
0248     y1 += dy;
0249     x2 += dx;
0250     y2 += dy;
0251 }
0252 
0253 constexpr inline void QRect::translate(const QPoint &p) noexcept
0254 {
0255     x1 += p.x();
0256     y1 += p.y();
0257     x2 += p.x();
0258     y2 += p.y();
0259 }
0260 
0261 constexpr inline QRect QRect::translated(int dx, int dy) const noexcept
0262 { return QRect(QPoint(x1 + dx, y1 + dy), QPoint(x2 + dx, y2 + dy)); }
0263 
0264 constexpr inline QRect QRect::translated(const QPoint &p) const noexcept
0265 { return QRect(QPoint(x1 + p.x(), y1 + p.y()), QPoint(x2 + p.x(), y2 + p.y())); }
0266 
0267 constexpr inline QRect QRect::transposed() const noexcept
0268 { return QRect(topLeft(), size().transposed()); }
0269 
0270 constexpr inline void QRect::moveTo(int ax, int ay) noexcept
0271 {
0272     x2 += ax - x1;
0273     y2 += ay - y1;
0274     x1 = ax;
0275     y1 = ay;
0276 }
0277 
0278 constexpr inline void QRect::moveTo(const QPoint &p) noexcept
0279 {
0280     x2 += p.x() - x1;
0281     y2 += p.y() - y1;
0282     x1 = p.x();
0283     y1 = p.y();
0284 }
0285 
0286 constexpr inline void QRect::moveLeft(int pos) noexcept
0287 { x2 += (pos - x1); x1 = pos; }
0288 
0289 constexpr inline void QRect::moveTop(int pos) noexcept
0290 { y2 += (pos - y1); y1 = pos; }
0291 
0292 constexpr inline void QRect::moveRight(int pos) noexcept
0293 {
0294     x1 += (pos - x2);
0295     x2 = pos;
0296 }
0297 
0298 constexpr inline void QRect::moveBottom(int pos) noexcept
0299 {
0300     y1 += (pos - y2);
0301     y2 = pos;
0302 }
0303 
0304 constexpr inline void QRect::moveTopLeft(const QPoint &p) noexcept
0305 {
0306     moveLeft(p.x());
0307     moveTop(p.y());
0308 }
0309 
0310 constexpr inline void QRect::moveBottomRight(const QPoint &p) noexcept
0311 {
0312     moveRight(p.x());
0313     moveBottom(p.y());
0314 }
0315 
0316 constexpr inline void QRect::moveTopRight(const QPoint &p) noexcept
0317 {
0318     moveRight(p.x());
0319     moveTop(p.y());
0320 }
0321 
0322 constexpr inline void QRect::moveBottomLeft(const QPoint &p) noexcept
0323 {
0324     moveLeft(p.x());
0325     moveBottom(p.y());
0326 }
0327 
0328 constexpr inline void QRect::moveCenter(const QPoint &p) noexcept
0329 {
0330     int w = x2 - x1;
0331     int h = y2 - y1;
0332     x1 = p.x() - w/2;
0333     y1 = p.y() - h/2;
0334     x2 = x1 + w;
0335     y2 = y1 + h;
0336 }
0337 
0338 constexpr inline void QRect::getRect(int *ax, int *ay, int *aw, int *ah) const
0339 {
0340     *ax = x1;
0341     *ay = y1;
0342     *aw = x2 - x1 + 1;
0343     *ah = y2 - y1 + 1;
0344 }
0345 
0346 constexpr inline void QRect::setRect(int ax, int ay, int aw, int ah) noexcept
0347 {
0348     x1 = ax;
0349     y1 = ay;
0350     x2 = (ax + aw - 1);
0351     y2 = (ay + ah - 1);
0352 }
0353 
0354 constexpr inline void QRect::getCoords(int *xp1, int *yp1, int *xp2, int *yp2) const
0355 {
0356     *xp1 = x1;
0357     *yp1 = y1;
0358     *xp2 = x2;
0359     *yp2 = y2;
0360 }
0361 
0362 constexpr inline void QRect::setCoords(int xp1, int yp1, int xp2, int yp2) noexcept
0363 {
0364     x1 = xp1;
0365     y1 = yp1;
0366     x2 = xp2;
0367     y2 = yp2;
0368 }
0369 
0370 constexpr inline QRect QRect::adjusted(int xp1, int yp1, int xp2, int yp2) const noexcept
0371 { return QRect(QPoint(x1 + xp1, y1 + yp1), QPoint(x2 + xp2, y2 + yp2)); }
0372 
0373 constexpr inline void QRect::adjust(int dx1, int dy1, int dx2, int dy2) noexcept
0374 {
0375     x1 += dx1;
0376     y1 += dy1;
0377     x2 += dx2;
0378     y2 += dy2;
0379 }
0380 
0381 constexpr inline void QRect::setWidth(int w) noexcept
0382 { x2 = (x1 + w - 1); }
0383 
0384 constexpr inline void QRect::setHeight(int h) noexcept
0385 { y2 = (y1 + h - 1); }
0386 
0387 constexpr inline void QRect::setSize(const QSize &s) noexcept
0388 {
0389     x2 = (s.width()  + x1 - 1);
0390     y2 = (s.height() + y1 - 1);
0391 }
0392 
0393 inline bool QRect::contains(int ax, int ay, bool aproper) const noexcept
0394 {
0395     return contains(QPoint(ax, ay), aproper);
0396 }
0397 
0398 inline bool QRect::contains(int ax, int ay) const noexcept
0399 {
0400     return contains(QPoint(ax, ay), false);
0401 }
0402 
0403 inline QRect &QRect::operator|=(const QRect &r) noexcept
0404 {
0405     *this = *this | r;
0406     return *this;
0407 }
0408 
0409 inline QRect &QRect::operator&=(const QRect &r) noexcept
0410 {
0411     *this = *this & r;
0412     return *this;
0413 }
0414 
0415 inline QRect QRect::intersected(const QRect &other) const noexcept
0416 {
0417     return *this & other;
0418 }
0419 
0420 inline QRect QRect::united(const QRect &r) const noexcept
0421 {
0422     return *this | r;
0423 }
0424 
0425 constexpr inline size_t qHash(const QRect &r, size_t seed = 0) noexcept
0426 {
0427     return qHashMulti(seed, r.x1, r.x2, r.y1, r.y2);
0428 }
0429 
0430 constexpr inline QRect operator+(const QRect &rectangle, const QMargins &margins) noexcept
0431 {
0432     return QRect(QPoint(rectangle.left() - margins.left(), rectangle.top() - margins.top()),
0433                  QPoint(rectangle.right() + margins.right(), rectangle.bottom() + margins.bottom()));
0434 }
0435 
0436 constexpr inline QRect operator+(const QMargins &margins, const QRect &rectangle) noexcept
0437 {
0438     return QRect(QPoint(rectangle.left() - margins.left(), rectangle.top() - margins.top()),
0439                  QPoint(rectangle.right() + margins.right(), rectangle.bottom() + margins.bottom()));
0440 }
0441 
0442 constexpr inline QRect operator-(const QRect &lhs, const QMargins &rhs) noexcept
0443 {
0444     return QRect(QPoint(lhs.left() + rhs.left(), lhs.top() + rhs.top()),
0445                  QPoint(lhs.right() - rhs.right(), lhs.bottom() - rhs.bottom()));
0446 }
0447 
0448 constexpr inline QRect QRect::marginsAdded(const QMargins &margins) const noexcept
0449 {
0450     return QRect(QPoint(x1 - margins.left(), y1 - margins.top()),
0451                  QPoint(x2 + margins.right(), y2 + margins.bottom()));
0452 }
0453 
0454 constexpr inline QRect QRect::marginsRemoved(const QMargins &margins) const noexcept
0455 {
0456     return QRect(QPoint(x1 + margins.left(), y1 + margins.top()),
0457                  QPoint(x2 - margins.right(), y2 - margins.bottom()));
0458 }
0459 
0460 constexpr inline QRect &QRect::operator+=(const QMargins &margins) noexcept
0461 {
0462     *this = marginsAdded(margins);
0463     return *this;
0464 }
0465 
0466 constexpr inline QRect &QRect::operator-=(const QMargins &margins) noexcept
0467 {
0468     *this = marginsRemoved(margins);
0469     return *this;
0470 }
0471 
0472 constexpr QRect QRect::span(const QPoint &p1, const QPoint &p2) noexcept
0473 {
0474     return QRect(QPoint(qMin(p1.x(), p2.x()), qMin(p1.y(), p2.y())),
0475                  QPoint(qMax(p1.x(), p2.x()), qMax(p1.y(), p2.y())));
0476 }
0477 
0478 #ifndef QT_NO_DEBUG_STREAM
0479 Q_CORE_EXPORT QDebug operator<<(QDebug, const QRect &);
0480 #endif
0481 
0482 
0483 class Q_CORE_EXPORT QRectF
0484 {
0485 public:
0486     constexpr QRectF() noexcept : xp(0.), yp(0.), w(0.), h(0.) {}
0487     constexpr QRectF(const QPointF &topleft, const QSizeF &size) noexcept;
0488     constexpr QRectF(const QPointF &topleft, const QPointF &bottomRight) noexcept;
0489     constexpr QRectF(qreal left, qreal top, qreal width, qreal height) noexcept;
0490     constexpr QRectF(const QRect &rect) noexcept;
0491 
0492     constexpr inline bool isNull() const noexcept;
0493     constexpr inline bool isEmpty() const noexcept;
0494     constexpr inline bool isValid() const noexcept;
0495     [[nodiscard]] QRectF normalized() const noexcept;
0496 
0497     constexpr inline qreal left() const noexcept { return xp; }
0498     constexpr inline qreal top() const noexcept { return yp; }
0499     constexpr inline qreal right() const noexcept { return xp + w; }
0500     constexpr inline qreal bottom() const noexcept { return yp + h; }
0501 
0502     constexpr inline qreal x() const noexcept;
0503     constexpr inline qreal y() const noexcept;
0504     constexpr inline void setLeft(qreal pos) noexcept;
0505     constexpr inline void setTop(qreal pos) noexcept;
0506     constexpr inline void setRight(qreal pos) noexcept;
0507     constexpr inline void setBottom(qreal pos) noexcept;
0508     constexpr inline void setX(qreal pos) noexcept { setLeft(pos); }
0509     constexpr inline void setY(qreal pos) noexcept { setTop(pos); }
0510 
0511     constexpr inline QPointF topLeft() const noexcept { return QPointF(xp, yp); }
0512     constexpr inline QPointF bottomRight() const noexcept { return QPointF(xp+w, yp+h); }
0513     constexpr inline QPointF topRight() const noexcept { return QPointF(xp+w, yp); }
0514     constexpr inline QPointF bottomLeft() const noexcept { return QPointF(xp, yp+h); }
0515     constexpr inline QPointF center() const noexcept;
0516 
0517     constexpr inline void setTopLeft(const QPointF &p) noexcept;
0518     constexpr inline void setBottomRight(const QPointF &p) noexcept;
0519     constexpr inline void setTopRight(const QPointF &p) noexcept;
0520     constexpr inline void setBottomLeft(const QPointF &p) noexcept;
0521 
0522     constexpr inline void moveLeft(qreal pos) noexcept;
0523     constexpr inline void moveTop(qreal pos) noexcept;
0524     constexpr inline void moveRight(qreal pos) noexcept;
0525     constexpr inline void moveBottom(qreal pos) noexcept;
0526     constexpr inline void moveTopLeft(const QPointF &p) noexcept;
0527     constexpr inline void moveBottomRight(const QPointF &p) noexcept;
0528     constexpr inline void moveTopRight(const QPointF &p) noexcept;
0529     constexpr inline void moveBottomLeft(const QPointF &p) noexcept;
0530     constexpr inline void moveCenter(const QPointF &p) noexcept;
0531 
0532     constexpr inline void translate(qreal dx, qreal dy) noexcept;
0533     constexpr inline void translate(const QPointF &p) noexcept;
0534 
0535     [[nodiscard]] constexpr inline QRectF translated(qreal dx, qreal dy) const noexcept;
0536     [[nodiscard]] constexpr inline QRectF translated(const QPointF &p) const noexcept;
0537 
0538     [[nodiscard]] constexpr inline QRectF transposed() const noexcept;
0539 
0540     constexpr inline void moveTo(qreal x, qreal y) noexcept;
0541     constexpr inline void moveTo(const QPointF &p) noexcept;
0542 
0543     constexpr inline void setRect(qreal x, qreal y, qreal w, qreal h) noexcept;
0544     constexpr inline void getRect(qreal *x, qreal *y, qreal *w, qreal *h) const;
0545 
0546     constexpr inline void setCoords(qreal x1, qreal y1, qreal x2, qreal y2) noexcept;
0547     constexpr inline void getCoords(qreal *x1, qreal *y1, qreal *x2, qreal *y2) const;
0548 
0549     constexpr inline void adjust(qreal x1, qreal y1, qreal x2, qreal y2) noexcept;
0550     [[nodiscard]] constexpr inline QRectF adjusted(qreal x1, qreal y1, qreal x2, qreal y2) const noexcept;
0551 
0552     constexpr inline QSizeF size() const noexcept;
0553     constexpr inline qreal width() const noexcept;
0554     constexpr inline qreal height() const noexcept;
0555     constexpr inline void setWidth(qreal w) noexcept;
0556     constexpr inline void setHeight(qreal h) noexcept;
0557     constexpr inline void setSize(const QSizeF &s) noexcept;
0558 
0559     QRectF operator|(const QRectF &r) const noexcept;
0560     QRectF operator&(const QRectF &r) const noexcept;
0561     inline QRectF &operator|=(const QRectF &r) noexcept;
0562     inline QRectF &operator&=(const QRectF &r) noexcept;
0563 
0564     bool contains(const QRectF &r) const noexcept;
0565     bool contains(const QPointF &p) const noexcept;
0566     inline bool contains(qreal x, qreal y) const noexcept;
0567     [[nodiscard]] inline QRectF united(const QRectF &other) const noexcept;
0568     [[nodiscard]] inline QRectF intersected(const QRectF &other) const noexcept;
0569     bool intersects(const QRectF &r) const noexcept;
0570 
0571     constexpr inline QRectF marginsAdded(const QMarginsF &margins) const noexcept;
0572     constexpr inline QRectF marginsRemoved(const QMarginsF &margins) const noexcept;
0573     constexpr inline QRectF &operator+=(const QMarginsF &margins) noexcept;
0574     constexpr inline QRectF &operator-=(const QMarginsF &margins) noexcept;
0575 
0576 private:
0577     friend constexpr bool comparesEqual(const QRectF &r1, const QRectF &r2) noexcept
0578     {
0579         return r1.topLeft() == r2.topLeft()
0580             && r1.size() == r2.size();
0581     }
0582     Q_DECLARE_EQUALITY_COMPARABLE_LITERAL_TYPE(QRectF)
0583 
0584     friend constexpr bool comparesEqual(const QRectF &r1, const QRect &r2) noexcept
0585     { return r1.topLeft() == r2.topLeft() && r1.size() == r2.size(); }
0586     Q_DECLARE_EQUALITY_COMPARABLE_LITERAL_TYPE(QRectF, QRect)
0587 
0588     friend constexpr bool qFuzzyCompare(const QRectF &lhs, const QRectF &rhs) noexcept
0589     {
0590         return qFuzzyCompare(lhs.topLeft(), rhs.topLeft())
0591                 && qFuzzyCompare(lhs.bottomRight(), rhs.bottomRight());
0592     }
0593 
0594     friend constexpr bool qFuzzyIsNull(const QRectF &rect) noexcept
0595     {
0596         return qFuzzyIsNull(rect.w) && qFuzzyIsNull(rect.h);
0597     }
0598 
0599 public:
0600     [[nodiscard]] constexpr inline QRect toRect() const noexcept;
0601     [[nodiscard]] QRect toAlignedRect() const noexcept;
0602 
0603 #if defined(Q_OS_DARWIN) || defined(Q_QDOC)
0604     [[nodiscard]] static QRectF fromCGRect(CGRect rect) noexcept;
0605     [[nodiscard]] CGRect toCGRect() const noexcept;
0606 #endif
0607 
0608 #if defined(Q_OS_WASM) || defined(Q_QDOC)
0609     [[nodiscard]] static QRectF fromDOMRect(emscripten::val domRect);
0610     [[nodiscard]] emscripten::val toDOMRect() const;
0611 #endif
0612 
0613 private:
0614     qreal xp;
0615     qreal yp;
0616     qreal w;
0617     qreal h;
0618 };
0619 Q_DECLARE_TYPEINFO(QRectF, Q_RELOCATABLE_TYPE);
0620 
0621 
0622 /*****************************************************************************
0623   QRectF stream functions
0624  *****************************************************************************/
0625 #ifndef QT_NO_DATASTREAM
0626 Q_CORE_EXPORT QDataStream &operator<<(QDataStream &, const QRectF &);
0627 Q_CORE_EXPORT QDataStream &operator>>(QDataStream &, QRectF &);
0628 #endif
0629 
0630 /*****************************************************************************
0631   QRectF inline member functions
0632  *****************************************************************************/
0633 
0634 constexpr inline QRectF::QRectF(qreal aleft, qreal atop, qreal awidth, qreal aheight) noexcept
0635     : xp(aleft), yp(atop), w(awidth), h(aheight)
0636 {
0637 }
0638 
0639 constexpr inline QRectF::QRectF(const QPointF &atopLeft, const QSizeF &asize) noexcept
0640     : xp(atopLeft.x()), yp(atopLeft.y()), w(asize.width()), h(asize.height())
0641 {
0642 }
0643 
0644 
0645 constexpr inline QRectF::QRectF(const QPointF &atopLeft, const QPointF &abottomRight) noexcept
0646     : xp(atopLeft.x()), yp(atopLeft.y()), w(abottomRight.x() - atopLeft.x()), h(abottomRight.y() - atopLeft.y())
0647 {
0648 }
0649 
0650 constexpr inline QRectF::QRectF(const QRect &r) noexcept
0651     : xp(r.x()), yp(r.y()), w(r.width()), h(r.height())
0652 {
0653 }
0654 
0655 QT_WARNING_PUSH
0656 QT_WARNING_DISABLE_FLOAT_COMPARE
0657 
0658 constexpr inline bool QRectF::isNull() const noexcept
0659 { return w == 0. && h == 0.; }
0660 
0661 constexpr inline bool QRectF::isEmpty() const noexcept
0662 { return w <= 0. || h <= 0.; }
0663 
0664 QT_WARNING_POP
0665 
0666 constexpr inline bool QRectF::isValid() const noexcept
0667 { return w > 0. && h > 0.; }
0668 
0669 constexpr inline qreal QRectF::x() const noexcept
0670 { return xp; }
0671 
0672 constexpr inline qreal QRectF::y() const noexcept
0673 { return yp; }
0674 
0675 constexpr inline void QRectF::setLeft(qreal pos) noexcept
0676 { qreal diff = pos - xp; xp += diff; w -= diff; }
0677 
0678 constexpr inline void QRectF::setRight(qreal pos) noexcept
0679 { w = pos - xp; }
0680 
0681 constexpr inline void QRectF::setTop(qreal pos) noexcept
0682 { qreal diff = pos - yp; yp += diff; h -= diff; }
0683 
0684 constexpr inline void QRectF::setBottom(qreal pos) noexcept
0685 { h = pos - yp; }
0686 
0687 constexpr inline void QRectF::setTopLeft(const QPointF &p) noexcept
0688 { setLeft(p.x()); setTop(p.y()); }
0689 
0690 constexpr inline void QRectF::setTopRight(const QPointF &p) noexcept
0691 { setRight(p.x()); setTop(p.y()); }
0692 
0693 constexpr inline void QRectF::setBottomLeft(const QPointF &p) noexcept
0694 { setLeft(p.x()); setBottom(p.y()); }
0695 
0696 constexpr inline void QRectF::setBottomRight(const QPointF &p) noexcept
0697 { setRight(p.x()); setBottom(p.y()); }
0698 
0699 constexpr inline QPointF QRectF::center() const noexcept
0700 { return QPointF(xp + w/2, yp + h/2); }
0701 
0702 constexpr inline void QRectF::moveLeft(qreal pos) noexcept
0703 { xp = pos; }
0704 
0705 constexpr inline void QRectF::moveTop(qreal pos) noexcept
0706 { yp = pos; }
0707 
0708 constexpr inline void QRectF::moveRight(qreal pos) noexcept
0709 { xp = pos - w; }
0710 
0711 constexpr inline void QRectF::moveBottom(qreal pos) noexcept
0712 { yp = pos - h; }
0713 
0714 constexpr inline void QRectF::moveTopLeft(const QPointF &p) noexcept
0715 { moveLeft(p.x()); moveTop(p.y()); }
0716 
0717 constexpr inline void QRectF::moveTopRight(const QPointF &p) noexcept
0718 { moveRight(p.x()); moveTop(p.y()); }
0719 
0720 constexpr inline void QRectF::moveBottomLeft(const QPointF &p) noexcept
0721 { moveLeft(p.x()); moveBottom(p.y()); }
0722 
0723 constexpr inline void QRectF::moveBottomRight(const QPointF &p) noexcept
0724 { moveRight(p.x()); moveBottom(p.y()); }
0725 
0726 constexpr inline void QRectF::moveCenter(const QPointF &p) noexcept
0727 { xp = p.x() - w/2; yp = p.y() - h/2; }
0728 
0729 constexpr inline qreal QRectF::width() const noexcept
0730 { return w; }
0731 
0732 constexpr inline qreal QRectF::height() const noexcept
0733 { return h; }
0734 
0735 constexpr inline QSizeF QRectF::size() const noexcept
0736 { return QSizeF(w, h); }
0737 
0738 constexpr inline void QRectF::translate(qreal dx, qreal dy) noexcept
0739 {
0740     xp += dx;
0741     yp += dy;
0742 }
0743 
0744 constexpr inline void QRectF::translate(const QPointF &p) noexcept
0745 {
0746     xp += p.x();
0747     yp += p.y();
0748 }
0749 
0750 constexpr inline void QRectF::moveTo(qreal ax, qreal ay) noexcept
0751 {
0752     xp = ax;
0753     yp = ay;
0754 }
0755 
0756 constexpr inline void QRectF::moveTo(const QPointF &p) noexcept
0757 {
0758     xp = p.x();
0759     yp = p.y();
0760 }
0761 
0762 constexpr inline QRectF QRectF::translated(qreal dx, qreal dy) const noexcept
0763 {
0764     return QRectF(xp + dx, yp + dy, w, h);
0765 }
0766 
0767 constexpr inline QRectF QRectF::translated(const QPointF &p) const noexcept
0768 { return QRectF(xp + p.x(), yp + p.y(), w, h); }
0769 
0770 constexpr inline QRectF QRectF::transposed() const noexcept
0771 { return QRectF(topLeft(), size().transposed()); }
0772 
0773 constexpr inline void QRectF::getRect(qreal *ax, qreal *ay, qreal *aaw, qreal *aah) const
0774 {
0775     *ax = this->xp;
0776     *ay = this->yp;
0777     *aaw = this->w;
0778     *aah = this->h;
0779 }
0780 
0781 constexpr inline void QRectF::setRect(qreal ax, qreal ay, qreal aaw, qreal aah) noexcept
0782 {
0783     this->xp = ax;
0784     this->yp = ay;
0785     this->w = aaw;
0786     this->h = aah;
0787 }
0788 
0789 constexpr inline void QRectF::getCoords(qreal *xp1, qreal *yp1, qreal *xp2, qreal *yp2) const
0790 {
0791     *xp1 = xp;
0792     *yp1 = yp;
0793     *xp2 = xp + w;
0794     *yp2 = yp + h;
0795 }
0796 
0797 constexpr inline void QRectF::setCoords(qreal xp1, qreal yp1, qreal xp2, qreal yp2) noexcept
0798 {
0799     xp = xp1;
0800     yp = yp1;
0801     w = xp2 - xp1;
0802     h = yp2 - yp1;
0803 }
0804 
0805 constexpr inline void QRectF::adjust(qreal xp1, qreal yp1, qreal xp2, qreal yp2) noexcept
0806 {
0807     xp += xp1;
0808     yp += yp1;
0809     w += xp2 - xp1;
0810     h += yp2 - yp1;
0811 }
0812 
0813 constexpr inline QRectF QRectF::adjusted(qreal xp1, qreal yp1, qreal xp2, qreal yp2) const noexcept
0814 {
0815     return QRectF(xp + xp1, yp + yp1, w + xp2 - xp1, h + yp2 - yp1);
0816 }
0817 
0818 constexpr inline void QRectF::setWidth(qreal aw) noexcept
0819 { this->w = aw; }
0820 
0821 constexpr inline void QRectF::setHeight(qreal ah) noexcept
0822 { this->h = ah; }
0823 
0824 constexpr inline void QRectF::setSize(const QSizeF &s) noexcept
0825 {
0826     w = s.width();
0827     h = s.height();
0828 }
0829 
0830 inline bool QRectF::contains(qreal ax, qreal ay) const noexcept
0831 {
0832     return contains(QPointF(ax, ay));
0833 }
0834 
0835 inline QRectF &QRectF::operator|=(const QRectF &r) noexcept
0836 {
0837     *this = *this | r;
0838     return *this;
0839 }
0840 
0841 inline QRectF &QRectF::operator&=(const QRectF &r) noexcept
0842 {
0843     *this = *this & r;
0844     return *this;
0845 }
0846 
0847 inline QRectF QRectF::intersected(const QRectF &r) const noexcept
0848 {
0849     return *this & r;
0850 }
0851 
0852 inline QRectF QRectF::united(const QRectF &r) const noexcept
0853 {
0854     return *this | r;
0855 }
0856 
0857 constexpr QRectF QRect::toRectF() const noexcept { return *this; }
0858 
0859 constexpr inline QRect QRectF::toRect() const noexcept
0860 {
0861     // This rounding is designed to minimize the maximum possible difference
0862     // in topLeft(), bottomRight(), and size() after rounding.
0863     // All dimensions are at most off by 0.75, and topLeft by at most 0.5.
0864     const int nxp = qRound(xp);
0865     const int nyp = qRound(yp);
0866     const int nw = qRound(w + (xp - nxp) / 2);
0867     const int nh = qRound(h + (yp - nyp) / 2);
0868     return QRect(nxp, nyp, nw, nh);
0869 }
0870 
0871 constexpr inline QRectF operator+(const QRectF &lhs, const QMarginsF &rhs) noexcept
0872 {
0873     return QRectF(QPointF(lhs.left() - rhs.left(), lhs.top() - rhs.top()),
0874                   QSizeF(lhs.width() + rhs.left() + rhs.right(), lhs.height() + rhs.top() + rhs.bottom()));
0875 }
0876 
0877 constexpr inline QRectF operator+(const QMarginsF &lhs, const QRectF &rhs) noexcept
0878 {
0879     return QRectF(QPointF(rhs.left() - lhs.left(), rhs.top() - lhs.top()),
0880                   QSizeF(rhs.width() + lhs.left() + lhs.right(), rhs.height() + lhs.top() + lhs.bottom()));
0881 }
0882 
0883 constexpr inline QRectF operator-(const QRectF &lhs, const QMarginsF &rhs) noexcept
0884 {
0885     return QRectF(QPointF(lhs.left() + rhs.left(), lhs.top() + rhs.top()),
0886                   QSizeF(lhs.width() - rhs.left() - rhs.right(), lhs.height() - rhs.top() - rhs.bottom()));
0887 }
0888 
0889 constexpr inline QRectF QRectF::marginsAdded(const QMarginsF &margins) const noexcept
0890 {
0891     return QRectF(QPointF(xp - margins.left(), yp - margins.top()),
0892                   QSizeF(w + margins.left() + margins.right(), h + margins.top() + margins.bottom()));
0893 }
0894 
0895 constexpr inline QRectF QRectF::marginsRemoved(const QMarginsF &margins) const noexcept
0896 {
0897     return QRectF(QPointF(xp + margins.left(), yp + margins.top()),
0898                   QSizeF(w - margins.left() - margins.right(), h - margins.top() - margins.bottom()));
0899 }
0900 
0901 constexpr inline QRectF &QRectF::operator+=(const QMarginsF &margins) noexcept
0902 {
0903     *this = marginsAdded(margins);
0904     return *this;
0905 }
0906 
0907 constexpr inline QRectF &QRectF::operator-=(const QMarginsF &margins) noexcept
0908 {
0909     *this = marginsRemoved(margins);
0910     return *this;
0911 }
0912 
0913 #ifndef QT_NO_DEBUG_STREAM
0914 Q_CORE_EXPORT QDebug operator<<(QDebug, const QRectF &);
0915 #endif
0916 
0917 QT_END_NAMESPACE
0918 
0919 #endif // QRECT_H