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