|
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 GlxSlideShowSetting::GlxSlideShowSetting( int slideDelayTime, GlxEffect effect, GlxSlideShowMoveDir moveDir ) |
|
27 : mSlideDelayTime(slideDelayTime), |
|
28 mEffect ( effect), |
|
29 mMoveDir ( moveDir) |
|
30 { |
|
31 |
|
32 } |
|
33 |
|
34 void GlxSlideShowSetting::readSlideShowSetting() |
|
35 { |
|
36 //To:Do read from the file system |
|
37 mSlideDelayTime = 3000; |
|
38 mEffect = FADE_EFFECT; |
|
39 mMoveDir = MOVE_FORWARD; |
|
40 qDebug("GlxSlideShowSetting::readSlideShowSetting() slide delay time %d effect %d move direction %d", mSlideDelayTime, mEffect, mMoveDir); |
|
41 } |
|
42 |
|
43 |
|
44 GlxTransitionEffectSetting::GlxTransitionEffectSetting(GlxEffect effect): mEffect(effect), mTransitionLater(false), mItem(0) |
|
45 { |
|
46 qDebug("GlxTransitionEffectSetting::GlxTransitionEffectSetting() effect id %d ", effect); |
|
47 mEffectFileList.clear(); |
|
48 mItemType.clear(); |
|
49 mEventType.clear(); |
|
50 init(); |
|
51 } |
|
52 |
|
53 void GlxTransitionEffectSetting::init() |
|
54 { |
|
55 qDebug("GlxTransitionEffectSetting::init() effect id %d ", mEffect); |
|
56 |
|
57 switch( mEffect ) { |
|
58 case GRID_TO_FULLSCREEN : |
|
59 mEffectFileList.append( QString(":/data/gridtofullscreenhide.fxml")); |
|
60 mItemType.append( QString("HbGridViewItem") ); |
|
61 mEventType.append(QString("click1") ); |
|
62 |
|
63 mEffectFileList.append( QString(":/data/gridtofullscreenshow.fxml")); |
|
64 mItemType.append( QString("HbView") ); |
|
65 mEventType.append(QString("click2") ); |
|
66 break; |
|
67 |
|
68 case FULLSCREEN_TO_GRID : |
|
69 mEffectFileList.append( QString(":/data/fullscreentogrid.fxml")); |
|
70 mItemType.append( QString("HbGridView") ); |
|
71 mEventType.append(QString("click3") ); |
|
72 break; |
|
73 |
|
74 case GRID_TO_ALBUMLIST: |
|
75 mEffectFileList.append( QString(":/data/gridtoalbumlisthide.fxml")); |
|
76 mItemType.append( QString("HbView") ); |
|
77 mEventType.append(QString("click4") ); |
|
78 |
|
79 mEffectFileList.append( QString(":/data/gridtoalbumlist.fxml")); |
|
80 mItemType.append( QString("HbListView") ); |
|
81 mEventType.append(QString("click5") ); |
|
82 break; |
|
83 |
|
84 case ALBUMLIST_TO_GRID: |
|
85 mEffectFileList.append( QString(":/data/albumlisttogrid.fxml")); |
|
86 mItemType.append( QString("HbListView") ); |
|
87 mEventType.append(QString("click6") ); |
|
88 |
|
89 mEffectFileList.append( QString(":/data/albumlisttogridshow.fxml")); |
|
90 mItemType.append( QString("HbView") ); |
|
91 mEventType.append(QString("click7") ); |
|
92 break; |
|
93 |
|
94 case FULLSCREEN_TO_DETAIL : |
|
95 mEffectFileList.append( QString(":/data/view_flip_hide.fxml")); |
|
96 mItemType.append( QString("HbView") ); |
|
97 mEventType.append(QString("click8") ); |
|
98 |
|
99 mEffectFileList.append( QString(":/data/view_flip_show.fxml")); |
|
100 mItemType.append( QString("HbView") ); |
|
101 mEventType.append(QString("click9") ); |
|
102 mTransitionLater = true; |
|
103 break; |
|
104 |
|
105 case DETAIL_TO_FULLSCREEN : |
|
106 mEffectFileList.append( QString(":/data/view_flip_hide.fxml")); |
|
107 mItemType.append( QString("HbView") ); |
|
108 mEventType.append(QString("click10") ); |
|
109 |
|
110 mEffectFileList.append( QString(":/data/view_flip_show.fxml")); |
|
111 mItemType.append( QString("HbView") ); |
|
112 mEventType.append(QString("click11") ); |
|
113 mTransitionLater = true; |
|
114 break; |
|
115 |
|
116 default : |
|
117 break; |
|
118 } |
|
119 } |
|
120 |
|
121 GlxTransitionEffectSetting::~GlxTransitionEffectSetting() |
|
122 { |
|
123 qDebug("GlxTransitionEffectSetting::~GlxTransitionEffectSetting() effect id %d ", mEffect); |
|
124 mEffectFileList.clear(); |
|
125 mItemType.clear(); |
|
126 mEventType.clear(); |
|
127 } |
|
128 |
|
129 |
|
130 GlxSlideShowEffectEngine::GlxSlideShowEffectEngine( ) : mNbrEffectRunning( 0 ), |
|
131 mEffectPlugin(NULL), |
|
132 mTransitionEffect(NO_EFFECT) |
|
133 { |
|
134 qDebug("GlxSlideShowEffectEngine::GlxSlideShowEffectEngine()"); |
|
135 mTransitionEffectList.clear(); |
|
136 } |
|
137 |
|
138 GlxSlideShowEffectEngine::~GlxSlideShowEffectEngine() |
|
139 { |
|
140 qDebug("GlxSlideShowEffectEngine::~GlxSlideShowEffectEngine()"); |
|
141 delete mEffectPlugin; |
|
142 mEffectPlugin = NULL; |
|
143 |
|
144 cleanTransitionEfffect(); |
|
145 } |
|
146 |
|
147 void GlxSlideShowEffectEngine::registerEffect(const QString &itemType) |
|
148 { |
|
149 effectPluginResolver(); |
|
150 QList <QString > effectPathList = mEffectPlugin->getEffectFileList(); |
|
151 |
|
152 qDebug("GlxSlideShowEffectEngine::registerEffect() item type %s file path %s", itemType.utf16(), effectPathList[0].utf16()); |
|
153 for ( int i = 0; i < effectPathList.count() ; ++i ) { |
|
154 HbEffect::add(itemType, effectPathList.at(i), QString( "Click%1" ).arg(i)); |
|
155 } |
|
156 } |
|
157 |
|
158 void GlxSlideShowEffectEngine::deRegisterEffect(const QString &itemType) |
|
159 { |
|
160 qDebug("GlxSlideShowEffectEngine::deRegisterEffect() item type %s", itemType.utf16()); |
|
161 QList <QString > effectPathList = mEffectPlugin->getEffectFileList(); |
|
162 for ( int i = 0; i < effectPathList.count() ; ++i ) { |
|
163 HbEffect::remove(itemType, effectPathList.at(i), QString( "Click%1" ).arg(i)); |
|
164 } |
|
165 delete mEffectPlugin ; |
|
166 mEffectPlugin = NULL; |
|
167 } |
|
168 |
|
169 void GlxSlideShowEffectEngine::registerTransitionEffect() |
|
170 { |
|
171 qDebug("GlxSlideShowEffectEngine::registerTransitionEffect()"); |
|
172 initTransitionEffect(); |
|
173 } |
|
174 |
|
175 void GlxSlideShowEffectEngine::deregistertransitionEffect() |
|
176 { |
|
177 qDebug("GlxSlideShowEffectEngine::deregisterTransitionEffect()"); |
|
178 cleanTransitionEfffect(); |
|
179 } |
|
180 |
|
181 void GlxSlideShowEffectEngine::runEffect(QGraphicsItem * item, const QString & itemType ) |
|
182 { |
|
183 qDebug("GlxSlideShowEffectEngine::runEffect()1 item type %s", itemType.utf16()); |
|
184 HbEffect::start(item, itemType, QString( "Click1" ), this, "slideShowEffectFinished"); |
|
185 ++mNbrEffectRunning; |
|
186 } |
|
187 |
|
188 void GlxSlideShowEffectEngine::runEffect(QList< QGraphicsItem * > & items, const QString & itemType ) |
|
189 { |
|
190 qDebug("GlxSlideShowEffectEngine::runEffect()2 item Type %s", itemType.utf16()); |
|
191 mEffectPlugin->setUpItems(items); |
|
192 for ( int i = 0; i < items.count() ; ++i ) { |
|
193 if ( mEffectPlugin->isAnimationLater(i) == FALSE ) { |
|
194 HbEffect::start(items.at(i), itemType, QString( "Click%1").arg(i), this, "slideShowEffectFinished"); |
|
195 } |
|
196 ++mNbrEffectRunning; |
|
197 } |
|
198 } |
|
199 |
|
200 void GlxSlideShowEffectEngine::runEffect(QList< QGraphicsItem * > & items, GlxEffect transitionEffect) |
|
201 { |
|
202 qDebug("GlxSlideShowEffectEngine::runEffect()3 effect type %d ", transitionEffect); |
|
203 |
|
204 GlxTransitionEffectSetting *effectSetting = mTransitionEffectList.value( transitionEffect ); |
|
205 |
|
206 if ( effectSetting == NULL && items.count() != effectSetting->count() ) { |
|
207 return; |
|
208 } |
|
209 |
|
210 mTransitionEffect = transitionEffect; |
|
211 for ( int i = 0; i < effectSetting->count() ; ++i) { |
|
212 ++mNbrEffectRunning; |
|
213 if ( ( i == effectSetting->count() -1) && effectSetting->isTransitionLater() ) |
|
214 { |
|
215 effectSetting->setAnimationItem( items.at(i) ); |
|
216 } |
|
217 else { |
|
218 HbEffect::start(items.at(i), effectSetting->itemType().at(i), effectSetting->eventType().at(i), this, "transitionEffectFinished"); |
|
219 } |
|
220 } |
|
221 } |
|
222 |
|
223 void GlxSlideShowEffectEngine::cancelEffect(QGraphicsItem * item) |
|
224 { |
|
225 if ( HbEffect::effectRunning( item, QString( "Click1" ) ) ) { |
|
226 HbEffect::cancel( item, QString( "Click1" ) ); |
|
227 } |
|
228 } |
|
229 |
|
230 void GlxSlideShowEffectEngine::cancelEffect(const QList< QGraphicsItem * > & items) |
|
231 { |
|
232 for ( int i = 0; i < items.count() ; ++i ) { |
|
233 if ( HbEffect::effectRunning( items.at(i), QString( "Click%1").arg(i) ) ) { |
|
234 HbEffect::cancel( items.at(i), QString( "Click%1").arg(i) ); |
|
235 } |
|
236 } |
|
237 } |
|
238 |
|
239 void GlxSlideShowEffectEngine::cancelEffect(QList< QGraphicsItem * > & items, GlxEffect transitionEffect) |
|
240 { |
|
241 GlxTransitionEffectSetting *effectSetting = mTransitionEffectList.value( transitionEffect ); |
|
242 |
|
243 if ( effectSetting == NULL && items.count() != effectSetting->count() ) { |
|
244 return; |
|
245 } |
|
246 |
|
247 for ( int i = 0; i < effectSetting->count() ; ++i) { |
|
248 HbEffect::cancel(items.at(i), effectSetting->eventType().at(i) ); |
|
249 } |
|
250 } |
|
251 |
|
252 bool GlxSlideShowEffectEngine::isEffectRuning(QGraphicsItem * item) |
|
253 { |
|
254 if ( HbEffect::effectRunning( item, QString( "Click1" ) ) ) { |
|
255 return true; |
|
256 } |
|
257 return false; |
|
258 } |
|
259 |
|
260 bool GlxSlideShowEffectEngine::isEffectRuning(const QList< QGraphicsItem * > & items) |
|
261 { |
|
262 for ( int i = 0; i < items.count() ; ++i ) { |
|
263 if ( HbEffect::effectRunning( items.at(i), QString( "Click%1").arg(i) ) ) { |
|
264 return true; |
|
265 } |
|
266 } |
|
267 return false; |
|
268 } |
|
269 |
|
270 void GlxSlideShowEffectEngine::slideShowEffectFinished( const HbEffect::EffectStatus &status ) |
|
271 { |
|
272 Q_UNUSED( status ) |
|
273 qDebug("GlxSlideShowEffectEngine::slideShowEffectFinished() number of effect %d ", mNbrEffectRunning); |
|
274 |
|
275 --mNbrEffectRunning; |
|
276 |
|
277 if ( mEffectPlugin->isAnimationLater( mNbrEffectRunning) ) { |
|
278 HbEffect::start( mEffectPlugin->animationItem(), mEffectPlugin->ItemType(), QString( "Click%1").arg(mNbrEffectRunning), this, "slideShowEffectFinished"); |
|
279 } |
|
280 |
|
281 if (mNbrEffectRunning == 0) { |
|
282 emit effectFinished(); |
|
283 } |
|
284 } |
|
285 |
|
286 void GlxSlideShowEffectEngine::transitionEffectFinished( const HbEffect::EffectStatus &status ) |
|
287 { |
|
288 Q_UNUSED( status ) |
|
289 qDebug("GlxSlideShowEffectEngine::transitionEffectFinished() number of effect %d status %d", mNbrEffectRunning, status.reason); |
|
290 |
|
291 --mNbrEffectRunning; |
|
292 if ( mNbrEffectRunning == 1 ) { |
|
293 GlxTransitionEffectSetting *effectSetting = mTransitionEffectList.value( mTransitionEffect ); |
|
294 if ( effectSetting->isTransitionLater() ){ |
|
295 HbEffect::start( effectSetting->animationItem(), effectSetting->itemType().at(1), effectSetting->eventType().at(1), this, "transitionEffectFinished"); |
|
296 mTransitionEffect = NO_EFFECT; |
|
297 } |
|
298 } |
|
299 |
|
300 if (mNbrEffectRunning == 0) { |
|
301 emit effectFinished(); |
|
302 } |
|
303 } |
|
304 |
|
305 void GlxSlideShowEffectEngine::effectPluginResolver() |
|
306 { |
|
307 //TO:DO improved the code by using factory design pattern |
|
308 |
|
309 delete mEffectPlugin; |
|
310 mEffectPlugin = NULL; |
|
311 |
|
312 switch ( mSlideShowSetting.effect() ) { |
|
313 case TRANSITION_EFFECT : |
|
314 if ( slideShowMoveDir() == MOVE_FORWARD ) { |
|
315 mEffectPlugin = new GlxForwardTransitionPlugin(); |
|
316 } |
|
317 else { |
|
318 mEffectPlugin = new GlxBackwardTransitionPlugin(); |
|
319 } |
|
320 break; |
|
321 |
|
322 case FADE_EFFECT : |
|
323 mEffectPlugin = new GlxFadePlugin(); |
|
324 break; |
|
325 |
|
326 default : |
|
327 break; |
|
328 } |
|
329 } |
|
330 |
|
331 void GlxSlideShowEffectEngine::initTransitionEffect() |
|
332 { |
|
333 GlxTransitionEffectSetting *effectSetting = NULL; |
|
334 |
|
335 effectSetting = new GlxTransitionEffectSetting(GRID_TO_FULLSCREEN); |
|
336 for ( int i = 0; i < effectSetting->count(); ++i ) { |
|
337 HbEffect::add( effectSetting->itemType().at(i), effectSetting->effectFileList().at(i), effectSetting->eventType().at(i)) ; |
|
338 } |
|
339 mTransitionEffectList[GRID_TO_FULLSCREEN] = effectSetting; |
|
340 |
|
341 effectSetting = new GlxTransitionEffectSetting( FULLSCREEN_TO_GRID ); |
|
342 for ( int i = 0; i < effectSetting->count(); ++i ) { |
|
343 HbEffect::add( effectSetting->itemType().at(i), effectSetting->effectFileList().at(i), effectSetting->eventType().at(i)) ; |
|
344 } |
|
345 mTransitionEffectList[FULLSCREEN_TO_GRID] = effectSetting; |
|
346 |
|
347 effectSetting = new GlxTransitionEffectSetting( GRID_TO_ALBUMLIST ); |
|
348 for ( int i = 0; i < effectSetting->count(); ++i ) { |
|
349 HbEffect::add( effectSetting->itemType().at(i), effectSetting->effectFileList().at(i), effectSetting->eventType().at(i)) ; |
|
350 } |
|
351 mTransitionEffectList[GRID_TO_ALBUMLIST] = effectSetting; |
|
352 |
|
353 effectSetting = new GlxTransitionEffectSetting( ALBUMLIST_TO_GRID ); |
|
354 for ( int i = 0; i < effectSetting->count(); ++i ) { |
|
355 HbEffect::add( effectSetting->itemType().at(i), effectSetting->effectFileList().at(i), effectSetting->eventType().at(i)) ; |
|
356 } |
|
357 mTransitionEffectList[ALBUMLIST_TO_GRID] = effectSetting; |
|
358 |
|
359 effectSetting = new GlxTransitionEffectSetting( FULLSCREEN_TO_DETAIL ); |
|
360 for ( int i = 0; i < effectSetting->count(); ++i ) { |
|
361 HbEffect::add( effectSetting->itemType().at(i), effectSetting->effectFileList().at(i), effectSetting->eventType().at(i)) ; |
|
362 } |
|
363 mTransitionEffectList[FULLSCREEN_TO_DETAIL] = effectSetting; |
|
364 |
|
365 effectSetting = new GlxTransitionEffectSetting( DETAIL_TO_FULLSCREEN ); |
|
366 for ( int i = 0; i < effectSetting->count(); ++i ) { |
|
367 HbEffect::add( effectSetting->itemType().at(i), effectSetting->effectFileList().at(i), effectSetting->eventType().at(i)) ; |
|
368 } |
|
369 mTransitionEffectList[DETAIL_TO_FULLSCREEN] = effectSetting; |
|
370 } |
|
371 |
|
372 void GlxSlideShowEffectEngine::cleanTransitionEfffect() |
|
373 { |
|
374 qDebug("GlxSlideShowEffectEngine::cleanTrnastionEfffect()"); |
|
375 |
|
376 foreach( GlxTransitionEffectSetting *list, mTransitionEffectList) { |
|
377 for ( int i = 0; i < list->count(); ++i ) { |
|
378 HbEffect::remove( list->itemType().at(i), list->effectFileList().at(i), list->eventType().at(i)) ; |
|
379 } |
|
380 delete list; |
|
381 } |
|
382 mTransitionEffectList.clear(); |
|
383 |
|
384 } |
|
385 |