ui/viewmanagement/viewmanager/src/glxviewmanager.cpp
changeset 23 74c9f037fd5d
child 24 99ad1390cd33
equal deleted inserted replaced
5:f7f0874bfe7d 23:74c9f037fd5d
       
     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 
       
    20 #include <glxviewmanager.h>
       
    21 #include <glxview.h>
       
    22 #include <glxviewsfactory.h>
       
    23 #include <glxeffectengine.h>
       
    24 #include <hbmainwindow.h>
       
    25 #include <glxexternalutility.h>
       
    26 #include <glxloggerenabler.h>
       
    27 #include <glxmenumanager.h>
       
    28 #include <glxcommandhandlers.hrh>
       
    29 #include <glxplugincommandid.hrh>
       
    30 
       
    31 #include <hbaction.h>
       
    32 #include <hbtoolbar.h>
       
    33 #include <hbmenu.h>
       
    34 #include <QDebug>
       
    35 
       
    36 
       
    37 GlxViewManager::GlxViewManager() : mBackAction( NULL ), mMenuManager( NULL ), mEffectEngine( NULL ), 
       
    38             mViewToolBar( NULL ), mMarkingToolBar( NULL ), mMenu( NULL )
       
    39 {
       
    40     qDebug("GlxViewManager::GlxViewManager() ");
       
    41     PERFORMANCE_ADV ( viewMgrD1, "main window creation time" ) {
       
    42         //check the case when application launch through some other application (view plugin)
       
    43         mMainWindow = GlxExternalUtility::instance()->getMainWindow();
       
    44         if(mMainWindow == NULL)	{
       
    45             mMainWindow = new HbMainWindow();
       
    46         }
       
    47     } //end PERFORMANCE_ADV
       
    48     
       
    49     //mMainWindow->setOptimizationFlag(QGraphicsView::DontSavePainterState);
       
    50 }
       
    51 
       
    52 void GlxViewManager::setupItems(int subState)
       
    53 {
       
    54     mMenuManager = new GlxMenuManager();
       
    55     addBackSoftKeyAction(); 
       
    56     createToolBar();
       
    57     addConnection();
       
    58     mView->addToolBar(mViewToolBar);
       
    59     mMenuManager->CreateViewMenu( mView->viewId(), mView->menu(), ( 0 == mModel->rowCount() ),subState);
       
    60 }
       
    61 
       
    62 void GlxViewManager::launchApplication(qint32 id, QAbstractItemModel *model)
       
    63 {
       
    64     mModel = model;
       
    65     PERFORMANCE_ADV ( viewMgrD1, "View Creation time" ) {
       
    66         mView = resolveView(id);
       
    67     }
       
    68     mView->activate();
       
    69     //mView->show();
       
    70     
       
    71     PERFORMANCE_ADV ( viewMgrD3, "Set Model time")  
       
    72         mView->setModel(mModel);
       
    73         
       
    74     PERFORMANCE_ADV( viewMgrD4, "View Display time") {
       
    75         mMainWindow->setCurrentView(mView, false);
       
    76         mMainWindow->showFullScreen();           
       
    77     }    
       
    78 }
       
    79 
       
    80 void GlxViewManager::handleMenuAction(qint32 commandId)
       
    81 {
       
    82     emit actionTriggered(commandId);
       
    83 }
       
    84 
       
    85 void GlxViewManager::handleAction()
       
    86 {
       
    87     HbAction *action = qobject_cast<HbAction*>(sender());
       
    88     qint32 commandId = action->data().toInt();
       
    89     emit actionTriggered(commandId);
       
    90 }
       
    91 
       
    92 void GlxViewManager::addBackSoftKeyAction ( )
       
    93 {
       
    94     qDebug("GlxViewManager::addBackSoftKeyAction ");
       
    95     //create the back soft key action and set the data
       
    96     mBackAction = new HbAction(Hb::BackAction, this);
       
    97     mBackAction->setData(EGlxCmdBack);
       
    98     
       
    99     //remove the current secondary soft key for main window and set the new created one
       
   100     HbAction *action = mMainWindow->softKeyAction(Hb::SecondarySoftKey);
       
   101     mMainWindow->removeSoftKeyAction(Hb::SecondarySoftKey,action);
       
   102     mMainWindow->addSoftKeyAction(Hb::SecondarySoftKey, mBackAction);
       
   103 }
       
   104 
       
   105 Qt::Orientation GlxViewManager::orientation() const
       
   106 {
       
   107     return mMainWindow->orientation();
       
   108 }
       
   109 
       
   110 
       
   111 void GlxViewManager::launchView(qint32 id, QAbstractItemModel *model)
       
   112 {
       
   113     qDebug("GlxViewManager::launchView Id = %d ", id);
       
   114     mModel = model;
       
   115     deActivateView();
       
   116     
       
   117     PERFORMANCE_ADV ( viewMgrD1, "View Creation time" ) {
       
   118         mView = resolveView(id);
       
   119     }
       
   120     
       
   121     activateView();
       
   122 }
       
   123 
       
   124 void GlxViewManager::launchView (qint32 id, QAbstractItemModel *model, GlxEffect effect, GlxViewEffect viewEffect)
       
   125 {
       
   126     qDebug("GlxViewManager::launchView Id = %d effect %d view effect %d", id, effect, viewEffect);
       
   127 
       
   128     //In the case of no animation is play during the view transition just call launch view and return
       
   129     if ( viewEffect == NO_VIEW ) {
       
   130         return launchView(id, model);
       
   131     }
       
   132     
       
   133     //create and registered the effect
       
   134     if ( mEffectEngine == NULL ) { 
       
   135         mEffectEngine = new GlxSlideShowEffectEngine();
       
   136         mEffectEngine->registerTransitionEffect();
       
   137         connect( mEffectEngine, SIGNAL( effectFinished() ), this, SLOT( effectFinished() ) );
       
   138     }
       
   139     
       
   140     QList< QGraphicsItem * > itemList;
       
   141     QGraphicsItem *item = NULL;
       
   142     itemList.clear();
       
   143     
       
   144     //partially clean the view so that animation run smoothly
       
   145     GlxView *curr_view = (GlxView *) mMainWindow->currentView();
       
   146     curr_view->resetView();
       
   147     
       
   148     mView = resolveView(id);
       
   149     //partially initialise the view so that animation run smoothly
       
   150     mView->initializeView( model);
       
   151     mModel = model; 
       
   152 
       
   153     if ( viewEffect == CURRENT_VIEW || viewEffect == BOTH_VIEW ) { 
       
   154         item = curr_view->getAnimationItem(effect);
       
   155         if ( item ) {
       
   156             itemList.append(item);
       
   157             item = NULL;
       
   158         }
       
   159     }
       
   160     
       
   161     if ( viewEffect == LAUNCH_VIEW || viewEffect == BOTH_VIEW ) {
       
   162         item = mView->getAnimationItem(effect);
       
   163         if ( item ) {
       
   164             //increase the z value and show the view to shown the view animation
       
   165             mView->setZValue(curr_view->zValue() + 2);
       
   166             mView->show();
       
   167             item->show();        
       
   168             itemList.append(item);
       
   169         }
       
   170     }
       
   171     
       
   172     //error check
       
   173     if ( itemList.count() > 0 ) {
       
   174         mEffectEngine->runEffect(itemList, effect);
       
   175         mMainWindow->grabMouse();
       
   176     }
       
   177     else {
       
   178         deActivateView();
       
   179         activateView();       
       
   180     }    
       
   181 }
       
   182 
       
   183 //to be called only when the photos plugin was activated by external means
       
   184 void GlxViewManager::deactivateCurrentView()
       
   185 {
       
   186     GlxView *curr_view = (GlxView *) mMainWindow->currentView();
       
   187     if ( curr_view ) {
       
   188         curr_view->deActivate() ;
       
   189     }
       
   190 }
       
   191 
       
   192 void GlxViewManager::updateToolBarIcon(int id)
       
   193 {
       
   194     QString path;
       
   195     int toolBarActionId = (int) GLX_ALL_ACTION_ID;
       
   196     int count = mActionList.count();
       
   197     
       
   198     qDebug("GlxViewManager::updateToolBarIcon() action ID list %d count %d", id, count);
       
   199     
       
   200     for ( int i = 0; i < count ; i++ ) {
       
   201         qDebug("GlxViewManager::updateToolBarIcon() toolBarActionId %d value %d", toolBarActionId, ( id & toolBarActionId ) );
       
   202         //check and get the icon path
       
   203         if ( ( id & toolBarActionId ) == toolBarActionId ) {
       
   204             path = mSelIconPathList.at(i);
       
   205         }
       
   206         else {
       
   207             path = mDefaultIconPathList.at(i);
       
   208         }
       
   209         //to get it the next action id to verify it is selecter or not
       
   210         toolBarActionId = toolBarActionId << 1; 
       
   211         HbIcon icon(path);
       
   212         mActionList[i]->setIcon(icon) ;
       
   213     }
       
   214 }
       
   215 
       
   216 void GlxViewManager::enterMarkingMode(qint32 viewId)
       
   217 {
       
   218     GlxView *view = findView ( viewId );
       
   219     qDebug("GlxViewManager::enterMarkingMode view ID %d", viewId);
       
   220     
       
   221     //In the case of first time create the marking mode menu( Mark All, Un Mark All )
       
   222     if( mMenu == NULL ) {
       
   223         mMenu = new HbMenu();
       
   224         mMenuManager->createMarkingModeMenu(mMenu);
       
   225     }
       
   226     
       
   227     if ( mMarkingToolBar == NULL) {
       
   228         createMarkingModeToolBar(); //Marking mode tool bar is different from normal mode tool bar
       
   229     }
       
   230     
       
   231     if ( view ) { 
       
   232         view->enableMarking();
       
   233         HbMenu *menu = view->takeMenu(); //Take the owner ship of current menu
       
   234         view->setMenu(mMenu); //Set the marking mode menu
       
   235         mMenu = menu;
       
   236         view->takeToolBar();
       
   237         view->addToolBar(mMarkingToolBar);
       
   238     }
       
   239     qDebug("GlxViewManager::enterMarkingMode view ID %d exit", viewId);
       
   240 }
       
   241 
       
   242 void GlxViewManager::exitMarkingMode(qint32 viewId)
       
   243 {
       
   244     GlxView *view = findView ( viewId );
       
   245     qDebug("GlxViewManager::exitMarkingMode view ID %d", viewId);
       
   246     if ( view ) { 
       
   247         //createToolBar(); //Marking mode tool bar is different from normal mode tool bar
       
   248         view->disableMarking(); 
       
   249         HbMenu *menu = view->takeMenu(); //Take the owner ship of current menu
       
   250         view->setMenu(mMenu); //Set the view menu option
       
   251         mMenu = menu;
       
   252         view->takeToolBar();
       
   253         view->addToolBar(mViewToolBar);
       
   254     }
       
   255     qDebug("GlxViewManager::exitMarkingMode view ID %d exit", viewId);
       
   256 }
       
   257 
       
   258 void GlxViewManager::handleUserAction(qint32 viewId, qint32 commandId)
       
   259 {
       
   260     GlxView *view = findView ( viewId );
       
   261     qDebug("GlxViewManager::handleUserAction view ID %d command id %d", viewId, commandId);
       
   262     if ( view ) { 
       
   263         view->handleUserAction(commandId);
       
   264     }    
       
   265 }
       
   266 
       
   267 QItemSelectionModel *  GlxViewManager::getSelectionModel(qint32 viewId) 
       
   268 { 
       
   269     GlxView *view = findView ( viewId );
       
   270     if ( view ) { 
       
   271         return view->getSelectionModel();
       
   272     }
       
   273     return NULL;
       
   274 }
       
   275 
       
   276 GlxView * GlxViewManager::resolveView(qint32 id)
       
   277 {
       
   278     qDebug("GlxViewManager::resolveView %d", id);
       
   279     GlxView *view = findView ( id );
       
   280     if ( view ) {
       
   281         return view ;
       
   282     }
       
   283     
       
   284     view = GlxViewsFactory::createView(id, mMainWindow);
       
   285     if ( view ) {
       
   286         //view->addToolBar(mViewToolBar);
       
   287         connect ( view, SIGNAL(actionTriggered(qint32 )), this, SLOT(actionProcess(qint32 )), Qt::QueuedConnection );
       
   288         connect ( view, SIGNAL(itemSpecificMenuTriggered(qint32,QPointF ) ), this, SLOT( itemSpecificMenuTriggered(qint32,QPointF ) ));
       
   289         mViewList.append(view);
       
   290         mMainWindow->addView(view);
       
   291     }
       
   292     return view;
       
   293 }
       
   294 
       
   295 void GlxViewManager::itemSpecificMenuTriggered(qint32 viewId,QPointF pos)
       
   296 {
       
   297     mMenuManager->ShowItemSpecificMenu(viewId,pos);
       
   298 }
       
   299 
       
   300 void GlxViewManager::cancelTimer()
       
   301 {
       
   302     emit externalCommand(EGlxPluginCmdUserActivity);
       
   303 }
       
   304 
       
   305 void GlxViewManager::effectFinished( )
       
   306 {
       
   307     qDebug("GlxViewManager::EffectFinished");
       
   308     mMainWindow->releaseMouse();
       
   309     deActivateView();
       
   310     activateView(); 
       
   311 }
       
   312 
       
   313 GlxView * GlxViewManager::findView(qint32 id)
       
   314 {
       
   315     qDebug("GlxViewManager::findView Id = %d ", id);
       
   316     int count = mViewList.count();
       
   317     
       
   318     for ( int i = 0 ; i < count; i++) {
       
   319         if ( mViewList.at(i)->compare(id) ) {
       
   320             return mViewList.at(i);
       
   321         }
       
   322     }
       
   323     //qDebug("GlxViewManager::findView view = %u ", view);
       
   324     return NULL;
       
   325 }
       
   326 
       
   327 void GlxViewManager::deActivateView()
       
   328 {
       
   329     qDebug("GlxViewManager::deActivateCurrentView()");
       
   330     
       
   331     GlxView *view = (GlxView *) mMainWindow->currentView();
       
   332     if ( view ){
       
   333         view->deActivate() ;
       
   334         //view->hide(); //To:do is it required
       
   335     }
       
   336     if (mView && view) {
       
   337         mView->setZValue(view->zValue());
       
   338     }
       
   339 }
       
   340 
       
   341 void GlxViewManager::activateView()
       
   342 {
       
   343     qDebug("GlxViewManager::activateView()");
       
   344         
       
   345     PERFORMANCE_ADV ( viewMgrD2, "View Activation time") {
       
   346         mView->addToolBar(mViewToolBar);
       
   347         mView->activate();
       
   348         mView->show();
       
   349         //check and create the view menu
       
   350         if ( mView->menu()->isEmpty() ) {
       
   351             mMenuManager->CreateViewMenu( mView->viewId(), mView->menu(), ( 0 == mModel->rowCount() ));
       
   352         }
       
   353     }        
       
   354       
       
   355     PERFORMANCE_ADV ( viewMgrD3, "Set Model time")  
       
   356         mView->setModel(mModel);
       
   357         
       
   358     PERFORMANCE_ADV( viewMgrD4, "View Display time") {
       
   359         mMainWindow->setCurrentView(mView, false);
       
   360         mMainWindow->showFullScreen();           
       
   361     }
       
   362 }
       
   363 
       
   364 void GlxViewManager::createActions()
       
   365 {
       
   366     qDebug("GlxViewManager::createActions() " );
       
   367     mActionList.clear();
       
   368     mSelIconPathList.clear();
       
   369     mDefaultIconPathList.clear();    
       
   370     
       
   371     //create the All tool bar button action
       
   372     HbAction* allAction = new HbAction(this);
       
   373     allAction->setData(EGlxCmdAllGridOpen);
       
   374     mActionList.append(allAction);
       
   375     mSelIconPathList.append(QString(":/data/All_selected.png"));
       
   376     mDefaultIconPathList.append(QString(":/data/All_default.png"));
       
   377 
       
   378     //create the Album tool bar button action
       
   379     HbAction* albumAction = new HbAction(this);
       
   380     albumAction->setData(EGlxCmdAlbumListOpen);
       
   381     mActionList.append(albumAction);
       
   382     mSelIconPathList.append(QString(":/data/Albums_selected.png"));
       
   383     mDefaultIconPathList.append(QString(":/data/Albums_default.png"));
       
   384     
       
   385     //create the album tool bar button action
       
   386     HbAction* cameraAction = new HbAction(this);
       
   387     cameraAction->setData(EGlxCmdCameraOpen);
       
   388     mActionList.append(cameraAction);
       
   389     mSelIconPathList.append(QString(":/data/camera_selected.png"));
       
   390     mDefaultIconPathList.append(QString(":/data/camera_default.png"));
       
   391     
       
   392     //create the ovi tool bar button action
       
   393     HbAction* oviAction = new HbAction(this);
       
   394     oviAction->setData(EGlxCmdOviOpen);
       
   395     mActionList.append(oviAction);
       
   396     mSelIconPathList.append(QString(":/data/ovi_selected.png"));
       
   397     mDefaultIconPathList.append(QString(":/data/ovi_default.png"));
       
   398 }
       
   399 
       
   400 void GlxViewManager::createMarkingModeActions()
       
   401 {
       
   402     mMarkingActionList.clear();
       
   403     
       
   404     //create the ok tool bar button action
       
   405     HbAction* selectAction = new HbAction("Ok", this);
       
   406     selectAction->setData(EGlxCmdSelect);
       
   407     mMarkingActionList.append(selectAction);
       
   408     connect( selectAction, SIGNAL(triggered( )), this, SLOT(handleAction( )), Qt::QueuedConnection );
       
   409     mMarkingToolBar->addAction( selectAction );
       
   410     
       
   411     //create the cancel tool bar button action
       
   412     HbAction* cancelAction = new HbAction("Cancel", this);
       
   413     cancelAction->setData(EGlxCmdCancel);
       
   414     mMarkingActionList.append(cancelAction); 
       
   415     connect( cancelAction, SIGNAL(triggered( )), this, SLOT(handleAction( )), Qt::QueuedConnection ); 
       
   416     mMarkingToolBar->addAction( cancelAction );
       
   417 }
       
   418 
       
   419 
       
   420 void GlxViewManager::createToolBar()
       
   421 {
       
   422     qDebug("GlxViewManager::createToolBar() " );
       
   423     
       
   424     mViewToolBar = new HbToolBar();
       
   425     mViewToolBar->setOrientation( Qt::Horizontal );
       
   426     mViewToolBar->setVisible(true);
       
   427     mViewToolBar->clearActions();
       
   428     
       
   429     createActions();    
       
   430     
       
   431     qDebug("GlxViewManager::createToolBar() clear the action" );
       
   432     int count = mActionList.count();
       
   433     for ( int i = 0; i < count; i++ ) {
       
   434         connect( mActionList.at(i), SIGNAL(triggered( )), this, SLOT(handleAction( )) );
       
   435         mViewToolBar->addAction( mActionList.at(i) );      
       
   436     }
       
   437     qDebug("GlxViewManager::createToolBar() exit" );
       
   438 }
       
   439 
       
   440 void GlxViewManager::createMarkingModeToolBar()
       
   441 {
       
   442     qDebug("GlxViewManager::createMarkingModeToolBar() " );
       
   443     mMarkingToolBar = new HbToolBar();
       
   444     mMarkingToolBar->setOrientation( Qt::Horizontal );
       
   445     mMarkingToolBar->setVisible(true);            
       
   446     mMarkingToolBar->clearActions();
       
   447     
       
   448     createMarkingModeActions();
       
   449 }
       
   450 
       
   451 void GlxViewManager::addConnection()
       
   452 {    
       
   453     if ( mMenuManager )
       
   454         connect(mMenuManager, SIGNAL( commandTriggered(qint32 ) ), this, SLOT( handleMenuAction(qint32 ) ));
       
   455     if ( mBackAction )
       
   456         connect(mBackAction, SIGNAL( triggered() ), this, SLOT( handleAction() ));
       
   457         
       
   458     if ( mEffectEngine )  {
       
   459         connect( mEffectEngine, SIGNAL( effectFinished() ), this, SLOT( effectFinished() ) );
       
   460     }        
       
   461 }
       
   462 
       
   463 void GlxViewManager::removeConnection()
       
   464 {
       
   465     int count = mActionList.count();
       
   466     for ( int i = 0; i < count; i++ ) {
       
   467         disconnect( mActionList.at(i), SIGNAL(triggered( )), this, SLOT(handleAction( )) );  
       
   468     }
       
   469     
       
   470     count = mMarkingActionList.count();
       
   471     for ( int i = 0; i < count; i++ ) {
       
   472         disconnect( mMarkingActionList.at(i), SIGNAL(triggered( )), this, SLOT(handleAction( )) );  
       
   473     }
       
   474     
       
   475     count = mViewList.count();
       
   476     for ( int i = 0; i < count; i++ ) {
       
   477         disconnect ( mViewList.at(i), SIGNAL(actionTriggered(qint32 )), this, SLOT(actionProcess(qint32 )) );
       
   478         disconnect ( mViewList.at(i), SIGNAL(itemSpecificMenuTriggered(qint32, QPointF ) ), this, SLOT( itemSpecificMenuTriggered(qint32, QPointF ) ));
       
   479     }
       
   480 	   
       
   481     if ( mMenuManager )
       
   482         disconnect(mMenuManager, SIGNAL( commandTriggered(qint32 ) ), this, SLOT( handleMenuAction(qint32 ) ));
       
   483     if ( mBackAction )
       
   484         disconnect(mBackAction, SIGNAL( triggered() ), this, SLOT( handleAction() ));
       
   485         
       
   486     if ( mEffectEngine )  {
       
   487         disconnect( mEffectEngine, SIGNAL( effectFinished() ), this, SLOT( effectFinished() ) );
       
   488     }
       
   489 }
       
   490 
       
   491 void GlxViewManager::destroyView(qint32 id)
       
   492 {
       
   493     qDebug("GlxViewManager::destroyView ");
       
   494     GlxView *view = findView ( id );
       
   495     mViewList.removeOne(view);
       
   496     delete view;
       
   497 }
       
   498 
       
   499 void GlxViewManager::actionProcess(qint32 id)
       
   500 {
       
   501     qDebug("GlxViewManager::actionProcess action Id = %d ", id);
       
   502     emit actionTriggered(id);
       
   503 }
       
   504 
       
   505 GlxViewManager::~GlxViewManager()
       
   506 {
       
   507     qDebug("GlxViewManager::~GlxViewManager");
       
   508 	
       
   509     removeConnection();
       
   510     delete mMenuManager;
       
   511     qDebug("GlxViewManager::~GlxViewManager deleted menu manager");
       
   512     
       
   513     while( mViewList.isEmpty( ) == FALSE){
       
   514         delete mViewList.takeLast() ;
       
   515     }
       
   516     qDebug("GlxViewManager::~GlxViewManager view deleted");
       
   517     
       
   518     while( mActionList.isEmpty() == FALSE) {
       
   519         delete mActionList.takeLast();
       
   520     }  
       
   521 	
       
   522     while ( mMarkingActionList.isEmpty() == FALSE ) {
       
   523         delete mMarkingActionList.takeLast();
       
   524     }
       
   525     qDebug("GlxViewManager::~GlxViewManager delete action list");
       
   526     
       
   527     delete mBackAction;
       
   528     delete mViewToolBar;
       
   529     delete mMarkingToolBar;
       
   530     delete mMenu;
       
   531     qDebug("GlxViewManager::~GlxViewManager delete toolbar");
       
   532     
       
   533     mSelIconPathList.clear();
       
   534     mDefaultIconPathList.clear();
       
   535     qDebug("GlxViewManager::~GlxViewManager clear path list");
       
   536     
       
   537     if ( mEffectEngine ) {
       
   538         mEffectEngine->deregistertransitionEffect();
       
   539         delete mEffectEngine;
       
   540     }
       
   541  
       
   542     if( mMainWindow != GlxExternalUtility::instance()->getMainWindow() ){
       
   543         qDebug("GlxViewManager::~GlxViewManager remove view");
       
   544         delete mMainWindow;
       
   545     }
       
   546     
       
   547     qDebug("GlxViewManager::~GlxViewManager Exit");
       
   548 }
       
   549