2009-10-21 03:51:31 +02:00
|
|
|
/*
|
2009-12-27 23:16:11 +01:00
|
|
|
Copyright (C) 2009 Adenilson Cavalcanti <adenilson.silva@idnt.org.br>
|
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or
|
|
|
|
modify it under the terms of the GNU Lesser General Public
|
|
|
|
License as published by the Free Software Foundation; either
|
|
|
|
version 2.1 of the License, or (at your option) any later version.
|
|
|
|
|
|
|
|
This library 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
|
|
|
|
Lesser General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU Lesser General Public
|
|
|
|
License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
2009-10-21 03:51:31 +02:00
|
|
|
|
|
|
|
#include "animator.h"
|
|
|
|
#include "private/animator_p.h"
|
|
|
|
|
2010-04-28 19:51:46 +02:00
|
|
|
#include <kdebug.h>
|
2009-10-21 03:51:31 +02:00
|
|
|
|
|
|
|
#include "animations/animation.h"
|
2010-04-28 19:41:16 +02:00
|
|
|
#include "animations/animationscriptengine_p.h"
|
2009-10-22 21:46:16 +02:00
|
|
|
#include "animations/fade_p.h"
|
|
|
|
#include "animations/grow_p.h"
|
|
|
|
#include "animations/pulser_p.h"
|
|
|
|
#include "animations/rotation_p.h"
|
|
|
|
#include "animations/slide_p.h"
|
2009-12-08 00:26:24 +01:00
|
|
|
#include "animations/rotationstacked_p.h"
|
2009-12-08 10:22:51 +01:00
|
|
|
#include "animations/geometry_p.h"
|
2009-12-05 21:23:13 +01:00
|
|
|
#include "animations/zoom_p.h"
|
2010-01-21 08:23:18 +01:00
|
|
|
#include "animations/pixmaptransition_p.h"
|
2010-04-19 17:09:36 +02:00
|
|
|
#include "animations/water_p.h"
|
2010-04-23 22:55:46 +02:00
|
|
|
#include "animations/pendulumcurve_p.h"
|
2010-04-26 23:30:55 +02:00
|
|
|
#include "animations/javascriptanimation_p.h"
|
2010-04-28 19:41:16 +02:00
|
|
|
#include "theme.h"
|
2010-04-26 23:30:55 +02:00
|
|
|
|
2010-04-28 19:41:16 +02:00
|
|
|
namespace Plasma
|
|
|
|
{
|
2010-04-26 23:30:55 +02:00
|
|
|
|
2010-04-28 19:41:16 +02:00
|
|
|
QHash<Animator::Animation, Animator::Animation> AnimatorPrivate::s_stockAnimMappings;
|
|
|
|
QHash<Animator::Animation, QString> AnimatorPrivate::s_loadableAnimMappings;
|
2010-04-23 22:55:46 +02:00
|
|
|
|
2011-05-26 23:30:58 +02:00
|
|
|
Animator::Animator(QObject *parent)
|
|
|
|
: QObject(parent),
|
|
|
|
d(0)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2010-04-28 19:41:16 +02:00
|
|
|
void AnimatorPrivate::mapAnimation(Animator::Animation from, Animator::Animation to)
|
|
|
|
{
|
|
|
|
if (from == to) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
s_loadableAnimMappings.remove(from);
|
|
|
|
s_stockAnimMappings.insert(from, to);
|
|
|
|
}
|
|
|
|
|
|
|
|
void AnimatorPrivate::mapAnimation(Animator::Animation from, const QString &to)
|
2009-10-21 03:51:31 +02:00
|
|
|
{
|
2010-04-28 19:41:16 +02:00
|
|
|
s_stockAnimMappings.remove(from);
|
|
|
|
s_loadableAnimMappings.insert(from, to);
|
|
|
|
}
|
2009-10-21 03:51:31 +02:00
|
|
|
|
2009-12-03 20:30:02 +01:00
|
|
|
Plasma::Animation* Animator::create(Animator::Animation type, QObject *parent)
|
2009-10-21 03:51:31 +02:00
|
|
|
{
|
2010-04-28 19:41:16 +02:00
|
|
|
if (AnimatorPrivate::s_stockAnimMappings.contains(type)) {
|
|
|
|
return create(AnimatorPrivate::s_stockAnimMappings.value(type));
|
|
|
|
} else if (AnimatorPrivate::s_loadableAnimMappings.contains(type)) {
|
|
|
|
const QString anim = AnimatorPrivate::s_loadableAnimMappings.value(type);
|
2010-04-28 19:45:24 +02:00
|
|
|
return create(anim, parent);
|
2010-04-28 19:41:16 +02:00
|
|
|
}
|
|
|
|
|
2010-04-28 19:45:24 +02:00
|
|
|
Plasma::Animation *result = 0;
|
|
|
|
|
2009-10-21 03:51:31 +02:00
|
|
|
switch (type) {
|
|
|
|
case FadeAnimation:
|
2010-04-28 20:14:37 +02:00
|
|
|
result = create("FadeAnimation", parent);
|
|
|
|
if (!result) {
|
2010-04-28 20:10:01 +02:00
|
|
|
result = new Plasma::FadeAnimation(parent);
|
|
|
|
}
|
2009-10-21 03:51:31 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case GrowAnimation:
|
2010-04-28 20:14:37 +02:00
|
|
|
result = create("GrowAnimation", parent);
|
|
|
|
if (!result) {
|
2010-04-28 20:10:01 +02:00
|
|
|
result = new Plasma::GrowAnimation(parent);
|
|
|
|
}
|
2009-10-21 03:51:31 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case PulseAnimation:
|
2010-04-28 20:14:37 +02:00
|
|
|
result = create("PulseAnimation", parent);
|
|
|
|
if (!result) {
|
2010-04-28 20:10:01 +02:00
|
|
|
result = new Plasma::PulseAnimation(parent);
|
|
|
|
}
|
2009-10-21 03:51:31 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case RotationAnimation:
|
2010-04-28 20:14:37 +02:00
|
|
|
result = create("RotationAnimation", parent);
|
|
|
|
if (!result) {
|
2010-04-28 20:10:01 +02:00
|
|
|
result = new Plasma::RotationAnimation(parent);
|
|
|
|
}
|
2009-10-21 03:51:31 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case RotationStackedAnimation:
|
2010-04-28 20:14:37 +02:00
|
|
|
result = create("RotationStackedAnimation", parent);
|
|
|
|
if (!result) {
|
2010-04-28 20:10:01 +02:00
|
|
|
result = new Plasma::RotationStackedAnimation(parent);
|
|
|
|
}
|
2009-10-21 03:51:31 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case SlideAnimation:
|
2010-04-28 20:14:37 +02:00
|
|
|
result = create("SlideAnimation", parent);
|
|
|
|
if (!result) {
|
2010-04-28 20:10:01 +02:00
|
|
|
result = new Plasma::SlideAnimation(parent);
|
|
|
|
}
|
2009-10-21 03:51:31 +02:00
|
|
|
break;
|
2009-12-08 10:22:51 +01:00
|
|
|
|
|
|
|
case GeometryAnimation:
|
2010-04-28 20:14:37 +02:00
|
|
|
result = create("GeometryAnimation", parent);
|
|
|
|
if (!result) {
|
2010-04-28 20:10:01 +02:00
|
|
|
result = new Plasma::GeometryAnimation(parent);
|
|
|
|
}
|
2009-12-05 20:54:27 +01:00
|
|
|
break;
|
2009-12-08 10:22:51 +01:00
|
|
|
|
2009-12-05 21:23:13 +01:00
|
|
|
case ZoomAnimation:
|
2010-04-28 20:14:37 +02:00
|
|
|
result = create("ZoomAnimation", parent);
|
|
|
|
if (!result) {
|
2010-04-28 20:10:01 +02:00
|
|
|
result = new Plasma::ZoomAnimation(parent);
|
|
|
|
}
|
2009-12-05 21:23:13 +01:00
|
|
|
break;
|
2009-10-21 03:51:31 +02:00
|
|
|
|
2010-01-21 08:23:18 +01:00
|
|
|
case PixmapTransitionAnimation:
|
2010-04-28 20:14:37 +02:00
|
|
|
result = create("PixmapTransitionAnimation", parent);
|
|
|
|
if (!result) {
|
2010-04-28 20:10:01 +02:00
|
|
|
result = new Plasma::PixmapTransition(parent);
|
|
|
|
}
|
2010-01-21 08:23:18 +01:00
|
|
|
break;
|
|
|
|
|
2010-04-19 17:09:36 +02:00
|
|
|
case WaterAnimation:
|
2010-04-28 20:14:37 +02:00
|
|
|
result = create("WaterAnimation", parent);
|
|
|
|
if (!result) {
|
2010-04-28 20:10:01 +02:00
|
|
|
result = new Plasma::WaterAnimation(parent);
|
|
|
|
}
|
2010-04-19 17:09:36 +02:00
|
|
|
break;
|
|
|
|
|
2009-10-21 03:51:31 +02:00
|
|
|
default:
|
2010-04-28 20:10:01 +02:00
|
|
|
//kDebug() << "Unsupported animation type.";
|
|
|
|
break;
|
2009-10-21 03:51:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2010-04-24 00:36:17 +02:00
|
|
|
QEasingCurve Animator::create(Animator::CurveShape type)
|
2010-04-23 22:55:46 +02:00
|
|
|
{
|
|
|
|
QEasingCurve result;
|
|
|
|
|
|
|
|
switch (type) {
|
|
|
|
case EaseInCurve:
|
|
|
|
result.setType(QEasingCurve::InQuad);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case EaseOutCurve:
|
|
|
|
result.setType(QEasingCurve::OutQuad);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case EaseInOutCurve:
|
|
|
|
result.setType(QEasingCurve::InOutQuad);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case LinearCurve:
|
|
|
|
result.setType(QEasingCurve::Linear);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case PendularCurve:
|
|
|
|
result = PendulumCurve();
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2011-07-29 15:46:52 +02:00
|
|
|
#ifndef NDEBUG
|
2010-04-23 22:55:46 +02:00
|
|
|
kDebug() << "Unsupported easing curve type.";
|
2011-07-29 15:46:52 +02:00
|
|
|
#endif
|
2010-04-23 22:55:46 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2010-04-28 19:45:24 +02:00
|
|
|
Plasma::Animation *Animator::create(const QString &anim, QObject *parent)
|
2010-04-26 23:30:55 +02:00
|
|
|
{
|
2010-06-15 20:02:44 +02:00
|
|
|
if (AnimationScriptEngine::animationFailedToLoad(anim)) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2010-04-28 19:41:16 +02:00
|
|
|
if (!AnimationScriptEngine::isAnimationRegistered(anim)) {
|
|
|
|
const QString path = Theme::defaultTheme()->animationPath(anim);
|
|
|
|
if (path.isEmpty()) {
|
2010-06-15 20:02:44 +02:00
|
|
|
AnimationScriptEngine::addToLoadFailures(anim);
|
2010-06-05 19:35:12 +02:00
|
|
|
//kError() << "************ failed to find script file for animation" << anim;
|
2010-04-28 19:41:16 +02:00
|
|
|
return 0;
|
|
|
|
}
|
2010-04-28 19:45:24 +02:00
|
|
|
|
2010-04-28 19:51:46 +02:00
|
|
|
if (!AnimationScriptEngine::loadScript(path)) {
|
2010-06-15 20:02:44 +02:00
|
|
|
AnimationScriptEngine::addToLoadFailures(anim);
|
2010-04-28 19:41:16 +02:00
|
|
|
return 0;
|
2010-04-26 23:30:55 +02:00
|
|
|
}
|
|
|
|
|
2010-04-28 19:41:16 +02:00
|
|
|
if (!AnimationScriptEngine::isAnimationRegistered(anim)) {
|
2010-06-05 19:35:12 +02:00
|
|
|
//kError() << "successfully loaded script file" << path << ", but did not get animation object for" << anim;
|
2010-06-15 20:02:44 +02:00
|
|
|
AnimationScriptEngine::addToLoadFailures(anim);
|
2010-04-28 20:14:37 +02:00
|
|
|
return 0;
|
2010-04-28 19:41:16 +02:00
|
|
|
}
|
|
|
|
}
|
2010-04-26 23:30:55 +02:00
|
|
|
|
2010-04-28 19:41:16 +02:00
|
|
|
return new Plasma::JavascriptAnimation(anim, parent);
|
2010-04-26 23:30:55 +02:00
|
|
|
}
|
|
|
|
|
2009-10-21 03:51:31 +02:00
|
|
|
} // namespace Plasma
|
|
|
|
|
|
|
|
#include <animator.moc>
|
|
|
|
|