|
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 //Includes |
|
20 |
|
21 #include <QDebug> |
|
22 #include <QTimer> |
|
23 #include <e32base.h> |
|
24 #include <hbiconitem.h> |
|
25 #include <hbpushbutton.h> |
|
26 #include <hbmainwindow.h> |
|
27 #include <hbdocumentloader.h> |
|
28 #include <QAbstractItemModel> |
|
29 #include <QGesture> |
|
30 #include <hbpangesture.h> |
|
31 #include <hblabel.h> |
|
32 |
|
33 //User Includes |
|
34 #include "glxicondefs.h" //Contains the icon names/Ids |
|
35 #include "glxmodelparm.h" |
|
36 #include "glxeffectengine.h" |
|
37 #include "glxdocloaderdefs.h" |
|
38 #include "glxslideshowwidget.h" |
|
39 #include "glxsettinginterface.h" |
|
40 #include "glxlocalisationstrings.h" |
|
41 #include "glxlog.h" |
|
42 #include "glxtracer.h" |
|
43 |
|
44 |
|
45 GlxSlideShowWidget::GlxSlideShowWidget( QGraphicsItem *parent ) |
|
46 : HbWidget( parent ), |
|
47 mEffectEngine( NULL ), |
|
48 mSettings( NULL ), |
|
49 mAnimItem( NULL ), |
|
50 mBackGroundItem( NULL ), |
|
51 mContinueButton( NULL ), |
|
52 mErrorNote( NULL ), |
|
53 mItemIndex( 1 ), |
|
54 mSlideTimer( NULL ), |
|
55 mModel( NULL ), |
|
56 mSlideShowItemCount( 0 ), |
|
57 mIsAutoMoving ( false ) |
|
58 { |
|
59 TRACER("GlxSlideShowWidget::GlxSlideShowWidget()"); |
|
60 mSettings = GlxSettingInterface::instance() ; //no owner ship |
|
61 grabGesture( Qt::PanGesture ); |
|
62 grabGesture( Qt::TapGesture ); |
|
63 } |
|
64 |
|
65 void GlxSlideShowWidget::setSlideShowWidget(HbDocumentLoader *DocLoader) |
|
66 { |
|
67 //To:Do error handling |
|
68 TRACER("GlxSlideShowWidget::setSlideShowWidget()"); |
|
69 |
|
70 //create the effect engine |
|
71 mEffectEngine = new GlxEffectEngine(); |
|
72 mItemIndex = 1; |
|
73 |
|
74 mBackGroundItem = new HbIconItem( this ); |
|
75 mBackGroundItem->setBrush( QBrush( Qt::black ) ); |
|
76 mAnimItem = new HbIconItem( this ); |
|
77 mAnimItem->setAlignment( Qt::AlignCenter ); |
|
78 |
|
79 // Now load the view and the contents. |
|
80 // and then set the play icon to the button |
|
81 mContinueButton = static_cast<HbPushButton*>( DocLoader->findWidget( GLXSLIDESHOW_PB ) ); |
|
82 mContinueButton->setIcon( HbIcon( GLXICON_PLAY ) ); |
|
83 mContinueButton->hide(); |
|
84 mIsPause = false; |
|
85 |
|
86 for ( int i = 0; i < NBR_ITEM ; i++) { |
|
87 mSelIndex[ i ] = -1; |
|
88 mIconItems[ i ] = new HbIconItem( this ); |
|
89 mIconItems[ i ]->setAlignment( Qt::AlignCenter ); |
|
90 mIconItems[ i ]->setObjectName( QString( "SlideShowIcon%1" ).arg( i ) ); |
|
91 } |
|
92 |
|
93 mSlideTimer = new QTimer(); |
|
94 mItemList.clear(); |
|
95 |
|
96 //Add the signal-slot for this widget. |
|
97 addConnections(); |
|
98 |
|
99 //Create the settings for the effects |
|
100 mEffectEngine->registerEffect( QString("HbIconItem") ); |
|
101 |
|
102 //provide the xml info for the effect to take place |
|
103 HbEffect::add( QString("HbIconItem"), QString(":/data/transition.fxml"), QString( "Move" )); |
|
104 HbEffect::add( QString("HbIconItem"), QString(":/data/transitionleft.fxml"), QString( "LeftMove" )); |
|
105 HbEffect::add( QString("HbIconItem"), QString(":/data/transitionright.fxml"), QString( "RightMove" )); |
|
106 } |
|
107 |
|
108 GlxSlideShowWidget::~GlxSlideShowWidget() |
|
109 { |
|
110 TRACER("GlxSlideShowWidget::~GlxSlideShowWidget()"); |
|
111 |
|
112 //Delete the resources allocated |
|
113 cleanUp(); |
|
114 |
|
115 if(mContinueButton) { |
|
116 delete mContinueButton; |
|
117 mContinueButton = NULL; |
|
118 } |
|
119 } |
|
120 |
|
121 void GlxSlideShowWidget::cleanUp() |
|
122 { |
|
123 TRACER("GlxSlideShowWidget::cleanUp()"); |
|
124 removeConnections(); |
|
125 |
|
126 if( mEffectEngine ) { |
|
127 mEffectEngine->deRegisterEffect( QString("HbIconItem") ); |
|
128 delete mEffectEngine; |
|
129 mEffectEngine = NULL; |
|
130 } |
|
131 |
|
132 for ( int i = 0; i < NBR_ITEM ; i++) { |
|
133 delete mIconItems[i] ; |
|
134 mIconItems[i] = NULL; |
|
135 } |
|
136 |
|
137 delete mBackGroundItem ; |
|
138 mBackGroundItem = NULL; |
|
139 |
|
140 delete mAnimItem; |
|
141 mAnimItem = NULL; |
|
142 |
|
143 if( mSlideTimer ) { |
|
144 delete mSlideTimer; |
|
145 mSlideTimer = NULL; |
|
146 } |
|
147 |
|
148 if ( mErrorNote ) { |
|
149 delete mErrorNote ; |
|
150 mErrorNote = NULL; |
|
151 } |
|
152 |
|
153 clearCurrentModel(); |
|
154 HbEffect::remove( QString("HbIconItem"), QString(":/data/transition.fxml"), QString( "Move" )); |
|
155 HbEffect::remove( QString("HbIconItem"), QString(":/data/transitionleft.fxml"), QString( "LeftMove" )); |
|
156 HbEffect::remove( QString("HbIconItem"), QString(":/data/transitionright.fxml"), QString( "RightMove" )); |
|
157 } |
|
158 |
|
159 QGraphicsItem * GlxSlideShowWidget::animationItem() |
|
160 { |
|
161 mAnimItem->setIcon( getIcon( mSelIndex[ mItemIndex ] ) ); |
|
162 return mAnimItem; |
|
163 } |
|
164 |
|
165 void GlxSlideShowWidget::updateAnimationItem() |
|
166 { |
|
167 mIconItems[ mItemIndex ]->setIcon( HbIcon() ); |
|
168 mAnimItem->setZValue( mAnimItem->zValue() + 10 ); |
|
169 } |
|
170 |
|
171 void GlxSlideShowWidget::setModel ( QAbstractItemModel *model ) |
|
172 { |
|
173 TRACER("GlxSlideShowWidget::setModel()"); |
|
174 if ( model == mModel ) { |
|
175 return ; |
|
176 } |
|
177 clearCurrentModel(); |
|
178 mModel = model; |
|
179 initializeNewModel(); |
|
180 resetSlideShow(); |
|
181 } |
|
182 |
|
183 void GlxSlideShowWidget::setItemGeometry( QRect screenRect ) |
|
184 { |
|
185 TRACER("GlxSlideShowWidget::setItemGeometry()"); |
|
186 int index = mItemIndex; |
|
187 mScreenRect = screenRect; |
|
188 mIconItems[ index ]->setGeometry( mScreenRect ); |
|
189 index = ( mItemIndex + 1 ) % NBR_ITEM; |
|
190 mIconItems[ index ]->setGeometry( QRect( mScreenRect.width(), mScreenRect.top(), mScreenRect.width(), mScreenRect.height() ) ); |
|
191 index = mItemIndex ? mItemIndex - 1 : NBR_ITEM - 1; |
|
192 mIconItems[ index ]->setGeometry( QRect( -mScreenRect.width(), mScreenRect.top(), mScreenRect.width(), mScreenRect.height() ) ); |
|
193 mBackGroundItem->setGeometry( mScreenRect ); |
|
194 int xPos = ( mScreenRect.width() - mScreenRect.height() ) >> 1 ; |
|
195 mAnimItem->setGeometry( QRect( xPos, -xPos, mScreenRect.height(), mScreenRect.width() ) ); |
|
196 } |
|
197 |
|
198 void GlxSlideShowWidget::triggeredEffect() |
|
199 { |
|
200 TRACER("GlxSlideShowWidget::triggeredEffect()"); |
|
201 int index = mItemIndex; |
|
202 mSlideTimer->stop(); |
|
203 mItemList.clear(); |
|
204 User::ResetInactivityTime(); |
|
205 |
|
206 mItemList.append( mIconItems[index] ); |
|
207 index = ( mItemIndex + 1 ) % NBR_ITEM; |
|
208 mItemList.append( mIconItems[index] ); |
|
209 |
|
210 GLX_LOG_INFO3("GlxSlideShowWidget::triggeredEffect() image selected index %d array index %d index %d", mSelIndex, mItemIndex, index); |
|
211 mEffectEngine->runEffect( mItemList, QString("HbIconItem") ); |
|
212 emit slideShowEvent( EFFECT_STARTED ); |
|
213 } |
|
214 |
|
215 void GlxSlideShowWidget::effectFinshed() |
|
216 { |
|
217 GLX_LOG_INFO2("GlxSlideShowWidget::effectFinshed() before image selected index %d array index %d", mSelIndex, mItemIndex); |
|
218 |
|
219 mItemIndex = ( ++mItemIndex ) % NBR_ITEM; |
|
220 mModel->setData( mModel->index( 0, 0 ), mSelIndex[ mItemIndex ], GlxFocusIndexRole ); |
|
221 mModel->setData( mModel->index( 0, 0 ), mSelIndex[ mItemIndex ], GlxVisualWindowIndex ); |
|
222 setNextItemIcon(); |
|
223 |
|
224 GLX_LOG_INFO2("GlxSlideShowWidget::effectFinshed() after image selected index %d array index %d ", mSelIndex, mItemIndex); |
|
225 |
|
226 startSlideShow(); |
|
227 mItemList.clear(); |
|
228 emit indexchanged(); // on each item change |
|
229 } |
|
230 |
|
231 void GlxSlideShowWidget::cancelEffect() |
|
232 { |
|
233 TRACER("GlxSlideShowWidget::cancelEffect()"); |
|
234 mEffectEngine->cancelEffect( mItemList ); |
|
235 } |
|
236 |
|
237 void GlxSlideShowWidget::pauseSlideShow() |
|
238 { |
|
239 TRACER("GlxSlideShowWidget::pauseSlideShow()"); |
|
240 GLX_LOG_INFO1("GlxSlideShowWidget::pauseSlideShow() %d", this->zValue()); |
|
241 mIsPause = true; |
|
242 mSlideTimer->stop(); |
|
243 cancelEffect(); |
|
244 mContinueButton->setZValue( this->zValue() + 2); |
|
245 mContinueButton->show() ; |
|
246 emit slideShowEvent( UI_ON_EVENT ); |
|
247 } |
|
248 |
|
249 void GlxSlideShowWidget::continueSlideShow(bool checked) |
|
250 { |
|
251 Q_UNUSED( checked ) |
|
252 TRACER("GlxSlideShowWidget::continueSlideShow()"); |
|
253 mIsPause = false; |
|
254 if ( mModel && mSlideShowItemCount > 1 ) { |
|
255 mSlideTimer->start( mSettings->slideShowDelayTime() ); |
|
256 } |
|
257 mContinueButton->hide(); |
|
258 emit slideShowEvent( UI_OFF_EVENT ); |
|
259 } |
|
260 |
|
261 void GlxSlideShowWidget::dataChanged(QModelIndex startIndex, QModelIndex endIndex) |
|
262 { |
|
263 Q_UNUSED( endIndex ) |
|
264 TRACER("GlxSlideShowWidget::dataChanged()"); |
|
265 GLX_LOG_INFO2("GlxSlideShowWidget::dataChanged startIndex = %d mSelIndex = %d ", startIndex.row(), mSelIndex ); |
|
266 |
|
267 if ( HbEffect::effectRunning( mAnimItem ) ) { |
|
268 return ; |
|
269 } |
|
270 |
|
271 for( int i = 0; i < NBR_ITEM; ++i ) { |
|
272 if ( mSelIndex[ i ] == startIndex.row() ) { |
|
273 mIconItems[ i ]->setIcon( getIcon( startIndex.row() ) ); |
|
274 } |
|
275 } |
|
276 } |
|
277 |
|
278 void GlxSlideShowWidget::rowsInserted(const QModelIndex &parent, int start, int end) |
|
279 { |
|
280 TRACER("GlxSlideShowWidget::rowsInserted()"); |
|
281 Q_UNUSED(parent); |
|
282 Q_UNUSED(start); |
|
283 Q_UNUSED(end); |
|
284 if ( HbEffect::effectRunning( mAnimItem ) ) { |
|
285 return ; |
|
286 } |
|
287 resetSlideShow(); |
|
288 } |
|
289 |
|
290 void GlxSlideShowWidget::rowsRemoved(const QModelIndex &parent, int start, int end) |
|
291 { |
|
292 TRACER("GlxSlideShowWidget::rowsRemoved()"); |
|
293 Q_UNUSED(parent); |
|
294 Q_UNUSED(start); |
|
295 Q_UNUSED(end); |
|
296 |
|
297 GLX_LOG_INFO1( "GlxSlideShowWidget::rowsRemoved row count = %d ", mModel->rowCount() ); |
|
298 |
|
299 if ( mModel->rowCount() <= 0 ) { |
|
300 clearCurrentModel(); |
|
301 emit slideShowEvent( EMPTY_DATA_EVENT ); |
|
302 } |
|
303 else { |
|
304 resetSlideShow(); |
|
305 } |
|
306 } |
|
307 |
|
308 void GlxSlideShowWidget::modelDestroyed() |
|
309 { |
|
310 TRACER("GlxSlideShowWidget::modelDestroyed()"); |
|
311 clearCurrentModel(); |
|
312 } |
|
313 |
|
314 |
|
315 void GlxSlideShowWidget::orientationChanged(QRect screenRect) |
|
316 { |
|
317 TRACER("GlxSlideShowWidget::orientationChanged()"); |
|
318 mAnimItem->setIcon( HbIcon() ); |
|
319 mAnimItem->setZValue( mAnimItem->zValue() - 10 ); |
|
320 cancelEffect(); |
|
321 setItemGeometry( screenRect); |
|
322 resetSlideShow(); |
|
323 } |
|
324 |
|
325 void GlxSlideShowWidget::leftGesture(int value) |
|
326 { |
|
327 Q_UNUSED(value) |
|
328 TRACER("GlxSlideShowWidget::leftGesture()"); |
|
329 |
|
330 int index = ( mItemIndex + 1 ) % NBR_ITEM; |
|
331 moveImage( index, mScreenRect.width(), QString("LeftMove"), "leftMoveEffectFinished"); |
|
332 } |
|
333 |
|
334 void GlxSlideShowWidget::rightGesture(int value) |
|
335 { |
|
336 Q_UNUSED(value) |
|
337 TRACER ("GlxSlideShowWidget::rightGesture()"); |
|
338 |
|
339 int index = mItemIndex ? mItemIndex - 1 : NBR_ITEM - 1; |
|
340 moveImage( index, -mScreenRect.width(), QString("RightMove"), "rightMoveEffectFinished"); |
|
341 } |
|
342 |
|
343 void GlxSlideShowWidget::leftMoveEffectFinished( const HbEffect::EffectStatus &status ) |
|
344 { |
|
345 Q_UNUSED(status) |
|
346 TRACER("GlxSlideShowWidget::leftMoveEffectFinished()"); |
|
347 GLX_LOG_INFO1("GlxSlideShowWidget::leftMoveEffectFinished() %d status", status.reason); |
|
348 |
|
349 mItemIndex = ( ++mItemIndex ) % NBR_ITEM; |
|
350 mModel->setData( mModel->index( 0, 0 ), mSelIndex[ mItemIndex ], GlxFocusIndexRole ); |
|
351 mModel->setData( mModel->index( 0, 0 ), mSelIndex[ mItemIndex ], GlxVisualWindowIndex ); |
|
352 setNextItemIcon(); |
|
353 startSlideShow(); |
|
354 mIsAutoMoving = false; |
|
355 emit indexchanged(); // on left swipe |
|
356 } |
|
357 |
|
358 void GlxSlideShowWidget::rightMoveEffectFinished( const HbEffect::EffectStatus &status ) |
|
359 { |
|
360 Q_UNUSED(status) |
|
361 TRACER ( "GlxSlideShowWidget::rightMoveEffectFinished( ) "); |
|
362 GLX_LOG_INFO1("GlxSlideShowWidget::rightMoveEffectFinished() %d status", status.reason); |
|
363 |
|
364 mItemIndex = mItemIndex ? mItemIndex - 1 : NBR_ITEM - 1; |
|
365 mModel->setData( mModel->index( 0, 0 ), mSelIndex[ mItemIndex ], GlxFocusIndexRole ); |
|
366 mModel->setData( mModel->index( 0, 0 ), mSelIndex[ mItemIndex ], GlxVisualWindowIndex ); |
|
367 setPreItemIcon(); |
|
368 startSlideShow(); |
|
369 mIsAutoMoving = false; |
|
370 emit indexchanged(); // on right swipe |
|
371 } |
|
372 |
|
373 void GlxSlideShowWidget::gestureEvent(QGestureEvent *event) |
|
374 { |
|
375 if( QTapGesture *gesture = static_cast<QTapGesture *>( event->gesture( Qt::TapGesture ) ) ) { |
|
376 if ( gesture->state() == Qt::GestureFinished ) { |
|
377 if ( mIsPause == false ) { |
|
378 pauseSlideShow(); |
|
379 } |
|
380 event->accept(gesture); |
|
381 } |
|
382 } |
|
383 |
|
384 if ( QPanGesture *panningGesture = qobject_cast<QPanGesture*>( event->gesture( Qt::PanGesture ) ) ) { |
|
385 HbPanGesture *hbPanGesture = qobject_cast<HbPanGesture *>( panningGesture ); |
|
386 if ( hbPanGesture ) { |
|
387 if( hbPanGesture->state() == Qt::GestureFinished && mIsAutoMoving == FALSE ) { |
|
388 QPointF delta( hbPanGesture->sceneDelta() ); |
|
389 if ( delta.x() > 0 ) { |
|
390 rightGesture( delta.x() ); |
|
391 } |
|
392 else { |
|
393 leftGesture( delta.x() ); |
|
394 } |
|
395 } |
|
396 event->accept(panningGesture); |
|
397 } |
|
398 } |
|
399 } |
|
400 |
|
401 void GlxSlideShowWidget::startSlideShow ( ) |
|
402 { |
|
403 TRACER ( "GlxSlideShowWidget::startSlideShow( ) "); |
|
404 GLX_LOG_INFO1 ( "GlxSlideShowWidget::startSlideShow( ) is pause %d", mIsPause); |
|
405 |
|
406 if ( mSlideShowItemCount == 0 ) { |
|
407 showErrorNote(); |
|
408 } |
|
409 if ( mIsPause == false && mModel && mSlideShowItemCount > 1 ) { |
|
410 mSlideTimer->start( mSettings->slideShowDelayTime() ); |
|
411 } |
|
412 } |
|
413 |
|
414 void GlxSlideShowWidget::stopSlideShow ( ) |
|
415 { |
|
416 TRACER ( "GlxSlideShowWidget::stopSlideShow( ) "); |
|
417 cancelEffect(); |
|
418 mSlideTimer->stop(); |
|
419 } |
|
420 |
|
421 void GlxSlideShowWidget::clearCurrentModel() |
|
422 { |
|
423 TRACER ( "GlxSlideShowWidget::clearCurrentModel( ) "); |
|
424 if ( mModel ) { |
|
425 disconnect( mModel, SIGNAL( dataChanged(QModelIndex,QModelIndex) ), this, SLOT( dataChanged(QModelIndex,QModelIndex) ) ); |
|
426 disconnect(mModel, SIGNAL(rowsInserted(QModelIndex,int,int)), this, SLOT(rowsInserted(QModelIndex,int,int))); |
|
427 disconnect(mModel, SIGNAL(rowsRemoved(QModelIndex,int,int)), this, SLOT(rowsRemoved(QModelIndex,int,int))); |
|
428 disconnect(mModel, SIGNAL(destroyed()), this, SLOT( modelDestroyed())); |
|
429 mModel = NULL ; |
|
430 } |
|
431 } |
|
432 |
|
433 void GlxSlideShowWidget::initializeNewModel() |
|
434 { |
|
435 TRACER("GlxSlideShowWidget::initializeNewModel" ); |
|
436 if ( mModel ) { |
|
437 connect( mModel, SIGNAL( dataChanged(QModelIndex,QModelIndex) ), this, SLOT( dataChanged(QModelIndex,QModelIndex) ) ); |
|
438 connect(mModel, SIGNAL(rowsInserted(QModelIndex,int,int)), this, SLOT(rowsInserted(QModelIndex,int,int))); |
|
439 connect(mModel, SIGNAL(rowsRemoved(QModelIndex,int,int)), this, SLOT(rowsRemoved(QModelIndex,int,int))); |
|
440 connect(mModel, SIGNAL(destroyed()), this, SLOT( modelDestroyed())); |
|
441 } |
|
442 } |
|
443 |
|
444 void GlxSlideShowWidget::resetSlideShow() |
|
445 { |
|
446 TRACER("GlxSlideShowWidget::resetSlideShow()" ); |
|
447 if( mModel == NULL || mModel->rowCount() == 0 ) { |
|
448 return; |
|
449 } |
|
450 |
|
451 mSlideShowItemCount = mModel->rowCount(); |
|
452 setFocusItemIcon() ; |
|
453 setNextItemIcon() ; |
|
454 setPreItemIcon() ; |
|
455 startSlideShow(); |
|
456 |
|
457 qDebug( "GlxSlideShowWidget::resetSlideShow slide show item count %d" , mSlideShowItemCount ); |
|
458 if ( mErrorNote && mErrorNote->isVisible() && mSlideShowItemCount > 1 ){ |
|
459 hideErrorNote(); |
|
460 } |
|
461 } |
|
462 |
|
463 void GlxSlideShowWidget::moveImage(int nextIndex, int posX, const QString & move, char * callBack) |
|
464 { |
|
465 TRACER("GlxSlideShowWidget::MoveImage()"); |
|
466 |
|
467 if ( mSlideShowItemCount <= 1 || mEffectEngine->isEffectRuning( mItemList ) ) { |
|
468 return ; |
|
469 } |
|
470 |
|
471 mSlideTimer->stop(); |
|
472 HbEffect::start( mIconItems[mItemIndex], QString("HbIconItem"), move ); |
|
473 mIconItems[nextIndex]->setPos( posX, mScreenRect.top()); |
|
474 mIconItems[nextIndex]->setOpacity(1); |
|
475 mIsAutoMoving = true; |
|
476 HbEffect::start(mIconItems[nextIndex], QString("HbIconItem"), QString("Move"), this, callBack ); |
|
477 } |
|
478 |
|
479 void GlxSlideShowWidget::addConnections() |
|
480 { |
|
481 TRACER("GlxSlideShowWidget::addConnections()"); |
|
482 if ( mEffectEngine ) { |
|
483 connect( mEffectEngine, SIGNAL( effectFinished() ), this, SLOT( effectFinshed() ) ); |
|
484 } |
|
485 if ( mSlideTimer ) { |
|
486 connect( mSlideTimer, SIGNAL(timeout()), this, SLOT( triggeredEffect() ) ); |
|
487 } |
|
488 if ( mContinueButton ) { |
|
489 connect( mContinueButton, SIGNAL( clicked(bool) ), this, SLOT( continueSlideShow(bool) ) ); |
|
490 } |
|
491 } |
|
492 |
|
493 void GlxSlideShowWidget::removeConnections() |
|
494 { |
|
495 TRACER("GlxSlideShowWidget::removeConnections()"); |
|
496 if ( mEffectEngine ) { |
|
497 disconnect( mEffectEngine, SIGNAL( effectFinished() ), this, SLOT( effectFinshed() ) ); |
|
498 } |
|
499 if ( mSlideTimer ) { |
|
500 disconnect( mSlideTimer, SIGNAL(timeout()), this, SLOT( triggeredEffect() ) ); |
|
501 } |
|
502 if ( mContinueButton ) { |
|
503 disconnect( mContinueButton, SIGNAL( clicked(bool) ), this, SLOT( continueSlideShow(bool) ) ); |
|
504 } |
|
505 } |
|
506 |
|
507 int GlxSlideShowWidget::getFocusIndex( ) |
|
508 { |
|
509 QVariant variant = mModel->data( mModel->index( 0, 0 ), GlxFocusIndexRole ) ; |
|
510 if ( variant.isValid() && variant.canConvert< int > () ) { |
|
511 return variant.value< int > (); |
|
512 } |
|
513 return -1; |
|
514 } |
|
515 |
|
516 HbIcon GlxSlideShowWidget::getIcon( int index ) |
|
517 { |
|
518 QVariant variant = mModel->data( mModel->index( index, 0 ), GlxFsImageRole ); |
|
519 if ( variant.isValid() && variant.canConvert< HbIcon > () ) { |
|
520 return variant.value< HbIcon > () ; |
|
521 } |
|
522 return HbIcon() ; |
|
523 } |
|
524 |
|
525 bool GlxSlideShowWidget::isCorrupt( int index ) |
|
526 { |
|
527 QVariant variant = mModel->data( mModel->index( index, 0 ), GlxImageCorruptRole ); |
|
528 if ( variant.isValid() && variant.canConvert< bool> () ) { |
|
529 return variant.value< bool > () ; |
|
530 } |
|
531 return false ; |
|
532 } |
|
533 |
|
534 bool GlxSlideShowWidget::setFocusItemIcon( ) |
|
535 { |
|
536 int nbrItem = mModel->rowCount(); |
|
537 int focusIndex = getFocusIndex(); |
|
538 |
|
539 for ( int i = 0; i < nbrItem ; ++i ) { |
|
540 if ( isCorrupt( focusIndex ) == false ) { |
|
541 qDebug( "GlxSlideShowWidget::setFocusItemIcon1 focus index %d" , focusIndex ); |
|
542 mIconItems[ mItemIndex ]->setIcon( getIcon( focusIndex ) ) ; |
|
543 mSelIndex[ mItemIndex ] = focusIndex ; |
|
544 mModel->setData( mModel->index( 0, 0 ), focusIndex, GlxFocusIndexRole ); |
|
545 mModel->setData( mModel->index( 0, 0 ), focusIndex, GlxVisualWindowIndex ); |
|
546 return true; |
|
547 } |
|
548 focusIndex = ( focusIndex + 1 ) % nbrItem; |
|
549 } |
|
550 mSlideShowItemCount = 0; |
|
551 return false; |
|
552 } |
|
553 |
|
554 bool GlxSlideShowWidget::setNextItemIcon( ) |
|
555 { |
|
556 int nbrItem = mModel->rowCount(); |
|
557 int imageIndex = ( mSelIndex[ mItemIndex ] + 1 ) % nbrItem ; |
|
558 int itemIndex = ( mItemIndex + 1 ) % NBR_ITEM ; |
|
559 |
|
560 for( int i = 1; i < nbrItem; ++i ) { |
|
561 if ( isCorrupt( imageIndex ) == false ) { |
|
562 mIconItems[ itemIndex ]->setIcon( getIcon( imageIndex ) ); |
|
563 mSelIndex[ itemIndex ] = imageIndex ; |
|
564 return true; |
|
565 } |
|
566 imageIndex = ( imageIndex + 1 ) % nbrItem ; |
|
567 } |
|
568 |
|
569 if ( isCorrupt( imageIndex ) ) { |
|
570 mSlideShowItemCount = 0; |
|
571 } |
|
572 else { |
|
573 mSlideShowItemCount = 1; |
|
574 } |
|
575 return false ; |
|
576 } |
|
577 |
|
578 bool GlxSlideShowWidget::setPreItemIcon() |
|
579 { |
|
580 int nbrItem = mModel->rowCount() ; |
|
581 int imageIndex = mSelIndex[ mItemIndex ] > 0 ? mSelIndex[ mItemIndex ] - 1 : nbrItem - 1 ; |
|
582 int itemIndex = mItemIndex > 0 ? mItemIndex - 1 : NBR_ITEM - 1 ; |
|
583 |
|
584 for( int i = 1; i < nbrItem; ++i ) { |
|
585 if ( isCorrupt( imageIndex ) == false ) { |
|
586 mIconItems[ itemIndex ]->setIcon( getIcon( imageIndex ) ) ; |
|
587 mSelIndex[ itemIndex ] = imageIndex ; |
|
588 return true; |
|
589 } |
|
590 imageIndex = imageIndex > 0 ? imageIndex - 1 : nbrItem - 1 ; |
|
591 } |
|
592 if ( isCorrupt( imageIndex ) ) { |
|
593 mSlideShowItemCount = 0; |
|
594 } |
|
595 else { |
|
596 mSlideShowItemCount = 1; |
|
597 } |
|
598 return false; |
|
599 } |
|
600 |
|
601 void GlxSlideShowWidget::showErrorNote() |
|
602 { |
|
603 if ( mErrorNote == NULL ){ |
|
604 mErrorNote = new HbLabel( QString( GLX_NOIMAGE_PLAY_SLIDESHOW ), this); |
|
605 mErrorNote->setObjectName( "No Image" ); |
|
606 mErrorNote->setGeometry( mIconItems[ 0 ]->geometry() ); |
|
607 mErrorNote->setAlignment( Qt::AlignCenter ); |
|
608 } |
|
609 |
|
610 for( int i = 0; i < NBR_ITEM; ++i ){ |
|
611 mIconItems[ i ]->setVisible( false ); |
|
612 } |
|
613 mErrorNote->setVisible( true ); |
|
614 emit slideShowEvent( UI_ON_EVENT ); |
|
615 } |
|
616 |
|
617 void GlxSlideShowWidget::hideErrorNote() |
|
618 { |
|
619 for( int i = 0; i < NBR_ITEM; ++i ){ |
|
620 mIconItems[ i ]->setVisible( true ); |
|
621 } |
|
622 mErrorNote->setVisible( false ); |
|
623 emit slideShowEvent( UI_OFF_EVENT ); |
|
624 } |
|
625 |