SVN commit 866781 by mart: use PaintUtils::transition M +36 -38 pushbutton.cpp M +1 -1 pushbutton.h --- trunk/KDE/kdebase/workspace/libs/plasma/widgets/pushbutton.cpp #866780:866781 @@ -1,5 +1,6 @@ /* * Copyright 2008 Aaron Seigo + * Copyright 2008 Marco Martin * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Library General Public License as @@ -33,6 +34,7 @@ #include "svg.h" #include "panelsvg.h" #include "animator.h" +#include "paintutils.h" namespace Plasma { @@ -44,7 +46,8 @@ : q(pushButton), background(0), activeBackgroundPixmap(0), - animId(0), + animId(-1), + fadeIn(false), svg(0) { } @@ -74,16 +77,18 @@ static_cast(q->widget())->setIcon(KIcon(pm)); } - void renderActiveBackgroundPixmap(); void syncActiveRect(); void syncBorders(); - void elementAnimationFinished(int id); + void animationUpdate(qreal progress); PushButton *q; PanelSvg *background; QPixmap *activeBackgroundPixmap; + QPixmap *backgroundPixmap; int animId; + bool fadeIn; + qreal opacity; QRectF activeRect; QString imagePath; @@ -92,17 +97,6 @@ }; -void PushButtonPrivate::renderActiveBackgroundPixmap() -{ - background->setElementPrefix("active"); - - activeBackgroundPixmap = new QPixmap(activeRect.size().toSize()); - activeBackgroundPixmap->fill(Qt::transparent); - - QPainter painter(activeBackgroundPixmap); - background->paintPanel(&painter); -} - void PushButtonPrivate::syncActiveRect() { background->setElementPrefix("normal"); @@ -133,15 +127,21 @@ syncActiveRect(); } -void PushButtonPrivate::elementAnimationFinished(int id) + +void PushButtonPrivate::animationUpdate(qreal progress) { - if (id == animId) { + if (progress == 1) { animId = -1; + fadeIn = true; } -} + opacity = fadeIn ? progress : 1 - progress; + // explicit update + q->update(); +} + PushButton::PushButton(QGraphicsWidget *parent) : QGraphicsProxyWidget(parent), d(new PushButtonPrivate(this)) @@ -157,7 +157,6 @@ d->background->setElementPrefix("normal"); d->syncBorders(); setAcceptHoverEvents(true); - connect(Plasma::Animator::self(), SIGNAL(elementAnimationFinished(int)), this, SLOT(elementAnimationFinished(int))); connect(Plasma::Theme::defaultTheme(), SIGNAL(themeChanged()), SLOT(syncBorders())); } @@ -271,7 +270,9 @@ } else { d->background->setElementPrefix("normal"); } - d->background->paintPanel(painter); + if (d->animId == -1) { + d->background->paintPanel(painter); + } //flat or disabled } else if (!isEnabled() || nativeWidget()->isFlat()) { bufferPixmap = QPixmap(rect().size().toSize()); @@ -288,12 +289,13 @@ //if is under mouse draw the animated glow overlay if (!nativeWidget()->isDown() && isEnabled() && acceptHoverEvents()) { if (d->animId != -1) { - painter->drawPixmap(d->activeRect.topLeft(), Plasma::Animator::self()->currentPixmap(d->animId) ); + //QPixmap normalPix = QPixmap(d->activeRect.size()); + QPixmap normalPix = d->background->panelPixmap(); + d->background->setElementPrefix("active"); + painter->drawPixmap(d->activeRect.topLeft(), PaintUtils::transition(d->background->panelPixmap(), normalPix, 1 - d->opacity)); } else if (isUnderMouse() || nativeWidget()->isDefault()) { - if (d->activeBackgroundPixmap == 0) { - d->renderActiveBackgroundPixmap(); - } - painter->drawPixmap( d->activeRect.topLeft(), *d->activeBackgroundPixmap ); + d->background->setElementPrefix("active"); + d->background->paintPanel(painter, d->activeRect.topLeft()); } } @@ -363,35 +365,31 @@ void PushButton::hoverEnterEvent(QGraphicsSceneHoverEvent *event) { + const int FadeInDuration = 75; + if (d->animId != -1) { - Plasma::Animator::self()->stopElementAnimation(d->animId); + Plasma::Animator::self()->stopCustomAnimation(d->animId); } - d->animId = Plasma::Animator::self()->animateElement(this, Plasma::Animator::AppearAnimation); + d->animId = Plasma::Animator::self()->customAnimation(40 / (1000 / FadeInDuration), FadeInDuration,Plasma::Animator::LinearCurve, this, "animationUpdate"); d->background->setElementPrefix("active"); - if (!d->activeBackgroundPixmap) { - d->renderActiveBackgroundPixmap(); - } - Plasma::Animator::self()->setInitialPixmap( d->animId, *d->activeBackgroundPixmap ); - QGraphicsProxyWidget::hoverEnterEvent(event); } void PushButton::hoverLeaveEvent(QGraphicsSceneHoverEvent *event) { + const int FadeOutDuration = 150; + if (d->animId != -1) { - Plasma::Animator::self()->stopElementAnimation(d->animId); + Plasma::Animator::self()->stopCustomAnimation(d->animId != -1); } - d->animId = Plasma::Animator::self()->animateElement(this, Plasma::Animator::DisappearAnimation); + d->fadeIn = false; + d->animId = Plasma::Animator::self()->customAnimation(40 / (1000 / FadeOutDuration), FadeOutDuration,Plasma::Animator::LinearCurve, this, "animationUpdate"); + d->background->setElementPrefix("active"); - if (!d->activeBackgroundPixmap) { - d->renderActiveBackgroundPixmap(); - } - Plasma::Animator::self()->setInitialPixmap( d->animId, *d->activeBackgroundPixmap ); - QGraphicsProxyWidget::hoverLeaveEvent(event); } --- trunk/KDE/kdebase/workspace/libs/plasma/widgets/pushbutton.h #866780:866781 @@ -108,7 +108,7 @@ friend class PushButtonPrivate; Q_PRIVATE_SLOT(d, void syncBorders()) - Q_PRIVATE_SLOT(d, void elementAnimationFinished(int id)) + Q_PRIVATE_SLOT(d, void animationUpdate(qreal progress)) }; } // namespace Plasma