From 85a8df184b3aaa7f3a5a35895aa1caa3d4c39f42 Mon Sep 17 00:00:00 2001 From: J-P Nurmi Date: Tue, 23 Oct 2012 14:39:26 +0200 Subject: [PATCH] Add QNumberStyleAnimation for fading out scroll bars on Mac Change-Id: I6a85ed069a418d62078af6490a3d3186d5599a95 Reviewed-by: Jens Bache-Wiig --- src/widgets/styles/qstyleanimation.cpp | 45 ++++++++++++++++++++++++++ src/widgets/styles/qstyleanimation_p.h | 24 ++++++++++++++ 2 files changed, 69 insertions(+) diff --git a/src/widgets/styles/qstyleanimation.cpp b/src/widgets/styles/qstyleanimation.cpp index d81532f8a5..0138996e33 100644 --- a/src/widgets/styles/qstyleanimation.cpp +++ b/src/widgets/styles/qstyleanimation.cpp @@ -163,4 +163,49 @@ bool QProgressStyleAnimation::isUpdateNeeded() const return false; } +QNumberStyleAnimation::QNumberStyleAnimation(QObject *target) : + QStyleAnimation(target), _start(0.0), _end(1.0), _prev(0.0) +{ + setDuration(250); +} + +qreal QNumberStyleAnimation::startValue() const +{ + return _start; +} + +void QNumberStyleAnimation::setStartValue(qreal value) +{ + _start = value; +} + +qreal QNumberStyleAnimation::endValue() const +{ + return _end; +} + +void QNumberStyleAnimation::setEndValue(qreal value) +{ + _end = value; +} + +qreal QNumberStyleAnimation::currentValue() const +{ + qreal step = qreal(currentTime() - delay()) / (duration() - delay()); + return _start + qMax(qreal(0), step) * (_end - _start); +} + +bool QNumberStyleAnimation::isUpdateNeeded() const +{ + if (QStyleAnimation::isUpdateNeeded()) { + qreal current = currentValue(); + if (!qFuzzyCompare(_prev, current)) + { + _prev = current; + return true; + } + } + return false; +} + QT_END_NAMESPACE diff --git a/src/widgets/styles/qstyleanimation_p.h b/src/widgets/styles/qstyleanimation_p.h index 3188eebebc..d9869533ef 100644 --- a/src/widgets/styles/qstyleanimation_p.h +++ b/src/widgets/styles/qstyleanimation_p.h @@ -110,6 +110,30 @@ private: mutable int _step; }; +class QNumberStyleAnimation : public QStyleAnimation +{ + Q_OBJECT + +public: + QNumberStyleAnimation(QObject *target); + + qreal startValue() const; + void setStartValue(qreal value); + + qreal endValue() const; + void setEndValue(qreal value); + + qreal currentValue() const; + +protected: + bool isUpdateNeeded() const; + +private: + qreal _start; + qreal _end; + mutable qreal _prev; +}; + QT_END_NAMESPACE #endif // QSTYLEANIMATION_P_H