File indexing completed on 2024-03-24 04:06:20
0001 /* 0002 SPDX-FileCopyrightText: 2007 Paolo Capriotti <p.capriotti@gmail.com> 0003 SPDX-FileCopyrightText: 2010 Brian Croom <brian.s.croom@gmail.com> 0004 0005 SPDX-License-Identifier: GPL-2.0-or-later 0006 */ 0007 0008 #include "ball.h" 0009 #include <KGameRenderer> 0010 0011 Ball::Ball(KGameRenderer* renderer, const QString& id, int size) 0012 : KGameRenderedItem(renderer, id), m_velocity(0.0, 0.0) 0013 { 0014 setRenderSize(QSize(size, size)); 0015 setShapeMode(BoundingRectShape); 0016 setTransform(QTransform::fromTranslate(-size / 2, -size / 2), true); 0017 setAcceptHoverEvents(false); 0018 } 0019 0020 void Ball::setOpacityF(qreal opacity) 0021 { 0022 QGraphicsItem::setOpacity(opacity); 0023 } 0024 0025 qreal Ball::opacityF() const 0026 { 0027 return QGraphicsItem::opacity(); 0028 } 0029 0030 void Ball::setVelocity(const QPointF& vel) 0031 { 0032 m_velocity = vel; 0033 } 0034 0035 QPointF Ball::velocity() const 0036 { 0037 return m_velocity; 0038 } 0039 0040 void Ball::setPosition(const QPointF& pos) 0041 { 0042 QGraphicsPixmapItem::setPos(pos); 0043 } 0044 0045 QPointF Ball::position() const 0046 { 0047 return QGraphicsPixmapItem::pos(); 0048 } 0049 0050 qreal Ball::radius() const 0051 { 0052 return renderSize().width() / 2.0; 0053 }