ui/viewmanagement/viewmanager/src/glxviewmanager.cpp
changeset 54 0f0f3f26f787
parent 52 a3a4c0de738e
child 58 383b67fbdb11
equal deleted inserted replaced
52:a3a4c0de738e 54:0f0f3f26f787
    38 #include <hbprogressdialog.h>
    38 #include <hbprogressdialog.h>
    39 #include <QItemSelectionModel>
    39 #include <QItemSelectionModel>
    40 #include <glxmainwindoweventfilter.h>
    40 #include <glxmainwindoweventfilter.h>
    41 #include <xqsettingsmanager.h>
    41 #include <xqsettingsmanager.h>
    42 #include <xqsettingskey.h>
    42 #include <xqsettingskey.h>
    43 
    43 #include <glxviewids.h>
       
    44 #include "glxmodelroles.h"
    44 
    45 
    45 GlxViewManager::GlxViewManager() 
    46 GlxViewManager::GlxViewManager() 
    46     : mBackAction( NULL ), 
    47     : mBackAction( NULL ), 
    47       mMenuManager( NULL ), 
    48       mMenuManager( NULL ), 
    48       mEffectEngine( NULL ), 
    49       mEffectEngine( NULL ), 
    50       mMarkingToolBar( NULL ), 
    51       mMarkingToolBar( NULL ), 
    51       mSelectionModel ( NULL ),
    52       mSelectionModel ( NULL ),
    52       mProgressDialog( NULL )
    53       mProgressDialog( NULL )
    53 {
    54 {
    54     qDebug("GlxViewManager::GlxViewManager() ");
    55     qDebug("GlxViewManager::GlxViewManager() ");
    55     PERFORMANCE_ADV ( viewMgrD1, "main window creation time" ) {
    56 
    56         //check the case when application launch through some other application (view plugin)
    57     //check the case when application launch through some other application (view plugin)
    57         mMainWindow = GlxExternalUtility::instance()->getMainWindow();
    58     mMainWindow = GlxExternalUtility::instance()->getMainWindow();
    58         if(mMainWindow == NULL)	{
    59     if(mMainWindow == NULL)	{
    59             mMainWindow = new HbMainWindow();
    60         mMainWindow = new HbMainWindow();
    60             connect(mMainWindow, SIGNAL( viewReady() ), this, SLOT( handleReadyView() ));
    61     }
    61         }
    62     connect(mMainWindow, SIGNAL( viewReady() ), this, SLOT( handleReadyView() ));
    62 		//Without this Zoom Does not work
    63     //Without this Zoom Does not work
    63 
    64 
    64 		mWindowEventFilter = new GlxMainWindowEventFilter;
    65     mWindowEventFilter = new GlxMainWindowEventFilter;
    65 		mMainWindow->scene()->installEventFilter(mWindowEventFilter);
    66     mMainWindow->scene()->installEventFilter(mWindowEventFilter);
    66 		mMainWindow->viewport()->setAttribute(Qt::WA_AcceptTouchEvents);
    67     mMainWindow->viewport()->setAttribute(Qt::WA_AcceptTouchEvents);
    67 		mMainWindow->viewport()->grabGesture(Qt::PinchGesture);
    68     mMainWindow->viewport()->grabGesture(Qt::PinchGesture);
    68     }
    69 
    69     HbStyleLoader::registerFilePath(":/data/photos.css");
    70     HbStyleLoader::registerFilePath(":/data/photos.css");
    70 }
    71 }
       
    72 
    71 void GlxViewManager::handleReadyView()
    73 void GlxViewManager::handleReadyView()
    72 {
    74 {
    73     emit actionTriggered( EGlxCmdSetupItem );
    75     emit actionTriggered( EGlxCmdSetupItem );
    74     emit applicationReady();
    76     emit applicationReady();
    75     disconnect(mMainWindow, SIGNAL( viewReady() ), this, SLOT( handleReadyView() ));
    77     disconnect(mMainWindow, SIGNAL( viewReady() ), this, SLOT( handleReadyView() ));
    76 }
    78 }
    77 
    79 
    78 void GlxViewManager::setupItems( )
    80 void GlxViewManager::setupItems( )
    79 {
    81 {
    80     mMenuManager = new GlxMenuManager(mMainWindow);
       
    81     addBackSoftKeyAction();    
    82     addBackSoftKeyAction();    
    82     addConnection();    
    83     addConnection();
    83     mMenuManager->addMenu( mView->viewId(), mView->menu() );
    84 }
       
    85 
       
    86 void GlxViewManager::launchApplication(qint32 id, QAbstractItemModel *model)
       
    87 {
       
    88     mModel = model;
       
    89     mMenuManager = new GlxMenuManager( mMainWindow );  //menu manager should be created before view.
    84     mMenuManager->setModel( mModel );
    90     mMenuManager->setModel( mModel );
    85 }
    91     mView = resolveView( id );
    86 
    92 
    87 void GlxViewManager::launchApplication(qint32 id, QAbstractItemModel *model)
       
    88 {
       
    89     mModel = model;
       
    90     PERFORMANCE_ADV ( viewMgrD1, "View Creation time" ) {
       
    91         mView = resolveView(id);
       
    92     }
       
    93     createToolBar();
    93     createToolBar();
    94     mView->addToolBar(mViewToolBar);
       
    95     
    94     
    96     /* We are showing the toolBar before activating the 
    95     /* We are showing the toolBar before activating the 
    97      * view. This is done to avoid the animation effect seen otherwise 
    96      * view. This is done to avoid the animation effect seen otherwise 
    98      * when the tool bar comes up.
    97      * when the tool bar comes up.
    99      * 
    98      * 
   101      * since we are creating a new tool bar..although a fake tool bar was 
   100      * since we are creating a new tool bar..although a fake tool bar was 
   102      * already created on the splashscreen
   101      * already created on the splashscreen
   103      * 
   102      * 
   104      */
   103      */
   105     mView->activate();
   104     mView->activate();
   106     
   105     mView->setModel( mModel );
   107     PERFORMANCE_ADV ( viewMgrD3, "Set Model time")  
   106     //visibility of tool bar dependes of view internal state so add the toolbar after setting model
   108         mView->setModel(mModel);
   107     mView->addToolBar( mViewToolBar ); 
   109         
   108     mMainWindow->setCurrentView( mView, false );
   110     PERFORMANCE_ADV( viewMgrD4, "View Display time") {
   109     mMainWindow->showFullScreen();
   111         mMainWindow->setCurrentView(mView, false);
       
   112         mMainWindow->showFullScreen();           
       
   113     }    
       
   114 }
   110 }
   115 
   111 
   116 void GlxViewManager::handleMenuAction(qint32 commandId)
   112 void GlxViewManager::handleMenuAction(qint32 commandId)
   117 {
   113 {
   118     emit actionTriggered(commandId);
   114     emit actionTriggered(commandId);
   119 }
   115 }
   120 
   116 
   121 void GlxViewManager::handleAction()
   117 void GlxViewManager::handleAction()
   122 {
   118 {
   123     HbAction *action = qobject_cast<HbAction*>(sender());
   119     HbAction *action = qobject_cast<HbAction*>(sender());
       
   120     action->setChecked( TRUE );
   124     qint32 commandId = action->data().toInt();
   121     qint32 commandId = action->data().toInt();
   125     emit actionTriggered(commandId);
   122     emit actionTriggered(commandId);
   126 }
   123 }
   127 
   124 
   128 void GlxViewManager::addBackSoftKeyAction ( )
   125 void GlxViewManager::addBackSoftKeyAction ( )
   138 Qt::Orientation GlxViewManager::orientation() const
   135 Qt::Orientation GlxViewManager::orientation() const
   139 {
   136 {
   140     return mMainWindow->orientation();
   137     return mMainWindow->orientation();
   141 }
   138 }
   142 
   139 
   143 void GlxViewManager::launchView(qint32 id, QAbstractItemModel *model)
   140 void GlxViewManager::launchView( qint32 id, QAbstractItemModel *model )
   144 {
   141 {
   145     qDebug("GlxViewManager::launchView Id = %d ", id);
   142     qDebug( "GlxViewManager::launchView Id = %d ", id );
   146     mModel = model;
   143     mModel = model;
   147     deActivateView();
   144     deActivateView();
   148     
   145     mMenuManager->setModel( mModel ); //set the model to get the item type info and row count info
   149     PERFORMANCE_ADV ( viewMgrD1, "View Creation time" ) {
   146     mView = resolveView( id );
   150         mView = resolveView(id);
       
   151     }
       
   152     
       
   153     activateView();
   147     activateView();
   154 }
   148 }
   155 
   149 
   156 void GlxViewManager::launchView (qint32 id, QAbstractItemModel *model, GlxEffect effect, GlxViewEffect viewEffect)
   150 void GlxViewManager::launchView (qint32 id, QAbstractItemModel *model, GlxEffect effect, GlxViewEffect viewEffect)
   157 {
   151 {
   174     itemList.clear();
   168     itemList.clear();
   175     
   169     
   176     //partially clean the view so that animation run smoothly
   170     //partially clean the view so that animation run smoothly
   177     GlxView *curr_view = (GlxView *) mMainWindow->currentView();
   171     GlxView *curr_view = (GlxView *) mMainWindow->currentView();
   178     curr_view->resetView();
   172     curr_view->resetView();
   179     
   173 
       
   174     mMenuManager->setModel( model ); //set the model to get the item type info and row count info
   180     mView = resolveView(id);
   175     mView = resolveView(id);
   181     //partially initialise the view so that animation run smoothly
   176     //partially initialise the view so that animation run smoothly
   182     mView->initializeView( model, curr_view );
   177     mView->initializeView( model, curr_view );
   183     mModel = model; 
   178     mModel = model; 
   184 
   179 
   199             item->show();        
   194             item->show();        
   200             itemList.append(item);
   195             itemList.append(item);
   201         }
   196         }
   202     }
   197     }
   203     
   198     
       
   199     if ( effect == GRID_TO_FULLSCREEN ) {
       
   200         mViewToolBar->setZValue( item->zValue() - 5 );
       
   201     }
       
   202     
   204     //error check
   203     //error check
   205     if ( itemList.count() > 0 ) {
   204     if ( itemList.count() > 0 ) {
   206         mEffectEngine->runEffect(itemList, effect);
   205         mEffectEngine->runEffect(itemList, effect);
   207         mMainWindow->grabMouse();
   206         mMainWindow->grabMouse();
   208     }
   207     }
   245     User::ResetInactivityTime();  
   244     User::ResetInactivityTime();  
   246 
   245 
   247     //To:Do temp code remove later
   246     //To:Do temp code remove later
   248     if ( mProgressDialog ) {
   247     if ( mProgressDialog ) {
   249         i = ++i % 10;
   248         i = ++i % 10;
   250         icon = HbIcon( QString( ":/data/wait/qgn_graf_ring_wait_%1.svg" ).arg( i + 1, 2, 10, QChar( '0' ) ) );
   249         icon = HbIcon( QString( ":/data/Wait/qgn_graf_ring_wait_%1.svg" ).arg( i + 1, 2, 10, QChar( '0' ) ) );
   251         mProgressDialog->setIcon(icon);
   250         mProgressDialog->setIcon(icon);
   252         
   251         
   253         int max = mProgressDialog->maximum() ;
   252         int max = mProgressDialog->maximum() ;
   254         if ( currentValue > max ) {
   253         if ( currentValue > max ) {
   255             mProgressDialog->setMaximum( currentValue );
   254             mProgressDialog->setMaximum( currentValue );
   283     int toolBarActionId = (int) GLX_ALL_ACTION_ID;
   282     int toolBarActionId = (int) GLX_ALL_ACTION_ID;
   284     int count = mActionList.count();
   283     int count = mActionList.count();
   285     
   284     
   286     qDebug("GlxViewManager::updateToolBarIcon() action ID list %d count %d", id, count);
   285     qDebug("GlxViewManager::updateToolBarIcon() action ID list %d count %d", id, count);
   287     
   286     
   288     for ( int i = 0; i < count ; i++ )
   287     for ( int i = 0; i < count ; i++ ) {
   289         {
       
   290         qDebug("GlxViewManager::updateToolBarIcon() toolBarActionId %d value %d", toolBarActionId, ( id & toolBarActionId ) );
   288         qDebug("GlxViewManager::updateToolBarIcon() toolBarActionId %d value %d", toolBarActionId, ( id & toolBarActionId ) );
   291         //check and get the icon path
   289         //check and get the icon path
   292         if ( ( id & toolBarActionId ) == toolBarActionId )
   290         if ( ( id & toolBarActionId ) == toolBarActionId ) {
   293             {
       
   294             mActionList[i]->setCheckable(TRUE);
       
   295             mActionList[i]->setChecked(TRUE);                        
   291             mActionList[i]->setChecked(TRUE);                        
   296             }
   292         }
   297         else 
   293         else {
   298             {
       
   299             mActionList[i]->setChecked(FALSE);
   294             mActionList[i]->setChecked(FALSE);
   300             }
   295         }
   301         //to get it the next action id to verify it is selecter or not
   296         //to get it the next action id to verify it is selecter or not
   302         toolBarActionId = toolBarActionId << 1; 
   297         toolBarActionId = toolBarActionId << 1; 
   303         }
   298     }
   304 }
   299 }
   305 
   300 
   306 void GlxViewManager::checkMarked()
   301 void GlxViewManager::checkMarked()
   307 {
   302 {
   308     qDebug("GlxViewManager::checkMarked");
   303     qDebug("GlxViewManager::checkMarked");
   382     if ( mMenuManager ) {
   377     if ( mMenuManager ) {
   383         mMenuManager->setModel( model );
   378         mMenuManager->setModel( model );
   384     }    
   379     }    
   385 }
   380 }
   386 
   381 
   387 GlxView * GlxViewManager::resolveView(qint32 id)
   382 GlxView * GlxViewManager::resolveView( qint32 id )
   388 {
   383 {
   389     qDebug("GlxViewManager::resolveView %d", id);
   384     qDebug("GlxViewManager::resolveView %d", id );
   390     GlxView *view = findView ( id );
   385     GlxView *view = findView ( id );
   391     if ( view ) {
   386     if ( view ) {
   392         return view ;
   387         return view ;
   393     }
   388     }
   394     
   389     
   395     view = GlxViewsFactory::createView(id, mMainWindow);
   390     view = GlxViewsFactory::createView( id, mMainWindow );
   396     if ( view ) {
   391     if ( view ) {
   397         connect ( view, SIGNAL(actionTriggered(qint32 )), this, SLOT(actionProcess(qint32 )), Qt::QueuedConnection );
   392         connect ( view, SIGNAL( actionTriggered( qint32 ) ), this, SLOT( actionProcess( qint32 ) ), Qt::QueuedConnection );
   398         connect ( view, SIGNAL(itemSpecificMenuTriggered(qint32,QPointF ) ), this, SLOT( itemSpecificMenuTriggered(qint32,QPointF ) ), Qt::QueuedConnection );
   393         connect ( view, SIGNAL( itemSpecificMenuTriggered( qint32, QPointF ) ), this, SLOT( itemSpecificMenuTriggered( qint32, QPointF ) ), Qt::QueuedConnection );
   399         mViewList.append(view);
   394         mViewList.append( view );
   400         mMainWindow->addView(view);
   395         mMainWindow->addView( view );
   401         if ( mMenuManager ) {
   396         mMenuManager->addMenu( id, view->menu() );
   402             mMenuManager->addMenu( id, view->menu());
   397         
   403         }
       
   404         if ( mBackAction ) {
   398         if ( mBackAction ) {
   405             view->setNavigationAction( mBackAction );
   399             view->setNavigationAction( mBackAction );
   406         }
   400         }
   407     }
   401     }
   408     return view;
   402     return view;
   453 }
   447 }
   454 
   448 
   455 void GlxViewManager::activateView()
   449 void GlxViewManager::activateView()
   456 {
   450 {
   457     qDebug("GlxViewManager::activateView()");
   451     qDebug("GlxViewManager::activateView()");
   458         
   452 
   459     PERFORMANCE_ADV ( viewMgrD2, "View Activation time") {
   453     mView->activate();
   460         mView->addToolBar(mViewToolBar);
   454     mView->show();
   461         mView->activate();
   455     mView->setModel( mModel );
   462         mView->show();
   456     //visibility of tool bar dependes of view internal state so add the toolbar after setting model
   463         mMenuManager->setModel( mModel ); //set the model to get the item type info and row count info
   457     mView->addToolBar( mViewToolBar );
   464     }        
   458     mMainWindow->setCurrentView(mView, false);
   465       
   459     mMainWindow->showFullScreen(); 
   466     PERFORMANCE_ADV ( viewMgrD3, "Set Model time")  
       
   467         mView->setModel(mModel);
       
   468         
       
   469     PERFORMANCE_ADV( viewMgrD4, "View Display time") {
       
   470         mMainWindow->setCurrentView(mView, false);
       
   471         mMainWindow->showFullScreen();           
       
   472     }
       
   473 }
   460 }
   474 
   461 
   475 void GlxViewManager::createActions()
   462 void GlxViewManager::createActions()
   476 {
   463 {
   477     qDebug("GlxViewManager::createActions() " );
   464     qDebug("GlxViewManager::createActions() " );
   478     mActionList.clear();  
   465     mActionList.clear();  
       
   466 
       
   467     int curSubstate = getSubState();    
   479     
   468     
   480     //create the All tool bar button action
   469     //create the All tool bar button action
   481     HbAction* allAction = new HbAction( this );
   470     HbAction* allAction = new HbAction( this );
   482     allAction->setData( EGlxCmdAllGridOpen );
   471 
       
   472     if( curSubstate == FETCHER_ITEM_S ) {
       
   473         allAction->setData( EGlxCmdFetcherAllGridOpen );
       
   474     }else{
       
   475         allAction->setData( EGlxCmdAllGridOpen );
       
   476     }
       
   477 
   483     mActionList.append( allAction );    
   478     mActionList.append( allAction );    
   484     allAction->setIcon( HbIcon( GLXICON_ALL ) ) ;
   479     allAction->setIcon( HbIcon( GLXICON_ALL ) ) ;
   485     allAction->setObjectName( "All Action" );
   480     allAction->setObjectName( "All Action" );
   486        
   481        
   487     //create the Album tool bar button action
   482     //create the Album tool bar button action
   488     HbAction* albumAction = new HbAction( this );
   483     HbAction* albumAction = new HbAction( this );
   489     albumAction->setData( EGlxCmdAlbumListOpen );
   484 
       
   485     if( curSubstate == FETCHER_ITEM_S ) {
       
   486         albumAction->setData( EGlxCmdFetcherAlbumListOpen );
       
   487     }else{
       
   488         albumAction->setData( EGlxCmdAlbumListOpen );
       
   489     }
       
   490 
   490     mActionList.append( albumAction );
   491     mActionList.append( albumAction );
   491     albumAction->setIcon( HbIcon( GLXICON_ALBUMS ) ) ;
   492     albumAction->setIcon( HbIcon( GLXICON_ALBUMS ) ) ;
   492     albumAction->setObjectName( "Album Action" );
   493     albumAction->setObjectName( "Album Action" );
   493    
   494 	
       
   495 	//in case of fetcher no need to create other actions
       
   496 	if( curSubstate == FETCHER_ITEM_S ) {
       
   497 		return;
       
   498 		}	
   494     //create the album tool bar button action
   499     //create the album tool bar button action
   495     HbAction* cameraAction = new HbAction( this );
   500     HbAction* cameraAction = new HbAction( this );
   496     cameraAction->setData( EGlxCmdCameraOpen );
   501     cameraAction->setData( EGlxCmdCameraOpen );
   497     mActionList.append( cameraAction );  
   502     mActionList.append( cameraAction );  
   498     cameraAction->setIcon( HbIcon( GLXICON_CAMERA ) ) ;
   503     cameraAction->setIcon( HbIcon( GLXICON_CAMERA ) ) ;
   572     
   577     
   573     qDebug("GlxViewManager::createToolBar() clear the action" );
   578     qDebug("GlxViewManager::createToolBar() clear the action" );
   574     int count = mActionList.count();
   579     int count = mActionList.count();
   575     for ( int i = 0; i < count; i++ ) {
   580     for ( int i = 0; i < count; i++ ) {
   576         connect( mActionList.at(i), SIGNAL(triggered( )), this, SLOT(handleAction( )) );
   581         connect( mActionList.at(i), SIGNAL(triggered( )), this, SLOT(handleAction( )) );
       
   582         mActionList.at(i)->setCheckable( TRUE );
   577         mViewToolBar->addAction( mActionList.at(i) );      
   583         mViewToolBar->addAction( mActionList.at(i) );      
   578     }
   584     }
   579     qDebug("GlxViewManager::createToolBar() exit" );
   585     qDebug("GlxViewManager::createToolBar() exit" );
   580 }
   586 }
   581 
   587 
   670         mEffectEngine->deregistertransitionEffect();
   676         mEffectEngine->deregistertransitionEffect();
   671         delete mEffectEngine;
   677         delete mEffectEngine;
   672     }
   678     }
   673  
   679  
   674     if( mMainWindow != GlxExternalUtility::instance()->getMainWindow() ){
   680     if( mMainWindow != GlxExternalUtility::instance()->getMainWindow() ){
   675         qDebug("GlxViewManager::~GlxViewManager remove view");
   681         qDebug("GlxViewManager::~GlxViewManager delete mainwindow");
   676         delete mMainWindow;
   682         delete mMainWindow;
   677     }
   683     }
   678     delete mWindowEventFilter;
   684     delete mWindowEventFilter;
   679     
   685     
   680     qDebug("GlxViewManager::~GlxViewManager Exit");
   686     qDebug("GlxViewManager::~GlxViewManager Exit");
   681 }
   687 }
   682 
   688 
       
   689 int GlxViewManager::getSubState()
       
   690 {
       
   691     int curSubstate = NO_GRID_S;    
       
   692     
       
   693     if ( mModel  ) {    
       
   694         QVariant variant = mModel->data( mModel->index(0,0), GlxSubStateRole );    
       
   695         if ( variant.isValid() &&  variant.canConvert<int> ()  ) {
       
   696             curSubstate = variant.value<int>();
       
   697         }
       
   698     }
       
   699     return curSubstate;
       
   700 }