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:
parent
0240110c58
commit
8738f09b9f
@ -1155,7 +1155,7 @@ void QCommonStylePrivate::startAnimation(QStyleAnimation *animation) const
|
|||||||
stopAnimation(animation->target());
|
stopAnimation(animation->target());
|
||||||
q->connect(animation, SIGNAL(destroyed()), SLOT(_q_removeAnimation()), Qt::UniqueConnection);
|
q->connect(animation, SIGNAL(destroyed()), SLOT(_q_removeAnimation()), Qt::UniqueConnection);
|
||||||
animations.insert(animation->target(), animation);
|
animations.insert(animation->target(), animation);
|
||||||
animation->start(QAbstractAnimation::DeleteWhenStopped);
|
animation->start();
|
||||||
}
|
}
|
||||||
|
|
||||||
/*! \internal */
|
/*! \internal */
|
||||||
|
@ -50,7 +50,7 @@ static const qreal ScrollBarFadeOutDuration = 200.0;
|
|||||||
static const qreal ScrollBarFadeOutDelay = 450.0;
|
static const qreal ScrollBarFadeOutDelay = 450.0;
|
||||||
|
|
||||||
QStyleAnimation::QStyleAnimation(QObject *target) : QAbstractAnimation(target),
|
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;
|
_startTime = time;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QStyleAnimation::FrameRate QStyleAnimation::frameRate() const
|
||||||
|
{
|
||||||
|
return _fps;
|
||||||
|
}
|
||||||
|
|
||||||
|
void QStyleAnimation::setFrameRate(FrameRate fps)
|
||||||
|
{
|
||||||
|
_fps = fps;
|
||||||
|
}
|
||||||
|
|
||||||
void QStyleAnimation::updateTarget()
|
void QStyleAnimation::updateTarget()
|
||||||
{
|
{
|
||||||
QEvent event(QEvent::StyleAnimationUpdate);
|
QEvent event(QEvent::StyleAnimationUpdate);
|
||||||
@ -102,6 +112,12 @@ void QStyleAnimation::updateTarget()
|
|||||||
stop();
|
stop();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void QStyleAnimation::start()
|
||||||
|
{
|
||||||
|
_skip = 0;
|
||||||
|
QAbstractAnimation::start(DeleteWhenStopped);
|
||||||
|
}
|
||||||
|
|
||||||
bool QStyleAnimation::isUpdateNeeded() const
|
bool QStyleAnimation::isUpdateNeeded() const
|
||||||
{
|
{
|
||||||
return currentTime() > _delay;
|
return currentTime() > _delay;
|
||||||
@ -109,8 +125,11 @@ bool QStyleAnimation::isUpdateNeeded() const
|
|||||||
|
|
||||||
void QStyleAnimation::updateCurrentTime(int)
|
void QStyleAnimation::updateCurrentTime(int)
|
||||||
{
|
{
|
||||||
if (target() && isUpdateNeeded())
|
if (++_skip >= _fps) {
|
||||||
updateTarget();
|
_skip = 0;
|
||||||
|
if (target() && isUpdateNeeded())
|
||||||
|
updateTarget();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
QProgressStyleAnimation::QProgressStyleAnimation(int speed, QObject *target) :
|
QProgressStyleAnimation::QProgressStyleAnimation(int speed, QObject *target) :
|
||||||
|
@ -78,8 +78,21 @@ public:
|
|||||||
QTime startTime() const;
|
QTime startTime() const;
|
||||||
void setStartTime(const QTime &time);
|
void setStartTime(const QTime &time);
|
||||||
|
|
||||||
|
enum FrameRate {
|
||||||
|
DefaultFps,
|
||||||
|
SixtyFps,
|
||||||
|
ThirtyFps,
|
||||||
|
TwentyFps
|
||||||
|
};
|
||||||
|
|
||||||
|
FrameRate frameRate() const;
|
||||||
|
void setFrameRate(FrameRate fps);
|
||||||
|
|
||||||
void updateTarget();
|
void updateTarget();
|
||||||
|
|
||||||
|
public Q_SLOTS:
|
||||||
|
void start();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual bool isUpdateNeeded() const;
|
virtual bool isUpdateNeeded() const;
|
||||||
virtual void updateCurrentTime(int time);
|
virtual void updateCurrentTime(int time);
|
||||||
@ -88,6 +101,8 @@ private:
|
|||||||
int _delay;
|
int _delay;
|
||||||
int _duration;
|
int _duration;
|
||||||
QTime _startTime;
|
QTime _startTime;
|
||||||
|
FrameRate _fps;
|
||||||
|
int _skip;
|
||||||
};
|
};
|
||||||
|
|
||||||
class QProgressStyleAnimation : public QStyleAnimation
|
class QProgressStyleAnimation : public QStyleAnimation
|
||||||
|
Loading…
x
Reference in New Issue
Block a user