On April 7, 2010, you wrote:
> This patch generated a discussion which ended up on a cooler idea (thanks
> notmart, Savago and igorto!) that is providing two properties on the
> Animation class in order to set up the pendulum behavior ("attenuation"
> for the amount of delta value decrement between each bounce step and
> "bounceCenter" to define from which point the target widget shall have the
> same distance throughout the whole animation).

this is just an easing curve, no? only it's hardcoded into Animation. and so 
every time we'd want another behaviour, we'd end up harcoding another curve 
method into Animation? 

Animation alreay has support for QEasingCurve. the attached patch makes it 
easier to use (with an example of how Rotation was modified; all the classes 
would need this modification though.)

then this pedulum behaviour could become a QEasingCurve implementation. the 
next question becomes: do we want to offer a Animator::easingCurve(..) method?

-- 
Aaron J. Seigo
humru othro a kohnu se
GPG Fingerprint: 8B8B 2209 0C6F 7C47 B1EA  EE75 D6B7 2EB1 A7F1 DB43

KDE core developer sponsored by Qt Development Frameworks
Index: CMakeLists.txt
===================================================================
--- CMakeLists.txt	(revision 1111854)
+++ CMakeLists.txt	(working copy)
@@ -50,6 +50,7 @@
     abstracttoolbox.cpp
     animator.cpp
     animations/animation.cpp
+    animations/easinganimation.cpp
     animations/fade.cpp
     animations/grow.cpp
     animations/slide.cpp
Index: animations/rotation.cpp
===================================================================
--- animations/rotation.cpp	(revision 1111854)
+++ animations/rotation.cpp	(working copy)
@@ -20,6 +20,7 @@
 
 #include <QGraphicsRotation>
 #include <QEasingCurve>
+#include <QVector3D>
 
 #include <kdebug.h>
 
@@ -27,7 +28,7 @@
 {
 
 RotationAnimation::RotationAnimation(QObject *parent, qint8 reference, Qt::Axis axis, qreal angle)
-    : Animation(parent)
+    : EasingAnimation(parent)
 {
     setAngle(angle);
     setAxis(axis);
@@ -158,7 +159,7 @@
     }
 }
 
-void RotationAnimation::updateCurrentTime(int currentTime)
+void RotationAnimation::updateEffectiveTime(int currentTime)
 {
     QGraphicsWidget *w = targetWidget();
     if (w) {
Index: animations/easinganimation.cpp
===================================================================
--- animations/easinganimation.cpp	(revision 0)
+++ animations/easinganimation.cpp	(revision 0)
@@ -0,0 +1,36 @@
+/*
+ *   Copyright 2010 Aaron Seigo <ase...@kde.org>
+ *
+ *   This program is free software; you can redistribute it and/or modify
+ *   it under the terms of the GNU Library General Public License as
+ *   published by the Free Software Foundation; either version 2, or
+ *   (at your option) any later version.
+ *
+ *   This program 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 General Public License for more details
+ *
+ *   You should have received a copy of the GNU Library General Public
+ *   License along with this program; if not, write to the
+ *   Free Software Foundation, Inc.,
+ *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+
+#include "easinganimation_p.h"
+
+namespace Plasma
+{
+
+EasingAnimation::EasingAnimation(QObject *parent)
+    : Animation(parent)
+{
+}
+
+void EasingAnimation::updateCurrentTime(int currentTime)
+{
+    updateEffectiveTime(easingCurve().valueForProgress(currentTime / duration()) * duration());
+}
+
+} // namespace Plasma
+
Index: animations/rotation_p.h
===================================================================
--- animations/rotation_p.h	(revision 1111854)
+++ animations/rotation_p.h	(working copy)
@@ -23,11 +23,8 @@
 #ifndef PLASMA_ROTATION_P_H
 #define PLASMA_ROTATION_P_H
 
-#include <plasma/animations/animation.h>
-#include <plasma/plasma_export.h>
+#include <plasma/animations/easinganimation_p.h>
 
-#include <QVector3D>
-
 class QGraphicsRotation;
 
 namespace Plasma {
@@ -39,7 +36,7 @@
  * axis can be defined using properties). See also
  * \ref StackedRotationAnimation.
  */
-class RotationAnimation : public Animation
+class RotationAnimation : public EasingAnimation
 {
 
     Q_OBJECT
@@ -101,7 +98,7 @@
 
 protected:
     void updateState(QAbstractAnimation::State newState, QAbstractAnimation::State oldState);
-    void updateCurrentTime(int currentTime);
+    void updateEffectiveTime(int currentTime);
 
 private:
     /** Rotation transform object */
Index: animations/easinganimation_p.h
===================================================================
--- animations/easinganimation_p.h	(revision 0)
+++ animations/easinganimation_p.h	(revision 0)
@@ -0,0 +1,46 @@
+/*
+ *   Copyright 2010 Aaron Seigo <ase...@kde.org>
+ *
+ *   This program is free software; you can redistribute it and/or modify
+ *   it under the terms of the GNU Library General Public License as
+ *   published by the Free Software Foundation; either version 2, or
+ *   (at your option) any later version.
+ *
+ *   This program 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 General Public License for more details
+ *
+ *   You should have received a copy of the GNU Library General Public
+ *   License along with this program; if not, write to the
+ *   Free Software Foundation, Inc.,
+ *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+
+#ifndef PLASMA_EASINGANIMATION_H
+#define PLASMA_EASINGANIMATION_H
+
+#include "animation.h"
+
+namespace Plasma
+{
+
+
+class EasingAnimation : public Animation
+{
+    Q_OBJECT
+
+public:
+    explicit EasingAnimation(QObject *parent = 0);
+
+protected:
+    virtual void updateEffectiveTime(int currentTime) = 0;
+
+private:
+    void updateCurrentTime(int currentTime);
+};
+
+} // namespace Plasma
+
+#endif // PLASMA_EASINGANIMATION_H
+
_______________________________________________
Plasma-devel mailing list
Plasma-devel@kde.org
https://mail.kde.org/mailman/listinfo/plasma-devel

Reply via email to