summaryrefslogtreecommitdiffstats
path: root/src/widgets
diff options
context:
space:
mode:
authorJ-P Nurmi <jpnurmi@digia.com>2013-12-18 16:37:17 +0100
committerThe Qt Project <gerrit-noreply@qt-project.org>2014-02-11 18:36:05 +0100
commit062d2a1f801a03db09db23763f024bd0397305a0 (patch)
tree9300a606bf5141ee1585e250e4daedc8d0938dbb /src/widgets
parente14885a18a3ab0bffd6d638dcccffd39cb52bf0e (diff)
Promote the scrollbar style animation to qstyleanimation_p.h
Makes it possible for QFusionStyle to utilize the same animation. Change-Id: Ifac9eaa3138cf1068439d5b0271a2acce54a3c16 Reviewed-by: Jens Bache-Wiig <jens.bache-wiig@digia.com>
Diffstat (limited to 'src/widgets')
-rw-r--r--src/widgets/styles/qmacstyle_mac.mm20
-rw-r--r--src/widgets/styles/qmacstyle_mac_p_p.h45
-rw-r--r--src/widgets/styles/qstyleanimation.cpp42
-rw-r--r--src/widgets/styles/qstyleanimation_p.h22
4 files changed, 72 insertions, 57 deletions
diff --git a/src/widgets/styles/qmacstyle_mac.mm b/src/widgets/styles/qmacstyle_mac.mm
index fa49bcb884..d180122ab2 100644
--- a/src/widgets/styles/qmacstyle_mac.mm
+++ b/src/widgets/styles/qmacstyle_mac.mm
@@ -143,8 +143,6 @@ const int QMacStylePrivate::SmallButtonH = 30;
const int QMacStylePrivate::BevelButtonW = 50;
const int QMacStylePrivate::BevelButtonH = 22;
const int QMacStylePrivate::PushButtonContentPadding = 6;
-const qreal QMacStylePrivate::ScrollBarFadeOutDuration = 200.0;
-const qreal QMacStylePrivate::ScrollBarFadeOutDelay = 450.0;
QSet<QPointer<QObject> > QMacStylePrivate::scrollBars;
@@ -5046,24 +5044,23 @@ void QMacStyle::drawComplexControl(ComplexControl cc, const QStyleOptionComplex
styleObject->setProperty("_q_stylestate", static_cast<int>(slider->state));
styleObject->setProperty("_q_stylecontrols", static_cast<uint>(slider->activeSubControls));
- QScrollbarAnimation *anim = qobject_cast<QScrollbarAnimation *>(d->animation(styleObject));
+ QScrollbarStyleAnimation *anim = qobject_cast<QScrollbarStyleAnimation *>(d->animation(styleObject));
if (transient) {
if (!anim) {
- anim = new QScrollbarAnimation(styleObject);
- anim->setFadingOut();
+ anim = new QScrollbarStyleAnimation(QScrollbarStyleAnimation::Deactivating, styleObject);
d->startAnimation(anim);
- } else if (anim->isFadingOut()) {
+ } else if (anim->mode() == QScrollbarStyleAnimation::Deactivating) {
// the scrollbar was already fading out while the
// state changed -> restart the fade out animation
anim->setCurrentTime(0);
}
- } else if (anim && anim->isFadingOut()) {
+ } else if (anim && anim->mode() == QScrollbarStyleAnimation::Deactivating) {
d->stopAnimation(styleObject);
}
}
- QScrollbarAnimation *anim = qobject_cast<QScrollbarAnimation *>(d->animation(styleObject));
- if (anim && anim->isFadingOut()) {
+ QScrollbarStyleAnimation *anim = qobject_cast<QScrollbarStyleAnimation *>(d->animation(styleObject));
+ if (anim && anim->mode() == QScrollbarStyleAnimation::Deactivating) {
// once a scrollbar was active (hovered/pressed), it retains
// the active look even if it's no longer active while fading out
if (oldActiveControls)
@@ -5077,11 +5074,10 @@ void QMacStyle::drawComplexControl(ComplexControl cc, const QStyleOptionComplex
if (shouldExpand) {
if (!anim && !oldActiveControls) {
// Start expand animation only once and when entering
- anim = new QScrollbarAnimation(styleObject);
- anim->setExpanding();
+ anim = new QScrollbarStyleAnimation(QScrollbarStyleAnimation::Activating, styleObject);
d->startAnimation(anim);
}
- if (anim && !anim->isFadingOut()) {
+ if (anim && anim->mode() == QScrollbarStyleAnimation::Activating) {
expandScale = 1.0 + (maxExpandScale - 1.0) * anim->currentValue();
expandOffset = 5.5 * anim->currentValue() - 1;
} else {
diff --git a/src/widgets/styles/qmacstyle_mac_p_p.h b/src/widgets/styles/qmacstyle_mac_p_p.h
index efeaa66e39..6f42f0ea79 100644
--- a/src/widgets/styles/qmacstyle_mac_p_p.h
+++ b/src/widgets/styles/qmacstyle_mac_p_p.h
@@ -156,8 +156,6 @@ public:
static const int BevelButtonW;
static const int BevelButtonH;
static const int PushButtonContentPadding;
- static const qreal ScrollBarFadeOutDuration;
- static const qreal ScrollBarFadeOutDelay;
enum Animates { AquaPushButton, AquaProgressBar, AquaListViewItemOpen, AquaScrollBar };
static ThemeDrawState getDrawState(QStyle::State flags);
@@ -216,49 +214,6 @@ public:
void *indicatorBranchButtonCell;
};
-class QScrollbarAnimation : public QNumberStyleAnimation
-{
- Q_OBJECT
-
-public:
- QScrollbarAnimation(QObject *target) : QNumberStyleAnimation(target), _active(false)
- { }
-
- bool wasActive() const { return _active; }
- void setActive(bool active) { _active = active; }
-
- bool isFadingOut() const { return _isFadingOut; }
-
- void setFadingOut()
- {
- _isFadingOut = true;
- setDuration(QMacStylePrivate::ScrollBarFadeOutDelay + QMacStylePrivate::ScrollBarFadeOutDuration);
- setDelay(QMacStylePrivate::ScrollBarFadeOutDelay);
- setStartValue(1.0);
- setEndValue(0.0);
- }
-
- void setExpanding()
- {
- _isFadingOut = false;
- setDuration(QMacStylePrivate::ScrollBarFadeOutDuration);
- setStartValue(0.0);
- setEndValue(1.0);
- }
-
-private slots:
- void updateCurrentTime(int time)
- {
- QNumberStyleAnimation::updateCurrentTime(time);
- if (_isFadingOut && qFuzzyIsNull(currentValue()))
- target()->setProperty("visible", false);
- }
-
-private:
- bool _active;
- bool _isFadingOut;
-};
-
QT_END_NAMESPACE
#endif // QMACSTYLE_MAC_P_P_H
diff --git a/src/widgets/styles/qstyleanimation.cpp b/src/widgets/styles/qstyleanimation.cpp
index 90fb371982..85dc357ab5 100644
--- a/src/widgets/styles/qstyleanimation.cpp
+++ b/src/widgets/styles/qstyleanimation.cpp
@@ -46,6 +46,9 @@
QT_BEGIN_NAMESPACE
+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())
{
@@ -301,4 +304,43 @@ void QBlendStyleAnimation::updateCurrentTime(int time)
_current = blendedImage(_start, _end, alpha);
}
+QScrollbarStyleAnimation::QScrollbarStyleAnimation(Mode mode, QObject *target) : QNumberStyleAnimation(target), _mode(mode), _active(false)
+{
+ switch (mode) {
+ case Activating:
+ setDuration(ScrollBarFadeOutDuration);
+ setStartValue(0.0);
+ setEndValue(1.0);
+ break;
+ case Deactivating:
+ setDuration(ScrollBarFadeOutDelay + ScrollBarFadeOutDuration);
+ setDelay(ScrollBarFadeOutDelay);
+ setStartValue(1.0);
+ setEndValue(0.0);
+ break;
+ }
+}
+
+QScrollbarStyleAnimation::Mode QScrollbarStyleAnimation::mode() const
+{
+ return _mode;
+}
+
+bool QScrollbarStyleAnimation::wasActive() const
+{
+ return _active;
+}
+
+void QScrollbarStyleAnimation::setActive(bool active)
+{
+ _active = active;
+}
+
+void QScrollbarStyleAnimation::updateCurrentTime(int time)
+{
+ QNumberStyleAnimation::updateCurrentTime(time);
+ if (_mode == Deactivating && qFuzzyIsNull(currentValue()))
+ target()->setProperty("visible", false);
+}
+
QT_END_NAMESPACE
diff --git a/src/widgets/styles/qstyleanimation_p.h b/src/widgets/styles/qstyleanimation_p.h
index 77962bedac..c344858812 100644
--- a/src/widgets/styles/qstyleanimation_p.h
+++ b/src/widgets/styles/qstyleanimation_p.h
@@ -162,6 +162,28 @@ private:
QImage _current;
};
+class QScrollbarStyleAnimation : public QNumberStyleAnimation
+{
+ Q_OBJECT
+
+public:
+ enum Mode { Activating, Deactivating };
+
+ QScrollbarStyleAnimation(Mode mode, QObject *target);
+
+ Mode mode() const;
+
+ bool wasActive() const;
+ void setActive(bool active);
+
+private slots:
+ void updateCurrentTime(int time);
+
+private:
+ Mode _mode;
+ bool _active;
+};
+
QT_END_NAMESPACE
#endif // QSTYLEANIMATION_P_H