Merge remote-tracking branch 'origin/master' into api_changes
[profile/ivi/qtbase.git] / src / corelib / tools / qrect.h
1 /****************************************************************************
2 **
3 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/
5 **
6 ** This file is part of the QtCore module of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** GNU Lesser General Public License Usage
10 ** This file may be used under the terms of the GNU Lesser General Public
11 ** License version 2.1 as published by the Free Software Foundation and
12 ** appearing in the file LICENSE.LGPL included in the packaging of this
13 ** file. Please review the following information to ensure the GNU Lesser
14 ** General Public License version 2.1 requirements will be met:
15 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
16 **
17 ** In addition, as a special exception, Nokia gives you certain additional
18 ** rights. These rights are described in the Nokia Qt LGPL Exception
19 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
20 **
21 ** GNU General Public License Usage
22 ** Alternatively, this file may be used under the terms of the GNU General
23 ** Public License version 3.0 as published by the Free Software Foundation
24 ** and appearing in the file LICENSE.GPL included in the packaging of this
25 ** file. Please review the following information to ensure the GNU General
26 ** Public License version 3.0 requirements will be met:
27 ** http://www.gnu.org/copyleft/gpl.html.
28 **
29 ** Other Usage
30 ** Alternatively, this file may be used in accordance with the terms and
31 ** conditions contained in a signed written agreement between you and Nokia.
32 **
33 **
34 **
35 **
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
52 QT_BEGIN_HEADER
53
54 QT_BEGIN_NAMESPACE
55
56
57 class Q_CORE_EXPORT QRect
58 {
59 public:
60     Q_DECL_CONSTEXPR QRect() : x1(0), y1(0), x2(-1), y2(-1) {}
61     Q_DECL_CONSTEXPR QRect(const QPoint &topleft, const QPoint &bottomright);
62     Q_DECL_CONSTEXPR QRect(const QPoint &topleft, const QSize &size);
63     Q_DECL_CONSTEXPR QRect(int left, int top, int width, int height);
64
65     Q_DECL_CONSTEXPR bool isNull() const;
66     Q_DECL_CONSTEXPR bool isEmpty() const;
67     Q_DECL_CONSTEXPR bool isValid() const;
68
69     Q_DECL_CONSTEXPR int left() const;
70     Q_DECL_CONSTEXPR int top() const;
71     Q_DECL_CONSTEXPR int right() const;
72     Q_DECL_CONSTEXPR int bottom() const;
73     QRect normalized() const;
74
75     Q_DECL_CONSTEXPR int x() const;
76     Q_DECL_CONSTEXPR int y() const;
77     void setLeft(int pos);
78     void setTop(int pos);
79     void setRight(int pos);
80     void setBottom(int pos);
81     void setX(int x);
82     void setY(int y);
83
84     void setTopLeft(const QPoint &p);
85     void setBottomRight(const QPoint &p);
86     void setTopRight(const QPoint &p);
87     void setBottomLeft(const QPoint &p);
88
89     Q_DECL_CONSTEXPR QPoint topLeft() const;
90     Q_DECL_CONSTEXPR QPoint bottomRight() const;
91     Q_DECL_CONSTEXPR QPoint topRight() const;
92     Q_DECL_CONSTEXPR QPoint bottomLeft() const;
93     Q_DECL_CONSTEXPR QPoint center() const;
94
95     void moveLeft(int pos);
96     void moveTop(int pos);
97     void moveRight(int pos);
98     void moveBottom(int pos);
99     void moveTopLeft(const QPoint &p);
100     void moveBottomRight(const QPoint &p);
101     void moveTopRight(const QPoint &p);
102     void moveBottomLeft(const QPoint &p);
103     void moveCenter(const QPoint &p);
104
105     inline void translate(int dx, int dy);
106     inline void translate(const QPoint &p);
107     Q_DECL_CONSTEXPR inline QRect translated(int dx, int dy) const;
108     Q_DECL_CONSTEXPR inline QRect translated(const QPoint &p) const;
109
110     void moveTo(int x, int t);
111     void moveTo(const QPoint &p);
112
113     void setRect(int x, int y, int w, int h);
114     inline void getRect(int *x, int *y, int *w, int *h) const;
115
116     void setCoords(int x1, int y1, int x2, int y2);
117     inline void getCoords(int *x1, int *y1, int *x2, int *y2) const;
118
119     inline void adjust(int x1, int y1, int x2, int y2);
120     Q_DECL_CONSTEXPR inline QRect adjusted(int x1, int y1, int x2, int y2) const;
121
122     Q_DECL_CONSTEXPR QSize size() const;
123     Q_DECL_CONSTEXPR int width() const;
124     Q_DECL_CONSTEXPR int height() const;
125     void setWidth(int w);
126     void setHeight(int h);
127     void setSize(const QSize &s);
128
129     QRect operator|(const QRect &r) const;
130     QRect operator&(const QRect &r) const;
131     QRect& operator|=(const QRect &r);
132     QRect& operator&=(const QRect &r);
133
134     bool contains(const QPoint &p, bool proper=false) const;
135     bool contains(int x, int y) const; // inline methods, _don't_ merge these
136     bool contains(int x, int y, bool proper) const;
137     bool contains(const QRect &r, bool proper = false) const;
138     QRect united(const QRect &other) const;
139     QRect intersected(const QRect &other) const;
140     bool intersects(const QRect &r) const;
141
142 #if QT_DEPRECATED_SINCE(5, 0)
143     QT_DEPRECATED QRect unite(const QRect &r) const { return united(r); }
144     QT_DEPRECATED QRect intersect(const QRect &r) const { return intersected(r); }
145 #endif
146
147     friend Q_CORE_EXPORT_INLINE Q_DECL_CONSTEXPR bool operator==(const QRect &, const QRect &);
148     friend Q_CORE_EXPORT_INLINE Q_DECL_CONSTEXPR bool operator!=(const QRect &, const QRect &);
149
150 private:
151     int x1;
152     int y1;
153     int x2;
154     int y2;
155 };
156 Q_DECLARE_TYPEINFO(QRect, Q_MOVABLE_TYPE);
157
158 Q_CORE_EXPORT_INLINE Q_DECL_CONSTEXPR bool operator==(const QRect &, const QRect &);
159 Q_CORE_EXPORT_INLINE Q_DECL_CONSTEXPR bool operator!=(const QRect &, const QRect &);
160
161
162 /*****************************************************************************
163   QRect stream functions
164  *****************************************************************************/
165 #ifndef QT_NO_DATASTREAM
166 Q_CORE_EXPORT QDataStream &operator<<(QDataStream &, const QRect &);
167 Q_CORE_EXPORT QDataStream &operator>>(QDataStream &, QRect &);
168 #endif
169
170 /*****************************************************************************
171   QRect inline member functions
172  *****************************************************************************/
173
174 Q_DECL_CONSTEXPR inline QRect::QRect(int aleft, int atop, int awidth, int aheight)
175     : x1(aleft), y1(atop), x2(aleft + awidth - 1), y2(atop + aheight - 1) {}
176
177 Q_DECL_CONSTEXPR inline QRect::QRect(const QPoint &atopLeft, const QPoint &abottomRight)
178     : x1(atopLeft.x()), y1(atopLeft.y()), x2(abottomRight.x()), y2(abottomRight.y()) {}
179
180 Q_DECL_CONSTEXPR inline QRect::QRect(const QPoint &atopLeft, const QSize &asize)
181     : x1(atopLeft.x()), y1(atopLeft.y()), x2(atopLeft.x()+asize.width() - 1), y2(atopLeft.y()+asize.height() - 1) {}
182
183 Q_DECL_CONSTEXPR inline bool QRect::isNull() const
184 { return x2 == x1 - 1 && y2 == y1 - 1; }
185
186 Q_DECL_CONSTEXPR inline bool QRect::isEmpty() const
187 { return x1 > x2 || y1 > y2; }
188
189 Q_DECL_CONSTEXPR inline bool QRect::isValid() const
190 { return x1 <= x2 && y1 <= y2; }
191
192 Q_DECL_CONSTEXPR inline int QRect::left() const
193 { return x1; }
194
195 Q_DECL_CONSTEXPR inline int QRect::top() const
196 { return y1; }
197
198 Q_DECL_CONSTEXPR inline int QRect::right() const
199 { return x2; }
200
201 Q_DECL_CONSTEXPR inline int QRect::bottom() const
202 { return y2; }
203
204 Q_DECL_CONSTEXPR inline int QRect::x() const
205 { return x1; }
206
207 Q_DECL_CONSTEXPR inline int QRect::y() const
208 { return y1; }
209
210 inline void QRect::setLeft(int pos)
211 { x1 = pos; }
212
213 inline void QRect::setTop(int pos)
214 { y1 = pos; }
215
216 inline void QRect::setRight(int pos)
217 { x2 = pos; }
218
219 inline void QRect::setBottom(int pos)
220 { y2 = pos; }
221
222 inline void QRect::setTopLeft(const QPoint &p)
223 { x1 = p.x(); y1 = p.y(); }
224
225 inline void QRect::setBottomRight(const QPoint &p)
226 { x2 = p.x(); y2 = p.y(); }
227
228 inline void QRect::setTopRight(const QPoint &p)
229 { x2 = p.x(); y1 = p.y(); }
230
231 inline void QRect::setBottomLeft(const QPoint &p)
232 { x1 = p.x(); y2 = p.y(); }
233
234 inline void QRect::setX(int ax)
235 { x1 = ax; }
236
237 inline void QRect::setY(int ay)
238 { y1 = ay; }
239
240 Q_DECL_CONSTEXPR inline QPoint QRect::topLeft() const
241 { return QPoint(x1, y1); }
242
243 Q_DECL_CONSTEXPR inline QPoint QRect::bottomRight() const
244 { return QPoint(x2, y2); }
245
246 Q_DECL_CONSTEXPR inline QPoint QRect::topRight() const
247 { return QPoint(x2, y1); }
248
249 Q_DECL_CONSTEXPR inline QPoint QRect::bottomLeft() const
250 { return QPoint(x1, y2); }
251
252 Q_DECL_CONSTEXPR inline QPoint QRect::center() const
253 { return QPoint((x1+x2)/2, (y1+y2)/2); }
254
255 Q_DECL_CONSTEXPR inline int QRect::width() const
256 { return  x2 - x1 + 1; }
257
258 Q_DECL_CONSTEXPR inline int QRect::height() const
259 { return  y2 - y1 + 1; }
260
261 Q_DECL_CONSTEXPR inline QSize QRect::size() const
262 { return QSize(width(), height()); }
263
264 inline void QRect::translate(int dx, int dy)
265 {
266     x1 += dx;
267     y1 += dy;
268     x2 += dx;
269     y2 += dy;
270 }
271
272 inline void QRect::translate(const QPoint &p)
273 {
274     x1 += p.x();
275     y1 += p.y();
276     x2 += p.x();
277     y2 += p.y();
278 }
279
280 Q_DECL_CONSTEXPR inline QRect QRect::translated(int dx, int dy) const
281 { return QRect(QPoint(x1 + dx, y1 + dy), QPoint(x2 + dx, y2 + dy)); }
282
283 Q_DECL_CONSTEXPR inline QRect QRect::translated(const QPoint &p) const
284 { return QRect(QPoint(x1 + p.x(), y1 + p.y()), QPoint(x2 + p.x(), y2 + p.y())); }
285
286 inline void QRect::moveTo(int ax, int ay)
287 {
288     x2 += ax - x1;
289     y2 += ay - y1;
290     x1 = ax;
291     y1 = ay;
292 }
293
294 inline void QRect::moveTo(const QPoint &p)
295 {
296     x2 += p.x() - x1;
297     y2 += p.y() - y1;
298     x1 = p.x();
299     y1 = p.y();
300 }
301
302 inline void QRect::moveLeft(int pos)
303 { x2 += (pos - x1); x1 = pos; }
304
305 inline void QRect::moveTop(int pos)
306 { y2 += (pos - y1); y1 = pos; }
307
308 inline void QRect::moveRight(int pos)
309 {
310     x1 += (pos - x2);
311     x2 = pos;
312 }
313
314 inline void QRect::moveBottom(int pos)
315 {
316     y1 += (pos - y2);
317     y2 = pos;
318 }
319
320 inline void QRect::moveTopLeft(const QPoint &p)
321 {
322     moveLeft(p.x());
323     moveTop(p.y());
324 }
325
326 inline void QRect::moveBottomRight(const QPoint &p)
327 {
328     moveRight(p.x());
329     moveBottom(p.y());
330 }
331
332 inline void QRect::moveTopRight(const QPoint &p)
333 {
334     moveRight(p.x());
335     moveTop(p.y());
336 }
337
338 inline void QRect::moveBottomLeft(const QPoint &p)
339 {
340     moveLeft(p.x());
341     moveBottom(p.y());
342 }
343
344 inline void QRect::getRect(int *ax, int *ay, int *aw, int *ah) const
345 {
346     *ax = x1;
347     *ay = y1;
348     *aw = x2 - x1 + 1;
349     *ah = y2 - y1 + 1;
350 }
351
352 inline void QRect::setRect(int ax, int ay, int aw, int ah)
353 {
354     x1 = ax;
355     y1 = ay;
356     x2 = (ax + aw - 1);
357     y2 = (ay + ah - 1);
358 }
359
360 inline void QRect::getCoords(int *xp1, int *yp1, int *xp2, int *yp2) const
361 {
362     *xp1 = x1;
363     *yp1 = y1;
364     *xp2 = x2;
365     *yp2 = y2;
366 }
367
368 inline void QRect::setCoords(int xp1, int yp1, int xp2, int yp2)
369 {
370     x1 = xp1;
371     y1 = yp1;
372     x2 = xp2;
373     y2 = yp2;
374 }
375
376 Q_DECL_CONSTEXPR inline QRect QRect::adjusted(int xp1, int yp1, int xp2, int yp2) const
377 { return QRect(QPoint(x1 + xp1, y1 + yp1), QPoint(x2 + xp2, y2 + yp2)); }
378
379 inline void QRect::adjust(int dx1, int dy1, int dx2, int dy2)
380 {
381     x1 += dx1;
382     y1 += dy1;
383     x2 += dx2;
384     y2 += dy2;
385 }
386
387 inline void QRect::setWidth(int w)
388 { x2 = (x1 + w - 1); }
389
390 inline void QRect::setHeight(int h)
391 { y2 = (y1 + h - 1); }
392
393 inline void QRect::setSize(const QSize &s)
394 {
395     x2 = (s.width()  + x1 - 1);
396     y2 = (s.height() + y1 - 1);
397 }
398
399 inline bool QRect::contains(int ax, int ay, bool aproper) const
400 {
401     return contains(QPoint(ax, ay), aproper);
402 }
403
404 inline bool QRect::contains(int ax, int ay) const
405 {
406     return contains(QPoint(ax, ay), false);
407 }
408
409 inline QRect& QRect::operator|=(const QRect &r)
410 {
411     *this = *this | r;
412     return *this;
413 }
414
415 inline QRect& QRect::operator&=(const QRect &r)
416 {
417     *this = *this & r;
418     return *this;
419 }
420
421 inline QRect QRect::intersected(const QRect &other) const
422 {
423     return *this & other;
424 }
425
426 inline QRect QRect::united(const QRect &r) const
427 {
428     return *this | r;
429 }
430
431 Q_DECL_CONSTEXPR inline bool operator==(const QRect &r1, const QRect &r2)
432 {
433     return r1.x1==r2.x1 && r1.x2==r2.x2 && r1.y1==r2.y1 && r1.y2==r2.y2;
434 }
435
436 Q_DECL_CONSTEXPR inline bool operator!=(const QRect &r1, const QRect &r2)
437 {
438     return r1.x1!=r2.x1 || r1.x2!=r2.x2 || r1.y1!=r2.y1 || r1.y2!=r2.y2;
439 }
440
441 #ifndef QT_NO_DEBUG_STREAM
442 Q_CORE_EXPORT QDebug operator<<(QDebug, const QRect &);
443 #endif
444
445
446 class Q_CORE_EXPORT QRectF
447 {
448 public:
449     Q_DECL_CONSTEXPR QRectF() : xp(0.), yp(0.), w(0.), h(0.) {}
450     Q_DECL_CONSTEXPR QRectF(const QPointF &topleft, const QSizeF &size);
451     Q_DECL_CONSTEXPR QRectF(const QPointF &topleft, const QPointF &bottomRight);
452     Q_DECL_CONSTEXPR QRectF(qreal left, qreal top, qreal width, qreal height);
453     Q_DECL_CONSTEXPR QRectF(const QRect &rect);
454
455     Q_DECL_CONSTEXPR bool isNull() const;
456     Q_DECL_CONSTEXPR bool isEmpty() const;
457     Q_DECL_CONSTEXPR bool isValid() const;
458     QRectF normalized() const;
459
460     Q_DECL_CONSTEXPR inline qreal left() const { return xp; }
461     Q_DECL_CONSTEXPR inline qreal top() const { return yp; }
462     Q_DECL_CONSTEXPR inline qreal right() const { return xp + w; }
463     Q_DECL_CONSTEXPR inline qreal bottom() const { return yp + h; }
464
465     Q_DECL_CONSTEXPR inline qreal x() const;
466     Q_DECL_CONSTEXPR inline qreal y() const;
467     inline void setLeft(qreal pos);
468     inline void setTop(qreal pos);
469     inline void setRight(qreal pos);
470     inline void setBottom(qreal pos);
471     inline void setX(qreal pos) { setLeft(pos); }
472     inline void setY(qreal pos) { setTop(pos); }
473
474     Q_DECL_CONSTEXPR inline QPointF topLeft() const { return QPointF(xp, yp); }
475     Q_DECL_CONSTEXPR inline QPointF bottomRight() const { return QPointF(xp+w, yp+h); }
476     Q_DECL_CONSTEXPR inline QPointF topRight() const { return QPointF(xp+w, yp); }
477     Q_DECL_CONSTEXPR inline QPointF bottomLeft() const { return QPointF(xp, yp+h); }
478     Q_DECL_CONSTEXPR inline QPointF center() const;
479
480     void setTopLeft(const QPointF &p);
481     void setBottomRight(const QPointF &p);
482     void setTopRight(const QPointF &p);
483     void setBottomLeft(const QPointF &p);
484
485     void moveLeft(qreal pos);
486     void moveTop(qreal pos);
487     void moveRight(qreal pos);
488     void moveBottom(qreal pos);
489     void moveTopLeft(const QPointF &p);
490     void moveBottomRight(const QPointF &p);
491     void moveTopRight(const QPointF &p);
492     void moveBottomLeft(const QPointF &p);
493     void moveCenter(const QPointF &p);
494
495     void translate(qreal dx, qreal dy);
496     void translate(const QPointF &p);
497
498     Q_DECL_CONSTEXPR QRectF translated(qreal dx, qreal dy) const;
499     Q_DECL_CONSTEXPR QRectF translated(const QPointF &p) const;
500
501     void moveTo(qreal x, qreal t);
502     void moveTo(const QPointF &p);
503
504     void setRect(qreal x, qreal y, qreal w, qreal h);
505     void getRect(qreal *x, qreal *y, qreal *w, qreal *h) const;
506
507     void setCoords(qreal x1, qreal y1, qreal x2, qreal y2);
508     void getCoords(qreal *x1, qreal *y1, qreal *x2, qreal *y2) const;
509
510     inline void adjust(qreal x1, qreal y1, qreal x2, qreal y2);
511     Q_DECL_CONSTEXPR inline QRectF adjusted(qreal x1, qreal y1, qreal x2, qreal y2) const;
512
513     Q_DECL_CONSTEXPR QSizeF size() const;
514     Q_DECL_CONSTEXPR qreal width() const;
515     Q_DECL_CONSTEXPR qreal height() const;
516     void setWidth(qreal w);
517     void setHeight(qreal h);
518     void setSize(const QSizeF &s);
519
520     QRectF operator|(const QRectF &r) const;
521     QRectF operator&(const QRectF &r) const;
522     QRectF& operator|=(const QRectF &r);
523     QRectF& operator&=(const QRectF &r);
524
525     bool contains(const QPointF &p) const;
526     bool contains(qreal x, qreal y) const;
527     bool contains(const QRectF &r) const;
528     QRectF united(const QRectF &other) const;
529     QRectF intersected(const QRectF &other) const;
530     bool intersects(const QRectF &r) const;
531
532 #if QT_DEPRECATED_SINCE(5, 0)
533     QT_DEPRECATED QRectF unite(const QRectF &r) const { return united(r); }
534     QT_DEPRECATED QRectF intersect(const QRectF &r) const { return intersected(r); }
535 #endif
536
537     friend Q_CORE_EXPORT_INLINE Q_DECL_CONSTEXPR bool operator==(const QRectF &, const QRectF &);
538     friend Q_CORE_EXPORT_INLINE Q_DECL_CONSTEXPR bool operator!=(const QRectF &, const QRectF &);
539
540     Q_DECL_CONSTEXPR QRect toRect() const;
541     QRect toAlignedRect() const;
542
543 private:
544     qreal xp;
545     qreal yp;
546     qreal w;
547     qreal h;
548 };
549 Q_DECLARE_TYPEINFO(QRectF, Q_MOVABLE_TYPE);
550
551 Q_CORE_EXPORT_INLINE Q_DECL_CONSTEXPR bool operator==(const QRectF &, const QRectF &);
552 Q_CORE_EXPORT_INLINE Q_DECL_CONSTEXPR bool operator!=(const QRectF &, const QRectF &);
553
554
555 /*****************************************************************************
556   QRectF stream functions
557  *****************************************************************************/
558 #ifndef QT_NO_DATASTREAM
559 Q_CORE_EXPORT QDataStream &operator<<(QDataStream &, const QRectF &);
560 Q_CORE_EXPORT QDataStream &operator>>(QDataStream &, QRectF &);
561 #endif
562
563 /*****************************************************************************
564   QRectF inline member functions
565  *****************************************************************************/
566
567 Q_DECL_CONSTEXPR inline QRectF::QRectF(qreal aleft, qreal atop, qreal awidth, qreal aheight)
568     : xp(aleft), yp(atop), w(awidth), h(aheight)
569 {
570 }
571
572 Q_DECL_CONSTEXPR inline QRectF::QRectF(const QPointF &atopLeft, const QSizeF &asize)
573     : xp(atopLeft.x()), yp(atopLeft.y()), w(asize.width()), h(asize.height())
574 {
575 }
576
577
578 Q_DECL_CONSTEXPR inline QRectF::QRectF(const QPointF &atopLeft, const QPointF &abottomRight)
579     : xp(atopLeft.x()), yp(atopLeft.y()), w(abottomRight.x() - atopLeft.x()), h(abottomRight.y() - atopLeft.y())
580 {
581 }
582
583 Q_DECL_CONSTEXPR inline QRectF::QRectF(const QRect &r)
584     : xp(r.x()), yp(r.y()), w(r.width()), h(r.height())
585 {
586 }
587
588 Q_DECL_CONSTEXPR inline bool QRectF::isNull() const
589 { return w == 0. && h == 0.; }
590
591 Q_DECL_CONSTEXPR inline bool QRectF::isEmpty() const
592 { return w <= 0. || h <= 0.; }
593
594 Q_DECL_CONSTEXPR inline bool QRectF::isValid() const
595 { return w > 0. && h > 0.; }
596
597 Q_DECL_CONSTEXPR inline qreal QRectF::x() const
598 { return xp; }
599
600 Q_DECL_CONSTEXPR inline qreal QRectF::y() const
601 { return yp; }
602
603 inline void QRectF::setLeft(qreal pos) { qreal diff = pos - xp; xp += diff; w -= diff; }
604
605 inline void QRectF::setRight(qreal pos) { w = pos - xp; }
606
607 inline void QRectF::setTop(qreal pos) { qreal diff = pos - yp; yp += diff; h -= diff; }
608
609 inline void QRectF::setBottom(qreal pos) { h = pos - yp; }
610
611 inline void QRectF::setTopLeft(const QPointF &p) { setLeft(p.x()); setTop(p.y()); }
612
613 inline void QRectF::setTopRight(const QPointF &p) { setRight(p.x()); setTop(p.y()); }
614
615 inline void QRectF::setBottomLeft(const QPointF &p) { setLeft(p.x()); setBottom(p.y()); }
616
617 inline void QRectF::setBottomRight(const QPointF &p) { setRight(p.x()); setBottom(p.y()); }
618
619 Q_DECL_CONSTEXPR inline QPointF QRectF::center() const
620 { return QPointF(xp + w/2, yp + h/2); }
621
622 inline void QRectF::moveLeft(qreal pos) { xp = pos; }
623
624 inline void QRectF::moveTop(qreal pos) { yp = pos; }
625
626 inline void QRectF::moveRight(qreal pos) { xp = pos - w; }
627
628 inline void QRectF::moveBottom(qreal pos) { yp = pos - h; }
629
630 inline void QRectF::moveTopLeft(const QPointF &p) { moveLeft(p.x()); moveTop(p.y()); }
631
632 inline void QRectF::moveTopRight(const QPointF &p) { moveRight(p.x()); moveTop(p.y()); }
633
634 inline void QRectF::moveBottomLeft(const QPointF &p) { moveLeft(p.x()); moveBottom(p.y()); }
635
636 inline void QRectF::moveBottomRight(const QPointF &p) { moveRight(p.x()); moveBottom(p.y()); }
637
638 inline void QRectF::moveCenter(const QPointF &p) { xp = p.x() - w/2; yp = p.y() - h/2; }
639
640 Q_DECL_CONSTEXPR inline qreal QRectF::width() const
641 { return w; }
642
643 Q_DECL_CONSTEXPR inline qreal QRectF::height() const
644 { return h; }
645
646 Q_DECL_CONSTEXPR inline QSizeF QRectF::size() const
647 { return QSizeF(w, h); }
648
649 inline void QRectF::translate(qreal dx, qreal dy)
650 {
651     xp += dx;
652     yp += dy;
653 }
654
655 inline void QRectF::translate(const QPointF &p)
656 {
657     xp += p.x();
658     yp += p.y();
659 }
660
661 inline void QRectF::moveTo(qreal ax, qreal ay)
662 {
663     xp = ax;
664     yp = ay;
665 }
666
667 inline void QRectF::moveTo(const QPointF &p)
668 {
669     xp = p.x();
670     yp = p.y();
671 }
672
673 Q_DECL_CONSTEXPR inline QRectF QRectF::translated(qreal dx, qreal dy) const
674 { return QRectF(xp + dx, yp + dy, w, h); }
675
676 Q_DECL_CONSTEXPR inline QRectF QRectF::translated(const QPointF &p) const
677 { return QRectF(xp + p.x(), yp + p.y(), w, h); }
678
679 inline void QRectF::getRect(qreal *ax, qreal *ay, qreal *aaw, qreal *aah) const
680 {
681     *ax = this->xp;
682     *ay = this->yp;
683     *aaw = this->w;
684     *aah = this->h;
685 }
686
687 inline void QRectF::setRect(qreal ax, qreal ay, qreal aaw, qreal aah)
688 {
689     this->xp = ax;
690     this->yp = ay;
691     this->w = aaw;
692     this->h = aah;
693 }
694
695 inline void QRectF::getCoords(qreal *xp1, qreal *yp1, qreal *xp2, qreal *yp2) const
696 {
697     *xp1 = xp;
698     *yp1 = yp;
699     *xp2 = xp + w;
700     *yp2 = yp + h;
701 }
702
703 inline void QRectF::setCoords(qreal xp1, qreal yp1, qreal xp2, qreal yp2)
704 {
705     xp = xp1;
706     yp = yp1;
707     w = xp2 - xp1;
708     h = yp2 - yp1;
709 }
710
711 inline void QRectF::adjust(qreal xp1, qreal yp1, qreal xp2, qreal yp2)
712 { xp += xp1; yp += yp1; w += xp2 - xp1; h += yp2 - yp1; }
713
714 Q_DECL_CONSTEXPR inline QRectF QRectF::adjusted(qreal xp1, qreal yp1, qreal xp2, qreal yp2) const
715 { return QRectF(xp + xp1, yp + yp1, w + xp2 - xp1, h + yp2 - yp1); }
716
717 inline void QRectF::setWidth(qreal aw)
718 { this->w = aw; }
719
720 inline void QRectF::setHeight(qreal ah)
721 { this->h = ah; }
722
723 inline void QRectF::setSize(const QSizeF &s)
724 {
725     w = s.width();
726     h = s.height();
727 }
728
729 inline bool QRectF::contains(qreal ax, qreal ay) const
730 {
731     return contains(QPointF(ax, ay));
732 }
733
734 inline QRectF& QRectF::operator|=(const QRectF &r)
735 {
736     *this = *this | r;
737     return *this;
738 }
739
740 inline QRectF& QRectF::operator&=(const QRectF &r)
741 {
742     *this = *this & r;
743     return *this;
744 }
745
746 inline QRectF QRectF::intersected(const QRectF &r) const
747 {
748     return *this & r;
749 }
750
751 inline QRectF QRectF::united(const QRectF &r) const
752 {
753     return *this | r;
754 }
755
756 Q_DECL_CONSTEXPR inline bool operator==(const QRectF &r1, const QRectF &r2)
757 {
758     return qFuzzyCompare(r1.xp, r2.xp) && qFuzzyCompare(r1.yp, r2.yp)
759            && qFuzzyCompare(r1.w, r2.w) && qFuzzyCompare(r1.h, r2.h);
760 }
761
762 Q_DECL_CONSTEXPR inline bool operator!=(const QRectF &r1, const QRectF &r2)
763 {
764     return !qFuzzyCompare(r1.xp, r2.xp) || !qFuzzyCompare(r1.yp, r2.yp)
765            || !qFuzzyCompare(r1.w, r2.w) || !qFuzzyCompare(r1.h, r2.h);
766 }
767
768 Q_DECL_CONSTEXPR inline QRect QRectF::toRect() const
769 {
770     return QRect(qRound(xp), qRound(yp), qRound(w), qRound(h));
771 }
772
773 #ifndef QT_NO_DEBUG_STREAM
774 Q_CORE_EXPORT QDebug operator<<(QDebug, const QRectF &);
775 #endif
776
777 QT_END_NAMESPACE
778
779 QT_END_HEADER
780
781 #endif // QRECT_H