[Qt-interest] QTimeLine from 0 to 100, to -100 and back to 0 ?

Sean Harmer sean.harmer at maps-technology.com
Fri Aug 21 11:40:48 CEST 2009


Hi,

On Friday 21 Aug 2009 10:24:29 Oliver Demetz wrote:
> Solved,
Cool.

> just in case someone is interested:
>
> class MyTimeLine : public QTimeLine
> {
> public:
> 	MyTimeLine ( int duration = 1000, QObject * parent = 0 )
>
> 	 : QTimeLine ( duration , parent ) {}
>
> 	qreal valueForTime(int msec) const
> 	{
> 		qreal d = (qreal) duration();
>
> 		if (msec < d/4)
> 		{
> 			return 4.0 * (qreal) msec / d;
> 		}
> 		else if(msec < 3*d/4)
> 		{
> 			return - 4*msec/d + 2;
> 		}
> 		else
> 		{
> 			return 4*msec/d - 4;
> 		}
> 	}
> };
You could also have used a sine function with the appropriate period and 
scaling. e.g.

qreal valueForTime(int msec) const
{
	qreal d = (qreal) duration();
	return 100 * sin( qreal(msec) * 2 * pi / d );
}

Sean



More information about the Qt-interest-old mailing list