66dff7cf72
is no 'shadow' widget (and thus not set the widget itself as its parent). By connecting a slot to the signal emited by animation end, it will also restore original opacity back. TODO: instead of a copy of object, the shadow should be an image where the animated widget was painted. This will solve a lot of issues and make this class easier to use. svn path=/trunk/KDE/kdelibs/; revision=1036351
159 lines
4.3 KiB
C++
159 lines
4.3 KiB
C++
/* Copyright (C) 2009 Adenilson Cavalcanti <cavalcantii@gmail.com>
|
|
*
|
|
* This program is free software; you can redistribute it and/or modify
|
|
* it under the terms of the GNU Library General Public License as
|
|
* published by the Free Software Foundation; either version 2, or
|
|
* (at your option) any later version.
|
|
*
|
|
* This program is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
* GNU General Public License for more details
|
|
*
|
|
* You should have received a copy of the GNU Library General Public
|
|
* License along with this program; if not, write to the
|
|
* Free Software Foundation, Inc.,
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
*/
|
|
|
|
/* TODO:
|
|
* - fix centering of pulsed shadow object
|
|
*/
|
|
|
|
#include "pulser.h"
|
|
#include <QGraphicsWidget>
|
|
#include <QEvent>
|
|
#include <QAbstractAnimation>
|
|
#include <QParallelAnimationGroup>
|
|
#include <QDebug>
|
|
#include <QPropertyAnimation>
|
|
|
|
namespace Plasma
|
|
{
|
|
|
|
PulseAnimation::PulseAnimation()
|
|
: animation(0),
|
|
under(0),
|
|
pulseGeometry(0),
|
|
zvalue(0),
|
|
mscale(0),
|
|
opacityAnimation(0),
|
|
geometryAnimation(0),
|
|
scaleAnimation(0)
|
|
{
|
|
|
|
}
|
|
|
|
PulseAnimation::~PulseAnimation()
|
|
{
|
|
//XXX: current plasma::Animation model will delete all animation objects
|
|
// delete animation;
|
|
// delete pulseGeometry;
|
|
}
|
|
|
|
void PulseAnimation::setCopy(QGraphicsWidget *copy)
|
|
{
|
|
QGraphicsWidget *target = getAnimatedObject();
|
|
under = copy;
|
|
if (under != target) {
|
|
under->setParentItem(target);
|
|
mopacity = 0;
|
|
} else {
|
|
mopacity = under->opacity();
|
|
}
|
|
|
|
zvalue = target->zValue();
|
|
--zvalue;
|
|
under->setOpacity(0);
|
|
under->setZValue(zvalue);
|
|
mscale = under->scale();
|
|
|
|
}
|
|
|
|
void PulseAnimation::updateGeometry(QRectF updated, qreal zCoordinate, qreal scale)
|
|
{
|
|
zvalue = zCoordinate;
|
|
--zvalue;
|
|
under->setGeometry(updated);
|
|
under->setPos(0, 0);
|
|
under->setOpacity(0);
|
|
under->setZValue(zvalue);
|
|
|
|
/* TODO: move this to a function */
|
|
QRectF initial(under->geometry());
|
|
qreal W = initial.width() * scale * 0.33;
|
|
qreal H = initial.height() * scale * 0.33;
|
|
QRectF end(initial.x() - W, initial.y() - H, initial.width() * scale,
|
|
initial.height() * scale);
|
|
geometryAnimation->setEndValue(end);
|
|
}
|
|
|
|
|
|
void PulseAnimation::resetPulser()
|
|
{
|
|
under->setGeometry(*pulseGeometry);
|
|
under->setOpacity(mopacity);
|
|
under->setZValue(zvalue);
|
|
under->setScale(mscale);
|
|
|
|
}
|
|
|
|
|
|
void PulseAnimation::createAnimation(qreal duration, qreal scale)
|
|
{
|
|
QGraphicsWidget *target = getAnimatedObject();
|
|
/* Fallback to parent widget if we don't have one 'shadow' widget */
|
|
if (!under) {
|
|
setCopy(target);
|
|
} else if (under != target) {
|
|
delete under;
|
|
under = new QGraphicsWidget(target);
|
|
setCopy(under);
|
|
}
|
|
|
|
pulseGeometry = new QRectF(under->geometry());
|
|
QParallelAnimationGroup *group = new QParallelAnimationGroup(this);
|
|
opacityAnimation = new QPropertyAnimation(under, "opacity");
|
|
opacityAnimation->setDuration(duration);
|
|
opacityAnimation->setEndValue(0);
|
|
group->addAnimation(opacityAnimation);
|
|
|
|
/* TODO: move this to a function */
|
|
geometryAnimation = new QPropertyAnimation(under, "geometry");
|
|
geometryAnimation->setDuration(duration);
|
|
QRectF initial(under->geometry());
|
|
qreal W = initial.width() * scale * 0.33;
|
|
qreal H = initial.height() * scale * 0.33;
|
|
QRectF end(initial.x() - W, initial.y() - H, initial.width() * scale,
|
|
initial.height() * scale);
|
|
geometryAnimation->setEndValue(end);
|
|
group->addAnimation(geometryAnimation);
|
|
|
|
scaleAnimation = new QPropertyAnimation(under, "scale");
|
|
scaleAnimation->setDuration(duration);
|
|
scaleAnimation->setEndValue(scale);
|
|
group->addAnimation(scaleAnimation);
|
|
|
|
animation = group;
|
|
|
|
//This makes sure that if there is *not* a shadow widget, the
|
|
//parent widget will still remain visible
|
|
connect(animation, SIGNAL(finished()), this, SLOT(resetPulser()));
|
|
}
|
|
|
|
QAbstractAnimation* PulseAnimation::render(QObject* parent)
|
|
{
|
|
Q_UNUSED(parent);
|
|
createAnimation();
|
|
under->setOpacity(1);
|
|
return animation;
|
|
}
|
|
|
|
void PulseAnimation::start()
|
|
{
|
|
under->setOpacity(1);
|
|
animation->start();
|
|
}
|
|
|
|
} //namespace Plasma
|