equal
deleted
inserted
replaced
20 ** |
20 ** |
21 ** If you have questions regarding the use of this file, please contact |
21 ** If you have questions regarding the use of this file, please contact |
22 ** Nokia at developer.feedback@nokia.com. |
22 ** Nokia at developer.feedback@nokia.com. |
23 ** |
23 ** |
24 ****************************************************************************/ |
24 ****************************************************************************/ |
|
25 |
25 #include <hbglobal.h> |
26 #include <hbglobal.h> |
26 #include "hbeffectanimation_p.h" |
27 #include "hbeffectanimation_p.h" |
27 #include "hbeffectgroup_p.h" |
28 #include "hbeffectgroup_p.h" |
28 #include "hbeffectdef_p.h" |
29 #include "hbeffectdef_p.h" |
29 #include "hbeffectfxmldata_p.h" |
30 #include "hbeffectfxmldata_p.h" |
30 #include <QGraphicsItem> |
31 #include <QGraphicsItem> |
31 #include <QtDebug> |
32 #include <QtDebug> |
32 |
33 |
33 HbEffectAnimation::HbEffectAnimation() : |
34 HbEffectAnimation::HbEffectAnimation(HbEffectGroup *group) : |
34 QVariantAnimation(), |
35 mGroup(group), |
35 mCurve(QEasingCurve::Linear), |
36 mCurve(QEasingCurve::Linear), |
36 mLoopStart(-1), |
37 mLoopStart(-1), |
37 mLoopEnd(-1), |
38 mLoopEnd(-1), |
38 mInactive(false), |
39 mInactive(false), |
39 mFinished(false) |
40 mFinished(false) |
43 |
44 |
44 HbEffectAnimation::~HbEffectAnimation() |
45 HbEffectAnimation::~HbEffectAnimation() |
45 { |
46 { |
46 } |
47 } |
47 |
48 |
48 void HbEffectAnimation::addLooping(const HbEffectFxmlParamData *param, HbEffectGroup *group) |
49 void HbEffectAnimation::addLooping(const HbEffectFxmlParamData *param) |
49 { |
50 { |
50 if (param) { |
51 if (param) { |
51 if (param->loopDefined()) { |
52 if (param->loopDefined()) { |
52 int duration = QVariantAnimation::duration(); |
53 int duration = QVariantAnimation::duration(); |
53 |
54 |
60 |
61 |
61 // Add looping range to animation if loop end is after its start |
62 // Add looping range to animation if loop end is after its start |
62 if (loopEnd > loopStart) { |
63 if (loopEnd > loopStart) { |
63 mLoopStart = loopStart; |
64 mLoopStart = loopStart; |
64 mLoopEnd = loopEnd; |
65 mLoopEnd = loopEnd; |
65 group->setLooping(true); |
66 mGroup->setLooping(true); |
66 } |
67 } |
67 } |
68 } |
68 } |
69 } |
69 } |
70 } |
70 |
71 |
73 if (mInactive) { |
74 if (mInactive) { |
74 return; |
75 return; |
75 } |
76 } |
76 |
77 |
77 // If there is a loop defined, check whether the current time of |
78 // If there is a loop defined, check whether the current time of |
78 // the animation is past the loop end. If it is, do not update the effect with that value |
79 // the animation is past the loop end. If it is, do not update the |
79 // but instead change the current time back to (loopStartTime + currentTime - LoopEndTime). |
80 // effect with that value but instead change the current time back |
|
81 // to (loopStartTime + currentTime - LoopEndTime). |
80 |
82 |
81 if (looping()) { |
83 if (looping()) { |
82 int current = currentTime(); |
84 int current = currentTime(); |
83 |
85 |
84 if (current > mLoopEnd) { |
86 if (current > mLoopEnd) { |
88 // change it to the loop end to avoid infinite recursion. |
90 // change it to the loop end to avoid infinite recursion. |
89 if (newCurrentTime > mLoopEnd) { |
91 if (newCurrentTime > mLoopEnd) { |
90 newCurrentTime = mLoopEnd; |
92 newCurrentTime = mLoopEnd; |
91 } |
93 } |
92 |
94 |
93 //qDebug() << "Loop restarted: current time changed from" << current << "to" << newCurrentTime; |
|
94 |
|
95 // Set the current time of the animation according to the defined loop, |
95 // Set the current time of the animation according to the defined loop, |
96 // it will create a callback to this function again. |
96 // it will create a callback to this function again. |
97 setCurrentTime(newCurrentTime); |
97 setCurrentTime(newCurrentTime); |
98 return; |
98 return; |
99 } |
99 } |
100 } |
100 } |
101 |
101 |
102 // Create a callback to derived classes |
102 // Let the derived classes handle the value change. |
103 handleAnimationUpdate(value); |
103 handleAnimationUpdate(value); |
104 } |
104 } |
105 |
105 |
106 void HbEffectAnimation::handleFinished() |
106 void HbEffectAnimation::handleFinished() |
107 { |
107 { |
113 // If the calculated new current time is again beyond the loop end, |
113 // If the calculated new current time is again beyond the loop end, |
114 // change it to the loop end to avoid infinite recursion. |
114 // change it to the loop end to avoid infinite recursion. |
115 if (newCurrentTime > mLoopEnd) { |
115 if (newCurrentTime > mLoopEnd) { |
116 newCurrentTime = mLoopEnd; |
116 newCurrentTime = mLoopEnd; |
117 } |
117 } |
118 |
|
119 //qDebug() << "Loop restarted: current time changed from" << current << "to" << newCurrentTime; |
|
120 |
118 |
121 // Temporarily prevent the animation from reacting to update request, |
119 // Temporarily prevent the animation from reacting to update request, |
122 // because start() causes update with time=0 and the loop might start from a later point of time. |
120 // because start() causes update with time=0 and the loop might start from a later point of time. |
123 mInactive = true; |
121 mInactive = true; |
124 // Restart the animation |
122 // Restart the animation |
145 |
143 |
146 return fromValue + mCurve.valueForProgress(progress) * (toValue - fromValue); |
144 return fromValue + mCurve.valueForProgress(progress) * (toValue - fromValue); |
147 } |
145 } |
148 |
146 |
149 // End of File |
147 // End of File |
150 |
|
151 |
|
152 |
|
153 |
|