|
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.trolltech.qt.QSignalEmitter
com.trolltech.qt.QtJambiObject
com.trolltech.qt.gui.QAbstractGraphicsShapeItem
com.trolltech.qt.gui.QGraphicsPolygonItem
public class QGraphicsPolygonItem
The QGraphicsPolygonItem class provides a polygon item that you can add to a QGraphicsScene.
To set the item's polygon, pass a QPolygonF to QGraphicsPolygonItem's constructor, or call the setPolygon function. The polygon function returns the current polygon.
QGraphicsPolygonItem uses the polygon and the pen width to provide a reasonable implementation of boundingRect, shape, and contains. The paint function draws the polygon using the item's associated pen and brush, which you can set by calling the setPen and setBrush functions.
Nested Class Summary | |
---|---|
static class |
QGraphicsPolygonItem.enum_1
Press link for info on QGraphicsPolygonItem.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 | |
---|---|
QGraphicsPolygonItem()
Equivalent to QGraphicsPolygonItem(, 0). |
|
QGraphicsPolygonItem(QGraphicsItemInterface parent)
Equivalent to QGraphicsPolygonItem(parent, 0). |
|
QGraphicsPolygonItem(QGraphicsItemInterface parent,
QGraphicsScene scene)
Constructs a QGraphicsPolygonItem with parent as the default polygon. |
|
QGraphicsPolygonItem(QPolygonF polygon)
Creates a new QGraphicsPolygonItem from polygon. |
|
QGraphicsPolygonItem(QPolygonF polygon,
QGraphicsItemInterface parent)
Creates a new QGraphicsPolygonItem of the specified polygon and parent. |
|
QGraphicsPolygonItem(QPolygonF polygon,
QGraphicsItemInterface parent,
QGraphicsScene scene)
Creates a new QGraphicsPolygonItem from the given polygon, and with the specified parent. |
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)
|
Qt.FillRule |
fillRule()
Returns the fill rule of the polygon. |
static QGraphicsPolygonItem |
fromNativePointer(QNativePointer nativePointer)
This function returns the QGraphicsPolygonItem 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. |
QPolygonF |
polygon()
Returns the item's polygon, or an empty polygon if no polygon has been set. |
void |
setExtension(QGraphicsItem.Extension extension,
java.lang.Object variant)
|
void |
setFillRule(Qt.FillRule rule)
Sets the fill rule of the polygon to rule. |
void |
setPolygon(QPolygonF polygon)
Sets the item's polygon to be the given polygon. |
QPainterPath |
shape()
Returns the shape of this item as a QPainterPath in local coordinates. |
boolean |
supportsExtension(QGraphicsItem.Extension extension)
|
int |
type()
Returns the type of an item as an int. |
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 |
---|
public QGraphicsPolygonItem(QGraphicsItemInterface parent)
Equivalent to QGraphicsPolygonItem(parent, 0).
public QGraphicsPolygonItem()
Equivalent to QGraphicsPolygonItem(, 0).
public QGraphicsPolygonItem(QGraphicsItemInterface parent, QGraphicsScene scene)
Constructs a QGraphicsPolygonItem with parent as the default polygon. scene is passed to QAbstractGraphicsShapeItem's constructor.
public QGraphicsPolygonItem(QPolygonF polygon, QGraphicsItemInterface parent)
public QGraphicsPolygonItem(QPolygonF polygon)
public QGraphicsPolygonItem(QPolygonF polygon, QGraphicsItemInterface parent, QGraphicsScene scene)
Method Detail |
---|
public final Qt.FillRule fillRule()
Returns the fill rule of the polygon. The default fill rule is Qt::OddEvenFill.
public final QPolygonF polygon()
Returns the item's polygon, or an empty polygon if no polygon has been set.
public final void setFillRule(Qt.FillRule rule)
Sets the fill rule of the polygon to rule. The default fill rule is Qt::OddEvenFill.
public final void setPolygon(QPolygonF polygon)
Sets the item's polygon to be the given polygon.
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); }
boundingRect
in interface QGraphicsItemInterface
boundingRect
in class QAbstractGraphicsShapeItem
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.
contains
in interface QGraphicsItemInterface
contains
in class QAbstractGraphicsShapeItem
public java.lang.Object extension(java.lang.Object variant)
extension
in interface QGraphicsItemInterface
extension
in class QAbstractGraphicsShapeItem
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.
isObscuredBy
in interface QGraphicsItemInterface
isObscuredBy
in class QAbstractGraphicsShapeItem
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.
opaqueArea
in interface QGraphicsItemInterface
opaqueArea
in class QAbstractGraphicsShapeItem
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.
paint
in interface QGraphicsItemInterface
paint
in class QAbstractGraphicsShapeItem
public void setExtension(QGraphicsItem.Extension extension, java.lang.Object variant)
setExtension
in interface QGraphicsItemInterface
setExtension
in class QAbstractGraphicsShapeItem
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.
shape
in interface QGraphicsItemInterface
shape
in class QAbstractGraphicsShapeItem
public boolean supportsExtension(QGraphicsItem.Extension extension)
supportsExtension
in interface QGraphicsItemInterface
supportsExtension
in class QAbstractGraphicsShapeItem
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.
type
in interface QGraphicsItemInterface
type
in class QAbstractGraphicsShapeItem
public static QGraphicsPolygonItem fromNativePointer(QNativePointer nativePointer)
nativePointer
- the QNativePointer of which object should be returned.
|
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |