1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
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 ****************************************************************************/
27 #include "parsetreenode.h"
30 RBImage::RBImage(QString file
, int tiles
, int x
, int y
, ParseTreeNode
* node
,
31 QGraphicsItem
* parent
)
32 : RBMovable(parent
), tiles(tiles
), currentTile(0),
35 /* Prevents RBMovable from interfering with initial position setting */
36 setFlag(ItemSendsGeometryChanges
, false);
38 if(QFile::exists(file
))
40 image
= new QPixmap(file
);
50 image
->setMask(image
->createMaskFromColor(QColor(255,0,255)));
54 size
= QRectF(0, 0, image
->width(), image
->height() / tiles
);
60 RBScene
* s
= dynamic_cast<RBScene
*>(scene());
61 s
->addWarning(QObject::tr("Image not found: ") + file
);
63 size
= QRectF(0, 0, 0, 0);
68 RBImage::RBImage(const RBImage
&other
, QGraphicsItem
* parent
)
69 : RBMovable(parent
), tiles(other
.tiles
), currentTile(other
.currentTile
),
73 image
= new QPixmap(*(other
.image
));
77 setPos(other
.x(), other
.y());
86 void RBImage::paint(QPainter
*painter
, const QStyleOptionGraphicsItem
*option
,
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);