Home | All Classes | Main Classes | Annotated | Grouped Classes | Functions |
The QCanvasItem class provides an abstract graphic object on a QCanvas. More...
#include <qcanvas.h>
Inherits Qt.
Inherited by QCanvasSprite, QCanvasPolygonalItem and QCanvasText.
A variety of QCanvasItem subclasses provide immediately usable behaviour. This class is a pure abstract superclass providing the behaviour that is shared among all the concrete canvas item classes. QCanvasItem is not intended for direct subclassing. It is much easier to subclass one of its subclasses, e.g. QCanvasPolygonalItem (the commonest base class), QCanvasRectangle, QCanvasSprite, QCanvasEllipse or QCanvasText.
Canvas items are added to a canvas by constructing them and passing the canvas to the canvas item's constructor. An item can be moved to a different canvas using setCanvas().
Items appear on the canvas after their show() function has been called (or setVisible(TRUE)), and after update() has been called. The canvas only shows items that are visible, and then only if update() is called. If you created the canvas without passing a width and height to the constructor you'll also need to call resize().
A QCanvasItem object can be moved in the x(), y() and z() dimensions using functions such as move(), moveBy(), setX(), setY() and setZ(). A canvas item can be set in motion, `animated', using setAnimated() and given a velocity in the x and y directions with setXVelocity() and setYVelocity() -- the same effect can be achieved by calling setVelocity(). Use the collidesWith() function to see if the canvas item will collide on the next advance(1) and use collisions() to see what collisions have occurred.
Use QCanvasSprite or your own subclass of QCanvasSprite to create canvas items which are animated, i.e. which change over time.
The size of a canvas item is given by boundingRect(). Use boundingRectAdvanced() to see what the size of the canvas item will be after the next advance(1) call.
The rtti() function is used for identifying subclasses of QCanvasItem. The canvas() function returns a pointer to the canvas which contains the canvas item.
QCanvasItem provides the show() and isVisible() functions like those in QWidget.
QCanvasItem also provides the setEnabled(), setActive() and setSelected() functions; these functions set the relevant boolean and cause a repaint but the boolean values they set are not used in QCanvasItem itself. You can make use of these booleans in your subclasses.
By default, canvas items have no velocity, no size, and are not in motion. The subclasses provided in Qt do not change these defaults except where noted.
See also Graphics Classes and Image Processing Classes.
This enum is used to name the different types of canvas item.
See also setCanvas().
Use isActive() instead.
Note that if you reimplement this function, the reimplementation must not change the canvas in any way, for example it must not add or remove items.
See also QCanvas::advance() and setVelocity().
Example: canvas/canvas.cpp.
Reimplemented in QCanvasSprite.
See also setVelocity() and setAnimated().
Returns the bounding rectangle in pixels that the canvas item covers.
See also boundingRectAdvanced().
Reimplemented in QCanvasSprite, QCanvasPolygonalItem and QCanvasText.
See also boundingRect().
Returns the canvas containing the canvas item.
Returns TRUE if the canvas item will collide with the other item after they have moved by their current velocities; otherwise returns FALSE.
See also collisions().
Example: canvas/canvas.cpp.
A collision is generally defined as occurring when the pixels of one item draw on the pixels of another item, but not all subclasses are so precise. Also, since pixel-wise collision detection can be slow, this function works in either exact or inexact mode, according to the exact parameter.
If exact is TRUE, the canvas items returned have been accurately tested for collision with the canvas item.
If exact is FALSE, the canvas items returned are near the canvas item. You can test the canvas items returned using collidesWith() if any are interesting collision candidates. By using this approach, you can ignore some canvas items for which collisions are not relevant.
The returned list is a list of QCanvasItems, but often you will need to cast the items to their subclass types. The safe way to do this is to use rtti() before casting. This provides some of the functionality of the standard C++ dynamic cast operation even on compilers where dynamic casts are not available.
Note that a canvas item may be `on' a canvas, e.g. it was created with the canvas as parameter, even though its coordinates place it beyond the edge of the canvas's area. Collision detection only works for canvas items which are wholly or partly within the canvas's area.
This abstract virtual function draws the canvas item using painter.
Reimplemented in QCanvasSprite, QCanvasPolygonalItem and QCanvasText.
Use isEnabled() instead.
Returns TRUE if the QCanvasItem is active; otherwise returns FALSE.
Returns TRUE if the QCanvasItem is enabled; otherwise returns FALSE.
Returns TRUE if the canvas item is selected; otherwise returns FALSE.
Returns TRUE if the canvas item is visible; otherwise returns FALSE.
Note that in this context TRUE does not mean that the canvas item is currently in a view, merely that if a view is showing the area where the canvas item is positioned, and the item is not obscured by items with higher z values, and the view is not obscured by overlaying windows, it would be visible.
See also setVisible() and z().
Example: canvas/canvas.cpp.
Example: canvas/canvas.cpp.
Make your derived classes return their own values for rtti(), so that you can distinguish between objects returned by QCanvas::at(). You should use values greater than 1000 to allow for extensions to this class.
Overuse of this functionality can damage it's 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); ... }
Example: canvas/canvas.cpp.
Reimplemented in QCanvasSprite, QCanvasPolygonalItem and QCanvasText.
Use isSelected() instead.
The QCanvas, QCanvasItem and the Qt-supplied QCanvasItem subclasses do not make use of this value. The setActive() function is supplied because many applications need it, but it is up to you how you use the isActive() value.
See also advance() and QCanvas::advance().
See also canvas().
The QCanvas, QCanvasItem and the Qt-supplied QCanvasItem subclasses do not make use of this value. The setEnabled() function is supplied because many applications need it, but it is up to you how you use the isEnabled() value.
The QCanvas, QCanvasItem and the Qt-supplied QCanvasItem subclasses do not make use of this value. The setSelected() function is supplied because many applications need it, but it is up to you how you use the isSelected() value.
See also advance().
Moves the canvas item so that its x-position is x.
Sets the horizontal component of the canvas item's velocity to vx.
Moves the canvas item so that its y-position is y.
Sets the vertical component of the canvas item's velocity to vy.
Sets the z index of the canvas item to z. Higher-z items obscure (are in front of) lower-z items.
Example: canvas/canvas.cpp.
Example: canvas/canvas.cpp.
Call this function to repaint the canvas's changed chunks.
Use isVisible() instead.
Returns the horizontal position of the canvas item. Note that subclasses often have an origin other than the top-left corner.
Example: canvas/canvas.cpp.
Returns the vertical position of the canvas item. Note that subclasses often have an origin other than the top-left corner.
Example: canvas/canvas.cpp.
Returns the z index of the canvas item, which is used for visual order: higher-z items obscure (are in front of) lower-z items.
This file is part of the Qt toolkit. Copyright © 1995-2002 Trolltech. All Rights Reserved.
Copyright © 2002 Trolltech | Trademarks | Qt version 3.0.4
|