|
1 /* |
|
2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * |
|
16 */ |
|
17 //USER |
|
18 #include "logseffecthandler.h" |
|
19 #include "logslogger.h" |
|
20 |
|
21 //SYSTEM |
|
22 #include <QPropertyAnimation> |
|
23 #include <QSequentialAnimationGroup> |
|
24 #include <hbinstance.h> |
|
25 |
|
26 const int logsMoveByExtra = 20; |
|
27 const int logsEffectDelayBetween = 200; |
|
28 const int logsEffectAppearDurationInMs = 500; |
|
29 const int logsEffectDissappearDurationInMs = 300; |
|
30 const int logsEffectMoveNotPossibleDurationInMs = 200; |
|
31 const int logsMoveNotPossibleAmount = 30; |
|
32 |
|
33 const int logsDissappearByMovingIndex = 0; |
|
34 const int logsAppearByMovingIndex = 2; |
|
35 |
|
36 // ----------------------------------------------------------------------------- |
|
37 // |
|
38 // ----------------------------------------------------------------------------- |
|
39 // |
|
40 LogsEffectHandler::LogsEffectHandler() : QObject() |
|
41 { |
|
42 LOGS_QDEBUG( "logs [UI] -> LogsEffectHandler::LogsEffectHandler()" ); |
|
43 |
|
44 QPropertyAnimation* itemAppearByMovingAnimation = new QPropertyAnimation(); |
|
45 QPropertyAnimation* itemAppearByMovingAnimation2 = new QPropertyAnimation(); |
|
46 QPropertyAnimation* itemDissappearByMovingAnimation = new QPropertyAnimation(); |
|
47 QPropertyAnimation* itemDissappearByMovingAnimation2 = new QPropertyAnimation(); |
|
48 |
|
49 mItemAppearByFadingAnimation = new QPropertyAnimation(); |
|
50 mItemDissappearByFadingAnimation = new QPropertyAnimation(); |
|
51 mItemMoveNotPossibleAnimationStart = new QPropertyAnimation(); |
|
52 mItemMoveNotPossibleAnimationEnd = new QPropertyAnimation(); |
|
53 |
|
54 mMoveGroup = new QSequentialAnimationGroup; |
|
55 mMoveGroup2 = new QSequentialAnimationGroup; |
|
56 mFadeGroup = new QSequentialAnimationGroup; |
|
57 mMoveNotPossibleGroup = new QSequentialAnimationGroup; |
|
58 |
|
59 mMoveGroup->addAnimation(itemDissappearByMovingAnimation); |
|
60 mMoveGroup->addPause(logsEffectDelayBetween); |
|
61 mMoveGroup->addAnimation(itemAppearByMovingAnimation); |
|
62 |
|
63 mMoveGroup2->addAnimation(itemDissappearByMovingAnimation2); |
|
64 mMoveGroup2->addPause(logsEffectDelayBetween); |
|
65 mMoveGroup2->addAnimation(itemAppearByMovingAnimation2); |
|
66 |
|
67 mFadeGroup->addAnimation(mItemDissappearByFadingAnimation); |
|
68 mFadeGroup->addAnimation(mItemAppearByFadingAnimation); |
|
69 |
|
70 mMoveNotPossibleGroup->addAnimation(mItemMoveNotPossibleAnimationStart); |
|
71 mMoveNotPossibleGroup->addAnimation(mItemMoveNotPossibleAnimationEnd); |
|
72 |
|
73 connect(mMoveGroup, SIGNAL(currentAnimationChanged(QAbstractAnimation *)), |
|
74 this, SLOT( moveAnimationChanged(QAbstractAnimation *))); |
|
75 connect(mFadeGroup, SIGNAL(currentAnimationChanged(QAbstractAnimation *)), |
|
76 this, SLOT( fadeAnimationChanged(QAbstractAnimation *))); |
|
77 |
|
78 LOGS_QDEBUG( "logs [UI] <- LogsEffectHandler::LogsEffectHandler()" ); |
|
79 } |
|
80 |
|
81 // ----------------------------------------------------------------------------- |
|
82 // |
|
83 // ----------------------------------------------------------------------------- |
|
84 // |
|
85 LogsEffectHandler::~LogsEffectHandler() |
|
86 { |
|
87 LOGS_QDEBUG( "logs [UI] -> LogsEffectHandler::~LogsEffectHandler()" ); |
|
88 |
|
89 // Groups delete attached animations |
|
90 delete mMoveGroup; |
|
91 delete mMoveGroup2; |
|
92 delete mFadeGroup; |
|
93 delete mMoveNotPossibleGroup; |
|
94 |
|
95 LOGS_QDEBUG( "logs [UI] <- LogsEffectHandler::~LogsEffectHandler()" ); |
|
96 } |
|
97 |
|
98 // ----------------------------------------------------------------------------- |
|
99 // |
|
100 // ----------------------------------------------------------------------------- |
|
101 // |
|
102 void LogsEffectHandler::moveAnimationChanged(QAbstractAnimation *currentAnimation) |
|
103 { |
|
104 if ( mMoveGroup->indexOfAnimation(currentAnimation) == 1 ) { |
|
105 emit dissappearByMovingComplete(); |
|
106 } |
|
107 } |
|
108 |
|
109 // ----------------------------------------------------------------------------- |
|
110 // |
|
111 // ----------------------------------------------------------------------------- |
|
112 // |
|
113 void LogsEffectHandler::fadeAnimationChanged(QAbstractAnimation *currentAnimation) |
|
114 { |
|
115 if ( mFadeGroup->indexOfAnimation(currentAnimation) == 1 ) { |
|
116 emit dissappearByFadingComplete(); |
|
117 } |
|
118 } |
|
119 |
|
120 // ----------------------------------------------------------------------------- |
|
121 // |
|
122 // ----------------------------------------------------------------------------- |
|
123 // |
|
124 void LogsEffectHandler::startDissappearAppearByFadingEffect(QObject& effectTarget) |
|
125 { |
|
126 initOpacityEffect(*mItemDissappearByFadingAnimation, &effectTarget, |
|
127 1.0, 0.0, logsEffectDissappearDurationInMs); |
|
128 initOpacityEffect(*mItemAppearByFadingAnimation, &effectTarget, |
|
129 0.0, 1.0, logsEffectAppearDurationInMs); |
|
130 mFadeGroup->start(); |
|
131 } |
|
132 |
|
133 // ----------------------------------------------------------------------------- |
|
134 // |
|
135 // ----------------------------------------------------------------------------- |
|
136 // |
|
137 void LogsEffectHandler::startDissappearAppearByMovingEffect( |
|
138 QObject& effectTarget, QObject& secondaryEffectTarget, |
|
139 bool dissappearToLeft, int origX) |
|
140 { |
|
141 doStartDissappearAppearByMovingEffect( |
|
142 *mMoveGroup, effectTarget, dissappearToLeft, origX); |
|
143 doStartDissappearAppearByMovingEffect( |
|
144 *mMoveGroup2, secondaryEffectTarget, dissappearToLeft, origX); |
|
145 } |
|
146 |
|
147 // ----------------------------------------------------------------------------- |
|
148 // |
|
149 // ----------------------------------------------------------------------------- |
|
150 // |
|
151 void LogsEffectHandler::doStartDissappearAppearByMovingEffect( |
|
152 QSequentialAnimationGroup& group, QObject& effectTarget, |
|
153 bool dissappearToLeft, int origX) |
|
154 { |
|
155 initDissappearByMovingEffect( |
|
156 static_cast<QPropertyAnimation&>(*group.animationAt(logsDissappearByMovingIndex)), |
|
157 &effectTarget, dissappearToLeft, origX); |
|
158 initAppearByMovingEffect( |
|
159 static_cast<QPropertyAnimation&>(*group.animationAt(logsAppearByMovingIndex)), |
|
160 &effectTarget, !dissappearToLeft, origX); |
|
161 group.start(); |
|
162 } |
|
163 |
|
164 // ----------------------------------------------------------------------------- |
|
165 // |
|
166 // ----------------------------------------------------------------------------- |
|
167 // |
|
168 void LogsEffectHandler::startMoveNotPossibleEffect( |
|
169 QObject& effectTarget, bool moveLeft, int origX) |
|
170 { |
|
171 LOGS_QDEBUG( "logs [UI] -> LogsEffectHandler::startMoveNotPossibleEffect()" ); |
|
172 |
|
173 // Move a bit to attempted direction and then back |
|
174 // |
|
175 //int origX = effectTarget.property("x").toInt(); |
|
176 int moveNotPossiblePos = |
|
177 moveLeft ? -logsMoveNotPossibleAmount : logsMoveNotPossibleAmount; |
|
178 QEasingCurve easing(QEasingCurve::OutBack); |
|
179 initMoveHorizontallyEffect( |
|
180 *mItemMoveNotPossibleAnimationStart, &effectTarget, origX, moveNotPossiblePos, |
|
181 logsEffectMoveNotPossibleDurationInMs, easing); |
|
182 QEasingCurve easing2(QEasingCurve::OutQuad); |
|
183 initMoveHorizontallyEffect( |
|
184 *mItemMoveNotPossibleAnimationEnd, &effectTarget, moveNotPossiblePos, origX, |
|
185 logsEffectMoveNotPossibleDurationInMs, easing2); |
|
186 mMoveNotPossibleGroup->start(); |
|
187 |
|
188 LOGS_QDEBUG( "logs [UI] <- LogsEffectHandler::startMoveNotPossibleEffect()" ); |
|
189 } |
|
190 |
|
191 // ----------------------------------------------------------------------------- |
|
192 // |
|
193 // ----------------------------------------------------------------------------- |
|
194 // |
|
195 void LogsEffectHandler::initAppearByMovingEffect( |
|
196 QPropertyAnimation& animation, QObject* effectTarget, bool appearFromLeft, int origX) |
|
197 { |
|
198 LOGS_QDEBUG( "logs [UI] -> LogsEffectHandler::startAppearByMovingEffect()" ); |
|
199 |
|
200 Q_ASSERT(!hbInstance->allMainWindows().isEmpty()); |
|
201 int moveBy = hbInstance->allMainWindows().at(0)->layoutRect().width() + logsMoveByExtra; |
|
202 int startPos = appearFromLeft ? -moveBy : moveBy; |
|
203 QEasingCurve easing(QEasingCurve::OutQuad); // decelerating |
|
204 initMoveHorizontallyEffect( |
|
205 animation, effectTarget, startPos, origX, |
|
206 logsEffectAppearDurationInMs, easing); |
|
207 |
|
208 LOGS_QDEBUG( "logs [UI] <- LogsEffectHandler::startAppearByMovingEffect()" ); |
|
209 } |
|
210 |
|
211 // ----------------------------------------------------------------------------- |
|
212 // |
|
213 // ----------------------------------------------------------------------------- |
|
214 // |
|
215 void LogsEffectHandler::initDissappearByMovingEffect( |
|
216 QPropertyAnimation& animation, QObject* effectTarget, bool dissappearToLeft, int origX) |
|
217 { |
|
218 LOGS_QDEBUG( "logs [UI] -> LogsEffectHandler::startDissappearByMovingEffect()" ); |
|
219 |
|
220 Q_ASSERT(!hbInstance->allMainWindows().isEmpty()); |
|
221 int moveBy = hbInstance->allMainWindows().at(0)->layoutRect().width() + logsMoveByExtra; |
|
222 int endPos = dissappearToLeft ? -moveBy : moveBy; |
|
223 QEasingCurve easing(QEasingCurve::InQuad); // accelerating |
|
224 initMoveHorizontallyEffect( |
|
225 animation, effectTarget, origX, endPos, |
|
226 logsEffectDissappearDurationInMs, easing); |
|
227 |
|
228 LOGS_QDEBUG( "logs [UI] <- LogsEffectHandler::startDissappearByMovingEffect()" ); |
|
229 } |
|
230 |
|
231 // ----------------------------------------------------------------------------- |
|
232 // |
|
233 // ----------------------------------------------------------------------------- |
|
234 // |
|
235 void LogsEffectHandler::initOpacityEffect( |
|
236 QPropertyAnimation& animation, QObject* effectTarget, |
|
237 qreal startVal, qreal endVal, int duration) |
|
238 { |
|
239 if (animation.state() == QAbstractAnimation::Running ){ |
|
240 animation.stop(); |
|
241 } |
|
242 animation.setTargetObject(effectTarget); |
|
243 animation.setPropertyName("opacity"); |
|
244 animation.setStartValue(startVal); |
|
245 animation.setEndValue(endVal); |
|
246 animation.setDuration(duration); |
|
247 } |
|
248 |
|
249 // ----------------------------------------------------------------------------- |
|
250 // |
|
251 // ----------------------------------------------------------------------------- |
|
252 // |
|
253 void LogsEffectHandler::initMoveHorizontallyEffect( |
|
254 QPropertyAnimation& animation, QObject* effectTarget, |
|
255 int startVal, int endVal, int duration, const QEasingCurve& easingCurve) |
|
256 { |
|
257 if (animation.state() == QAbstractAnimation::Running ){ |
|
258 animation.stop(); |
|
259 } |
|
260 animation.setTargetObject(effectTarget); |
|
261 animation.setPropertyName("x"); |
|
262 animation.setStartValue(startVal); |
|
263 animation.setEndValue(endVal); |
|
264 animation.setDuration(duration); |
|
265 animation.setEasingCurve(easingCurve); |
|
266 } |