1 | /* |
---|---|
2 | Copyright (c) 2007 Paolo Capriotti <p.capriotti@gmail.com> |
3 | Copyright (c) 2010 Brian Croom <brian.s.croom@gmail.com> |
4 | |
5 | This program is free software; you can redistribute it and/or modify |
6 | it under the terms of the GNU General Public License as published by |
7 | the Free Software Foundation; either version 2 of the License, or |
8 | (at your option) any later version. |
9 | */ |
10 | |
11 | #include "ball.h" |
12 | #include <QPainter> |
13 | #include <KGameRenderer> |
14 | |
15 | Ball::Ball(KGameRenderer* renderer, const QString& id, int size) |
16 | : KGameRenderedItem(renderer, id), m_velocity(0.0, 0.0) |
17 | { |
18 | setRenderSize(QSize(size, size)); |
19 | setShapeMode(BoundingRectShape); |
20 | translate(-size / 2, -size / 2); |
21 | setAcceptsHoverEvents(false); |
22 | } |
23 | |
24 | void Ball::setOpacityF(qreal opacity) |
25 | { |
26 | QGraphicsItem::setOpacity(opacity); |
27 | } |
28 | |
29 | qreal Ball::opacityF() const |
30 | { |
31 | return QGraphicsItem::opacity(); |
32 | } |
33 | |
34 | void Ball::setVelocity(const QPointF& vel) |
35 | { |
36 | m_velocity = vel; |
37 | } |
38 | |
39 | QPointF Ball::velocity() const |
40 | { |
41 | return m_velocity; |
42 | } |
43 | |
44 | void Ball::setPosition(const QPointF& pos) |
45 | { |
46 | QGraphicsPixmapItem::setPos(pos); |
47 | } |
48 | |
49 | QPointF Ball::position() const |
50 | { |
51 | return QGraphicsPixmapItem::pos(); |
52 | } |
53 | |
54 | qreal Ball::radius() const |
55 | { |
56 | return renderSize().width() / 2.0; |
57 | } |
58 |