diff options
Diffstat (limited to 'pacman-c++/pixmapitem.cpp')
| -rw-r--r-- | pacman-c++/pixmapitem.cpp | 44 |
1 files changed, 44 insertions, 0 deletions
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 @@ | |||
| 1 | #include "pixmapitem.h" | ||
| 2 | #include <QPainter> | ||
| 3 | |||
| 4 | PixmapItem::PixmapItem(const QString &fileName, QGraphicsItem *parent) | ||
| 5 | : QGraphicsObject(parent), m_x(0), m_y(0) | ||
| 6 | { | ||
| 7 | m_pix = ":/" + fileName; | ||
| 8 | m_width = m_pix.width(); | ||
| 9 | m_height = m_pix.height(); | ||
| 10 | } | ||
| 11 | |||
| 12 | PixmapItem::PixmapItem(const QString &fileName, QGraphicsScene *scene) | ||
| 13 | : QGraphicsObject(), m_x(0), m_y(0) | ||
| 14 | { | ||
| 15 | m_pix = ":/" + fileName; | ||
| 16 | m_width = m_pix.width(); | ||
| 17 | m_height = m_pix.height(); | ||
| 18 | scene->addItem(this); | ||
| 19 | } | ||
| 20 | |||
| 21 | void PixmapItem::setSprite(int x, int y, int width, int height) | ||
| 22 | { | ||
| 23 | m_x = x; | ||
| 24 | m_y = y; | ||
| 25 | m_width = width; | ||
| 26 | m_height = height; | ||
| 27 | } | ||
| 28 | |||
| 29 | QSizeF PixmapItem::size() const | ||
| 30 | { | ||
| 31 | return QSizeF(m_width, m_height); | ||
| 32 | } | ||
| 33 | |||
| 34 | QRectF PixmapItem::boundingRect() const | ||
| 35 | { | ||
| 36 | return QRectF(QPointF(0, 0), size()); | ||
| 37 | } | ||
| 38 | |||
| 39 | void PixmapItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *) | ||
| 40 | { | ||
| 41 | painter->drawPixmap(0, 0, m_pix, m_x, m_y, m_width, m_height); | ||
| 42 | } | ||
| 43 | |||
| 44 | |||
