diff --git a/src/widgets/styles/qcommonstyle.cpp b/src/widgets/styles/qcommonstyle.cpp index 94498f48c9..d8b67edff8 100644 --- a/src/widgets/styles/qcommonstyle.cpp +++ b/src/widgets/styles/qcommonstyle.cpp @@ -1155,7 +1155,7 @@ void QCommonStylePrivate::startAnimation(QStyleAnimation *animation) const stopAnimation(animation->target()); q->connect(animation, SIGNAL(destroyed()), SLOT(_q_removeAnimation()), Qt::UniqueConnection); animations.insert(animation->target(), animation); - animation->start(QAbstractAnimation::DeleteWhenStopped); + animation->start(); } /*! \internal */ diff --git a/src/widgets/styles/qstyleanimation.cpp b/src/widgets/styles/qstyleanimation.cpp index 85dc357ab5..e6e47a98e9 100644 --- a/src/widgets/styles/qstyleanimation.cpp +++ b/src/widgets/styles/qstyleanimation.cpp @@ -50,7 +50,7 @@ static const qreal ScrollBarFadeOutDuration = 200.0; static const qreal ScrollBarFadeOutDelay = 450.0; QStyleAnimation::QStyleAnimation(QObject *target) : QAbstractAnimation(target), - _delay(0), _duration(-1), _startTime(QTime::currentTime()) + _delay(0), _duration(-1), _startTime(QTime::currentTime()), _fps(ThirtyFps), _skip(0) { } @@ -93,6 +93,16 @@ void QStyleAnimation::setStartTime(const QTime &time) _startTime = time; } +QStyleAnimation::FrameRate QStyleAnimation::frameRate() const +{ + return _fps; +} + +void QStyleAnimation::setFrameRate(FrameRate fps) +{ + _fps = fps; +} + void QStyleAnimation::updateTarget() { QEvent event(QEvent::StyleAnimationUpdate); @@ -102,6 +112,12 @@ void QStyleAnimation::updateTarget() stop(); } +void QStyleAnimation::start() +{ + _skip = 0; + QAbstractAnimation::start(DeleteWhenStopped); +} + bool QStyleAnimation::isUpdateNeeded() const { return currentTime() > _delay; @@ -109,8 +125,11 @@ bool QStyleAnimation::isUpdateNeeded() const void QStyleAnimation::updateCurrentTime(int) { - if (target() && isUpdateNeeded()) - updateTarget(); + if (++_skip >= _fps) { + _skip = 0; + if (target() && isUpdateNeeded()) + updateTarget(); + } } QProgressStyleAnimation::QProgressStyleAnimation(int speed, QObject *target) : diff --git a/src/widgets/styles/qstyleanimation_p.h b/src/widgets/styles/qstyleanimation_p.h index c344858812..19e629cb25 100644 --- a/src/widgets/styles/qstyleanimation_p.h +++ b/src/widgets/styles/qstyleanimation_p.h @@ -78,8 +78,21 @@ public: QTime startTime() const; void setStartTime(const QTime &time); + enum FrameRate { + DefaultFps, + SixtyFps, + ThirtyFps, + TwentyFps + }; + + FrameRate frameRate() const; + void setFrameRate(FrameRate fps); + void updateTarget(); +public Q_SLOTS: + void start(); + protected: virtual bool isUpdateNeeded() const; virtual void updateCurrentTime(int time); @@ -88,6 +101,8 @@ private: int _delay; int _duration; QTime _startTime; + FrameRate _fps; + int _skip; }; class QProgressStyleAnimation : public QStyleAnimation