From 0f1dbde6699ea778da6c02eab5d73a8d1cacd8fb Mon Sep 17 00:00:00 2001 From: Francois Cartegnie Date: Sat, 8 Feb 2014 15:01:03 +0100 Subject: [PATCH] Qt: move animators code --- modules/gui/qt4/Makefile.am | 2 + .../qt4/components/playlist/standardpanel.cpp | 2 +- modules/gui/qt4/util/animators.cpp | 47 +++++++++++++++ modules/gui/qt4/util/animators.hpp | 59 +++++++++++++++++++ modules/gui/qt4/util/customwidgets.cpp | 22 ------- modules/gui/qt4/util/customwidgets.hpp | 32 +--------- 6 files changed, 111 insertions(+), 53 deletions(-) create mode 100644 modules/gui/qt4/util/animators.cpp create mode 100644 modules/gui/qt4/util/animators.hpp diff --git a/modules/gui/qt4/Makefile.am b/modules/gui/qt4/Makefile.am index 82f55fbcb4..fd588dd906 100644 --- a/modules/gui/qt4/Makefile.am +++ b/modules/gui/qt4/Makefile.am @@ -100,6 +100,7 @@ libqt4_plugin_la_SOURCES = \ components/sout/profile_selector.hpp \ components/sout/sout_widgets.cpp components/sout/sout_widgets.hpp \ components/sout/profiles.hpp \ + util/animators.cpp util/animators.hpp \ util/input_slider.cpp util/input_slider.hpp \ util/timetooltip.cpp util/timetooltip.hpp \ util/customwidgets.cpp util/customwidgets.hpp \ @@ -190,6 +191,7 @@ nodist_libqt4_plugin_la_SOURCES = \ components/playlist/ml_model.moc.cpp \ components/sout/profile_selector.moc.cpp \ components/sout/sout_widgets.moc.cpp \ + util/animators.moc.cpp \ util/input_slider.moc.cpp \ util/timetooltip.moc.cpp \ util/customwidgets.moc.cpp \ diff --git a/modules/gui/qt4/components/playlist/standardpanel.cpp b/modules/gui/qt4/components/playlist/standardpanel.cpp index faac01b9a1..954bda692c 100644 --- a/modules/gui/qt4/components/playlist/standardpanel.cpp +++ b/modules/gui/qt4/components/playlist/standardpanel.cpp @@ -33,7 +33,7 @@ #include "components/playlist/ml_model.hpp" /* MLModel */ #include "components/playlist/views.hpp" /* 3 views */ #include "components/playlist/selector.hpp" /* PLSelector */ -#include "util/customwidgets.hpp" /* PixmapAnimator */ +#include "util/animators.hpp" /* PixmapAnimator */ #include "menus.hpp" /* Popup */ #include "input_manager.hpp" /* THEMIM */ #include "dialogs_provider.hpp" /* THEDP */ diff --git a/modules/gui/qt4/util/animators.cpp b/modules/gui/qt4/util/animators.cpp new file mode 100644 index 0000000000..9bed3a6193 --- /dev/null +++ b/modules/gui/qt4/util/animators.cpp @@ -0,0 +1,47 @@ +/***************************************************************************** + * animators.cpp: Object animators + **************************************************************************** + * Copyright (C) 2006-2014 the VideoLAN team + * + * 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. + *****************************************************************************/ + +#include "animators.hpp" + +#include +#include + +PixmapAnimator::PixmapAnimator( QWidget *parent, QList frames ) + : QAbstractAnimation( parent ), current_frame( 0 ) +{ + foreach( QString name, frames ) + pixmaps.append( new QPixmap( name ) ); + currentPixmap = pixmaps.at( 0 ); + setFps( frames.count() ); /* default to 1 sec loop */ + setLoopCount( -1 ); +} + +void PixmapAnimator::updateCurrentTime( int msecs ) +{ + int i = msecs / interval; + if ( i >= pixmaps.count() ) i = pixmaps.count() - 1; /* roundings */ + if ( i != current_frame ) + { + current_frame = i; + currentPixmap = pixmaps.at( current_frame ); + emit pixmapReady( *currentPixmap ); + } +} + diff --git a/modules/gui/qt4/util/animators.hpp b/modules/gui/qt4/util/animators.hpp new file mode 100644 index 0000000000..87cb160c6b --- /dev/null +++ b/modules/gui/qt4/util/animators.hpp @@ -0,0 +1,59 @@ +/***************************************************************************** + * animators.hpp: Object animators + **************************************************************************** + * Copyright (C) 2006-2014 the VideoLAN team + * + * 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. + *****************************************************************************/ + +#ifndef ANIMATORS_HPP +#define ANIMATORS_HPP + +#include +#include +#include +#include +class QWidget; +class QPixmap; + +/** An animated pixmap + * Use this widget to display an animated icon based on a series of + * pixmaps. The pixmaps will be stored in memory and should be kept small. + * First, create the widget, add frames and then start playing. Looping + * is supported. + **/ +class PixmapAnimator : public QAbstractAnimation +{ + Q_OBJECT + +public: + PixmapAnimator( QWidget *parent, QList _frames ); + void setFps( int _fps ) { fps = _fps; interval = 1000.0 / fps; } + virtual int duration() const { return interval * pixmaps.count(); } + virtual ~PixmapAnimator() { qDeleteAll( pixmaps ); } + QPixmap *getPixmap() { return currentPixmap; } +protected: + virtual void updateCurrentTime ( int msecs ); + QList pixmaps; + QPixmap *currentPixmap; + int fps; + int interval; + int lastframe_msecs; + int current_frame; +signals: + void pixmapReady( const QPixmap & ); +}; + +#endif // ANIMATORS_HPP diff --git a/modules/gui/qt4/util/customwidgets.cpp b/modules/gui/qt4/util/customwidgets.cpp index 847ea65771..8b766ead8a 100644 --- a/modules/gui/qt4/util/customwidgets.cpp +++ b/modules/gui/qt4/util/customwidgets.cpp @@ -318,28 +318,6 @@ QString VLCKeyToString( unsigned val, bool locale ) return r; } -PixmapAnimator::PixmapAnimator( QWidget *parent, QList frames ) - : QAbstractAnimation( parent ), current_frame( 0 ) -{ - foreach( QString name, frames ) - pixmaps.append( new QPixmap( name ) ); - currentPixmap = pixmaps.at( 0 ); - setFps( frames.count() ); /* default to 1 sec loop */ - setLoopCount( -1 ); -} - -void PixmapAnimator::updateCurrentTime( int msecs ) -{ - int i = msecs / interval; - if ( i >= pixmaps.count() ) i = pixmaps.count() - 1; /* roundings */ - if ( i != current_frame ) - { - current_frame = i; - currentPixmap = pixmaps.at( current_frame ); - emit pixmapReady( *currentPixmap ); - } -} - /* Animated Icon implementation */ SpinningIcon::SpinningIcon( QWidget *parent ) : QLabel( parent ) { diff --git a/modules/gui/qt4/util/customwidgets.hpp b/modules/gui/qt4/util/customwidgets.hpp index fd2cd937f8..e1e6c6d38f 100644 --- a/modules/gui/qt4/util/customwidgets.hpp +++ b/modules/gui/qt4/util/customwidgets.hpp @@ -34,11 +34,11 @@ #include #include #include -#include #include -#include #include +#include "animators.hpp" + class QPixmap; class QWidget; @@ -112,34 +112,6 @@ protected: virtual int valueFromText( const QString& ) const { return -1; } }; -/** An animated pixmap - * Use this widget to display an animated icon based on a series of - * pixmaps. The pixmaps will be stored in memory and should be kept small. - * First, create the widget, add frames and then start playing. Looping - * is supported. - **/ -class PixmapAnimator : public QAbstractAnimation -{ - Q_OBJECT - -public: - PixmapAnimator( QWidget *parent, QList _frames ); - void setFps( int _fps ) { fps = _fps; interval = 1000.0 / fps; }; - virtual int duration() const { return interval * pixmaps.count(); }; - virtual ~PixmapAnimator() { qDeleteAll( pixmaps ); }; - QPixmap *getPixmap() { return currentPixmap; } -protected: - virtual void updateCurrentTime ( int msecs ); - QList pixmaps; - QPixmap *currentPixmap; - int fps; - int interval; - int lastframe_msecs; - int current_frame; -signals: - void pixmapReady( const QPixmap & ); -}; - /** This spinning icon, to the colors of the VLC cone, will show * that there is some background activity running **/ -- 2.39.2