Home | All Classes | Main Classes | Annotated | Grouped Classes | Functions

TQRect Class Reference

The TQRect class defines a rectangle in the plane. More...

#include <qrect.h>

List of all member functions.

Public Members

Related Functions


Detailed Description

The TQRect class defines a rectangle in the plane.

A rectangle is internally represented as an upper-left corner and a bottom-right corner, but it is normally expressed as an upper-left corner and a size.

The coordinate type is TQCOORD (defined in qwindowdefs.h as int). The minimum value of TQCOORD is TQCOORD_MIN (-2147483648) and the maximum value is TQCOORD_MAX (2147483647).

Note that the size (width and height) of a rectangle might be different from what you are used to. If the top-left corner and the bottom-right corner are the same, the height and the width of the rectangle will both be 1.

Generally, width = right - left + 1 and height = bottom - top + 1. We designed it this way to make it correspond to rectangular spaces used by drawing functions in which the width and height denote a number of pixels. For example, drawing a rectangle with width and height 1 draws a single pixel.

The default coordinate system has origin (0, 0) in the top-left corner. The positive direction of the y axis is down, and the positive x axis is from left to right.

A TQRect can be constructed with a set of left, top, width and height integers, from two TQPoints or from a TQPoint and a TQSize. After creation the dimensions can be changed, e.g. with setLeft(), setRight(), setTop() and setBottom(), or by setting sizes, e.g. setWidth(), setHeight() and setSize(). The dimensions can also be changed with the move functions, e.g. moveBy(), moveCenter(), moveBottomRight(), etc. You can also add coordinates to a rectangle with addCoords().

You can test to see if a TQRect contains a specific point with contains(). You can also test to see if two TQRects intersect with intersects() (see also intersect()). To get the bounding rectangle of two TQRects use unite().

See also TQPoint, TQSize, Graphics Classes, and Image Processing Classes.


Member Function Documentation

TQRect::TQRect ()

Constructs an invalid rectangle.

TQRect::TQRect ( const TQPoint & topLeft, const TQPoint & bottomRight )

Constructs a rectangle with topLeft as the top-left corner and bottomRight as the bottom-right corner.

TQRect::TQRect ( const TQPoint & topLeft, const TQSize & size )

Constructs a rectangle with topLeft as the top-left corner and size as the rectangle size.

TQRect::TQRect ( int left, int top, int width, int height )

Constructs a rectangle with the top, left corner and width and height.

Example (creates three identical rectangles):

        TQRect r1( TQPoint(100,200), TQPoint(110,215) );
        TQRect r2( TQPoint(100,200), TQSize(11,16) );
        TQRect r3( 100, 200, 11, 16 );
    

void TQRect::addCoords ( int xp1, int yp1, int xp2, int yp2 )

Adds xp1, yp1, xp2 and yp2 respectively to the existing coordinates of the rectangle.

Examples: multiple/ax1.h and multiple/ax2.h.

int TQRect::bottom () const

Returns the bottom coordinate of the rectangle.

See also setBottom(), top(), bottomLeft(), and bottomRight().

Examples: action/application.cpp, application/application.cpp, desktop/desktop.cpp, helpviewer/helpwindow.cpp, qfd/fontdisplayer.cpp, scribble/scribble.cpp, and themes/wood.cpp.

TQPoint TQRect::bottomLeft () const

Returns the bottom-left position of the rectangle.

See also setBottomLeft(), moveBottomLeft(), topRight(), bottom(), and left().

Example: tictac/tictac.cpp.

TQPoint TQRect::bottomRight () const

Returns the bottom-right position of the rectangle.

See also setBottomRight(), moveBottomRight(), topLeft(), right(), and bottom().

Example: tictac/tictac.cpp.

TQPoint TQRect::center () const

Returns the center point of the rectangle.

See also moveCenter(), topLeft(), bottomRight(), topRight(), and bottomLeft().

Example: tooltip/tooltip.cpp.

bool TQRect::contains ( const TQPoint & p, bool proper = FALSE ) const

Returns TRUE if the point p is inside or on the edge of the rectangle; otherwise returns FALSE.

If proper is TRUE, this function returns TRUE only if p is inside (not on the edge).

Example: t14/cannon.cpp.

bool TQRect::contains ( int x, int y ) const

This is an overloaded member function, provided for convenience. It behaves essentially like the above function.

Returns TRUE if the point x, y is inside this rectangle; otherwise returns FALSE.

bool TQRect::contains ( int x, int y, bool proper ) const

This is an overloaded member function, provided for convenience. It behaves essentially like the above function.

Returns TRUE if the point x, y is inside this rectangle; otherwise returns FALSE.

If proper is TRUE, this function returns TRUE only if the point is entirely inside (not on the edge).

bool TQRect::contains ( const TQRect & r, bool proper = FALSE ) const

This is an overloaded member function, provided for convenience. It behaves essentially like the above function.

Returns TRUE if the rectangle r is inside this rectangle; otherwise returns FALSE.

If proper is TRUE, this function returns TRUE only if r is entirely inside (not on the edge).

See also unite(), intersect(), and intersects().

void TQRect::coords ( int * xp1, int * yp1, int * xp2, int * yp2 ) const

Extracts the rectangle parameters as the top-left point *xp1, *yp1 and the bottom-right point *xp2, *yp2.

See also setCoords() and rect().

Examples: themes/metal.cpp and themes/wood.cpp.

int TQRect::height () const

Returns the height of the rectangle. The height includes both the top and bottom edges, i.e. height = bottom - top + 1.

See also width(), size(), and setHeight().

Examples: aclock/aclock.cpp, desktop/desktop.cpp, movies/main.cpp, scribble/scribble.cpp, themes/metal.cpp, themes/wood.cpp, and xform/xform.cpp.

TQRect TQRect::intersect ( const TQRect & r ) const

Returns the intersection of this rectangle and rectangle r. r.intersect(s) is equivalent to r&s.

bool TQRect::intersects ( const TQRect & r ) const

Returns TRUE if this rectangle intersects with rectangle r (there is at least one pixel that is within both rectangles); otherwise returns FALSE.

See also intersect() and contains().

Examples: t11/cannon.cpp, t12/cannon.cpp, t13/cannon.cpp, and t14/cannon.cpp.

bool TQRect::isEmpty () const

Returns TRUE if the rectangle is empty; otherwise returns FALSE.

An empty rectangle has a left() > right() or top() > bottom().

An empty rectangle is not valid. isEmpty() == !isValid()

See also isNull(), isValid(), and normalize().

bool TQRect::isNull () const

Returns TRUE if the rectangle is a null rectangle; otherwise returns FALSE.

A null rectangle has both the width and the height set to 0, that is right() == left() - 1 and bottom() == top() - 1.

Note that if right() == left() and bottom() == top(), then the rectangle has width 1 and height 1.

A null rectangle is also empty.

A null rectangle is not valid.

See also isEmpty() and isValid().

bool TQRect::isValid () const

Returns TRUE if the rectangle is valid; otherwise returns FALSE.

A valid rectangle has a left() <= right() and top() <= bottom().

Note that non-trivial operations like intersections are not defined for invalid rectangles.

isValid() == !isEmpty()

See also isNull(), isEmpty(), and normalize().

Examples: themes/metal.cpp and tooltip/tooltip.cpp.

int TQRect::left () const

Returns the left coordinate of the rectangle. Identical to x().

See also setLeft(), right(), topLeft(), and bottomLeft().

Examples: aclock/aclock.cpp, desktop/desktop.cpp, i18n/main.cpp, scribble/scribble.cpp, tictac/tictac.cpp, and xform/xform.cpp.

void TQRect::moveBottom ( int pos )

Sets the bottom position of the rectangle to pos, leaving the size unchanged.

See also bottom(), setBottom(), moveLeft(), moveTop(), and moveRight().

void TQRect::moveBottomLeft ( const TQPoint & p )

Sets the bottom-left position of the rectangle to p, leaving the size unchanged.

See also bottomLeft(), setBottomLeft(), moveTopLeft(), moveBottomRight(), and moveTopRight().

Example: t10/cannon.cpp.

void TQRect::moveBottomRight ( const TQPoint & p )

Sets the bottom-right position of the rectangle to p, leaving the size unchanged.

See also bottomRight(), setBottomRight(), moveTopLeft(), moveTopRight(), and moveBottomLeft().

void TQRect::moveBy ( int dx, int dy )

Moves the rectangle dx along the x axis and dy along the y axis, relative to the current position. Positive values move the rectangle to the right and down.

See also moveTopLeft().

Examples: action/application.cpp, application/application.cpp, helpviewer/helpwindow.cpp, mdi/application.cpp, themes/wood.cpp, and xform/xform.cpp.

void TQRect::moveCenter ( const TQPoint & p )

Sets the center point of the rectangle to p, leaving the size unchanged.

See also center(), moveTopLeft(), moveBottomRight(), moveTopRight(), and moveBottomLeft().

Examples: t11/cannon.cpp and t12/cannon.cpp.

void TQRect::moveLeft ( int pos )

Sets the left position of the rectangle to pos, leaving the size unchanged.

See also left(), setLeft(), moveTop(), moveRight(), and moveBottom().

void TQRect::moveRight ( int pos )

Sets the right position of the rectangle to pos, leaving the size unchanged.

See also right(), setRight(), moveLeft(), moveTop(), and moveBottom().

void TQRect::moveTop ( int pos )

Sets the top position of the rectangle to pos, leaving the size unchanged.

See also top(), setTop(), moveLeft(), moveRight(), and moveBottom().

void TQRect::moveTopLeft ( const TQPoint & p )

Sets the top-left position of the rectangle to p, leaving the size unchanged.

See also topLeft(), setTopLeft(), moveBottomRight(), moveTopRight(), and moveBottomLeft().

Examples: helpsystem/tooltip.cpp and xform/xform.cpp.

void TQRect::moveTopRight ( const TQPoint & p )

Sets the top-right position of the rectangle to p, leaving the size unchanged.

See also topRight(), setTopRight(), moveTopLeft(), moveBottomRight(), and moveBottomLeft().

TQRect TQRect::normalize () const

Returns a normalized rectangle, i.e. a rectangle that has a non-negative width and height.

It swaps left and right if left() > right(), and swaps top and bottom if top() > bottom().

See also isValid().

Example: scribble/scribble.cpp.

TQRect TQRect::operator& ( const TQRect & r ) const

Returns the intersection of this rectangle and rectangle r.

Returns an empty rectangle if there is no intersection.

See also operator&=(), operator|(), isEmpty(), intersects(), and contains().

TQRect & TQRect::operator&= ( const TQRect & r )

Intersects this rectangle with rectangle r.

TQRect TQRect::operator| ( const TQRect & r ) const

Returns the bounding rectangle of this rectangle and rectangle r.

The bounding rectangle of a nonempty rectangle and an empty or invalid rectangle is defined to be the nonempty rectangle.

See also operator|=(), operator&(), intersects(), and contains().

TQRect & TQRect::operator|= ( const TQRect & r )

Unites this rectangle with rectangle r.

TQCOORD & TQRect::rBottom ()

Returns a reference to the bottom coordinate of the rectangle.

See also rLeft(), rTop(), and rRight().

TQCOORD & TQRect::rLeft ()

Returns a reference to the left coordinate of the rectangle.

See also rTop(), rRight(), and rBottom().

TQCOORD & TQRect::rRight ()

Returns a reference to the right coordinate of the rectangle.

See also rLeft(), rTop(), and rBottom().

TQCOORD & TQRect::rTop ()

Returns a reference to the top coordinate of the rectangle.

See also rLeft(), rRight(), and rBottom().

void TQRect::rect ( int * x, int * y, int * w, int * h ) const

Extracts the rectangle parameters as the position *x, *y and width *w and height *h.

See also setRect() and coords().

Examples: themes/metal.cpp and themes/wood.cpp.

int TQRect::right () const

Returns the right coordinate of the rectangle.

See also setRight(), left(), topRight(), and bottomRight().

Examples: action/application.cpp, application/application.cpp, customlayout/flow.cpp, desktop/desktop.cpp, scribble/scribble.cpp, t11/cannon.cpp, and themes/wood.cpp.

void TQRect::setBottom ( int pos )

Sets the bottom edge of the rectangle to pos. May change the height, but will never change the top edge of the rectangle.

See also bottom(), setTop(), and setHeight().

Example: scribble/scribble.cpp.

void TQRect::setBottomLeft ( const TQPoint & p )

Set the bottom-left corner of the rectangle to p. May change the size, but will the never change the top-right corner of the rectangle.

See also bottomLeft(), moveBottomLeft(), setTopLeft(), setBottomRight(), and setTopRight().

void TQRect::setBottomRight ( const TQPoint & p )

Set the bottom-right corner of the rectangle to p. May change the size, but will the never change the top-left corner of the rectangle.

See also bottomRight(), moveBottomRight(), setTopLeft(), setTopRight(), and setBottomLeft().

void TQRect::setCoords ( int xp1, int yp1, int xp2, int yp2 )

Sets the coordinates of the rectangle's top-left corner to (xp1, yp1), and the coordinates of its bottom-right corner to (xp2, yp2).

See also coords() and setRect().

void TQRect::setHeight ( int h )

Sets the height of the rectangle to h. The top edge is not moved, but the bottom edge may be moved.

See also height(), setTop(), setBottom(), and setSize().

Example: desktop/desktop.cpp.

void TQRect::setLeft ( int pos )

Sets the left edge of the rectangle to pos. May change the width, but will never change the right edge of the rectangle.

Identical to setX().

See also left(), setTop(), and setWidth().

Example: scribble/scribble.cpp.

void TQRect::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 (w, h).

See also rect() and setCoords().

Example: themes/wood.cpp.

void TQRect::setRight ( int pos )

Sets the right edge of the rectangle to pos. May change the width, but will never change the left edge of the rectangle.

See also right(), setLeft(), and setWidth().

Example: scribble/scribble.cpp.

void TQRect::setSize ( const TQSize & s )

Sets the size of the rectangle to s. The top-left corner is not moved.

See also size(), setWidth(), and setHeight().

Example: xform/xform.cpp.

void TQRect::setTop ( int pos )

Sets the top edge of the rectangle to pos. May change the height, but will never change the bottom edge of the rectangle.

Identical to setY().

See also top(), setBottom(), and setHeight().

Example: scribble/scribble.cpp.

void TQRect::setTopLeft ( const TQPoint & p )

Set the top-left corner of the rectangle to p. May change the size, but will the never change the bottom-right corner of the rectangle.

See also topLeft(), moveTopLeft(), setBottomRight(), setTopRight(), and setBottomLeft().

void TQRect::setTopRight ( const TQPoint & p )

Set the top-right corner of the rectangle to p. May change the size, but will the never change the bottom-left corner of the rectangle.

See also topRight(), moveTopRight(), setTopLeft(), setBottomRight(), and setBottomLeft().

void TQRect::setWidth ( int w )

Sets the width of the rectangle to w. The right edge is changed, but not the left edge.

See also width(), setLeft(), setRight(), and setSize().

Example: desktop/desktop.cpp.

void TQRect::setX ( int x )

Sets the x position of the rectangle (its left end) to x. May change the width, but will never change the right edge of the rectangle.

Identical to setLeft().

See also x() and setY().

void TQRect::setY ( int y )

Sets the y position of the rectangle (its top) to y. May change the height, but will never change the bottom edge of the rectangle.

Identical to setTop().

See also y() and setX().

TQSize TQRect::size () const

Returns the size of the rectangle.

See also width() and height().

Examples: desktop/desktop.cpp, movies/main.cpp, and t10/cannon.cpp.

int TQRect::top () const

Returns the top coordinate of the rectangle. Identical to y().

See also setTop(), bottom(), topLeft(), and topRight().

Examples: aclock/aclock.cpp, desktop/desktop.cpp, scribble/scribble.cpp, themes/wood.cpp, tictac/tictac.cpp, and xform/xform.cpp.

TQPoint TQRect::topLeft () const

Returns the top-left position of the rectangle.

See also setTopLeft(), moveTopLeft(), bottomRight(), left(), and top().

Examples: helpsystem/tooltip.cpp, t10/cannon.cpp, and tictac/tictac.cpp.

TQPoint TQRect::topRight () const

Returns the top-right position of the rectangle.

See also setTopRight(), moveTopRight(), bottomLeft(), top(), and right().

Example: tictac/tictac.cpp.

TQRect TQRect::unite ( const TQRect & r ) const

Returns the bounding rectangle of this rectangle and rectangle r. r.unite(s) is equivalent to r|s.

Examples: t11/cannon.cpp, t12/cannon.cpp, and xform/xform.cpp.

int TQRect::width () const

Returns the width of the rectangle. The width includes both the left and right edges, i.e. width = right - left + 1.

See also height(), size(), and setHeight().

Examples: aclock/aclock.cpp, customlayout/border.cpp, desktop/desktop.cpp, movies/main.cpp, themes/metal.cpp, themes/wood.cpp, and xform/xform.cpp.

int TQRect::x () const

Returns the left coordinate of the rectangle. Identical to left().

See also left(), y(), and setX().

Examples: customlayout/border.cpp, desktop/desktop.cpp, movies/main.cpp, scribble/scribble.cpp, t12/cannon.cpp, themes/metal.cpp, and themes/wood.cpp.

int TQRect::y () const

Returns the top coordinate of the rectangle. Identical to top().

See also top(), x(), and setY().

Examples: desktop/desktop.cpp, movies/main.cpp, scribble/scribble.cpp, t12/cannon.cpp, t14/cannon.cpp, themes/metal.cpp, and themes/wood.cpp.


Related Functions

bool operator!= ( const TQRect & r1, const TQRect & r2 )

Returns TRUE if r1 and r2 are different; otherwise returns FALSE.

TQDataStream & operator<< ( TQDataStream & s, const TQRect & r )

Writes the TQRect, r, to the stream s, and returns a reference to the stream.

See also Format of the TQDataStream operators.

bool operator== ( const TQRect & r1, const TQRect & r2 )

Returns TRUE if r1 and r2 are equal; otherwise returns FALSE.

TQDataStream & operator>> ( TQDataStream & s, TQRect & r )

Reads a TQRect from the stream s into rect r and returns a reference to the stream.

See also Format of the TQDataStream operators.


This file is part of the TQt toolkit. Copyright © 1995-2007 Trolltech. All Rights Reserved.


Copyright © 2007 TrolltechTrademarks
TQt 3.3.8