SVN_SILENT made messages (.desktop file)
[kdegames.git] / kollision / ball.cpp
blobb4519e742f32be057f4adff39fa7aef2f5726748
1 /*
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.
8 */
10 #include "ball.h"
11 #include <QPainter>
12 #include "renderer.h"
14 Ball::Ball(Renderer* renderer, const QString& id)
15 : m_opacity(1.0)
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,
27 QWidget* widget)
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)
37 m_opacity = opacity;
38 update();
41 qreal Ball::opacityF() const
43 return m_opacity;
46 void Ball::setVelocity(const QPointF& vel)
48 m_velocity = vel;
51 QPointF Ball::velocity() const
53 return m_velocity;
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;