File indexing completed on 2024-04-21 15:38:42

0001 /***************************************************************************
0002  *   Copyright (C) 2005-2013 by Linuxstopmotion contributors;              *
0003  *   see the AUTHORS file for details.                                     *
0004  *                                                                         *
0005  *   This program is free software; you can redistribute it and/or modify  *
0006  *   it under the terms of the GNU General Public License as published by  *
0007  *   the Free Software Foundation; either version 2 of the License, or     *
0008  *   (at your option) any later version.                                   *
0009  *                                                                         *
0010  *   This program is distributed in the hope that it will be useful,       *
0011  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
0012  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
0013  *   GNU General Public License for more details.                          *
0014  *                                                                         *
0015  *   You should have received a copy of the GNU General Public License     *
0016  *   along with this program; if not, write to the                         *
0017  *   Free Software Foundation, Inc.,                                       *
0018  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
0019  ***************************************************************************/
0020 #ifndef RUNANIMATIONHANDLER_H
0021 #define RUNANIMATIONHANDLER_H
0022 
0023 #include "src/config.h"
0024 
0025 #include <QObject>
0026 
0027 class Selection;
0028 class QPushButton;
0029 class QTimer;
0030 class QStatusBar;
0031 
0032 /**
0033  * Handles the running of the animation as a sequence of pictures. This is implemented
0034  * as a timer trigger, to to make it easier to time the fps and, more importantly, to
0035  * avoid threads.
0036  *
0037  * @author Bjoern Erik Nilsen & Fredrik Berg Kjoelstad
0038  */
0039 class RunAnimationHandler : public QObject {
0040     Q_OBJECT
0041 public:
0042     /**
0043      * Creates the RunAnimationHandler and initializes the member fields.
0044      * @param parent the parent of this QOject.
0045      * @param sb the statusBar for displaying information to the user
0046      * @param name the name of this QObject
0047      */
0048     RunAnimationHandler ( QObject *parent = 0, QStatusBar *sb = 0,
0049             Selection *selection = 0, const char *name = 0 );
0050 
0051 
0052     /**
0053      * Stores the playButton so that it can be toggled
0054      * @param playButton the button which starts and stops the
0055      * animation running. This is needed for toggling the button states.
0056      */
0057     void setPlayButton(QPushButton *playButton);
0058 
0059     /**
0060      * Stores the removeFramesButton so that it can be deactivated as needed.
0061      * @param removeFramesButton the button for removing frames.
0062      * This is needed for canceling this while running the animations to
0063      * avoid system crash :D
0064      */
0065     void setRemoveFramesButton(QPushButton *removeFramesButton);
0066 
0067     /**
0068      * Sets the loop button.
0069      * @param loopButton the button to be used as loop button
0070      */
0071     void setLoopButton(QPushButton *loopButton);
0072 
0073     /**
0074      * Sets the pause button.
0075      * @param pauseButton the button to be used as pause button
0076      */
0077     void setPauseButton(QPushButton *pauseButton);
0078 
0079 signals:
0080 
0081     /**
0082      * The animation has reached this frame.
0083      */
0084     void playFrame(int scene, int frame);
0085     void paused();
0086     void stopped(int scene, int startFrame, int endFrame);
0087 
0088 public slots:
0089 
0090     /**
0091      * Starts the animation if it isn't playing and stops it if it is.
0092      *
0093      * This function is provided for ease of use with keyaccelerators.
0094      */
0095     void toggleRunning();
0096 
0097     /**
0098      * Runs the animation.
0099      */
0100     void runAnimation();
0101 
0102     /**
0103      * Stops the running of the animation.
0104      */
0105     void stopAnimation();
0106 
0107     /**
0108      * Freezes the running of the animation.
0109      */
0110     void pauseAnimation();
0111 
0112     /**
0113      * Sets the speed of the animation in frames per second
0114      * @param fps the number of frames per second the animation will run at.
0115      */
0116     void setSpeed(int fps);
0117 
0118     /**
0119      * Toggles between looping the animation when it is running and closing it
0120      * when it reaches the end.
0121      */
0122     void toggleLooping();
0123 
0124 private:
0125     QStatusBar *statusBar;
0126     Selection *selection;
0127     QPushButton *playButton;
0128     QPushButton *removeFramesButton;
0129     QPushButton *loopButton;
0130     QPushButton *pauseButton;
0131     QTimer *timer;
0132     int sceneNr;
0133     int frameNr;
0134     int fps;
0135     bool isLooping;
0136     int startFrame;
0137     int endFrame;
0138 
0139 private slots:
0140     /**
0141      * Slot for playing the next frame. This slot is triggered by the timer.
0142      */
0143     void playNextFrame();
0144     /**
0145      * Runs the animation from previously-set current frame
0146      */
0147     void resumeAnimation();
0148 };
0149 
0150 #endif