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>
This commit is contained in:
parent
e14885a18a
commit
062d2a1f80
@ -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 {
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user