ui/viewmanagement/viewmanager/src/glxviewmanager.cpp
changeset 72 0a8e959402e5
parent 71 27f2d7aec52a
equal deleted inserted replaced
71:27f2d7aec52a 72:0a8e959402e5
    48       mMenuManager( NULL ), 
    48       mMenuManager( NULL ), 
    49       mEffectEngine( NULL ), 
    49       mEffectEngine( NULL ), 
    50       mViewToolBar( NULL ), 
    50       mViewToolBar( NULL ), 
    51       mMarkingToolBar( NULL ), 
    51       mMarkingToolBar( NULL ), 
    52       mSelectionModel ( NULL ),
    52       mSelectionModel ( NULL ),
    53       mProgressDialog( NULL )
    53       mProgressDialog( NULL ),
       
    54       mIsViewTransitionRunning( false ),
       
    55       mEffect( NO_EFFECT )
    54 {
    56 {
    55     qDebug("GlxViewManager::GlxViewManager() ");
    57     qDebug("GlxViewManager::GlxViewManager() ");
    56 
    58 
    57     //check the case when application launch through some other application (view plugin)
    59     //check the case when application launch through some other application (view plugin)
    58     mMainWindow = GlxExternalUtility::instance()->getMainWindow();
    60     mMainWindow = GlxExternalUtility::instance()->getMainWindow();
    59     if(mMainWindow == NULL)	{
    61     if(mMainWindow == NULL)	{
    60         mMainWindow = new HbMainWindow();
    62         mMainWindow = new HbMainWindow();
    61     }
    63     }
    62     connect(mMainWindow, SIGNAL( viewReady() ), this, SLOT( handleReadyView() ));
    64     connect( mMainWindow, SIGNAL( viewReady() ), this, 
       
    65             SLOT( handleReadyView() ) );
       
    66     
    63     //Without this Zoom Does not work
    67     //Without this Zoom Does not work
    64 
       
    65     mWindowEventFilter = new GlxMainWindowEventFilter;
    68     mWindowEventFilter = new GlxMainWindowEventFilter;
    66     mMainWindow->scene()->installEventFilter(mWindowEventFilter);
    69     mMainWindow->scene()->installEventFilter( mWindowEventFilter );
    67     mMainWindow->viewport()->setAttribute(Qt::WA_AcceptTouchEvents);
    70     mMainWindow->viewport()->setAttribute( Qt::WA_AcceptTouchEvents );
    68     mMainWindow->viewport()->grabGesture(Qt::PinchGesture);
    71     mMainWindow->viewport()->grabGesture( Qt::PinchGesture );
    69 
    72 
    70     HbStyleLoader::registerFilePath(":/data/photos.css");
    73     HbStyleLoader::registerFilePath( ":/data/photos.css" );
    71 }
    74 }
    72 
    75 
    73 void GlxViewManager::handleReadyView()
    76 GlxViewManager::~GlxViewManager()
    74 {
    77 {
    75     emit actionTriggered( EGlxCmdSetupItem );
    78     qDebug("GlxViewManager::~GlxViewManager");
    76     disconnect( mMainWindow, SIGNAL( viewReady() ), this, SLOT( handleReadyView() ) );
    79     HbStyleLoader::unregisterFilePath(":/data/photos.css");    
       
    80     removeConnection();
       
    81     
       
    82     delete mMenuManager; 
       
    83     delete mViewToolBar;
       
    84     delete mMarkingToolBar;
       
    85     
       
    86     while( mViewList.isEmpty( ) == FALSE){
       
    87         delete mViewList.takeLast() ;
       
    88     }
       
    89         
       
    90     delete mBackAction;
       
    91     delete mProgressDialog;
       
    92     
       
    93     if ( mEffectEngine ) {
       
    94         mEffectEngine->deregistertransitionEffect();
       
    95         delete mEffectEngine;
       
    96     }
       
    97  
       
    98     if( mMainWindow != GlxExternalUtility::instance()->getMainWindow() ){
       
    99         delete mMainWindow;
       
   100     }
       
   101     delete mWindowEventFilter;
       
   102     
       
   103     qDebug("GlxViewManager::~GlxViewManager Exit");
    77 }
   104 }
    78 
   105 
    79 void GlxViewManager::setupItems( )
   106 void GlxViewManager::setupItems( )
    80 {
   107 {
    81     addBackSoftKeyAction();    
   108     addBackSoftKeyAction();    
   106     mView->addToolBar( mViewToolBar ); 
   133     mView->addToolBar( mViewToolBar ); 
   107     mMainWindow->setCurrentView( mView, false );
   134     mMainWindow->setCurrentView( mView, false );
   108     mMainWindow->showFullScreen();
   135     mMainWindow->showFullScreen();
   109 }
   136 }
   110 
   137 
   111 void GlxViewManager::handleMenuAction(qint32 commandId)
       
   112 {
       
   113     emit actionTriggered(commandId);
       
   114 }
       
   115 
       
   116 void GlxViewManager::handleAction()
   138 void GlxViewManager::handleAction()
   117 {
   139 {
   118     HbAction *action = qobject_cast<HbAction*>(sender());
   140     HbAction *action = qobject_cast<HbAction*>(sender());
   119     action->setChecked( TRUE );
   141     action->setChecked( TRUE );
   120     qint32 commandId = action->data().toInt();
   142     qint32 commandId = action->data().toInt();
   150 {
   172 {
   151     qDebug("GlxViewManager::launchView Id = %d effect %d view effect %d", id, effect, viewEffect);
   173     qDebug("GlxViewManager::launchView Id = %d effect %d view effect %d", id, effect, viewEffect);
   152 
   174 
   153     //In the case of no animation is play during the view transition just call launch view and return
   175     //In the case of no animation is play during the view transition just call launch view and return
   154     if ( viewEffect == NO_VIEW ) {
   176     if ( viewEffect == NO_VIEW ) {
   155         return launchView(id, model);
   177         return launchView( id, model );
   156     }
   178     }
   157     
   179     
   158     //create and registered the effect
   180     //create and registered the effect
   159     if ( mEffectEngine == NULL ) { 
   181     if ( mEffectEngine == NULL ) { 
   160         mEffectEngine = new GlxEffectEngine();
   182         mEffectEngine = new GlxEffectEngine();
   161         mEffectEngine->registerTransitionEffect();
   183         mEffectEngine->registerTransitionEffect();
   162         connect( mEffectEngine, SIGNAL( effectFinished() ), this, SLOT( effectFinished() ), Qt::QueuedConnection );
   184         connect( mEffectEngine, SIGNAL( effectFinished() ), this, 
   163     }
   185                 SLOT( effectFinished() ), Qt::QueuedConnection );
   164     
   186     }
   165     QList< QGraphicsItem * > itemList;
   187     
   166     QGraphicsItem *item = NULL;
   188     QGraphicsItem *item = NULL;
   167     itemList.clear();
   189     mItemList.clear();
   168     
   190     
   169     //partially clean the view so that animation run smoothly
   191     //partially clean the view so that animation run smoothly
   170     GlxView *curr_view = (GlxView *) mMainWindow->currentView();
   192     GlxView *curr_view = (GlxView *) mMainWindow->currentView();
   171     curr_view->resetView();
   193     curr_view->resetView();
   172 
   194 
   175     //partially initialise the view so that animation run smoothly
   197     //partially initialise the view so that animation run smoothly
   176     mView->initializeView( model, curr_view );
   198     mView->initializeView( model, curr_view );
   177     mModel = model; 
   199     mModel = model; 
   178 
   200 
   179     if ( viewEffect == CURRENT_VIEW || viewEffect == BOTH_VIEW ) { 
   201     if ( viewEffect == CURRENT_VIEW || viewEffect == BOTH_VIEW ) { 
   180         item = curr_view->getAnimationItem(effect);
   202         item = curr_view->getAnimationItem( effect );
   181         if ( item ) {
   203         if ( item ) {
   182             itemList.append(item);
   204             mItemList.append(item);
   183             item = NULL;
   205             item = NULL;
   184         }
   206         }
   185     }
   207     }
   186     
   208     
   187     if ( viewEffect == LAUNCH_VIEW || viewEffect == BOTH_VIEW ) {
   209     if ( viewEffect == LAUNCH_VIEW || viewEffect == BOTH_VIEW ) {
   188         item = mView->getAnimationItem(effect);
   210         item = mView->getAnimationItem( effect );
   189         if ( item ) {
   211         if ( item ) {
   190             //increase the z value and show the view to shown the view animation
   212             //increase the z value and show the view to shown the view animation
   191             mView->setZValue(curr_view->zValue() + 2);
   213             mView->setZValue( curr_view->zValue() + 2 );
   192             mView->show();
   214             mView->show();
   193             item->show();        
   215             item->show();        
   194             itemList.append(item);
   216             mItemList.append( item );
   195         }
   217         }
   196     }
   218     }
   197     
   219     
   198     if ( effect == GRID_TO_FULLSCREEN ) {
   220     if ( effect == GRID_TO_FULLSCREEN ) {
   199         mViewToolBar->setZValue( item->zValue() - 5 );
   221         mViewToolBar->setZValue( item->zValue() - 5 );
   200     }
   222     }
   201     
   223     
   202     //error check
   224     //error check
   203     if ( itemList.count() > 0 ) {
   225     if ( mItemList.count() > 0 ) {
   204         mEffectEngine->runEffect(itemList, effect);
   226         mEffectEngine->runEffect( mItemList, effect );
   205         mMainWindow->grabMouse();
   227         mMainWindow->grabMouse();
       
   228         mIsViewTransitionRunning = true;
       
   229         mEffect = effect;
   206     }
   230     }
   207     else {
   231     else {
   208         deActivateView();
   232         deActivateView();
   209         activateView();       
   233         activateView();       
   210     }    
   234     }    
   219 		          
   243 		          
   220     }
   244     }
   221     if ( mProgressDialog == NULL ) {
   245     if ( mProgressDialog == NULL ) {
   222         mProgressDialog = new HbProgressDialog( HbProgressDialog::ProgressDialog );
   246         mProgressDialog = new HbProgressDialog( HbProgressDialog::ProgressDialog );
   223         mProgressDialog->actions().at(0)->disconnect( SIGNAL( triggered() ) );
   247         mProgressDialog->actions().at(0)->disconnect( SIGNAL( triggered() ) );
   224         connect ( mProgressDialog->actions().at(0), SIGNAL( triggered() ), this, SLOT( hideProgressDialog() ) );
   248         connect ( mProgressDialog->actions().at(0), SIGNAL( triggered() ), 
       
   249                 this, SLOT( hideProgressDialog() ) );
   225         mProgressDialog->setMinimum( 0 );
   250         mProgressDialog->setMinimum( 0 );
   226     }
   251     }
   227     mProgressDialog->setMaximum( maxValue );
   252     mProgressDialog->setMaximum( maxValue );
   228     mProgressDialog->setProgressValue( 0 );
   253     mProgressDialog->setProgressValue( 0 );
   229     mProgressDialog->setModal( true );
   254     mProgressDialog->setModal( true );
   292         if ( ( id & toolBarActionId ) == toolBarActionId ) {
   317         if ( ( id & toolBarActionId ) == toolBarActionId ) {
   293             mActionList[i]->setChecked(TRUE);                        
   318             mActionList[i]->setChecked(TRUE);                        
   294         }
   319         }
   295         else {
   320         else {
   296             mActionList[i]->setChecked(FALSE);
   321             mActionList[i]->setChecked(FALSE);
       
   322         }
       
   323         //to get it the next action id to verify it is selecter or not
       
   324         toolBarActionId = toolBarActionId << 1; 
       
   325     }
       
   326 }
       
   327 
       
   328 void GlxViewManager::updateToolBarActionState( int id, bool isChecked )
       
   329 {
       
   330     int toolBarActionId = (int) GLX_ALL_ACTION_ID;
       
   331     int count = mActionList.count();
       
   332     
       
   333     for ( int i = 0; i < count ; i++ ) {
       
   334         //check and get the icon path
       
   335         if ( ( id & toolBarActionId ) == toolBarActionId ) {
       
   336             mActionList[i]->setChecked( isChecked );                        
   297         }
   337         }
   298         //to get it the next action id to verify it is selecter or not
   338         //to get it the next action id to verify it is selecter or not
   299         toolBarActionId = toolBarActionId << 1; 
   339         toolBarActionId = toolBarActionId << 1; 
   300     }
   340     }
   301 }
   341 }
   325     setMarkingToolBarAction( commandId );
   365     setMarkingToolBarAction( commandId );
   326     
   366     
   327     if ( view ) { 
   367     if ( view ) { 
   328         view->enableMarking();
   368         view->enableMarking();
   329         view->takeToolBar();
   369         view->takeToolBar();
   330         view->addToolBar(mMarkingToolBar);
   370         view->addToolBar( mMarkingToolBar );
   331         mSelectionModel = view->getSelectionModel();
   371         mSelectionModel = view->getSelectionModel();
   332         if(mSelectionModel) 
   372         if( mSelectionModel ) {
   333         {
   373             connect(mSelectionModel, SIGNAL( selectionChanged
   334             connect(mSelectionModel, SIGNAL(selectionChanged(const QItemSelection &, const QItemSelection& ) ), this, SLOT(checkMarked()));
   374                     ( const QItemSelection &, const QItemSelection& ) ),
       
   375                     this, SLOT( checkMarked() ) );
   335             checkMarked();
   376             checkMarked();
   336         }
   377         }
   337     }
   378     }
   338     qDebug("GlxViewManager::enterMarkingMode view ID %d exit", viewId);
       
   339 }
   379 }
   340 
   380 
   341 void GlxViewManager::exitMarkingMode( qint32 viewId )
   381 void GlxViewManager::exitMarkingMode( qint32 viewId )
   342 {
   382 {
   343     GlxView *view = findView ( viewId );
   383     GlxView *view = findView ( viewId );
   344     qDebug("GlxViewManager::exitMarkingMode view ID %d", viewId);
   384     qDebug( "GlxViewManager::exitMarkingMode view ID %d", viewId );
   345     if ( view ) { 
   385     if ( view ) { 
   346         view->disableMarking(); 
   386         view->disableMarking(); 
   347         view->takeToolBar();
   387         view->takeToolBar();
   348         view->addToolBar(mViewToolBar);
   388         view->addToolBar( mViewToolBar );
   349         if(mSelectionModel)
   389         if( mSelectionModel ) {
   350         {
   390             disconnect( mSelectionModel, SIGNAL( selectionChanged
   351             disconnect(mSelectionModel, SIGNAL(selectionChanged(const QItemSelection &, const QItemSelection& ) ), this, SLOT(checkMarked()));
   391                     ( const QItemSelection &, const QItemSelection& ) ), 
   352         }
   392                     this, SLOT( checkMarked() ) );
   353     }
   393         }
   354     qDebug("GlxViewManager::exitMarkingMode view ID %d exit", viewId);
   394     }
   355 }
   395 }
   356 
   396 
   357 void GlxViewManager::handleUserAction(qint32 viewId, qint32 commandId)
   397 void GlxViewManager::handleUserAction(qint32 viewId, qint32 commandId)
   358 {
   398 {
   359     GlxView *view = findView ( viewId );
   399     GlxView *view = findView ( viewId );
   379     }
   419     }
   380     
   420     
   381     if ( mMenuManager ) {
   421     if ( mMenuManager ) {
   382         mMenuManager->setModel( model );
   422         mMenuManager->setModel( model );
   383     }    
   423     }    
       
   424 }
       
   425 
       
   426 void GlxViewManager::cancelViewTransitionEffect()
       
   427 {
       
   428     if( mIsViewTransitionRunning ) {
       
   429         mEffectEngine->cancelEffect( mItemList, mEffect );
       
   430         effectFinished();
       
   431     }
   384 }
   432 }
   385 
   433 
   386 GlxView * GlxViewManager::resolveView( qint32 id )
   434 GlxView * GlxViewManager::resolveView( qint32 id )
   387 {
   435 {
   388     qDebug("GlxViewManager::resolveView %d", id );
   436     qDebug("GlxViewManager::resolveView %d", id );
   409 void GlxViewManager::itemSpecificMenuTriggered(qint32 viewId,QPointF pos)
   457 void GlxViewManager::itemSpecificMenuTriggered(qint32 viewId,QPointF pos)
   410 {
   458 {
   411     mMenuManager->ShowItemSpecificMenu(viewId,pos);
   459     mMenuManager->ShowItemSpecificMenu(viewId,pos);
   412 }
   460 }
   413 
   461 
   414 void GlxViewManager::cancelTimer()
   462 void GlxViewManager::handleReadyView()
   415 {
   463 {
   416     emit externalCommand(EGlxPluginCmdUserActivity);
   464     emit actionTriggered( EGlxCmdSetupItem );
       
   465     disconnect( mMainWindow, SIGNAL( viewReady() ), this, 
       
   466             SLOT( handleReadyView() ) );
   417 }
   467 }
   418 
   468 
   419 void GlxViewManager::effectFinished( )
   469 void GlxViewManager::effectFinished( )
   420 {
   470 {
   421     qDebug("GlxViewManager::EffectFinished");
   471     qDebug("GlxViewManager::EffectFinished");
   422     mMainWindow->releaseMouse();
   472     if ( mIsViewTransitionRunning ) {
   423     deActivateView();
   473         mMainWindow->releaseMouse();
   424     activateView(); 
   474         deActivateView();
       
   475         activateView();
       
   476         mIsViewTransitionRunning = false;
       
   477         mItemList.clear();
       
   478     }
   425 }
   479 }
   426 
   480 
   427 GlxView * GlxViewManager::findView(qint32 id)
   481 GlxView * GlxViewManager::findView(qint32 id)
   428 {
   482 {
   429     qDebug("GlxViewManager::findView Id = %d ", id);
   483     qDebug("GlxViewManager::findView Id = %d ", id);
   624     }
   678     }
   625 }
   679 }
   626 
   680 
   627 void GlxViewManager::addConnection()
   681 void GlxViewManager::addConnection()
   628 {    
   682 {    
   629     if ( mMenuManager )
   683     if ( mMenuManager ) {
   630         connect(mMenuManager, SIGNAL( commandTriggered(qint32 ) ), this, SLOT( handleMenuAction(qint32 ) ));
   684         connect( mMenuManager, SIGNAL( commandTriggered(qint32 ) ), 
   631     if ( mBackAction )
   685                 this, SLOT( actionProcess(qint32 ) ));
       
   686     }
       
   687     if ( mBackAction ) {
   632         connect(mBackAction, SIGNAL( triggered() ), this, SLOT( handleAction() ));
   688         connect(mBackAction, SIGNAL( triggered() ), this, SLOT( handleAction() ));
       
   689     }
   633         
   690         
   634     if ( mEffectEngine )  {
   691     if ( mEffectEngine )  {
   635         connect( mEffectEngine, SIGNAL( effectFinished() ), this, SLOT( effectFinished() ), Qt::QueuedConnection );
   692         connect( mEffectEngine, SIGNAL( effectFinished() ), this, 
       
   693                 SLOT( effectFinished() ), Qt::QueuedConnection );
   636     }        
   694     }        
   637 }
   695 }
   638 
   696 
   639 void GlxViewManager::removeConnection()
   697 void GlxViewManager::removeConnection()
   640 {
   698 {
   653         disconnect ( mViewList.at(i), SIGNAL(actionTriggered(qint32 )), this, SLOT(actionProcess(qint32 )) );
   711         disconnect ( mViewList.at(i), SIGNAL(actionTriggered(qint32 )), this, SLOT(actionProcess(qint32 )) );
   654         disconnect ( mViewList.at(i), SIGNAL(itemSpecificMenuTriggered(qint32, QPointF ) ), this, SLOT( itemSpecificMenuTriggered(qint32, QPointF ) ));
   712         disconnect ( mViewList.at(i), SIGNAL(itemSpecificMenuTriggered(qint32, QPointF ) ), this, SLOT( itemSpecificMenuTriggered(qint32, QPointF ) ));
   655         mMenuManager->removeMenu( mViewList.at(i)->viewId(), mViewList.at(i)->menu() ) ;
   713         mMenuManager->removeMenu( mViewList.at(i)->viewId(), mViewList.at(i)->menu() ) ;
   656     }
   714     }
   657 	   
   715 	   
   658     if ( mMenuManager )
   716     if ( mMenuManager ) {
   659         disconnect(mMenuManager, SIGNAL( commandTriggered(qint32 ) ), this, SLOT( handleMenuAction(qint32 ) ));
   717         disconnect( mMenuManager, SIGNAL( commandTriggered( qint32 ) ), 
       
   718                 this, SLOT( actionProcess( qint32 ) ) );
       
   719     }
   660     
   720     
   661     if ( mBackAction )
   721     if ( mBackAction )
   662         disconnect(mBackAction, SIGNAL( triggered() ), this, SLOT( handleAction() ));
   722         disconnect(mBackAction, SIGNAL( triggered() ), this, SLOT( handleAction() ));
   663         
   723         
   664     if ( mEffectEngine )  {
   724     if ( mEffectEngine )  {
   678 {
   738 {
   679     qDebug("GlxViewManager::actionProcess action Id = %d ", id);
   739     qDebug("GlxViewManager::actionProcess action Id = %d ", id);
   680     emit actionTriggered(id);
   740     emit actionTriggered(id);
   681 }
   741 }
   682 
   742 
   683 GlxViewManager::~GlxViewManager()
       
   684 {
       
   685     qDebug("GlxViewManager::~GlxViewManager");
       
   686     HbStyleLoader::unregisterFilePath(":/data/photos.css");
       
   687 	
       
   688     removeConnection();
       
   689 	
       
   690     delete mMenuManager;
       
   691     qDebug("GlxViewManager::~GlxViewManager deleted menu manager");    
       
   692     delete mViewToolBar;
       
   693     delete mMarkingToolBar;
       
   694     qDebug("GlxViewManager::~GlxViewManager deleted toolbar");
       
   695     
       
   696     while( mViewList.isEmpty( ) == FALSE){
       
   697         delete mViewList.takeLast() ;
       
   698     }
       
   699     qDebug("GlxViewManager::~GlxViewManager view deleted");    
       
   700         
       
   701     delete mBackAction;
       
   702     delete mProgressDialog;
       
   703     
       
   704     if ( mEffectEngine ) {
       
   705         mEffectEngine->deregistertransitionEffect();
       
   706         delete mEffectEngine;
       
   707     }
       
   708  
       
   709     if( mMainWindow != GlxExternalUtility::instance()->getMainWindow() ){
       
   710         qDebug("GlxViewManager::~GlxViewManager delete mainwindow");
       
   711         delete mMainWindow;
       
   712     }
       
   713     delete mWindowEventFilter;
       
   714     
       
   715     qDebug("GlxViewManager::~GlxViewManager Exit");
       
   716 }
       
   717 
       
   718 int GlxViewManager::getSubState()
   743 int GlxViewManager::getSubState()
   719 {
   744 {
   720     int curSubstate = NO_GRID_S;    
   745     int curSubstate = NO_GRID_S;    
   721     
   746     
   722     if ( mModel  ) {    
   747     if ( mModel  ) {