summaryrefslogtreecommitdiffstats
path: root/pacman-c++/pixmapitem.cpp
diff options
context:
space:
mode:
authormanuel <manuel@mausz.at>2011-04-03 16:28:52 +0200
committermanuel <manuel@mausz.at>2011-04-03 16:28:52 +0200
commit818383fec4f220a2410177b58518797e81d8eab3 (patch)
tree695236d9cec1c9fda09a22ec6df0cc0cd2298cc5 /pacman-c++/pixmapitem.cpp
parentc3abe9924ffa2b223988cbfc206abcd88c5d4094 (diff)
downloadfoop-818383fec4f220a2410177b58518797e81d8eab3.tar.gz
foop-818383fec4f220a2410177b58518797e81d8eab3.tar.bz2
foop-818383fec4f220a2410177b58518797e81d8eab3.zip
basic pacman qt setup
Diffstat (limited to 'pacman-c++/pixmapitem.cpp')
-rw-r--r--pacman-c++/pixmapitem.cpp44
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
4PixmapItem::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
12PixmapItem::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
21void 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
29QSizeF PixmapItem::size() const
30{
31 return QSizeF(m_width, m_height);
32}
33
34QRectF PixmapItem::boundingRect() const
35{
36 return QRectF(QPointF(0, 0), size());
37}
38
39void 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