Eneboo - Documentación para desarrolladores
|
The QCanvasItem class provides an abstract graphic object on a QCanvas.canvasA 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. Más...
#include <qcanvas.h>
Tipos públicos | |
enum | RttiValues { Rtti_Item = 0, Rtti_Sprite = 1, Rtti_PolygonalItem = 2, Rtti_Text = 3, Rtti_Polygon = 4, Rtti_Rectangle = 5, Rtti_Ellipse = 6, Rtti_Line = 7, Rtti_Spline = 8, Rtti_Item = 0, Rtti_Sprite = 1, Rtti_PolygonalItem = 2, Rtti_Text = 3, Rtti_Polygon = 4, Rtti_Rectangle = 5, Rtti_Ellipse = 6, Rtti_Line = 7, Rtti_Spline = 8 } |
enum | RttiValues { Rtti_Item = 0, Rtti_Sprite = 1, Rtti_PolygonalItem = 2, Rtti_Text = 3, Rtti_Polygon = 4, Rtti_Rectangle = 5, Rtti_Ellipse = 6, Rtti_Line = 7, Rtti_Spline = 8, Rtti_Item = 0, Rtti_Sprite = 1, Rtti_PolygonalItem = 2, Rtti_Text = 3, Rtti_Polygon = 4, Rtti_Rectangle = 5, Rtti_Ellipse = 6, Rtti_Line = 7, Rtti_Spline = 8 } |
Métodos públicos | |
QCanvasItem (QCanvas *canvas) | |
virtual | ~QCanvasItem () |
double | x () const |
double | y () const |
double | z () const |
virtual void | moveBy (double dx, double dy) |
void | move (double x, double y) |
void | setX (double a) |
void | setY (double a) |
void | setZ (double a) |
bool | animated () const |
virtual void | setAnimated (bool y) |
virtual void | setVelocity (double vx, double vy) |
void | setXVelocity (double vx) |
void | setYVelocity (double vy) |
double | xVelocity () const |
double | yVelocity () const |
virtual void | advance (int stage) |
virtual bool | collidesWith (const QCanvasItem *) const =0 |
QCanvasItemList | collisions (bool exact) const |
virtual void | setCanvas (QCanvas *) |
virtual void | draw (QPainter &)=0 |
void | show () |
void | hide () |
virtual void | setVisible (bool yes) |
bool | isVisible () const |
virtual void | setSelected (bool yes) |
bool | isSelected () const |
virtual void | setEnabled (bool yes) |
bool | isEnabled () const |
virtual void | setActive (bool yes) |
bool | isActive () const |
bool | visible () const |
bool | selected () const |
bool | enabled () const |
bool | active () const |
virtual int | rtti () const |
virtual QRect | boundingRect () const =0 |
virtual QRect | boundingRectAdvanced () const |
QCanvas * | canvas () const |
QCanvasItem (QCanvas *canvas) | |
virtual | ~QCanvasItem () |
double | x () const |
double | y () const |
double | z () const |
virtual void | moveBy (double dx, double dy) |
void | move (double x, double y) |
void | setX (double a) |
void | setY (double a) |
void | setZ (double a) |
bool | animated () const |
virtual void | setAnimated (bool y) |
virtual void | setVelocity (double vx, double vy) |
void | setXVelocity (double vx) |
void | setYVelocity (double vy) |
double | xVelocity () const |
double | yVelocity () const |
virtual void | advance (int stage) |
virtual bool | collidesWith (const QCanvasItem *) const =0 |
QCanvasItemList | collisions (bool exact) const |
virtual void | setCanvas (QCanvas *) |
virtual void | draw (QPainter &)=0 |
void | show () |
void | hide () |
virtual void | setVisible (bool yes) |
bool | isVisible () const |
virtual void | setSelected (bool yes) |
bool | isSelected () const |
virtual void | setEnabled (bool yes) |
bool | isEnabled () const |
virtual void | setActive (bool yes) |
bool | isActive () const |
bool | visible () const |
bool | selected () const |
bool | enabled () const |
bool | active () const |
virtual int | rtti () const |
virtual QRect | boundingRect () const =0 |
virtual QRect | boundingRectAdvanced () const |
QCanvas * | canvas () const |
Atributos públicos estáticos | |
static int | RTTI = Rtti_Item |
Métodos protegidos | |
void | update () |
void | update () |
Amigas | |
class | QCanvasPolygonalItem |
class | QCanvasSprite |
class | QCanvasRectangle |
class | QCanvasPolygon |
class | QCanvasEllipse |
class | QCanvasText |
class | QCanvasLine |
The QCanvasItem class provides an abstract graphic object on a QCanvas.
canvas
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(). Since the canvas background defaults to white and canvas items default to white, you may need to change colors to see your items.
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.
This enum is used to name the different types of canvas item.
Rtti_Item Canvas item abstract base class Rtti_Ellipse Rtti_Line Rtti_Polygon Rtti_PolygonalItem Rtti_Rectangle Rtti_Spline Rtti_Sprite Rtti_Text
QCanvasItem::QCanvasItem | ( | QCanvas * | canvas | ) |
Constructs a QCanvasItem on canvas canvas.
QCanvasItem::~QCanvasItem | ( | ) | [virtual] |
Destroys the QCanvasItem and removes it from its canvas.
QCanvasItem::QCanvasItem | ( | QCanvas * | canvas | ) |
virtual QCanvasItem::~QCanvasItem | ( | ) | [virtual] |
bool QCanvasItem::active | ( | ) | const [inline] |
Use isActive() instead.
bool QCanvasItem::active | ( | ) | const [inline] |
void QCanvasItem::advance | ( | int | phase | ) | [virtual] |
The default implementation moves the canvas item, if it is animated(), by the preset velocity if phase is 1, and does nothing if phase is 0.
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.
Reimplementado en QCanvasSprite y QCanvasSprite.
virtual void QCanvasItem::advance | ( | int | stage | ) | [virtual] |
Reimplementado en QCanvasSprite y QCanvasSprite.
bool QCanvasItem::animated | ( | ) | const |
Returns TRUE if the canvas item is in motion; otherwise returns FALSE.
bool QCanvasItem::animated | ( | ) | const |
QRect QCanvasItem::boundingRect | ( | ) | const [pure virtual] |
Returns the bounding rectangle in pixels that the canvas item covers.
Implementado en QCanvasSprite, QCanvasPolygonalItem, QCanvasText, QCanvasSprite, QCanvasPolygonalItem y QCanvasText.
virtual QRect QCanvasItem::boundingRect | ( | ) | const [pure virtual] |
Implementado en QCanvasSprite, QCanvasPolygonalItem, QCanvasText, QCanvasSprite, QCanvasPolygonalItem y QCanvasText.
QRect QCanvasItem::boundingRectAdvanced | ( | ) | const [virtual] |
Returns the bounding rectangle of pixels that the canvas item will cover after advance(1) is called.
virtual QRect QCanvasItem::boundingRectAdvanced | ( | ) | const [virtual] |
QCanvas* QCanvasItem::canvas | ( | ) | const [inline] |
QCanvas * QCanvasItem::canvas | ( | ) | const [inline] |
Returns the canvas containing the canvas item.
bool QCanvasItem::collidesWith | ( | const QCanvasItem * | other | ) | const [pure virtual] |
Returns TRUE if the canvas item will collide with the other item after they have moved by their current velocities; otherwise returns FALSE.
Implementado en QCanvasSprite, QCanvasPolygonalItem, QCanvasRectangle, QCanvasEllipse, QCanvasText, QCanvasSprite, QCanvasPolygonalItem, QCanvasRectangle, QCanvasEllipse y QCanvasText.
virtual bool QCanvasItem::collidesWith | ( | const QCanvasItem * | ) | const [pure virtual] |
QCanvasItemList QCanvasItem::collisions | ( | bool | exact | ) | const |
Returns the list of canvas items that this canvas item has collided with.
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.
Note that if items have a velocity (see setVelocity()), then collision testing is done based on where the item will be when it moves, not its current location. For example, a "ball" item doesn't need to actually embed into a "wall" item before a collision is detected. For items without velocity, plain intersection is used.
QCanvasItemList QCanvasItem::collisions | ( | bool | exact | ) | const |
void QCanvasItem::draw | ( | QPainter & | painter | ) | [pure virtual] |
This abstract virtual function draws the canvas item using painter.
Implementado en QCanvasSprite, QCanvasPolygonalItem, QCanvasText, QCanvasSprite, QCanvasPolygonalItem y QCanvasText.
virtual void QCanvasItem::draw | ( | QPainter & | ) | [pure virtual] |
Implementado en QCanvasSprite, QCanvasPolygonalItem, QCanvasText, QCanvasSprite, QCanvasPolygonalItem y QCanvasText.
bool QCanvasItem::enabled | ( | ) | const [inline] |
Use isEnabled() instead.
bool QCanvasItem::enabled | ( | ) | const [inline] |
void QCanvasItem::hide | ( | ) |
Shorthand for setVisible(FALSE).
void QCanvasItem::hide | ( | ) |
bool QCanvasItem::isActive | ( | ) | const [inline] |
bool QCanvasItem::isActive | ( | ) | const [inline] |
Returns TRUE if the QCanvasItem is active; otherwise returns FALSE.
bool QCanvasItem::isEnabled | ( | ) | const [inline] |
bool QCanvasItem::isEnabled | ( | ) | const [inline] |
Returns TRUE if the QCanvasItem is enabled; otherwise returns FALSE.
bool QCanvasItem::isSelected | ( | ) | const [inline] |
bool QCanvasItem::isSelected | ( | ) | const [inline] |
Returns TRUE if the canvas item is selected; otherwise returns FALSE.
bool QCanvasItem::isVisible | ( | ) | const [inline] |
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.
bool QCanvasItem::isVisible | ( | ) | const [inline] |
void QCanvasItem::move | ( | double | x, |
double | y | ||
) |
Moves the canvas item to the absolute position (x, y).
Reimplementado en QCanvasSprite y QCanvasSprite.
void QCanvasItem::move | ( | double | x, |
double | y | ||
) |
Reimplementado en QCanvasSprite y QCanvasSprite.
void QCanvasItem::moveBy | ( | double | dx, |
double | dy | ||
) | [virtual] |
Moves the canvas item relative to its current position by (dx, dy).
Reimplementado en QCanvasPolygon, QCanvasLine, QCanvasText, QCanvasPolygon, QCanvasLine y QCanvasText.
virtual void QCanvasItem::moveBy | ( | double | dx, |
double | dy | ||
) | [virtual] |
Reimplementado en QCanvasPolygon, QCanvasLine, QCanvasText, QCanvasPolygon, QCanvasLine y QCanvasText.
int QCanvasItem::rtti | ( | ) | const [virtual] |
Returns 0 (QCanvasItem::Rtti_Item).
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, e.g. with QCanvasItem::collisions(). ... if (item->rtti() == MySprite::RTTI ) { MySprite* s = (MySprite*)item; if (s->isDamagable()) s->loseHitPoints(1000); if (s->isHot()) myself->loseHitPoints(1000); ... }
Reimplementado en QCanvasSprite, QCanvasPolygonalItem, QCanvasRectangle, QCanvasPolygon, QCanvasSpline, QCanvasLine, QCanvasEllipse, QCanvasText, QCanvasSprite, QCanvasPolygonalItem, QCanvasRectangle, QCanvasPolygon, QCanvasSpline, QCanvasLine, QCanvasEllipse y QCanvasText.
virtual int QCanvasItem::rtti | ( | ) | const [virtual] |
bool QCanvasItem::selected | ( | ) | const [inline] |
Use isSelected() instead.
bool QCanvasItem::selected | ( | ) | const [inline] |
virtual void QCanvasItem::setActive | ( | bool | yes | ) | [virtual] |
void QCanvasItem::setActive | ( | bool | yes | ) | [virtual] |
Sets the active flag of the item to yes. If this changes the item's active state the item will be redrawn when QCanvas::update() is next called.
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.
void QCanvasItem::setAnimated | ( | bool | y | ) | [virtual] |
Sets the canvas item to be in motion if y is TRUE, or not if y is FALSE. The speed and direction of the motion is set with setVelocity(), or with setXVelocity() and setYVelocity().
virtual void QCanvasItem::setAnimated | ( | bool | y | ) | [virtual] |
void QCanvasItem::setCanvas | ( | QCanvas * | c | ) | [virtual] |
virtual void QCanvasItem::setCanvas | ( | QCanvas * | ) | [virtual] |
virtual void QCanvasItem::setEnabled | ( | bool | yes | ) | [virtual] |
void QCanvasItem::setEnabled | ( | bool | yes | ) | [virtual] |
Sets the enabled flag of the item to yes. If this changes the item's enabled state the item will be redrawn when QCanvas::update() is next called.
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.
void QCanvasItem::setSelected | ( | bool | yes | ) | [virtual] |
Sets the selected flag of the item to yes. If this changes the item's selected state the item will be redrawn when QCanvas::update() is next called.
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.
virtual void QCanvasItem::setSelected | ( | bool | yes | ) | [virtual] |
void QCanvasItem::setVelocity | ( | double | vx, |
double | vy | ||
) | [virtual] |
Sets the canvas item to be in motion, moving by vx and vy pixels in the horizontal and vertical directions respectively.
virtual void QCanvasItem::setVelocity | ( | double | vx, |
double | vy | ||
) | [virtual] |
virtual void QCanvasItem::setVisible | ( | bool | yes | ) | [virtual] |
void QCanvasItem::setVisible | ( | bool | yes | ) | [virtual] |
Makes the canvas item visible if yes is TRUE, or invisible if yes is FALSE. The change takes effect when QCanvas::update() is next called.
void QCanvasItem::setX | ( | double | a | ) | [inline] |
void QCanvasItem::setX | ( | double | x | ) | [inline] |
void QCanvasItem::setXVelocity | ( | double | vx | ) | [inline] |
Sets the horizontal component of the canvas item's velocity to vx.
void QCanvasItem::setXVelocity | ( | double | vx | ) | [inline] |
void QCanvasItem::setY | ( | double | a | ) | [inline] |
void QCanvasItem::setY | ( | double | y | ) | [inline] |
void QCanvasItem::setYVelocity | ( | double | vy | ) | [inline] |
Sets the vertical component of the canvas item's velocity to vy.
void QCanvasItem::setYVelocity | ( | double | vy | ) | [inline] |
void QCanvasItem::setZ | ( | double | z | ) | [inline] |
void QCanvasItem::setZ | ( | double | a | ) | [inline] |
void QCanvasItem::show | ( | ) |
Shorthand for setVisible(TRUE).
void QCanvasItem::show | ( | ) |
void QCanvasItem::update | ( | ) | [inline, protected] |
Call this function to repaint the canvas's changed chunks.
void QCanvasItem::update | ( | ) | [inline, protected] |
bool QCanvasItem::visible | ( | ) | const [inline] |
Use isVisible() instead.
bool QCanvasItem::visible | ( | ) | const [inline] |
double QCanvasItem::x | ( | ) | const [inline] |
double QCanvasItem::x | ( | ) | const [inline] |
Returns the horizontal position of the canvas item. Note that subclasses often have an origin other than the top-left corner.
double QCanvasItem::xVelocity | ( | ) | const |
double QCanvasItem::xVelocity | ( | ) | const |
Returns the horizontal velocity component of the canvas item.
double QCanvasItem::y | ( | ) | const [inline] |
Returns the vertical position of the canvas item. Note that subclasses often have an origin other than the top-left corner.
double QCanvasItem::y | ( | ) | const [inline] |
double QCanvasItem::yVelocity | ( | ) | const |
double QCanvasItem::yVelocity | ( | ) | const |
Returns the vertical velocity component of the canvas item.
double QCanvasItem::z | ( | ) | const [inline] |
double QCanvasItem::z | ( | ) | const [inline] |
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.
QCanvasEllipse [friend] |
QCanvasLine [friend] |
QCanvasPolygon [friend] |
QCanvasPolygonalItem [friend] |
QCanvasRectangle [friend] |
QCanvasSprite [friend] |
QCanvasText [friend] |
static int QCanvasItem::RTTI = Rtti_Item [static] |
Reimplementado en QCanvasSprite, QCanvasPolygonalItem, QCanvasRectangle, QCanvasPolygon, QCanvasSpline, QCanvasLine, QCanvasEllipse y QCanvasText.