返回介绍

QCanvasPolygonalItem Class

发布于 2019-10-04 14:58:42 字数 6956 浏览 907 评论 0 收藏 0

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

#include <qcanvas.h>

Inherits QCanvasItem.

Inherited by QCanvasRectangle, QCanvasPolygon, QCanvasLine and QCanvasEllipse.

List of all member functions.

Public Members

  • QCanvasPolygonalItem ( QCanvas*canvas )
  • virtual ~QCanvasPolygonalItem ()
  • virtual void setPen ( QPenp )
  • virtual void setBrush ( QBrushb )
  • QPen pen () const
  • QBrush brush () const
  • virtual QPointArray areaPoints () const = 0
  • virtual QPointArray areaPointsAdvanced () const
  • virtual QRect boundingRect () const
  • virtual int rtti () const

Protected Members

  • virtual void draw ( QPainter&p )
  • virtual void drawShape ( QPainter&p ) = 0
  • bool winding () const
  • void setWinding ( boolenable )

Detailed Description

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

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.

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().

See also Graphics Classes and Image Processing Classes.


Member Function Documentation

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().

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.

Reimplemented in QCanvasPolygon.

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().

Reimplemented from QCanvasItem.

QBrush QCanvasPolygonalItem::brush () const

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

See also setBrush().

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

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

Reimplemented from QCanvasItem.

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

Reimplemented in QCanvasRectangle, QCanvasPolygon and QCanvasEllipse.

QPen QCanvasPolygonalItem::pen () const

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

See also setPen().

int QCanvasPolygonalItem::rtti () const [virtual]

Returns 2 (QCanvasItem::Rtti_PolygonalItem).

See also QCanvasItem::rtti().

Reimplemented from QCanvasItem.

Reimplemented in QCanvasRectangle, QCanvasPolygon, QCanvasLine and QCanvasEllipse.

void QCanvasPolygonalItem::setBrush ( QBrushb ) [virtual]

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

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

Examples: canvas/canvas.cpp and chart/chartform_canvas.cpp.

void QCanvasPolygonalItem::setPen ( QPenp ) [virtual]

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

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

Examples: canvas/canvas.cpp and chart/chartform_canvas.cpp.

void QCanvasPolygonalItem::setWinding ( boolenable ) [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 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.

See also setWinding().

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文