Added SH_Widget_Animate in QStyle

Added SH_Widget_Animate in QStyle styleHint, and use it to determine
whether widgets should be animated or not.

In this patch QTabBar, QColumnView,QTreeView and QWidgetAnimator are
patched to obey the new Hint.

Change-Id: Iefdbddc52c7843f6653dbfb5462125942489b4d9
Reviewed-by: Olivier Goffart <ogoffart@woboq.com>
This commit is contained in:
Àlex Fiestas 2013-06-17 11:21:32 +02:00 committed by The Qt Project
parent 25fc7a3068
commit 0ace311213
7 changed files with 45 additions and 16 deletions

View File

@ -332,11 +332,14 @@ void QColumnView::scrollTo(const QModelIndex &index, ScrollHint hint)
}
#ifndef QT_NO_ANIMATION
d->currentAnimation.setEndValue(newScrollbarValue);
d->currentAnimation.start();
#else
horizontalScrollBar()->setValue(newScrollbarValue);
if (style()->styleHint(QStyle::SH_Widget_Animate, 0, this)) {
d->currentAnimation.setEndValue(newScrollbarValue);
d->currentAnimation.start();
} else
#endif //QT_NO_ANIMATION
{
horizontalScrollBar()->setValue(newScrollbarValue);
}
}
/*!

View File

@ -2986,6 +2986,7 @@ void QTreeViewPrivate::initialize()
header->setDefaultAlignment(Qt::AlignLeft|Qt::AlignVCenter);
q->setHeader(header);
#ifndef QT_NO_ANIMATION
animationsEnabled = q->style()->styleHint(QStyle::SH_Widget_Animate, 0, q);
QObject::connect(&animatedOperation, SIGNAL(finished()), q, SLOT(_q_endAnimatedOperation()));
#endif //QT_NO_ANIMATION
}

View File

@ -65,6 +65,7 @@
#include <qtoolbar.h>
#include <qtoolbutton.h>
#include <qrubberband.h>
#include "qtreeview.h"
#include <private/qcommonstylepixmaps_p.h>
#include <private/qmath_p.h>
#include <qdebug.h>
@ -5113,6 +5114,16 @@ int QCommonStyle::styleHint(StyleHint sh, const QStyleOption *opt, const QWidget
ret = 2000;
break;
#endif
case SH_Widget_Animate:
#ifndef QT_NO_TREEVIEW
if (qobject_cast<const QTreeView*>(widget)) {
ret = false;
} else
#endif
{
ret = true;
}
break;
default:
ret = 0;
break;

View File

@ -1900,6 +1900,10 @@ void QStyle::drawItemPixmap(QPainter *painter, const QRect &rect, int alignment,
a tooltip is shown (notice: shown, not hidden). When a new wake isn't needed, a user-requested tooltip
will be shown nearly instantly.
\value SH_Widget_Animate Determines if the widget should show animations or not, for example
a transition between checked and unchecked statuses in a checkbox.
This enum value has been introduced in Qt 5.2.
\sa styleHint()
*/

View File

@ -700,6 +700,7 @@ public:
SH_Menu_SupportsSections,
SH_ToolTip_WakeUpDelay,
SH_ToolTip_FallAsleepDelay,
SH_Widget_Animate,
// Add new style hint values here
SH_CustomBase = 0xf0000000

View File

@ -138,6 +138,10 @@ public:
} *animation;
void startAnimation(QTabBarPrivate *priv, int duration) {
if (!priv->isAnimated()) {
priv->moveTabFinished(priv->tabList.indexOf(*this));
return;
}
if (!animation)
animation = new TabBarAnimation(this, priv);
animation->setStartValue(dragOffset);
@ -162,6 +166,7 @@ public:
int indexAtPos(const QPoint &p) const;
inline bool isAnimated() const { Q_Q(const QTabBar); return q->style()->styleHint(QStyle::SH_Widget_Animate, 0, q); }
inline bool validIndex(int index) const { return index >= 0 && index < tabList.count(); }
void setCurrentNextEnabledIndex(int offset);

View File

@ -91,24 +91,28 @@ void QWidgetAnimator::animate(QWidget *widget, const QRect &_final_geometry, boo
QRect(QPoint(-500 - widget->width(), -500 - widget->height()), widget->size());
#ifndef QT_NO_ANIMATION
AnimationMap::const_iterator it = m_animation_map.constFind(widget);
if (it != m_animation_map.constEnd() && (*it)->endValue().toRect() == final_geometry)
return;
//If the QStyle has animations, animate
if (widget->style()->styleHint(QStyle::SH_Widget_Animate, 0, widget)) {
AnimationMap::const_iterator it = m_animation_map.constFind(widget);
if (it != m_animation_map.constEnd() && (*it)->endValue().toRect() == final_geometry)
return;
QPropertyAnimation *anim = new QPropertyAnimation(widget, "geometry", widget);
anim->setDuration(animate ? 200 : 0);
anim->setEasingCurve(QEasingCurve::InOutQuad);
anim->setEndValue(final_geometry);
m_animation_map[widget] = anim;
connect(anim, SIGNAL(finished()), SLOT(animationFinished()));
anim->start(QPropertyAnimation::DeleteWhenStopped);
#else
QPropertyAnimation *anim = new QPropertyAnimation(widget, "geometry", widget);
anim->setDuration(animate ? 200 : 0);
anim->setEasingCurve(QEasingCurve::InOutQuad);
anim->setEndValue(final_geometry);
m_animation_map[widget] = anim;
connect(anim, SIGNAL(finished()), SLOT(animationFinished()));
anim->start(QPropertyAnimation::DeleteWhenStopped);
} else
#endif //QT_NO_ANIMATION
{
//we do it in one shot
widget->setGeometry(final_geometry);
#ifndef QT_NO_MAINWINDOW
m_mainWindowLayout->animationFinished(widget);
#endif //QT_NO_MAINWINDOW
#endif //QT_NO_ANIMATION
}
}
bool QWidgetAnimator::animating() const