• 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
  • animations
javascriptanimation.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2010 Adenilson Cavalcanti <cavalcantii@gmail.com>
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU Library General Public License as
6  * published by the Free Software Foundation; either version 2, or
7  * (at your option) any later version.
8  *
9  * This program 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
12  * GNU General Public License for more details
13  *
14  * You should have received a copy of the GNU Library General Public
15  * License along with this program; if not, write to the
16  * Free Software Foundation, Inc.,
17  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18  */
19 
20 #include "javascriptanimation_p.h"
21 
22 #include <kdebug.h>
23 
24 #include "animationscriptengine_p.h"
25 /* TODO:
26  * - support passing more parameters to the js animation object
27  * - support more properties: angle, direction, etc
28  * - support calling a 'resetAnimation' in js class when animation is stopped
29  */
30 #define ADD_ENUM_VALUE(__c__, __ns__, __v__) \
31  __c__.setProperty(#__v__, QScriptValue(__c__.engine(), __ns__::__v__))
32 
33 namespace Plasma
34 {
35 
36 JavascriptAnimation::JavascriptAnimation(const QString &name, QObject *parent)
37  : EasingAnimation(parent),
38 #ifdef PLASMA_JSANIM_FPS
39  m_fps(0),
40 #endif
41  m_name(name)
42 {
43 
44 }
45 
46 JavascriptAnimation::~JavascriptAnimation()
47 {
48 }
49 
50 void JavascriptAnimation::prepInstance()
51 {
52  QScriptEngine *engine = AnimationScriptEngine::globalEngine();
53  m_instance.setProperty("__plasma_javascriptanimation", engine->newQObject(this),
54  QScriptValue::ReadOnly | QScriptValue::Undeletable | QScriptValue::SkipInEnumeration);
55  ADD_ENUM_VALUE(m_instance, Plasma::Animator, FadeAnimation);
56  ADD_ENUM_VALUE(m_instance, Plasma::Animator, AppearAnimation);
57  ADD_ENUM_VALUE(m_instance, Plasma::Animator, DisappearAnimation);
58  ADD_ENUM_VALUE(m_instance, Plasma::Animator, ActivateAnimation);
59  ADD_ENUM_VALUE(m_instance, Plasma::Animator, FadeAnimation);
60  ADD_ENUM_VALUE(m_instance, Plasma::Animator, GrowAnimation);
61  ADD_ENUM_VALUE(m_instance, Plasma::Animator, PulseAnimation);
62  ADD_ENUM_VALUE(m_instance, Plasma::Animator, RotationAnimation);
63  ADD_ENUM_VALUE(m_instance, Plasma::Animator, RotationStackedAnimation);
64  ADD_ENUM_VALUE(m_instance, Plasma::Animator, SlideAnimation);
65  ADD_ENUM_VALUE(m_instance, Plasma::Animator, GeometryAnimation);
66  ADD_ENUM_VALUE(m_instance, Plasma::Animator, ZoomAnimation);
67  ADD_ENUM_VALUE(m_instance, Plasma::Animator, PixmapTransitionAnimation);
68  ADD_ENUM_VALUE(m_instance, JavascriptAnimation, PauseAnimation);
69  ADD_ENUM_VALUE(m_instance, JavascriptAnimation, PropertyAnimation);
70 }
71 
72 void JavascriptAnimation::updateState(QAbstractAnimation::State newState, QAbstractAnimation::State oldState)
73 {
74  //kDebug() << ".................. state: " << newState;
75  if (oldState == Stopped && newState == Running) {
76  if (!m_method.isFunction()) {
77  //Define the class and create an instance
78  m_instance = AnimationScriptEngine::animation(m_name).construct();
79  kDebug() << "trying for" << m_name << m_instance.isFunction();
80 
81  //Get the method of the object
82  m_method = m_instance.property(QString("updateCurrentTime"));
83  if (!m_method.isFunction()) {
84  qDebug() << "**************** ERROR! Name: " << m_name << " ************";
85  m_instance = m_method = QScriptValue();
86  } else {
87  prepInstance();
88 
89  //TODO: this really should be done in the bindings provided
90  //Center the widget for transformation
91  qreal x = targetWidget()->geometry().height()/2;
92  qreal y = targetWidget()->geometry().width()/2;
93  targetWidget()->setTransformOriginPoint(x, y);
94  }
95  }
96 
97  if (m_method.isFunction()) {
98  m_instance.setProperty("duration", duration(), QScriptValue::ReadOnly);
99  m_instance.setProperty("target", m_instance.engine()->newQObject(targetWidget()), QScriptValue::ReadOnly);
100  }
101 #ifdef PLASMA_JSANIM_FPS
102  m_fps = 0;
103  } else if (oldState == Running && newState == Stopped) {
104  kDebug() << ".........." << m_name << " fps: " << m_fps * 1000/duration();
105 #endif
106  }
107 }
108 
109 void JavascriptAnimation::updateEffectiveTime(int currentTime)
110 {
111  if (m_method.isFunction()) {
112 #ifdef PLASMA_JSANIM_FPS
113  ++m_fps;
114 #endif
115  QScriptValueList args;
116  args << currentTime;
117 
118  m_method.call(m_instance, args);
119  }
120 }
121 
122 } //namespace Plasma
123 
124 #include "javascriptanimation_p.moc"
Plasma::Animator
A system for applying effects to Plasma elements.
Definition: animator.h:46
Plasma::AnimationScriptEngine::globalEngine
QScriptEngine * globalEngine()
Definition: animationscriptengine.cpp:172
QObject
Plasma::AnimationScriptEngine::animation
QScriptValue animation(const QString &anim)
Definition: animationscriptengine.cpp:55
ADD_ENUM_VALUE
#define ADD_ENUM_VALUE(__c__, __ns__, __v__)
Definition: javascriptanimation.cpp:30
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:48:33 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