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