QtCanvasPolygonalItem Class Reference

The QtCanvasPolygonalItem class provides a polygonal canvas item on a QtCanvas. More...

#include <QtCanvasPolygonalItem>

Inherits QtCanvasItem.

Inherited by QtCanvasEllipse, QtCanvasLine, QtCanvasPolygon, and QtCanvasRectangle.

Public Functions

Protected Functions


Detailed Description

The QtCanvasPolygonalItem class provides a polygonal canvas item on a QtCanvas.

The mostly rectangular classes, such as QtCanvasSprite and QtCanvasText, use the object's bounding rectangle for movement, repainting and collision calculations. For most other items, the bounding rectangle can be far too large -- a diagonal line being the worst case, and there are many other cases which are also bad. QtCanvasPolygonalItem provides polygon-based bounding rectangle handling, etc., which is much faster for non-rectangular items.

Derived classes should try to define as small an area as possible to maximize efficiency, but the polygon must definitely be contained completely within the polygonal area. Calculating the exact requirements is usually difficult, but if you allow a small overestimate it can be easy and quick, while still getting almost all of QtCanvasPolygonalItem's speed.

Note that all subclasses must call hide() in their destructor since hide() needs to be able to access areaPoints().

Normally, QtCanvasPolygonalItem uses the odd-even algorithm for determining whether an object intersects this object. You can change this to the winding algorithm using setWinding().

The bounding rectangle is available using boundingRect(). The points bounding the polygonal item are retrieved with areaPoints(). Use areaPointsAdvanced() to retrieve the bounding points the polygonal item will have after QtCanvasItem::advance(1) has been called.

If the shape of the polygonal item is about to change while the item is visible, call invalidate() before updating with a different result from areaPoints().

By default, QtCanvasPolygonalItem objects have a black pen and no brush (the default QPen and QBrush constructors). You can change this with setPen() and setBrush(), but note that some QtCanvasPolygonalItem subclasses only use the brush, ignoring the pen setting.

The polygonal item can be drawn on a painter with draw(). Subclasses must reimplement drawShape() to draw themselves.

Like any other canvas item polygonal items can be moved with QtCanvasItem::move() and QtCanvasItem::moveBy(), or by setting coordinates with QtCanvasItem::setX(), QtCanvasItem::setY() and QtCanvasItem::setZ().


Member Function Documentation

QtCanvasPolygonalItem::QtCanvasPolygonalItem ( QtCanvas * canvas )

Constructs a QtCanvasPolygonalItem on the canvas canvas.

QtCanvasPolygonalItem::~QtCanvasPolygonalItem ()   [virtual]

Note that all subclasses must call hide() in their destructor since hide() needs to be able to access areaPoints().

QPolygon QtCanvasPolygonalItem::areaPoints () const   [pure virtual]

This function must be reimplemented by subclasses. It must return the points bounding (i.e. outside and not touching) the shape or drawing errors will occur.

QPolygon QtCanvasPolygonalItem::areaPointsAdvanced () const   [virtual]

Returns the points the polygonal item will have after QtCanvasItem::advance(1) is called, i.e. what the points are when advanced by the current xVelocity() and yVelocity().

QRect QtCanvasPolygonalItem::boundingRect () const   [virtual]

Returns the bounding rectangle of the polygonal item, based on areaPoints().

Reimplemented from QtCanvasItem.

QBrush QtCanvasPolygonalItem::brush () const

Returns the QBrush used to fill the item, if filled.

See also setBrush().

void QtCanvasPolygonalItem::draw ( QPainter & p )   [virtual protected]

Reimplemented from QtCanvasItem, this draws the polygonal item by setting the pen and brush for the item on the painter p and calling drawShape().

Reimplemented from QtCanvasItem.

void QtCanvasPolygonalItem::drawShape ( QPainter & p )   [pure virtual protected]

Subclasses must reimplement this function to draw their shape. The pen and brush of p are already set to pen() and brush() prior to calling this function.

See also draw().

void QtCanvasPolygonalItem::invalidate ()   [protected]

Invalidates all information about the area covered by the canvas item. The item will be updated automatically on the next call that changes the item's status, for example, move() or update(). Call this function if you are going to change the shape of the item (as returned by areaPoints()) while the item is visible.

bool QtCanvasPolygonalItem::isValid () const   [protected]

Returns true if the polygonal item's area information has not been invalidated; otherwise returns false.

See also invalidate().

QPen QtCanvasPolygonalItem::pen () const

Returns the QPen used to draw the outline of the item, if any.

See also setPen().

int QtCanvasPolygonalItem::rtti () const   [virtual]

Returns 2 (QtCanvasItem::Rtti_PolygonalItem).

Reimplemented from QtCanvasItem.

See also QtCanvasItem::rtti().

void QtCanvasPolygonalItem::setBrush ( QBrush b )   [virtual]

Sets the QBrush used when drawing the polygonal item to the brush b.

See also setPen(), brush(), and drawShape().

void QtCanvasPolygonalItem::setPen ( QPen p )   [virtual]

Sets the QPen used when drawing the item to the pen p. Note that many QtCanvasPolygonalItems do not use the pen value.

See also setBrush(), pen(), and drawShape().

void QtCanvasPolygonalItem::setWinding ( bool enable )   [protected]

If enable is true, the polygonal item will use the winding algorithm to determine the "inside" of the polygon; otherwise the odd-even algorithm will be used.

The default is to use the odd-even algorithm.

See also winding().

bool QtCanvasPolygonalItem::winding () const   [protected]

Returns true if the polygonal item uses the winding algorithm to determine the "inside" of the polygon. Returns false if it uses the odd-even algorithm.

The default is to use the odd-even algorithm.

See also setWinding().


Copyright © 2005 Trolltech Trademarks