AnimatedPixmapItem Class Reference

#include <animateditem.h>

Inheritance diagram for AnimatedPixmapItem:

Inheritance graph
[legend]
Collaboration diagram for AnimatedPixmapItem:

Collaboration graph
[legend]
List of all members.

Detailed Description

Definition at line 29 of file animateditem.h.

Public Member Functions

 AnimatedPixmapItem (const QList< QPixmap > &animation, QGraphicsScene *scene=0)
void setFrame (int frame)
int frame () const
int frameCount () const
QPixmap image (int frame) const
void setVelocity (qreal xvel, qreal yvel)
qreal xVelocity () const
qreal yVelocity () const
QPainterPath shape () const
void advance (int phase)

Private Attributes

int currentFrame
QList< QPixmapframes
qreal vx
qreal vy


Constructor & Destructor Documentation

AnimatedPixmapItem::AnimatedPixmapItem ( const QList< QPixmap > &  animation,
QGraphicsScene scene = 0 
)

Definition at line 26 of file animateditem.cpp.

00028     : QGraphicsPixmapItem(0, scene), currentFrame(0), frames(animation), vx(0), vy(0)
00029 {
00030 }


Member Function Documentation

void AnimatedPixmapItem::setFrame ( int  frame  ) 

Definition at line 32 of file animateditem.cpp.

References QList< T >::at(), currentFrame, frames, QList< T >::isEmpty(), QGraphicsPixmapItem::setPixmap(), and QList< T >::size().

Referenced by KAsteroidsView::newShip(), KRock::nextFrame(), KAsteroidsView::processShip(), and KAsteroidsView::rockHit().

00033 {
00034     if (!frames.isEmpty()) {
00035         currentFrame = frame % frames.size();
00036         setPixmap(frames.at(currentFrame));
00037     }
00038 }

Here is the call graph for this function:

int AnimatedPixmapItem::frame (  )  const [inline]

Definition at line 35 of file animateditem.h.

References currentFrame.

Referenced by KRock::nextFrame(), and KAsteroidsView::processShip().

00036     { return currentFrame; }

int AnimatedPixmapItem::frameCount (  )  const [inline]

Definition at line 37 of file animateditem.h.

References frames, and QList< T >::size().

Referenced by KRock::nextFrame(), KAsteroidsView::processShip(), and KAsteroidsView::rockHit().

00038     { return frames.size(); }

Here is the call graph for this function:

QPixmap AnimatedPixmapItem::image ( int  frame  )  const [inline]

Definition at line 39 of file animateditem.h.

References QList< T >::at(), frames, QList< T >::isEmpty(), and QList< T >::size().

Referenced by KAsteroidsView::readSprites().

00040     { return frames.isEmpty() ? QPixmap() : frames.at(frame % frames.size()); }

Here is the call graph for this function:

void AnimatedPixmapItem::setVelocity ( qreal  xvel,
qreal  yvel 
) [inline]

Definition at line 41 of file animateditem.h.

References vx, and vy.

Referenced by KAsteroidsView::newShip(), KAsteroidsView::processShip(), and KAsteroidsView::rockHit().

00042     { vx = xvel; vy = yvel; }

qreal AnimatedPixmapItem::xVelocity (  )  const [inline]

Definition at line 43 of file animateditem.h.

References vx.

Referenced by KAsteroidsView::rockHit().

00044     { return vx; }

qreal AnimatedPixmapItem::yVelocity (  )  const [inline]

Definition at line 45 of file animateditem.h.

References vy.

Referenced by KAsteroidsView::rockHit().

00046     { return vy; }

QPainterPath AnimatedPixmapItem::shape (  )  const [virtual]

Reimplemented from QGraphicsPixmapItem.

Definition at line 50 of file animateditem.cpp.

References QList< T >::at(), currentFrame, frames, QPixmap::height(), path, and QPixmap::width().

00051 {
00052     QPainterPath path;
00053     path.addRect(0, 0,
00054                  frames.at(currentFrame).width(),
00055                  frames.at(currentFrame).height());
00056     return path;
00057 }

Here is the call graph for this function:

void AnimatedPixmapItem::advance ( int  phase  )  [virtual]

This virtual function is called twice for all items by the QGraphicsScene::advance() slot. In the first phase, all items are called with phase == 0, indicating that items on the scene are about to advance, and then all items are called with phase == 1. Reimplement this function to update your item if you need simple scene-controlled animation.

The default implementation does nothing.

For individual item animation, an alternative to this function is to either use QGraphicsItemAnimation, or to multiple-inherit from QObject and QGraphicsItem, and animate your item using QObject::startTimer() and QObject::timerEvent().

See also:
QGraphicsItemAnimation, QTimeLine

Reimplemented from QGraphicsItem.

Definition at line 40 of file animateditem.cpp.

References QList< T >::at(), currentFrame, frames, QList< T >::isEmpty(), QGraphicsItem::moveBy(), QGraphicsPixmapItem::setPixmap(), QList< T >::size(), vx, and vy.

00041 {
00042     if (phase == 1 && !frames.isEmpty()) {
00043         currentFrame = (currentFrame + 1) % frames.size();
00044         setPixmap(frames.at(currentFrame));
00045         if (vx || vy)
00046             moveBy(vx, vy);
00047     }
00048 }

Here is the call graph for this function:


Member Data Documentation

int AnimatedPixmapItem::currentFrame [private]

Definition at line 53 of file animateditem.h.

Referenced by advance(), frame(), setFrame(), and shape().

QList<QPixmap> AnimatedPixmapItem::frames [private]

Definition at line 54 of file animateditem.h.

Referenced by advance(), frameCount(), image(), setFrame(), and shape().

qreal AnimatedPixmapItem::vx [private]

Definition at line 55 of file animateditem.h.

Referenced by advance(), setVelocity(), and xVelocity().

qreal AnimatedPixmapItem::vy [private]

Definition at line 55 of file animateditem.h.

Referenced by advance(), setVelocity(), and yVelocity().


The documentation for this class was generated from the following files:
Generated on Thu Mar 15 14:43:53 2007 for Qt 4.2 User's Guide by  doxygen 1.5.1