From ce48af53646cd9e7ec762fc1ac176b3aa620b11d Mon Sep 17 00:00:00 2001 From: manuel Date: Thu, 5 May 2011 00:57:07 +0200 Subject: - refactorized the whole project and made a few subprojects - replaced tcp with enet - added connect dialog - some smaller bugfixes --- pacman-c++/common/pixmapitem.cpp | 77 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 77 insertions(+) create mode 100644 pacman-c++/common/pixmapitem.cpp (limited to 'pacman-c++/common/pixmapitem.cpp') diff --git a/pacman-c++/common/pixmapitem.cpp b/pacman-c++/common/pixmapitem.cpp new file mode 100644 index 0000000..1ceeec1 --- /dev/null +++ b/pacman-c++/common/pixmapitem.cpp @@ -0,0 +1,77 @@ +#include "pixmapitem.h" +#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_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); +} + +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; + 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()); +} + +QPainterPath PixmapItem::shape() const +{ + QPainterPath path; + path.addRect(boundingRect()); + return path; +} + +void PixmapItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *) +{ + painter->drawPixmap(QPoint(0, 0), m_pix, QRect(m_x, m_y, m_width, m_height)); +} + -- cgit v1.2.3