45 #include <QtCore/qsize.h> 46 #include <QtCore/qpoint.h> 49 #error qrect.h must be included before any header file that defines topLeft 61 QRect() { x1 = y1 = 0; x2 = y2 = -1; }
64 QRect(
int left,
int top,
int width,
int height);
74 QRect normalized()
const;
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; }
82 QT3_SUPPORT QRect
normalize()
const {
return normalized(); }
87 void setLeft(
int pos);
89 void setRight(
int pos);
90 void setBottom(
int pos);
94 void setTopLeft(
const QPoint &p);
95 void setBottomRight(
const QPoint &p);
96 void setTopRight(
const QPoint &p);
97 void setBottomLeft(
const QPoint &p);
100 QPoint bottomRight()
const;
102 QPoint bottomLeft()
const;
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);
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;
120 void moveTo(
int x,
int t);
121 void moveTo(
const QPoint &p);
124 QT3_SUPPORT
void moveBy(
int dx,
int dy) { translate(dx, dy); }
125 QT3_SUPPORT
void moveBy(
const QPoint &p) { translate(p); }
128 void setRect(
int x,
int y,
int w,
int h);
129 inline void getRect(
int *x,
int *y,
int *w,
int *h)
const;
131 void setCoords(
int x1,
int y1,
int x2,
int y2);
133 QT3_SUPPORT
void addCoords(
int x1,
int y1,
int x2,
int y2);
135 inline void getCoords(
int *x1,
int *y1,
int *x2,
int *y2)
const;
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;
143 void setWidth(
int w);
144 void setHeight(
int h);
145 void setSize(
const QSize &s);
150 QRect& operator&=(
const QRect &r);
152 bool contains(
const QPoint &p,
bool proper=
false)
const;
153 bool contains(
int x,
int y)
const;
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;
157 QRect united(
const QRect &other)
const;
158 QRect intersect(
const QRect &r)
const;
159 QRect intersected(
const QRect &other)
const;
160 bool intersects(
const QRect &r)
const;
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); }
172 #if defined(Q_WS_X11) 173 friend void qt_setCoords(QRect *r,
int xp1,
int yp1,
int xp2,
int yp2);
176 #if defined(Q_OS_MAC) 198 #ifndef QT_NO_DATASTREAM 211 x2 = (aleft + awidth - 1);
212 y2 = (atop + aheight - 1);
219 x2 = abottomRight.
x();
220 y2 = abottomRight.
y();
232 {
return x2 ==
x1 - 1 &&
y2 ==
y1 - 1; }
271 {
x1 = p.
x();
y1 = p.
y(); }
274 {
x2 = p.
x();
y2 = p.
y(); }
277 {
x2 = p.
x();
y1 = p.
y(); }
280 {
x1 = p.
x();
y2 = p.
y(); }
304 {
return x2 -
x1 + 1; }
307 {
return y2 -
y1 + 1; }
351 {
x2 += (pos -
x1);
x1 = pos; }
354 {
y2 += (pos -
y1);
y1 = pos; }
425 inline void QRect::addCoords(
int dx1,
int dy1,
int dx2,
int dy2)
427 adjust(dx1, dy1, dx2, dy2);
443 {
x2 = (
x1 + w - 1); }
446 {
y2 = (
y1 + h - 1); }
506 #ifndef QT_NO_DEBUG_STREAM 602 QRect toRect()
const;
603 QRect toAlignedRect()
const;
620 #ifndef QT_NO_DATASTREAM 630 : xp(aleft), yp(atop), w(awidth), h(aheight)
646 w = abottomRight.
x() -
xp;
647 h = abottomRight.
y() -
yp;
656 {
return w == 0. &&
h == 0.; }
659 {
return w <= 0. ||
h <= 0.; }
662 {
return w > 0. &&
h > 0.; }
779 {
xp += xp1;
yp += yp1;
w += xp2 - xp1;
h += yp2 - yp1; }
782 {
return QRectF(
xp + xp1,
yp + yp1,
w + xp2 - xp1,
h + yp2 - yp1); }
850 #ifndef QT_NO_DEBUG_STREAM void setBottomRight(const QPointF &p)
Set the bottom-right corner of the rectangle to the given position.
The QDebug class provides an output stream for debugging information.
QPointF bottomRight() const
Returns the position of the rectangle's bottom-right corner.
void getRect(qreal *x, qreal *y, qreal *w, qreal *h) const
Extracts the position of the rectangle's top-left corner to *x and y, and its dimensions to *width an...
void moveTop(qreal pos)
Moves the rectangle vertically, leaving the rectangle's top line at the given y coordinate.
#define Q_CORE_EXPORT_INLINE
void moveBottomRight(const QPoint &p)
Moves the rectangle, leaving the bottom-right corner at the given position.
qreal y() const
Returns the y-coordinate of the rectangle's top edge.
void setTopLeft(const QPointF &p)
Set the top-left corner of the rectangle to the given position.
qreal right() const
Returns the x-coordinate of the rectangle's right edge.
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 ...
bool isNull() const
Returns true if the rectangle is a null rectangle, otherwise returns false.
void setHeight(int h)
Sets the height of the rectangle to the given height.
void setBottom(int pos)
Sets the bottom edge of the rectangle to the given y coordinate.
void setHeight(qreal h)
Sets the height of the rectangle to the given height.
#define QT_END_NAMESPACE
This macro expands to.
QRect operator &(const QRect &r) const
bool isValid() const
Returns true if the rectangle is valid, otherwise returns false.
void moveLeft(int pos)
Moves the rectangle horizontally, leaving the rectangle's left edge at the given x coordinate...
void moveLeft(qreal pos)
Moves the rectangle horizontally, leaving the rectangle's left edge at the given x coordinate...
void setLeft(qreal pos)
Sets the left edge of the rectangle to the given x coordinate.
QRect & operator|=(const QRect &r)
Unites this rectangle with the given rectangle.
void setX(qreal pos)
Sets the left edge of the rectangle to the given x coordinate.
QRectF & operator|=(const QRectF &r)
Unites this rectangle with the given rectangle.
void setTopRight(const QPoint &p)
Set the top-right corner of the rectangle to the given position.
qreal width() const
Returns the width.
QRect united(const QRect &other) const
Returns the bounding rectangle of this rectangle and the given rectangle.
void setTopRight(const QPointF &p)
Set the top-right corner of the rectangle to the given position.
The QPointF class defines a point in the plane using floating point precision.
QRect intersect(const QRect &r) const
Use intersected(rectangle) instead.
qreal height() const
Returns the height.
qreal left() const
Returns the x-coordinate of the rectangle's left edge.
friend Q_CORE_EXPORT_INLINE bool operator!=(const QRectF &, const QRectF &)
Returns true if the rectangles r1 and r2 are different, otherwise returns false.
void setBottomLeft(const QPointF &p)
Set the bottom-left corner of the rectangle to the given position.
QRect normalized() const
Returns a normalized rectangle; i.e., a rectangle that has a non-negative width and height...
void moveRight(int pos)
Moves the rectangle horizontally, leaving the rectangle's right edge at the given x coordinate...
void moveBottom(qreal pos)
Moves the rectangle vertically, leaving the rectangle's bottom edge at the given y coordinate...
QPointF topLeft() const
Returns the position of the rectangle's top-left corner.
int left() const
Returns the x-coordinate of the rectangle's left edge.
void getCoords(qreal *x1, qreal *y1, qreal *x2, qreal *y2) const
Extracts the position of the rectangle's top-left corner to *x1 and *y1, and the position of the bott...
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...
int width() const
Returns the width of the rectangle.
void setTop(qreal pos)
Sets the top edge of the rectangle to the given y coordinate.
void setBottom(qreal pos)
Sets the bottom edge of the rectangle to the given y coordinate.
friend Q_CORE_EXPORT_INLINE bool operator!=(const QRect &, const QRect &)
Returns true if the rectangles r1 and r2 are different, otherwise returns false.
static Q_DECL_CONSTEXPR bool qFuzzyCompare(double p1, double p2)
QRect intersected(const QRect &other) const
Returns the intersection of this rectangle and the given rectangle.
void moveTo(int x, int t)
Moves the rectangle, leaving the top-left corner at the given position (x, y).
QPointF bottomLeft() const
Returns the position of the rectangle's bottom-left corner.
int height() const
Returns the height of the rectangle.
void setY(int y)
Sets the top edge of the rectangle to the given y coordinate.
QRectF intersected(const QRectF &other) const
Returns the intersection of this rectangle and the given rectangle.
int bottom() const
Returns the y-coordinate of the rectangle's bottom edge.
void moveBottom(int pos)
Moves the rectangle vertically, leaving the rectangle's bottom edge at the given y coordinate...
QDataStream & operator<<(QDataStream &stream, const QRectF &rectangle)
Writes the rectangle to the stream, and returns a reference to the stream.
friend Q_CORE_EXPORT_INLINE bool operator==(const QRect &, const QRect &)
Returns true if the rectangles r1 and r2 are equal, otherwise returns false.
The QSizeF class defines the size of a two-dimensional object using floating point precision...
void setRight(qreal pos)
Sets the right edge of the rectangle to the given x coordinate.
QRect unite(const QRect &r) const
Use united(rectangle) instead.
void operator|=(ItemType::Ptr &op1, const ItemType::Ptr &op2)
Computes the union type of op1 and op2, and assigns it to op1.
qreal x() const
Returns the x-coordinate of this point.
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...
void getCoords(int *x1, int *y1, int *x2, int *y2) const
Extracts the position of the rectangle's top-left corner to *x1 and *y1, and the position of the bott...
int width() const
Returns the width.
QTextStream & right(QTextStream &stream)
Calls QTextStream::setFieldAlignment(QTextStream::AlignRight) on stream and returns stream...
#define QT_BEGIN_NAMESPACE
This macro expands to.
static void setCoords(GLfloat *coords, const QGLRect &rect)
The QRectF class defines a rectangle in the plane using floating point precision. ...
static bool isEmpty(const char *str)
QPoint bottomRight() const
Returns the position of the rectangle's bottom-right corner.
friend Q_CORE_EXPORT_INLINE bool operator==(const QRectF &, const QRectF &)
Returns true if the rectangles r1 and r2 are equal, otherwise returns false.
void setTop(int pos)
Sets the top edge of the rectangle to the given y coordinate.
QRect()
Constructs a null rectangle.
qreal height() const
Returns the height of the rectangle.
void moveTopRight(const QPoint &p)
Moves the rectangle, leaving the top-right corner at the given position.
QSize size() const
Returns the size of the rectangle.
void moveTopRight(const QPointF &p)
Moves the rectangle, leaving the top-right corner at the given position.
void adjust(int x1, int y1, int x2, int y2)
Adds dx1, dy1, dx2 and dy2 respectively to the existing coordinates of the rectangle.
void setRight(int pos)
Sets the right edge of the rectangle to the given x coordinate.
void moveTopLeft(const QPointF &p)
Moves the rectangle, leaving the top-left corner at the given position.
void setSize(const QSize &s)
Sets the size of the rectangle to the given size.
void setTopLeft(const QPoint &p)
Set the top-left corner of the rectangle to the given position.
qreal width() const
Returns the width of the rectangle.
void setRect(qreal x, qreal y, qreal w, qreal h)
Sets the coordinates of the rectangle's top-left corner to (x, y), and its size to the given width an...
void setCoords(int x1, int y1, int x2, int y2)
Sets the coordinates of the rectangle's top-left corner to (x1, y1), and the coordinates of its botto...
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 ...
void setBottomLeft(const QPoint &p)
Set the bottom-left corner of the rectangle to the given position.
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...
void setX(int x)
Sets the left edge of the rectangle to the given x coordinate.
QRect toRect() const
Returns a QRect based on the values of this rectangle.
QRectF()
Constructs a null rectangle.
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...
void setSize(const QSizeF &s)
Sets the size of the rectangle to the given size.
void setBottomRight(const QPoint &p)
Set the bottom-right corner of the rectangle to the given position.
void moveTopLeft(const QPoint &p)
Moves the rectangle, leaving the top-left corner at the given position.
void moveCenter(const QPoint &p)
Moves the rectangle, leaving the center point at the given position.
QDataStream & operator>>(QDataStream &stream, QRect &rectangle)
Reads a rectangle from the given stream into the given rectangle, and returns a reference to the stre...
void moveRight(qreal pos)
Moves the rectangle horizontally, leaving the rectangle's right edge at the given x coordinate...
QPoint topRight() const
Returns the position of the rectangle's top-right corner.
bool isEmpty() const
Returns true if the rectangle is empty, otherwise returns false.
QPoint center() const
Returns the center point of the rectangle.
void moveBottomLeft(const QPoint &p)
Moves the rectangle, leaving the bottom-left corner at the given position.
bool operator!=(const T *o, const QPointer< T > &p)
int top() const
Returns the y-coordinate of the rectangle's top edge.
int right() const
Returns the x-coordinate of the rectangle's right edge.
QPoint bottomLeft() const
Returns the position of the rectangle's bottom-left corner.
void setLeft(int pos)
Sets the left edge of the rectangle to the given x coordinate.
int y() const
Returns the y-coordinate of the rectangle's top edge.
qreal x() const
Returns the x-coordinate of the rectangle's left edge.
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.
int x() const
Returns the x-coordinate of the rectangle's left edge.
void setCoords(qreal x1, qreal y1, qreal x2, qreal y2)
Sets the coordinates of the rectangle's top-left corner to (x1, y1), and the coordinates of its botto...
void setRect(int x, int y, int w, int h)
Sets the coordinates of the rectangle's top-left corner to ({x}, {y}), and its size to the given widt...
The QPoint class defines a point in the plane using integer precision.
void moveBottomRight(const QPointF &p)
Moves the rectangle, leaving the bottom-right corner at the given position.
QRectF united(const QRectF &other) const
Returns the bounding rectangle of this rectangle and the given rectangle.
void setWidth(int w)
Sets the width of the rectangle to the given width.
int height() const
Returns the height.
The QRect class defines a rectangle in the plane using integer precision.
QRectF intersect(const QRectF &r) const
Use intersected(rectangle) instead.
void getRect(int *x, int *y, int *w, int *h) const
Extracts the position of the rectangle's top-left corner to *x and *y, and its dimensions to *width a...
QSizeF size() const
Returns the size of the rectangle.
void moveTo(qreal x, qreal t)
Moves the rectangle, leaving the top-left corner at the given position (x, y).
bool operator==(const T *o, const QPointer< T > &p)
void setY(qreal pos)
Sets the top edge of the rectangle to the given y coordinate.
int y() const
Returns the y coordinate of this point.
void moveBottomLeft(const QPointF &p)
Moves the rectangle, leaving the bottom-left corner at the given position.
qreal y() const
Returns the y-coordinate of this point.
QRectF & operator &=(const QRectF &r)
qreal top() const
Returns the y-coordinate of the rectangle's top edge.
The QSize class defines the size of a two-dimensional object using integer point precision.
void setWidth(qreal w)
Sets the width of the rectangle to the given width.
The QDataStream class provides serialization of binary data to a QIODevice.
bool intersects(const QRect &r) const
Returns true if this rectangle intersects with the given rectangle (i.
int x() const
Returns the x coordinate of this point.
qreal bottom() const
Returns the y-coordinate of the rectangle's bottom edge.
QRect operator|(const QRect &r) const
Returns the bounding rectangle of this rectangle and the given rectangle.
Q_DECLARE_TYPEINFO(QRect, Q_MOVABLE_TYPE)
void moveTop(int pos)
Moves the rectangle vertically, leaving the rectangle's top edge at the given y coordinate.
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...
bool isValid() const
Returns true if the rectangle is valid, otherwise returns false.
bool isEmpty() const
Returns true if the rectangle is empty, otherwise returns false.
QBitArray operator|(const QBitArray &a1, const QBitArray &a2)
Returns a bit array that is the OR of the bit arrays a1 and a2.
QPointF topRight() const
Returns the position of the rectangle's top-right corner.
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...
void moveCenter(const QPointF &p)
Moves the rectangle, leaving the center point at the given position.
QPointF center() const
Returns the center point of the rectangle.
QRectF unite(const QRectF &r) const
Use united(rectangle) instead.
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.
bool isNull() const
Returns true if the rectangle is a null rectangle, otherwise returns false.
QRect & operator &=(const QRect &r)
Q_DECL_CONSTEXPR int qRound(qreal d)
static bool isNull(const QVariant::Private *d)
QDataStream & operator<<(QDataStream &stream, const QRect &rectangle)
Writes the given rectangle to the given stream, and returns a reference to the stream.
QPoint topLeft() const
Returns the position of the rectangle's top-left corner.
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.