Eneboo - Documentación para desarrolladores
Métodos públicos | Atributos públicos estáticos | Métodos protegidos
Referencia de la Clase QCanvasPolygonalItem

The QCanvasPolygonalItem class provides a polygonal canvas item on a QCanvas.canvasThe mostly rectangular classes, such as QCanvasSprite and QCanvasText, 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. QCanvasPolygonalItem provides polygon-based bounding rectangle handling, etc., which is much faster for non-rectangular items. Más...

#include <qcanvas.h>

Diagrama de herencias de QCanvasPolygonalItem
QCanvasItem QCanvasItem Qt Qt Qt Qt QCanvasEllipse QCanvasEllipse QCanvasLine QCanvasLine QCanvasPolygon QCanvasPolygon QCanvasRectangle QCanvasRectangle

Lista de todos los miembros.

Métodos públicos

 QCanvasPolygonalItem (QCanvas *canvas)
virtual ~QCanvasPolygonalItem ()
bool collidesWith (const QCanvasItem *) const
virtual void setPen (QPen p)
virtual void setBrush (QBrush b)
QPen pen () const
QBrush brush () const
virtual QPointArray areaPoints () const =0
virtual QPointArray areaPointsAdvanced () const
QRect boundingRect () const
int rtti () const
 QCanvasPolygonalItem (QCanvas *canvas)
virtual ~QCanvasPolygonalItem ()
bool collidesWith (const QCanvasItem *) const
virtual void setPen (QPen p)
virtual void setBrush (QBrush b)
QPen pen () const
QBrush brush () const
virtual QPointArray areaPoints () const =0
virtual QPointArray areaPointsAdvanced () const
QRect boundingRect () const
int rtti () const

Atributos públicos estáticos

static int RTTI = Rtti_PolygonalItem

Métodos protegidos

void draw (QPainter &)
virtual void drawShape (QPainter &)=0
bool winding () const
void setWinding (bool)
void invalidate ()
bool isValid () const
void draw (QPainter &)
virtual void drawShape (QPainter &)=0
bool winding () const
void setWinding (bool)
void invalidate ()
bool isValid () const

Descripción detallada

The QCanvasPolygonalItem class provides a polygonal canvas item on a QCanvas.

canvas

The mostly rectangular classes, such as QCanvasSprite and QCanvasText, 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. QCanvasPolygonalItem 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 QCanvasPolygonalItem's speed.

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

Normally, QCanvasPolygonalItem 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 QCanvasItem::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, QCanvasPolygonalItem 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 QCanvasPolygonalItem 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 QCanvasItem::move() and QCanvasItem::moveBy(), or by setting coordinates with QCanvasItem::setX(), QCanvasItem::setY() and QCanvasItem::setZ().


Documentación del constructor y destructor

QCanvasPolygonalItem::QCanvasPolygonalItem ( QCanvas canvas)

Constructs a QCanvasPolygonalItem on the canvas canvas.

QCanvasPolygonalItem::~QCanvasPolygonalItem ( ) [virtual]

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

QCanvasPolygonalItem::QCanvasPolygonalItem ( QCanvas canvas)
virtual QCanvasPolygonalItem::~QCanvasPolygonalItem ( ) [virtual]

Documentación de las funciones miembro

QPointArray QCanvasPolygonalItem::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.

Implementado en QCanvasRectangle, QCanvasPolygon, QCanvasLine, QCanvasEllipse, QCanvasRectangle, QCanvasPolygon, QCanvasLine y QCanvasEllipse.

virtual QPointArray QCanvasPolygonalItem::areaPoints ( ) const [pure virtual]
virtual QPointArray QCanvasPolygonalItem::areaPointsAdvanced ( ) const [virtual]
QPointArray QCanvasPolygonalItem::areaPointsAdvanced ( ) const [virtual]

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

QRect QCanvasPolygonalItem::boundingRect ( ) const [virtual]

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

Implementa QCanvasItem.

QRect QCanvasPolygonalItem::boundingRect ( ) const [virtual]

Returns the bounding rectangle in pixels that the canvas item covers.

Ver también:
boundingRectAdvanced()

Implementa QCanvasItem.

QBrush QCanvasPolygonalItem::brush ( ) const [inline]
QBrush QCanvasPolygonalItem::brush ( ) const [inline]

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

Ver también:
setBrush()
bool QCanvasPolygonalItem::collidesWith ( const QCanvasItem i) const [virtual]
bool QCanvasPolygonalItem::collidesWith ( const QCanvasItem other) const [virtual]

Returns TRUE if the canvas item will collide with the other item after they have moved by their current velocities; otherwise returns FALSE.

Ver también:
collisions()

Implementa QCanvasItem.

Reimplementado en QCanvasRectangle, QCanvasEllipse, QCanvasRectangle y QCanvasEllipse.

void QCanvasPolygonalItem::draw ( QPainter p) [protected, virtual]

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

Implementa QCanvasItem.

void QCanvasPolygonalItem::draw ( QPainter painter) [protected, virtual]

This abstract virtual function draws the canvas item using painter.

Atención:
When you reimplement this function, make sure that you leave the painter in the same state as you found it. For example, if you start by calling QPainter::translate(50, 50), end your code by calling QPainter::translate(-50, -50). Be also aware that the painter might already have some transformations set (i.e., don't call QPainter::resetXForm() when you're done).

Implementa QCanvasItem.

void QCanvasPolygonalItem::drawShape ( QPainter p) [protected, pure virtual]

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.

Atención:
When you reimplement this function, make sure that you leave the painter in the same state as you found it. For example, if you start by calling QPainter::translate(50, 50), end your code by calling QPainter::translate(-50, -50). Be also aware that the painter might already have some transformations set (i.e., don't call QPainter::resetXForm() when you're done).
Ver también:
draw()

Implementado en QCanvasRectangle, QCanvasPolygon, QCanvasLine, QCanvasEllipse, QCanvasRectangle, QCanvasPolygon, QCanvasLine y QCanvasEllipse.

virtual void QCanvasPolygonalItem::drawShape ( QPainter ) [protected, pure virtual]
void QCanvasPolygonalItem::invalidate ( ) [protected]
void QCanvasPolygonalItem::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 QCanvasPolygonalItem::isValid ( void  ) const [inline, protected]
QCanvasPolygonalItem::isValid ( void  ) const [inline, protected]

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

Ver también:
invalidate()
QPen QCanvasPolygonalItem::pen ( ) const [inline]
QPen QCanvasPolygonalItem::pen ( ) const [inline]

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

Ver también:
setPen()
int QCanvasPolygonalItem::rtti ( ) const [virtual]
int QCanvasPolygonalItem::rtti ( ) const [virtual]

Returns 0 (QCanvasItem::Rtti_Item).

Make your derived classes return their own values for rtti(), so that you can distinguish between objects returned by QCanvas::at(). You should use values greater than 1000 to allow for extensions to this class.

Overuse of this functionality can damage it's extensibility. For example, once you have identified a base class of a QCanvasItem found by QCanvas::at(), cast it to that type and call meaningful methods rather than acting upon the object based on its rtti value.

For example:

        QCanvasItem* item;
        // Find an item, e.g. with QCanvasItem::collisions().
        ...
        if (item->rtti() == MySprite::RTTI ) {
            MySprite* s = (MySprite*)item;
            if (s->isDamagable()) s->loseHitPoints(1000);
            if (s->isHot()) myself->loseHitPoints(1000);
            ...
        }

Reimplementado de QCanvasItem.

Reimplementado en QCanvasRectangle, QCanvasPolygon, QCanvasSpline, QCanvasLine, QCanvasEllipse, QCanvasRectangle, QCanvasPolygon, QCanvasSpline, QCanvasLine y QCanvasEllipse.

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

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

Ver también:
setPen(), brush(), drawShape()
virtual void QCanvasPolygonalItem::setBrush ( QBrush  b) [virtual]
virtual void QCanvasPolygonalItem::setPen ( QPen  p) [virtual]

Reimplementado en QCanvasLine y QCanvasLine.

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

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

Ver también:
setBrush(), pen(), drawShape()

Reimplementado en QCanvasLine y QCanvasLine.

void QCanvasPolygonalItem::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.

Ver también:
winding()
void QCanvasPolygonalItem::setWinding ( bool  ) [protected]
bool QCanvasPolygonalItem::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.

Ver también:
setWinding()
bool QCanvasPolygonalItem::winding ( ) const [protected]

Documentación de los datos miembro

static int QCanvasPolygonalItem::RTTI = Rtti_PolygonalItem [static]

La documentación para esta clase fue generada a partir de los siguientes ficheros:
 Todo Clases Namespaces Archivos Funciones Variables 'typedefs' Enumeraciones Valores de enumeraciones Propiedades Amigas 'defines'