ui/views/fullscreenview/src/glxcoverflow.cpp
changeset 55 fb37077c270f
parent 49 f291796e213d
child 61 743eb0b9959e
equal deleted inserted replaced
49:f291796e213d 55:fb37077c270f
    22 #include <QGraphicsSceneMouseEvent>
    22 #include <QGraphicsSceneMouseEvent>
    23 #include <QDebug>
    23 #include <QDebug>
    24 #include <QGesture>
    24 #include <QGesture>
    25 #include <hbpangesture.h>
    25 #include <hbpangesture.h>
    26 #include <hbiconanimator.h>
    26 #include <hbiconanimator.h>
       
    27 #include <hbinstance.h>
    27 
    28 
    28 //User Includes
    29 //User Includes
    29 #include <glxmodelparm.h>
    30 #include <glxmodelparm.h>
    30 #include <glxcoverflow.h>
    31 #include <glxcoverflow.h>
    31 #include "glxviewids.h"
    32 #include "glxviewids.h"
    32 
    33 
    33 #define GLX_COVERFLOW_SPEED  32
    34 #define GLX_COVERFLOW_SPEED  32
    34 #define GLX_BOUNCEBACK_SPEED 16
    35 #define GLX_BOUNCEBACK_SPEED 16
    35 #define GLX_BOUNCEBACK_DELTA 8
    36 #define GLX_BOUNCEBACK_DELTA 8
    36 
    37 
    37 GlxCoverFlow::GlxCoverFlow(QGraphicsItem *parent ) 
    38 GlxCoverFlow::GlxCoverFlow( QGraphicsItem *parent ) 
    38      : HbWidget(parent), 
    39      : HbWidget( parent ), 
    39        mSelItemIndex (0),
    40        mSelItemIndex ( 0 ),
    40        mRows(0),
    41        mRows( 0 ),
    41        mSelIndex (0),
    42        mSelIndex ( 0 ),
    42        mStripLen (0),
    43        mStripLen ( 0 ),
    43        mCurrentPos(0),
    44        mCurrentPos( 0 ),
    44        mItemSize (QSize(0,0)),
    45        mItemSize ( QSize( 0, 0 ) ),
    45        mModel ( NULL),
    46        mModel ( NULL ),
    46        mMoveDir(NO_MOVE),
    47        mMoveDir( NO_MOVE ),
    47        mSpeed ( GLX_COVERFLOW_SPEED ),
    48        mSpeed ( GLX_COVERFLOW_SPEED ),
    48 	   mZoomOn(false),
    49 	   mZoomOn( false ),
    49 	   mMultitouchFilter(NULL),
    50 	   mMultitouchFilter( NULL ),
    50        mTimerId(0)
    51        mTimerId( 0 ),
    51 {
    52        mIsInit( false )
    52 //TO:DO through exception
    53 {
    53    qDebug("GlxCoverFlow::GlxCoverFlow");
    54    qDebug( "GlxCoverFlow::GlxCoverFlow" );
    54    grabGesture(Qt::PanGesture);
    55    grabGesture( Qt::PanGesture );
    55    grabGesture(Qt::TapGesture);
    56    grabGesture( Qt::TapGesture );
    56    connect( this, SIGNAL( autoLeftMoveSignal() ), this, SLOT( autoLeftMove() ), Qt::QueuedConnection );
    57    connect( this, SIGNAL( autoLeftMoveSignal() ), this, SLOT( autoLeftMove() ), Qt::QueuedConnection );
    57    connect( this, SIGNAL( autoRightMoveSignal() ), this, SLOT( autoRightMove() ), Qt::QueuedConnection );   
    58    connect( this, SIGNAL( autoRightMoveSignal() ), this, SLOT( autoRightMove() ), Qt::QueuedConnection );   
    58 }
    59 }
    59 
    60 
    60 void GlxCoverFlow::setMultitouchFilter(QGraphicsItem* mtFilter)
    61 void GlxCoverFlow::setMultitouchFilter(QGraphicsItem* mtFilter)
    61 {
    62 {
    62 	mMultitouchFilter = mtFilter;
    63 	mMultitouchFilter = mtFilter;
    63 }
    64 }
       
    65 
    64 void GlxCoverFlow::setCoverFlow()
    66 void GlxCoverFlow::setCoverFlow()
    65 {
    67 {
    66     qDebug("GlxCoverFlow::setCoverFlow");
    68     qDebug("GlxCoverFlow::setCoverFlow");
    67     for ( qint8 i = 0; i < NBR_ICON_ITEM ; i++ ) {
    69     for ( qint8 i = 0; i < NBR_ICON_ITEM ; i++ ) {
    68         mIconItem[i] = new HbIconItem( this );
    70         mIconItem[i] = new HbIconItem( this );
    72         mIconItem[i]->setSize( QSize( 0, 0 ) );
    74         mIconItem[i]->setSize( QSize( 0, 0 ) );
    73         mIconItem[i]->setAlignment( Qt::AlignCenter );
    75         mIconItem[i]->setAlignment( Qt::AlignCenter );
    74         mIconItem[i]->setObjectName( QString( "Cover%1" ).arg( i ) );
    76         mIconItem[i]->setObjectName( QString( "Cover%1" ).arg( i ) );
    75     }
    77     }
    76     
    78     
    77     mUiOn = FALSE;
    79     mIsInit = true;
       
    80     mUiOn = false;
    78     mBounceBackDeltaX = GLX_BOUNCEBACK_DELTA;
    81     mBounceBackDeltaX = GLX_BOUNCEBACK_DELTA;
    79 }
    82 }
    80 
    83 
    81 void GlxCoverFlow::setItemSize(QSize &size)
    84 void GlxCoverFlow::setItemSize(QSize &size)
    82 {
    85 {
   117                 mTimerId = startTimer(500);
   120                 mTimerId = startTimer(500);
   118             }
   121             }
   119             else {
   122             else {
   120                 killTimer(mTimerId);
   123                 killTimer(mTimerId);
   121                 mTimerId = 0;
   124                 mTimerId = 0;
   122                 emit doubleTapEventReceived(gesture->position());
   125                 emit doubleTapEventReceived(hbInstance->allMainWindows().first()->mapToScene(gesture->position().toPoint()));
   123             }
   126             }
   124             event->accept(gesture);
   127             event->accept(gesture);
   125         }
   128         }
   126     }
   129     }
   127   
   130   
   158 }
   161 }
   159 
   162 
   160 void GlxCoverFlow::panGesture ( const QPointF & delta )  
   163 void GlxCoverFlow::panGesture ( const QPointF & delta )  
   161 {
   164 {
   162     qDebug("GlxCoverFlow::panGesture deltaX= %d", (int)delta.x());  
   165     qDebug("GlxCoverFlow::panGesture deltaX= %d", (int)delta.x());  
   163     if(getSubState() == IMAGEVIEWER_S || getSubState() == FETCHER_S ) {
   166    
       
   167     if( !mIsInit || getSubState() == IMAGEVIEWER_S || getSubState() == FETCHER_S ) {
   164         return;
   168         return;
   165     }
   169     }
   166     move((int) delta.x());    
   170     move( ( int ) delta.x() );    
   167     if( delta.x() > 0 ) {     
   171     if( delta.x() > 0 ) {     
   168         mMoveDir = RIGHT_MOVE;
   172         mMoveDir = RIGHT_MOVE;
   169     }
   173     }
   170     else if ( delta.x() < 0) {
   174     else if ( delta.x() < 0) {
   171         mMoveDir = LEFT_MOVE;
   175         mMoveDir = LEFT_MOVE;
   236 void GlxCoverFlow::autoLeftMove()
   240 void GlxCoverFlow::autoLeftMove()
   237 {
   241 {
   238     int width = mItemSize.width() ;
   242     int width = mItemSize.width() ;
   239     
   243     
   240     qDebug("GlxCoverFlow::autoLeftMove current pos = %d mBounceBackDeltaX x = %d", mCurrentPos, mBounceBackDeltaX);
   244     qDebug("GlxCoverFlow::autoLeftMove current pos = %d mBounceBackDeltaX x = %d", mCurrentPos, mBounceBackDeltaX);
   241     
   245     if ( !mIsInit ) {
   242     if ( mSelIndex == ( mRows -1 )) {
   246         return;
       
   247     }
       
   248     
       
   249     if ( mSelIndex == ( mRows -1 ) ) {
   243         mSpeed = GLX_BOUNCEBACK_SPEED;
   250         mSpeed = GLX_BOUNCEBACK_SPEED;
   244     }
   251     }
   245     //for bounce back effect for last image ( it will do the back)
   252     //for bounce back effect for last image ( it will do the back)
   246     if ( ( mCurrentPos + width ) > ( mStripLen + mBounceBackDeltaX ) && mMoveDir == NO_MOVE ) {
   253     if ( ( mCurrentPos + width ) > ( mStripLen + mBounceBackDeltaX ) && mMoveDir == NO_MOVE ) {
   247         mMoveDir = LEFT_MOVE;
   254         mMoveDir = LEFT_MOVE;
   286 }
   293 }
   287 
   294 
   288 void GlxCoverFlow::autoRightMove()
   295 void GlxCoverFlow::autoRightMove()
   289 {
   296 {
   290     qDebug("GlxCoverFlow::autoRightMove ");
   297     qDebug("GlxCoverFlow::autoRightMove ");
       
   298     if ( !mIsInit ) {
       
   299         return;
       
   300     }
   291     int width = mItemSize.width()  ;
   301     int width = mItemSize.width()  ;
   292     int diffX = mStripLen - mCurrentPos ;
   302     int diffX = mStripLen - mCurrentPos ;
   293     
   303  
   294     //slow the speed for bounce back effect
   304     //slow the speed for bounce back effect
   295     if ( mSelIndex == 0 ) {
   305     if ( mSelIndex == 0 ) {
   296         mSpeed = GLX_BOUNCEBACK_SPEED;
   306         mSpeed = GLX_BOUNCEBACK_SPEED;
   297     }
   307     }
   298     //for bounce back effect for back image ( it will do the back)
   308     //for bounce back effect for back image ( it will do the back)
   398 }
   408 }
   399 
   409 
   400 void GlxCoverFlow::loadIconItems()
   410 void GlxCoverFlow::loadIconItems()
   401 {  
   411 {  
   402     qDebug("GlxCoverFlow::loadIconItems ");
   412     qDebug("GlxCoverFlow::loadIconItems ");
       
   413     
       
   414     if ( !mIsInit ) {
       
   415         return ;
       
   416     }
       
   417 
   403     int index = 0;
   418     int index = 0;
   404     stopAnimation();
   419     stopAnimation();
   405     mSelIndex = getFocusIndex();
   420     mSelIndex = getFocusIndex();
   406     
   421     
   407     qDebug("GlxCoverFlow::loadIconItems index = %d, width = %d", mSelIndex, size().width() );    
   422     qDebug("GlxCoverFlow::loadIconItems index = %d, width = %d", mSelIndex, size().width() );    
   427 }
   442 }
   428 
   443 
   429 void GlxCoverFlow::stopAnimation()
   444 void GlxCoverFlow::stopAnimation()
   430 {
   445 {
   431     mIconItem[ mSelItemIndex ]->animator().stopAnimation();
   446     mIconItem[ mSelItemIndex ]->animator().stopAnimation();
       
   447     mIconItem[ mSelItemIndex ]->setIcon( getIcon( mSelIndex ) );
   432 }
   448 }
   433 
   449 
   434 void GlxCoverFlow::updateIconItem (qint16 selIndex, qint16 selItemIndex, qint16 posX)
   450 void GlxCoverFlow::updateIconItem (qint16 selIndex, qint16 selItemIndex, qint16 posX)
   435 {
   451 {
   436     qDebug("GlxCoverFlow::updateIconItem selIndex = %d, selIconIndex = %d posX = %d", selIndex, selItemIndex, posX );
   452     qDebug("GlxCoverFlow::updateIconItem selIndex = %d, selIconIndex = %d posX = %d", selIndex, selItemIndex, posX );
   476 
   492 
   477 void GlxCoverFlow::partiallyClean()
   493 void GlxCoverFlow::partiallyClean()
   478 {
   494 {
   479     qDebug("GlxCoverFlow::partiallyClean Enter");
   495     qDebug("GlxCoverFlow::partiallyClean Enter");
   480     clearCurrentModel(); //during the animation data update will not cause the crash
   496     clearCurrentModel(); //during the animation data update will not cause the crash
       
   497     mIsInit = false;
   481     for ( qint8 i = 0; i < NBR_ICON_ITEM ; i++ ) {
   498     for ( qint8 i = 0; i < NBR_ICON_ITEM ; i++ ) {
   482         if ( mSelItemIndex != i){
   499         if ( mSelItemIndex != i){
   483             delete mIconItem[i] ;
   500             delete mIconItem[i] ;
   484             mIconItem[i] = NULL;
   501             mIconItem[i] = NULL;
   485         }
   502         }
   486     }      
   503     }      
   487 }
   504 }
   488 
   505 
   489 void GlxCoverFlow::partiallyCreate(QAbstractItemModel *model, QSize itemSize)
   506 void GlxCoverFlow::partiallyCreate( QAbstractItemModel *model, QSize itemSize, int posY )
   490 {
   507 {
   491     qDebug("GlxCoverFlow::resetpartiallyCreated");
   508     qDebug("GlxCoverFlow::resetpartiallyCreated poxY %d", posY );
   492     mIconItem[2]->setSize ( itemSize );
   509     mIconItem[2]->setSize ( itemSize );
   493     mIconItem[2]->setPos ( QPointF ( 0, 0) ); 
   510     mIconItem[2]->setPos ( QPointF ( 0, posY ) ); 
   494     mModel = model ; 
   511     mModel = model ; 
   495     mSelIndex = getFocusIndex();
   512     mSelIndex = getFocusIndex();
   496     mIconItem[2]->setIcon( getIcon( mSelIndex ) ) ;
   513     mIconItem[2]->setIcon( getIcon( mSelIndex ) ) ;
   497     mModel = NULL;
   514     mModel = NULL;
   498 }
   515 }
   506 }
   523 }
   507 
   524 
   508 void GlxCoverFlow::ClearCoverFlow()
   525 void GlxCoverFlow::ClearCoverFlow()
   509 {
   526 {
   510     qDebug("GlxCoverFlow::ClearCoverFlow  " );
   527     qDebug("GlxCoverFlow::ClearCoverFlow  " );
       
   528     mIsInit = false;
   511     clearCurrentModel();    
   529     clearCurrentModel();    
   512     for ( qint8 i = 0; i < NBR_ICON_ITEM ; i++ ) {
   530     for ( qint8 i = 0; i < NBR_ICON_ITEM ; i++ ) {
   513         if(mIconItem[i] != NULL ) {
   531         if(mIconItem[i] != NULL ) {
   514             delete mIconItem[i] ;
   532             delete mIconItem[i] ;
   515             mIconItem[i] = NULL;
   533             mIconItem[i] = NULL;
   528 }
   546 }
   529 
   547 
   530 void GlxCoverFlow::zoomStarted(int index)
   548 void GlxCoverFlow::zoomStarted(int index)
   531 {
   549 {
   532     Q_UNUSED(index)
   550     Q_UNUSED(index)
       
   551     emit coverFlowEvent( ZOOM_START_EVENT );
   533     stopAnimation();
   552     stopAnimation();
   534 	mZoomOn = true;	
   553 	mZoomOn = true;	
   535 }
   554 }
   536 
   555 
   537 void GlxCoverFlow::zoomFinished(int index)
   556 void GlxCoverFlow::zoomFinished(int index)