From 818383fec4f220a2410177b58518797e81d8eab3 Mon Sep 17 00:00:00 2001 From: manuel Date: Sun, 3 Apr 2011 16:28:52 +0200 Subject: basic pacman qt setup --- pacman-c++/pixmapitem.cpp | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 pacman-c++/pixmapitem.cpp (limited to 'pacman-c++/pixmapitem.cpp') diff --git a/pacman-c++/pixmapitem.cpp b/pacman-c++/pixmapitem.cpp new file mode 100644 index 0000000..9c2f941 --- /dev/null +++ b/pacman-c++/pixmapitem.cpp @@ -0,0 +1,44 @@ +#include "pixmapitem.h" +#include + +PixmapItem::PixmapItem(const QString &fileName, QGraphicsItem *parent) + : QGraphicsObject(parent), m_x(0), m_y(0) +{ + m_pix = ":/" + fileName; + m_width = m_pix.width(); + m_height = m_pix.height(); +} + +PixmapItem::PixmapItem(const QString &fileName, QGraphicsScene *scene) + : QGraphicsObject(), m_x(0), m_y(0) +{ + m_pix = ":/" + fileName; + m_width = m_pix.width(); + m_height = m_pix.height(); + scene->addItem(this); +} + +void PixmapItem::setSprite(int x, int y, int width, int height) +{ + m_x = x; + m_y = y; + m_width = width; + m_height = height; +} + +QSizeF PixmapItem::size() const +{ + return QSizeF(m_width, m_height); +} + +QRectF PixmapItem::boundingRect() const +{ + return QRectF(QPointF(0, 0), size()); +} + +void PixmapItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *) +{ + painter->drawPixmap(0, 0, m_pix, m_x, m_y, m_width, m_height); +} + + -- cgit v1.2.3