1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121
|
/*
* Bespin style for Qt4
* Copyright 2007-2012 by Thomas Lübking <thomas.luebking@gmail.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2
*
* 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 BASIC_ANIMATOR_H
#define BASIC_ANIMATOR_H
#include <QBasicTimer>
#include <QMap>
#include "../bepointer.h"
namespace Animator {
class Info
{
public:
Info(int s = 0, bool bwd = false);
virtual ~Info(){}
virtual int step(long int idx = 0) const;
bool bwd() const;
int & operator++ (){return ++_step;}
int operator++ ( int ) {return _step++;}
int & operator-- () {return --_step;}
int operator-- ( int ) {return _step--;}
protected:
friend class Basic;
friend class Progress;
friend class Hover;
int _step; bool backwards;
void init(int s = 0, bool bwd = false);
};
class Basic : public QObject
{
Q_OBJECT
public:
static bool manage(QWidget *w);
static void release(QWidget *w);
static int step(const QWidget *widget);
virtual const Info &info(const QWidget *widget, long int index = 0) const;
static void setFPS(uint fps);
protected:
Basic();
virtual ~Basic(){}
virtual bool eventFilter( QObject *object, QEvent *event );
virtual bool noAnimations() const;
virtual void play(QWidget *widget, bool bwd = false);
virtual bool _manage(QWidget *w);
virtual void _release(QWidget *w);
virtual int _step(const QWidget *widget, long int index = 0) const;
virtual void timerEvent(QTimerEvent * event);
virtual void _setFPS(uint fps);
QBasicTimer timer;
uint timeStep;
uint count;
typedef BePointer<QWidget> WidgetPtr;
typedef QMap<WidgetPtr, Info> Items;
Items items;
protected slots:
virtual void release_s(QObject*);
// void pause(QWidget *w);
private:
Q_DISABLE_COPY(Basic)
};
} // namespace
#define INSTANCE(_CLASS_) static _CLASS_ *instance = 0;
#define MANAGE(_CLASS_)\
bool _CLASS_::manage(QWidget *w)\
{\
if (!w) return false;\
if (!instance) instance = new _CLASS_;\
return instance->_manage(w);\
}
// TODO check whether the eventFilter is used at all!
// if (!instance->count) {
// delete instance; instance = 0;
// }
#define RELEASE(_CLASS_)\
void _CLASS_::release(QWidget *w)\
{\
if (!(w && instance)) return;\
instance->_release(w);\
}
#define STEP(_CLASS_)\
int _CLASS_::step(const QWidget *widget)\
{\
if (!instance) return 0;\
return instance->_step(widget);\
}
#define SET_FPS(_CLASS_)\
static uint _timeStep = 50;\
void _CLASS_::setFPS(uint fps)\
{\
_timeStep = 1000/fps;\
if (!instance) return;\
instance->_setFPS(fps);\
}
#endif // BASIC_ANIMATOR_H
|