diff options
author | Thierry Bastian <thierry.bastian@nokia.com> | 2009-10-05 09:49:54 (GMT) |
---|---|---|
committer | Thierry Bastian <thierry.bastian@nokia.com> | 2009-10-05 09:51:38 (GMT) |
commit | 32a9237c49fd126bee0cbe02c3c5bff5145a6e21 (patch) | |
tree | 6fc313f62e0eafeda35483c9f3630f4275a472ec /demos/sub-attaq/pixmapitem.cpp | |
parent | 429c7c6760c100685e9800b89fca7f0afd2d8abc (diff) | |
download | Qt-32a9237c49fd126bee0cbe02c3c5bff5145a6e21.zip Qt-32a9237c49fd126bee0cbe02c3c5bff5145a6e21.tar.gz Qt-32a9237c49fd126bee0cbe02c3c5bff5145a6e21.tar.bz2 |
Simplification and use of QGraphicsObject in sub-attas demo
Reviewed-by: alexis
Diffstat (limited to 'demos/sub-attaq/pixmapitem.cpp')
-rw-r--r-- | demos/sub-attaq/pixmapitem.cpp | 33 |
1 files changed, 25 insertions, 8 deletions
diff --git a/demos/sub-attaq/pixmapitem.cpp b/demos/sub-attaq/pixmapitem.cpp index 9abf745..fcc7ce9 100644 --- a/demos/sub-attaq/pixmapitem.cpp +++ b/demos/sub-attaq/pixmapitem.cpp @@ -43,17 +43,34 @@ #include "pixmapitem.h" //Qt -#include <QtCore/QDir> +#include <QPainter> -PixmapItem::PixmapItem(const QString &fileName,GraphicsScene::Mode mode, QGraphicsItem * parent) : QGraphicsPixmapItem(parent),name(fileName) +PixmapItem::PixmapItem(const QString &fileName,GraphicsScene::Mode mode, QGraphicsItem * parent) : QGraphicsObject(parent) { - loadPixmap(mode); + if (mode == GraphicsScene::Big) + pix = ":/big/" + fileName; + else + pix = ":/small/" + fileName; } -void PixmapItem::loadPixmap(GraphicsScene::Mode mode) +PixmapItem::PixmapItem(const QString &fileName, QGraphicsScene *scene) : QGraphicsObject(), pix(fileName) { - if (mode == GraphicsScene::Big) - setPixmap(":/big/" + name); - else - setPixmap(":/small/" + name); + scene->addItem(this); } + +QSizeF PixmapItem::size() const +{ + return pix.size(); +} + +QRectF PixmapItem::boundingRect() const +{ + return QRectF(QPointF(0, 0), pix.size()); +} + +void PixmapItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *) +{ + painter->drawPixmap(0, 0, pix); +} + + |