PDA

View Full Version : QEasingCurve how to get progress for value?



Mechan
14th August 2010, 22:57
Hi,
I'm trying to get linear progress from eased value of QEasingCurve, i.e. basically inverse function for valueForProgress. I could do that by inversing equations from functions in src/3rdparty/easing/easing.cpp, but maybe there is simpler way?

What i'm trying to do is an animation which has different easing curves for different directions (Forward/Backward), but it's direction can be changed while animation is in progress. When I just do:

QPropertyAnimation *anim = new QPropertyAnimation(this, "pos");

(...)

if(dir == AnimateIn){
anim->setEasingCurve(QEasingCurve::OutExpo);
anim->setDirection(QAbstractAnimation::Forward);
} else if(dir == AnimateOut){
anim->setEasingCurve(QEasingCurve::InExpo);
anim->setDirection(QAbstractAnimation::Backward);
}
value is diferrent for the same progress in different easing curves, so animation is rough.


With progressForValue function I could do something like that:

QEasingCurve oldCurve = anim->easingCurve();
int time = anim->currentTime();
if(dir == AnimateIn){
anim->setEasingCurve(QEasingCurve::OutExpo);
anim->setDirection(QAbstractAnimation::Forward);
} else if(dir == AnimateOut){
anim->setEasingCurve(QEasingCurve::InExpo);
anim->setDirection(QAbstractAnimation::Backward);
}

int duration = anim->duration();
qreal progress = ((duration == 0) ? 1 : ((((time - 1) % duration) + 1) / qreal(duration)));

qreal newProgress = anim->easingCurve().progressForValue(oldCurve.valueForPr ogress(progress));

anim->setCurrentTime(duration * newProgress);

Any suggestions?