[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[vidalia-svn] r1699: Add an AnimatedPixmap class to display animated images, with (in trunk: . src/gui/common)
Author: edmanm
Date: 2007-04-08 21:50:59 -0400 (Sun, 08 Apr 2007)
New Revision: 1699
Added:
trunk/src/gui/common/animatedpixmap.cpp
trunk/src/gui/common/animatedpixmap.h
Modified:
trunk/
trunk/src/gui/common/common.pri
Log:
r1781@adrastea: edmanm | 2007-04-08 21:39:46 -0400
Add an AnimatedPixmap class to display animated images, without relying on
Qt's often excluded GIF support or libmng. (seriously, how often have you seen
mng used anyway?)
Property changes on: trunk
___________________________________________________________________
svk:merge ticket from /vidalia/local/trunk [r1781] on 54b3572a-7227-0410-958f-53ecd705b71a
Added: trunk/src/gui/common/animatedpixmap.cpp
===================================================================
--- trunk/src/gui/common/animatedpixmap.cpp (rev 0)
+++ trunk/src/gui/common/animatedpixmap.cpp 2007-04-09 01:50:59 UTC (rev 1699)
@@ -0,0 +1,103 @@
+/****************************************************************
+ * Vidalia is distributed under the following license:
+ *
+ * Copyright (C) 2007, Matt Edman, Justin Hipple
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ ****************************************************************/
+
+/**
+ * \file animatedpixmap.cpp
+ * \version $Id$
+ */
+
+#include <QSize>
+#include <QRect>
+
+#include "animatedpixmap.h"
+
+
+/** Default constructor. */
+AnimatedPixmap::AnimatedPixmap()
+: _frameNumber(-1)
+{
+ _frameTimer.setInterval(100);
+ connect(&_frameTimer, SIGNAL(timeout()), this, SLOT(frameTimeout()));
+}
+
+/** Creates an animated pixmap from the specified file. */
+AnimatedPixmap::AnimatedPixmap(const QString &fileName)
+{
+ _frameTimer.setInterval(100);
+ setPixmap(QPixmap(fileName));
+ connect(&_frameTimer, SIGNAL(timeout()), this, SLOT(frameTimeout()));
+}
+
+/** Starts the animation. */
+void
+AnimatedPixmap::start()
+{
+ _frameTimer.start();
+ _frameNumber = 0;
+}
+
+/** Stops the animated image. */
+void
+AnimatedPixmap::stop()
+{
+ _frameTimer.stop();
+}
+
+/** Sets the duration of each animation frame to <b>frameDelay</b>. */
+void
+AnimatedPixmap::setFrameDelay(int frameDelay)
+{
+ _frameTimer.setInterval(frameDelay);
+}
+
+/** Sets the source image for the animation to <b>pixmap</b>. */
+void
+AnimatedPixmap::setPixmap(const QPixmap &pixmap)
+{
+ _pixmap = pixmap;
+ _frameNumber = 0;
+}
+
+/** Returns the number of frames in the animation. */
+int
+AnimatedPixmap::frameCount() const
+{
+ return (_pixmap.width()/_pixmap.height());
+}
+
+/** Called when the current animation frame should be changed. */
+void
+AnimatedPixmap::frameTimeout()
+{
+ _frameNumber = (_frameNumber + 1) % frameCount();
+ emit frameChanged(_frameNumber);
+}
+
+/** Returns the current animation frame. */
+QPixmap
+AnimatedPixmap::currentFrame() const
+{
+ return _pixmap.copy(_frameNumber * _pixmap.height(),
+ 0,
+ _pixmap.height(),
+ _pixmap.height());
+}
+
Property changes on: trunk/src/gui/common/animatedpixmap.cpp
___________________________________________________________________
Name: svn:keywords
+ Id
Name: svn:eol-style
+ native
Added: trunk/src/gui/common/animatedpixmap.h
===================================================================
--- trunk/src/gui/common/animatedpixmap.h (rev 0)
+++ trunk/src/gui/common/animatedpixmap.h 2007-04-09 01:50:59 UTC (rev 1699)
@@ -0,0 +1,77 @@
+/****************************************************************
+ * Vidalia is distributed under the following license:
+ *
+ * Copyright (C) 2007, Matt Edman, Justin Hipple
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ ****************************************************************/
+
+/**
+ * \file animatedpixmap.h
+ * \version $Id$
+ */
+
+#ifndef _ANIMATEDPIXMAP_H
+#define _ANIMATEDPIXMAP_H
+
+#include <QTimer>
+#include <QPixmap>
+
+/** Provides an animated pixmap that can be used even if Qt was compiled
+ * without GIF support (which it is, by default) or the system doesn't have a
+ * libmng available by default (OS X, for example, usually doesn't). Animated
+ * pixmaps should have a series of square frames adjoined horizontally in a
+ * single image file. */
+class AnimatedPixmap : public QObject
+{
+ Q_OBJECT
+
+public:
+ /** Default constructor. */
+ AnimatedPixmap();
+ /** Creates an animated pixmap from the specified file. */
+ AnimatedPixmap(const QString &fileName);
+
+ /** Starts the animation. */
+ void start();
+ /** Stops the animated image. */
+ void stop();
+ /** Returns the number of frames in the animation. */
+ int frameCount() const;
+ /** Returns the current animation frame. */
+ QPixmap currentFrame() const;
+ /** Sets the duration of each animation frame to <b>frameDelay</b>. */
+ void setFrameDelay(int frameDelay);
+ /** Sets the source image for the animation to <b>pixmap</b>. */
+ void setPixmap(const QPixmap &pixmap);
+
+signals:
+ /** Emitted when the current frame has changed. <b>frameNumber</b> contains
+ * the current frame number. */
+ void frameChanged(int frameNumber);
+
+private slots:
+ /** Called when the current animation frame should be changed. */
+ void frameTimeout();
+
+private:
+ QPixmap _pixmap; /**< Source image for the animation frames. */
+ int _frameNumber; /**< Current animation frame number. */
+ QTimer _frameTimer; /**< Timer to control the delay between frames. */
+};
+
+#endif
+
Property changes on: trunk/src/gui/common/animatedpixmap.h
___________________________________________________________________
Name: svn:keywords
+ Id
Name: svn:eol-style
+ native
Modified: trunk/src/gui/common/common.pri
===================================================================
--- trunk/src/gui/common/common.pri 2007-04-08 07:06:12 UTC (rev 1698)
+++ trunk/src/gui/common/common.pri 2007-04-09 01:50:59 UTC (rev 1699)
@@ -23,9 +23,11 @@
HEADERS += $$PWD/vidaliawindow.h \
$$PWD/vmessagebox.h \
- $$PWD/vclicklabel.h
+ $$PWD/vclicklabel.h \
+ $$PWD/animatedpixmap.h
SOURCES += $$PWD/vidaliawindow.cpp \
$$PWD/vmessagebox.cpp \
- $$PWD/vclicklabel.cpp
+ $$PWD/vclicklabel.cpp \
+ $$PWD/animatedpixmap.cpp