Qt 4.8
qrect.h
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/legal
5 **
6 ** This file is part of the QtCore module of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia. For licensing terms and
14 ** conditions see http://qt.digia.com/licensing. For further information
15 ** use the contact form at http://qt.digia.com/contact-us.
16 **
17 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24 **
25 ** In addition, as a special exception, Digia gives you certain additional
26 ** rights. These rights are described in the Digia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28 **
29 ** GNU General Public License Usage
30 ** Alternatively, this file may be used under the terms of the GNU
31 ** General Public License version 3.0 as published by the Free Software
32 ** Foundation and appearing in the file LICENSE.GPL included in the
33 ** packaging of this file. Please review the following information to
34 ** ensure the GNU General Public License version 3.0 requirements will be
35 ** met: http://www.gnu.org/copyleft/gpl.html.
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41 
42 #ifndef QRECT_H
43 #define QRECT_H
44 
45 #include <QtCore/qsize.h>
46 #include <QtCore/qpoint.h>
47 
48 #ifdef topLeft
49 #error qrect.h must be included before any header file that defines topLeft
50 #endif
51 
53 
55 
56 QT_MODULE(Core)
57 
59 {
60 public:
61  QRect() { x1 = y1 = 0; x2 = y2 = -1; }
62  QRect(const QPoint &topleft, const QPoint &bottomright);
63  QRect(const QPoint &topleft, const QSize &size);
64  QRect(int left, int top, int width, int height);
65 
66  bool isNull() const;
67  bool isEmpty() const;
68  bool isValid() const;
69 
70  int left() const;
71  int top() const;
72  int right() const;
73  int bottom() const;
74  QRect normalized() const;
75 
76 #ifdef QT3_SUPPORT
77  QT3_SUPPORT int &rLeft() { return x1; }
78  QT3_SUPPORT int &rTop() { return y1; }
79  QT3_SUPPORT int &rRight() { return x2; }
80  QT3_SUPPORT int &rBottom() { return y2; }
81 
82  QT3_SUPPORT QRect normalize() const { return normalized(); }
83 #endif
84 
85  int x() const;
86  int y() const;
87  void setLeft(int pos);
88  void setTop(int pos);
89  void setRight(int pos);
90  void setBottom(int pos);
91  void setX(int x);
92  void setY(int y);
93 
94  void setTopLeft(const QPoint &p);
95  void setBottomRight(const QPoint &p);
96  void setTopRight(const QPoint &p);
97  void setBottomLeft(const QPoint &p);
98 
99  QPoint topLeft() const;
100  QPoint bottomRight() const;
101  QPoint topRight() const;
102  QPoint bottomLeft() const;
103  QPoint center() const;
104 
105  void moveLeft(int pos);
106  void moveTop(int pos);
107  void moveRight(int pos);
108  void moveBottom(int pos);
109  void moveTopLeft(const QPoint &p);
110  void moveBottomRight(const QPoint &p);
111  void moveTopRight(const QPoint &p);
112  void moveBottomLeft(const QPoint &p);
113  void moveCenter(const QPoint &p);
114 
115  inline void translate(int dx, int dy);
116  inline void translate(const QPoint &p);
117  inline QRect translated(int dx, int dy) const;
118  inline QRect translated(const QPoint &p) const;
119 
120  void moveTo(int x, int t);
121  void moveTo(const QPoint &p);
122 
123 #ifdef QT3_SUPPORT
124  QT3_SUPPORT void moveBy(int dx, int dy) { translate(dx, dy); }
125  QT3_SUPPORT void moveBy(const QPoint &p) { translate(p); }
126 #endif
127 
128  void setRect(int x, int y, int w, int h);
129  inline void getRect(int *x, int *y, int *w, int *h) const;
130 
131  void setCoords(int x1, int y1, int x2, int y2);
132 #ifdef QT3_SUPPORT
133  QT3_SUPPORT void addCoords(int x1, int y1, int x2, int y2);
134 #endif
135  inline void getCoords(int *x1, int *y1, int *x2, int *y2) const;
136 
137  inline void adjust(int x1, int y1, int x2, int y2);
138  inline QRect adjusted(int x1, int y1, int x2, int y2) const;
139 
140  QSize size() const;
141  int width() const;
142  int height() const;
143  void setWidth(int w);
144  void setHeight(int h);
145  void setSize(const QSize &s);
146 
147  QRect operator|(const QRect &r) const;
148  QRect operator&(const QRect &r) const;
149  QRect& operator|=(const QRect &r);
150  QRect& operator&=(const QRect &r);
151 
152  bool contains(const QPoint &p, bool proper=false) const;
153  bool contains(int x, int y) const; // inline methods, _don't_ merge these
154  bool contains(int x, int y, bool proper) const;
155  bool contains(const QRect &r, bool proper = false) const;
156  QRect unite(const QRect &r) const; // ### Qt 5: make QT4_SUPPORT
157  QRect united(const QRect &other) const;
158  QRect intersect(const QRect &r) const; // ### Qt 5: make QT4_SUPPORT
159  QRect intersected(const QRect &other) const;
160  bool intersects(const QRect &r) const;
161 
162  friend Q_CORE_EXPORT_INLINE bool operator==(const QRect &, const QRect &);
163  friend Q_CORE_EXPORT_INLINE bool operator!=(const QRect &, const QRect &);
164 
165 #ifdef QT3_SUPPORT
166  inline QT3_SUPPORT void rect(int *x, int *y, int *w, int *h) const { getRect(x, y, w, h); }
167  inline QT3_SUPPORT void coords(int *ax1, int *ay1, int *ax2, int *ay2) const
168  { getCoords(ax1, ay1, ax2, ay2); }
169 #endif
170 
171 private:
172 #if defined(Q_WS_X11)
173  friend void qt_setCoords(QRect *r, int xp1, int yp1, int xp2, int yp2);
174 #endif
175  // ### Qt 5; remove the ifdef and just have the same order on all platforms.
176 #if defined(Q_OS_MAC)
177  int y1;
178  int x1;
179  int y2;
180  int x2;
181 #else
182  int x1;
183  int y1;
184  int x2;
185  int y2;
186 #endif
187 
188 };
190 
191 Q_CORE_EXPORT_INLINE bool operator==(const QRect &, const QRect &);
192 Q_CORE_EXPORT_INLINE bool operator!=(const QRect &, const QRect &);
193 
194 
195 /*****************************************************************************
196  QRect stream functions
197  *****************************************************************************/
198 #ifndef QT_NO_DATASTREAM
201 #endif
202 
203 /*****************************************************************************
204  QRect inline member functions
205  *****************************************************************************/
206 
207 inline QRect::QRect(int aleft, int atop, int awidth, int aheight)
208 {
209  x1 = aleft;
210  y1 = atop;
211  x2 = (aleft + awidth - 1);
212  y2 = (atop + aheight - 1);
213 }
214 
215 inline QRect::QRect(const QPoint &atopLeft, const QPoint &abottomRight)
216 {
217  x1 = atopLeft.x();
218  y1 = atopLeft.y();
219  x2 = abottomRight.x();
220  y2 = abottomRight.y();
221 }
222 
223 inline QRect::QRect(const QPoint &atopLeft, const QSize &asize)
224 {
225  x1 = atopLeft.x();
226  y1 = atopLeft.y();
227  x2 = (x1+asize.width() - 1);
228  y2 = (y1+asize.height() - 1);
229 }
230 
231 inline bool QRect::isNull() const
232 { return x2 == x1 - 1 && y2 == y1 - 1; }
233 
234 inline bool QRect::isEmpty() const
235 { return x1 > x2 || y1 > y2; }
236 
237 inline bool QRect::isValid() const
238 { return x1 <= x2 && y1 <= y2; }
239 
240 inline int QRect::left() const
241 { return x1; }
242 
243 inline int QRect::top() const
244 { return y1; }
245 
246 inline int QRect::right() const
247 { return x2; }
248 
249 inline int QRect::bottom() const
250 { return y2; }
251 
252 inline int QRect::x() const
253 { return x1; }
254 
255 inline int QRect::y() const
256 { return y1; }
257 
258 inline void QRect::setLeft(int pos)
259 { x1 = pos; }
260 
261 inline void QRect::setTop(int pos)
262 { y1 = pos; }
263 
264 inline void QRect::setRight(int pos)
265 { x2 = pos; }
266 
267 inline void QRect::setBottom(int pos)
268 { y2 = pos; }
269 
270 inline void QRect::setTopLeft(const QPoint &p)
271 { x1 = p.x(); y1 = p.y(); }
272 
273 inline void QRect::setBottomRight(const QPoint &p)
274 { x2 = p.x(); y2 = p.y(); }
275 
276 inline void QRect::setTopRight(const QPoint &p)
277 { x2 = p.x(); y1 = p.y(); }
278 
279 inline void QRect::setBottomLeft(const QPoint &p)
280 { x1 = p.x(); y2 = p.y(); }
281 
282 inline void QRect::setX(int ax)
283 { x1 = ax; }
284 
285 inline void QRect::setY(int ay)
286 { y1 = ay; }
287 
288 inline QPoint QRect::topLeft() const
289 { return QPoint(x1, y1); }
290 
292 { return QPoint(x2, y2); }
293 
294 inline QPoint QRect::topRight() const
295 { return QPoint(x2, y1); }
296 
297 inline QPoint QRect::bottomLeft() const
298 { return QPoint(x1, y2); }
299 
300 inline QPoint QRect::center() const
301 { return QPoint((x1+x2)/2, (y1+y2)/2); }
302 
303 inline int QRect::width() const
304 { return x2 - x1 + 1; }
305 
306 inline int QRect::height() const
307 { return y2 - y1 + 1; }
308 
309 inline QSize QRect::size() const
310 { return QSize(width(), height()); }
311 
312 inline void QRect::translate(int dx, int dy)
313 {
314  x1 += dx;
315  y1 += dy;
316  x2 += dx;
317  y2 += dy;
318 }
319 
320 inline void QRect::translate(const QPoint &p)
321 {
322  x1 += p.x();
323  y1 += p.y();
324  x2 += p.x();
325  y2 += p.y();
326 }
327 
328 inline QRect QRect::translated(int dx, int dy) const
329 { return QRect(QPoint(x1 + dx, y1 + dy), QPoint(x2 + dx, y2 + dy)); }
330 
331 inline QRect QRect::translated(const QPoint &p) const
332 { return QRect(QPoint(x1 + p.x(), y1 + p.y()), QPoint(x2 + p.x(), y2 + p.y())); }
333 
334 inline void QRect::moveTo(int ax, int ay)
335 {
336  x2 += ax - x1;
337  y2 += ay - y1;
338  x1 = ax;
339  y1 = ay;
340 }
341 
342 inline void QRect::moveTo(const QPoint &p)
343 {
344  x2 += p.x() - x1;
345  y2 += p.y() - y1;
346  x1 = p.x();
347  y1 = p.y();
348 }
349 
350 inline void QRect::moveLeft(int pos)
351 { x2 += (pos - x1); x1 = pos; }
352 
353 inline void QRect::moveTop(int pos)
354 { y2 += (pos - y1); y1 = pos; }
355 
356 inline void QRect::moveRight(int pos)
357 {
358  x1 += (pos - x2);
359  x2 = pos;
360 }
361 
362 inline void QRect::moveBottom(int pos)
363 {
364  y1 += (pos - y2);
365  y2 = pos;
366 }
367 
368 inline void QRect::moveTopLeft(const QPoint &p)
369 {
370  moveLeft(p.x());
371  moveTop(p.y());
372 }
373 
374 inline void QRect::moveBottomRight(const QPoint &p)
375 {
376  moveRight(p.x());
377  moveBottom(p.y());
378 }
379 
380 inline void QRect::moveTopRight(const QPoint &p)
381 {
382  moveRight(p.x());
383  moveTop(p.y());
384 }
385 
386 inline void QRect::moveBottomLeft(const QPoint &p)
387 {
388  moveLeft(p.x());
389  moveBottom(p.y());
390 }
391 
392 inline void QRect::getRect(int *ax, int *ay, int *aw, int *ah) const
393 {
394  *ax = x1;
395  *ay = y1;
396  *aw = x2 - x1 + 1;
397  *ah = y2 - y1 + 1;
398 }
399 
400 inline void QRect::setRect(int ax, int ay, int aw, int ah)
401 {
402  x1 = ax;
403  y1 = ay;
404  x2 = (ax + aw - 1);
405  y2 = (ay + ah - 1);
406 }
407 
408 inline void QRect::getCoords(int *xp1, int *yp1, int *xp2, int *yp2) const
409 {
410  *xp1 = x1;
411  *yp1 = y1;
412  *xp2 = x2;
413  *yp2 = y2;
414 }
415 
416 inline void QRect::setCoords(int xp1, int yp1, int xp2, int yp2)
417 {
418  x1 = xp1;
419  y1 = yp1;
420  x2 = xp2;
421  y2 = yp2;
422 }
423 
424 #ifdef QT3_SUPPORT
425 inline void QRect::addCoords(int dx1, int dy1, int dx2, int dy2)
426 {
427  adjust(dx1, dy1, dx2, dy2);
428 }
429 #endif
430 
431 inline QRect QRect::adjusted(int xp1, int yp1, int xp2, int yp2) const
432 { return QRect(QPoint(x1 + xp1, y1 + yp1), QPoint(x2 + xp2, y2 + yp2)); }
433 
434 inline void QRect::adjust(int dx1, int dy1, int dx2, int dy2)
435 {
436  x1 += dx1;
437  y1 += dy1;
438  x2 += dx2;
439  y2 += dy2;
440 }
441 
442 inline void QRect::setWidth(int w)
443 { x2 = (x1 + w - 1); }
444 
445 inline void QRect::setHeight(int h)
446 { y2 = (y1 + h - 1); }
447 
448 inline void QRect::setSize(const QSize &s)
449 {
450  x2 = (s.width() + x1 - 1);
451  y2 = (s.height() + y1 - 1);
452 }
453 
454 inline bool QRect::contains(int ax, int ay, bool aproper) const
455 {
456  return contains(QPoint(ax, ay), aproper);
457 }
458 
459 inline bool QRect::contains(int ax, int ay) const
460 {
461  return contains(QPoint(ax, ay), false);
462 }
463 
464 inline QRect& QRect::operator|=(const QRect &r)
465 {
466  *this = *this | r;
467  return *this;
468 }
469 
470 inline QRect& QRect::operator&=(const QRect &r)
471 {
472  *this = *this & r;
473  return *this;
474 }
475 
476 inline QRect QRect::intersect(const QRect &r) const
477 {
478  return *this & r;
479 }
480 
481 inline QRect QRect::intersected(const QRect &other) const
482 {
483  return intersect(other);
484 }
485 
486 inline QRect QRect::unite(const QRect &r) const
487 {
488  return *this | r;
489 }
490 
491 inline QRect QRect::united(const QRect &r) const
492 {
493  return unite(r);
494 }
495 
496 inline bool operator==(const QRect &r1, const QRect &r2)
497 {
498  return r1.x1==r2.x1 && r1.x2==r2.x2 && r1.y1==r2.y1 && r1.y2==r2.y2;
499 }
500 
501 inline bool operator!=(const QRect &r1, const QRect &r2)
502 {
503  return r1.x1!=r2.x1 || r1.x2!=r2.x2 || r1.y1!=r2.y1 || r1.y2!=r2.y2;
504 }
505 
506 #ifndef QT_NO_DEBUG_STREAM
508 #endif
509 
510 
512 {
513 public:
514  QRectF() { xp = yp = 0.; w = h = 0.; }
515  QRectF(const QPointF &topleft, const QSizeF &size);
516  QRectF(const QPointF &topleft, const QPointF &bottomRight);
518  QRectF(const QRect &rect);
519 
520  bool isNull() const;
521  bool isEmpty() const;
522  bool isValid() const;
523  QRectF normalized() const;
524 
525  inline qreal left() const { return xp; }
526  inline qreal top() const { return yp; }
527  inline qreal right() const { return xp + w; }
528  inline qreal bottom() const { return yp + h; }
529 
530  inline qreal x() const;
531  inline qreal y() const;
532  inline void setLeft(qreal pos);
533  inline void setTop(qreal pos);
534  inline void setRight(qreal pos);
535  inline void setBottom(qreal pos);
536  inline void setX(qreal pos) { setLeft(pos); }
537  inline void setY(qreal pos) { setTop(pos); }
538 
539  inline QPointF topLeft() const { return QPointF(xp, yp); }
540  inline QPointF bottomRight() const { return QPointF(xp+w, yp+h); }
541  inline QPointF topRight() const { return QPointF(xp+w, yp); }
542  inline QPointF bottomLeft() const { return QPointF(xp, yp+h); }
543  inline QPointF center() const;
544 
545  void setTopLeft(const QPointF &p);
546  void setBottomRight(const QPointF &p);
547  void setTopRight(const QPointF &p);
548  void setBottomLeft(const QPointF &p);
549 
550  void moveLeft(qreal pos);
551  void moveTop(qreal pos);
552  void moveRight(qreal pos);
553  void moveBottom(qreal pos);
554  void moveTopLeft(const QPointF &p);
555  void moveBottomRight(const QPointF &p);
556  void moveTopRight(const QPointF &p);
557  void moveBottomLeft(const QPointF &p);
558  void moveCenter(const QPointF &p);
559 
560  void translate(qreal dx, qreal dy);
561  void translate(const QPointF &p);
562 
563  QRectF translated(qreal dx, qreal dy) const;
564  QRectF translated(const QPointF &p) const;
565 
566  void moveTo(qreal x, qreal t);
567  void moveTo(const QPointF &p);
568 
569  void setRect(qreal x, qreal y, qreal w, qreal h);
570  void getRect(qreal *x, qreal *y, qreal *w, qreal *h) const;
571 
572  void setCoords(qreal x1, qreal y1, qreal x2, qreal y2);
573  void getCoords(qreal *x1, qreal *y1, qreal *x2, qreal *y2) const;
574 
575  inline void adjust(qreal x1, qreal y1, qreal x2, qreal y2);
576  inline QRectF adjusted(qreal x1, qreal y1, qreal x2, qreal y2) const;
577 
578  QSizeF size() const;
579  qreal width() const;
580  qreal height() const;
581  void setWidth(qreal w);
582  void setHeight(qreal h);
583  void setSize(const QSizeF &s);
584 
585  QRectF operator|(const QRectF &r) const;
586  QRectF operator&(const QRectF &r) const;
587  QRectF& operator|=(const QRectF &r);
588  QRectF& operator&=(const QRectF &r);
589 
590  bool contains(const QPointF &p) const;
591  bool contains(qreal x, qreal y) const;
592  bool contains(const QRectF &r) const;
593  QRectF unite(const QRectF &r) const; // ### Qt 5: make QT4_SUPPORT
594  QRectF united(const QRectF &other) const;
595  QRectF intersect(const QRectF &r) const; // ### Qt 5: make QT4_SUPPORT
596  QRectF intersected(const QRectF &other) const;
597  bool intersects(const QRectF &r) const;
598 
599  friend Q_CORE_EXPORT_INLINE bool operator==(const QRectF &, const QRectF &);
600  friend Q_CORE_EXPORT_INLINE bool operator!=(const QRectF &, const QRectF &);
601 
602  QRect toRect() const;
603  QRect toAlignedRect() const;
604 
605 private:
610 };
612 
613 Q_CORE_EXPORT_INLINE bool operator==(const QRectF &, const QRectF &);
614 Q_CORE_EXPORT_INLINE bool operator!=(const QRectF &, const QRectF &);
615 
616 
617 /*****************************************************************************
618  QRectF stream functions
619  *****************************************************************************/
620 #ifndef QT_NO_DATASTREAM
623 #endif
624 
625 /*****************************************************************************
626  QRectF inline member functions
627  *****************************************************************************/
628 
629 inline QRectF::QRectF(qreal aleft, qreal atop, qreal awidth, qreal aheight)
630  : xp(aleft), yp(atop), w(awidth), h(aheight)
631 {
632 }
633 
634 inline QRectF::QRectF(const QPointF &atopLeft, const QSizeF &asize)
635 {
636  xp = atopLeft.x();
637  yp = atopLeft.y();
638  w = asize.width();
639  h = asize.height();
640 }
641 
642 inline QRectF::QRectF(const QPointF &atopLeft, const QPointF &abottomRight)
643 {
644  xp = atopLeft.x();
645  yp = atopLeft.y();
646  w = abottomRight.x() - xp;
647  h = abottomRight.y() - yp;
648 }
649 
650 inline QRectF::QRectF(const QRect &r)
651  : xp(r.x()), yp(r.y()), w(r.width()), h(r.height())
652 {
653 }
654 
655 inline bool QRectF::isNull() const
656 { return w == 0. && h == 0.; }
657 
658 inline bool QRectF::isEmpty() const
659 { return w <= 0. || h <= 0.; }
660 
661 inline bool QRectF::isValid() const
662 { return w > 0. && h > 0.; }
663 
664 inline qreal QRectF::x() const
665 { return xp; }
666 
667 inline qreal QRectF::y() const
668 { return yp; }
669 
670 inline void QRectF::setLeft(qreal pos) { qreal diff = pos - xp; xp += diff; w -= diff; }
671 
672 inline void QRectF::setRight(qreal pos) { w = pos - xp; }
673 
674 inline void QRectF::setTop(qreal pos) { qreal diff = pos - yp; yp += diff; h -= diff; }
675 
676 inline void QRectF::setBottom(qreal pos) { h = pos - yp; }
677 
678 inline void QRectF::setTopLeft(const QPointF &p) { setLeft(p.x()); setTop(p.y()); }
679 
680 inline void QRectF::setTopRight(const QPointF &p) { setRight(p.x()); setTop(p.y()); }
681 
682 inline void QRectF::setBottomLeft(const QPointF &p) { setLeft(p.x()); setBottom(p.y()); }
683 
684 inline void QRectF::setBottomRight(const QPointF &p) { setRight(p.x()); setBottom(p.y()); }
685 
686 inline QPointF QRectF::center() const
687 { return QPointF(xp + w/2, yp + h/2); }
688 
689 inline void QRectF::moveLeft(qreal pos) { xp = pos; }
690 
691 inline void QRectF::moveTop(qreal pos) { yp = pos; }
692 
693 inline void QRectF::moveRight(qreal pos) { xp = pos - w; }
694 
695 inline void QRectF::moveBottom(qreal pos) { yp = pos - h; }
696 
697 inline void QRectF::moveTopLeft(const QPointF &p) { moveLeft(p.x()); moveTop(p.y()); }
698 
699 inline void QRectF::moveTopRight(const QPointF &p) { moveRight(p.x()); moveTop(p.y()); }
700 
701 inline void QRectF::moveBottomLeft(const QPointF &p) { moveLeft(p.x()); moveBottom(p.y()); }
702 
703 inline void QRectF::moveBottomRight(const QPointF &p) { moveRight(p.x()); moveBottom(p.y()); }
704 
705 inline void QRectF::moveCenter(const QPointF &p) { xp = p.x() - w/2; yp = p.y() - h/2; }
706 
707 inline qreal QRectF::width() const
708 { return w; }
709 
710 inline qreal QRectF::height() const
711 { return h; }
712 
713 inline QSizeF QRectF::size() const
714 { return QSizeF(w, h); }
715 
716 inline void QRectF::translate(qreal dx, qreal dy)
717 {
718  xp += dx;
719  yp += dy;
720 }
721 
722 inline void QRectF::translate(const QPointF &p)
723 {
724  xp += p.x();
725  yp += p.y();
726 }
727 
728 inline void QRectF::moveTo(qreal ax, qreal ay)
729 {
730  xp = ax;
731  yp = ay;
732 }
733 
734 inline void QRectF::moveTo(const QPointF &p)
735 {
736  xp = p.x();
737  yp = p.y();
738 }
739 
740 inline QRectF QRectF::translated(qreal dx, qreal dy) const
741 { return QRectF(xp + dx, yp + dy, w, h); }
742 
743 inline QRectF QRectF::translated(const QPointF &p) const
744 { return QRectF(xp + p.x(), yp + p.y(), w, h); }
745 
746 inline void QRectF::getRect(qreal *ax, qreal *ay, qreal *aaw, qreal *aah) const
747 {
748  *ax = this->xp;
749  *ay = this->yp;
750  *aaw = this->w;
751  *aah = this->h;
752 }
753 
754 inline void QRectF::setRect(qreal ax, qreal ay, qreal aaw, qreal aah)
755 {
756  this->xp = ax;
757  this->yp = ay;
758  this->w = aaw;
759  this->h = aah;
760 }
761 
762 inline void QRectF::getCoords(qreal *xp1, qreal *yp1, qreal *xp2, qreal *yp2) const
763 {
764  *xp1 = xp;
765  *yp1 = yp;
766  *xp2 = xp + w;
767  *yp2 = yp + h;
768 }
769 
770 inline void QRectF::setCoords(qreal xp1, qreal yp1, qreal xp2, qreal yp2)
771 {
772  xp = xp1;
773  yp = yp1;
774  w = xp2 - xp1;
775  h = yp2 - yp1;
776 }
777 
778 inline void QRectF::adjust(qreal xp1, qreal yp1, qreal xp2, qreal yp2)
779 { xp += xp1; yp += yp1; w += xp2 - xp1; h += yp2 - yp1; }
780 
781 inline QRectF QRectF::adjusted(qreal xp1, qreal yp1, qreal xp2, qreal yp2) const
782 { return QRectF(xp + xp1, yp + yp1, w + xp2 - xp1, h + yp2 - yp1); }
783 
784 inline void QRectF::setWidth(qreal aw)
785 { this->w = aw; }
786 
787 inline void QRectF::setHeight(qreal ah)
788 { this->h = ah; }
789 
790 inline void QRectF::setSize(const QSizeF &s)
791 {
792  w = s.width();
793  h = s.height();
794 }
795 
796 inline bool QRectF::contains(qreal ax, qreal ay) const
797 {
798  return contains(QPointF(ax, ay));
799 }
800 
802 {
803  *this = *this | r;
804  return *this;
805 }
806 
807 inline QRectF& QRectF::operator&=(const QRectF &r)
808 {
809  *this = *this & r;
810  return *this;
811 }
812 
813 inline QRectF QRectF::intersect(const QRectF &r) const
814 {
815  return *this & r;
816 }
817 
818 inline QRectF QRectF::intersected(const QRectF &r) const
819 {
820  return intersect(r);
821 }
822 
823 inline QRectF QRectF::unite(const QRectF &r) const
824 {
825  return *this | r;
826 }
827 
828 inline QRectF QRectF::united(const QRectF &r) const
829 {
830  return unite(r);
831 }
832 
833 inline bool operator==(const QRectF &r1, const QRectF &r2)
834 {
835  return qFuzzyCompare(r1.xp, r2.xp) && qFuzzyCompare(r1.yp, r2.yp)
836  && qFuzzyCompare(r1.w, r2.w) && qFuzzyCompare(r1.h, r2.h);
837 }
838 
839 inline bool operator!=(const QRectF &r1, const QRectF &r2)
840 {
841  return !qFuzzyCompare(r1.xp, r2.xp) || !qFuzzyCompare(r1.yp, r2.yp)
842  || !qFuzzyCompare(r1.w, r2.w) || !qFuzzyCompare(r1.h, r2.h);
843 }
844 
845 inline QRect QRectF::toRect() const
846 {
847  return QRect(qRound(xp), qRound(yp), qRound(w), qRound(h));
848 }
849 
850 #ifndef QT_NO_DEBUG_STREAM
852 #endif
853 
855 
857 
858 #endif // QRECT_H
void setBottomRight(const QPointF &p)
Set the bottom-right corner of the rectangle to the given position.
Definition: qrect.h:684
The QDebug class provides an output stream for debugging information.
Definition: qdebug.h:62
QPointF bottomRight() const
Returns the position of the rectangle&#39;s bottom-right corner.
Definition: qrect.h:540
void getRect(qreal *x, qreal *y, qreal *w, qreal *h) const
Extracts the position of the rectangle&#39;s top-left corner to *x and y, and its dimensions to *width an...
Definition: qrect.h:746
void moveTop(qreal pos)
Moves the rectangle vertically, leaving the rectangle&#39;s top line at the given y coordinate.
Definition: qrect.h:691
#define Q_CORE_EXPORT_INLINE
Definition: qglobal.h:1493
void moveBottomRight(const QPoint &p)
Moves the rectangle, leaving the bottom-right corner at the given position.
Definition: qrect.h:374
qreal y() const
Returns the y-coordinate of the rectangle&#39;s top edge.
Definition: qrect.h:667
void setTopLeft(const QPointF &p)
Set the top-left corner of the rectangle to the given position.
Definition: qrect.h:678
qreal right() const
Returns the x-coordinate of the rectangle&#39;s right edge.
Definition: qrect.h:527
QRect adjusted(int x1, int y1, int x2, int y2) const
Returns a new rectangle with dx1, dy1, dx2 and dy2 added respectively to the existing coordinates of ...
Definition: qrect.h:431
bool isNull() const
Returns true if the rectangle is a null rectangle, otherwise returns false.
Definition: qrect.h:231
void setHeight(int h)
Sets the height of the rectangle to the given height.
Definition: qrect.h:445
double qreal
Definition: qglobal.h:1193
void setBottom(int pos)
Sets the bottom edge of the rectangle to the given y coordinate.
Definition: qrect.h:267
void setHeight(qreal h)
Sets the height of the rectangle to the given height.
Definition: qrect.h:787
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
QRect operator &(const QRect &r) const
#define QT_MODULE(x)
Definition: qglobal.h:2783
bool isValid() const
Returns true if the rectangle is valid, otherwise returns false.
Definition: qrect.h:661
void moveLeft(int pos)
Moves the rectangle horizontally, leaving the rectangle&#39;s left edge at the given x coordinate...
Definition: qrect.h:350
int y1
Definition: qrect.h:177
void moveLeft(qreal pos)
Moves the rectangle horizontally, leaving the rectangle&#39;s left edge at the given x coordinate...
Definition: qrect.h:689
void setLeft(qreal pos)
Sets the left edge of the rectangle to the given x coordinate.
Definition: qrect.h:670
#define QT_BEGIN_HEADER
Definition: qglobal.h:136
QRect & operator|=(const QRect &r)
Unites this rectangle with the given rectangle.
Definition: qrect.h:464
void setX(qreal pos)
Sets the left edge of the rectangle to the given x coordinate.
Definition: qrect.h:536
QRectF & operator|=(const QRectF &r)
Unites this rectangle with the given rectangle.
Definition: qrect.h:801
void setTopRight(const QPoint &p)
Set the top-right corner of the rectangle to the given position.
Definition: qrect.h:276
qreal width() const
Returns the width.
Definition: qsize.h:284
int y2
Definition: qrect.h:179
QRect united(const QRect &other) const
Returns the bounding rectangle of this rectangle and the given rectangle.
Definition: qrect.h:491
void setTopRight(const QPointF &p)
Set the top-right corner of the rectangle to the given position.
Definition: qrect.h:680
The QPointF class defines a point in the plane using floating point precision.
Definition: qpoint.h:214
QRect intersect(const QRect &r) const
Use intersected(rectangle) instead.
Definition: qrect.h:476
qreal height() const
Returns the height.
Definition: qsize.h:287
qreal left() const
Returns the x-coordinate of the rectangle&#39;s left edge.
Definition: qrect.h:525
friend Q_CORE_EXPORT_INLINE bool operator!=(const QRectF &, const QRectF &)
Returns true if the rectangles r1 and r2 are different, otherwise returns false.
Definition: qrect.h:839
qreal xp
Definition: qrect.h:606
void setBottomLeft(const QPointF &p)
Set the bottom-left corner of the rectangle to the given position.
Definition: qrect.h:682
QRect normalized() const
Returns a normalized rectangle; i.e., a rectangle that has a non-negative width and height...
Definition: qrect.cpp:322
void moveRight(int pos)
Moves the rectangle horizontally, leaving the rectangle&#39;s right edge at the given x coordinate...
Definition: qrect.h:356
void moveBottom(qreal pos)
Moves the rectangle vertically, leaving the rectangle&#39;s bottom edge at the given y coordinate...
Definition: qrect.h:695
QPointF topLeft() const
Returns the position of the rectangle&#39;s top-left corner.
Definition: qrect.h:539
int left() const
Returns the x-coordinate of the rectangle&#39;s left edge.
Definition: qrect.h:240
void getCoords(qreal *x1, qreal *y1, qreal *x2, qreal *y2) const
Extracts the position of the rectangle&#39;s top-left corner to *x1 and *y1, and the position of the bott...
Definition: qrect.h:762
QRect translated(int dx, int dy) const
Returns a copy of the rectangle that is translated dx along the x axis and dy along the y axis...
Definition: qrect.h:328
int width() const
Returns the width of the rectangle.
Definition: qrect.h:303
void setTop(qreal pos)
Sets the top edge of the rectangle to the given y coordinate.
Definition: qrect.h:674
void setBottom(qreal pos)
Sets the bottom edge of the rectangle to the given y coordinate.
Definition: qrect.h:676
friend Q_CORE_EXPORT_INLINE bool operator!=(const QRect &, const QRect &)
Returns true if the rectangles r1 and r2 are different, otherwise returns false.
Definition: qrect.h:501
static Q_DECL_CONSTEXPR bool qFuzzyCompare(double p1, double p2)
Definition: qglobal.h:2030
QRect intersected(const QRect &other) const
Returns the intersection of this rectangle and the given rectangle.
Definition: qrect.h:481
void moveTo(int x, int t)
Moves the rectangle, leaving the top-left corner at the given position (x, y).
Definition: qrect.h:334
QPointF bottomLeft() const
Returns the position of the rectangle&#39;s bottom-left corner.
Definition: qrect.h:542
qreal h
Definition: qrect.h:609
int height() const
Returns the height of the rectangle.
Definition: qrect.h:306
void setY(int y)
Sets the top edge of the rectangle to the given y coordinate.
Definition: qrect.h:285
QRectF intersected(const QRectF &other) const
Returns the intersection of this rectangle and the given rectangle.
Definition: qrect.h:818
int bottom() const
Returns the y-coordinate of the rectangle&#39;s bottom edge.
Definition: qrect.h:249
void moveBottom(int pos)
Moves the rectangle vertically, leaving the rectangle&#39;s bottom edge at the given y coordinate...
Definition: qrect.h:362
QDataStream & operator<<(QDataStream &stream, const QRectF &rectangle)
Writes the rectangle to the stream, and returns a reference to the stream.
Definition: qrect.cpp:2879
friend Q_CORE_EXPORT_INLINE bool operator==(const QRect &, const QRect &)
Returns true if the rectangles r1 and r2 are equal, otherwise returns false.
Definition: qrect.h:496
The QSizeF class defines the size of a two-dimensional object using floating point precision...
Definition: qsize.h:202
void setRight(qreal pos)
Sets the right edge of the rectangle to the given x coordinate.
Definition: qrect.h:672
QRect unite(const QRect &r) const
Use united(rectangle) instead.
Definition: qrect.h:486
void operator|=(ItemType::Ptr &op1, const ItemType::Ptr &op2)
Computes the union type of op1 and op2, and assigns it to op1.
Definition: qitemtype_p.h:273
qreal x() const
Returns the x-coordinate of this point.
Definition: qpoint.h:282
QTextStream & center(QTextStream &stream)
Calls QTextStream::setFieldAlignment(QTextStream::AlignCenter) on stream and returns stream...
bool contains(const QPointF &p) const
Returns true if the given point is inside or on the edge of the rectangle; otherwise returns false...
Definition: qrect.cpp:2349
void getCoords(int *x1, int *y1, int *x2, int *y2) const
Extracts the position of the rectangle&#39;s top-left corner to *x1 and *y1, and the position of the bott...
Definition: qrect.h:408
int width() const
Returns the width.
Definition: qsize.h:126
QTextStream & right(QTextStream &stream)
Calls QTextStream::setFieldAlignment(QTextStream::AlignRight) on stream and returns stream...
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
static void setCoords(GLfloat *coords, const QGLRect &rect)
The QRectF class defines a rectangle in the plane using floating point precision. ...
Definition: qrect.h:511
qreal w
Definition: qrect.h:608
static bool isEmpty(const char *str)
QPoint bottomRight() const
Returns the position of the rectangle&#39;s bottom-right corner.
Definition: qrect.h:291
friend Q_CORE_EXPORT_INLINE bool operator==(const QRectF &, const QRectF &)
Returns true if the rectangles r1 and r2 are equal, otherwise returns false.
Definition: qrect.h:833
void setTop(int pos)
Sets the top edge of the rectangle to the given y coordinate.
Definition: qrect.h:261
QRect()
Constructs a null rectangle.
Definition: qrect.h:61
qreal height() const
Returns the height of the rectangle.
Definition: qrect.h:710
void moveTopRight(const QPoint &p)
Moves the rectangle, leaving the top-right corner at the given position.
Definition: qrect.h:380
QSize size() const
Returns the size of the rectangle.
Definition: qrect.h:309
void moveTopRight(const QPointF &p)
Moves the rectangle, leaving the top-right corner at the given position.
Definition: qrect.h:699
void adjust(int x1, int y1, int x2, int y2)
Adds dx1, dy1, dx2 and dy2 respectively to the existing coordinates of the rectangle.
Definition: qrect.h:434
void setRight(int pos)
Sets the right edge of the rectangle to the given x coordinate.
Definition: qrect.h:264
void moveTopLeft(const QPointF &p)
Moves the rectangle, leaving the top-left corner at the given position.
Definition: qrect.h:697
void setSize(const QSize &s)
Sets the size of the rectangle to the given size.
Definition: qrect.h:448
static Bigint * diff(Bigint *a, Bigint *b)
void setTopLeft(const QPoint &p)
Set the top-left corner of the rectangle to the given position.
Definition: qrect.h:270
qreal width() const
Returns the width of the rectangle.
Definition: qrect.h:707
void setRect(qreal x, qreal y, qreal w, qreal h)
Sets the coordinates of the rectangle&#39;s top-left corner to (x, y), and its size to the given width an...
Definition: qrect.h:754
void setCoords(int x1, int y1, int x2, int y2)
Sets the coordinates of the rectangle&#39;s top-left corner to (x1, y1), and the coordinates of its botto...
Definition: qrect.h:416
QRectF adjusted(qreal x1, qreal y1, qreal x2, qreal y2) const
Returns a new rectangle with dx1, dy1, dx2 and dy2 added respectively to the existing coordinates of ...
Definition: qrect.h:781
void setBottomLeft(const QPoint &p)
Set the bottom-left corner of the rectangle to the given position.
Definition: qrect.h:279
void translate(qreal dx, qreal dy)
Moves the rectangle dx along the x-axis and dy along the y-axis, relative to the current position...
Definition: qrect.h:716
void setX(int x)
Sets the left edge of the rectangle to the given x coordinate.
Definition: qrect.h:282
QRect toRect() const
Returns a QRect based on the values of this rectangle.
Definition: qrect.h:845
QRectF()
Constructs a null rectangle.
Definition: qrect.h:514
bool contains(const QPoint &p, bool proper=false) const
Returns true if the given point is inside or on the edge of the rectangle, otherwise returns false...
Definition: qrect.cpp:1101
void setSize(const QSizeF &s)
Sets the size of the rectangle to the given size.
Definition: qrect.h:790
void setBottomRight(const QPoint &p)
Set the bottom-right corner of the rectangle to the given position.
Definition: qrect.h:273
void moveTopLeft(const QPoint &p)
Moves the rectangle, leaving the top-left corner at the given position.
Definition: qrect.h:368
void moveCenter(const QPoint &p)
Moves the rectangle, leaving the center point at the given position.
Definition: qrect.cpp:840
QDataStream & operator>>(QDataStream &stream, QRect &rectangle)
Reads a rectangle from the given stream into the given rectangle, and returns a reference to the stre...
Definition: qrect.cpp:1536
void moveRight(qreal pos)
Moves the rectangle horizontally, leaving the rectangle&#39;s right edge at the given x coordinate...
Definition: qrect.h:693
QPoint topRight() const
Returns the position of the rectangle&#39;s top-right corner.
Definition: qrect.h:294
bool isEmpty() const
Returns true if the rectangle is empty, otherwise returns false.
Definition: qrect.h:234
QPoint center() const
Returns the center point of the rectangle.
Definition: qrect.h:300
void moveBottomLeft(const QPoint &p)
Moves the rectangle, leaving the bottom-left corner at the given position.
Definition: qrect.h:386
bool operator!=(const T *o, const QPointer< T > &p)
Definition: qpointer.h:122
int top() const
Returns the y-coordinate of the rectangle&#39;s top edge.
Definition: qrect.h:243
int right() const
Returns the x-coordinate of the rectangle&#39;s right edge.
Definition: qrect.h:246
QPoint bottomLeft() const
Returns the position of the rectangle&#39;s bottom-left corner.
Definition: qrect.h:297
#define Q_CORE_EXPORT
Definition: qglobal.h:1449
void setLeft(int pos)
Sets the left edge of the rectangle to the given x coordinate.
Definition: qrect.h:258
int y() const
Returns the y-coordinate of the rectangle&#39;s top edge.
Definition: qrect.h:255
qreal x() const
Returns the x-coordinate of the rectangle&#39;s left edge.
Definition: qrect.h:664
Q_CORE_EXPORT QBitArray operator &(const QBitArray &, const QBitArray &)
void adjust(qreal x1, qreal y1, qreal x2, qreal y2)
Adds dx1, dy1, dx2 and dy2 respectively to the existing coordinates of the rectangle.
Definition: qrect.h:778
int x() const
Returns the x-coordinate of the rectangle&#39;s left edge.
Definition: qrect.h:252
void setCoords(qreal x1, qreal y1, qreal x2, qreal y2)
Sets the coordinates of the rectangle&#39;s top-left corner to (x1, y1), and the coordinates of its botto...
Definition: qrect.h:770
void setRect(int x, int y, int w, int h)
Sets the coordinates of the rectangle&#39;s top-left corner to ({x}, {y}), and its size to the given widt...
Definition: qrect.h:400
The QPoint class defines a point in the plane using integer precision.
Definition: qpoint.h:53
void moveBottomRight(const QPointF &p)
Moves the rectangle, leaving the bottom-right corner at the given position.
Definition: qrect.h:703
QRectF united(const QRectF &other) const
Returns the bounding rectangle of this rectangle and the given rectangle.
Definition: qrect.h:828
void setWidth(int w)
Sets the width of the rectangle to the given width.
Definition: qrect.h:442
int height() const
Returns the height.
Definition: qsize.h:129
The QRect class defines a rectangle in the plane using integer precision.
Definition: qrect.h:58
QRectF intersect(const QRectF &r) const
Use intersected(rectangle) instead.
Definition: qrect.h:813
void getRect(int *x, int *y, int *w, int *h) const
Extracts the position of the rectangle&#39;s top-left corner to *x and *y, and its dimensions to *width a...
Definition: qrect.h:392
QSizeF size() const
Returns the size of the rectangle.
Definition: qrect.h:713
void moveTo(qreal x, qreal t)
Moves the rectangle, leaving the top-left corner at the given position (x, y).
Definition: qrect.h:728
bool operator==(const T *o, const QPointer< T > &p)
Definition: qpointer.h:87
void setY(qreal pos)
Sets the top edge of the rectangle to the given y coordinate.
Definition: qrect.h:537
int y() const
Returns the y coordinate of this point.
Definition: qpoint.h:131
void moveBottomLeft(const QPointF &p)
Moves the rectangle, leaving the bottom-left corner at the given position.
Definition: qrect.h:701
qreal y() const
Returns the y-coordinate of this point.
Definition: qpoint.h:287
QRectF & operator &=(const QRectF &r)
qreal top() const
Returns the y-coordinate of the rectangle&#39;s top edge.
Definition: qrect.h:526
int x2
Definition: qrect.h:180
The QSize class defines the size of a two-dimensional object using integer point precision.
Definition: qsize.h:53
void setWidth(qreal w)
Sets the width of the rectangle to the given width.
Definition: qrect.h:784
qreal yp
Definition: qrect.h:607
The QDataStream class provides serialization of binary data to a QIODevice.
Definition: qdatastream.h:71
bool intersects(const QRect &r) const
Returns true if this rectangle intersects with the given rectangle (i.
Definition: qrect.cpp:1429
int x() const
Returns the x coordinate of this point.
Definition: qpoint.h:128
qreal bottom() const
Returns the y-coordinate of the rectangle&#39;s bottom edge.
Definition: qrect.h:528
QRect operator|(const QRect &r) const
Returns the bounding rectangle of this rectangle and the given rectangle.
Definition: qrect.cpp:1261
Q_DECLARE_TYPEINFO(QRect, Q_MOVABLE_TYPE)
void moveTop(int pos)
Moves the rectangle vertically, leaving the rectangle&#39;s top edge at the given y coordinate.
Definition: qrect.h:353
int x1
Definition: qrect.h:178
QRectF translated(qreal dx, qreal dy) const
Returns a copy of the rectangle that is translated dx along the x axis and dy along the y axis...
Definition: qrect.h:740
bool isValid() const
Returns true if the rectangle is valid, otherwise returns false.
Definition: qrect.h:237
bool isEmpty() const
Returns true if the rectangle is empty, otherwise returns false.
Definition: qrect.h:658
QBitArray operator|(const QBitArray &a1, const QBitArray &a2)
Returns a bit array that is the OR of the bit arrays a1 and a2.
Definition: qbitarray.cpp:662
QPointF topRight() const
Returns the position of the rectangle&#39;s top-right corner.
Definition: qrect.h:541
#define class
void translate(int dx, int dy)
Moves the rectangle dx along the x axis and dy along the y axis, relative to the current position...
Definition: qrect.h:312
void moveCenter(const QPointF &p)
Moves the rectangle, leaving the center point at the given position.
Definition: qrect.h:705
#define QT_END_HEADER
Definition: qglobal.h:137
QPointF center() const
Returns the center point of the rectangle.
Definition: qrect.h:686
QRectF unite(const QRectF &r) const
Use united(rectangle) instead.
Definition: qrect.h:823
static void normalize(double &x, double &y)
QDataStream & operator<<(QDataStream &out, const QUrl &url)
Writes url url to the stream out and returns a reference to the stream.
Definition: qurl.cpp:6757
bool isNull() const
Returns true if the rectangle is a null rectangle, otherwise returns false.
Definition: qrect.h:655
QRect & operator &=(const QRect &r)
Q_DECL_CONSTEXPR int qRound(qreal d)
Definition: qglobal.h:1203
static bool isNull(const QVariant::Private *d)
Definition: qvariant.cpp:300
QDataStream & operator<<(QDataStream &stream, const QRect &rectangle)
Writes the given rectangle to the given stream, and returns a reference to the stream.
Definition: qrect.cpp:1512
QPoint topLeft() const
Returns the position of the rectangle&#39;s top-left corner.
Definition: qrect.h:288
QTextStream & left(QTextStream &stream)
Calls QTextStream::setFieldAlignment(QTextStream::AlignLeft) on stream and returns stream...
QDataStream & operator>>(QDataStream &in, QUrl &url)
Reads a url into url from the stream in and returns a reference to the stream.
Definition: qurl.cpp:6774