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

Plasma

  • sources
  • kde-4.12
  • kdelibs
  • plasma
animator.cpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2009 Adenilson Cavalcanti <adenilson.silva@idnt.org.br>
3 
4  This library is free software; you can redistribute it and/or
5  modify it under the terms of the GNU Lesser General Public
6  License as published by the Free Software Foundation; either
7  version 2.1 of the License, or (at your option) any later version.
8 
9  This library is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  Lesser General Public License for more details.
13 
14  You should have received a copy of the GNU Lesser General Public
15  License along with this library. If not, see <http://www.gnu.org/licenses/>.
16 */
17 
18 #include "animator.h"
19 #include "private/animator_p.h"
20 
21 #include <kdebug.h>
22 
23 #include "animations/animation.h"
24 #include "animations/animationscriptengine_p.h"
25 #include "animations/fade_p.h"
26 #include "animations/grow_p.h"
27 #include "animations/pulser_p.h"
28 #include "animations/rotation_p.h"
29 #include "animations/slide_p.h"
30 #include "animations/rotationstacked_p.h"
31 #include "animations/geometry_p.h"
32 #include "animations/zoom_p.h"
33 #include "animations/pixmaptransition_p.h"
34 #include "animations/water_p.h"
35 #include "animations/pendulumcurve_p.h"
36 #include "animations/javascriptanimation_p.h"
37 #include "theme.h"
38 
39 namespace Plasma
40 {
41 
42 QHash<Animator::Animation, Animator::Animation> AnimatorPrivate::s_stockAnimMappings;
43 QHash<Animator::Animation, QString> AnimatorPrivate::s_loadableAnimMappings;
44 
45 void AnimatorPrivate::mapAnimation(Animator::Animation from, Animator::Animation to)
46 {
47  if (from == to) {
48  return;
49  }
50 
51  s_loadableAnimMappings.remove(from);
52  s_stockAnimMappings.insert(from, to);
53 }
54 
55 void AnimatorPrivate::mapAnimation(Animator::Animation from, const QString &to)
56 {
57  s_stockAnimMappings.remove(from);
58  s_loadableAnimMappings.insert(from, to);
59 }
60 
61 Plasma::Animation* Animator::create(Animator::Animation type, QObject *parent)
62 {
63  if (AnimatorPrivate::s_stockAnimMappings.contains(type)) {
64  return create(AnimatorPrivate::s_stockAnimMappings.value(type));
65  } else if (AnimatorPrivate::s_loadableAnimMappings.contains(type)) {
66  const QString anim = AnimatorPrivate::s_loadableAnimMappings.value(type);
67  return create(anim, parent);
68  }
69 
70  Plasma::Animation *result = 0;
71 
72  switch (type) {
73  case FadeAnimation:
74  result = create("FadeAnimation", parent);
75  if (!result) {
76  result = new Plasma::FadeAnimation(parent);
77  }
78  break;
79 
80  case GrowAnimation:
81  result = create("GrowAnimation", parent);
82  if (!result) {
83  result = new Plasma::GrowAnimation(parent);
84  }
85  break;
86 
87  case PulseAnimation:
88  result = create("PulseAnimation", parent);
89  if (!result) {
90  result = new Plasma::PulseAnimation(parent);
91  }
92  break;
93 
94  case RotationAnimation:
95  result = create("RotationAnimation", parent);
96  if (!result) {
97  result = new Plasma::RotationAnimation(parent);
98  }
99  break;
100 
101  case RotationStackedAnimation:
102  result = create("RotationStackedAnimation", parent);
103  if (!result) {
104  result = new Plasma::RotationStackedAnimation(parent);
105  }
106  break;
107 
108  case SlideAnimation:
109  result = create("SlideAnimation", parent);
110  if (!result) {
111  result = new Plasma::SlideAnimation(parent);
112  }
113  break;
114 
115  case GeometryAnimation:
116  result = create("GeometryAnimation", parent);
117  if (!result) {
118  result = new Plasma::GeometryAnimation(parent);
119  }
120  break;
121 
122  case ZoomAnimation:
123  result = create("ZoomAnimation", parent);
124  if (!result) {
125  result = new Plasma::ZoomAnimation(parent);
126  }
127  break;
128 
129  case PixmapTransitionAnimation:
130  result = create("PixmapTransitionAnimation", parent);
131  if (!result) {
132  result = new Plasma::PixmapTransition(parent);
133  }
134  break;
135 
136  case WaterAnimation:
137  result = create("WaterAnimation", parent);
138  if (!result) {
139  result = new Plasma::WaterAnimation(parent);
140  }
141  break;
142 
143  default:
144  //kDebug() << "Unsupported animation type.";
145  break;
146  }
147 
148  return result;
149 }
150 
151 QEasingCurve Animator::create(Animator::CurveShape type)
152 {
153  QEasingCurve result;
154 
155  switch (type) {
156  case EaseInCurve:
157  result.setType(QEasingCurve::InQuad);
158  break;
159 
160  case EaseOutCurve:
161  result.setType(QEasingCurve::OutQuad);
162  break;
163 
164  case EaseInOutCurve:
165  result.setType(QEasingCurve::InOutQuad);
166  break;
167 
168  case LinearCurve:
169  result.setType(QEasingCurve::Linear);
170  break;
171 
172  case PendularCurve:
173  result = PendulumCurve();
174  break;
175 
176  default:
177  kDebug() << "Unsupported easing curve type.";
178  break;
179  }
180 
181  return result;
182 }
183 
184 Plasma::Animation *Animator::create(const QString &anim, QObject *parent)
185 {
186  if (AnimationScriptEngine::animationFailedToLoad(anim)) {
187  return 0;
188  }
189 
190  if (!AnimationScriptEngine::isAnimationRegistered(anim)) {
191  const QString path = Theme::defaultTheme()->animationPath(anim);
192  if (path.isEmpty()) {
193  AnimationScriptEngine::addToLoadFailures(anim);
194  //kError() << "************ failed to find script file for animation" << anim;
195  return 0;
196  }
197 
198  if (!AnimationScriptEngine::loadScript(path)) {
199  AnimationScriptEngine::addToLoadFailures(anim);
200  return 0;
201  }
202 
203  if (!AnimationScriptEngine::isAnimationRegistered(anim)) {
204  //kError() << "successfully loaded script file" << path << ", but did not get animation object for" << anim;
205  AnimationScriptEngine::addToLoadFailures(anim);
206  return 0;
207  }
208  }
209 
210  return new Plasma::JavascriptAnimation(anim, parent);
211 }
212 
213 } // namespace Plasma
214 
215 #include <animator.moc>
216 
Plasma::Animator::SlideAnimation
Definition: animator.h:65
Plasma::Animator::EaseInCurve
Definition: animator.h:74
Plasma::Animator::WaterAnimation
Definition: animator.h:69
animation.h
Plasma::Animator::Animation
Animation
Definition: animator.h:55
Plasma::Animator::LinearCurve
Definition: animator.h:77
Plasma::Animator::EaseInOutCurve
Definition: animator.h:76
Plasma::Animator::PixmapTransitionAnimation
Definition: animator.h:68
Plasma::Theme::animationPath
Q_INVOKABLE QString animationPath(const QString &name) const
Retrieves the path for the script file that contains a given Javascript animation.
Definition: theme.cpp:841
Plasma::AnimationScriptEngine::loadScript
bool loadScript(const QString &path, const QString &prefix)
Definition: animationscriptengine.cpp:187
theme.h
Plasma::Animation
Abstract representation of a single animation.
Definition: animation.h:46
QObject
Plasma::AnimationScriptEngine::addToLoadFailures
void addToLoadFailures(const QString &anim)
Definition: animationscriptengine.cpp:65
Plasma::Animator::ZoomAnimation
Definition: animator.h:67
Plasma::Animator::RotationAnimation
Definition: animator.h:63
Plasma::AnimationScriptEngine::animationFailedToLoad
bool animationFailedToLoad(const QString &anim)
Definition: animationscriptengine.cpp:70
Plasma::Animator::GeometryAnimation
Definition: animator.h:66
Plasma::Animator::PendularCurve
Definition: animator.h:78
Plasma::type
static QScriptValue type(QScriptContext *ctx, QScriptEngine *eng)
Definition: easingcurve.cpp:63
Plasma::Animator::CurveShape
CurveShape
Definition: animator.h:73
Plasma::Animator::FadeAnimation
Definition: animator.h:60
Plasma::Theme::defaultTheme
static Theme * defaultTheme()
Singleton pattern accessor.
Definition: theme.cpp:544
Plasma::Animator::create
static Plasma::Animation * create(Animator::Animation type, QObject *parent=0)
Factory to build new animation objects.
Definition: animator.cpp:61
Plasma::AnimationScriptEngine::isAnimationRegistered
bool isAnimationRegistered(const QString &anim)
Definition: animationscriptengine.cpp:60
animator.h
Plasma::Animator::RotationStackedAnimation
Definition: animator.h:64
Plasma::Animator::GrowAnimation
Definition: animator.h:61
Plasma::Animator::EaseOutCurve
Definition: animator.h:75
Plasma::Animator::PulseAnimation
Definition: animator.h:62
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:48:32 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

Plasma

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

kdelibs API Reference

Skip menu "kdelibs API Reference"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDEWebKit
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  • kjsembed
  •   WTF
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUnitConversion
  • KUtils
  • Nepomuk
  • Nepomuk-Core
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal