Sunday, September 27, 2009

Extending Qt Animation

Recently working with Qt Animation Framework I realised that though QVariantAnimation has property for setting easing curve to Custom type .

However this custom graph style doesnt really help the animation to follow graph of user s choice as the function pointer behind expects a definition like

qreal customFunc( qreal time) ;

where time t element of [0,1]  closed interval

also the return value is progress normalised between [0,1].

To support custom graph style that does have more parameters varying rather than just time one needs to extend QtVariantAnimation or QtPropertyAnimation.

I extended from QtPropertyAnimation for my CustomAnimation class something like..
class CustomAnimation : public QtPropertyAnimation

{

Q_OBJECT

public:

qreal a1Value() const;

void seta1Value(const qreal value);

...

QString style();

void setStyle(QString style);

CustomAnimation(QObject *parent = 0);

CustomAnimation(QObject *target, const QByteArray &propertyName, QObject *parent = 0);

~ CustomAnimation();

void updateCurrentValue(const qreal value);

void updateState(QtAbstractAnimation::State oldState, QtAbstractAnimation::State newState);

void updateCurrentTime(int msecs);

private:

qreal a1;

QString curveStyle;

Q_DISABLE_COPY(CustomAnimation);

};


No comments: