From a246be9d420c28e1e43c92927ea7c70e0d2f104f Mon Sep 17 00:00:00 2001 From: "Aaron J. Seigo" Date: Thu, 29 Apr 2010 21:17:43 +0000 Subject: [PATCH] * get rid of some manual memory management * get rid of some members that were really only used as local members * make the fps stuff optional (and off by default) svn path=/trunk/KDE/kdelibs/; revision=1120750 --- animations/javascriptanimation.cpp | 55 ++++++++++++++---------------- animations/javascriptanimation_p.h | 12 ++++--- 2 files changed, 33 insertions(+), 34 deletions(-) diff --git a/animations/javascriptanimation.cpp b/animations/javascriptanimation.cpp index e81def715..c5dd4932e 100644 --- a/animations/javascriptanimation.cpp +++ b/animations/javascriptanimation.cpp @@ -18,7 +18,8 @@ */ #include "javascriptanimation_p.h" -#include + +#include #include "animationscriptengine_p.h" /* TODO: @@ -31,68 +32,62 @@ namespace Plasma { JavascriptAnimation::JavascriptAnimation(const QString &name, QObject *parent) - : Animation(parent), m_fps(0), m_name(name), engine(0), m_instance(0), m_method(0) + : Animation(parent), +#ifdef PLASMA_JSANIM_FPS + m_fps(0), +#endif + m_name(name) { } JavascriptAnimation::~JavascriptAnimation() { - delete m_instance; - delete m_method; } void JavascriptAnimation::updateState(QAbstractAnimation::State newState, QAbstractAnimation::State oldState) { - qDebug() << ".................. state: " << newState; + //kDebug() << ".................. state: " << newState; if (oldState == Stopped && newState == Running) { - if (!engine) { - engine = AnimationScriptEngine::globalEngine(); - + if (!m_method.isFunction()) { //Define the class and create an instance - if (!m_instance) { - m_instance = new QScriptValue; - QScriptValueList args; - args << engine->newQObject(targetWidget()) << duration(); - *m_instance = AnimationScriptEngine::animation(m_name).construct(args); - qDebug( )<< "trying for" << m_name << m_instance->isFunction(); - } + QScriptValueList args; + args << AnimationScriptEngine::globalEngine()->newQObject(targetWidget()) << duration(); + m_instance = AnimationScriptEngine::animation(m_name).construct(args); + kDebug() << "trying for" << m_name << m_instance.isFunction(); //Get the method of the object - if (!m_method) { - m_method = new QScriptValue; - *m_method = m_instance->property(QString("updateCurrentTime")); - if (!m_method->isFunction()) { - qDebug() << "**************** ERROR! ************"; - } else { - qDebug() << ".................. success js instance creation!"; - } - + m_method = m_instance.property(QString("updateCurrentTime")); + if (!m_method.isFunction()) { + qDebug() << "**************** ERROR! ************"; + m_instance = m_method = QScriptValue(); } + //TODO: this really should be done in the bindings provided //Center the widget for transformation qreal x = targetWidget()->geometry().height()/2; qreal y = targetWidget()->geometry().width()/2; targetWidget()->setTransformOriginPoint(x, y); - } +#ifdef PLASMA_JSANIM_FPS m_fps = 0; - } else if (oldState == Running && newState == Stopped) { - - qDebug() << ".........." << m_name << " fps: " << m_fps * 1000/duration(); + kDebug() << ".........." << m_name << " fps: " << m_fps * 1000/duration(); +#endif } } void JavascriptAnimation::updateCurrentTime(int currentTime) { - if (m_method->isFunction()) { + if (m_method.isFunction()) { +#ifdef PLASMA_JSANIM_FPS ++m_fps; +#endif QScriptValueList args; args << currentTime; - m_method->call(*m_instance, args); + m_method.call(m_instance, args); } } diff --git a/animations/javascriptanimation_p.h b/animations/javascriptanimation_p.h index 4c52f0755..ca86b23dc 100644 --- a/animations/javascriptanimation_p.h +++ b/animations/javascriptanimation_p.h @@ -20,12 +20,15 @@ #ifndef PLASMA_ANIMATIONS_JS_P_H #define PLASMA_ANIMATIONS_JS_P_H +#include + #include #include class QString; class QScriptEngine; -class QScriptValue; + +//#define PLASMA_JSANIM_FPS namespace Plasma { @@ -45,11 +48,12 @@ protected: void updateCurrentTime(int currentTime); private: +#ifdef PLASMA_JSANIM_FPS int m_fps; +#endif QString m_name; - QScriptEngine *engine; - QScriptValue *m_instance; - QScriptValue *m_method; + QScriptValue m_instance; + QScriptValue m_method; }; }