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