File indexing completed on 2024-04-21 04:02:34

0001 /*
0002     This file is part of the KDE project "KLines"
0003 
0004     SPDX-FileCopyrightText: 2006 Dmitry Suzdalev <dimsuz@gmail.com>
0005 
0006     SPDX-License-Identifier: GPL-2.0-or-later
0007 */
0008 
0009 #ifndef BALL_ITEM_H
0010 #define BALL_ITEM_H
0011 
0012 #include <KGameRenderedItem>
0013 #include <QTimeLine>
0014 
0015 #include "commondefs.h"
0016 
0017 /**
0018  *  KGameRenderedItem for Ball
0019  */
0020 class BallItem : public QObject, public KGameRenderedItem
0021 {
0022     Q_OBJECT
0023 public:
0024     explicit BallItem( QGraphicsScene* parent );
0025     /**
0026      *  Sets ball's color
0027      *  @param setPix specifies whether to set corresponding ball pixmap to this
0028      *  item. In rare cases this may not be needed.
0029      *  (for example when the ball is created and born animation is played immediately)
0030      */
0031     void setColor( BallColor c, bool setPix = true );
0032     /**
0033      *  @return color of the ball
0034      */
0035     BallColor color() const { return m_color; }
0036     /**
0037      * Starts "Selected" animation
0038      */
0039     void startSelectedAnimation();
0040     /**
0041      *  Interrupts animation
0042      */
0043     void stopAnimation();
0044 
0045     // enable use of qgraphicsitem_cast
0046     enum { Type = UserType + 1 };
0047     int type() const override { return Type; }
0048 private Q_SLOTS:
0049     void animFrameChanged(int);
0050 private:
0051     /**
0052      *  Timeline for controlling animations
0053      */
0054     QTimeLine m_timeLine;
0055     /**
0056      *  Color of the ball
0057      */
0058     BallColor m_color;
0059 };
0060 
0061 #endif