Results 1 to 1 of 1

Thread: QEasingCurve how to get progress for value?

  1. #1
    Join Date
    Aug 2010
    Posts
    4
    Thanks
    1
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default QEasingCurve how to get progress for value?

    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:
    Qt Code:
    1. QPropertyAnimation *anim = new QPropertyAnimation(this, "pos");
    2.  
    3. (...)
    4.  
    5. if(dir == AnimateIn){
    6. anim->setEasingCurve(QEasingCurve::OutExpo);
    7. anim->setDirection(QAbstractAnimation::Forward);
    8. } else if(dir == AnimateOut){
    9. anim->setEasingCurve(QEasingCurve::InExpo);
    10. anim->setDirection(QAbstractAnimation::Backward);
    11. }
    To copy to clipboard, switch view to plain text mode 
    value is diferrent for the same progress in different easing curves, so animation is rough.


    With progressForValue function I could do something like that:
    Qt Code:
    1. QEasingCurve oldCurve = anim->easingCurve();
    2. int time = anim->currentTime();
    3. if(dir == AnimateIn){
    4. anim->setEasingCurve(QEasingCurve::OutExpo);
    5. anim->setDirection(QAbstractAnimation::Forward);
    6. } else if(dir == AnimateOut){
    7. anim->setEasingCurve(QEasingCurve::InExpo);
    8. anim->setDirection(QAbstractAnimation::Backward);
    9. }
    10.  
    11. int duration = anim->duration();
    12. qreal progress = ((duration == 0) ? 1 : ((((time - 1) % duration) + 1) / qreal(duration)));
    13.  
    14. qreal newProgress = anim->easingCurve().progressForValue(oldCurve.valueForProgress(progress));
    15.  
    16. anim->setCurrentTime(duration * newProgress);
    To copy to clipboard, switch view to plain text mode 

    Any suggestions?
    Last edited by Mechan; 14th August 2010 at 23:12.

Similar Threads

  1. How to use progress bar
    By Ashwani in forum Newbie
    Replies: 6
    Last Post: 10th September 2010, 15:19
  2. Adding a Progress bar
    By srohit24 in forum Qt Programming
    Replies: 15
    Last Post: 1st June 2009, 09:52
  3. progress bar issues
    By shooogun in forum Qt Programming
    Replies: 4
    Last Post: 14th March 2008, 04:57
  4. Replies: 4
    Last Post: 11th March 2008, 11:44
  5. Reg - Progress bar
    By suresh in forum Qt Programming
    Replies: 1
    Last Post: 12th December 2006, 15:11

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.