QGraphicsEllipseItem Class Reference

#include <qgraphicsitem.h>

Inheritance diagram for QGraphicsEllipseItem:

Inheritance graph
[legend]
Collaboration diagram for QGraphicsEllipseItem:

Collaboration graph
[legend]
List of all members.

Detailed Description

The QGraphicsEllipseItem class provides an ellipse item that you can add to a QGraphicsScene.

Since:
4.2
QGraphicsEllipseItem respresents an ellipse with a fill and an outline, and you can also use it for ellipse segments (see startAngle(), spanAngle()).

graphicsview-ellipseitem.png graphicsview-ellipseitem-pie.png

To set the item's ellipse, pass a QRectF to QGraphicsEllipseItem's constructor, or call setRect(). The rect() function returns the current ellipse geometry.

QGraphicsEllipseItem uses the rect and the pen width to provide a reasonable implementation of boundingRect(), shape(), and contains(). The paint() function draws the ellipse using the item's associated pen and brush, which you can set by calling setPen() and setBrush().

See also:
QGraphicsPathItem, QGraphicsRectItem, QGraphicsPolygonItem, QGraphicsTextItem, QGraphicsLineItem, QGraphicsPixmapItem, {The Graphics View Framework}

Definition at line 404 of file qgraphicsitem.h.

Public Types

enum  

Public Member Functions

 QGraphicsEllipseItem (QGraphicsItem *parent=0, QGraphicsScene *scene=0)
 QGraphicsEllipseItem (const QRectF &rect, QGraphicsItem *parent=0, QGraphicsScene *scene=0)
 QGraphicsEllipseItem (qreal x, qreal y, qreal w, qreal h, QGraphicsItem *parent=0, QGraphicsScene *scene=0)
 ~QGraphicsEllipseItem ()
QRectF rect () const
void setRect (const QRectF &rect)
void setRect (qreal x, qreal y, qreal w, qreal h)
int startAngle () const
void setStartAngle (int angle)
int spanAngle () const
void setSpanAngle (int angle)
QRectF boundingRect () const
QPainterPath shape () const
bool contains (const QPointF &point) const
void paint (QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget=0)
bool isObscuredBy (const QGraphicsItem *item) const
QPainterPath opaqueArea () const
int type () const

Protected Member Functions

bool supportsExtension (Extension extension) const
void setExtension (Extension extension, const QVariant &variant)
QVariant extension (const QVariant &variant) const


Member Enumeration Documentation

anonymous enum

Definition at line 431 of file qgraphicsitem.h.

00431 { Type = 4 };


Constructor & Destructor Documentation

QGraphicsEllipseItem::QGraphicsEllipseItem ( QGraphicsItem parent = 0,
QGraphicsScene scene = 0 
)

Constructs a QGraphicsEllipseItem. The parent and scene parameters are passed to QAbstractGraphicsShapeItem's constructor.

Definition at line 3680 of file qgraphicsitem.cpp.

03681     : QAbstractGraphicsShapeItem(*new QGraphicsEllipseItemPrivate, parent, scene)
03682 {
03683 }

QGraphicsEllipseItem::QGraphicsEllipseItem ( const QRectF rect,
QGraphicsItem parent = 0,
QGraphicsScene scene = 0 
)

Constructs a QGraphicsEllipseItem using rect as the default rectangle. The parent and scene parameters are passed to QAbstractGraphicsShapeItem's constructor.

Definition at line 3652 of file qgraphicsitem.cpp.

References rect(), and setRect().

03654     : QAbstractGraphicsShapeItem(*new QGraphicsEllipseItemPrivate, parent, scene)
03655 {
03656     setRect(rect);
03657 }

Here is the call graph for this function:

QGraphicsEllipseItem::QGraphicsEllipseItem ( qreal  x,
qreal  y,
qreal  width,
qreal  height,
QGraphicsItem parent = 0,
QGraphicsScene scene = 0 
)

Constructs a QGraphicsEllipseItem using the rectangle defined by (x, y) and the given width and height, as the default rectangle. The parent and scene parameters are passed to QAbstractGraphicsShapeItem's constructor.

Definition at line 3667 of file qgraphicsitem.cpp.

References setRect().

03669     : QAbstractGraphicsShapeItem(*new QGraphicsEllipseItemPrivate, parent, scene)
03670 {
03671     setRect(x,y,w,h);
03672 }

Here is the call graph for this function:

QGraphicsEllipseItem::~QGraphicsEllipseItem (  ) 

Destroys the QGraphicsEllipseItem.

Definition at line 3688 of file qgraphicsitem.cpp.

03689 {
03690 }


Member Function Documentation

QRectF QGraphicsEllipseItem::rect (  )  const

Returns the item's ellipse geometry as a QRectF.

See also:
setRect(), QPainter::drawEllipse()

Definition at line 3697 of file qgraphicsitem.cpp.

References d.

Referenced by QGraphicsEllipseItem(), and setRect().

03698 {
03699     Q_D(const QGraphicsEllipseItem);
03700     return d->rect;
03701 }

void QGraphicsEllipseItem::setRect ( const QRectF rect  ) 

Sets the item's ellipse geometry to rect. The rectangle's left edge defines the left edge of the ellipse, and the rectangle's top edge describes the top of the ellipse. The height and width of the rectangle describe the height and width of the ellipse.

See also:
rect(), QPainter::drawEllipse()

Definition at line 3711 of file qgraphicsitem.cpp.

References QGraphicsItem::addToIndex(), d, rect(), and QGraphicsItem::removeFromIndex().

Referenced by QGraphicsEllipseItem(), and setRect().

03712 {
03713     Q_D(QGraphicsEllipseItem);
03714     removeFromIndex();
03715     d->rect = rect;
03716     addToIndex();
03717 }

Here is the call graph for this function:

void QGraphicsEllipseItem::setRect ( qreal  x,
qreal  y,
qreal  width,
qreal  height 
) [inline]

Sets the item's rectangle to the rectangle defined by (x, y) and the given width and height.

This convenience function is equivalent to calling {setRect(QRectF(x, y, width, height))}

See also:
rect()

Definition at line 444 of file qgraphicsitem.h.

References setRect().

00445 { setRect(QRectF(ax, ay, w, h)); }

Here is the call graph for this function:

int QGraphicsEllipseItem::startAngle (  )  const

Returns the start angle for an ellipse segment in 16ths of a degree. This angle is used together with spanAngle() for representing an ellipse segment (a pie). By default, the start angle is 0.

See also:
setStartAngle(), spanAngle()

Definition at line 3726 of file qgraphicsitem.cpp.

References d.

03727 {
03728     Q_D(const QGraphicsEllipseItem);
03729     return d->startAngle;
03730 }

void QGraphicsEllipseItem::setStartAngle ( int  angle  ) 

Sets the start angle for an ellipse segment to angle, which is in 16ths of a degree. This angle is used together with spanAngle() for representing an ellipse segment (a pie). By default, the start angle is 0.

See also:
startAngle(), setSpanAngle(), QPainter::drawPie()

Definition at line 3739 of file qgraphicsitem.cpp.

References d, and QGraphicsItem::update().

03740 {
03741     Q_D(QGraphicsEllipseItem);
03742     if (angle != d->startAngle) {
03743         d->startAngle = angle;
03744         update();
03745     }
03746 }

Here is the call graph for this function:

int QGraphicsEllipseItem::spanAngle (  )  const

Returns the span angle of an ellipse segment in 16ths of a degree. This angle is used together with startAngle() for representing an ellipse segment (a pie). By default, this function returns 5760 (360 * 16, a full ellipse).

See also:
setSpanAngle(), startAngle()

Definition at line 3756 of file qgraphicsitem.cpp.

References d.

03757 {
03758     Q_D(const QGraphicsEllipseItem);
03759     return d->spanAngle;
03760 }

void QGraphicsEllipseItem::setSpanAngle ( int  angle  ) 

Sets the span angle for an ellipse segment to angle, which is in 16ths of a degree. This angle is used together with startAngle() to represent an ellipse segment (a pie). By default, the span angle is 5760 (360 * 16, a full ellipse).

See also:
spanAngle(), setStartAngle(), QPainter::drawPie()

Definition at line 3770 of file qgraphicsitem.cpp.

References d, and QGraphicsItem::update().

03771 {
03772     Q_D(QGraphicsEllipseItem);
03773     if (angle != d->spanAngle) {
03774         d->spanAngle = angle;
03775         update();
03776     }
03777 }

Here is the call graph for this function:

QRectF QGraphicsEllipseItem::boundingRect (  )  const [virtual]

Implements QGraphicsItem.

Definition at line 3782 of file qgraphicsitem.cpp.

References d.

Referenced by paint().

03783 {
03784     Q_D(const QGraphicsEllipseItem);
03785     qreal penWidth = d->pen.widthF() / 2.0;
03786     return d->rect.adjusted(-penWidth, -penWidth,
03787                             penWidth, penWidth);
03788 }

QPainterPath QGraphicsEllipseItem::shape (  )  const [virtual]

Reimplemented from QGraphicsItem.

Definition at line 3793 of file qgraphicsitem.cpp.

References d, path, and qt_graphicsItem_shapeFromPath().

03794 {
03795     Q_D(const QGraphicsEllipseItem);
03796     QPainterPath path;
03797     if (d->rect.isNull())
03798         return path;
03799     if (d->spanAngle != 360 * 16) {
03800         path.moveTo(d->rect.center());
03801         path.arcTo(d->rect, d->startAngle / 16.0, d->spanAngle / 16.0);
03802     } else {
03803         path.addEllipse(d->rect);
03804     }
03805 
03806     return qt_graphicsItem_shapeFromPath(path, d->pen);
03807 }

Here is the call graph for this function:

bool QGraphicsEllipseItem::contains ( const QPointF point  )  const [virtual]

Reimplemented from QGraphicsItem.

Definition at line 3812 of file qgraphicsitem.cpp.

References QGraphicsItem::contains().

03813 {
03814     return QAbstractGraphicsShapeItem::contains(point);
03815 }

Here is the call graph for this function:

void QGraphicsEllipseItem::paint ( QPainter painter,
const QStyleOptionGraphicsItem option,
QWidget widget = 0 
) [virtual]

Implements QGraphicsItem.

Definition at line 3820 of file qgraphicsitem.cpp.

References boundingRect(), d, Qt::DashLine, QPainter::drawEllipse(), QPainter::drawPie(), QPainter::drawRect(), Qt::NoBrush, QStyleOption::palette, QPainter::setBrush(), QPainter::setPen(), QStyleOption::state, QStyle::State_Selected, and QPalette::text().

03822 {
03823     Q_D(QGraphicsEllipseItem);
03824     Q_UNUSED(widget);
03825     painter->setPen(d->pen);
03826     painter->setBrush(d->brush);
03827     if ((d->spanAngle != 0) && (qAbs(d->spanAngle) % (360 * 16) == 0))
03828         painter->drawEllipse(d->rect);
03829     else
03830         painter->drawPie(d->rect, d->startAngle, d->spanAngle);
03831 
03832     if (option->state & QStyle::State_Selected) {
03833         painter->setPen(QPen(option->palette.text(), 1.0, Qt::DashLine));
03834         painter->setBrush(Qt::NoBrush);
03835         painter->drawRect(boundingRect().adjusted(2, 2, -2, -2));
03836     }
03837 }

Here is the call graph for this function:

bool QGraphicsEllipseItem::isObscuredBy ( const QGraphicsItem item  )  const [virtual]

Reimplemented from QAbstractGraphicsShapeItem.

Definition at line 3842 of file qgraphicsitem.cpp.

References QAbstractGraphicsShapeItem::isObscuredBy().

03843 {
03844     return QAbstractGraphicsShapeItem::isObscuredBy(item);
03845 }

Here is the call graph for this function:

QPainterPath QGraphicsEllipseItem::opaqueArea (  )  const [virtual]

Reimplemented from QAbstractGraphicsShapeItem.

Definition at line 3850 of file qgraphicsitem.cpp.

References QAbstractGraphicsShapeItem::opaqueArea().

03851 {
03852     return QAbstractGraphicsShapeItem::opaqueArea();
03853 }

Here is the call graph for this function:

int QGraphicsEllipseItem::type (  )  const [virtual]

Reimplemented from QGraphicsItem.

Definition at line 3858 of file qgraphicsitem.cpp.

03859 {
03860     return Type;
03861 }

bool QGraphicsEllipseItem::supportsExtension ( Extension  extension  )  const [protected, virtual]

Reimplemented from QGraphicsItem.

Definition at line 3867 of file qgraphicsitem.cpp.

03868 {
03869     Q_UNUSED(extension);
03870     return false;
03871 }

void QGraphicsEllipseItem::setExtension ( Extension  extension,
const QVariant variant 
) [protected, virtual]

Reimplemented from QGraphicsItem.

Definition at line 3876 of file qgraphicsitem.cpp.

References variant.

03877 {
03878     Q_UNUSED(extension);
03879     Q_UNUSED(variant);
03880 }

QVariant QGraphicsEllipseItem::extension ( const QVariant variant  )  const [protected, virtual]

Reimplemented from QGraphicsItem.

Definition at line 3885 of file qgraphicsitem.cpp.

References variant.

03886 {
03887     Q_UNUSED(variant);
03888     return QVariant();
03889 }


The documentation for this class was generated from the following files:
Generated on Thu Mar 15 17:46:57 2007 for Qt 4.2 User's Guide by  doxygen 1.5.1