From 0ef80e4c17595e04db3926be09b504acf1e02075 Mon Sep 17 00:00:00 2001 From: Michael Brasser Date: Mon, 27 Apr 2009 09:18:37 +1000 Subject: Tweak the Dial example. --- examples/declarative/dial/DialLibrary/Dial.qml | 6 +++--- examples/declarative/dial/dial.qml | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/examples/declarative/dial/DialLibrary/Dial.qml b/examples/declarative/dial/DialLibrary/Dial.qml index e1b9f18..e2a11b1 100644 --- a/examples/declarative/dial/DialLibrary/Dial.qml +++ b/examples/declarative/dial/DialLibrary/Dial.qml @@ -1,12 +1,12 @@ + + + - - - diff --git a/examples/declarative/dial/dial.qml b/examples/declarative/dial/dial.qml index ce43b01..bda9b41 100644 --- a/examples/declarative/dial/dial.qml +++ b/examples/declarative/dial/dial.qml @@ -3,7 +3,7 @@ - + Date: Mon, 27 Apr 2009 11:06:47 +1000 Subject: Replace the use of the obsolete GfxEasing with QEasingCurve. --- src/declarative/3rdparty/easing.cpp | 726 --------------------- src/declarative/3rdparty/legal.qdoc | 35 - src/declarative/canvas/qsimplecanvasitem.h | 1 - src/declarative/fx/qfxflickable.cpp | 9 +- src/declarative/fx/qfxlistview.cpp | 9 +- src/declarative/fx/qfxparticles.cpp | 1 - src/declarative/fx/qfxpathview.cpp | 13 +- src/declarative/qml/qmlbindablevalue.cpp | 2 - src/declarative/test/qfxtestengine.cpp | 2 +- src/declarative/timeline/gfxeasing.cpp | 811 ------------------------ src/declarative/timeline/gfxeasing.h | 107 ---- src/declarative/timeline/gfxtimeline.cpp | 946 ---------------------------- src/declarative/timeline/gfxtimeline.h | 190 ------ src/declarative/timeline/gfxvalueproxy.h | 3 + src/declarative/timeline/qmltimeline.cpp | 943 +++++++++++++++++++++++++++ src/declarative/timeline/qmltimeline.h | 190 ++++++ src/declarative/timeline/timeline.pri | 6 +- src/declarative/util/qmlanimation.cpp | 58 +- src/declarative/util/qmlbehaviour.h | 2 - src/declarative/util/qmlfollow.cpp | 1 - src/declarative/util/qmlstate.cpp | 1 - src/declarative/util/qmlstate.h | 1 - src/declarative/util/qmlstateoperations.cpp | 1 - src/declarative/util/qmltransition.h | 1 - 24 files changed, 1207 insertions(+), 2852 deletions(-) delete mode 100644 src/declarative/3rdparty/easing.cpp delete mode 100644 src/declarative/3rdparty/legal.qdoc delete mode 100644 src/declarative/timeline/gfxeasing.cpp delete mode 100644 src/declarative/timeline/gfxeasing.h delete mode 100644 src/declarative/timeline/gfxtimeline.cpp delete mode 100644 src/declarative/timeline/gfxtimeline.h create mode 100644 src/declarative/timeline/qmltimeline.cpp create mode 100644 src/declarative/timeline/qmltimeline.h diff --git a/src/declarative/3rdparty/easing.cpp b/src/declarative/3rdparty/easing.cpp deleted file mode 100644 index 50e9e51..0000000 --- a/src/declarative/3rdparty/easing.cpp +++ /dev/null @@ -1,726 +0,0 @@ -/* -Disclaimer for Robert Penner's Easing Equations license: - -TERMS OF USE - EASING EQUATIONS - -Open source under the BSD License. - -Copyright © 2001 Robert Penner -All rights reserved. - -Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: - - * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. - * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. - * Neither the name of the author nor the names of contributors may be used to endorse or promote products derived from this software without specific prior written permission. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -*/ - -#ifndef M_PI -#define M_PI 3.14159265358979323846 -#endif -#ifndef M_PI_2 -#define M_PI_2 (M_PI / 2) -#endif - - -/** - * Easing equation function for a simple linear tweening, with no easing. - * - * @param t Current time (in frames or seconds). - * @param b Starting value. - * @param c Change needed in value. - * @param d Expected easing duration (in frames or seconds). - * @return The correct value. - */ -static float easeNone(float t, float b, float c, float d) -{ - return c*t/d + b; -} - -/** - * Easing equation function for a quadratic (t^2) easing in: accelerating from zero velocity. - * - * @param t Current time (in frames or seconds). - * @param b Starting value. - * @param c Change needed in value. - * @param d Expected easing duration (in frames or seconds). - * @return The correct value. - */ -static float easeInQuad(float t, float b, float c, float d) -{ - float t_adj = (float)t / (float)d; - return c*t_adj*t_adj + b; -} - -/** -* Easing equation function for a quadratic (t^2) easing out: decelerating to zero velocity. -* -* @param t Current time (in frames or seconds). -* @param b Starting value. -* @param c Change needed in value. -* @param d Expected easing duration (in frames or seconds). -* @return The correct value. -*/ -static float easeOutQuad(float t, float b, float c, float d) -{ - float t_adj = (float)t / (float)d; - return -c *t_adj*(t_adj-2) + b; -} - -/** -* Easing equation function for a quadratic (t^2) easing in/out: acceleration until halfway, then deceleration. -* -* @param t Current time (in frames or seconds). -* @param b Starting value. -* @param c Change needed in value. -* @param d Expected easing duration (in frames or seconds). -* @return The correct value. -*/ -static float easeInOutQuad(float t, float b, float c, float d) -{ - float t_adj = 2.0f * (float)t / (float)d; - if (t_adj < 1) { - return c/2*t_adj*t_adj + b; - } else { - --t_adj; - return -c/2 * ((t_adj)*(t_adj-2) - 1) + b; - } -} - -/** -* Easing equation function for a quadratic (t^2) easing out/in: deceleration until halfway, then acceleration. -* -* @param t Current time (in frames or seconds). -* @param b Starting value. -* @param c Change needed in value. -* @param d Expected easing duration (in frames or seconds). -* @return The correct value. -*/ -static float easeOutInQuad(float t, float b, float c, float d) -{ - if (t < d/2) return easeOutQuad (t*2, b, c/2, d); - return easeInQuad((t*2)-d, b+c/2, c/2, d); -} - -/** -* Easing equation function for a cubic (t^3) easing in: accelerating from zero velocity. -* -* @param t Current time (in frames or seconds). -* @param b Starting value. -* @param c Change needed in value. -* @param d Expected easing duration (in frames or seconds). -* @return The correct value. -*/ -static float easeInCubic(float t, float b, float c, float d) -{ - float t_adj = (float)t / (float)d; - return c*t_adj*t_adj*t_adj + b; -} - -/** -* Easing equation function for a cubic (t^3) easing out: decelerating from zero velocity. -* -* @param t Current time (in frames or seconds). -* @param b Starting value. -* @param c Change needed in value. -* @param d Expected easing duration (in frames or seconds). -* @return The correct value. -*/ -static float easeOutCubic(float t, float b, float c, float d) -{ - float t_adj = (float)t / (float)(d) - 1.0f; - return c*(t_adj*t_adj*t_adj + 1) + b; -} - -/** -* Easing equation function for a cubic (t^3) easing in/out: acceleration until halfway, then deceleration. -* -* @param t Current time (in frames or seconds). -* @param b Starting value. -* @param c Change needed in value. -* @param d Expected easing duration (in frames or seconds). -* @return The correct value. -*/ -static float easeInOutCubic(float t, float b, float c, float d) -{ - float t_adj = 2.0f * (float)t / (float)(d); - if(t_adj < 1) return c/2*t_adj*t_adj*t_adj + b; - else { - t_adj -= 2; - return c/2*(t_adj*t_adj*t_adj + 2) + b; - } -} - -/** -* Easing equation function for a cubic (t^3) easing out/in: deceleration until halfway, then acceleration. -* -* @param t Current time (in frames or seconds). -* @param b Starting value. -* @param c Change needed in value. -* @param d Expected easing duration (in frames or seconds). -* @return The correct value. -*/ -static float easeOutInCubic(float t, float b, float c, float d) -{ - if (t < d/2) return easeOutCubic (t*2, b, c/2, d); - return easeInCubic((t*2)-d, b+c/2, c/2, d); -} - -/** -* Easing equation function for a quartic (t^4) easing in: accelerating from zero velocity. -* -* @param t Current time (in frames or seconds). -* @param b Starting value. -* @param c Change needed in value. -* @param d Expected easing duration (in frames or seconds). -* @return The correct value. -*/ -static float easeInQuart(float t, float b, float c, float d) -{ - float t_adj = (float)t / (float)d; - return c*t_adj*t_adj*t_adj*t_adj + b; -} - -/** -* Easing equation function for a quartic (t^4) easing out: decelerating from zero velocity. -* -* @param t Current time (in frames or seconds). -* @param b Starting value. -* @param c Change needed in value. -* @param d Expected easing duration (in frames or seconds). -* @return The correct value. -*/ -static float easeOutQuart(float t, float b, float c, float d) -{ - float t_adj = (float)t / (float)d - 1.0f; - return -c * (t_adj*t_adj*t_adj*t_adj - 1) + b; -} - -/** -* Easing equation function for a quartic (t^4) easing in/out: acceleration until halfway, then deceleration. -* -* @param t Current time (in frames or seconds). -* @param b Starting value. -* @param c Change needed in value. -* @param d Expected easing duration (in frames or seconds). -* @return The correct value. -*/ -static float easeInOutQuart(float t, float b, float c, float d) -{ - float t_adj = 2.0f * (float)t / (float)d; - if (t_adj < 1) return c/2*t_adj*t_adj*t_adj*t_adj + b; - else { - t_adj -= 2.0f; - return -c/2 * (t_adj*t_adj*t_adj*t_adj - 2) + b; - } -} - -/** -* Easing equation function for a quartic (t^4) easing out/in: deceleration until halfway, then acceleration. -* -* @param t Current time (in frames or seconds). -* @param b Starting value. -* @param c Change needed in value. -* @param d Expected easing duration (in frames or seconds). -* @return The correct value. -*/ -static float easeOutInQuart(float t, float b, float c, float d) -{ - if (t < d/2) return easeOutQuart (t*2, b, c/2, d); - return easeInQuart((t*2)-d, b+c/2, c/2, d); -} - -/** - * Easing equation function for a quintic (t^5) easing in: accelerating from zero velocity. - * - * @param t Current time (in frames or seconds). - * @param b Starting value. - * @param c Change needed in value. - * @param d Expected easing duration (in frames or seconds). - * @return The correct value. - */ -static float easeInQuint(float t, float b, float c, float d) -{ - float t_adj = (float)t/(float)d; - return c*t_adj*t_adj*t_adj*t_adj*t_adj + b; -} - -/** - * Easing equation function for a quintic (t^5) easing out: decelerating from zero velocity. - * - * @param t Current time (in frames or seconds). - * @param b Starting value. - * @param c Change needed in value. - * @param d Expected easing duration (in frames or seconds). - * @return The correct value. - */ -static float easeOutQuint(float t, float b, float c, float d) -{ - float t_adj = (float)t/(float)d - 1.0f; - return c*(t_adj*t_adj*t_adj*t_adj*t_adj + 1) + b; -} - -/** - * Easing equation function for a quintic (t^5) easing in/out: acceleration until halfway, then deceleration. - * - * @param t Current time (in frames or seconds). - * @param b Starting value. - * @param c Change needed in value. - * @param d Expected easing duration (in frames or seconds). - * @return The correct value. - */ -static float easeInOutQuint(float t, float b, float c, float d) -{ - float t_adj = 2.0f * (float)t/(float)d; - if (t_adj < 1) return c/2*t_adj*t_adj*t_adj*t_adj*t_adj + b; - else { - t_adj -= 2.0f; - return c/2*(t_adj*t_adj*t_adj*t_adj*t_adj + 2) + b; - } -} - -/** - * Easing equation function for a quintic (t^5) easing out/in: deceleration until halfway, then acceleration. - * - * @param t Current time (in frames or seconds). - * @param b Starting value. - * @param c Change needed in value. - * @param d Expected easing duration (in frames or seconds). - * @return The correct value. - */ -static float easeOutInQuint(float t, float b, float c, float d) -{ - if (t < d/2) return easeOutQuint (t*2, b, c/2, d); - return easeInQuint((t*2)-d, b+c/2, c/2, d); -} - -/** - * Easing equation function for a sinusoidal (sin(t)) easing in: accelerating from zero velocity. - * - * @param t Current time (in frames or seconds). - * @param b Starting value. - * @param c Change needed in value. - * @param d Expected easing duration (in frames or seconds). - * @return The correct value. - */ -static float easeInSine(float t, float b, float c, float d) -{ - float t_adj = (float)t/(float)d; - return -c * ::cos(t_adj * M_PI_2) + c + b; -} - -/** - * Easing equation function for a sinusoidal (sin(t)) easing out: decelerating from zero velocity. - * - * @param t Current time (in frames or seconds). - * @param b Starting value. - * @param c Change needed in value. - * @param d Expected easing duration (in frames or seconds). - * @return The correct value. - */ -static float easeOutSine(float t, float b, float c, float d) -{ - float t_adj = (float)t/(float)d; - return c * ::sin(t_adj * M_PI_2) + b; -} - -/** - * Easing equation function for a sinusoidal (sin(t)) easing in/out: acceleration until halfway, then deceleration. - * - * @param t Current time (in frames or seconds). - * @param b Starting value. - * @param c Change needed in value. - * @param d Expected easing duration (in frames or seconds). - * @return The correct value. - */ -static float easeInOutSine(float t, float b, float c, float d) -{ - float t_adj = (float)t/(float)d; - return -c/2 * (::cos(M_PI*t_adj) - 1) + b; -} - -/** - * Easing equation function for a sinusoidal (sin(t)) easing out/in: deceleration until halfway, then acceleration. - * - * @param t Current time (in frames or seconds). - * @param b Starting value. - * @param c Change needed in value. - * @param d Expected easing duration (in frames or seconds). - * @return The correct value. - */ -static float easeOutInSine(float t, float b, float c, float d) -{ - if (t < d/2) return easeOutSine (t*2, b, c/2, d); - return easeInSine((t*2)-d, b+c/2, c/2, d); -} - -/** - * Easing equation function for an exponential (2^t) easing in: accelerating from zero velocity. - * - * @param t Current time (in frames or seconds). - * @param b Starting value. - * @param c Change needed in value. - * @param d Expected easing duration (in frames or seconds). - * @return The correct value. - */ -static float easeInExpo(float t, float b, float c, float d) -{ - return (t==0) ? b : c * ::pow(2, 10 * ((float)t/(float)d - 1)) + b - c * 0.001; -} - -/** - * Easing equation function for an exponential (2^t) easing out: decelerating from zero velocity. - * - * @param t Current time (in frames or seconds). - * @param b Starting value. - * @param c Change needed in value. - * @param d Expected easing duration (in frames or seconds). - * @return The correct value. - */ -static float easeOutExpo(float t, float b, float c, float d) -{ - return (t==d) ? b+c : c * 1.001 * (-::pow(2, -10 * (float)t/(float)d) + 1) + b; -} - -/** - * Easing equation function for an exponential (2^t) easing in/out: acceleration until halfway, then deceleration. - * - * @param t Current time (in frames or seconds). - * @param b Starting value. - * @param c Change needed in value. - * @param d Expected easing duration (in frames or seconds). - * @return The correct value. - */ -static float easeInOutExpo(float t, float b, float c, float d) -{ - if (t==0) return b; - if (t==d) return b+c; - float t_adj = 2.0f * (float)t/(float)d; - if (t_adj < 1) return c/2 * ::pow(2, 10 * (t_adj - 1)) + b - c * 0.0005; - return c/2 * 1.0005 * (-::pow(2, -10 * (t_adj - 1)) + 2) + b; -} - -/** - * Easing equation function for an exponential (2^t) easing out/in: deceleration until halfway, then acceleration. - * - * @param t Current time (in frames or seconds). - * @param b Starting value. - * @param c Change needed in value. - * @param d Expected easing duration (in frames or seconds). - * @return The correct value. - */ -static float easeOutInExpo(float t, float b, float c, float d) -{ - if (t < d/2) return easeOutExpo (t*2, b, c/2, d); - return easeInExpo((t*2)-d, b+c/2, c/2, d); -} - -/** - * Easing equation function for a circular (sqrt(1-t^2)) easing in: accelerating from zero velocity. - * - * @param t Current time (in frames or seconds). - * @param b Starting value. - * @param c Change needed in value. - * @param d Expected easing duration (in frames or seconds). - * @return The correct value. - */ -static float easeInCirc(float t, float b, float c, float d) -{ - float t_adj = (float)t / (float)d; - return -c * (::sqrt(1 - t_adj*t_adj) - 1) + b; -} - -/** - * Easing equation function for a circular (sqrt(1-t^2)) easing out: decelerating from zero velocity. - * - * @param t Current time (in frames or seconds). - * @param b Starting value. - * @param c Change needed in value. - * @param d Expected easing duration (in frames or seconds). - * @return The correct value. - */ -static float easeOutCirc(float t, float b, float c, float d) -{ - float t_adj = (float)t / (float)d - 1.0f; - return c * ::sqrt(1 - t_adj * t_adj) + b; -} - -/** - * Easing equation function for a circular (sqrt(1-t^2)) easing in/out: acceleration until halfway, then deceleration. - * - * @param t Current time (in frames or seconds). - * @param b Starting value. - * @param c Change needed in value. - * @param d Expected easing duration (in frames or seconds). - * @return The correct value. - */ -static float easeInOutCirc(float t, float b, float c, float d) -{ - float t_adj = 2.0f * (float)t / (float)d; - if (t_adj < 1) return -c/2 * (::sqrt(1 - t_adj*t_adj) - 1) + b; - else { - t_adj -= 2.0f; - return c/2 * (::sqrt(1 - t_adj*t_adj) + 1) + b; - } -} - -/** - * Easing equation function for a circular (sqrt(1-t^2)) easing out/in: deceleration until halfway, then acceleration. - * - * @param t Current time (in frames or seconds). - * @param b Starting value. - * @param c Change needed in value. - * @param d Expected easing duration (in frames or seconds). - * @return The correct value. - */ -static float easeOutInCirc(float t, float b, float c, float d) -{ - if (t < d/2) return easeOutCirc (t*2, b, c/2, d); - return easeInCirc((t*2)-d, b+c/2, c/2, d); -} - -/** - * Easing equation function for an elastic (exponentially decaying sine wave) easing in: accelerating from zero velocity. - * - * @param t Current time (in frames or seconds). - * @param b Starting value. - * @param c Change needed in value. - * @param d Expected easing duration (in frames or seconds). - * @param a Amplitude. - * @param p Period. - * @return The correct value. - */ -static float easeInElastic(float t, float b, float c, float d) -{ - if (t==0) return b; - float t_adj = (float)t / (float)d; - if (t_adj==1) return b+c; - - qreal p = d * 0.3f; - qreal a = c; - qreal s = p / 4.0f; - - t_adj -= 1.0f; - return -(a*::pow(2,10*t_adj) * ::sin( (t_adj*d-s)*(2*M_PI)/p )) + b; -} - -/** - * Easing equation function for an elastic (exponentially decaying sine wave) easing out: decelerating from zero velocity. - * - * @param t Current time (in frames or seconds). - * @param b Starting value. - * @param c Change needed in value. - * @param d Expected easing duration (in frames or seconds). - * @param a Amplitude. - * @param p Period. - * @return The correct value. - */ -static float easeOutElastic(float t, float b, float c, float d) -{ - if (t==0) return b; - float t_adj = (float)t / (float)d; - if (t_adj==1) return b+c; - - qreal p = d * 0.3f; - qreal a = c; - qreal s = p / 4; - - return (a*::pow(2,-10*t_adj) * ::sin( (t_adj*d-s)*(2*M_PI)/p ) + c + b); -} - -/** - * Easing equation function for an elastic (exponentially decaying sine wave) easing in/out: acceleration until halfway, then deceleration. - * - * @param t Current time (in frames or seconds). - * @param b Starting value. - * @param c Change needed in value. - * @param d Expected easing duration (in frames or seconds). - * @param a Amplitude. - * @param p Period. - * @return The correct value. - */ -static float easeInOutElastic(float t, float b, float c, float d) -{ - if (t==0) return b; - float t_adj = 2.0f * (float)t / (float)d; - if (t_adj==2) return b+c; - - // XXX - qreal p = d * 0.3f * 1.5f; - qreal a = c; - qreal s = p / 4; - - if (t_adj < 1) return -.5*(a*::pow(2,10*(t_adj-1)) * ::sin( ((t_adj-1)*d-s)*(2*M_PI)/p )) + b; - return a*::pow(2,-10*(t_adj-1)) * ::sin( ((t_adj-1)*d-s)*(2*M_PI)/p )*.5 + c + b; -} - -/** - * Easing equation function for an elastic (exponentially decaying sine wave) easing out/in: deceleration until halfway, then acceleration. - * - * @param t Current time (in frames or seconds). - * @param b Starting value. - * @param c Change needed in value. - * @param d Expected easing duration (in frames or seconds). - * @param a Amplitude. - * @param p Period. - * @return The correct value. - */ -static float easeOutInElastic(float t, float b, float c, float d) -{ - if (t < d/2) return easeOutElastic (t*2, b, c/2, d); - return easeInElastic((t*2)-d, b+c/2, c/2, d); -} - -/** - * Easing equation function for a back (overshooting cubic easing: (s+1)*t^3 - s*t^2) easing in: accelerating from zero velocity. - * - * @param t Current time (in frames or seconds). - * @param b Starting value. - * @param c Change needed in value. - * @param d Expected easing duration (in frames or seconds). - * @param s Overshoot ammount: higher s means greater overshoot (0 produces cubic easing with no overshoot, and the default value of 1.70158 produces an overshoot of 10 percent). - * @return The correct value. - */ -static float easeInBack(float t, float b, float c, float d) -{ - // XXX - qreal s = 1.70158; - - float t_adj = (float)t / (float)d; - return c*(t_adj)*t_adj*((s+1)*t_adj - s) + b; -} - -/** - * Easing equation function for a back (overshooting cubic easing: (s+1)*t^3 - s*t^2) easing out: decelerating from zero velocity. - * - * @param t Current time (in frames or seconds). - * @param b Starting value. - * @param c Change needed in value. - * @param d Expected easing duration (in frames or seconds). - * @param s Overshoot ammount: higher s means greater overshoot (0 produces cubic easing with no overshoot, and the default value of 1.70158 produces an overshoot of 10 percent). - * @return The correct value. - */ -static float easeOutBack(float t, float b, float c, float d) -{ - // XXX - qreal s = 1.70158; - - float t_adj = (float)t / (float)d - 1.0f; - return c*(t_adj*t_adj*((s+1)*t_adj + s) + 1) + b; -} - -/** - * Easing equation function for a back (overshooting cubic easing: (s+1)*t^3 - s*t^2) easing in/out: acceleration until halfway, then deceleration. - * - * @param t Current time (in frames or seconds). - * @param b Starting value. - * @param c Change needed in value. - * @param d Expected easing duration (in frames or seconds). - * @param s Overshoot ammount: higher s means greater overshoot (0 produces cubic easing with no overshoot, and the default value of 1.70158 produces an overshoot of 10 percent). - * @return The correct value. - */ -static float easeInOutBack(float t, float b, float c, float d) -{ - // XXX - qreal s = 1.70158; - - float t_adj = 2.0f * (float)t / (float)d; - if (t_adj < 1) { - s *= 1.525f; - return c/2*(t_adj*t_adj*((s+1)*t_adj - s)) + b; - } else { - t_adj -= 2; - s *= 1.525f; - return c/2*(t_adj*t_adj*((s+1)*t_adj + s) + 2) + b; - } -} - -/** - * Easing equation function for a back (overshooting cubic easing: (s+1)*t^3 - s*t^2) easing out/in: deceleration until halfway, then acceleration. - * - * @param t Current time (in frames or seconds). - * @param b Starting value. - * @param c Change needed in value. - * @param d Expected easing duration (in frames or seconds). - * @param s Overshoot ammount: higher s means greater overshoot (0 produces cubic easing with no overshoot, and the default value of 1.70158 produces an overshoot of 10 percent). - * @return The correct value. - */ -static float easeOutInBack(float t, float b, float c, float d) -{ - if (t < d/2) return easeOutBack (t*2, b, c/2, d); - return easeInBack((t*2)-d, b+c/2, c/2, d); -} - -/** - * Easing equation function for a bounce (exponentially decaying parabolic bounce) easing out: decelerating from zero velocity. - * - * @param t Current time (in frames or seconds). - * @param b Starting value. - * @param c Change needed in value. - * @param d Expected easing duration (in frames or seconds). - * @return The correct value. - */ -static float easeOutBounce(float t, float b, float c, float d) -{ - float t_adj = (float)t / (float)d; - if ((t_adj) < (1/2.75)) { - return c*(7.5625*t_adj*t_adj) + b; - } else if (t_adj < (2/2.75)) { - t_adj -= (1.5f/2.75f); - return c*(7.5625*t_adj*t_adj + .75) + b; - } else if (t_adj < (2.5/2.75)) { - t_adj -= (2.25f/2.75f); - return c*(7.5625*t_adj*t_adj + .9375) + b; - } else { - t_adj -= (2.65f/2.75f); - return c*(7.5625*t_adj*t_adj + .984375) + b; - } -} - -/** - * Easing equation function for a bounce (exponentially decaying parabolic bounce) easing in: accelerating from zero velocity. - * - * @param t Current time (in frames or seconds). - * @param b Starting value. - * @param c Change needed in value. - * @param d Expected easing duration (in frames or seconds). - * @return The correct value. - */ -static float easeInBounce(float t, float b, float c, float d) -{ - return c - easeOutBounce (d-t, 0, c, d) + b; -} - - -/** - * Easing equation function for a bounce (exponentially decaying parabolic bounce) easing in/out: acceleration until halfway, then deceleration. - * - * @param t Current time (in frames or seconds). - * @param b Starting value. - * @param c Change needed in value. - * @param d Expected easing duration (in frames or seconds). - * @return The correct value. - */ -static float easeInOutBounce(float t, float b, float c, float d) -{ - if (t < d/2) return easeInBounce (t*2, 0, c, d) * .5 + b; - else return easeOutBounce (t*2-d, 0, c, d) * .5 + c*.5 + b; -} - -/** - * Easing equation function for a bounce (exponentially decaying parabolic bounce) easing out/in: deceleration until halfway, then acceleration. - * - * @param t Current time (in frames or seconds). - * @param b Starting value. - * @param c Change needed in value. - * @param d Expected easing duration (in frames or seconds). - * @return The correct value. - */ -static float easeOutInBounce(float t, float b, float c, float d) -{ - if (t < d/2) return easeOutBounce (t*2, b, c/2, d); - return easeInBounce((t*2)-d, b+c/2, c/2, d); -} - diff --git a/src/declarative/3rdparty/legal.qdoc b/src/declarative/3rdparty/legal.qdoc deleted file mode 100644 index bd0a9b2..0000000 --- a/src/declarative/3rdparty/legal.qdoc +++ /dev/null @@ -1,35 +0,0 @@ -/*! -\page legal-easing.html -\title easing -\ingroup qtopia3rdparty -Easing Equations by Robert Penner. -\legalese -\code -Copyright (c) 2001 Robert Penner -All rights reserved. - -Redistribution and use in source and binary forms, with or without modification, -are permitted provided that the following conditions are met: - - * Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - * Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. - * Neither the name of the author nor the names of contributors may be used - to endorse or promote products derived from this software without specific - prior written permission. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND -ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED -WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR -ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES -(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; -LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON -ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS -SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -\endcode -\endlegalese -*/ diff --git a/src/declarative/canvas/qsimplecanvasitem.h b/src/declarative/canvas/qsimplecanvasitem.h index 9b010e8..83f19c3 100644 --- a/src/declarative/canvas/qsimplecanvasitem.h +++ b/src/declarative/canvas/qsimplecanvasitem.h @@ -42,7 +42,6 @@ #ifndef QSIMPLECANVASITEM_H #define QSIMPLECANVASITEM_H -#include #include #include #include diff --git a/src/declarative/fx/qfxflickable.cpp b/src/declarative/fx/qfxflickable.cpp index 5715116..4cd7e88 100644 --- a/src/declarative/fx/qfxflickable.cpp +++ b/src/declarative/fx/qfxflickable.cpp @@ -43,7 +43,6 @@ #include "qfxflickable_p.h" #include -#include #include #include @@ -128,11 +127,11 @@ void QFxFlickablePrivate::fixupX() vTime = _tl.time(); if(_moveX.value() > q->minXExtent() || q->maxXExtent() > 0) { - _tl.move(_moveX, q->minXExtent(), GfxEasing(GfxEasing::InOutQuad), 200); + _tl.move(_moveX, q->minXExtent(), QEasingCurve(QEasingCurve::InOutQuad), 200); flicked = false; //emit flickingChanged(); } else if(_moveX.value() < q->maxXExtent()) { - _tl.move(_moveX, q->maxXExtent(), GfxEasing(GfxEasing::InOutQuad), 200); + _tl.move(_moveX, q->maxXExtent(), QEasingCurve(QEasingCurve::InOutQuad), 200); flicked = false; //emit flickingChanged(); } @@ -147,10 +146,10 @@ void QFxFlickablePrivate::fixupY() vTime = _tl.time(); if(_moveY.value() > q->minYExtent() || (q->maxYExtent() > q->minYExtent())) { - _tl.move(_moveY, q->minYExtent(), GfxEasing(GfxEasing::InOutQuad), 200); + _tl.move(_moveY, q->minYExtent(), QEasingCurve(QEasingCurve::InOutQuad), 200); //emit flickingChanged(); } else if(_moveY.value() < q->maxYExtent()) { - _tl.move(_moveY, q->maxYExtent(), GfxEasing(GfxEasing::InOutQuad), 200); + _tl.move(_moveY, q->maxYExtent(), QEasingCurve(QEasingCurve::InOutQuad), 200); //emit flickingChanged(); } else { flicked = false; diff --git a/src/declarative/fx/qfxlistview.cpp b/src/declarative/fx/qfxlistview.cpp index 3c8c12c..f25470b 100644 --- a/src/declarative/fx/qfxlistview.cpp +++ b/src/declarative/fx/qfxlistview.cpp @@ -43,7 +43,6 @@ #include "qmlfollow.h" #include "qlistmodelinterface.h" #include "qfxvisualitemmodel.h" -#include "gfxeasing.h" #include "qfxlistview.h" #include @@ -749,7 +748,7 @@ void QFxListViewPrivate::fixupY() if (currentItem) { moveReason = Mouse; _tl.clear(); - _tl.move(_moveY, -(currentItem->position() - snapPos), GfxEasing(GfxEasing::InOutQuad), 200); + _tl.move(_moveY, -(currentItem->position() - snapPos), QEasingCurve(QEasingCurve::InOutQuad), 200); } } else if (currItemMode == QFxListView::Snap) { moveReason = Mouse; @@ -761,7 +760,7 @@ void QFxListViewPrivate::fixupY() else if (pos < -q->minYExtent()) pos = -q->minYExtent(); _tl.clear(); - _tl.move(_moveY, -(pos), GfxEasing(GfxEasing::InOutQuad), 200); + _tl.move(_moveY, -(pos), QEasingCurve(QEasingCurve::InOutQuad), 200); } } } @@ -775,7 +774,7 @@ void QFxListViewPrivate::fixupX() if (currItemMode == QFxListView::SnapAuto) { moveReason = Mouse; _tl.clear(); - _tl.move(_moveX, -(currentItem->position() - snapPos), GfxEasing(GfxEasing::InOutQuad), 200); + _tl.move(_moveX, -(currentItem->position() - snapPos), QEasingCurve(QEasingCurve::InOutQuad), 200); } else if (currItemMode == QFxListView::Snap) { moveReason = Mouse; int idx = snapIndex(); @@ -786,7 +785,7 @@ void QFxListViewPrivate::fixupX() else if (pos < -q->minXExtent()) pos = -q->minXExtent(); _tl.clear(); - _tl.move(_moveX, -(pos), GfxEasing(GfxEasing::InOutQuad), 200); + _tl.move(_moveX, -(pos), QEasingCurve(QEasingCurve::InOutQuad), 200); } } } diff --git a/src/declarative/fx/qfxparticles.cpp b/src/declarative/fx/qfxparticles.cpp index 9319c46..54e3778 100644 --- a/src/declarative/fx/qfxparticles.cpp +++ b/src/declarative/fx/qfxparticles.cpp @@ -39,7 +39,6 @@ ** ****************************************************************************/ -#include "gfxtimeline.h" #include "qfxitem_p.h" #if defined(QFX_RENDER_OPENGL) #include "gltexture.h" diff --git a/src/declarative/fx/qfxpathview.cpp b/src/declarative/fx/qfxpathview.cpp index 99f6e86..f2a9065 100644 --- a/src/declarative/fx/qfxpathview.cpp +++ b/src/declarative/fx/qfxpathview.cpp @@ -43,7 +43,6 @@ #include #include #include -#include #include "qmlbindablevalue.h" #include "qmlstate.h" #include "qlistmodelinterface.h" @@ -805,7 +804,7 @@ void QFxPathViewPrivate::snapToCurrent() rounds--; if(distance > 50) rounds++; - tl.move(moveOffset, targetOffset + 100.0*(-rounds), GfxEasing(GfxEasing::InOutQuad), + tl.move(moveOffset, targetOffset + 100.0*(-rounds), QEasingCurve(QEasingCurve::InOutQuad), int(100*items.count()*qMax((qreal)(2.0/items.count()),(qreal)qAbs(rounds)))); tl.execute(fixupOffsetEvent); return; @@ -813,16 +812,16 @@ void QFxPathViewPrivate::snapToCurrent() if (targetOffset - _offset > 50.0) { qreal distance = 100 - targetOffset + _offset; - tl.move(moveOffset, 0.0, GfxEasing(GfxEasing::OutQuad), int(200 * _offset / distance)); + tl.move(moveOffset, 0.0, QEasingCurve(QEasingCurve::OutQuad), int(200 * _offset / distance)); tl.set(moveOffset, 100.0); - tl.move(moveOffset, targetOffset, GfxEasing(GfxEasing::InQuad), int(200 * (100-targetOffset) / distance)); + tl.move(moveOffset, targetOffset, QEasingCurve(QEasingCurve::InQuad), int(200 * (100-targetOffset) / distance)); } else if (targetOffset - _offset <= -50.0) { qreal distance = 100 - _offset + targetOffset; - tl.move(moveOffset, 100.0, GfxEasing(GfxEasing::OutQuad), int(200 * (100-_offset) / distance)); + tl.move(moveOffset, 100.0, QEasingCurve(QEasingCurve::OutQuad), int(200 * (100-_offset) / distance)); tl.set(moveOffset, 0.0); - tl.move(moveOffset, targetOffset, GfxEasing(GfxEasing::InQuad), int(200 * targetOffset / distance)); + tl.move(moveOffset, targetOffset, QEasingCurve(QEasingCurve::InQuad), int(200 * targetOffset / distance)); } else { - tl.move(moveOffset, targetOffset, GfxEasing(GfxEasing::InOutQuad), 200); + tl.move(moveOffset, targetOffset, QEasingCurve(QEasingCurve::InOutQuad), 200); } } diff --git a/src/declarative/qml/qmlbindablevalue.cpp b/src/declarative/qml/qmlbindablevalue.cpp index 423fda8..c2632da 100644 --- a/src/declarative/qml/qmlbindablevalue.cpp +++ b/src/declarative/qml/qmlbindablevalue.cpp @@ -41,9 +41,7 @@ #include #include "qmlbindablevalue.h" -#include #include -#include #include #include #include diff --git a/src/declarative/test/qfxtestengine.cpp b/src/declarative/test/qfxtestengine.cpp index 96ce451..d9e3533 100644 --- a/src/declarative/test/qfxtestengine.cpp +++ b/src/declarative/test/qfxtestengine.cpp @@ -41,7 +41,7 @@ #include #include -#include +#include #include "qfxtestengine.h" #include "qfxtestobjects.h" #include diff --git a/src/declarative/timeline/gfxeasing.cpp b/src/declarative/timeline/gfxeasing.cpp deleted file mode 100644 index 45b84eb..0000000 --- a/src/declarative/timeline/gfxeasing.cpp +++ /dev/null @@ -1,811 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** Contact: Qt Software Information (qt-info@nokia.com) -** -** This file is part of the QtDeclarative module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the either Technology Preview License Agreement or the -** Beta Release License Agreement. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain -** additional rights. These rights are described in the Nokia Qt LGPL -** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this -** package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3.0 as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU General Public License version 3.0 requirements will be -** met: http://www.gnu.org/copyleft/gpl.html. -** -** If you are unsure which license is appropriate for your use, please -** contact the sales department at qt-sales@nokia.com. -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "gfxeasing.h" -#include -#include -#include -#include -#include -#include -#include -#include "gfxtimeline.h" - - -QT_BEGIN_NAMESPACE -typedef QHash GfxEasingProperties; -class GfxEasingFunction -{ -public: - virtual ~GfxEasingFunction() {} - virtual float value(float t, float b, float c, float d) = 0; - virtual GfxEasingFunction *copy() const = 0; -}; - -#include "../3rdparty/easing.cpp" - -struct ElasticEase : public GfxEasingFunction -{ - enum Type { In, Out }; - ElasticEase(Type t) : _t(t), _p(0.0f), _a(0.0f) {} - - Type _t; - qreal _p; - qreal _a; - - GfxEasingFunction *copy() const - { - ElasticEase *rv = new ElasticEase(_t); - rv->_p = _p; - rv->_a = _a; - return rv; - } - - float value(float t, float b, float c, float d) - { - if (t==0) return b; - float t_adj = (float)t / (float)d; - if (t_adj==1) return b+c; - - qreal p = _p?_p:(d * 0.3f); - - qreal a; - qreal s; - - if(!_a || _a < ::fabs(c)) { - a = c; - s = p / 4.0f; - } else { - a = _a; - s = p / (2 * M_PI) * ::asin(c / a); - } - - if(_t == In) - t_adj -= 1.0f; - - return (a*::pow(2,-10*t_adj) * ::sin( (t_adj*d-s)*(2*M_PI)/p ) + c + b); - } -}; - -struct BounceEase : public GfxEasingFunction -{ - enum Type { In, Out }; - BounceEase(Type t) : _t(t), _a(-1.0) {} - - Type _t; - qreal _a; - - GfxEasingFunction *copy() const - { - BounceEase *rv = new BounceEase(_t); - rv->_t = _t; - rv->_a = _a; - return rv; - } - - float value(float t, float b, float c, float d) - { - if(In == _t) - return c - bounce(d - t, 0, c, d) + b; - else - return bounce(t, b, c, d); - } - - float bounce(float t, float b, float c, float d) - { - float t_adj = (float)t / (float)d; - float amp = (_a == -1.0)?c:_a; - if ((t_adj) < (1/2.75)) { - if(c == 0. && _a != -1.0) { - t_adj -= (0.5f/2.75f); - return -amp * (1. - (30.25*t_adj*t_adj)) + b; - } else { - return c*(7.5625*t_adj*t_adj) + b; - } - } else if (t_adj < (2/2.75)) { - t_adj -= (1.5f/2.75f); - return -amp * (1. - (7.5625*t_adj*t_adj + .75)) + (b + c); - } else if (t_adj < (2.5/2.75)) { - t_adj -= (2.25f/2.75f); - return -amp * (1. - (7.5625*t_adj*t_adj + .9375)) + (b + c); - } else { - t_adj -= (2.65f/2.75f); - return -amp * (1. - (7.5625*t_adj*t_adj + .984375)) + (b + c); - } - } -}; - -static GfxEasingFunction *easeInElasticC(const GfxEasingProperties &p) -{ - ElasticEase *rv = new ElasticEase(ElasticEase::In); - rv->_p = p[QLatin1String("period")]; - rv->_a = p[QLatin1String("amplitude")]; - return rv; -} - - -static GfxEasingFunction *easeOutElasticC(const GfxEasingProperties &p) -{ - ElasticEase *rv = new ElasticEase(ElasticEase::Out); - rv->_p = p[QLatin1String("period")]; - rv->_a = p[QLatin1String("amplitude")]; - return rv; -} - -static GfxEasingFunction *easeOutBounceC(const GfxEasingProperties &p) -{ - BounceEase *rv = new BounceEase(BounceEase::Out); - rv->_a = p[QLatin1String("amplitude")]; - return rv; -} - -static GfxEasingFunction *easeInBounceC(const GfxEasingProperties &p) -{ - BounceEase *rv = new BounceEase(BounceEase::Out); - rv->_a = p[QLatin1String("amplitude")]; - return rv; -} - - -struct SimpleConfig : public GfxEasingFunction -{ - GfxEasing::Function func; - - float value(float t, float b, float c, float d) - { - return func(t, b, c, d); - } - - GfxEasingFunction *copy() const - { - SimpleConfig *rv = new SimpleConfig; - rv->func = func; - return rv; - } -}; - -GfxEasing::Function curveToFunc(GfxEasing::Curve curve) -{ - switch(curve) - { - case GfxEasing::None: - return &easeNone; - case GfxEasing::InQuad: - return &easeInQuad; - case GfxEasing::OutQuad: - return &easeOutQuad; - case GfxEasing::InOutQuad: - return &easeInOutQuad; - case GfxEasing::OutInQuad: - return &easeOutInQuad; - case GfxEasing::InCubic: - return &easeInCubic; - case GfxEasing::OutCubic: - return &easeOutCubic; - case GfxEasing::InOutCubic: - return &easeInOutCubic; - case GfxEasing::OutInCubic: - return &easeOutInCubic; - case GfxEasing::InQuart: - return &easeInQuart; - case GfxEasing::OutQuart: - return &easeOutQuart; - case GfxEasing::InOutQuart: - return &easeInOutQuart; - case GfxEasing::OutInQuart: - return &easeOutInQuart; - case GfxEasing::InQuint: - return &easeInQuint; - case GfxEasing::OutQuint: - return &easeOutQuint; - case GfxEasing::InOutQuint: - return &easeInOutQuint; - case GfxEasing::OutInQuint: - return &easeOutInQuint; - case GfxEasing::InSine: - return &easeInSine; - case GfxEasing::OutSine: - return &easeOutSine; - case GfxEasing::InOutSine: - return &easeInOutSine; - case GfxEasing::OutInSine: - return &easeOutInSine; - case GfxEasing::InExpo: - return &easeInExpo; - case GfxEasing::OutExpo: - return &easeOutExpo; - case GfxEasing::InOutExpo: - return &easeInOutExpo; - case GfxEasing::OutInExpo: - return &easeOutInExpo; - case GfxEasing::InCirc: - return &easeInCirc; - case GfxEasing::OutCirc: - return &easeOutCirc; - case GfxEasing::InOutCirc: - return &easeInOutCirc; - case GfxEasing::OutInCirc: - return &easeOutInCirc; - case GfxEasing::InElastic: - return &easeInElastic; - case GfxEasing::OutElastic: - return &easeOutElastic; - case GfxEasing::InOutElastic: - return &easeInOutElastic; - case GfxEasing::OutInElastic: - return &easeOutInElastic; - case GfxEasing::InBack: - return &easeInBack; - case GfxEasing::OutBack: - return &easeOutBack; - case GfxEasing::InOutBack: - return &easeInOutBack; - case GfxEasing::OutInBack: - return &easeOutInBack; - case GfxEasing::InBounce: - return &easeInBounce; - case GfxEasing::OutBounce: - return &easeOutBounce; - case GfxEasing::InOutBounce: - return &easeInOutBounce; - case GfxEasing::OutInBounce: - return &easeOutInBounce; - default: - return 0; - }; -} - -struct NameFunctionMap : public QHash -{ - NameFunctionMap() - { - insert(QLatin1String("easeNone"), easeNone); - insert(QLatin1String("easeInQuad"), easeInQuad); - insert(QLatin1String("easeOutQuad"), easeOutQuad); - insert(QLatin1String("easeInOutQuad"), easeInOutQuad); - insert(QLatin1String("easeOutInQuad"), easeOutInQuad); - insert(QLatin1String("easeInCubic"), easeInCubic); - insert(QLatin1String("easeOutCubic"), easeOutCubic); - insert(QLatin1String("easeInOutCubic"), easeInOutCubic); - insert(QLatin1String("easeOutInCubic"), easeOutInCubic); - insert(QLatin1String("easeInQuart"), easeInQuart); - insert(QLatin1String("easeOutQuart"), easeOutQuart); - insert(QLatin1String("easeInOutQuart"), easeInOutQuart); - insert(QLatin1String("easeOutInQuart"), easeOutInQuart); - insert(QLatin1String("easeInQuint"), easeInQuint); - insert(QLatin1String("easeOutQuint"), easeOutQuint); - insert(QLatin1String("easeInOutQuint"), easeInOutQuint); - insert(QLatin1String("easeOutInQuint"), easeOutInQuint); - insert(QLatin1String("easeInSine"), easeInSine); - insert(QLatin1String("easeOutSine"), easeOutSine); - insert(QLatin1String("easeInOutSine"), easeInOutSine); - insert(QLatin1String("easeOutInSine"), easeOutInSine); - insert(QLatin1String("easeInExpo"), easeInExpo); - insert(QLatin1String("easeOutExpo"), easeOutExpo); - insert(QLatin1String("easeInOutExpo"), easeInOutExpo); - insert(QLatin1String("easeOutInExpo"), easeOutInExpo); - insert(QLatin1String("easeInCirc"), easeInCirc); - insert(QLatin1String("easeOutCirc"), easeOutCirc); - insert(QLatin1String("easeInOutCirc"), easeInOutCirc); - insert(QLatin1String("easeOutInCirc"), easeOutInCirc); - insert(QLatin1String("easeInElastic"), easeInElastic); - insert(QLatin1String("easeOutElastic"), easeOutElastic); - insert(QLatin1String("easeInOutElastic"), easeInOutElastic); - insert(QLatin1String("easeOutInElastic"), easeOutInElastic); - insert(QLatin1String("easeInBack"), easeInBack); - insert(QLatin1String("easeOutBack"), easeOutBack); - insert(QLatin1String("easeInOutBack"), easeInOutBack); - insert(QLatin1String("easeOutInBack"), easeOutInBack); - insert(QLatin1String("easeInBounce"), easeInBounce); - insert(QLatin1String("easeOutBounce"), easeOutBounce); - insert(QLatin1String("easeInOutBounce"), easeInOutBounce); - insert(QLatin1String("easeOutInBounce"), easeOutInBounce); - } -}; -Q_GLOBAL_STATIC(NameFunctionMap, nameFunctionMap); - -typedef GfxEasingFunction *(*ConfigurableFunction)(const GfxEasingProperties &); -struct ConfigFunctionMap : public QHash -{ - ConfigFunctionMap() - { - insert(QLatin1String("easeInElastic"), easeInElasticC); - insert(QLatin1String("easeOutElastic"), easeOutElasticC); - insert(QLatin1String("easeInBounce"), easeInBounceC); - insert(QLatin1String("easeOutBounce"), easeOutBounceC); - } -}; -Q_GLOBAL_STATIC(ConfigFunctionMap, configFunctionMap); - -/*! - \class GfxEasing - \ingroup group_animation - \brief The GfxEasing class provides easing curves for controlling animation. - - Easing curves describe a function that controls how a value changes over - time. Easing curves allow transitions from one value to another to appear - more natural than a simple linear motion would allow. The GfxEasing class - is usually used in conjunction with the GfxTimeLine class, but can be used - on its own. - - To calculate the value at a given time, the easing curve function requires - the starting value, the final value and the total time to change from the - starting to the final value. When using the GfxEasing class with - GfxTimeLine, these values are supplied by the GfxTimeLine. When using - the GfxEasing class on its own, the programmer must specify them using - the GfxEasing::setFrom(), GfxEasing::setTo() and GfxEasing::setLength() - methods, or by passing them explicitly to the GfxEasing::valueAt() method. - - For example, - \code - GfxEasing easing(GfxEasing::InOutQuad); - easing.setFrom(0); - easing.setTo(1000); - easing.setLength(1000); - - for(int milliseconds = 0; milliseconds < 1000; ++milliseconds) - qWarning() << "Value at" << milliseconds << "milliseconds is - << easing.valueAt(milliseconds); - \endcode - will print the value at each millisecond for an InOutQuad transition from - 0 to 1000 over 1 second. - - When using a GfxTimeLine, the values are communicated implicitly. - \code - GfxTimeLine timeline; - GfxValue value(0); - - timeline.move(value, 1000, GfxEasing(GfxEasing::InOutQuad), 1000); - \endcode - In this case, any values set using the previous setter methods would be - ignored. - */ - -/*! - \qmlproperty string NumericAnimation::easing - \brief the easing curve used for the transition. - - Available values are: - - \list - \i \e easeNone - Easing equation function for a simple linear tweening, with no easing. - \i \e easeInQuad - Easing equation function for a quadratic (t^2) easing in: accelerating from zero velocity. - \i \e easeOutQuad - Easing equation function for a quadratic (t^2) easing out: decelerating to zero velocity. - \i \e easeInOutQuad - Easing equation function for a quadratic (t^2) easing in/out: acceleration until halfway, then deceleration. - \i \e easeOutInQuad - Easing equation function for a quadratic (t^2) easing out/in: deceleration until halfway, then acceleration. - \i \e easeInCubic - Easing equation function for a cubic (t^3) easing in: accelerating from zero velocity. - \i \e easeOutCubic - Easing equation function for a cubic (t^3) easing out: decelerating from zero velocity. - \i \e easeInOutCubic - Easing equation function for a cubic (t^3) easing in/out: acceleration until halfway, then deceleration. - \i \e easeOutInCubic - Easing equation function for a cubic (t^3) easing out/in: deceleration until halfway, then acceleration. - \i \e easeInQuart - Easing equation function for a quartic (t^4) easing in: accelerating from zero velocity. - \i \e easeOutQuart - Easing equation function for a quartic (t^4) easing out: decelerating from zero velocity. - \i \e easeInOutQuart - Easing equation function for a quartic (t^4) easing in/out: acceleration until halfway, then deceleration. - \i \e easeOutInQuart - Easing equation function for a quartic (t^4) easing out/in: deceleration until halfway, then acceleration. - \i \e easeInQuint - Easing equation function for a quintic (t^5) easing in: accelerating from zero velocity. - \i \e easeOutQuint - Easing equation function for a quintic (t^5) easing out: decelerating from zero velocity. - \i \e easeInOutQuint - Easing equation function for a quintic (t^5) easing in/out: acceleration until halfway, then deceleration. - \i \e easeOutInQuint - Easing equation function for a quintic (t^5) easing out/in: deceleration until halfway, then acceleration. - \i \e easeInSine - Easing equation function for a sinusoidal (sin(t)) easing in: accelerating from zero velocity. - \i \e easeOutSine - Easing equation function for a sinusoidal (sin(t)) easing out: decelerating from zero velocity. - \i \e easeInOutSine - Easing equation function for a sinusoidal (sin(t)) easing in/out: acceleration until halfway, then deceleration. - \i \e easeOutInSine - Easing equation function for a sinusoidal (sin(t)) easing out/in: deceleration until halfway, then acceleration. - \i \e easeInExpo - Easing equation function for an exponential (2^t) easing in: accelerating from zero velocity. - \i \e easeOutExpo - Easing equation function for an exponential (2^t) easing out: decelerating from zero velocity. - \i \e easeInOutExpo - Easing equation function for an exponential (2^t) easing in/out: acceleration until halfway, then deceleration. - \i \e easeOutInExpo - Easing equation function for an exponential (2^t) easing out/in: deceleration until halfway, then acceleration. - \i \e easeInCirc - Easing equation function for a circular (sqrt(1-t^2)) easing in: accelerating from zero velocity. - \i \e easeOutCirc - Easing equation function for a circular (sqrt(1-t^2)) easing out: decelerating from zero velocity. - \i \e easeInOutCirc - Easing equation function for a circular (sqrt(1-t^2)) easing in/out: acceleration until halfway, then deceleration. - \i \e easeOutInCirc - Easing equation function for a circular (sqrt(1-t^2)) easing out/in: deceleration until halfway, then acceleration. - \i \e easeInElastic - Easing equation function for an elastic (exponentially decaying sine wave) easing in: accelerating from zero velocity. The peak amplitude can be set with the \i amplitude parameter, and the period of decay by the \i period parameter. - \i \e easeOutElastic - Easing equation function for an elastic (exponentially decaying sine wave) easing out: decelerating from zero velocity. The peak amplitude can be set with the \i amplitude parameter, and the period of decay by the \i period parameter. - \i \e easeInOutElastic - Easing equation function for an elastic (exponentially decaying sine wave) easing in/out: acceleration until halfway, then deceleration. - \i \e easeOutInElastic - Easing equation function for an elastic (exponentially decaying sine wave) easing out/in: deceleration until halfway, then acceleration. - \i \e easeInBack - Easing equation function for a back (overshooting cubic easing: (s+1)*t^3 - s*t^2) easing in: accelerating from zero velocity. - \i \e easeOutBack - Easing equation function for a back (overshooting cubic easing: (s+1)*t^3 - s*t^2) easing out: decelerating from zero velocity. - \i \e easeInOutBack - Easing equation function for a back (overshooting cubic easing: (s+1)*t^3 - s*t^2) easing in/out: acceleration until halfway, then deceleration. - \i \e easeOutInBack - Easing equation function for a back (overshooting cubic easing: (s+1)*t^3 - s*t^2) easing out/in: deceleration until halfway, then acceleration. - \i \e easeOutBounce - Easing equation function for a bounce (exponentially decaying parabolic bounce) easing out: decelerating from zero velocity. - \i \e easeInBounce - Easing equation function for a bounce (exponentially decaying parabolic bounce) easing in: accelerating from zero velocity. - \i \e easeInOutBounce - Easing equation function for a bounce (exponentially decaying parabolic bounce) easing in/out: acceleration until halfway, then deceleration. - \i \e easeOutInBounce - Easing equation function for a bounce (exponentially decaying parabolic bounce) easing out/in: deceleration until halfway, then acceleration. - \endlist -*/ - -/*! - \enum GfxEasing::Curve - - The type of easing curve. - - \value None - Easing equation function for a simple linear tweening, with no easing. - - \value InQuad - Easing equation function for a quadratic (t^2) easing in: accelerating from zero velocity. - - \value OutQuad - Easing equation function for a quadratic (t^2) easing out: decelerating to zero velocity. - - \value InOutQuad - Easing equation function for a quadratic (t^2) easing in/out: acceleration until halfway, then deceleration. - - \value OutInQuad - Easing equation function for a quadratic (t^2) easing out/in: deceleration until halfway, then acceleration. - - \value InCubic - Easing equation function for a cubic (t^3) easing in: accelerating from zero velocity. - - \value OutCubic - Easing equation function for a cubic (t^3) easing out: decelerating from zero velocity. - - \value InOutCubic - Easing equation function for a cubic (t^3) easing in/out: acceleration until halfway, then deceleration. - - \value OutInCubic - Easing equation function for a cubic (t^3) easing out/in: deceleration until halfway, then acceleration. - - \value InQuart - Easing equation function for a quartic (t^4) easing in: accelerating from zero velocity. - - \value OutQuart - Easing equation function for a quartic (t^4) easing out: decelerating from zero velocity. - - \value InOutQuart - Easing equation function for a quartic (t^4) easing in/out: acceleration until halfway, then deceleration. - - \value OutInQuart - Easing equation function for a quartic (t^4) easing out/in: deceleration until halfway, then acceleration. - - \value InQuint - Easing equation function for a quintic (t^5) easing in: accelerating from zero velocity. - - \value OutQuint - Easing equation function for a quintic (t^5) easing out: decelerating from zero velocity. - - \value InOutQuint - Easing equation function for a quintic (t^5) easing in/out: acceleration until halfway, then deceleration. - - \value OutInQuint - Easing equation function for a quintic (t^5) easing out/in: deceleration until halfway, then acceleration. - - \value InSine - Easing equation function for a sinusoidal (sin(t)) easing in: accelerating from zero velocity. - - \value OutSine - Easing equation function for a sinusoidal (sin(t)) easing out: decelerating from zero velocity. - - \value InOutSine - Easing equation function for a sinusoidal (sin(t)) easing in/out: acceleration until halfway, then deceleration. - - \value OutInSine - Easing equation function for a sinusoidal (sin(t)) easing out/in: deceleration until halfway, then acceleration. - - \value InExpo - Easing equation function for an exponential (2^t) easing in: accelerating from zero velocity. - - \value OutExpo - Easing equation function for an exponential (2^t) easing out: decelerating from zero velocity. - - \value InOutExpo - Easing equation function for an exponential (2^t) easing in/out: acceleration until halfway, then deceleration. - - \value OutInExpo - Easing equation function for an exponential (2^t) easing out/in: deceleration until halfway, then acceleration. - - \value InCirc - Easing equation function for a circular (sqrt(1-t^2)) easing in: accelerating from zero velocity. - - \value OutCirc - Easing equation function for a circular (sqrt(1-t^2)) easing out: decelerating from zero velocity. - - \value InOutCirc - Easing equation function for a circular (sqrt(1-t^2)) easing in/out: acceleration until halfway, then deceleration. - - \value OutInCirc - Easing equation function for a circular (sqrt(1-t^2)) easing out/in: deceleration until halfway, then acceleration. - - \value InElastic - Easing equation function for an elastic (exponentially decaying - sine wave) easing in: accelerating from zero velocity. The peak - amplitude can be set with the \e amplitude parameter, and the - period of decay by the \e period parameter. - - \value OutElastic - Easing equation function for an elastic (exponentially decaying - sine wave) easing out: decelerating from zero velocity. The peak - amplitude can be set with the \e amplitude parameter, and the - period of decay by the \e period parameter. - - \value InOutElastic - Easing equation function for an elastic (exponentially decaying sine wave) easing in/out: acceleration until halfway, then deceleration. - - \value OutInElastic - Easing equation function for an elastic (exponentially decaying sine wave) easing out/in: deceleration until halfway, then acceleration. - - \value InBack - Easing equation function for a back (overshooting cubic easing: (s+1)*t^3 - s*t^2) easing in: accelerating from zero velocity. - - \value OutBack - Easing equation function for a back (overshooting cubic easing: (s+1)*t^3 - s*t^2) easing out: decelerating from zero velocity. - - \value InOutBack - Easing equation function for a back (overshooting cubic easing: (s+1)*t^3 - s*t^2) easing in/out: acceleration until halfway, then deceleration. - - \value OutInBack - Easing equation function for a back (overshooting cubic easing: (s+1)*t^3 - s*t^2) easing out/in: deceleration until halfway, then acceleration. - - \value OutBounce - Easing equation function for a bounce (exponentially decaying parabolic bounce) easing out: decelerating from zero velocity. - - \value InBounce - Easing equation function for a bounce (exponentially decaying parabolic bounce) easing in: accelerating from zero velocity. - - \value InOutBounce - Easing equation function for a bounce (exponentially decaying parabolic bounce) easing in/out: acceleration until halfway, then deceleration. - - \value OutInBounce - Easing equation function for a bounce (exponentially decaying parabolic bounce) easing out/in: deceleration until halfway, then acceleration. -*/ - -/*! - Construct a linear easing object. This is equivalent to \c {GfxEasing(GfxEasing::None)}. - */ -GfxEasing::GfxEasing() -: _config(0), _func(&easeNone), _b(0.), _c(1.), _d(1.) -{ -} - -/*! - Construct an easing object with the given \a curve. - */ -GfxEasing::GfxEasing(Curve curve) -: _config(0), _func(0), _b(0.), _c(1.), _d(1.) -{ - _func = curveToFunc(curve); - if(!_func) { - qWarning("GfxEasing: Invalid curve type %d", curve); - _func = &easeNone; - } -} - -/*! - Construct an easing object with the given \a curve. If \a curve does not - describe a legal curve, a linear easing object is constructed. - - Curve names have the form - \c {ease[(: [, : ])]}. The - \e CurveName is equivalent to the GfxEasing::Curve enum name. Some more - advanced curves can take arguments to further refine their behaviour. Where - applicable, these parameters are described in the corresponding - GfxEasing::Curve value documentation. - - For example, - \code - GfxEasing easing("easeInOutQuad"); - GfxEasing easing2("easeInElastic(period: 5, amplitude: 100)"); - \endcode - */ -GfxEasing::GfxEasing(const QString &curve) -: _config(0), _func(&easeNone), _b(0.), _c(1.), _d(1.) -{ - if(curve.contains(QLatin1Char('('))) { - QString easeName = curve.trimmed(); - GfxEasingProperties prop; - if(!easeName.endsWith(QLatin1Char(')'))) { - qWarning("GfxEasing: Unmatched perenthesis in easing function '%s'", - curve.toLatin1().constData()); - return; - } - - int idx = easeName.indexOf(QLatin1Char('(')); - QString prop_str = - easeName.mid(idx + 1, easeName.length() - 1 - idx - 1); - easeName = easeName.left(idx); - - QStringList props = prop_str.split(QLatin1Char(',')); - foreach(QString str, props) { - int sep = str.indexOf(QLatin1Char(':')); - - if(sep == -1) { - qWarning("GfxEasing: Improperly specified property in easing function '%s'", - curve.toLatin1().constData()); - return; - } - - QString propName = str.left(sep).trimmed(); - bool isOk; - qreal propValue = str.mid(sep + 1).trimmed().toDouble(&isOk); - - if(propName.isEmpty() || !isOk) { - qWarning("GfxEasing: Improperly specified property in easing function '%s'", - curve.toLatin1().constData()); - return; - } - - prop.insert(propName, propValue); - } - - QHash::Iterator iter = - configFunctionMap()->find(easeName); - - if(iter != configFunctionMap()->end()) - _config = (*iter)(prop); - } else { - if(nameFunctionMap()->contains(curve)) - _func = *(nameFunctionMap()->find(curve)); - } - - if(!_func && !_config) { - qWarning("GfxEasing: Unknown easing curve '%s'", - curve.toLatin1().constData()); - _func = &easeNone; - } -} - -/*! - Construct a copy of \a other. - */ -GfxEasing::GfxEasing(const GfxEasing &other) -: _config(0), _func(other._func), _b(other._b), _c(other._c), _d(other._d) -{ - if(other._config) _config = other._config->copy(); -} - -/*! - Copy \a other. - */ -GfxEasing &GfxEasing::operator=(const GfxEasing &other) -{ - if(_config) { delete _config; _config = 0; } - if(other._config) _config = other._config->copy(); - - _func = other._func; - _b = other._b; - _c = other._c; - _d = other._d; - - return *this; -} - -/*! - Returns true if this is a linear easing object. - */ -bool GfxEasing::isLinear() const -{ - return !_config && _func == &easeNone; -} - -/*! - Return the starting value for the easing curve. By default this is 0. - */ -qreal GfxEasing::from() const -{ - return _b; -} - -/*! - Set the starting value for the easing curve to \a from. - */ -void GfxEasing::setFrom(qreal from) -{ - _b = from; -} - -/*! - Return the final value for the easing curve. By default this is 0. - */ -qreal GfxEasing::to() const -{ - return _c; -} - -/*! - Set the final value for the easing curve to \a to. - */ -void GfxEasing::setTo(qreal to) -{ - _c = to; -} - -/*! - Return the length of the easing curve, in milliseconds. By default this - is 1. - */ -qreal GfxEasing::length() const -{ - return _d; -} - -/*! - Set the \a length of the easing curve, in milliseconds. - */ -void GfxEasing::setLength(qreal length) -{ - Q_ASSERT(length > 0); - _d = length; -} - -/*! - Return the value for the easing curve at time \a t milliseconds, based on - the parameters returned by GfxEasing::from(), GfxEasing::to() and - GfxEasing::length(). - - \a t is clamped to (0, GfxEasing::length()). - */ -qreal GfxEasing::valueAt(qreal t) const -{ - if(t < 0) t = 0; - else if(t > length()) t = length(); - - if(_config) - return _config->value(t, _b, _c - _b, _d); - else - return _func(t, _b, _c - _b, _d); -} - -/* - Return the value for the easing curve at time \a t milliseconds, based on - the provided parameters \a from, \a to and \a length. The values returned - from the object's GfxEasing::from(), GfxEasing::to() and GfxEasing::length() - methods are ignored. - - \a t is clamped to (0, \a length). - */ -qreal GfxEasing::valueAt(qreal t, qreal from, qreal to, qreal length) const -{ - if(t < 0) t = 0; - else if(t > length) t = length; - - if(_config) - return _config->value(t, from, to - from, length); - else - return _func(t, from, to - from, length); -} - -/*! - \internal - */ -QStringList GfxEasing::curves() -{ - return nameFunctionMap()->keys(); -} - -QT_END_NAMESPACE diff --git a/src/declarative/timeline/gfxeasing.h b/src/declarative/timeline/gfxeasing.h deleted file mode 100644 index c15aadc..0000000 --- a/src/declarative/timeline/gfxeasing.h +++ /dev/null @@ -1,107 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** Contact: Qt Software Information (qt-info@nokia.com) -** -** This file is part of the QtDeclarative module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the either Technology Preview License Agreement or the -** Beta Release License Agreement. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain -** additional rights. These rights are described in the Nokia Qt LGPL -** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this -** package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3.0 as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU General Public License version 3.0 requirements will be -** met: http://www.gnu.org/copyleft/gpl.html. -** -** If you are unsure which license is appropriate for your use, please -** contact the sales department at qt-sales@nokia.com. -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef GFXEASING_H -#define GFXEASING_H - -#include -#include -#include -#include - - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -QT_MODULE(Declarative) - -class GfxEasingFunction; -class Q_DECLARATIVE_EXPORT GfxEasing -{ -public: - enum Curve { - None, - InQuad, OutQuad, InOutQuad, OutInQuad, - InCubic, OutCubic, InOutCubic, OutInCubic, - InQuart, OutQuart, InOutQuart, OutInQuart, - InQuint, OutQuint, InOutQuint, OutInQuint, - InSine, OutSine, InOutSine, OutInSine, - InExpo, OutExpo, InOutExpo, OutInExpo, - InCirc, OutCirc, InOutCirc, OutInCirc, - InElastic, OutElastic, InOutElastic, OutInElastic, - InBack, OutBack, InOutBack, OutInBack, - InBounce, OutBounce, InOutBounce, OutInBounce - }; - - GfxEasing(); - GfxEasing(Curve); - GfxEasing(const QString &); - GfxEasing(const GfxEasing &); - GfxEasing &operator=(const GfxEasing &); - - bool isLinear() const; - - qreal from() const; - void setFrom(qreal); - qreal to() const; - void setTo(qreal); - qreal length() const; - void setLength(qreal); - - qreal valueAt(qreal t) const; - qreal valueAt(qreal t, qreal from, qreal to, qreal length) const; - - static QStringList curves(); - - typedef float (*Function)(float t, float b, float c, float d); -private: - GfxEasingFunction *_config; - Function _func; - - qreal _b, _c, _d; -}; - - -QT_END_NAMESPACE - -QT_END_HEADER -#endif diff --git a/src/declarative/timeline/gfxtimeline.cpp b/src/declarative/timeline/gfxtimeline.cpp deleted file mode 100644 index 3e84df8..0000000 --- a/src/declarative/timeline/gfxtimeline.cpp +++ /dev/null @@ -1,946 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** Contact: Qt Software Information (qt-info@nokia.com) -** -** This file is part of the QtDeclarative module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the either Technology Preview License Agreement or the -** Beta Release License Agreement. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain -** additional rights. These rights are described in the Nokia Qt LGPL -** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this -** package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3.0 as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU General Public License version 3.0 requirements will be -** met: http://www.gnu.org/copyleft/gpl.html. -** -** If you are unsure which license is appropriate for your use, please -** contact the sales department at qt-sales@nokia.com. -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "gfxtimeline.h" -#include -#include -#include -#include -#include -#include -#include "gfxeasing.h" -#include - -QT_BEGIN_NAMESPACE - -#define TIMETICK 5 - -// -// Timeline stuff -// - -struct Update { - Update(GfxValue *_g, qreal _v) - : g(_g), v(_v) {} - Update(const GfxEvent &_e) - : g(0), v(0), e(_e) {} - - GfxValue *g; - qreal v; - GfxEvent e; -}; - -struct QmlTimeLinePrivate -{ - QmlTimeLinePrivate(QmlTimeLine *); - - struct Op { - enum Type { - Pause, - Set, - Move, - MoveBy, - Accel, - AccelDistance, - Execute - }; - Op() {} - Op(Type t, int l, qreal v, qreal v2, int o, - const GfxEvent &ev = GfxEvent(), const GfxEasing &es = GfxEasing()) - : type(t), length(l), value(v), value2(v2), order(o), event(ev), - easing(es) {} - Op(const Op &o) - : type(o.type), length(o.length), value(o.value), value2(o.value2), - order(o.order), event(o.event), easing(o.easing) {} - Op &operator=(const Op &o) { - type = o.type; length = o.length; value = o.value; - value2 = o.value2; order = o.order; event = o.event; - easing = o.easing; - return *this; - } - - Type type; - int length; - qreal value; - qreal value2; - - int order; - GfxEvent event; - GfxEasing easing; - }; - struct TimeLine - { - TimeLine() : length(0), consumedOpLength(0), base(0.) {} - QList ops; - int length; - int consumedOpLength; - qreal base; - }; - - int length; - int syncPoint; - typedef QHash Ops; - Ops ops; - QmlTimeLine *q; - - void add(QmlTimeLineObject &, const Op &); - qreal value(const Op &op, int time, qreal base, bool *) const; - - int advance(int); - - bool clockRunning; - int prevTime; - - int order; - - QmlTimeLine::SyncMode syncMode; - int syncAdj; - QList > *updateQueue; -}; - -QmlTimeLinePrivate::QmlTimeLinePrivate(QmlTimeLine *parent) -: length(0), syncPoint(0), q(parent), clockRunning(false), prevTime(0), order(0), syncMode(QmlTimeLine::LocalSync), syncAdj(0), updateQueue(0) -{ -} - -void QmlTimeLinePrivate::add(QmlTimeLineObject &g, const Op &o) -{ - if(g._t && g._t != q) { - qWarning() << "QmlTimeLine: Cannot modify a GfxValue owned by" - << "another timeline."; - return; - } - g._t = q; - - Ops::Iterator iter = ops.find(&g); - if(iter == ops.end()) { - iter = ops.insert(&g, TimeLine()); - if(syncPoint > 0) - q->pause(g, syncPoint); - } - if(!iter->ops.isEmpty() && - o.type == Op::Pause && - iter->ops.last().type == Op::Pause) { - iter->ops.last().length += o.length; - iter->length += o.length; - } else { - iter->ops.append(o); - iter->length += o.length; - } - - if(iter->length > length) - length = iter->length; - - if(!clockRunning) { - q->stop(); - prevTime = 0; - clockRunning = true; - - if(syncMode == QmlTimeLine::LocalSync) { - syncAdj = -1; - } else { - syncAdj = 0; - } - q->start(); -/* q->tick(0); - if(syncMode == QmlTimeLine::LocalSync) { - syncAdj = -1; - } else { - syncAdj = 0; - } - */ - } -} - -qreal QmlTimeLinePrivate::value(const Op &op, int time, qreal base, bool *changed) const -{ - Q_ASSERT(time >= 0); - Q_ASSERT(time <= op.length); - *changed = true; - - switch(op.type) { - case Op::Pause: - *changed = false; - return base; - case Op::Set: - return op.value; - case Op::Move: - if(time == 0) { - return base; - } else if(time == (op.length)) { - return op.value; - } else { - if(op.easing.isLinear()) { - qreal delta = op.value - base; - qreal pTime = (qreal)(time) / (qreal)op.length; - return base + delta * pTime; - } else { - return op.easing.valueAt(time, base, op.value, op.length); - } - } - case Op::MoveBy: - if(time == 0) { - return base; - } else if(time == (op.length)) { - return base + op.value; - } else { - if(op.easing.isLinear()) { - qreal delta = op.value; - qreal pTime = (qreal)(time) / (qreal)op.length; - return base + delta * pTime; - } else { - return op.easing.valueAt(time, base, base + op.value, op.length); - } - } - case Op::Accel: - if(time == 0) { - return base; - } else { - qreal t = (qreal)(time) / 1000.0f; - qreal delta = op.value * t + 0.5f * op.value2 * t * t; - return base + delta; - } - case Op::AccelDistance: - if(time == 0) { - return base; - } else if(time == (op.length)) { - return base + op.value2; - } else { - qreal t = (qreal)(time) / 1000.0f; - qreal accel = -1.0f * 1000.0f * op.value / (qreal)op.length; - qreal delta = op.value * t + 0.5f * accel * t * t; - return base + delta; - - } - case Op::Execute: - op.event.execute(); - *changed = false; - return -1; - } - - return base; -} - -/*! - \class QmlTimeLine - \ingroup group_animation - \brief The QmlTimeLine class provides a timeline for controlling animations. - - QmlTimeLine is similar to QTimeLine except: - \list - \i It updates GfxValue instances directly, rather than maintaining a single - current value. - - For example, the following animates a simple value over 200 milliseconds: - \code - GfxValue v(); - QmlTimeLine tl; - tl.move(v, 100., 200); - tl.start() - \endcode - - If your program needs to know when values are changed, it can either - connect to the QmlTimeLine's updated() signal, or inherit from GfxValue - and reimplement the GfxValue::setValue() method. - - \i Supports multiple GfxValue, arbitrary start and end values and allows - animations to be strung together for more complex effects. - - For example, the following animation moves the x and y coordinates of - an object from wherever they are to the position (100, 100) in 50 - milliseconds and then further animates them to (100, 200) in 50 - milliseconds: - - \code - GfxValue x(); - GfxValue y(); - - QmlTimeLine tl; - tl.start(); - - tl.move(x, 100., 50); - tl.move(y, 100., 50); - tl.move(y, 200., 50); - \endcode - - \i All QmlTimeLine instances share a single, synchronized clock. - - Actions scheduled within the same event loop tick are scheduled - synchronously against each other, regardless of the wall time between the - scheduling. Synchronized scheduling applies both to within the same - QmlTimeLine and across separate QmlTimeLine's within the same process. - - \endlist - - Currently easing functions are not supported. -*/ - - -/*! - Construct a new QmlTimeLine with the specified \a parent. -*/ -QmlTimeLine::QmlTimeLine(QObject *parent) -: QAbstractAnimation(parent) -{ - d = new QmlTimeLinePrivate(this); -} - -/*! - Destroys the time line. Any inprogress animations are canceled, but not - completed. -*/ -QmlTimeLine::~QmlTimeLine() -{ - for(QmlTimeLinePrivate::Ops::Iterator iter = d->ops.begin(); - iter != d->ops.end(); - ++iter) - iter.key()->_t = 0; - - delete d; d = 0; -} - -/*! - \enum QmlTimeLine::SyncMode - */ - -/*! - Return the timeline's synchronization mode. - */ -QmlTimeLine::SyncMode QmlTimeLine::syncMode() const -{ - return d->syncMode; -} - -/*! - Set the timeline's synchronization mode to \a syncMode. - */ -void QmlTimeLine::setSyncMode(SyncMode syncMode) -{ - d->syncMode = syncMode; -} - -/*! - Pause \a gfxValue for \a time milliseconds. -*/ -void QmlTimeLine::pause(QmlTimeLineObject &obj, int time) -{ - if(time <= 0) return; - QmlTimeLinePrivate::Op op(QmlTimeLinePrivate::Op::Pause, time, 0., 0., d->order++); - d->add(obj, op); -} - -/*! - Execute the \a event. - */ -void QmlTimeLine::execute(const GfxEvent &event) -{ - QmlTimeLinePrivate::Op op(QmlTimeLinePrivate::Op::Execute, 0, 0, 0., d->order++, event); - d->add(*event.eventObject(), op); -} - -/*! - Set the \a value of \a gfxValue. -*/ -void QmlTimeLine::set(GfxValue &gfxValue, qreal value) -{ - QmlTimeLinePrivate::Op op(QmlTimeLinePrivate::Op::Set, 0, value, 0., d->order++); - d->add(gfxValue, op); -} - -/*! - Decelerate \a gfxValue from the starting \a velocity to zero at the - given \a acceleration rate. Although the \a acceleration is technically - a deceleration, it should always be positive. The QmlTimeLine will ensure - that the deceleration is in the opposite direction to the initial velocity. -*/ -int QmlTimeLine::accel(GfxValue &gfxValue, qreal velocity, qreal acceleration) -{ - if((velocity > 0.0f) == (acceleration > 0.0f)) - acceleration = acceleration * -1.0f; - - int time = static_cast(-1000 * velocity / acceleration); - - QmlTimeLinePrivate::Op op(QmlTimeLinePrivate::Op::Accel, time, velocity, acceleration, d->order++); - d->add(gfxValue, op); - - return time; -} - -/*! - \overload - - Decelerate \a gfxValue from the starting \a velocity to zero at the - given \a acceleration rate over a maximum distance of maxDistance. - - If necessary, QmlTimeLine will reduce the acceleration to ensure that the - entire operation does not require a move of more than \a maxDistance. - \a maxDistance should always be positive. -*/ -int QmlTimeLine::accel(GfxValue &gfxValue, qreal velocity, qreal acceleration, qreal maxDistance) -{ - Q_ASSERT(acceleration >= 0.0f && maxDistance >= 0.0f); - - qreal maxAccel = (velocity * velocity) / (2.0f * maxDistance); - if(maxAccel > acceleration) - acceleration = maxAccel; - - if((velocity > 0.0f) == (acceleration > 0.0f)) - acceleration = acceleration * -1.0f; - - int time = static_cast(-1000 * velocity / acceleration); - - QmlTimeLinePrivate::Op op(QmlTimeLinePrivate::Op::Accel, time, velocity, acceleration, d->order++); - d->add(gfxValue, op); - - return time; -} - -/*! - Decelerate \a gfxValue from the starting \a velocity to zero over the given - \a distance. This is like accel(), but the QmlTimeLine calculates the exact - deceleration to use. - - \a distance should be positive. -*/ -int QmlTimeLine::accelDistance(GfxValue &gfxValue, qreal velocity, qreal distance) -{ - if (distance == 0.0f || velocity == 0.0f) - return -1; - Q_ASSERT((distance >= 0.0f) == (velocity >= 0.0f)); - - int time = static_cast(1000 * (2.0f * distance) / velocity); - - QmlTimeLinePrivate::Op op(QmlTimeLinePrivate::Op::AccelDistance, time, velocity, distance, d->order++); - d->add(gfxValue, op); - - return time; -} - -/*! - Linearly change the \a gfxValue from its current value to the given - \a destination value over \a time milliseconds. -*/ -void QmlTimeLine::move(GfxValue &gfxValue, qreal destination, int time) -{ - if(time <= 0) return; - QmlTimeLinePrivate::Op op(QmlTimeLinePrivate::Op::Move, time, destination, 0.0f, d->order++); - d->add(gfxValue, op); -} - -/*! - Change the \a gfxValue from its current value to the given \a destination - value over \a time milliseconds using the \a easing curve. - */ -void QmlTimeLine::move(GfxValue &gfxValue, qreal destination, const GfxEasing &easing, int time) -{ - if(time <= 0) return; - QmlTimeLinePrivate::Op op(QmlTimeLinePrivate::Op::Move, time, destination, 0.0f, d->order++, GfxEvent(), easing); - d->add(gfxValue, op); -} - -/*! - Linearly change the \a gfxValue from its current value by the \a change amount - over \a time milliseconds. -*/ -void QmlTimeLine::moveBy(GfxValue &gfxValue, qreal change, int time) -{ - if(time <= 0) return; - QmlTimeLinePrivate::Op op(QmlTimeLinePrivate::Op::MoveBy, time, change, 0.0f, d->order++); - d->add(gfxValue, op); -} - -/*! - Change the \a gfxValue from its current value by the \a change amount over - \a time milliseconds using the \a easing curve. - */ -void QmlTimeLine::moveBy(GfxValue &gfxValue, qreal change, const GfxEasing &easing, int time) -{ - if(time <= 0) return; - QmlTimeLinePrivate::Op op(QmlTimeLinePrivate::Op::MoveBy, time, change, 0.0f, d->order++, GfxEvent(), easing); - d->add(gfxValue, op); -} - -/*! - Cancel (but don't complete) all scheduled actions for \a gfxValue. -*/ -void QmlTimeLine::reset(GfxValue &gfxValue) -{ - if(!gfxValue._t) - return; - if(gfxValue._t != this) { - qWarning() << "QmlTimeLine: Cannot reset a GfxValue owned by another timeline."; - return; - } - remove(&gfxValue); - gfxValue._t = 0; -} - -int QmlTimeLine::duration() const -{ - return -1; -} - -/*! - Synchronize the end point of \a gfxValue to the endpoint of \a syncTo - within this timeline. - - Following operations on \a gfxValue in this timeline will be scheduled after - all the currently scheduled actions on \a syncTo are complete. In - psuedo-code this is equivalent to: - \code - QmlTimeLine::pause(gfxValue, min(0, length_of(syncTo) - length_of(gfxValue))) - \endcode -*/ -void QmlTimeLine::sync(GfxValue &gfxValue, GfxValue &syncTo) -{ - QmlTimeLinePrivate::Ops::Iterator iter = d->ops.find(&syncTo); - if(iter == d->ops.end()) - return; - int length = iter->length; - - iter = d->ops.find(&gfxValue); - if(iter == d->ops.end()) { - pause(gfxValue, length); - } else { - int glength = iter->length; - pause(gfxValue, length - glength); - } -} - -/*! - Synchronize the end point of \a gfxValue to the endpoint of the longest - action currently scheduled in the timeline. - - In psuedo-code, this is equivalent to: - \code - QmlTimeLine::pause(gfxValue, length_of(timeline) - length_of(gfxValue)) - \endcode -*/ -void QmlTimeLine::sync(GfxValue &gfxValue) -{ - QmlTimeLinePrivate::Ops::Iterator iter = d->ops.find(&gfxValue); - if(iter == d->ops.end()) { - pause(gfxValue, d->length); - } else { - pause(gfxValue, d->length - iter->length); - } -} - -/*! - Synchronize all currently and future scheduled values in this timeline to - the longest action currently scheduled. - - For example: - \code - value1->setValue(0.); - value2->setValue(0.); - value3->setValue(0.); - QmlTimeLine tl; - ... - tl.move(value1, 10, 200); - tl.move(value2, 10, 100); - tl.sync(); - tl.move(value2, 20, 100); - tl.move(value3, 20, 100); - \endcode - - will result in: - - \table - \header \o \o 0ms \o 50ms \o 100ms \o 150ms \o 200ms \o 250ms \o 300ms - \row \o value1 \o 0 \o 2.5 \o 5.0 \o 7.5 \o 10 \o 10 \o 10 - \row \o value2 \o 0 \o 5.0 \o 10.0 \o 10.0 \o 10.0 \o 15.0 \o 20.0 - \row \o value2 \o 0 \o 0 \o 0 \o 0 \o 0 \o 10.0 \o 20.0 - \endtable -*/ - -/*void QmlTimeLine::sync() -{ - for(QmlTimeLinePrivate::Ops::Iterator iter = d->ops.begin(); - iter != d->ops.end(); - ++iter) - pause(*iter.key(), d->length - iter->length); - d->syncPoint = d->length; -}*/ - -/*! - \internal - - Temporary hack. - */ -void QmlTimeLine::setSyncPoint(int sp) -{ - d->syncPoint = sp; -} - -/*! - \internal - - Temporary hack. - */ -int QmlTimeLine::syncPoint() const -{ - return d->syncPoint; -} - -/*! - Returns true if the timeline is active. An active timeline is one where - GfxValue actions are still pending. -*/ -bool QmlTimeLine::isActive() const -{ - return !d->ops.isEmpty(); -} - -/*! - Completes the timeline. All queued actions are played to completion, and then discarded. For example, - \code - GfxValue v(0.); - QmlTimeLine tl; - tl.move(v, 100., 1000.); - // 500 ms passes - // v.value() == 50. - tl.complete(); - // v.value() == 100. - \endcode -*/ -void QmlTimeLine::complete() -{ - d->advance(d->length); -} - -/*! - Resets the timeline. All queued actions are discarded and GfxValue's retain their current value. For example, - \code - GfxValue v(0.); - QmlTimeLine tl; - tl.move(v, 100., 1000.); - // 500 ms passes - // v.value() == 50. - tl.clear(); - // v.value() == 50. - \endcode -*/ -void QmlTimeLine::clear() -{ - for(QmlTimeLinePrivate::Ops::ConstIterator iter = d->ops.begin(); iter != d->ops.end(); ++iter) - iter.key()->_t = 0; - d->ops.clear(); - d->length = 0; - d->syncPoint = 0; - //XXX need stop here? -} - -int QmlTimeLine::time() const -{ - return d->prevTime; -} - -/*! - \fn void QmlTimeLine::updated() - - Emitted each time the timeline modifies GfxValues. Even if multiple - GfxValues are changed, this signal is only emitted once for each clock tick. -*/ - -void QmlTimeLine::updateCurrentTime(int v) -{ - if(d->syncAdj == -1) - d->syncAdj = v; - v -= d->syncAdj; - - int timeChanged = v - d->prevTime; -#if 0 - if(!timeChanged) - return; -#endif - d->prevTime = v; - d->advance(timeChanged); - emit updated(); - - // Do we need to stop the clock? - if(d->ops.isEmpty()) { - stop(); - d->prevTime = 0; - d->clockRunning = false; - emit completed(); - } /*else if(pauseTime > 0) { - GfxClock::cancelClock(); - d->prevTime = 0; - GfxClock::pauseFor(pauseTime); - d->syncAdj = 0; - d->clockRunning = false; - }*/ else if(/*!GfxClock::isActive()*/ state() != Running) { - stop(); - d->prevTime = 0; - d->clockRunning = true; - d->syncAdj = 0; - start(); - } -} - -bool operator<(const QPair &lhs, - const QPair &rhs) -{ - return lhs.first < rhs.first; -} - -int QmlTimeLinePrivate::advance(int t) -{ - int pauseTime = -1; - - // XXX - surely there is a more efficient way? - do { - pauseTime = -1; - // Minimal advance time - int advanceTime = t; - for(Ops::Iterator iter = ops.begin(); iter != ops.end(); ++iter) { - TimeLine &tl = *iter; - Op &op = tl.ops.first(); - int length = op.length - tl.consumedOpLength; - - if(length < advanceTime) { - advanceTime = length; - if(advanceTime == 0) - break; - } - } - t -= advanceTime; - - // Process until then. A zero length advance time will only process - // sets. - QList > updates; - - for(Ops::Iterator iter = ops.begin(); iter != ops.end(); ) { - GfxValue *v = static_cast(iter.key()); - TimeLine &tl = *iter; - Q_ASSERT(!tl.ops.isEmpty()); - - do { - Op &op = tl.ops.first(); - if(advanceTime == 0 && op.length != 0) - continue; - - if(tl.consumedOpLength == 0 && - op.type != Op::Pause && - op.type != Op::Execute) - tl.base = v->value(); - - if((tl.consumedOpLength + advanceTime) == op.length) { - if(op.type == Op::Execute) { - updates << qMakePair(op.order, Update(op.event)); - } else { - bool changed = false; - qreal val = value(op, op.length, tl.base, &changed); - if(changed) - updates << qMakePair(op.order, Update(v, val)); - } - tl.length -= qMin(advanceTime, tl.length); - tl.consumedOpLength = 0; - tl.ops.removeFirst(); - } else { - tl.consumedOpLength += advanceTime; - bool changed = false; - qreal val = value(op, tl.consumedOpLength, tl.base, &changed); - if(changed) - updates << qMakePair(op.order, Update(v, val)); - tl.length -= qMin(advanceTime, tl.length); - break; - } - - } while(!tl.ops.isEmpty() && advanceTime == 0 && tl.ops.first().length == 0); - - - if(tl.ops.isEmpty()) { - iter = ops.erase(iter); - v->_t = 0; - } else { - if(tl.ops.first().type == Op::Pause && pauseTime != 0) { - int opPauseTime = tl.ops.first().length - tl.consumedOpLength; - if(pauseTime == -1 || opPauseTime < pauseTime) - pauseTime = opPauseTime; - } else { - pauseTime = 0; - } - ++iter; - } - } - - length -= qMin(length, advanceTime); - syncPoint -= advanceTime; - - qSort(updates.begin(), updates.end()); - updateQueue = &updates; - for(int ii = 0; ii < updates.count(); ++ii) { - const Update &v = updates.at(ii).second; - if(v.g) - v.g->setValue(v.v); - else - v.e.execute(); - } - updateQueue = 0; - } while(t); - - return pauseTime; -} - -void QmlTimeLine::remove(QmlTimeLineObject *v) -{ - QmlTimeLinePrivate::Ops::Iterator iter = d->ops.find(v); - Q_ASSERT(iter != d->ops.end()); - - int len = iter->length; - d->ops.erase(iter); - if(len == d->length) { - // We need to recalculate the length - d->length = 0; - for(QmlTimeLinePrivate::Ops::Iterator iter = d->ops.begin(); - iter != d->ops.end(); - ++iter) { - - if(iter->length > d->length) - d->length = iter->length; - - } - } - if(d->ops.isEmpty()) { - stop(); - d->clockRunning = false; - } else if(/*!GfxClock::isActive()*/ state() != Running) { - stop(); - d->prevTime = 0; - d->clockRunning = true; - - if(d->syncMode == QmlTimeLine::LocalSync) { - d->syncAdj = -1; - } else { - d->syncAdj = 0; - } - start(); - } - - if(d->updateQueue) { - for(int ii = 0; ii < d->updateQueue->count(); ++ii) { - if(d->updateQueue->at(ii).second.g == v || - d->updateQueue->at(ii).second.e.eventObject() == v) { - d->updateQueue->removeAt(ii); - --ii; - } - } - } - - -} - -/*! - \class GfxValue - \ingroup group_animation - \brief The GfxValue class is modified by QmlTimeLine. -*/ - -/*! - \fn GfxValue::GfxValue(qreal value = 0) - - Construct a new GfxValue with an initial \a value. -*/ - -/*! - \fn qreal GfxValue::value() const - - Return the current value. -*/ - -/*! - \fn void GfxValue::setValue(qreal value) - - Set the current \a value. -*/ - -/*! - \fn QmlTimeLine *GfxValue::timeLine() const - - If a QmlTimeLine is operating on this value, return a pointer to it, - otherwise return null. -*/ - - -QmlTimeLineObject::QmlTimeLineObject() -: _t(0) -{ -} - -QmlTimeLineObject::~QmlTimeLineObject() -{ - if(_t) { - _t->remove(this); - _t = 0; - } -} - -GfxEvent::GfxEvent() -: d0(0), d1(0), d2(0) -{ -} - -GfxEvent::GfxEvent(const GfxEvent &o) -: d0(o.d0), d1(o.d1), d2(o.d2) -{ -} - -GfxEvent &GfxEvent::operator=(const GfxEvent &o) -{ - d0 = o.d0; - d1 = o.d1; - d2 = o.d2; - return *this; -} - -void GfxEvent::execute() const -{ - d0(d1); -} - -QmlTimeLineObject *GfxEvent::eventObject() const -{ - return d2; -} - -QT_END_NAMESPACE diff --git a/src/declarative/timeline/gfxtimeline.h b/src/declarative/timeline/gfxtimeline.h deleted file mode 100644 index 0bdddaf..0000000 --- a/src/declarative/timeline/gfxtimeline.h +++ /dev/null @@ -1,190 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** Contact: Qt Software Information (qt-info@nokia.com) -** -** This file is part of the QtDeclarative module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the either Technology Preview License Agreement or the -** Beta Release License Agreement. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain -** additional rights. These rights are described in the Nokia Qt LGPL -** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this -** package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3.0 as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU General Public License version 3.0 requirements will be -** met: http://www.gnu.org/copyleft/gpl.html. -** -** If you are unsure which license is appropriate for your use, please -** contact the sales department at qt-sales@nokia.com. -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef GFXTIMELINE_H -#define GFXTIMELINE_H - -#include -#include -#include - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -QT_MODULE(Declarative) - -class GfxEasing; -class GfxValue; -class GfxEvent; -struct QmlTimeLinePrivate; -class QmlTimeLineObject; -class Q_DECLARATIVE_EXPORT QmlTimeLine : public QAbstractAnimation -{ -Q_OBJECT -public: - QmlTimeLine(QObject *parent = 0); - ~QmlTimeLine(); - - enum SyncMode { LocalSync, GlobalSync }; - SyncMode syncMode() const; - void setSyncMode(SyncMode); - - void pause(QmlTimeLineObject &, int); - void execute(const GfxEvent &); - void set(GfxValue &, qreal); - - int accel(GfxValue &, qreal velocity, qreal accel); - int accel(GfxValue &, qreal velocity, qreal accel, qreal maxDistance); - int accelDistance(GfxValue &, qreal velocity, qreal distance); - - void move(GfxValue &, qreal destination, int time = 500); - void move(GfxValue &, qreal destination, const GfxEasing &, int time = 500); - void moveBy(GfxValue &, qreal change, int time = 500); - void moveBy(GfxValue &, qreal change, const GfxEasing &, int time = 500); - - void sync(); - void setSyncPoint(int); - int syncPoint() const; - - void sync(GfxValue &); - void sync(GfxValue &, GfxValue &); - - void reset(GfxValue &); - - void complete(); - void clear(); - bool isActive() const; - - int time() const; - - virtual int duration() const; -Q_SIGNALS: - void updated(); - void completed(); - -protected: - virtual void updateCurrentTime(int); - -private: - void remove(QmlTimeLineObject *); - friend class QmlTimeLineObject; - friend struct QmlTimeLinePrivate; - QmlTimeLinePrivate *d; -}; - -class Q_DECLARATIVE_EXPORT QmlTimeLineObject -{ -public: - QmlTimeLineObject(); - virtual ~QmlTimeLineObject(); - -protected: - friend class QmlTimeLine; - friend struct QmlTimeLinePrivate; - QmlTimeLine *_t; -}; - -class Q_DECLARATIVE_EXPORT GfxValue : public QmlTimeLineObject -{ -public: - GfxValue(qreal v = 0.) : _v(v) {} - - qreal value() const { return _v; } - virtual void setValue(qreal v) { _v = v; } - - QmlTimeLine *timeLine() const { return _t; } - - operator qreal() const { return _v; } - GfxValue &operator=(qreal v) { setValue(v); return *this; } -private: - friend class QmlTimeLine; - friend struct QmlTimeLinePrivate; - qreal _v; -}; - -class Q_DECLARATIVE_EXPORT GfxEvent -{ -public: - GfxEvent(); - GfxEvent(const GfxEvent &o); - - template - GfxEvent(QmlTimeLineObject *b, T *c) - { - d0 = &callFunc; - d1 = (void *)c; - d2 = b; - } - - template - static GfxEvent gfxEvent(QmlTimeLineObject *b, T *c) - { - GfxEvent rv; - rv.d0 = &callFunc; - rv.d1 = (void *)c; - rv.d2 = b; - return rv; - } - - GfxEvent &operator=(const GfxEvent &o); - void execute() const; - QmlTimeLineObject *eventObject() const; - -private: - typedef void (*CallFunc)(void *c); - - template - static void callFunc(void *c) - { - T *cls = (T *)c; - (cls->*method)(); - } - CallFunc d0; - void *d1; - QmlTimeLineObject *d2; -}; - -QT_END_NAMESPACE - -QT_END_HEADER - -#endif diff --git a/src/declarative/timeline/gfxvalueproxy.h b/src/declarative/timeline/gfxvalueproxy.h index 1eaf44e..1bb716c 100644 --- a/src/declarative/timeline/gfxvalueproxy.h +++ b/src/declarative/timeline/gfxvalueproxy.h @@ -41,6 +41,9 @@ #ifndef GFXVALUEPROXY_H #define GFXVALUEPROXY_H + +#include "qmltimeline.h" + QT_BEGIN_HEADER QT_BEGIN_NAMESPACE diff --git a/src/declarative/timeline/qmltimeline.cpp b/src/declarative/timeline/qmltimeline.cpp new file mode 100644 index 0000000..2006fd0 --- /dev/null +++ b/src/declarative/timeline/qmltimeline.cpp @@ -0,0 +1,943 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +** This file is part of the QtDeclarative module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain +** additional rights. These rights are described in the Nokia Qt LGPL +** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qmltimeline.h" +#include +#include +#include +#include +#include +#include +#include +#include + +QT_BEGIN_NAMESPACE + +// +// Timeline stuff +// + +struct Update { + Update(GfxValue *_g, qreal _v) + : g(_g), v(_v) {} + Update(const GfxEvent &_e) + : g(0), v(0), e(_e) {} + + GfxValue *g; + qreal v; + GfxEvent e; +}; + +struct QmlTimeLinePrivate +{ + QmlTimeLinePrivate(QmlTimeLine *); + + struct Op { + enum Type { + Pause, + Set, + Move, + MoveBy, + Accel, + AccelDistance, + Execute + }; + Op() {} + Op(Type t, int l, qreal v, qreal v2, int o, + const GfxEvent &ev = GfxEvent(), const QEasingCurve &es = QEasingCurve()) + : type(t), length(l), value(v), value2(v2), order(o), event(ev), + easing(es) {} + Op(const Op &o) + : type(o.type), length(o.length), value(o.value), value2(o.value2), + order(o.order), event(o.event), easing(o.easing) {} + Op &operator=(const Op &o) { + type = o.type; length = o.length; value = o.value; + value2 = o.value2; order = o.order; event = o.event; + easing = o.easing; + return *this; + } + + Type type; + int length; + qreal value; + qreal value2; + + int order; + GfxEvent event; + QEasingCurve easing; + }; + struct TimeLine + { + TimeLine() : length(0), consumedOpLength(0), base(0.) {} + QList ops; + int length; + int consumedOpLength; + qreal base; + }; + + int length; + int syncPoint; + typedef QHash Ops; + Ops ops; + QmlTimeLine *q; + + void add(QmlTimeLineObject &, const Op &); + qreal value(const Op &op, int time, qreal base, bool *) const; + + int advance(int); + + bool clockRunning; + int prevTime; + + int order; + + QmlTimeLine::SyncMode syncMode; + int syncAdj; + QList > *updateQueue; +}; + +QmlTimeLinePrivate::QmlTimeLinePrivate(QmlTimeLine *parent) +: length(0), syncPoint(0), q(parent), clockRunning(false), prevTime(0), order(0), syncMode(QmlTimeLine::LocalSync), syncAdj(0), updateQueue(0) +{ +} + +void QmlTimeLinePrivate::add(QmlTimeLineObject &g, const Op &o) +{ + if(g._t && g._t != q) { + qWarning() << "QmlTimeLine: Cannot modify a GfxValue owned by" + << "another timeline."; + return; + } + g._t = q; + + Ops::Iterator iter = ops.find(&g); + if(iter == ops.end()) { + iter = ops.insert(&g, TimeLine()); + if(syncPoint > 0) + q->pause(g, syncPoint); + } + if(!iter->ops.isEmpty() && + o.type == Op::Pause && + iter->ops.last().type == Op::Pause) { + iter->ops.last().length += o.length; + iter->length += o.length; + } else { + iter->ops.append(o); + iter->length += o.length; + } + + if(iter->length > length) + length = iter->length; + + if(!clockRunning) { + q->stop(); + prevTime = 0; + clockRunning = true; + + if(syncMode == QmlTimeLine::LocalSync) { + syncAdj = -1; + } else { + syncAdj = 0; + } + q->start(); +/* q->tick(0); + if(syncMode == QmlTimeLine::LocalSync) { + syncAdj = -1; + } else { + syncAdj = 0; + } + */ + } +} + +qreal QmlTimeLinePrivate::value(const Op &op, int time, qreal base, bool *changed) const +{ + Q_ASSERT(time >= 0); + Q_ASSERT(time <= op.length); + *changed = true; + + switch(op.type) { + case Op::Pause: + *changed = false; + return base; + case Op::Set: + return op.value; + case Op::Move: + if(time == 0) { + return base; + } else if(time == (op.length)) { + return op.value; + } else { + qreal delta = op.value - base; + qreal pTime = (qreal)(time) / (qreal)op.length; + if(op.easing.type() == QEasingCurve::Linear) + return base + delta * pTime; + else + return base + delta * op.easing.valueForProgress(pTime); + } + case Op::MoveBy: + if(time == 0) { + return base; + } else if(time == (op.length)) { + return base + op.value; + } else { + qreal delta = op.value; + qreal pTime = (qreal)(time) / (qreal)op.length; + if(op.easing.type() == QEasingCurve::Linear) + return base + delta * pTime; + else + return base + delta * op.easing.valueForProgress(pTime); + } + case Op::Accel: + if(time == 0) { + return base; + } else { + qreal t = (qreal)(time) / 1000.0f; + qreal delta = op.value * t + 0.5f * op.value2 * t * t; + return base + delta; + } + case Op::AccelDistance: + if(time == 0) { + return base; + } else if(time == (op.length)) { + return base + op.value2; + } else { + qreal t = (qreal)(time) / 1000.0f; + qreal accel = -1.0f * 1000.0f * op.value / (qreal)op.length; + qreal delta = op.value * t + 0.5f * accel * t * t; + return base + delta; + + } + case Op::Execute: + op.event.execute(); + *changed = false; + return -1; + } + + return base; +} + +/*! + \internal + \class QmlTimeLine + \ingroup group_animation + \brief The QmlTimeLine class provides a timeline for controlling animations. + + QmlTimeLine is similar to QTimeLine except: + \list + \i It updates GfxValue instances directly, rather than maintaining a single + current value. + + For example, the following animates a simple value over 200 milliseconds: + \code + GfxValue v(); + QmlTimeLine tl; + tl.move(v, 100., 200); + tl.start() + \endcode + + If your program needs to know when values are changed, it can either + connect to the QmlTimeLine's updated() signal, or inherit from GfxValue + and reimplement the GfxValue::setValue() method. + + \i Supports multiple GfxValue, arbitrary start and end values and allows + animations to be strung together for more complex effects. + + For example, the following animation moves the x and y coordinates of + an object from wherever they are to the position (100, 100) in 50 + milliseconds and then further animates them to (100, 200) in 50 + milliseconds: + + \code + GfxValue x(); + GfxValue y(); + + QmlTimeLine tl; + tl.start(); + + tl.move(x, 100., 50); + tl.move(y, 100., 50); + tl.move(y, 200., 50); + \endcode + + \i All QmlTimeLine instances share a single, synchronized clock. + + Actions scheduled within the same event loop tick are scheduled + synchronously against each other, regardless of the wall time between the + scheduling. Synchronized scheduling applies both to within the same + QmlTimeLine and across separate QmlTimeLine's within the same process. + + \endlist + + Currently easing functions are not supported. +*/ + + +/*! + Construct a new QmlTimeLine with the specified \a parent. +*/ +QmlTimeLine::QmlTimeLine(QObject *parent) +: QAbstractAnimation(parent) +{ + d = new QmlTimeLinePrivate(this); +} + +/*! + Destroys the time line. Any inprogress animations are canceled, but not + completed. +*/ +QmlTimeLine::~QmlTimeLine() +{ + for(QmlTimeLinePrivate::Ops::Iterator iter = d->ops.begin(); + iter != d->ops.end(); + ++iter) + iter.key()->_t = 0; + + delete d; d = 0; +} + +/*! + \enum QmlTimeLine::SyncMode + */ + +/*! + Return the timeline's synchronization mode. + */ +QmlTimeLine::SyncMode QmlTimeLine::syncMode() const +{ + return d->syncMode; +} + +/*! + Set the timeline's synchronization mode to \a syncMode. + */ +void QmlTimeLine::setSyncMode(SyncMode syncMode) +{ + d->syncMode = syncMode; +} + +/*! + Pause \a gfxValue for \a time milliseconds. +*/ +void QmlTimeLine::pause(QmlTimeLineObject &obj, int time) +{ + if(time <= 0) return; + QmlTimeLinePrivate::Op op(QmlTimeLinePrivate::Op::Pause, time, 0., 0., d->order++); + d->add(obj, op); +} + +/*! + Execute the \a event. + */ +void QmlTimeLine::execute(const GfxEvent &event) +{ + QmlTimeLinePrivate::Op op(QmlTimeLinePrivate::Op::Execute, 0, 0, 0., d->order++, event); + d->add(*event.eventObject(), op); +} + +/*! + Set the \a value of \a gfxValue. +*/ +void QmlTimeLine::set(GfxValue &gfxValue, qreal value) +{ + QmlTimeLinePrivate::Op op(QmlTimeLinePrivate::Op::Set, 0, value, 0., d->order++); + d->add(gfxValue, op); +} + +/*! + Decelerate \a gfxValue from the starting \a velocity to zero at the + given \a acceleration rate. Although the \a acceleration is technically + a deceleration, it should always be positive. The QmlTimeLine will ensure + that the deceleration is in the opposite direction to the initial velocity. +*/ +int QmlTimeLine::accel(GfxValue &gfxValue, qreal velocity, qreal acceleration) +{ + if((velocity > 0.0f) == (acceleration > 0.0f)) + acceleration = acceleration * -1.0f; + + int time = static_cast(-1000 * velocity / acceleration); + + QmlTimeLinePrivate::Op op(QmlTimeLinePrivate::Op::Accel, time, velocity, acceleration, d->order++); + d->add(gfxValue, op); + + return time; +} + +/*! + \overload + + Decelerate \a gfxValue from the starting \a velocity to zero at the + given \a acceleration rate over a maximum distance of maxDistance. + + If necessary, QmlTimeLine will reduce the acceleration to ensure that the + entire operation does not require a move of more than \a maxDistance. + \a maxDistance should always be positive. +*/ +int QmlTimeLine::accel(GfxValue &gfxValue, qreal velocity, qreal acceleration, qreal maxDistance) +{ + Q_ASSERT(acceleration >= 0.0f && maxDistance >= 0.0f); + + qreal maxAccel = (velocity * velocity) / (2.0f * maxDistance); + if(maxAccel > acceleration) + acceleration = maxAccel; + + if((velocity > 0.0f) == (acceleration > 0.0f)) + acceleration = acceleration * -1.0f; + + int time = static_cast(-1000 * velocity / acceleration); + + QmlTimeLinePrivate::Op op(QmlTimeLinePrivate::Op::Accel, time, velocity, acceleration, d->order++); + d->add(gfxValue, op); + + return time; +} + +/*! + Decelerate \a gfxValue from the starting \a velocity to zero over the given + \a distance. This is like accel(), but the QmlTimeLine calculates the exact + deceleration to use. + + \a distance should be positive. +*/ +int QmlTimeLine::accelDistance(GfxValue &gfxValue, qreal velocity, qreal distance) +{ + if (distance == 0.0f || velocity == 0.0f) + return -1; + Q_ASSERT((distance >= 0.0f) == (velocity >= 0.0f)); + + int time = static_cast(1000 * (2.0f * distance) / velocity); + + QmlTimeLinePrivate::Op op(QmlTimeLinePrivate::Op::AccelDistance, time, velocity, distance, d->order++); + d->add(gfxValue, op); + + return time; +} + +/*! + Linearly change the \a gfxValue from its current value to the given + \a destination value over \a time milliseconds. +*/ +void QmlTimeLine::move(GfxValue &gfxValue, qreal destination, int time) +{ + if(time <= 0) return; + QmlTimeLinePrivate::Op op(QmlTimeLinePrivate::Op::Move, time, destination, 0.0f, d->order++); + d->add(gfxValue, op); +} + +/*! + Change the \a gfxValue from its current value to the given \a destination + value over \a time milliseconds using the \a easing curve. + */ +void QmlTimeLine::move(GfxValue &gfxValue, qreal destination, const QEasingCurve &easing, int time) +{ + if(time <= 0) return; + QmlTimeLinePrivate::Op op(QmlTimeLinePrivate::Op::Move, time, destination, 0.0f, d->order++, GfxEvent(), easing); + d->add(gfxValue, op); +} + +/*! + Linearly change the \a gfxValue from its current value by the \a change amount + over \a time milliseconds. +*/ +void QmlTimeLine::moveBy(GfxValue &gfxValue, qreal change, int time) +{ + if(time <= 0) return; + QmlTimeLinePrivate::Op op(QmlTimeLinePrivate::Op::MoveBy, time, change, 0.0f, d->order++); + d->add(gfxValue, op); +} + +/*! + Change the \a gfxValue from its current value by the \a change amount over + \a time milliseconds using the \a easing curve. + */ +void QmlTimeLine::moveBy(GfxValue &gfxValue, qreal change, const QEasingCurve &easing, int time) +{ + if(time <= 0) return; + QmlTimeLinePrivate::Op op(QmlTimeLinePrivate::Op::MoveBy, time, change, 0.0f, d->order++, GfxEvent(), easing); + d->add(gfxValue, op); +} + +/*! + Cancel (but don't complete) all scheduled actions for \a gfxValue. +*/ +void QmlTimeLine::reset(GfxValue &gfxValue) +{ + if(!gfxValue._t) + return; + if(gfxValue._t != this) { + qWarning() << "QmlTimeLine: Cannot reset a GfxValue owned by another timeline."; + return; + } + remove(&gfxValue); + gfxValue._t = 0; +} + +int QmlTimeLine::duration() const +{ + return -1; +} + +/*! + Synchronize the end point of \a gfxValue to the endpoint of \a syncTo + within this timeline. + + Following operations on \a gfxValue in this timeline will be scheduled after + all the currently scheduled actions on \a syncTo are complete. In + psuedo-code this is equivalent to: + \code + QmlTimeLine::pause(gfxValue, min(0, length_of(syncTo) - length_of(gfxValue))) + \endcode +*/ +void QmlTimeLine::sync(GfxValue &gfxValue, GfxValue &syncTo) +{ + QmlTimeLinePrivate::Ops::Iterator iter = d->ops.find(&syncTo); + if(iter == d->ops.end()) + return; + int length = iter->length; + + iter = d->ops.find(&gfxValue); + if(iter == d->ops.end()) { + pause(gfxValue, length); + } else { + int glength = iter->length; + pause(gfxValue, length - glength); + } +} + +/*! + Synchronize the end point of \a gfxValue to the endpoint of the longest + action currently scheduled in the timeline. + + In psuedo-code, this is equivalent to: + \code + QmlTimeLine::pause(gfxValue, length_of(timeline) - length_of(gfxValue)) + \endcode +*/ +void QmlTimeLine::sync(GfxValue &gfxValue) +{ + QmlTimeLinePrivate::Ops::Iterator iter = d->ops.find(&gfxValue); + if(iter == d->ops.end()) { + pause(gfxValue, d->length); + } else { + pause(gfxValue, d->length - iter->length); + } +} + +/*! + Synchronize all currently and future scheduled values in this timeline to + the longest action currently scheduled. + + For example: + \code + value1->setValue(0.); + value2->setValue(0.); + value3->setValue(0.); + QmlTimeLine tl; + ... + tl.move(value1, 10, 200); + tl.move(value2, 10, 100); + tl.sync(); + tl.move(value2, 20, 100); + tl.move(value3, 20, 100); + \endcode + + will result in: + + \table + \header \o \o 0ms \o 50ms \o 100ms \o 150ms \o 200ms \o 250ms \o 300ms + \row \o value1 \o 0 \o 2.5 \o 5.0 \o 7.5 \o 10 \o 10 \o 10 + \row \o value2 \o 0 \o 5.0 \o 10.0 \o 10.0 \o 10.0 \o 15.0 \o 20.0 + \row \o value2 \o 0 \o 0 \o 0 \o 0 \o 0 \o 10.0 \o 20.0 + \endtable +*/ + +/*void QmlTimeLine::sync() +{ + for(QmlTimeLinePrivate::Ops::Iterator iter = d->ops.begin(); + iter != d->ops.end(); + ++iter) + pause(*iter.key(), d->length - iter->length); + d->syncPoint = d->length; +}*/ + +/*! + \internal + + Temporary hack. + */ +void QmlTimeLine::setSyncPoint(int sp) +{ + d->syncPoint = sp; +} + +/*! + \internal + + Temporary hack. + */ +int QmlTimeLine::syncPoint() const +{ + return d->syncPoint; +} + +/*! + Returns true if the timeline is active. An active timeline is one where + GfxValue actions are still pending. +*/ +bool QmlTimeLine::isActive() const +{ + return !d->ops.isEmpty(); +} + +/*! + Completes the timeline. All queued actions are played to completion, and then discarded. For example, + \code + GfxValue v(0.); + QmlTimeLine tl; + tl.move(v, 100., 1000.); + // 500 ms passes + // v.value() == 50. + tl.complete(); + // v.value() == 100. + \endcode +*/ +void QmlTimeLine::complete() +{ + d->advance(d->length); +} + +/*! + Resets the timeline. All queued actions are discarded and GfxValue's retain their current value. For example, + \code + GfxValue v(0.); + QmlTimeLine tl; + tl.move(v, 100., 1000.); + // 500 ms passes + // v.value() == 50. + tl.clear(); + // v.value() == 50. + \endcode +*/ +void QmlTimeLine::clear() +{ + for(QmlTimeLinePrivate::Ops::ConstIterator iter = d->ops.begin(); iter != d->ops.end(); ++iter) + iter.key()->_t = 0; + d->ops.clear(); + d->length = 0; + d->syncPoint = 0; + //XXX need stop here? +} + +int QmlTimeLine::time() const +{ + return d->prevTime; +} + +/*! + \fn void QmlTimeLine::updated() + + Emitted each time the timeline modifies GfxValues. Even if multiple + GfxValues are changed, this signal is only emitted once for each clock tick. +*/ + +void QmlTimeLine::updateCurrentTime(int v) +{ + if(d->syncAdj == -1) + d->syncAdj = v; + v -= d->syncAdj; + + int timeChanged = v - d->prevTime; +#if 0 + if(!timeChanged) + return; +#endif + d->prevTime = v; + d->advance(timeChanged); + emit updated(); + + // Do we need to stop the clock? + if(d->ops.isEmpty()) { + stop(); + d->prevTime = 0; + d->clockRunning = false; + emit completed(); + } /*else if(pauseTime > 0) { + GfxClock::cancelClock(); + d->prevTime = 0; + GfxClock::pauseFor(pauseTime); + d->syncAdj = 0; + d->clockRunning = false; + }*/ else if(/*!GfxClock::isActive()*/ state() != Running) { + stop(); + d->prevTime = 0; + d->clockRunning = true; + d->syncAdj = 0; + start(); + } +} + +bool operator<(const QPair &lhs, + const QPair &rhs) +{ + return lhs.first < rhs.first; +} + +int QmlTimeLinePrivate::advance(int t) +{ + int pauseTime = -1; + + // XXX - surely there is a more efficient way? + do { + pauseTime = -1; + // Minimal advance time + int advanceTime = t; + for(Ops::Iterator iter = ops.begin(); iter != ops.end(); ++iter) { + TimeLine &tl = *iter; + Op &op = tl.ops.first(); + int length = op.length - tl.consumedOpLength; + + if(length < advanceTime) { + advanceTime = length; + if(advanceTime == 0) + break; + } + } + t -= advanceTime; + + // Process until then. A zero length advance time will only process + // sets. + QList > updates; + + for(Ops::Iterator iter = ops.begin(); iter != ops.end(); ) { + GfxValue *v = static_cast(iter.key()); + TimeLine &tl = *iter; + Q_ASSERT(!tl.ops.isEmpty()); + + do { + Op &op = tl.ops.first(); + if(advanceTime == 0 && op.length != 0) + continue; + + if(tl.consumedOpLength == 0 && + op.type != Op::Pause && + op.type != Op::Execute) + tl.base = v->value(); + + if((tl.consumedOpLength + advanceTime) == op.length) { + if(op.type == Op::Execute) { + updates << qMakePair(op.order, Update(op.event)); + } else { + bool changed = false; + qreal val = value(op, op.length, tl.base, &changed); + if(changed) + updates << qMakePair(op.order, Update(v, val)); + } + tl.length -= qMin(advanceTime, tl.length); + tl.consumedOpLength = 0; + tl.ops.removeFirst(); + } else { + tl.consumedOpLength += advanceTime; + bool changed = false; + qreal val = value(op, tl.consumedOpLength, tl.base, &changed); + if(changed) + updates << qMakePair(op.order, Update(v, val)); + tl.length -= qMin(advanceTime, tl.length); + break; + } + + } while(!tl.ops.isEmpty() && advanceTime == 0 && tl.ops.first().length == 0); + + + if(tl.ops.isEmpty()) { + iter = ops.erase(iter); + v->_t = 0; + } else { + if(tl.ops.first().type == Op::Pause && pauseTime != 0) { + int opPauseTime = tl.ops.first().length - tl.consumedOpLength; + if(pauseTime == -1 || opPauseTime < pauseTime) + pauseTime = opPauseTime; + } else { + pauseTime = 0; + } + ++iter; + } + } + + length -= qMin(length, advanceTime); + syncPoint -= advanceTime; + + qSort(updates.begin(), updates.end()); + updateQueue = &updates; + for(int ii = 0; ii < updates.count(); ++ii) { + const Update &v = updates.at(ii).second; + if(v.g) + v.g->setValue(v.v); + else + v.e.execute(); + } + updateQueue = 0; + } while(t); + + return pauseTime; +} + +void QmlTimeLine::remove(QmlTimeLineObject *v) +{ + QmlTimeLinePrivate::Ops::Iterator iter = d->ops.find(v); + Q_ASSERT(iter != d->ops.end()); + + int len = iter->length; + d->ops.erase(iter); + if(len == d->length) { + // We need to recalculate the length + d->length = 0; + for(QmlTimeLinePrivate::Ops::Iterator iter = d->ops.begin(); + iter != d->ops.end(); + ++iter) { + + if(iter->length > d->length) + d->length = iter->length; + + } + } + if(d->ops.isEmpty()) { + stop(); + d->clockRunning = false; + } else if(/*!GfxClock::isActive()*/ state() != Running) { + stop(); + d->prevTime = 0; + d->clockRunning = true; + + if(d->syncMode == QmlTimeLine::LocalSync) { + d->syncAdj = -1; + } else { + d->syncAdj = 0; + } + start(); + } + + if(d->updateQueue) { + for(int ii = 0; ii < d->updateQueue->count(); ++ii) { + if(d->updateQueue->at(ii).second.g == v || + d->updateQueue->at(ii).second.e.eventObject() == v) { + d->updateQueue->removeAt(ii); + --ii; + } + } + } + + +} + +/*! + \class GfxValue + \ingroup group_animation + \brief The GfxValue class is modified by QmlTimeLine. +*/ + +/*! + \fn GfxValue::GfxValue(qreal value = 0) + + Construct a new GfxValue with an initial \a value. +*/ + +/*! + \fn qreal GfxValue::value() const + + Return the current value. +*/ + +/*! + \fn void GfxValue::setValue(qreal value) + + Set the current \a value. +*/ + +/*! + \fn QmlTimeLine *GfxValue::timeLine() const + + If a QmlTimeLine is operating on this value, return a pointer to it, + otherwise return null. +*/ + + +QmlTimeLineObject::QmlTimeLineObject() +: _t(0) +{ +} + +QmlTimeLineObject::~QmlTimeLineObject() +{ + if(_t) { + _t->remove(this); + _t = 0; + } +} + +GfxEvent::GfxEvent() +: d0(0), d1(0), d2(0) +{ +} + +GfxEvent::GfxEvent(const GfxEvent &o) +: d0(o.d0), d1(o.d1), d2(o.d2) +{ +} + +GfxEvent &GfxEvent::operator=(const GfxEvent &o) +{ + d0 = o.d0; + d1 = o.d1; + d2 = o.d2; + return *this; +} + +void GfxEvent::execute() const +{ + d0(d1); +} + +QmlTimeLineObject *GfxEvent::eventObject() const +{ + return d2; +} + +QT_END_NAMESPACE diff --git a/src/declarative/timeline/qmltimeline.h b/src/declarative/timeline/qmltimeline.h new file mode 100644 index 0000000..77980fb --- /dev/null +++ b/src/declarative/timeline/qmltimeline.h @@ -0,0 +1,190 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +** This file is part of the QtDeclarative module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain +** additional rights. These rights are described in the Nokia Qt LGPL +** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QMLTIMELINE_H +#define QMLTIMELINE_H + +#include +#include +#include + +QT_BEGIN_HEADER + +QT_BEGIN_NAMESPACE + +QT_MODULE(Declarative) + +class QEasingCurve; +class GfxValue; +class GfxEvent; +struct QmlTimeLinePrivate; +class QmlTimeLineObject; +class Q_DECLARATIVE_EXPORT QmlTimeLine : public QAbstractAnimation +{ +Q_OBJECT +public: + QmlTimeLine(QObject *parent = 0); + ~QmlTimeLine(); + + enum SyncMode { LocalSync, GlobalSync }; + SyncMode syncMode() const; + void setSyncMode(SyncMode); + + void pause(QmlTimeLineObject &, int); + void execute(const GfxEvent &); + void set(GfxValue &, qreal); + + int accel(GfxValue &, qreal velocity, qreal accel); + int accel(GfxValue &, qreal velocity, qreal accel, qreal maxDistance); + int accelDistance(GfxValue &, qreal velocity, qreal distance); + + void move(GfxValue &, qreal destination, int time = 500); + void move(GfxValue &, qreal destination, const QEasingCurve &, int time = 500); + void moveBy(GfxValue &, qreal change, int time = 500); + void moveBy(GfxValue &, qreal change, const QEasingCurve &, int time = 500); + + void sync(); + void setSyncPoint(int); + int syncPoint() const; + + void sync(GfxValue &); + void sync(GfxValue &, GfxValue &); + + void reset(GfxValue &); + + void complete(); + void clear(); + bool isActive() const; + + int time() const; + + virtual int duration() const; +Q_SIGNALS: + void updated(); + void completed(); + +protected: + virtual void updateCurrentTime(int); + +private: + void remove(QmlTimeLineObject *); + friend class QmlTimeLineObject; + friend struct QmlTimeLinePrivate; + QmlTimeLinePrivate *d; +}; + +class Q_DECLARATIVE_EXPORT QmlTimeLineObject +{ +public: + QmlTimeLineObject(); + virtual ~QmlTimeLineObject(); + +protected: + friend class QmlTimeLine; + friend struct QmlTimeLinePrivate; + QmlTimeLine *_t; +}; + +class Q_DECLARATIVE_EXPORT GfxValue : public QmlTimeLineObject +{ +public: + GfxValue(qreal v = 0.) : _v(v) {} + + qreal value() const { return _v; } + virtual void setValue(qreal v) { _v = v; } + + QmlTimeLine *timeLine() const { return _t; } + + operator qreal() const { return _v; } + GfxValue &operator=(qreal v) { setValue(v); return *this; } +private: + friend class QmlTimeLine; + friend struct QmlTimeLinePrivate; + qreal _v; +}; + +class Q_DECLARATIVE_EXPORT GfxEvent +{ +public: + GfxEvent(); + GfxEvent(const GfxEvent &o); + + template + GfxEvent(QmlTimeLineObject *b, T *c) + { + d0 = &callFunc; + d1 = (void *)c; + d2 = b; + } + + template + static GfxEvent gfxEvent(QmlTimeLineObject *b, T *c) + { + GfxEvent rv; + rv.d0 = &callFunc; + rv.d1 = (void *)c; + rv.d2 = b; + return rv; + } + + GfxEvent &operator=(const GfxEvent &o); + void execute() const; + QmlTimeLineObject *eventObject() const; + +private: + typedef void (*CallFunc)(void *c); + + template + static void callFunc(void *c) + { + T *cls = (T *)c; + (cls->*method)(); + } + CallFunc d0; + void *d1; + QmlTimeLineObject *d2; +}; + +QT_END_NAMESPACE + +QT_END_HEADER + +#endif diff --git a/src/declarative/timeline/timeline.pri b/src/declarative/timeline/timeline.pri index 8994c78..0a0875c 100644 --- a/src/declarative/timeline/timeline.pri +++ b/src/declarative/timeline/timeline.pri @@ -1,9 +1,7 @@ SOURCES += \ - timeline/gfxeasing.cpp \ - timeline/gfxtimeline.cpp \ + timeline/qmltimeline.cpp \ HEADERS += \ - timeline/gfxeasing.h \ - timeline/gfxtimeline.h \ + timeline/qmltimeline.h \ timeline/gfxvalueproxy.h \ diff --git a/src/declarative/util/qmlanimation.cpp b/src/declarative/util/qmlanimation.cpp index ede4008..c0b89be 100644 --- a/src/declarative/util/qmlanimation.cpp +++ b/src/declarative/util/qmlanimation.cpp @@ -40,19 +40,19 @@ ****************************************************************************/ #include "qmlanimation.h" -#include "gfxtimeline.h" #include "qvariant.h" #include "qcolor.h" #include "qfile.h" -#include "gfxeasing.h" #include "qmlpropertyvaluesource.h" #include "qml.h" #include "qmlanimation_p.h" -#include "gfxtimeline.h" #include "qmlbehaviour.h" #include #include #include +#include +#include +#include #include #include #include @@ -1447,7 +1447,57 @@ void QmlNumericAnimation::setTo(qreal t) emit toChanged(t); } -/* XML docs in GfxEasing */ +/*! + \qmlproperty string NumericAnimation::easing + \brief the easing curve used for the transition. + + Available values are: + + \list + \i \e easeNone - Easing equation function for a simple linear tweening, with no easing. + \i \e easeInQuad - Easing equation function for a quadratic (t^2) easing in: accelerating from zero velocity. + \i \e easeOutQuad - Easing equation function for a quadratic (t^2) easing out: decelerating to zero velocity. + \i \e easeInOutQuad - Easing equation function for a quadratic (t^2) easing in/out: acceleration until halfway, then deceleration. + \i \e easeOutInQuad - Easing equation function for a quadratic (t^2) easing out/in: deceleration until halfway, then acceleration. + \i \e easeInCubic - Easing equation function for a cubic (t^3) easing in: accelerating from zero velocity. + \i \e easeOutCubic - Easing equation function for a cubic (t^3) easing out: decelerating from zero velocity. + \i \e easeInOutCubic - Easing equation function for a cubic (t^3) easing in/out: acceleration until halfway, then deceleration. + \i \e easeOutInCubic - Easing equation function for a cubic (t^3) easing out/in: deceleration until halfway, then acceleration. + \i \e easeInQuart - Easing equation function for a quartic (t^4) easing in: accelerating from zero velocity. + \i \e easeOutQuart - Easing equation function for a quartic (t^4) easing out: decelerating from zero velocity. + \i \e easeInOutQuart - Easing equation function for a quartic (t^4) easing in/out: acceleration until halfway, then deceleration. + \i \e easeOutInQuart - Easing equation function for a quartic (t^4) easing out/in: deceleration until halfway, then acceleration. + \i \e easeInQuint - Easing equation function for a quintic (t^5) easing in: accelerating from zero velocity. + \i \e easeOutQuint - Easing equation function for a quintic (t^5) easing out: decelerating from zero velocity. + \i \e easeInOutQuint - Easing equation function for a quintic (t^5) easing in/out: acceleration until halfway, then deceleration. + \i \e easeOutInQuint - Easing equation function for a quintic (t^5) easing out/in: deceleration until halfway, then acceleration. + \i \e easeInSine - Easing equation function for a sinusoidal (sin(t)) easing in: accelerating from zero velocity. + \i \e easeOutSine - Easing equation function for a sinusoidal (sin(t)) easing out: decelerating from zero velocity. + \i \e easeInOutSine - Easing equation function for a sinusoidal (sin(t)) easing in/out: acceleration until halfway, then deceleration. + \i \e easeOutInSine - Easing equation function for a sinusoidal (sin(t)) easing out/in: deceleration until halfway, then acceleration. + \i \e easeInExpo - Easing equation function for an exponential (2^t) easing in: accelerating from zero velocity. + \i \e easeOutExpo - Easing equation function for an exponential (2^t) easing out: decelerating from zero velocity. + \i \e easeInOutExpo - Easing equation function for an exponential (2^t) easing in/out: acceleration until halfway, then deceleration. + \i \e easeOutInExpo - Easing equation function for an exponential (2^t) easing out/in: deceleration until halfway, then acceleration. + \i \e easeInCirc - Easing equation function for a circular (sqrt(1-t^2)) easing in: accelerating from zero velocity. + \i \e easeOutCirc - Easing equation function for a circular (sqrt(1-t^2)) easing out: decelerating from zero velocity. + \i \e easeInOutCirc - Easing equation function for a circular (sqrt(1-t^2)) easing in/out: acceleration until halfway, then deceleration. + \i \e easeOutInCirc - Easing equation function for a circular (sqrt(1-t^2)) easing out/in: deceleration until halfway, then acceleration. + \i \e easeInElastic - Easing equation function for an elastic (exponentially decaying sine wave) easing in: accelerating from zero velocity. The peak amplitude can be set with the \e amplitude parameter, and the period of decay by the \e period parameter. + \i \e easeOutElastic - Easing equation function for an elastic (exponentially decaying sine wave) easing out: decelerating from zero velocity. The peak amplitude can be set with the \e amplitude parameter, and the period of decay by the \e period parameter. + \i \e easeInOutElastic - Easing equation function for an elastic (exponentially decaying sine wave) easing in/out: acceleration until halfway, then deceleration. + \i \e easeOutInElastic - Easing equation function for an elastic (exponentially decaying sine wave) easing out/in: deceleration until halfway, then acceleration. + \i \e easeInBack - Easing equation function for a back (overshooting cubic easing: (s+1)*t^3 - s*t^2) easing in: accelerating from zero velocity. + \i \e easeOutBack - Easing equation function for a back (overshooting cubic easing: (s+1)*t^3 - s*t^2) easing out: decelerating from zero velocity. + \i \e easeInOutBack - Easing equation function for a back (overshooting cubic easing: (s+1)*t^3 - s*t^2) easing in/out: acceleration until halfway, then deceleration. + \i \e easeOutInBack - Easing equation function for a back (overshooting cubic easing: (s+1)*t^3 - s*t^2) easing out/in: deceleration until halfway, then acceleration. + \i \e easeOutBounce - Easing equation function for a bounce (exponentially decaying parabolic bounce) easing out: decelerating from zero velocity. + \i \e easeInBounce - Easing equation function for a bounce (exponentially decaying parabolic bounce) easing in: accelerating from zero velocity. + \i \e easeInOutBounce - Easing equation function for a bounce (exponentially decaying parabolic bounce) easing in/out: acceleration until halfway, then deceleration. + \i \e easeOutInBounce - Easing equation function for a bounce (exponentially decaying parabolic bounce) easing out/in: deceleration until halfway, then acceleration. + \endlist +*/ + /*! \property QmlNumericAnimation::easing This property holds the easing curve to use. diff --git a/src/declarative/util/qmlbehaviour.h b/src/declarative/util/qmlbehaviour.h index 080423a..3d25cd8 100644 --- a/src/declarative/util/qmlbehaviour.h +++ b/src/declarative/util/qmlbehaviour.h @@ -45,8 +45,6 @@ #include #include #include -#include - QT_BEGIN_HEADER diff --git a/src/declarative/util/qmlfollow.cpp b/src/declarative/util/qmlfollow.cpp index 01d8962..35f3c49 100644 --- a/src/declarative/util/qmlfollow.cpp +++ b/src/declarative/util/qmlfollow.cpp @@ -41,7 +41,6 @@ #include #include -#include #include "private/qobject_p.h" #include "qmlfollow.h" #include "private/qmlanimation_p.h" diff --git a/src/declarative/util/qmlstate.cpp b/src/declarative/util/qmlstate.cpp index f07fecb..9b1b695 100644 --- a/src/declarative/util/qmlstate.cpp +++ b/src/declarative/util/qmlstate.cpp @@ -39,7 +39,6 @@ ** ****************************************************************************/ -#include #include "qmltransition.h" #include "qmlstategroup.h" #include "qmlstate_p.h" diff --git a/src/declarative/util/qmlstate.h b/src/declarative/util/qmlstate.h index 3e6727d..68c43fa 100644 --- a/src/declarative/util/qmlstate.h +++ b/src/declarative/util/qmlstate.h @@ -44,7 +44,6 @@ #include #include -#include #include #include diff --git a/src/declarative/util/qmlstateoperations.cpp b/src/declarative/util/qmlstateoperations.cpp index a8779f9..6836472 100644 --- a/src/declarative/util/qmlstateoperations.cpp +++ b/src/declarative/util/qmlstateoperations.cpp @@ -40,7 +40,6 @@ ****************************************************************************/ #include -#include #include #include #include "qmlbindablevalue.h" diff --git a/src/declarative/util/qmltransition.h b/src/declarative/util/qmltransition.h index 0d86b7d..0b7ea14 100644 --- a/src/declarative/util/qmltransition.h +++ b/src/declarative/util/qmltransition.h @@ -44,7 +44,6 @@ #include #include -#include #include #include -- cgit v0.12 From f1326b02c582b5044b8a2f491eed649020846111 Mon Sep 17 00:00:00 2001 From: Michael Brasser Date: Mon, 27 Apr 2009 11:55:43 +1000 Subject: Rename GfxEvent to QmlTimeLineEvent. --- src/declarative/fx/qfxflickable.cpp | 4 ++-- src/declarative/fx/qfxflickable_p.h | 4 ++-- src/declarative/fx/qfxpathview_p.h | 4 ++-- src/declarative/timeline/qmltimeline.cpp | 24 ++++++++++++------------ src/declarative/timeline/qmltimeline.h | 18 +++++++++--------- 5 files changed, 27 insertions(+), 27 deletions(-) diff --git a/src/declarative/fx/qfxflickable.cpp b/src/declarative/fx/qfxflickable.cpp index 4cd7e88..a04fe97 100644 --- a/src/declarative/fx/qfxflickable.cpp +++ b/src/declarative/fx/qfxflickable.cpp @@ -100,8 +100,8 @@ QFxFlickablePrivate::QFxFlickablePrivate() , vTime(0), atXEnd(false), atXBeginning(true), pageXPosition(0.), pageWidth(0.) , atYEnd(false), atYBeginning(true), pageYPosition(0.), pageHeight(0.) { - fixupXEvent = GfxEvent::gfxEvent(&_moveX, this); - fixupYEvent = GfxEvent::gfxEvent(&_moveY, this); + fixupXEvent = QmlTimeLineEvent::timeLineEvent(&_moveX, this); + fixupYEvent = QmlTimeLineEvent::timeLineEvent(&_moveY, this); } void QFxFlickablePrivate::init() diff --git a/src/declarative/fx/qfxflickable_p.h b/src/declarative/fx/qfxflickable_p.h index 59450e0..ce880f9 100644 --- a/src/declarative/fx/qfxflickable_p.h +++ b/src/declarative/fx/qfxflickable_p.h @@ -116,8 +116,8 @@ public: qreal velocityX; qreal velocityY; QTime pressTime; - GfxEvent fixupXEvent; - GfxEvent fixupYEvent; + QmlTimeLineEvent fixupXEvent; + QmlTimeLineEvent fixupYEvent; int maxVelocity; bool locked; QFxFlickable::DragMode dragMode; diff --git a/src/declarative/fx/qfxpathview_p.h b/src/declarative/fx/qfxpathview_p.h index 31933c0..43f4ffa 100644 --- a/src/declarative/fx/qfxpathview_p.h +++ b/src/declarative/fx/qfxpathview_p.h @@ -79,7 +79,7 @@ public: , firstIndex(0), pathItems(-1), pathOffset(0), model(0) , moveReason(Other) { - fixupOffsetEvent = GfxEvent::gfxEvent(&moveOffset, this); + fixupOffsetEvent = QmlTimeLineEvent::timeLineEvent(&moveOffset, this); } void init() @@ -116,7 +116,7 @@ public: qreal dragMargin; QmlTimeLine tl; GfxValueProxy moveOffset; - GfxEvent fixupOffsetEvent; + QmlTimeLineEvent fixupOffsetEvent; int firstIndex; int pathItems; int pathOffset; diff --git a/src/declarative/timeline/qmltimeline.cpp b/src/declarative/timeline/qmltimeline.cpp index 2006fd0..7cbb3ce 100644 --- a/src/declarative/timeline/qmltimeline.cpp +++ b/src/declarative/timeline/qmltimeline.cpp @@ -58,12 +58,12 @@ QT_BEGIN_NAMESPACE struct Update { Update(GfxValue *_g, qreal _v) : g(_g), v(_v) {} - Update(const GfxEvent &_e) + Update(const QmlTimeLineEvent &_e) : g(0), v(0), e(_e) {} GfxValue *g; qreal v; - GfxEvent e; + QmlTimeLineEvent e; }; struct QmlTimeLinePrivate @@ -82,7 +82,7 @@ struct QmlTimeLinePrivate }; Op() {} Op(Type t, int l, qreal v, qreal v2, int o, - const GfxEvent &ev = GfxEvent(), const QEasingCurve &es = QEasingCurve()) + const QmlTimeLineEvent &ev = QmlTimeLineEvent(), const QEasingCurve &es = QEasingCurve()) : type(t), length(l), value(v), value2(v2), order(o), event(ev), easing(es) {} Op(const Op &o) @@ -101,7 +101,7 @@ struct QmlTimeLinePrivate qreal value2; int order; - GfxEvent event; + QmlTimeLineEvent event; QEasingCurve easing; }; struct TimeLine @@ -367,7 +367,7 @@ void QmlTimeLine::pause(QmlTimeLineObject &obj, int time) /*! Execute the \a event. */ -void QmlTimeLine::execute(const GfxEvent &event) +void QmlTimeLine::execute(const QmlTimeLineEvent &event) { QmlTimeLinePrivate::Op op(QmlTimeLinePrivate::Op::Execute, 0, 0, 0., d->order++, event); d->add(*event.eventObject(), op); @@ -469,7 +469,7 @@ void QmlTimeLine::move(GfxValue &gfxValue, qreal destination, int time) void QmlTimeLine::move(GfxValue &gfxValue, qreal destination, const QEasingCurve &easing, int time) { if(time <= 0) return; - QmlTimeLinePrivate::Op op(QmlTimeLinePrivate::Op::Move, time, destination, 0.0f, d->order++, GfxEvent(), easing); + QmlTimeLinePrivate::Op op(QmlTimeLinePrivate::Op::Move, time, destination, 0.0f, d->order++, QmlTimeLineEvent(), easing); d->add(gfxValue, op); } @@ -491,7 +491,7 @@ void QmlTimeLine::moveBy(GfxValue &gfxValue, qreal change, int time) void QmlTimeLine::moveBy(GfxValue &gfxValue, qreal change, const QEasingCurve &easing, int time) { if(time <= 0) return; - QmlTimeLinePrivate::Op op(QmlTimeLinePrivate::Op::MoveBy, time, change, 0.0f, d->order++, GfxEvent(), easing); + QmlTimeLinePrivate::Op op(QmlTimeLinePrivate::Op::MoveBy, time, change, 0.0f, d->order++, QmlTimeLineEvent(), easing); d->add(gfxValue, op); } @@ -912,17 +912,17 @@ QmlTimeLineObject::~QmlTimeLineObject() } } -GfxEvent::GfxEvent() +QmlTimeLineEvent::QmlTimeLineEvent() : d0(0), d1(0), d2(0) { } -GfxEvent::GfxEvent(const GfxEvent &o) +QmlTimeLineEvent::QmlTimeLineEvent(const QmlTimeLineEvent &o) : d0(o.d0), d1(o.d1), d2(o.d2) { } -GfxEvent &GfxEvent::operator=(const GfxEvent &o) +QmlTimeLineEvent &QmlTimeLineEvent::operator=(const QmlTimeLineEvent &o) { d0 = o.d0; d1 = o.d1; @@ -930,12 +930,12 @@ GfxEvent &GfxEvent::operator=(const GfxEvent &o) return *this; } -void GfxEvent::execute() const +void QmlTimeLineEvent::execute() const { d0(d1); } -QmlTimeLineObject *GfxEvent::eventObject() const +QmlTimeLineObject *QmlTimeLineEvent::eventObject() const { return d2; } diff --git a/src/declarative/timeline/qmltimeline.h b/src/declarative/timeline/qmltimeline.h index 77980fb..603669c 100644 --- a/src/declarative/timeline/qmltimeline.h +++ b/src/declarative/timeline/qmltimeline.h @@ -54,7 +54,7 @@ QT_MODULE(Declarative) class QEasingCurve; class GfxValue; -class GfxEvent; +class QmlTimeLineEvent; struct QmlTimeLinePrivate; class QmlTimeLineObject; class Q_DECLARATIVE_EXPORT QmlTimeLine : public QAbstractAnimation @@ -69,7 +69,7 @@ public: void setSyncMode(SyncMode); void pause(QmlTimeLineObject &, int); - void execute(const GfxEvent &); + void execute(const QmlTimeLineEvent &); void set(GfxValue &, qreal); int accel(GfxValue &, qreal velocity, qreal accel); @@ -141,14 +141,14 @@ private: qreal _v; }; -class Q_DECLARATIVE_EXPORT GfxEvent +class Q_DECLARATIVE_EXPORT QmlTimeLineEvent { public: - GfxEvent(); - GfxEvent(const GfxEvent &o); + QmlTimeLineEvent(); + QmlTimeLineEvent(const QmlTimeLineEvent &o); template - GfxEvent(QmlTimeLineObject *b, T *c) + QmlTimeLineEvent(QmlTimeLineObject *b, T *c) { d0 = &callFunc; d1 = (void *)c; @@ -156,16 +156,16 @@ public: } template - static GfxEvent gfxEvent(QmlTimeLineObject *b, T *c) + static QmlTimeLineEvent timeLineEvent(QmlTimeLineObject *b, T *c) { - GfxEvent rv; + QmlTimeLineEvent rv; rv.d0 = &callFunc; rv.d1 = (void *)c; rv.d2 = b; return rv; } - GfxEvent &operator=(const GfxEvent &o); + QmlTimeLineEvent &operator=(const QmlTimeLineEvent &o); void execute() const; QmlTimeLineObject *eventObject() const; -- cgit v0.12 From ecf0a1937d81e047e25ac551703a77f75767d881 Mon Sep 17 00:00:00 2001 From: Michael Brasser Date: Mon, 27 Apr 2009 12:49:18 +1000 Subject: Rename GfxValue to QmlTimeLineValue. --- src/declarative/fx/qfxflickable.cpp | 2 +- src/declarative/fx/qfxflickable_p.h | 14 +-- src/declarative/fx/qfxpathview.h | 1 - src/declarative/fx/qfxpathview_p.h | 3 +- src/declarative/timeline/gfxvalueproxy.h | 86 -------------- src/declarative/timeline/qmltimeline.cpp | 140 +++++++++++------------ src/declarative/timeline/qmltimeline.h | 30 ++--- src/declarative/timeline/qmltimelinevalueproxy.h | 86 ++++++++++++++ src/declarative/timeline/timeline.pri | 2 +- src/declarative/util/qmlanimation.cpp | 24 ++-- src/declarative/util/qmlanimation_p.h | 26 ++--- 11 files changed, 207 insertions(+), 207 deletions(-) delete mode 100644 src/declarative/timeline/gfxvalueproxy.h create mode 100644 src/declarative/timeline/qmltimelinevalueproxy.h diff --git a/src/declarative/fx/qfxflickable.cpp b/src/declarative/fx/qfxflickable.cpp index a04fe97..04b4a3d 100644 --- a/src/declarative/fx/qfxflickable.cpp +++ b/src/declarative/fx/qfxflickable.cpp @@ -48,7 +48,7 @@ QT_BEGIN_NAMESPACE -ElasticValue::ElasticValue(GfxValue &val) +ElasticValue::ElasticValue(QmlTimeLineValue &val) : _value(val) { _to = _value.value(); diff --git a/src/declarative/fx/qfxflickable_p.h b/src/declarative/fx/qfxflickable_p.h index ce880f9..ebd0327 100644 --- a/src/declarative/fx/qfxflickable_p.h +++ b/src/declarative/fx/qfxflickable_p.h @@ -57,7 +57,7 @@ #include "qfxflickable.h" #include "qfxitem_p.h" #include "qml.h" -#include "gfxvalueproxy.h" +#include "qmltimelinevalueproxy.h" #include "private/qmlanimation_p.h" QT_BEGIN_NAMESPACE @@ -65,7 +65,7 @@ QT_BEGIN_NAMESPACE class ElasticValue : public QAbstractAnimation { Q_OBJECT public: - ElasticValue(GfxValue &); + ElasticValue(QmlTimeLineValue &); void setValue(qreal to); void clear(); @@ -81,7 +81,7 @@ private: qreal _to; qreal _myValue; qreal _velocity; - GfxValue &_value; + QmlTimeLineValue &_value; QTime _startTime; }; @@ -98,8 +98,8 @@ public: public: QFxItem *_flick; - GfxValueProxy _moveX; - GfxValueProxy _moveY; + QmlTimeLineValueProxy _moveX; + QmlTimeLineValueProxy _moveY; QmlTimeLine _tl; int vWidth; int vHeight; @@ -128,12 +128,12 @@ public: int velocityDecay; void updateVelocity(); - struct Velocity : public GfxValue + struct Velocity : public QmlTimeLineValue { Velocity(QFxFlickablePrivate *p) : parent(p) {} virtual void setValue(qreal v) { - GfxValue::setValue(v); + QmlTimeLineValue::setValue(v); parent->updateVelocity(); } QFxFlickablePrivate *parent; diff --git a/src/declarative/fx/qfxpathview.h b/src/declarative/fx/qfxpathview.h index 6d4280d..2cc0769 100644 --- a/src/declarative/fx/qfxpathview.h +++ b/src/declarative/fx/qfxpathview.h @@ -44,7 +44,6 @@ #include #include -#include QT_BEGIN_HEADER diff --git a/src/declarative/fx/qfxpathview_p.h b/src/declarative/fx/qfxpathview_p.h index 43f4ffa..a19d778 100644 --- a/src/declarative/fx/qfxpathview_p.h +++ b/src/declarative/fx/qfxpathview_p.h @@ -58,6 +58,7 @@ #include "qfxitem_p.h" #include "qfxvisualitemmodel.h" #include "qml.h" +#include "qmltimelinevalueproxy.h" #include "private/qmlanimation_p.h" QT_BEGIN_NAMESPACE @@ -115,7 +116,7 @@ public: qreal snapPos; qreal dragMargin; QmlTimeLine tl; - GfxValueProxy moveOffset; + QmlTimeLineValueProxy moveOffset; QmlTimeLineEvent fixupOffsetEvent; int firstIndex; int pathItems; diff --git a/src/declarative/timeline/gfxvalueproxy.h b/src/declarative/timeline/gfxvalueproxy.h deleted file mode 100644 index 1bb716c..0000000 --- a/src/declarative/timeline/gfxvalueproxy.h +++ /dev/null @@ -1,86 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** Contact: Qt Software Information (qt-info@nokia.com) -** -** This file is part of the QtDeclarative module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the either Technology Preview License Agreement or the -** Beta Release License Agreement. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain -** additional rights. These rights are described in the Nokia Qt LGPL -** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this -** package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3.0 as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU General Public License version 3.0 requirements will be -** met: http://www.gnu.org/copyleft/gpl.html. -** -** If you are unsure which license is appropriate for your use, please -** contact the sales department at qt-sales@nokia.com. -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef GFXVALUEPROXY_H -#define GFXVALUEPROXY_H - -#include "qmltimeline.h" - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -QT_MODULE(Declarative) - -template -class GfxValueProxy : public GfxValue -{ -public: - GfxValueProxy(T *cls, void (T::*func)(qreal), qreal v = 0.) - : GfxValue(v), _class(cls), _setFunctionReal(func), _setFunctionInt(0) - { - Q_ASSERT(_class); - } - - GfxValueProxy(T *cls, void (T::*func)(int), qreal v = 0.) - : GfxValue(v), _class(cls), _setFunctionReal(0), _setFunctionInt(func) - { - Q_ASSERT(_class); - } - - virtual void setValue(qreal v) - { - GfxValue::setValue(v); - if(_setFunctionReal) (_class->*_setFunctionReal)(v); - else if(_setFunctionInt) (_class->*_setFunctionInt)((int)v); - } - -private: - T *_class; - void (T::*_setFunctionReal)(qreal); - void (T::*_setFunctionInt)(int); -}; - -QT_END_NAMESPACE - -QT_END_HEADER - -#endif//GFXVALUEPROXY diff --git a/src/declarative/timeline/qmltimeline.cpp b/src/declarative/timeline/qmltimeline.cpp index 7cbb3ce..fc901eb 100644 --- a/src/declarative/timeline/qmltimeline.cpp +++ b/src/declarative/timeline/qmltimeline.cpp @@ -56,12 +56,12 @@ QT_BEGIN_NAMESPACE // struct Update { - Update(GfxValue *_g, qreal _v) + Update(QmlTimeLineValue *_g, qreal _v) : g(_g), v(_v) {} Update(const QmlTimeLineEvent &_e) : g(0), v(0), e(_e) {} - GfxValue *g; + QmlTimeLineValue *g; qreal v; QmlTimeLineEvent e; }; @@ -142,7 +142,7 @@ QmlTimeLinePrivate::QmlTimeLinePrivate(QmlTimeLine *parent) void QmlTimeLinePrivate::add(QmlTimeLineObject &g, const Op &o) { if(g._t && g._t != q) { - qWarning() << "QmlTimeLine: Cannot modify a GfxValue owned by" + qWarning() << "QmlTimeLine: Cannot modify a QmlTimeLineValue owned by" << "another timeline."; return; } @@ -263,22 +263,22 @@ qreal QmlTimeLinePrivate::value(const Op &op, int time, qreal base, bool *change QmlTimeLine is similar to QTimeLine except: \list - \i It updates GfxValue instances directly, rather than maintaining a single + \i It updates QmlTimeLineValue instances directly, rather than maintaining a single current value. For example, the following animates a simple value over 200 milliseconds: \code - GfxValue v(); + QmlTimeLineValue v(); QmlTimeLine tl; tl.move(v, 100., 200); tl.start() \endcode If your program needs to know when values are changed, it can either - connect to the QmlTimeLine's updated() signal, or inherit from GfxValue - and reimplement the GfxValue::setValue() method. + connect to the QmlTimeLine's updated() signal, or inherit from QmlTimeLineValue + and reimplement the QmlTimeLineValue::setValue() method. - \i Supports multiple GfxValue, arbitrary start and end values and allows + \i Supports multiple QmlTimeLineValue, arbitrary start and end values and allows animations to be strung together for more complex effects. For example, the following animation moves the x and y coordinates of @@ -287,8 +287,8 @@ qreal QmlTimeLinePrivate::value(const Op &op, int time, qreal base, bool *change milliseconds: \code - GfxValue x(); - GfxValue y(); + QmlTimeLineValue x(); + QmlTimeLineValue y(); QmlTimeLine tl; tl.start(); @@ -355,7 +355,7 @@ void QmlTimeLine::setSyncMode(SyncMode syncMode) } /*! - Pause \a gfxValue for \a time milliseconds. + Pause \a obj for \a time milliseconds. */ void QmlTimeLine::pause(QmlTimeLineObject &obj, int time) { @@ -374,21 +374,21 @@ void QmlTimeLine::execute(const QmlTimeLineEvent &event) } /*! - Set the \a value of \a gfxValue. + Set the \a value of \a timeLineValue. */ -void QmlTimeLine::set(GfxValue &gfxValue, qreal value) +void QmlTimeLine::set(QmlTimeLineValue &timeLineValue, qreal value) { QmlTimeLinePrivate::Op op(QmlTimeLinePrivate::Op::Set, 0, value, 0., d->order++); - d->add(gfxValue, op); + d->add(timeLineValue, op); } /*! - Decelerate \a gfxValue from the starting \a velocity to zero at the + Decelerate \a timeLineValue from the starting \a velocity to zero at the given \a acceleration rate. Although the \a acceleration is technically a deceleration, it should always be positive. The QmlTimeLine will ensure that the deceleration is in the opposite direction to the initial velocity. */ -int QmlTimeLine::accel(GfxValue &gfxValue, qreal velocity, qreal acceleration) +int QmlTimeLine::accel(QmlTimeLineValue &timeLineValue, qreal velocity, qreal acceleration) { if((velocity > 0.0f) == (acceleration > 0.0f)) acceleration = acceleration * -1.0f; @@ -396,7 +396,7 @@ int QmlTimeLine::accel(GfxValue &gfxValue, qreal velocity, qreal acceleration) int time = static_cast(-1000 * velocity / acceleration); QmlTimeLinePrivate::Op op(QmlTimeLinePrivate::Op::Accel, time, velocity, acceleration, d->order++); - d->add(gfxValue, op); + d->add(timeLineValue, op); return time; } @@ -404,14 +404,14 @@ int QmlTimeLine::accel(GfxValue &gfxValue, qreal velocity, qreal acceleration) /*! \overload - Decelerate \a gfxValue from the starting \a velocity to zero at the + Decelerate \a timeLineValue from the starting \a velocity to zero at the given \a acceleration rate over a maximum distance of maxDistance. If necessary, QmlTimeLine will reduce the acceleration to ensure that the entire operation does not require a move of more than \a maxDistance. \a maxDistance should always be positive. */ -int QmlTimeLine::accel(GfxValue &gfxValue, qreal velocity, qreal acceleration, qreal maxDistance) +int QmlTimeLine::accel(QmlTimeLineValue &timeLineValue, qreal velocity, qreal acceleration, qreal maxDistance) { Q_ASSERT(acceleration >= 0.0f && maxDistance >= 0.0f); @@ -425,19 +425,19 @@ int QmlTimeLine::accel(GfxValue &gfxValue, qreal velocity, qreal acceleration, q int time = static_cast(-1000 * velocity / acceleration); QmlTimeLinePrivate::Op op(QmlTimeLinePrivate::Op::Accel, time, velocity, acceleration, d->order++); - d->add(gfxValue, op); + d->add(timeLineValue, op); return time; } /*! - Decelerate \a gfxValue from the starting \a velocity to zero over the given + Decelerate \a timeLineValue from the starting \a velocity to zero over the given \a distance. This is like accel(), but the QmlTimeLine calculates the exact deceleration to use. \a distance should be positive. */ -int QmlTimeLine::accelDistance(GfxValue &gfxValue, qreal velocity, qreal distance) +int QmlTimeLine::accelDistance(QmlTimeLineValue &timeLineValue, qreal velocity, qreal distance) { if (distance == 0.0f || velocity == 0.0f) return -1; @@ -446,68 +446,68 @@ int QmlTimeLine::accelDistance(GfxValue &gfxValue, qreal velocity, qreal distanc int time = static_cast(1000 * (2.0f * distance) / velocity); QmlTimeLinePrivate::Op op(QmlTimeLinePrivate::Op::AccelDistance, time, velocity, distance, d->order++); - d->add(gfxValue, op); + d->add(timeLineValue, op); return time; } /*! - Linearly change the \a gfxValue from its current value to the given + Linearly change the \a timeLineValue from its current value to the given \a destination value over \a time milliseconds. */ -void QmlTimeLine::move(GfxValue &gfxValue, qreal destination, int time) +void QmlTimeLine::move(QmlTimeLineValue &timeLineValue, qreal destination, int time) { if(time <= 0) return; QmlTimeLinePrivate::Op op(QmlTimeLinePrivate::Op::Move, time, destination, 0.0f, d->order++); - d->add(gfxValue, op); + d->add(timeLineValue, op); } /*! - Change the \a gfxValue from its current value to the given \a destination + Change the \a timeLineValue from its current value to the given \a destination value over \a time milliseconds using the \a easing curve. */ -void QmlTimeLine::move(GfxValue &gfxValue, qreal destination, const QEasingCurve &easing, int time) +void QmlTimeLine::move(QmlTimeLineValue &timeLineValue, qreal destination, const QEasingCurve &easing, int time) { if(time <= 0) return; QmlTimeLinePrivate::Op op(QmlTimeLinePrivate::Op::Move, time, destination, 0.0f, d->order++, QmlTimeLineEvent(), easing); - d->add(gfxValue, op); + d->add(timeLineValue, op); } /*! - Linearly change the \a gfxValue from its current value by the \a change amount + Linearly change the \a timeLineValue from its current value by the \a change amount over \a time milliseconds. */ -void QmlTimeLine::moveBy(GfxValue &gfxValue, qreal change, int time) +void QmlTimeLine::moveBy(QmlTimeLineValue &timeLineValue, qreal change, int time) { if(time <= 0) return; QmlTimeLinePrivate::Op op(QmlTimeLinePrivate::Op::MoveBy, time, change, 0.0f, d->order++); - d->add(gfxValue, op); + d->add(timeLineValue, op); } /*! - Change the \a gfxValue from its current value by the \a change amount over + Change the \a timeLineValue from its current value by the \a change amount over \a time milliseconds using the \a easing curve. */ -void QmlTimeLine::moveBy(GfxValue &gfxValue, qreal change, const QEasingCurve &easing, int time) +void QmlTimeLine::moveBy(QmlTimeLineValue &timeLineValue, qreal change, const QEasingCurve &easing, int time) { if(time <= 0) return; QmlTimeLinePrivate::Op op(QmlTimeLinePrivate::Op::MoveBy, time, change, 0.0f, d->order++, QmlTimeLineEvent(), easing); - d->add(gfxValue, op); + d->add(timeLineValue, op); } /*! - Cancel (but don't complete) all scheduled actions for \a gfxValue. + Cancel (but don't complete) all scheduled actions for \a timeLineValue. */ -void QmlTimeLine::reset(GfxValue &gfxValue) +void QmlTimeLine::reset(QmlTimeLineValue &timeLineValue) { - if(!gfxValue._t) + if(!timeLineValue._t) return; - if(gfxValue._t != this) { - qWarning() << "QmlTimeLine: Cannot reset a GfxValue owned by another timeline."; + if(timeLineValue._t != this) { + qWarning() << "QmlTimeLine: Cannot reset a QmlTimeLineValue owned by another timeline."; return; } - remove(&gfxValue); - gfxValue._t = 0; + remove(&timeLineValue); + timeLineValue._t = 0; } int QmlTimeLine::duration() const @@ -516,48 +516,48 @@ int QmlTimeLine::duration() const } /*! - Synchronize the end point of \a gfxValue to the endpoint of \a syncTo + Synchronize the end point of \a timeLineValue to the endpoint of \a syncTo within this timeline. - Following operations on \a gfxValue in this timeline will be scheduled after + Following operations on \a timeLineValue in this timeline will be scheduled after all the currently scheduled actions on \a syncTo are complete. In psuedo-code this is equivalent to: \code - QmlTimeLine::pause(gfxValue, min(0, length_of(syncTo) - length_of(gfxValue))) + QmlTimeLine::pause(timeLineValue, min(0, length_of(syncTo) - length_of(timeLineValue))) \endcode */ -void QmlTimeLine::sync(GfxValue &gfxValue, GfxValue &syncTo) +void QmlTimeLine::sync(QmlTimeLineValue &timeLineValue, QmlTimeLineValue &syncTo) { QmlTimeLinePrivate::Ops::Iterator iter = d->ops.find(&syncTo); if(iter == d->ops.end()) return; int length = iter->length; - iter = d->ops.find(&gfxValue); + iter = d->ops.find(&timeLineValue); if(iter == d->ops.end()) { - pause(gfxValue, length); + pause(timeLineValue, length); } else { int glength = iter->length; - pause(gfxValue, length - glength); + pause(timeLineValue, length - glength); } } /*! - Synchronize the end point of \a gfxValue to the endpoint of the longest - action currently scheduled in the timeline. + Synchronize the end point of \a timeLineValue to the endpoint of the longest + action cursrently scheduled in the timeline. In psuedo-code, this is equivalent to: \code - QmlTimeLine::pause(gfxValue, length_of(timeline) - length_of(gfxValue)) + QmlTimeLine::pause(timeLineValue, length_of(timeline) - length_of(timeLineValue)) \endcode */ -void QmlTimeLine::sync(GfxValue &gfxValue) +void QmlTimeLine::sync(QmlTimeLineValue &timeLineValue) { - QmlTimeLinePrivate::Ops::Iterator iter = d->ops.find(&gfxValue); + QmlTimeLinePrivate::Ops::Iterator iter = d->ops.find(&timeLineValue); if(iter == d->ops.end()) { - pause(gfxValue, d->length); + pause(timeLineValue, d->length); } else { - pause(gfxValue, d->length - iter->length); + pause(timeLineValue, d->length - iter->length); } } @@ -620,7 +620,7 @@ int QmlTimeLine::syncPoint() const /*! Returns true if the timeline is active. An active timeline is one where - GfxValue actions are still pending. + QmlTimeLineValue actions are still pending. */ bool QmlTimeLine::isActive() const { @@ -630,7 +630,7 @@ bool QmlTimeLine::isActive() const /*! Completes the timeline. All queued actions are played to completion, and then discarded. For example, \code - GfxValue v(0.); + QmlTimeLineValue v(0.); QmlTimeLine tl; tl.move(v, 100., 1000.); // 500 ms passes @@ -645,9 +645,9 @@ void QmlTimeLine::complete() } /*! - Resets the timeline. All queued actions are discarded and GfxValue's retain their current value. For example, + Resets the timeline. All queued actions are discarded and QmlTimeLineValue's retain their current value. For example, \code - GfxValue v(0.); + QmlTimeLineValue v(0.); QmlTimeLine tl; tl.move(v, 100., 1000.); // 500 ms passes @@ -674,8 +674,8 @@ int QmlTimeLine::time() const /*! \fn void QmlTimeLine::updated() - Emitted each time the timeline modifies GfxValues. Even if multiple - GfxValues are changed, this signal is only emitted once for each clock tick. + Emitted each time the timeline modifies QmlTimeLineValues. Even if multiple + QmlTimeLineValues are changed, this signal is only emitted once for each clock tick. */ void QmlTimeLine::updateCurrentTime(int v) @@ -747,7 +747,7 @@ int QmlTimeLinePrivate::advance(int t) QList > updates; for(Ops::Iterator iter = ops.begin(); iter != ops.end(); ) { - GfxValue *v = static_cast(iter.key()); + QmlTimeLineValue *v = static_cast(iter.key()); TimeLine &tl = *iter; Q_ASSERT(!tl.ops.isEmpty()); @@ -868,31 +868,31 @@ void QmlTimeLine::remove(QmlTimeLineObject *v) } /*! - \class GfxValue + \class QmlTimeLineValue \ingroup group_animation - \brief The GfxValue class is modified by QmlTimeLine. + \brief The QmlTimeLineValue class is modified by QmlTimeLine. */ /*! - \fn GfxValue::GfxValue(qreal value = 0) + \fn QmlTimeLineValue::QmlTimeLineValue(qreal value = 0) - Construct a new GfxValue with an initial \a value. + Construct a new QmlTimeLineValue with an initial \a value. */ /*! - \fn qreal GfxValue::value() const + \fn qreal QmlTimeLineValue::value() const Return the current value. */ /*! - \fn void GfxValue::setValue(qreal value) + \fn void QmlTimeLineValue::setValue(qreal value) Set the current \a value. */ /*! - \fn QmlTimeLine *GfxValue::timeLine() const + \fn QmlTimeLine *QmlTimeLineValue::timeLine() const If a QmlTimeLine is operating on this value, return a pointer to it, otherwise return null. diff --git a/src/declarative/timeline/qmltimeline.h b/src/declarative/timeline/qmltimeline.h index 603669c..ce9d1f2 100644 --- a/src/declarative/timeline/qmltimeline.h +++ b/src/declarative/timeline/qmltimeline.h @@ -53,7 +53,7 @@ QT_BEGIN_NAMESPACE QT_MODULE(Declarative) class QEasingCurve; -class GfxValue; +class QmlTimeLineValue; class QmlTimeLineEvent; struct QmlTimeLinePrivate; class QmlTimeLineObject; @@ -70,25 +70,25 @@ public: void pause(QmlTimeLineObject &, int); void execute(const QmlTimeLineEvent &); - void set(GfxValue &, qreal); + void set(QmlTimeLineValue &, qreal); - int accel(GfxValue &, qreal velocity, qreal accel); - int accel(GfxValue &, qreal velocity, qreal accel, qreal maxDistance); - int accelDistance(GfxValue &, qreal velocity, qreal distance); + int accel(QmlTimeLineValue &, qreal velocity, qreal accel); + int accel(QmlTimeLineValue &, qreal velocity, qreal accel, qreal maxDistance); + int accelDistance(QmlTimeLineValue &, qreal velocity, qreal distance); - void move(GfxValue &, qreal destination, int time = 500); - void move(GfxValue &, qreal destination, const QEasingCurve &, int time = 500); - void moveBy(GfxValue &, qreal change, int time = 500); - void moveBy(GfxValue &, qreal change, const QEasingCurve &, int time = 500); + void move(QmlTimeLineValue &, qreal destination, int time = 500); + void move(QmlTimeLineValue &, qreal destination, const QEasingCurve &, int time = 500); + void moveBy(QmlTimeLineValue &, qreal change, int time = 500); + void moveBy(QmlTimeLineValue &, qreal change, const QEasingCurve &, int time = 500); void sync(); void setSyncPoint(int); int syncPoint() const; - void sync(GfxValue &); - void sync(GfxValue &, GfxValue &); + void sync(QmlTimeLineValue &); + void sync(QmlTimeLineValue &, QmlTimeLineValue &); - void reset(GfxValue &); + void reset(QmlTimeLineValue &); void complete(); void clear(); @@ -123,10 +123,10 @@ protected: QmlTimeLine *_t; }; -class Q_DECLARATIVE_EXPORT GfxValue : public QmlTimeLineObject +class Q_DECLARATIVE_EXPORT QmlTimeLineValue : public QmlTimeLineObject { public: - GfxValue(qreal v = 0.) : _v(v) {} + QmlTimeLineValue(qreal v = 0.) : _v(v) {} qreal value() const { return _v; } virtual void setValue(qreal v) { _v = v; } @@ -134,7 +134,7 @@ public: QmlTimeLine *timeLine() const { return _t; } operator qreal() const { return _v; } - GfxValue &operator=(qreal v) { setValue(v); return *this; } + QmlTimeLineValue &operator=(qreal v) { setValue(v); return *this; } private: friend class QmlTimeLine; friend struct QmlTimeLinePrivate; diff --git a/src/declarative/timeline/qmltimelinevalueproxy.h b/src/declarative/timeline/qmltimelinevalueproxy.h new file mode 100644 index 0000000..add45dd --- /dev/null +++ b/src/declarative/timeline/qmltimelinevalueproxy.h @@ -0,0 +1,86 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +** This file is part of the QtDeclarative module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain +** additional rights. These rights are described in the Nokia Qt LGPL +** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QMLTIMELINEVALUEPROXY_H +#define QMLTIMELINEVALUEPROXY_H + +#include "qmltimeline.h" + +QT_BEGIN_HEADER + +QT_BEGIN_NAMESPACE + +QT_MODULE(Declarative) + +template +class QmlTimeLineValueProxy : public QmlTimeLineValue +{ +public: + QmlTimeLineValueProxy(T *cls, void (T::*func)(qreal), qreal v = 0.) + : QmlTimeLineValue(v), _class(cls), _setFunctionReal(func), _setFunctionInt(0) + { + Q_ASSERT(_class); + } + + QmlTimeLineValueProxy(T *cls, void (T::*func)(int), qreal v = 0.) + : QmlTimeLineValue(v), _class(cls), _setFunctionReal(0), _setFunctionInt(func) + { + Q_ASSERT(_class); + } + + virtual void setValue(qreal v) + { + QmlTimeLineValue::setValue(v); + if(_setFunctionReal) (_class->*_setFunctionReal)(v); + else if(_setFunctionInt) (_class->*_setFunctionInt)((int)v); + } + +private: + T *_class; + void (T::*_setFunctionReal)(qreal); + void (T::*_setFunctionInt)(int); +}; + +QT_END_NAMESPACE + +QT_END_HEADER + +#endif//QMLTIMELINEVALUEPROXY_H diff --git a/src/declarative/timeline/timeline.pri b/src/declarative/timeline/timeline.pri index 0a0875c..a7b3cb9 100644 --- a/src/declarative/timeline/timeline.pri +++ b/src/declarative/timeline/timeline.pri @@ -3,5 +3,5 @@ SOURCES += \ HEADERS += \ timeline/qmltimeline.h \ - timeline/gfxvalueproxy.h \ + timeline/qmltimelinevalueproxy.h \ diff --git a/src/declarative/util/qmlanimation.cpp b/src/declarative/util/qmlanimation.cpp index c0b89be..f71d203 100644 --- a/src/declarative/util/qmlanimation.cpp +++ b/src/declarative/util/qmlanimation.cpp @@ -653,7 +653,7 @@ QmlColorAnimation::~QmlColorAnimation() void QmlColorAnimationPrivate::init() { Q_Q(QmlColorAnimation); - ca = new GfxValueAnimator(q); + ca = new QmlTimeLineValueAnimator(q); ca->setStartValue(QVariant(0.0f)); ca->setEndValue(QVariant(1.0f)); } @@ -791,7 +791,7 @@ void QmlColorAnimation::prepare(QmlMetaProperty &p) else d->property = d->userProperty; d->fromSourced = false; - d->value.GfxValue::setValue(0.); + d->value.QmlTimeLineValue::setValue(0.); d->ca->setAnimValue(&d->value, QAbstractAnimation::KeepWhenStopped); } @@ -808,7 +808,7 @@ void QmlColorAnimation::transition(QmlStateActions &actions, Q_D(QmlColorAnimation); Q_UNUSED(direction); - struct NTransitionData : public GfxValue + struct NTransitionData : public QmlTimeLineValue { QmlStateActions actions; void write(QmlMetaProperty &property, const QColor &color) @@ -820,7 +820,7 @@ void QmlColorAnimation::transition(QmlStateActions &actions, void setValue(qreal v) { - GfxValue::setValue(v); + QmlTimeLineValue::setValue(v); for(int ii = 0; ii < actions.count(); ++ii) { Action &action = actions[ii]; @@ -1362,7 +1362,7 @@ QmlNumericAnimation::~QmlNumericAnimation() void QmlNumericAnimationPrivate::init() { Q_Q(QmlNumericAnimation); - na = new GfxValueAnimator(q); + na = new QmlTimeLineValueAnimator(q); na->setStartValue(QVariant(0.0f)); na->setEndValue(QVariant(1.0f)); } @@ -1600,7 +1600,7 @@ void QmlNumericAnimation::prepare(QmlMetaProperty &p) else d->property = d->userProperty; d->fromSourced = false; - d->value.GfxValue::setValue(0.); + d->value.QmlTimeLineValue::setValue(0.); d->na->setAnimValue(&d->value, QAbstractAnimation::KeepWhenStopped); } @@ -1617,12 +1617,12 @@ void QmlNumericAnimation::transition(QmlStateActions &actions, Q_D(QmlNumericAnimation); Q_UNUSED(direction); - struct NTransitionData : public GfxValue + struct NTransitionData : public QmlTimeLineValue { QmlStateActions actions; void setValue(qreal v) { - GfxValue::setValue(v); + QmlTimeLineValue::setValue(v); for(int ii = 0; ii < actions.count(); ++ii) { Action &action = actions[ii]; @@ -1951,7 +1951,7 @@ QmlVariantAnimation::~QmlVariantAnimation() void QmlVariantAnimationPrivate::init() { Q_Q(QmlVariantAnimation); - va = new GfxValueAnimator(q); + va = new QmlTimeLineValueAnimator(q); va->setStartValue(QVariant(0.0f)); va->setEndValue(QVariant(1.0f)); } @@ -2157,7 +2157,7 @@ void QmlVariantAnimation::prepare(QmlMetaProperty &p) d->convertVariant(d->from.value, (QVariant::Type)d->property.propertyType()); d->fromSourced = false; - d->value.GfxValue::setValue(0.); + d->value.QmlTimeLineValue::setValue(0.); d->va->setAnimValue(&d->value, QAbstractAnimation::KeepWhenStopped); } @@ -2168,12 +2168,12 @@ void QmlVariantAnimation::transition(QmlStateActions &actions, Q_D(QmlVariantAnimation); Q_UNUSED(direction); - struct NTransitionData : public GfxValue + struct NTransitionData : public QmlTimeLineValue { QmlStateActions actions; void setValue(qreal v) { - GfxValue::setValue(v); + QmlTimeLineValue::setValue(v); for(int ii = 0; ii < actions.count(); ++ii) { Action &action = actions[ii]; diff --git a/src/declarative/util/qmlanimation_p.h b/src/declarative/util/qmlanimation_p.h index db7cb18..f14df82 100644 --- a/src/declarative/util/qmlanimation_p.h +++ b/src/declarative/util/qmlanimation_p.h @@ -52,7 +52,7 @@ #include #include #include -#include +#include QT_BEGIN_NAMESPACE @@ -112,13 +112,13 @@ private: DeletionPolicy policy; }; -//animates GfxValue (assumes start and end values will be reals or compatible) -class GfxValueAnimator : public QVariantAnimation +//animates QmlTimeLineValue (assumes start and end values will be reals or compatible) +class QmlTimeLineValueAnimator : public QVariantAnimation { public: - GfxValueAnimator(QObject *parent = 0) : QVariantAnimation(parent), animValue(0), policy(KeepWhenStopped) {} - GfxValueAnimator(GfxValue *value, QObject *parent = 0) : QVariantAnimation(parent), animValue(value), policy(KeepWhenStopped) {} - void setAnimValue(GfxValue *value, DeletionPolicy p) + QmlTimeLineValueAnimator(QObject *parent = 0) : QVariantAnimation(parent), animValue(0), policy(KeepWhenStopped) {} + QmlTimeLineValueAnimator(QmlTimeLineValue *value, QObject *parent = 0) : QVariantAnimation(parent), animValue(value), policy(KeepWhenStopped) {} + void setAnimValue(QmlTimeLineValue *value, DeletionPolicy p) { if (state() == Running) stop(); @@ -141,7 +141,7 @@ protected: } private: - GfxValue *animValue; + QmlTimeLineValue *animValue; DeletionPolicy policy; }; @@ -214,10 +214,10 @@ public: bool fromSourced; QColor fromValue; QColor toValue; - GfxValueAnimator *ca; + QmlTimeLineValueAnimator *ca; virtual void valueChanged(qreal); - GfxValueProxy value; + QmlTimeLineValueProxy value; }; class QmlRunScriptActionPrivate : public QmlAbstractAnimationPrivate @@ -295,10 +295,10 @@ public: bool fromSourced; qreal fromValue; - GfxValueAnimator *na; + QmlTimeLineValueAnimator *na; virtual void valueChanged(qreal); - GfxValueProxy value; + QmlTimeLineValueProxy value; }; class QmlAnimationGroupPrivate : public QmlAbstractAnimationPrivate @@ -360,10 +360,10 @@ public: bool fromSourced; QVariant fromValue; - GfxValueAnimator *va; + QmlTimeLineValueAnimator *va; virtual void valueChanged(qreal); - GfxValueProxy value; + QmlTimeLineValueProxy value; static QVariant interpolateVariant(const QVariant &from, const QVariant &to, qreal progress); static void convertVariant(QVariant &variant, QVariant::Type type); -- cgit v0.12 From 35bf64817a3af2f4df2fb7669eb830b25fcc672c Mon Sep 17 00:00:00 2001 From: Michael Brasser Date: Mon, 27 Apr 2009 13:55:02 +1000 Subject: Update tile images for minehunt example. --- examples/declarative/minehunt/minehunt.qml | 4 ++-- examples/declarative/minehunt/pics/back.png | Bin 0 -> 558 bytes examples/declarative/minehunt/pics/cachepix-black.png | Bin 1658 -> 0 bytes examples/declarative/minehunt/pics/cachepix-black.sci | 5 ----- examples/declarative/minehunt/pics/cachepix-boxless.png | Bin 1819 -> 0 bytes examples/declarative/minehunt/pics/cachepix-boxless.sci | 5 ----- examples/declarative/minehunt/pics/front.png | Bin 0 -> 580 bytes 7 files changed, 2 insertions(+), 12 deletions(-) create mode 100644 examples/declarative/minehunt/pics/back.png delete mode 100644 examples/declarative/minehunt/pics/cachepix-black.png delete mode 100644 examples/declarative/minehunt/pics/cachepix-black.sci delete mode 100644 examples/declarative/minehunt/pics/cachepix-boxless.png delete mode 100644 examples/declarative/minehunt/pics/cachepix-boxless.sci create mode 100644 examples/declarative/minehunt/pics/front.png diff --git a/examples/declarative/minehunt/minehunt.qml b/examples/declarative/minehunt/minehunt.qml index 9cde164..9db0e84 100644 --- a/examples/declarative/minehunt/minehunt.qml +++ b/examples/declarative/minehunt/minehunt.qml @@ -10,7 +10,7 @@ - + @@ -23,7 +23,7 @@ - + diff --git a/examples/declarative/minehunt/pics/back.png b/examples/declarative/minehunt/pics/back.png new file mode 100644 index 0000000..f6b3f0b Binary files /dev/null and b/examples/declarative/minehunt/pics/back.png differ diff --git a/examples/declarative/minehunt/pics/cachepix-black.png b/examples/declarative/minehunt/pics/cachepix-black.png deleted file mode 100644 index 53db3ae..0000000 Binary files a/examples/declarative/minehunt/pics/cachepix-black.png and /dev/null differ diff --git a/examples/declarative/minehunt/pics/cachepix-black.sci b/examples/declarative/minehunt/pics/cachepix-black.sci deleted file mode 100644 index 21d5436..0000000 --- a/examples/declarative/minehunt/pics/cachepix-black.sci +++ /dev/null @@ -1,5 +0,0 @@ -gridLeft: 10 -gridTop: 10 -gridBottom: 10 -gridRight: 10 -imageFile: cachepix-black.png diff --git a/examples/declarative/minehunt/pics/cachepix-boxless.png b/examples/declarative/minehunt/pics/cachepix-boxless.png deleted file mode 100644 index 288e0e4..0000000 Binary files a/examples/declarative/minehunt/pics/cachepix-boxless.png and /dev/null differ diff --git a/examples/declarative/minehunt/pics/cachepix-boxless.sci b/examples/declarative/minehunt/pics/cachepix-boxless.sci deleted file mode 100644 index d224fd9..0000000 --- a/examples/declarative/minehunt/pics/cachepix-boxless.sci +++ /dev/null @@ -1,5 +0,0 @@ -gridLeft: 10 -gridTop: 10 -gridBottom: 10 -gridRight: 10 -imageFile: cachepix-boxless.png diff --git a/examples/declarative/minehunt/pics/front.png b/examples/declarative/minehunt/pics/front.png new file mode 100644 index 0000000..834331b Binary files /dev/null and b/examples/declarative/minehunt/pics/front.png differ -- cgit v0.12 From c818abd743a6877aa27ded1a01d5f8fd498cc116 Mon Sep 17 00:00:00 2001 From: Michael Brasser Date: Mon, 27 Apr 2009 13:56:53 +1000 Subject: Fix crash in PathView. If a component had runtime errors it could cause PathView to crash. Now we check in rengenerate to make sure the model actually returns an item before using it. --- src/declarative/fx/qfxpathview.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/declarative/fx/qfxpathview.cpp b/src/declarative/fx/qfxpathview.cpp index f2a9065..b1cfaa5 100644 --- a/src/declarative/fx/qfxpathview.cpp +++ b/src/declarative/fx/qfxpathview.cpp @@ -594,6 +594,8 @@ void QFxPathViewPrivate::regenerate() int minI = -1; for(int i=0; iitem(i); + if (!item) + return; items.append(item); item->setZ(i); item->setParent(q); -- cgit v0.12 From 7e3aee5b4f50733fa8d88def28b4fce78070f9e2 Mon Sep 17 00:00:00 2001 From: Michael Brasser Date: Mon, 27 Apr 2009 14:33:07 +1000 Subject: Add 'smooth' property to BlendedImage. --- src/declarative/fx/qfxblendedimage.cpp | 37 +++++++++++++++++++++++++++++++++- src/declarative/fx/qfxblendedimage.h | 6 ++++++ 2 files changed, 42 insertions(+), 1 deletion(-) diff --git a/src/declarative/fx/qfxblendedimage.cpp b/src/declarative/fx/qfxblendedimage.cpp index b5d9a9a..b5b7bb3 100644 --- a/src/declarative/fx/qfxblendedimage.cpp +++ b/src/declarative/fx/qfxblendedimage.cpp @@ -73,7 +73,7 @@ QT_BEGIN_NAMESPACE secondary image. */ QFxBlendedImage::QFxBlendedImage(QFxItem *parent) -: QFxItem(parent), _blend(0), dirty(false) +: QFxItem(parent), _blend(0), _smooth(false), dirty(false) { #if defined(QFX_RENDER_OPENGL2) setOptions(HasContents); @@ -154,16 +154,51 @@ void QFxBlendedImage::setBlend(qreal b) update(); } +/*! + \qmlproperty bool BlendedImage::smooth + + Set this property if you want the image to be smoothly filtered when scaled or + transformed. Smooth filtering gives better visual quality, but is slower. If + the BlendedImage is displayed at its natural size, this property has no visual or + performance effect. + + \note Generally scaling artifacts are only visible if the image is stationary on + the screen. A common pattern when animating an image is to disable smooth + filtering at the beginning of the animation and reenable it at the conclusion. + */ +bool QFxBlendedImage::smoothTransform() const +{ + return _smooth; +} + +void QFxBlendedImage::setSmoothTransform(bool s) +{ + if(_smooth == s) + return; + _smooth = s; + update(); +} + #if defined(QFX_RENDER_QPAINTER) void QFxBlendedImage::paintContents(QPainter &p) { if (primSrc.isNull() && secSrc.isNull()) return; + + if(_smooth) { + p.save(); + p.setRenderHints(QPainter::Antialiasing | QPainter::SmoothPixmapTransform, _smooth); + } + if (_blend < 0.75) p.drawImage(0, 0, primPix); else p.drawImage(0, 0, secPix); + + if(_smooth) { + p.restore(); + } } #elif defined(QFX_RENDER_OPENGL2) diff --git a/src/declarative/fx/qfxblendedimage.h b/src/declarative/fx/qfxblendedimage.h index 96d3135..5cc0238 100644 --- a/src/declarative/fx/qfxblendedimage.h +++ b/src/declarative/fx/qfxblendedimage.h @@ -60,17 +60,22 @@ class QFxBlendedImage : public QFxItem Q_PROPERTY(QString primaryUrl READ primaryUrl WRITE setPrimaryUrl) Q_PROPERTY(QString secondaryUrl READ secondaryUrl WRITE setSecondaryUrl) Q_PROPERTY(qreal blend READ blend WRITE setBlend) + Q_PROPERTY(bool smooth READ smoothTransform WRITE setSmoothTransform) public: QFxBlendedImage(QFxItem *parent=0); QString primaryUrl() const; void setPrimaryUrl(const QString &); + QString secondaryUrl() const; void setSecondaryUrl(const QString &); qreal blend() const; void setBlend(qreal); + bool smoothTransform() const; + void setSmoothTransform(bool); + #if defined(QFX_RENDER_QPAINTER) void paintContents(QPainter &painter); #elif defined(QFX_RENDER_OPENGL2) @@ -88,6 +93,7 @@ private: QUrl secUrl; qreal _blend; + bool _smooth; bool dirty; #if defined(QFX_RENDER_OPENGL2) GLTexture prim; -- cgit v0.12