42 #include "hbvgeffect_p.h" |
42 #include "hbvgeffect_p.h" |
43 #include "hbvgchainedeffect_p.h" |
43 #include "hbvgchainedeffect_p.h" |
44 #endif |
44 #endif |
45 |
45 |
46 HbEffectGroup::HbEffectGroup( |
46 HbEffectGroup::HbEffectGroup( |
47 const QString &effectEventType, |
47 const QString &effectEventType, |
48 QGraphicsItem *registrationItem, |
48 QGraphicsItem *registrationItem, |
49 QGraphicsItem *targetItem, |
49 QGraphicsItem *targetItem, |
50 const QString &itemType) |
50 const QString &itemType) |
51 : mRegistrationItem(registrationItem), |
51 : mRegistrationItem(registrationItem), |
52 mTargetItem(targetItem), |
52 mTargetItem(targetItem), |
53 mEffectEventType(effectEventType), |
53 mEffectEventType(effectEventType), |
131 for (int i = last; i >= 0; --i) { |
131 for (int i = last; i >= 0; --i) { |
132 HbEffectAbstract *effect = mEffects[i]; |
132 HbEffectAbstract *effect = mEffects[i]; |
133 if (effect->name() == HB_EFFECT_NAME_SCALE) { |
133 if (effect->name() == HB_EFFECT_NAME_SCALE) { |
134 // Move scale effect second last in the effect list |
134 // Move scale effect second last in the effect list |
135 mEffects.takeAt(i); |
135 mEffects.takeAt(i); |
136 mEffects.insert(mEffects.size()-1, effect); |
136 mEffects.insert(mEffects.size() - 1, effect); |
137 } |
137 } |
138 } |
138 } |
139 |
139 |
140 } |
140 } |
141 } |
141 } |
146 mEffectFinishedSlotName = effectFinishedSlotName; |
146 mEffectFinishedSlotName = effectFinishedSlotName; |
147 } |
147 } |
148 |
148 |
149 void HbEffectGroup::updateItemTransform() |
149 void HbEffectGroup::updateItemTransform() |
150 { |
150 { |
151 QGraphicsView *gv(0); |
151 QGraphicsView *gv(0); |
152 // support for graphics view transforms |
152 // support for graphics view transforms |
153 if (mTargetItem->type() == HbGVWrapperItemType) { |
153 if (mTargetItem->type() == HbGVWrapperItemType) { |
154 HbGVWrapperItem *gvw = static_cast<HbGVWrapperItem*>(mTargetItem); |
154 HbGVWrapperItem *gvw = static_cast<HbGVWrapperItem *>(mTargetItem); |
155 if (gvw) |
155 if (gvw) { |
156 gv = gvw->mainWindow(); |
156 gv = gvw->mainWindow(); |
|
157 } |
157 } |
158 } |
158 QTransform transform; |
159 QTransform transform; |
159 |
160 |
160 foreach (HbEffectAbstract *effect, mEffects) { |
161 foreach(HbEffectAbstract * effect, mEffects) { |
161 if (effect) |
162 if (effect) { |
162 effect->updateItemTransform(transform); |
163 effect->updateItemTransform(transform); |
|
164 } |
163 } |
165 } |
164 if (!gv) { |
166 if (!gv) { |
165 mTargetItem->setTransform(transform); |
167 mTargetItem->setTransform(transform); |
166 } else { |
168 } else { |
167 gv->setTransform(transform); |
169 gv->setTransform(transform); |
198 return mLooping; |
200 return mLooping; |
199 } |
201 } |
200 |
202 |
201 void HbEffectGroup::pause() |
203 void HbEffectGroup::pause() |
202 { |
204 { |
203 foreach (HbEffectAbstract *effect, mEffects) { |
205 foreach(HbEffectAbstract * effect, mEffects) { |
204 effect->pause(); |
206 effect->pause(); |
205 } |
207 } |
206 } |
208 } |
207 |
209 |
208 void HbEffectGroup::resume() |
210 void HbEffectGroup::resume() |
209 { |
211 { |
210 foreach (HbEffectAbstract *effect, mEffects) { |
212 foreach(HbEffectAbstract * effect, mEffects) { |
211 effect->resume(); |
213 effect->resume(); |
212 } |
214 } |
213 } |
215 } |
214 |
216 |
215 const QVariant &HbEffectGroup::userData() const |
217 const QVariant &HbEffectGroup::userData() const |
301 } |
303 } |
302 |
304 |
303 // First resolve parameters and set the start states for all the effects. |
305 // First resolve parameters and set the start states for all the effects. |
304 // This is done before starting the effect animations to avoid screen flickering. |
306 // This is done before starting the effect animations to avoid screen flickering. |
305 QTransform transform; |
307 QTransform transform; |
306 foreach (HbEffectAbstract *effect, mEffects) { |
308 foreach(HbEffectAbstract * effect, mEffects) { |
307 // Resolve parameters etc. |
309 // Resolve parameters etc. |
308 effect->init(); |
310 effect->init(); |
309 if (effect->interval() == 0) { |
311 if (effect->interval() == 0) { |
310 // Set start state if effect starts immediately |
312 // Set start state if effect starts immediately |
311 effect->setStartState(transform); |
313 effect->setStartState(transform); |
327 |
329 |
328 mRegItemHidden = false; |
330 mRegItemHidden = false; |
329 mTargetItemHidden = false; |
331 mTargetItemHidden = false; |
330 |
332 |
331 if (mEffects.empty()) { |
333 if (mEffects.empty()) { |
332 // No effect exists but user wants notification when effect finishes. |
334 // No effect exists but user wants notification when effect finishes. |
333 // Let the user do whatever he wanted to do when effect finishes. |
335 // Let the user do whatever he wanted to do when effect finishes. |
334 invokeObserver(Hb::EffectNotStarted); |
336 invokeObserver(Hb::EffectNotStarted); |
335 } else { |
337 } else { |
336 // Start state has been set for all the effects, |
338 // Start state has been set for all the effects, |
337 // next step is to start the effect animations. |
339 // next step is to start the effect animations. |
338 // Before that, resolve the view where the effect belongs if the effect is looping. |
340 // Before that, resolve the view where the effect belongs if the effect is looping. |
339 // This is needed for being able to pause looping effects when their view is inactive. |
341 // This is needed for being able to pause looping effects when their view is inactive. |
340 if (isLooping()) { |
342 if (isLooping()) { |
341 resolveView(); |
343 resolveView(); |
342 } |
344 } |
343 foreach (HbEffectAbstract *effect, mEffects) { |
345 foreach(HbEffectAbstract * effect, mEffects) { |
344 // If the starttime is zero, start effect immediately |
346 // If the starttime is zero, start effect immediately |
345 if (effect->interval() == 0) { |
347 if (effect->interval() == 0) { |
346 effect->start(); // This may call group's effectFinished if the effect was empty. |
348 effect->start(); // This may call group's effectFinished if the effect was empty. |
347 } else { |
349 } else { |
348 //Else register the effect to timeline to wait its turn. |
350 //Else register the effect to timeline to wait its turn. |
357 if (!mView && mTargetItem) { |
359 if (!mView && mTargetItem) { |
358 QGraphicsScene *scene = mTargetItem->scene(); |
360 QGraphicsScene *scene = mTargetItem->scene(); |
359 if (scene) { |
361 if (scene) { |
360 // Resolve the main window having the same scene that the item belongs to |
362 // Resolve the main window having the same scene that the item belongs to |
361 QList<HbMainWindow *> windowList = hbInstance->allMainWindows(); |
363 QList<HbMainWindow *> windowList = hbInstance->allMainWindows(); |
362 foreach (const HbMainWindow *window, windowList) { |
364 foreach(const HbMainWindow * window, windowList) { |
363 if (window->scene() == scene) { |
365 if (window->scene() == scene) { |
364 mView = window->currentView(); |
366 mView = window->currentView(); |
365 break; |
367 break; |
366 } |
368 } |
367 } |
369 } |
369 } |
371 } |
370 } |
372 } |
371 |
373 |
372 bool HbEffectGroup::hasTranslateEffect() const |
374 bool HbEffectGroup::hasTranslateEffect() const |
373 { |
375 { |
374 foreach (HbEffectAbstract *effect, mEffects) { |
376 foreach(HbEffectAbstract * effect, mEffects) { |
375 if (effect->name() == HB_EFFECT_NAME_TRANSLATE) { |
377 if (effect->name() == HB_EFFECT_NAME_TRANSLATE) { |
376 return true; |
378 return true; |
377 } |
379 } |
378 } |
380 } |
379 return false; |
381 return false; |
380 } |
382 } |
381 |
383 |
382 bool HbEffectGroup::hasRotateEffect() const |
384 bool HbEffectGroup::hasRotateEffect() const |
383 { |
385 { |
384 foreach (HbEffectAbstract *effect, mEffects) { |
386 foreach(HbEffectAbstract * effect, mEffects) { |
385 if (effect->name() == HB_EFFECT_NAME_ROTATE) { |
387 if (effect->name() == HB_EFFECT_NAME_ROTATE) { |
386 return true; |
388 return true; |
387 } |
389 } |
388 } |
390 } |
389 |
391 |
390 return false; |
392 return false; |
391 } |
393 } |
392 |
394 |
393 bool HbEffectGroup::hasScaleEffect() const |
395 bool HbEffectGroup::hasScaleEffect() const |
394 { |
396 { |
395 foreach (HbEffectAbstract *effect, mEffects) { |
397 foreach(HbEffectAbstract * effect, mEffects) { |
396 if (effect->name() == HB_EFFECT_NAME_SCALE) { |
398 if (effect->name() == HB_EFFECT_NAME_SCALE) { |
397 return true; |
399 return true; |
398 } |
400 } |
399 } |
401 } |
400 return false; |
402 return false; |
401 } |
403 } |
402 |
404 |
403 bool HbEffectGroup::hasOpacityEffect() const |
405 bool HbEffectGroup::hasOpacityEffect() const |
404 { |
406 { |
405 foreach (HbEffectAbstract *effect, mEffects) { |
407 foreach(HbEffectAbstract * effect, mEffects) { |
406 if (effect->name() == HB_EFFECT_NAME_OPACITY) { |
408 if (effect->name() == HB_EFFECT_NAME_OPACITY) { |
407 return true; |
409 return true; |
408 } |
410 } |
409 } |
411 } |
410 return false; |
412 return false; |
436 // Hide opacity effect by setting item fully opaque regardless of what |
438 // Hide opacity effect by setting item fully opaque regardless of what |
437 // its opacity value was before the effect. |
439 // its opacity value was before the effect. |
438 mTargetItem->setOpacity(1.0f); |
440 mTargetItem->setOpacity(1.0f); |
439 } |
441 } |
440 // Reset filter effects. |
442 // Reset filter effects. |
441 #ifdef HB_FILTER_EFFECTS |
443 #ifdef HB_FILTER_EFFECTS |
442 deactivateVgEffect(); |
444 deactivateVgEffect(); |
443 #endif |
445 #endif |
444 } |
446 } |
445 |
447 |
446 void HbEffectGroup::cancelAll(bool sendCallback, bool itemIsValid, bool clearEffect, const QTransform &initialItemTransform) |
448 void HbEffectGroup::cancelAll(bool sendCallback, bool itemIsValid, bool clearEffect, const QTransform &initialItemTransform) |
447 { |
449 { |
448 // No checks for running state here. The cancellation (esp. the clearing of |
450 // No checks for running state here. The cancellation (esp. the clearing of |
450 // state. |
452 // state. |
451 |
453 |
452 QTransform transform; |
454 QTransform transform; |
453 bool opacityEffectUsed = false; |
455 bool opacityEffectUsed = false; |
454 |
456 |
455 foreach (HbEffectAbstract *effect, mEffects) { |
457 foreach(HbEffectAbstract * effect, mEffects) { |
456 if (effect) { |
458 if (effect) { |
457 HbTimer::instance()->unregisterEntry(effect); |
459 HbTimer::instance()->unregisterEntry(effect); |
458 effect->cancel(transform, itemIsValid); |
460 effect->cancel(transform, itemIsValid); |
459 if (effect->name() == HB_EFFECT_NAME_OPACITY) { |
461 if (effect->name() == HB_EFFECT_NAME_OPACITY) { |
460 opacityEffectUsed = true; |
462 opacityEffectUsed = true; |
529 status.item = mRegistrationItem; |
531 status.item = mRegistrationItem; |
530 status.effectEvent = mEffectEventType; |
532 status.effectEvent = mEffectEventType; |
531 status.userData = mUserData; |
533 status.userData = mUserData; |
532 status.reason = reason; |
534 status.reason = reason; |
533 |
535 |
534 QObject *observer = mObserver; |
536 QObject *observer = mObserver; |
535 |
537 |
536 // Clear the observer to make sure it is not sent more than once. |
538 // Clear the observer to make sure it is not sent more than once. |
537 // This is done before invokeMethod to avoid crash if the callback |
539 // This is done before invokeMethod to avoid crash if the callback |
538 // deletes this object. |
540 // deletes this object. |
539 mObserver = 0; |
541 mObserver = 0; |
540 |
542 |