![]() ![]() |
An abstract graphic object on a QCanvas. More...
#include <qcanvas.h>
Inherits Qt.
Inherited by QCanvasPolygonalItem, QCanvasSprite and QCanvasText.
QCanvasItems can be moved, hidden, and tested for collision with other items. They have selected, enabled, and active state flags which subclasses may use to adjust appearance or behavior.
For details of collision detection, see collisions(). Other functions related to collision detection are collidesWith(), and the QCanvas::collisions() functions.
Constructs a QCanvasItem on canvas.
See also: setCanvas(QCanvas*).
[virtual]
Destructs the QCanvasItem. It is removed from its canvas.
Returns TRUE if the QCanvasItem is active.
[virtual]
Advances the animation of the item. The default is to move the item by the preset velocity (see setVelocity()) if stage is 1.
See also: QCanvas::advance().
Returns TRUE is the item is animated.
See also: setVelocity() and setAnimated().
[virtual]
Returns the bounding rectangle of pixels that the item covers.
See also: boundingRectAdvanced().
Reimplemented in QCanvasText, QCanvasSprite and QCanvasPolygonalItem.
[virtual]
Returns the bounding rectangle of pixels that the item will cover after advance(1) is called.
See also: boundingRect().
Returns the canvas containing the item.
[virtual]
Returns TRUE if the item will collide with the other item after they have moved by their current velocities.
See also: collisions().
Reimplemented in QCanvasPolygonalItem, QCanvasText, QCanvasRectangle, QCanvasEllipse and QCanvasSprite.
Returns the list of items that this item collides with.
A collision is generally defined as pixels of one item drawing on the pixels of another item, but not all subclasses are so precise. Also, since pixelwise collision detection can be slow, this function works in either exact or inexact mode, according to the exact parameter.
In exact mode, items returned have been accurately tested to collide with the item.
In inexact mode, the items returned are only near the item and should be tested using collidesWith() if they are interesting collision candidates. By using this, you can ignore some items for which collisions are not interesting.
The returned list is just a list of QCanvasItems, but often you will need to cast the items to more useful types. The safe way to do that is to use rtti() before casting. This provides some of the functionality of standard C++ dynamic cast operation even on compilers where that is not available.
Note that while a QCanvasItem may be `on' a QCanvas even if it's coordinates place it far off the edge of the area of the QCanvas, collision detection only works for parts of an item that are within the area of the canvas.
[virtual]
This abstract method should draw the item using painter.
Reimplemented in QCanvasPolygonalItem and QCanvasSprite.
Returns TRUE if the QCanvasItem is enabled.
Shorthand for setVisible(FALSE).
Moves the item to (x,\a y) by calling the moveBy() virtual function.
[virtual]
Moves the item from its current position by the given amounts.
Reimplemented in QCanvasPolygon and QCanvasText.
[virtual]
Returns 0.
Although often frowned upon by purists, Run Time Type Identification is very useful in this case, as it allows a QCanvas to be an efficient indexed storage mechanism.
Make your derived classes return their own values for rtti(), and you can distinguish between objects returned by QCanvas::at(). You should use values greater than 1000 preferrably a large random number, to allow for extensions to this class.
However, it is important not to overuse this facility, as it damages extensibility. For example, once you have identified a base class of a QCanvasItem found by QCanvas::at(), cast it to that type and call meaningful methods rather than acting upon the object based on its rtti value.
For example:
QCanvasItem* item; // Find an item, eg. with QCanvasItem::collisions(). ... if (item->rtti() == MySprite::rtti()) { MySprite* s = (MySprite*)item; if (s->isDamagable()) s->loseHitPoints(1000); if (s->isHot()) myself->loseHitPoints(1000); ... }
Reimplemented in QCanvasLine, QCanvasRectangle, QCanvasPolygonalItem, QCanvasEllipse and QCanvasPolygon.
Returns TRUE if the QCanvasItem is selected.
[virtual]
Sets the active flag of the item to yes and causes it to be redrawn when QCanvas::update() is next called.
The behavior of items is not influenced by this value - it is for users of the QCanvas/QCanvasItem/QCanvasView classes to use it if needed.
Note that subclasses may not look any different if there draw() functions ignore the value of active().
Sets the item to be animated (or not if y is FALSE).
See also: advance() and QCanvas::advance().
Sets the QCanvas upon which the QCanvasItem is to be drawn to c.
See also: canvas().
[virtual]
Sets the enabled flag of the item to yes and causes it to be redrawn when QCanvas::update() is next called.
The behavior of items is not influenced by this value - it is for users of the QCanvas/QCanvasItem/QCanvasView classes to use it if needed.
Note that subclasses may not look any different if there draw() functions ignore the value of enabled().
[virtual]
Sets the selected flag of the item to yes and causes it to be redrawn.
The behavior of items is not influenced by this value - it is for users of the QCanvas/QCanvasItem/QCanvasView classes to use it if needed.
Note that subclasses may not look any different if their draw() functions ignore the value of selected().
[virtual]
Sets the item to be animated and moving by dx and dy pixels in the horizontal and vertical directions respectively.
See also: advance().
[virtual]
Makes the items visible (or invisible if yes is FALSE) when QCanvas::update() is next called.
Moves the item so that its X-position is x;
Sets the horizontal component of the item's velocity to vx.
Moves the item so that its Y-position is y;
Sets the vertical component of the item's velocity to vy.
Sets the height of the item to z. Higher-z items obscure lower-z ones.
Shorthand for setVisible(TRUE).
Returns TRUE if the QCanvasItem is visible. This does not mean the QCanvasItem is currently in a view, merely that if a view was showing the area where the QCanvasItem is, and the item was not obscured by items at a higher z, it would be visible.
See also: setVisible() and z().
Returns the horizontal position of the item. Note that subclasses often have an origin other than the top-left corner.
Returns the horizontal component of the velocity of the item.
Returns the vertical position of the item. Note that subclasses often have an origin other than the top-left corner.
Returns the vertical component of the velocity of the item.
Returns the z height of the item, which is used for visual order: higher-z items obscure lower-z ones.
Search the documentation, FAQ, qt-interest archive and more (uses
www.trolltech.com):
This file is part of the Qt toolkit, copyright © 1995-2000 Trolltech, all rights reserved.
Copyright © 2000 Trolltech | Trademarks | Qt version 2.2.0-beta0
|