Q3CanvasPolygonalItem Class

The Q3CanvasPolygonalItem class provides a polygonal canvas item on a Q3Canvas . 更多...

头: #include <Q3CanvasPolygonalItem>
继承: Q3CanvasItem
继承者: Q3CanvasEllipse , Q3CanvasLine , Q3CanvasPolygon ,和 Q3CanvasRectangle

公共函数

Q3CanvasPolygonalItem (Q3Canvas * canvas )
virtual ~Q3CanvasPolygonalItem ()
virtual Q3PointArray areaPoints () const = 0
virtual Q3PointArray areaPointsAdvanced () const
QBrush brush () const
QPen pen () const
virtual void setBrush (QBrush b )
virtual void setPen (QPen p )

重实现公共函数

virtual QRect boundingRect () const
virtual bool collidesWith (const Q3CanvasItem * i ) const
virtual int rtti () const

保护函数

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

重实现保护函数

virtual void draw (QPainter & p )

详细描述

The Q3CanvasPolygonalItem class provides a polygonal canvas item on a Q3Canvas .

The mostly rectangular classes, such as Q3CanvasSprite and Q3CanvasText , 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. Q3CanvasPolygonalItem 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 Q3CanvasPolygonalItem 's speed.

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

Normally, Q3CanvasPolygonalItem 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 ()。使用 areaPointsAdvanced () to retrieve the bounding points the polygonal item will have after Q3CanvasItem::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 ().

默认情况下, Q3CanvasPolygonalItem objects have a black pen and no brush (the default QPen and QBrush constructors). You can change this with setPen () 和 setBrush (), but note that some Q3CanvasPolygonalItem 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 Q3CanvasItem::move () 和 Q3CanvasItem::moveBy (), or by setting coordinates with Q3CanvasItem::setX (), Q3CanvasItem::setY () 和 Q3CanvasItem::setZ ().

另请参阅 QtCanvas and Porting to Graphics View .

成员函数文档编制

Q3CanvasPolygonalItem:: Q3CanvasPolygonalItem ( Q3Canvas * canvas )

构造 Q3CanvasPolygonalItem on the canvas canvas .

[虚拟] Q3CanvasPolygonalItem:: ~Q3CanvasPolygonalItem ()

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

[pure virtual] Q3PointArray Q3CanvasPolygonalItem:: areaPoints () const

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.

[虚拟] Q3PointArray Q3CanvasPolygonalItem:: areaPointsAdvanced () const

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

[虚拟] QRect Q3CanvasPolygonalItem:: boundingRect () const

重实现自 Q3CanvasItem::boundingRect ().

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

QBrush Q3CanvasPolygonalItem:: brush () const

返回 QBrush used to fill the item, if filled.

另请参阅 setBrush ().

[虚拟] bool Q3CanvasPolygonalItem:: collidesWith (const Q3CanvasItem * i ) const

重实现自 Q3CanvasItem::collidesWith ().

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

重实现自 Q3CanvasItem::draw ().

重实现自 Q3CanvasItem , this draws the polygonal item by setting the pen and brush for the item on the painter p and calling drawShape ().

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

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

另请参阅 draw ().

[protected] void Q3CanvasPolygonalItem:: invalidate ()

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 () 或 update (). Call this function if you are going to change the shape of the item (as returned by areaPoints ()) while the item is visible.

[protected] bool Q3CanvasPolygonalItem:: isValid () const

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

另请参阅 invalidate ().

QPen Q3CanvasPolygonalItem:: pen () const

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

另请参阅 setPen ().

[虚拟] int Q3CanvasPolygonalItem:: rtti () const

重实现自 Q3CanvasItem::rtti ().

Returns 2 ( Q3CanvasItem::Rtti_PolygonalItem ).

另请参阅 Q3CanvasItem::rtti ().

[虚拟] void Q3CanvasPolygonalItem:: setBrush ( QBrush b )

设置 QBrush used when drawing the polygonal item to the brush b .

另请参阅 setPen (), brush (),和 drawShape ().

[虚拟] void Q3CanvasPolygonalItem:: setPen ( QPen p )

设置 QPen used when drawing the item to the pen p . Note that many Q3CanvasPolygonalItems do not use the pen value.

另请参阅 setBrush (), pen (),和 drawShape ().

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

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.

另请参阅 winding ().

[protected] bool Q3CanvasPolygonalItem:: winding () const

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.

另请参阅 setWinding ().