animate icon change with fade, but only if the chage doesn't happen too frequently (so is still possible to fo an animation by quicky change the icon)
svn path=/trunk/KDE/kdelibs/; revision=1091092
This commit is contained in:
parent
bd87a3f3b7
commit
a9cc788fb2
@ -656,10 +656,10 @@ QSizeF IconWidget::sizeHint(Qt::SizeHint which, const QSizeF & constraint) const
|
||||
}
|
||||
}
|
||||
|
||||
void IconWidgetPrivate::hoverEffect(bool show)
|
||||
void IconWidgetPrivate::animateMainIcon(bool show, const IconWidgetStates state)
|
||||
{
|
||||
if (show) {
|
||||
states |= IconWidgetPrivate::HoverState;
|
||||
states = state;
|
||||
}
|
||||
|
||||
hoverAnimation->setFadeIn(show);
|
||||
@ -754,6 +754,14 @@ QPixmap IconWidgetPrivate::decoration(const QStyleOptionGraphicsItem *option, bo
|
||||
KIconLoader::ActiveState), hoverAnimation->value());
|
||||
}
|
||||
}
|
||||
} else if (!result.isNull() && !oldIcon.isNull()) {
|
||||
if (qFuzzyCompare(qreal(1.0), hoverAnimation->value())) {
|
||||
oldIcon = QIcon();
|
||||
} else {
|
||||
result = PaintUtils::transition(
|
||||
oldIcon.pixmap(iconSize.toSize(), mode, state),
|
||||
result, hoverAnimation->value());
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
@ -1208,6 +1216,14 @@ void IconWidget::setIcon(const QString &icon)
|
||||
|
||||
void IconWidget::setIcon(const QIcon &icon)
|
||||
{
|
||||
/*fade to the new icon, but to not bee a too big hog, not do that when:
|
||||
- the fade animation is already running
|
||||
- the icon is under mouse
|
||||
- one betwen the old and new icon is null*/
|
||||
if (!(d->states & IconWidgetPrivate::HoverState) && d->oldIcon.isNull() && !d->icon.isNull() && !icon.isNull()) {
|
||||
d->oldIcon = d->icon;
|
||||
d->animateMainIcon(true, d->states);
|
||||
}
|
||||
d->icon = icon;
|
||||
update();
|
||||
}
|
||||
@ -1318,7 +1334,7 @@ void IconWidget::hoverEnterEvent(QGraphicsSceneHoverEvent *event)
|
||||
action->event(event->type(), event->pos());
|
||||
}
|
||||
|
||||
d->hoverEffect(true);
|
||||
d->animateMainIcon(true, d->states|IconWidgetPrivate::HoverState);
|
||||
update();
|
||||
|
||||
QGraphicsWidget::hoverEnterEvent(event);
|
||||
@ -1335,7 +1351,7 @@ void IconWidget::hoverLeaveEvent(QGraphicsSceneHoverEvent *event)
|
||||
//if an eventfilter stolen the mousereleaseevent remove the pressed state here
|
||||
d->states &= ~IconWidgetPrivate::PressedState;
|
||||
|
||||
d->hoverEffect(false);
|
||||
d->animateMainIcon(false, d->states|IconWidgetPrivate::HoverState);
|
||||
update();
|
||||
|
||||
QGraphicsWidget::hoverLeaveEvent(event);
|
||||
@ -1346,10 +1362,10 @@ bool IconWidget::sceneEventFilter(QGraphicsItem *watched, QEvent *event)
|
||||
Q_UNUSED(watched)
|
||||
|
||||
if (event->type() == QEvent::GraphicsSceneDragEnter) {
|
||||
d->hoverEffect(true);
|
||||
d->animateMainIcon(true, d->states|IconWidgetPrivate::HoverState);
|
||||
update();
|
||||
} else if (event->type() == QEvent::GraphicsSceneDragLeave) {
|
||||
d->hoverEffect(false);
|
||||
d->animateMainIcon(false, d->states|IconWidgetPrivate::HoverState);
|
||||
update();
|
||||
}
|
||||
|
||||
|
@ -195,7 +195,7 @@ public:
|
||||
void hoverAnimationFinished();
|
||||
void init();
|
||||
void layoutIcons(const QStyleOptionGraphicsItem *option);
|
||||
void hoverEffect(bool);
|
||||
void animateMainIcon(bool, const IconWidgetStates state);
|
||||
|
||||
IconWidget *q;
|
||||
QString text;
|
||||
@ -210,6 +210,7 @@ public:
|
||||
IconHoverAnimation *hoverAnimation;
|
||||
QSizeF iconSize;
|
||||
QIcon icon;
|
||||
QIcon oldIcon;
|
||||
IconWidgetStates states;
|
||||
Qt::Orientation orientation;
|
||||
int numDisplayLines;
|
||||
|
Loading…
Reference in New Issue
Block a user