2 Copyright (c) 2007 Paolo Capriotti <p.capriotti@gmail.com>
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
14 Ball::Ball(Renderer
* renderer
, const QString
& id
)
16 , m_velocity(0.0, 0.0)
18 setPixmap(renderer
->render(id
));
19 setShapeMode(BoundingRectShape
);
20 QSize size
= pixmap().size();
21 translate(-size
.width() / 2, -size
.height() / 2);
22 setAcceptsHoverEvents(false);
25 void Ball::paint(QPainter
*painter
,
26 const QStyleOptionGraphicsItem
* option
,
29 qreal oldOpacity
= painter
->opacity();
30 painter
->setOpacity(m_opacity
);
31 QGraphicsPixmapItem::paint(painter
, option
, widget
);
32 painter
->setOpacity(oldOpacity
);
35 void Ball::setOpacityF(qreal opacity
)
41 qreal
Ball::opacityF() const
46 void Ball::setVelocity(const QPointF
& vel
)
51 QPointF
Ball::velocity() const
56 void Ball::setPosition(const QPointF
& pos
)
58 QGraphicsPixmapItem::setPos(pos
);
61 QPointF
Ball::position() const
63 return QGraphicsPixmapItem::pos();
66 qreal
Ball::radius() const
68 return pixmap().size().width() / 2.0;