From a35824a3319ae9c304263185c4efc449e2c2cf73 Mon Sep 17 00:00:00 2001 From: manuel Date: Mon, 4 Apr 2011 11:27:54 +0200 Subject: added simple pacman animation --- pacman-c++/pixmapitem.cpp | 44 ++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 42 insertions(+), 2 deletions(-) (limited to 'pacman-c++/pixmapitem.cpp') diff --git a/pacman-c++/pixmapitem.cpp b/pacman-c++/pixmapitem.cpp index 9c2f941..a977a9e 100644 --- a/pacman-c++/pixmapitem.cpp +++ b/pacman-c++/pixmapitem.cpp @@ -1,10 +1,16 @@ #include "pixmapitem.h" #include +#include + +PixmapItem::PixmapItem(QGraphicsItem *parent) + : QGraphicsObject(parent), m_x(0), m_y(0) +{ +} PixmapItem::PixmapItem(const QString &fileName, QGraphicsItem *parent) : QGraphicsObject(parent), m_x(0), m_y(0) { - m_pix = ":/" + fileName; + m_pix = ":/" + fileName; m_width = m_pix.width(); m_height = m_pix.height(); } @@ -12,12 +18,34 @@ PixmapItem::PixmapItem(const QString &fileName, QGraphicsItem *parent) PixmapItem::PixmapItem(const QString &fileName, QGraphicsScene *scene) : QGraphicsObject(), m_x(0), m_y(0) { - m_pix = ":/" + fileName; + m_pix = ":/" + fileName; m_width = m_pix.width(); m_height = m_pix.height(); scene->addItem(this); } +PixmapItem::PixmapItem(const QPixmap &pix, QGraphicsItem *parent) + : QGraphicsObject(parent), m_pix(pix), m_x(0), m_y(0) +{ + m_width = m_pix.width(); + m_height = m_pix.height(); +} + +PixmapItem::PixmapItem(const QPixmap &pix, QGraphicsScene *scene) + : QGraphicsObject(), m_pix(pix), m_x(0), m_y(0) +{ + m_width = m_pix.width(); + m_height = m_pix.height(); + scene->addItem(this); +} + +void PixmapItem::setPixmap(const QPixmap &pix) +{ + m_pix = pix; + m_width = m_pix.width(); + m_height = m_pix.height(); +} + void PixmapItem::setSprite(int x, int y, int width, int height) { m_x = x; @@ -41,4 +69,16 @@ void PixmapItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWid painter->drawPixmap(0, 0, m_pix, m_x, m_y, m_width, m_height); } +#if 0 +bool PixmapItem::isVisible() const +{ + qDebug() << "isVisible()"; + return true; +} + +void PixmapItem::setVisible(bool v) +{ + qDebug() << "setVisible(" << v << ")"; +} +#endif -- cgit v1.2.3