• Skip to content
  • Skip to link menu
KDE 4.6 API Reference
  • KDE API Reference
  • kdelibs
  • KDE Home
  • Contact Us
 

Plasma

animator.cpp

Go to the documentation of this file.
00001 /*
00002     Copyright (C) 2009 Adenilson Cavalcanti <adenilson.silva@idnt.org.br>
00003 
00004     This library is free software; you can redistribute it and/or
00005     modify it under the terms of the GNU Lesser General Public
00006     License as published by the Free Software Foundation; either
00007     version 2.1 of the License, or (at your option) any later version.
00008 
00009     This library is distributed in the hope that it will be useful,
00010     but WITHOUT ANY WARRANTY; without even the implied warranty of
00011     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012     Lesser General Public License for more details.
00013 
00014     You should have received a copy of the GNU Lesser General Public
00015     License along with this library.  If not, see <http://www.gnu.org/licenses/>.
00016 */
00017 
00018 #include "animator.h"
00019 #include "private/animator_p.h"
00020 
00021 #include <kdebug.h>
00022 
00023 #include "animations/animation.h"
00024 #include "animations/animationscriptengine_p.h"
00025 #include "animations/fade_p.h"
00026 #include "animations/grow_p.h"
00027 #include "animations/pulser_p.h"
00028 #include "animations/rotation_p.h"
00029 #include "animations/slide_p.h"
00030 #include "animations/rotationstacked_p.h"
00031 #include "animations/geometry_p.h"
00032 #include "animations/zoom_p.h"
00033 #include "animations/pixmaptransition_p.h"
00034 #include "animations/water_p.h"
00035 #include "animations/pendulumcurve_p.h"
00036 #include "animations/javascriptanimation_p.h"
00037 #include "theme.h"
00038 
00039 namespace Plasma
00040 {
00041 
00042 QHash<Animator::Animation, Animator::Animation> AnimatorPrivate::s_stockAnimMappings;
00043 QHash<Animator::Animation, QString> AnimatorPrivate::s_loadableAnimMappings;
00044 
00045 void AnimatorPrivate::mapAnimation(Animator::Animation from, Animator::Animation to)
00046 {
00047     if (from == to) {
00048         return;
00049     }
00050 
00051     s_loadableAnimMappings.remove(from);
00052     s_stockAnimMappings.insert(from, to);
00053 }
00054 
00055 void AnimatorPrivate::mapAnimation(Animator::Animation from, const QString &to)
00056 {
00057     s_stockAnimMappings.remove(from);
00058     s_loadableAnimMappings.insert(from, to);
00059 }
00060 
00061 Plasma::Animation* Animator::create(Animator::Animation type, QObject *parent)
00062 {
00063     if (AnimatorPrivate::s_stockAnimMappings.contains(type)) {
00064         return create(AnimatorPrivate::s_stockAnimMappings.value(type));
00065     } else if (AnimatorPrivate::s_loadableAnimMappings.contains(type)) {
00066         const QString anim = AnimatorPrivate::s_loadableAnimMappings.value(type);
00067         return create(anim, parent);
00068     }
00069 
00070     Plasma::Animation *result = 0;
00071 
00072     switch (type) {
00073     case FadeAnimation:
00074         result = create("FadeAnimation", parent);
00075         if (!result) {
00076             result = new Plasma::FadeAnimation(parent);
00077         }
00078         break;
00079 
00080     case GrowAnimation:
00081         result = create("GrowAnimation", parent);
00082         if (!result) {
00083             result = new Plasma::GrowAnimation(parent);
00084         }
00085         break;
00086 
00087     case PulseAnimation:
00088         result = create("PulseAnimation", parent);
00089         if (!result) {
00090             result = new Plasma::PulseAnimation(parent);
00091         }
00092         break;
00093 
00094     case RotationAnimation:
00095         result = create("RotationAnimation", parent);
00096         if (!result) {
00097             result = new Plasma::RotationAnimation(parent);
00098         }
00099         break;
00100 
00101     case RotationStackedAnimation:
00102         result = create("RotationStackedAnimation", parent);
00103         if (!result) {
00104             result = new Plasma::RotationStackedAnimation(parent);
00105         }
00106         break;
00107 
00108     case SlideAnimation:
00109         result = create("SlideAnimation", parent);
00110         if (!result) {
00111             result = new Plasma::SlideAnimation(parent);
00112         }
00113         break;
00114 
00115     case GeometryAnimation:
00116         result = create("GeometryAnimation", parent);
00117         if (!result) {
00118             result = new Plasma::GeometryAnimation(parent);
00119         }
00120         break;
00121 
00122     case ZoomAnimation:
00123         result = create("ZoomAnimation", parent);
00124         if (!result) {
00125             result = new Plasma::ZoomAnimation(parent);
00126         }
00127         break;
00128 
00129     case PixmapTransitionAnimation:
00130         result = create("PixmapTransitionAnimation", parent);
00131         if (!result) {
00132             result = new Plasma::PixmapTransition(parent);
00133         }
00134         break;
00135 
00136     case WaterAnimation:
00137         result = create("WaterAnimation", parent);
00138         if (!result) {
00139             result = new Plasma::WaterAnimation(parent);
00140         }
00141         break;
00142 
00143     default:
00144         //kDebug() << "Unsupported animation type.";
00145         break;
00146     }
00147 
00148     return result;
00149 }
00150 
00151 QEasingCurve Animator::create(Animator::CurveShape type)
00152 {
00153     QEasingCurve result;
00154 
00155     switch (type) {
00156     case EaseInCurve:
00157         result.setType(QEasingCurve::InQuad);
00158         break;
00159 
00160     case EaseOutCurve:
00161         result.setType(QEasingCurve::OutQuad);
00162         break;
00163 
00164     case EaseInOutCurve:
00165         result.setType(QEasingCurve::InOutQuad);
00166         break;
00167 
00168     case LinearCurve:
00169         result.setType(QEasingCurve::Linear);
00170         break;
00171 
00172     case PendularCurve:
00173         result = PendulumCurve();
00174         break;
00175 
00176     default:
00177         kDebug() << "Unsupported easing curve type.";
00178         break;
00179     }
00180 
00181     return result;
00182 }
00183 
00184 Plasma::Animation *Animator::create(const QString &anim, QObject *parent)
00185 {
00186     if (AnimationScriptEngine::animationFailedToLoad(anim)) {
00187         return 0;
00188     }
00189 
00190     if (!AnimationScriptEngine::isAnimationRegistered(anim)) {
00191         const QString path = Theme::defaultTheme()->animationPath(anim);
00192         if (path.isEmpty()) {
00193             AnimationScriptEngine::addToLoadFailures(anim);
00194             //kError() << "************ failed to find script file for animation" << anim;
00195             return 0;
00196         }
00197 
00198         if (!AnimationScriptEngine::loadScript(path)) {
00199             AnimationScriptEngine::addToLoadFailures(anim);
00200             return 0;
00201         }
00202 
00203         if (!AnimationScriptEngine::isAnimationRegistered(anim)) {
00204             //kError() << "successfully loaded script file" << path << ", but did not get animation object for" << anim;
00205             AnimationScriptEngine::addToLoadFailures(anim);
00206             return 0;
00207         }
00208     }
00209 
00210     return new Plasma::JavascriptAnimation(anim, parent);
00211 }
00212 
00213 } // namespace Plasma
00214 
00215 #include <animator.moc>
00216 

Plasma

Skip menu "Plasma"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members
  • Related Pages

kdelibs

Skip menu "kdelibs"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • Kate
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDEWebKit
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUnitConversion
  • KUtils
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver
Generated for kdelibs by doxygen 1.7.3
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal