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: ?Description |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include <glxeffectengine.h> |
|
20 #include "glxeffectpluginbase.h" |
|
21 #include "glxforwardtransitionplugin.h" |
|
22 #include "glxbackwardtransitionplugin.h" |
|
23 #include "glxfadeplugin.h" |
|
24 #include <QDebug> |
|
25 |
|
26 #include <xqsettingsmanager.h> |
|
27 #include <xqsettingskey.h> |
|
28 #include <QStringList> |
|
29 const TUint32 KGlxTransitionEffect = 0x1; |
|
30 const TUint32 KGlxTransitionDelay = 0x2; |
|
31 const TUint32 KGlxSlow = 0x3; |
|
32 const TUint32 KGlxMeduim = 0x4; |
|
33 const TUint32 KGlxFast = 0x5; |
|
34 const TUint32 KGlxWaveEffect = 0x6; |
|
35 const TUint32 KGlxFadeEffect = 0x7; |
|
36 const TUint32 KGlxZoomToFaceEffect = 0x8; |
|
37 const TUint32 KCRUidGallery = 0x20007194; |
|
38 GlxSlideShowSetting::GlxSlideShowSetting( int slideDelayTime, GlxEffect effect, GlxSlideShowMoveDir moveDir ) |
|
39 : mSlideDelayTime(slideDelayTime), |
|
40 mEffect ( effect), |
|
41 mMoveDir ( moveDir) |
|
42 { |
|
43 mSettingsManager = new XQSettingsManager(); |
|
44 mTransitionEffectCenrepKey= new XQSettingsKey(XQSettingsKey::TargetCentralRepository, KCRUidGallery , KGlxTransitionEffect); |
|
45 mTransitionDelayCenrepKey= new XQSettingsKey(XQSettingsKey::TargetCentralRepository, KCRUidGallery , KGlxTransitionDelay); |
|
46 mSlowCenRepKey= new XQSettingsKey(XQSettingsKey::TargetCentralRepository, KCRUidGallery ,KGlxSlow); |
|
47 mMediumCenRepKey= new XQSettingsKey(XQSettingsKey::TargetCentralRepository, KCRUidGallery ,KGlxMeduim); |
|
48 mFastCenRepKey= new XQSettingsKey(XQSettingsKey::TargetCentralRepository, KCRUidGallery ,KGlxFast); |
|
49 |
|
50 mWaveEffectCenRepKey= new XQSettingsKey(XQSettingsKey::TargetCentralRepository, KCRUidGallery ,KGlxWaveEffect ); |
|
51 mFadeEffectCenRepKey= new XQSettingsKey(XQSettingsKey::TargetCentralRepository, KCRUidGallery ,KGlxFadeEffect); |
|
52 mZoomEffectCenRepKey= new XQSettingsKey(XQSettingsKey::TargetCentralRepository, KCRUidGallery , KGlxZoomToFaceEffect ); |
|
53 } |
|
54 |
|
55 GlxSlideShowSetting::~GlxSlideShowSetting( ) |
|
56 { |
|
57 delete mFastCenRepKey; |
|
58 delete mMediumCenRepKey; |
|
59 delete mSlowCenRepKey; |
|
60 delete mZoomEffectCenRepKey; |
|
61 delete mFadeEffectCenRepKey; |
|
62 delete mWaveEffectCenRepKey; |
|
63 delete mTransitionDelayCenrepKey; |
|
64 delete mTransitionEffectCenrepKey; |
|
65 delete mSettingsManager; |
|
66 } |
|
67 int GlxSlideShowSetting::slideShowDelayIndex() |
|
68 { |
|
69 QVariant effectvalue = mSettingsManager->readItemValue(*mTransitionDelayCenrepKey); |
|
70 return effectvalue.toInt(); |
|
71 } |
|
72 void GlxSlideShowSetting::setSlideShowDelayIndex( int index ) |
|
73 { |
|
74 mSettingsManager->writeItemValue(*mTransitionDelayCenrepKey, index); |
|
75 } |
|
76 QStringList GlxSlideShowSetting::slideShowEffectList() |
|
77 { |
|
78 if(mSettingsManager->readItemValue(*mWaveEffectCenRepKey).toInt() == WAVE_EFFECT) |
|
79 mEffectList<<"wave"; |
|
80 if(mSettingsManager->readItemValue(*mFadeEffectCenRepKey).toInt() == SMOOTH_FADE) |
|
81 mEffectList<<"Fade"; |
|
82 if(mSettingsManager->readItemValue(*mZoomEffectCenRepKey).toInt() == ZOOM_TO_FACE) |
|
83 mEffectList<<"Zoom to face"; |
|
84 return mEffectList; |
|
85 } |
|
86 int GlxSlideShowSetting::slideShowEffectIndex() |
|
87 { |
|
88 QVariant effectvalue = mSettingsManager->readItemValue(*mTransitionEffectCenrepKey); |
|
89 return effectvalue.toInt(); |
|
90 } |
|
91 void GlxSlideShowSetting::setslideShowEffectIndex( int index ) |
|
92 { |
|
93 mSettingsManager->writeItemValue(*mTransitionEffectCenrepKey, index); |
|
94 } |
|
95 void GlxSlideShowSetting::readSlideShowSetting() |
|
96 { |
|
97 //To:Do read from the file system |
|
98 QVariant effectvalue = mSettingsManager->readItemValue(*mTransitionDelayCenrepKey); |
|
99 switch (effectvalue.toInt()) { |
|
100 case SLOW: |
|
101 mSlideDelayTime = mSettingsManager->readItemValue(*mSlowCenRepKey).toInt(); |
|
102 break; |
|
103 case MEDIUM: |
|
104 mSlideDelayTime = mSettingsManager->readItemValue(*mMediumCenRepKey).toInt(); |
|
105 break; |
|
106 case FAST: |
|
107 mSlideDelayTime = mSettingsManager->readItemValue(*mFastCenRepKey).toInt(); |
|
108 break; |
|
109 default: |
|
110 mSlideDelayTime = 3000; |
|
111 break; |
|
112 } |
|
113 mEffect = FADE_EFFECT; |
|
114 mMoveDir = MOVE_FORWARD; |
|
115 qDebug("GlxSlideShowSetting::readSlideShowSetting() slide delay time %d effect %d move direction %d", mSlideDelayTime, mEffect, mMoveDir); |
|
116 } |
|
117 |
|
118 |
|
119 GlxTransitionEffectSetting::GlxTransitionEffectSetting(GlxEffect effect): mEffect(effect), mTransitionLater(false), mItem(0) |
|
120 { |
|
121 qDebug("GlxTransitionEffectSetting::GlxTransitionEffectSetting() effect id %d ", effect); |
|
122 mEffectFileList.clear(); |
|
123 mItemType.clear(); |
|
124 mEventType.clear(); |
|
125 init(); |
|
126 } |
|
127 |
|
128 void GlxTransitionEffectSetting::init() |
|
129 { |
|
130 qDebug("GlxTransitionEffectSetting::init() effect id %d ", mEffect); |
|
131 |
|
132 switch( mEffect ) { |
|
133 case GRID_TO_FULLSCREEN : |
|
134 mEffectFileList.append( QString(":/data/gridtofullscreenhide.fxml")); |
|
135 mItemType.append( QString("HbGridViewItem") ); |
|
136 mEventType.append(QString("click1") ); |
|
137 |
|
138 mEffectFileList.append( QString(":/data/gridtofullscreenshow.fxml")); |
|
139 mItemType.append( QString("HbView") ); |
|
140 mEventType.append(QString("click2") ); |
|
141 break; |
|
142 |
|
143 case FULLSCREEN_TO_GRID : |
|
144 mEffectFileList.append( QString(":/data/fullscreentogrid.fxml")); |
|
145 mItemType.append( QString("HbGridView") ); |
|
146 mEventType.append(QString("click3") ); |
|
147 break; |
|
148 |
|
149 case GRID_TO_ALBUMLIST: |
|
150 mEffectFileList.append( QString(":/data/gridtoalbumlisthide.fxml")); |
|
151 mItemType.append( QString("HbView") ); |
|
152 mEventType.append(QString("click4") ); |
|
153 |
|
154 mEffectFileList.append( QString(":/data/gridtoalbumlist.fxml")); |
|
155 mItemType.append( QString("HbListView") ); |
|
156 mEventType.append(QString("click5") ); |
|
157 break; |
|
158 |
|
159 case ALBUMLIST_TO_GRID: |
|
160 mEffectFileList.append( QString(":/data/albumlisttogrid.fxml")); |
|
161 mItemType.append( QString("HbListView") ); |
|
162 mEventType.append(QString("click6") ); |
|
163 |
|
164 mEffectFileList.append( QString(":/data/albumlisttogridshow.fxml")); |
|
165 mItemType.append( QString("HbView") ); |
|
166 mEventType.append(QString("click7") ); |
|
167 break; |
|
168 |
|
169 case FULLSCREEN_TO_DETAIL : |
|
170 mEffectFileList.append( QString(":/data/view_flip_hide.fxml")); |
|
171 mItemType.append( QString("HbView") ); |
|
172 mEventType.append(QString("click8") ); |
|
173 |
|
174 mEffectFileList.append( QString(":/data/view_flip_show.fxml")); |
|
175 mItemType.append( QString("HbView") ); |
|
176 mEventType.append(QString("click9") ); |
|
177 mTransitionLater = true; |
|
178 break; |
|
179 |
|
180 case DETAIL_TO_FULLSCREEN : |
|
181 mEffectFileList.append( QString(":/data/view_flip_hide.fxml")); |
|
182 mItemType.append( QString("HbView") ); |
|
183 mEventType.append(QString("click10") ); |
|
184 |
|
185 mEffectFileList.append( QString(":/data/view_flip_show.fxml")); |
|
186 mItemType.append( QString("HbView") ); |
|
187 mEventType.append(QString("click11") ); |
|
188 mTransitionLater = true; |
|
189 break; |
|
190 |
|
191 default : |
|
192 break; |
|
193 } |
|
194 } |
|
195 |
|
196 GlxTransitionEffectSetting::~GlxTransitionEffectSetting() |
|
197 { |
|
198 qDebug("GlxTransitionEffectSetting::~GlxTransitionEffectSetting() effect id %d ", mEffect); |
|
199 mEffectFileList.clear(); |
|
200 mItemType.clear(); |
|
201 mEventType.clear(); |
|
202 } |
|
203 |
|
204 |
|
205 GlxSlideShowEffectEngine::GlxSlideShowEffectEngine( ) : mNbrEffectRunning( 0 ), |
|
206 mEffectPlugin(NULL), |
|
207 mTransitionEffect(NO_EFFECT) |
|
208 { |
|
209 qDebug("GlxSlideShowEffectEngine::GlxSlideShowEffectEngine()"); |
|
210 mTransitionEffectList.clear(); |
|
211 } |
|
212 |
|
213 GlxSlideShowEffectEngine::~GlxSlideShowEffectEngine() |
|
214 { |
|
215 qDebug("GlxSlideShowEffectEngine::~GlxSlideShowEffectEngine()"); |
|
216 delete mEffectPlugin; |
|
217 mEffectPlugin = NULL; |
|
218 |
|
219 cleanTransitionEfffect(); |
|
220 } |
|
221 |
|
222 void GlxSlideShowEffectEngine::registerEffect(const QString &itemType) |
|
223 { |
|
224 effectPluginResolver(); |
|
225 QList <QString > effectPathList = mEffectPlugin->getEffectFileList(); |
|
226 |
|
227 qDebug("GlxSlideShowEffectEngine::registerEffect() item type %s file path %s", itemType.utf16(), effectPathList[0].utf16()); |
|
228 for ( int i = 0; i < effectPathList.count() ; ++i ) { |
|
229 HbEffect::add(itemType, effectPathList.at(i), QString( "Click%1" ).arg(i)); |
|
230 } |
|
231 } |
|
232 |
|
233 void GlxSlideShowEffectEngine::deRegisterEffect(const QString &itemType) |
|
234 { |
|
235 qDebug("GlxSlideShowEffectEngine::deRegisterEffect() item type %s", itemType.utf16()); |
|
236 QList <QString > effectPathList = mEffectPlugin->getEffectFileList(); |
|
237 for ( int i = 0; i < effectPathList.count() ; ++i ) { |
|
238 HbEffect::remove(itemType, effectPathList.at(i), QString( "Click%1" ).arg(i)); |
|
239 } |
|
240 delete mEffectPlugin ; |
|
241 mEffectPlugin = NULL; |
|
242 } |
|
243 |
|
244 void GlxSlideShowEffectEngine::registerTransitionEffect() |
|
245 { |
|
246 qDebug("GlxSlideShowEffectEngine::registerTransitionEffect()"); |
|
247 initTransitionEffect(); |
|
248 } |
|
249 |
|
250 void GlxSlideShowEffectEngine::deregistertransitionEffect() |
|
251 { |
|
252 qDebug("GlxSlideShowEffectEngine::deregisterTransitionEffect()"); |
|
253 cleanTransitionEfffect(); |
|
254 } |
|
255 |
|
256 void GlxSlideShowEffectEngine::runEffect(QGraphicsItem * item, const QString & itemType ) |
|
257 { |
|
258 qDebug("GlxSlideShowEffectEngine::runEffect()1 item type %s", itemType.utf16()); |
|
259 HbEffect::start(item, itemType, QString( "Click1" ), this, "slideShowEffectFinished"); |
|
260 ++mNbrEffectRunning; |
|
261 } |
|
262 |
|
263 void GlxSlideShowEffectEngine::runEffect(QList< QGraphicsItem * > & items, const QString & itemType ) |
|
264 { |
|
265 qDebug("GlxSlideShowEffectEngine::runEffect()2 item Type %s", itemType.utf16()); |
|
266 mEffectPlugin->setUpItems(items); |
|
267 for ( int i = 0; i < items.count() ; ++i ) { |
|
268 if ( mEffectPlugin->isAnimationLater(i) == FALSE ) { |
|
269 HbEffect::start(items.at(i), itemType, QString( "Click%1").arg(i), this, "slideShowEffectFinished"); |
|
270 } |
|
271 ++mNbrEffectRunning; |
|
272 } |
|
273 } |
|
274 |
|
275 void GlxSlideShowEffectEngine::runEffect(QList< QGraphicsItem * > & items, GlxEffect transitionEffect) |
|
276 { |
|
277 qDebug("GlxSlideShowEffectEngine::runEffect()3 effect type %d ", transitionEffect); |
|
278 |
|
279 GlxTransitionEffectSetting *effectSetting = mTransitionEffectList.value( transitionEffect ); |
|
280 |
|
281 if ( effectSetting == NULL || items.count() != effectSetting->count() ) { |
|
282 return; |
|
283 } |
|
284 |
|
285 mTransitionEffect = transitionEffect; |
|
286 for ( int i = 0; i < effectSetting->count() ; ++i) { |
|
287 ++mNbrEffectRunning; |
|
288 if ( ( i == effectSetting->count() -1) && effectSetting->isTransitionLater() ) |
|
289 { |
|
290 effectSetting->setAnimationItem( items.at(i) ); |
|
291 items.at(i)->hide(); |
|
292 } |
|
293 else { |
|
294 HbEffect::start(items.at(i), effectSetting->itemType().at(i), effectSetting->eventType().at(i), this, "transitionEffectFinished"); |
|
295 } |
|
296 } |
|
297 } |
|
298 |
|
299 void GlxSlideShowEffectEngine::cancelEffect(QGraphicsItem * item) |
|
300 { |
|
301 if ( HbEffect::effectRunning( item, QString( "Click1" ) ) ) { |
|
302 HbEffect::cancel( item, QString( "Click1" ) ); |
|
303 } |
|
304 } |
|
305 |
|
306 void GlxSlideShowEffectEngine::cancelEffect(const QList< QGraphicsItem * > & items) |
|
307 { |
|
308 for ( int i = 0; i < items.count() ; ++i ) { |
|
309 if ( HbEffect::effectRunning( items.at(i), QString( "Click%1").arg(i) ) ) { |
|
310 HbEffect::cancel( items.at(i), QString( "Click%1").arg(i) ); |
|
311 } |
|
312 } |
|
313 } |
|
314 |
|
315 void GlxSlideShowEffectEngine::cancelEffect(QList< QGraphicsItem * > & items, GlxEffect transitionEffect) |
|
316 { |
|
317 GlxTransitionEffectSetting *effectSetting = mTransitionEffectList.value( transitionEffect ); |
|
318 |
|
319 if ( effectSetting == NULL || items.count() != effectSetting->count() ) { |
|
320 return; |
|
321 } |
|
322 |
|
323 for ( int i = 0; i < effectSetting->count() ; ++i) { |
|
324 HbEffect::cancel(items.at(i), effectSetting->eventType().at(i) ); |
|
325 } |
|
326 } |
|
327 |
|
328 bool GlxSlideShowEffectEngine::isEffectRuning(QGraphicsItem * item) |
|
329 { |
|
330 if ( HbEffect::effectRunning( item, QString( "Click1" ) ) ) { |
|
331 return true; |
|
332 } |
|
333 return false; |
|
334 } |
|
335 |
|
336 bool GlxSlideShowEffectEngine::isEffectRuning(const QList< QGraphicsItem * > & items) |
|
337 { |
|
338 for ( int i = 0; i < items.count() ; ++i ) { |
|
339 if ( HbEffect::effectRunning( items.at(i), QString( "Click%1").arg(i) ) ) { |
|
340 return true; |
|
341 } |
|
342 } |
|
343 return false; |
|
344 } |
|
345 |
|
346 void GlxSlideShowEffectEngine::slideShowEffectFinished( const HbEffect::EffectStatus &status ) |
|
347 { |
|
348 Q_UNUSED( status ) |
|
349 qDebug("GlxSlideShowEffectEngine::slideShowEffectFinished() number of effect %d ", mNbrEffectRunning); |
|
350 |
|
351 --mNbrEffectRunning; |
|
352 |
|
353 if ( mEffectPlugin->isAnimationLater( mNbrEffectRunning) ) { |
|
354 HbEffect::start( mEffectPlugin->animationItem(), mEffectPlugin->ItemType(), QString( "Click%1").arg(mNbrEffectRunning), this, "slideShowEffectFinished"); |
|
355 } |
|
356 |
|
357 if (mNbrEffectRunning == 0) { |
|
358 emit effectFinished(); |
|
359 } |
|
360 } |
|
361 |
|
362 void GlxSlideShowEffectEngine::transitionEffectFinished( const HbEffect::EffectStatus &status ) |
|
363 { |
|
364 Q_UNUSED( status ) |
|
365 qDebug("GlxSlideShowEffectEngine::transitionEffectFinished() number of effect %d status %d", mNbrEffectRunning, status.reason); |
|
366 |
|
367 --mNbrEffectRunning; |
|
368 if ( mNbrEffectRunning == 1 ) { |
|
369 GlxTransitionEffectSetting *effectSetting = mTransitionEffectList.value( mTransitionEffect ); |
|
370 if ( effectSetting->isTransitionLater() ){ |
|
371 effectSetting->animationItem()->show(); |
|
372 HbEffect::start( effectSetting->animationItem(), effectSetting->itemType().at(1), effectSetting->eventType().at(1), this, "transitionEffectFinished"); |
|
373 mTransitionEffect = NO_EFFECT; |
|
374 } |
|
375 } |
|
376 |
|
377 if (mNbrEffectRunning == 0) { |
|
378 emit effectFinished(); |
|
379 } |
|
380 } |
|
381 |
|
382 void GlxSlideShowEffectEngine::effectPluginResolver() |
|
383 { |
|
384 //TO:DO improved the code by using factory design pattern |
|
385 |
|
386 delete mEffectPlugin; |
|
387 mEffectPlugin = NULL; |
|
388 |
|
389 switch ( mSlideShowSetting.effect() ) { |
|
390 case TRANSITION_EFFECT : |
|
391 if ( slideShowMoveDir() == MOVE_FORWARD ) { |
|
392 mEffectPlugin = new GlxForwardTransitionPlugin(); |
|
393 } |
|
394 else { |
|
395 mEffectPlugin = new GlxBackwardTransitionPlugin(); |
|
396 } |
|
397 break; |
|
398 |
|
399 case FADE_EFFECT : |
|
400 mEffectPlugin = new GlxFadePlugin(); |
|
401 break; |
|
402 |
|
403 default : |
|
404 break; |
|
405 } |
|
406 } |
|
407 |
|
408 void GlxSlideShowEffectEngine::initTransitionEffect() |
|
409 { |
|
410 GlxTransitionEffectSetting *effectSetting = NULL; |
|
411 |
|
412 effectSetting = new GlxTransitionEffectSetting(GRID_TO_FULLSCREEN); |
|
413 for ( int i = 0; i < effectSetting->count(); ++i ) { |
|
414 HbEffect::add( effectSetting->itemType().at(i), effectSetting->effectFileList().at(i), effectSetting->eventType().at(i)) ; |
|
415 } |
|
416 mTransitionEffectList[GRID_TO_FULLSCREEN] = effectSetting; |
|
417 |
|
418 effectSetting = new GlxTransitionEffectSetting( FULLSCREEN_TO_GRID ); |
|
419 for ( int i = 0; i < effectSetting->count(); ++i ) { |
|
420 HbEffect::add( effectSetting->itemType().at(i), effectSetting->effectFileList().at(i), effectSetting->eventType().at(i)) ; |
|
421 } |
|
422 mTransitionEffectList[FULLSCREEN_TO_GRID] = effectSetting; |
|
423 |
|
424 effectSetting = new GlxTransitionEffectSetting( GRID_TO_ALBUMLIST ); |
|
425 for ( int i = 0; i < effectSetting->count(); ++i ) { |
|
426 HbEffect::add( effectSetting->itemType().at(i), effectSetting->effectFileList().at(i), effectSetting->eventType().at(i)) ; |
|
427 } |
|
428 mTransitionEffectList[GRID_TO_ALBUMLIST] = effectSetting; |
|
429 |
|
430 effectSetting = new GlxTransitionEffectSetting( ALBUMLIST_TO_GRID ); |
|
431 for ( int i = 0; i < effectSetting->count(); ++i ) { |
|
432 HbEffect::add( effectSetting->itemType().at(i), effectSetting->effectFileList().at(i), effectSetting->eventType().at(i)) ; |
|
433 } |
|
434 mTransitionEffectList[ALBUMLIST_TO_GRID] = effectSetting; |
|
435 |
|
436 effectSetting = new GlxTransitionEffectSetting( FULLSCREEN_TO_DETAIL ); |
|
437 for ( int i = 0; i < effectSetting->count(); ++i ) { |
|
438 HbEffect::add( effectSetting->itemType().at(i), effectSetting->effectFileList().at(i), effectSetting->eventType().at(i)) ; |
|
439 } |
|
440 mTransitionEffectList[FULLSCREEN_TO_DETAIL] = effectSetting; |
|
441 |
|
442 effectSetting = new GlxTransitionEffectSetting( DETAIL_TO_FULLSCREEN ); |
|
443 for ( int i = 0; i < effectSetting->count(); ++i ) { |
|
444 HbEffect::add( effectSetting->itemType().at(i), effectSetting->effectFileList().at(i), effectSetting->eventType().at(i)) ; |
|
445 } |
|
446 mTransitionEffectList[DETAIL_TO_FULLSCREEN] = effectSetting; |
|
447 } |
|
448 |
|
449 void GlxSlideShowEffectEngine::cleanTransitionEfffect() |
|
450 { |
|
451 qDebug("GlxSlideShowEffectEngine::cleanTrnastionEfffect()"); |
|
452 |
|
453 foreach( GlxTransitionEffectSetting *list, mTransitionEffectList) { |
|
454 for ( int i = 0; i < list->count(); ++i ) { |
|
455 HbEffect::remove( list->itemType().at(i), list->effectFileList().at(i), list->eventType().at(i)) ; |
|
456 } |
|
457 delete list; |
|
458 } |
|
459 mTransitionEffectList.clear(); |
|
460 |
|
461 } |
|
462 |
|