File indexing completed on 2024-04-14 03:59:48

0001 /*
0002     This file is part of the KDE project "KLines"
0003 
0004     SPDX-FileCopyrightText: 2006-2007 Dmitry Suzdalev <dimsuz@gmail.com>
0005 
0006     SPDX-License-Identifier: GPL-2.0-or-later
0007 */
0008 
0009 #ifndef ANIMATOR_H
0010 #define ANIMATOR_H
0011 
0012 #include <QTimeLine>
0013 #include "commondefs.h"
0014 
0015 class KLinesScene;
0016 class BallItem;
0017 
0018 /**
0019  *  Drives KLines animations
0020  */
0021 class KLinesAnimator : public QObject
0022 {
0023     Q_OBJECT
0024 public:
0025     explicit KLinesAnimator( KLinesScene *scene );
0026     /**
0027      *  Starts animation of ball movement.
0028      *  When animation finishes moveFinished() signal is emitted
0029      *  @param from starting field position
0030      *  @param to   target field position
0031      *
0032      *  @return true is there exists a path (from,to), false otherwise
0033      */
0034     bool animateMove(FieldPos from, FieldPos to );
0035     /**
0036      *  Starts animation of ball deletion from field.
0037      *  Note that it doesn't do actual deletion - it just runs
0038      *  animation of deletion.
0039      *  When animation finishes removeFinished() signal is emitted
0040      *  @param list list of balls to 'remove'
0041      */
0042     void animateRemove( const QList<BallItem*>& list );
0043     /**
0044      *  Starts animation of ball movement.
0045      *  When animation finishes bornFinished() signal is emitted
0046      *  @param list list of balls to be 'born'
0047      */
0048     void animateBorn( const QList<BallItem*>& list );
0049     /**
0050      *  @return whether some animation is in progress
0051      */
0052     bool isAnimating() const;
0053     /**
0054      * Starts game over animation on the scene, shows game over message
0055      * TODO: does nothing useful yet
0056      */
0057     void startGameOverAnimation();
0058     /**
0059      * Stops game over animation
0060      * TODO: does nothing useful yet
0061      */
0062     void stopGameOverAnimation();
0063 Q_SIGNALS:
0064     void moveFinished();
0065     void removeFinished();
0066     void bornFinished();
0067 private Q_SLOTS:
0068     void moveAnimationFrame(int);
0069     void removeAnimationFrame(int);
0070     void bornAnimationFrame(int);
0071 
0072     void slotBornFinished();
0073 private:
0074     /**
0075      *  Implements A* pathfinding algorithm.
0076      */
0077     void findPath(FieldPos from, FieldPos to);
0078     /**
0079      *  Timeline used to control movement animation
0080      */
0081     QTimeLine m_moveTimeLine;
0082     /**
0083      *  Timeline used to control deletion animation
0084      */
0085     QTimeLine m_removeTimeLine;
0086     /**
0087      *  Timeline used to control birth animation
0088      */
0089     QTimeLine m_bornTimeLine;
0090     /**
0091      *  Scene on which animations are played
0092      */
0093     KLinesScene* m_scene;
0094     /**
0095      *  Ball object used while animating movement
0096      */
0097     BallItem* m_movingBall;
0098     /**
0099      *  findPath() algorithm stores found path in this variable
0100      */
0101     QList<FieldPos> m_foundPath;
0102     /**
0103      *  Balls for which 'remove' animation is played
0104      */
0105     QList<BallItem*> m_removedBalls;
0106     /**
0107      *  Balls for which 'born' animation is played
0108      */
0109     QList<BallItem*> m_bornBalls;
0110 };
0111 
0112 #endif