Qt Jambi Home

com.trolltech.qt.gui
Class QGraphicsEllipseItem

java.lang.Object
  extended by com.trolltech.qt.QSignalEmitter
      extended by com.trolltech.qt.QtJambiObject
          extended by com.trolltech.qt.gui.QAbstractGraphicsShapeItem
              extended by com.trolltech.qt.gui.QGraphicsEllipseItem
All Implemented Interfaces:
QGraphicsItemInterface, QtJambiInterface

public class QGraphicsEllipseItem
extends QAbstractGraphicsShapeItem

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

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

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

Nested Class Summary
static class QGraphicsEllipseItem.enum_1
          Press link for info on QGraphicsEllipseItem.enum_1
 
Nested classes/interfaces inherited from class com.trolltech.qt.QSignalEmitter
QSignalEmitter.Signal0, QSignalEmitter.Signal1<A>, QSignalEmitter.Signal2<A,B>, QSignalEmitter.Signal3<A,B,C>, QSignalEmitter.Signal4<A,B,C,D>, QSignalEmitter.Signal5<A,B,C,D,E>, QSignalEmitter.Signal6<A,B,C,D,E,F>, QSignalEmitter.Signal7<A,B,C,D,E,F,G>, QSignalEmitter.Signal8<A,B,C,D,E,F,G,H>, QSignalEmitter.Signal9<A,B,C,D,E,F,G,H,I>
 
Constructor Summary
QGraphicsEllipseItem()
          Equivalent to QGraphicsEllipseItem(, 0).
QGraphicsEllipseItem(double x, double y, double w, double h)
          Creates a new QGraphicsEllipseItem with top left corner in the point (x, y), width w.
QGraphicsEllipseItem(double x, double y, double w, double h, QGraphicsItemInterface parent)
          Creates a new QGraphicsEllipseItem with top left corner in the point (x, y), width w, and height h, and the specified parent.
QGraphicsEllipseItem(double x, double y, double w, double h, QGraphicsItemInterface parent, QGraphicsScene scene)
          Creates a new QGraphicsEllipseItem with top left corner in the point (x, y), width w, and height h, and the specified parent.
QGraphicsEllipseItem(QGraphicsItemInterface parent)
          Equivalent to QGraphicsEllipseItem(parent, 0).
QGraphicsEllipseItem(QGraphicsItemInterface parent, QGraphicsScene scene)
          Constructs a QGraphicsEllipseItem using parent as the default rectangle.
QGraphicsEllipseItem(QRectF rect)
          tes a new QGraphicsEllipseItem with the specified rect bounds.
QGraphicsEllipseItem(QRectF rect, QGraphicsItemInterface parent)
          Creates a new QGraphicsEllipseItem with the specified rect bounds and parent.
QGraphicsEllipseItem(QRectF rect, QGraphicsItemInterface parent, QGraphicsScene scene)
          Creates a new QGraphicsEllipseItem with the specified rect bounds and parent, and then adds it to scene.
 
Method Summary
 QRectF boundingRect()
          

This pure virtual function defines the outer bounds of the item as a rectangle; all painting must be restricted to inside an item's bounding rect.

 boolean contains(QPointF point)
          

Returns true if this item contains point, which is in local coordinates; otherwise, false is returned.

 java.lang.Object extension(java.lang.Object variant)
          

static QGraphicsEllipseItem fromNativePointer(QNativePointer nativePointer)
          This function returns the QGraphicsEllipseItem instance pointed to by nativePointer
 boolean isObscuredBy(QGraphicsItemInterface item)
          

Returns true if this item's bounding rect is completely obscured by the opaque shape of item.

The base implementation maps item's opaqueArea to this item's coordinate system, and then checks if this item's boundingRect is fully contained within the mapped shape.

You can reimplement this function to provide a custom algorithm for determining whether this item is obscured by item.

 QPainterPath opaqueArea()
          

This virtual function returns a shape representing the area where this item is opaque. An area is opaque if it is filled using an opaque brush or color (i.e., not transparent).

This function is used by isObscuredBy, which is called by underlying items to determine if they are obscured by this item.

The default implementation returns an empty QPainterPath, indicating that this item is completely transparent and does not obscure any other items.

 void paint(QPainter painter, QStyleOptionGraphicsItem option, QWidget widget)
          

This function, which is usually called by QGraphicsView, paints the contents of an item in local coordinates.

 QRectF rect()
          Returns the item's ellipse geometry as a QRectF.
 void setExtension(QGraphicsItem.Extension extension, java.lang.Object variant)
          
 void setRect(double x, double y, double w, double h)
          Sets the item's rectangle to the rectangle defined by (x, y) and the given w and h.
 void setRect(QRectF rect)
          Sets the item's ellipse geometry to rect.
 void setSpanAngle(int angle)
          Sets the span angle for an ellipse segment to angle, which is in 16ths of a degree.
 void setStartAngle(int angle)
          Sets the start angle for an ellipse segment to angle, which is in 16ths of a degree.
 QPainterPath shape()
          

Returns the shape of this item as a QPainterPath in local coordinates.

 int spanAngle()
          Returns the span angle of an ellipse segment in 16ths of a degree.
 int startAngle()
          Returns the start angle for an ellipse segment in 16ths of a degree.
 boolean supportsExtension(QGraphicsItem.Extension extension)
          
 int type()
          

Returns the type of an item as an int.

 
Methods inherited from class com.trolltech.qt.gui.QAbstractGraphicsShapeItem
acceptDrops, acceptedMouseButtons, acceptsHoverEvents, addToIndex, advance, brush, childItems, childrenBoundingRect, clearFocus, collidesWithItem, collidesWithPath, collidingItems, contextMenuEvent, cursor, data, deviceTransform, dragEnterEvent, dragLeaveEvent, dragMoveEvent, dropEvent, ensureVisible, ensureVisible, flags, focusInEvent, focusOutEvent, group, handlesChildEvents, hasCursor, hasFocus, hide, hoverEnterEvent, hoverLeaveEvent, hoverMoveEvent, inputMethodEvent, inputMethodQuery, installSceneEventFilter, isAncestorOf, isEnabled, isObscured, isObscured, isObscured, isSelected, isVisible, itemChange, keyPressEvent, keyReleaseEvent, mapFromItem, mapFromItem, mapFromItem, mapFromItem, mapFromItem, mapFromItem, mapFromParent, mapFromParent, mapFromParent, mapFromParent, mapFromParent, mapFromParent, mapFromScene, mapFromScene, mapFromScene, mapFromScene, mapFromScene, mapFromScene, mapToItem, mapToItem, mapToItem, mapToItem, mapToItem, mapToItem, mapToParent, mapToParent, mapToParent, mapToParent, mapToParent, mapToParent, mapToScene, mapToScene, mapToScene, mapToScene, mapToScene, mapToScene, mouseDoubleClickEvent, mouseMoveEvent, mousePressEvent, mouseReleaseEvent, moveBy, parentItem, pen, pos, prepareGeometryChange, removeFromIndex, removeSceneEventFilter, resetTransform, rotate, scale, scene, sceneBoundingRect, sceneEvent, sceneEventFilter, scenePos, sceneTransform, setAcceptDrops, setAcceptedMouseButtons, setAcceptsHoverEvents, setBrush, setCursor, setData, setEnabled, setFlag, setFlags, setFocus, setGroup, setHandlesChildEvents, setParentItem, setPen, setPos, setPos, setSelected, setToolTip, setTransform, setVisible, setZValue, shear, show, toolTip, topLevelItem, transform, translate, unsetCursor, update, update, wheelEvent, x, y, zValue
 
Methods inherited from class com.trolltech.qt.QtJambiObject
dispose, disposed, finalize, reassignNativeResources, tr, tr, tr
 
Methods inherited from class com.trolltech.qt.QSignalEmitter
blockSignals, disconnect, disconnect, signalsBlocked, signalSender, thread
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface com.trolltech.qt.QtJambiInterface
disableGarbageCollection, nativeId, nativePointer, reenableGarbageCollection, setJavaOwnership
 

Constructor Detail

QGraphicsEllipseItem

public QGraphicsEllipseItem(double x,
                            double y,
                            double w,
                            double h,
                            QGraphicsItemInterface parent)
Creates a new QGraphicsEllipseItem with top left corner in the point (x, y), width w, and height h, and the specified parent.


QGraphicsEllipseItem

public QGraphicsEllipseItem(double x,
                            double y,
                            double w,
                            double h)
Creates a new QGraphicsEllipseItem with top left corner in the point (x, y), width w.


QGraphicsEllipseItem

public QGraphicsEllipseItem(double x,
                            double y,
                            double w,
                            double h,
                            QGraphicsItemInterface parent,
                            QGraphicsScene scene)
Creates a new QGraphicsEllipseItem with top left corner in the point (x, y), width w, and height h, and the specified parent. It is then added to scene.


QGraphicsEllipseItem

public QGraphicsEllipseItem(QGraphicsItemInterface parent)

Equivalent to QGraphicsEllipseItem(parent, 0).


QGraphicsEllipseItem

public QGraphicsEllipseItem()

Equivalent to QGraphicsEllipseItem(, 0).


QGraphicsEllipseItem

public QGraphicsEllipseItem(QGraphicsItemInterface parent,
                            QGraphicsScene scene)

Constructs a QGraphicsEllipseItem using parent as the default rectangle. scene is passed to QAbstractGraphicsShapeItem's constructor.

See Also:
QGraphicsScene::addItem

QGraphicsEllipseItem

public QGraphicsEllipseItem(QRectF rect,
                            QGraphicsItemInterface parent)
Creates a new QGraphicsEllipseItem with the specified rect bounds and parent.


QGraphicsEllipseItem

public QGraphicsEllipseItem(QRectF rect)
tes a new QGraphicsEllipseItem with the specified rect bounds.


QGraphicsEllipseItem

public QGraphicsEllipseItem(QRectF rect,
                            QGraphicsItemInterface parent,
                            QGraphicsScene scene)
Creates a new QGraphicsEllipseItem with the specified rect bounds and parent, and then adds it to scene.

Method Detail

rect

public final QRectF rect()

Returns the item's ellipse geometry as a QRectF.

See Also:
setRect, QPainter::drawEllipse

setRect

public final void setRect(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

setRect

public final void setRect(double x,
                          double y,
                          double w,
                          double h)

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

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

See Also:
rect

setSpanAngle

public final void 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

setStartAngle

public final void 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

spanAngle

public final int spanAngle()

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

startAngle

public final int startAngle()

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

boundingRect

public QRectF boundingRect()

This pure virtual function defines the outer bounds of the item as a rectangle; all painting must be restricted to inside an item's bounding rect. QGraphicsView uses this to determine whether the item requires redrawing.

Although the item's shape can be arbitrary, the bounding rect is always rectangular, and it is unaffected by the items' transformation (scale, rotate, etc.).

If you want to change the item's bounding rectangle, you must first call prepareGeometryChange. This notifies the scene of the imminent change, so that its can update its item geometry index; otherwise, the scene will be unaware of the item's new geometry, and the results are undefined (typically, rendering artifacts are left around in the view).

Reimplement this function to let QGraphicsView determine what parts of the widget, if any, need to be redrawn.

Note: For shapes that paint an outline / stroke, it is important to include half the pen width in the bounding rect. It is not necessary to compensate for antialiasing, though.

Example:

    QRectF CircleItem::boundingRect() const
    {
        qreal penWidth = 1;
        return QRectF(-radius - penWidth / 2, -radius - penWidth / 2,
                      diameter + penWidth, diameter + penWidth);
    }

Specified by:
boundingRect in interface QGraphicsItemInterface
Specified by:
boundingRect in class QAbstractGraphicsShapeItem
See Also:
shape, contains, The Graphics View Coordinate System, prepareGeometryChange

contains

public boolean contains(QPointF point)

Returns true if this item contains point, which is in local coordinates; otherwise, false is returned. It is most often called from QGraphicsView to determine what item is under the cursor, and for that reason, the implementation of this function should be as light-weight as possible.

By default, this function calls shape, but you can reimplement it in a subclass to provide a (perhaps more efficient) implementation.

Specified by:
contains in interface QGraphicsItemInterface
Overrides:
contains in class QAbstractGraphicsShapeItem
See Also:
shape, boundingRect, collidesWithPath

extension

public java.lang.Object extension(java.lang.Object variant)

Specified by:
extension in interface QGraphicsItemInterface
Overrides:
extension in class QAbstractGraphicsShapeItem
See Also:
setExtension

isObscuredBy

public boolean isObscuredBy(QGraphicsItemInterface item)

Returns true if this item's bounding rect is completely obscured by the opaque shape of item.

The base implementation maps item's opaqueArea to this item's coordinate system, and then checks if this item's boundingRect is fully contained within the mapped shape.

You can reimplement this function to provide a custom algorithm for determining whether this item is obscured by item.

Specified by:
isObscuredBy in interface QGraphicsItemInterface
Overrides:
isObscuredBy in class QAbstractGraphicsShapeItem
See Also:
opaqueArea, isObscured

opaqueArea

public QPainterPath opaqueArea()

This virtual function returns a shape representing the area where this item is opaque. An area is opaque if it is filled using an opaque brush or color (i.e., not transparent).

This function is used by isObscuredBy, which is called by underlying items to determine if they are obscured by this item.

The default implementation returns an empty QPainterPath, indicating that this item is completely transparent and does not obscure any other items.

Specified by:
opaqueArea in interface QGraphicsItemInterface
Overrides:
opaqueArea in class QAbstractGraphicsShapeItem
See Also:
isObscuredBy, isObscured, shape

paint

public void paint(QPainter painter,
                  QStyleOptionGraphicsItem option,
                  QWidget widget)

This function, which is usually called by QGraphicsView, paints the contents of an item in local coordinates.

Reimplement this function in a QGraphicsItem subclass to provide the item's painting implementation, using painter. The option parameter provides style options for the item, such as its state, exposed area and its level-of-detail hints. The widget argument is optional. If provided, it points to the widget that is being painted on; otherwise, it is 0.

    void RoundRectItem::paint(QPainter *painter,
                              const QStyleOptionGraphicsItem *option,
                              QWidget *widget)
    {
        painter->drawRoundRect(-10, -10, 20, 20);
    }

The painter's pen is 0-width by default, and its pen is initialized to the QPalette::Text brush from the paint device's palette. The brush is initialized to QPalette::Window.

All painting is done in local coordinates.

Specified by:
paint in interface QGraphicsItemInterface
Specified by:
paint in class QAbstractGraphicsShapeItem

setExtension

public void setExtension(QGraphicsItem.Extension extension,
                         java.lang.Object variant)

Specified by:
setExtension in interface QGraphicsItemInterface
Overrides:
setExtension in class QAbstractGraphicsShapeItem
See Also:
extension

shape

public QPainterPath shape()

Returns the shape of this item as a QPainterPath in local coordinates. The shape is used for many things, including collision detection, hit tests, and for the QGraphicsScene::items() functions.

The default implementation calls boundingRect to return a simple rectangular shape, but subclasses can reimplement this function to return a more accurate shape for non-rectangular items. For example, a round item may choose to return an elliptic shape for better collision detection. For example:

    QPainterPath RoundItem::shape() const
    {
        QPainterPath path;
        path.addEllipse(boundingRect());
        return path;
    }

This function is called by the default implementations of contains and collidesWithPath.

Specified by:
shape in interface QGraphicsItemInterface
Overrides:
shape in class QAbstractGraphicsShapeItem
See Also:
boundingRect, contains, prepareGeometryChange

supportsExtension

public boolean supportsExtension(QGraphicsItem.Extension extension)

Specified by:
supportsExtension in interface QGraphicsItemInterface
Overrides:
supportsExtension in class QAbstractGraphicsShapeItem

type

public int type()

Returns the type of an item as an int. All standard graphicsitem classes are associated with a unique value; see QGraphicsItem::Type. This type information is used by qgraphicsitem_cast() to distinguish between types.

Reimplementing this function and declaring a Type enum value equal to your custom item's type will enable use of qgraphicsitem_cast() with the item. Custom items must return a value larger than or equal to UserType (65536).

The default implementation (in QGraphicsItem) returns UserType.

Specified by:
type in interface QGraphicsItemInterface
Overrides:
type in class QAbstractGraphicsShapeItem

fromNativePointer

public static QGraphicsEllipseItem fromNativePointer(QNativePointer nativePointer)
This function returns the QGraphicsEllipseItem instance pointed to by nativePointer

Parameters:
nativePointer - the QNativePointer of which object should be returned.

Qt Jambi Home