Remove two unused defines.
[maemo-rb.git] / utils / themeeditor / graphics / rbimage.cpp
blob31159ecf7549d91aaf821a835e9aff7d6cfaff8a
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
10 * Copyright (C) 2010 Robert Bieber
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
20 ****************************************************************************/
22 #include <QPainter>
23 #include <QFile>
24 #include <QBitmap>
26 #include "rbimage.h"
27 #include "parsetreenode.h"
28 #include <rbscene.h>
30 RBImage::RBImage(QString file, int tiles, int x, int y, ParseTreeNode* node,
31 QGraphicsItem* parent)
32 : RBMovable(parent), tiles(tiles), currentTile(0),
33 node(node)
35 /* Prevents RBMovable from interfering with initial position setting */
36 setFlag(ItemSendsGeometryChanges, false);
38 if(QFile::exists(file))
40 image = new QPixmap(file);
42 if(image->isNull())
44 delete image;
45 image = 0;
46 return;
48 else
50 image->setMask(image->createMaskFromColor(QColor(255,0,255)));
54 size = QRectF(0, 0, image->width(), image->height() / tiles);
55 setPos(x, y);
58 else
60 RBScene* s = dynamic_cast<RBScene*>(scene());
61 s->addWarning(QObject::tr("Image not found: ") + file);
63 size = QRectF(0, 0, 0, 0);
64 image = 0;
68 RBImage::RBImage(const RBImage &other, QGraphicsItem* parent)
69 : RBMovable(parent), tiles(other.tiles), currentTile(other.currentTile),
70 node(other.node)
72 if(other.image)
73 image = new QPixmap(*(other.image));
74 else
75 image = 0;
76 size = other.size;
77 setPos(other.x(), other.y());
80 RBImage::~RBImage()
82 if(image)
83 delete image;
86 void RBImage::paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
87 QWidget *widget)
89 if(!image)
90 return;
92 painter->drawPixmap(size, *image, QRect(0, currentTile * image->height()
93 / tiles, image->width(),
94 image->height() / tiles));
96 RBMovable::paint(painter, option, widget);
101 void RBImage::saveGeometry()
103 QPointF origin = pos();
105 node->modParam(static_cast<int>(origin.x()), 2);
106 node->modParam(static_cast<int>(origin.y()), 3);