Reduce the default frame rate of style animations

Halves the amount of paint events triggered by transient scrollbars.

Task-number: QTBUG-30316
Change-Id: Ifdf968d5c45013332758a6b751ce11d1ef2a2ca8
Reviewed-by: Gabriel de Dietrich <gabriel.dedietrich@digia.com>
This commit is contained in:
J-P Nurmi 2014-07-26 17:29:54 +02:00
parent 0240110c58
commit 8738f09b9f
3 changed files with 38 additions and 4 deletions

View File

@ -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 */

View File

@ -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) :

View File

@ -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