00001 /**************************************************************** 00002 * Vidalia is distributed under the following license: 00003 * 00004 * Copyright (C) 2007, Matt Edman, Justin Hipple 00005 * 00006 * This program is free software; you can redistribute it and/or 00007 * modify it under the terms of the GNU General Public License 00008 * as published by the Free Software Foundation; either version 2 00009 * of the License, or (at your option) any later version. 00010 * 00011 * This program is distributed in the hope that it will be useful, 00012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00014 * GNU General Public License for more details. 00015 * 00016 * You should have received a copy of the GNU General Public License 00017 * along with this program; if not, write to the Free Software 00018 * Foundation, Inc., 51 Franklin Street, Fifth Floor, 00019 * Boston, MA 02110-1301, USA. 00020 ****************************************************************/ 00021 00022 /** 00023 * \file animatedpixmap.h 00024 * \version $Id: animatedpixmap.h 1699 2007-04-09 01:50:59Z edmanm $ 00025 */ 00026 00027 #ifndef _ANIMATEDPIXMAP_H 00028 #define _ANIMATEDPIXMAP_H 00029 00030 #include <QTimer> 00031 #include <QPixmap> 00032 00033 /** Provides an animated pixmap that can be used even if Qt was compiled 00034 * without GIF support (which it is, by default) or the system doesn't have a 00035 * libmng available by default (OS X, for example, usually doesn't). Animated 00036 * pixmaps should have a series of square frames adjoined horizontally in a 00037 * single image file. */ 00038 class AnimatedPixmap : public QObject 00039 { 00040 Q_OBJECT 00041 00042 public: 00043 /** Default constructor. */ 00044 AnimatedPixmap(); 00045 /** Creates an animated pixmap from the specified file. */ 00046 AnimatedPixmap(const QString &fileName); 00047 00048 /** Starts the animation. */ 00049 void start(); 00050 /** Stops the animated image. */ 00051 void stop(); 00052 /** Returns the number of frames in the animation. */ 00053 int frameCount() const; 00054 /** Returns the current animation frame. */ 00055 QPixmap currentFrame() const; 00056 /** Sets the duration of each animation frame to <b>frameDelay</b>. */ 00057 void setFrameDelay(int frameDelay); 00058 /** Sets the source image for the animation to <b>pixmap</b>. */ 00059 void setPixmap(const QPixmap &pixmap); 00060 00061 signals: 00062 /** Emitted when the current frame has changed. <b>frameNumber</b> contains 00063 * the current frame number. */ 00064 void frameChanged(int frameNumber); 00065 00066 private slots: 00067 /** Called when the current animation frame should be changed. */ 00068 void frameTimeout(); 00069 00070 private: 00071 QPixmap _pixmap; /**< Source image for the animation frames. */ 00072 int _frameNumber; /**< Current animation frame number. */ 00073 QTimer _frameTimer; /**< Timer to control the delay between frames. */ 00074 }; 00075 00076 #endif 00077