stateproviders/ftustateprovider/src/ftuwizardactivatedstate.cpp
changeset 7 446dc0e90e84
parent 5 1c5fe9af5d39
child 9 aa22d2c19e57
equal deleted inserted replaced
5:1c5fe9af5d39 7:446dc0e90e84
    34 #include <QDebug>
    34 #include <QDebug>
    35 #include <QGraphicsWidget>
    35 #include <QGraphicsWidget>
    36 #include <QDir>
    36 #include <QDir>
    37 #include <hbmenu.h>
    37 #include <hbmenu.h>
    38 
    38 
    39 const int gridRowCount = 1;
       
    40 
    39 
    41 const char *FTUSTATEPROVIDER_DOCML2 = ":/xml/ftustateprovider.docml";
    40 const char *FTUSTATEPROVIDER_DOCML2 = ":/xml/ftustateprovider.docml";
    42 const char *WIZARD_VIEW = "wizardView";
    41 const char *WIZARD_VIEW = "wizardView";
    43 const char *WIZARD_INFOTEXT_LABEL = "wizardInfoTextLabel";
    42 const char *WIZARD_INFOTEXT_LABEL = "wizardInfoTextLabel";
    44 const char *WIZARD_STACKEDWIDGET = "wizardStackedWidget";
    43 const char *WIZARD_STACKEDWIDGET = "wizardStackedWidget";
    65     mPluginView(NULL),
    64     mPluginView(NULL),
    66     mActiveWizard(NULL),
    65     mActiveWizard(NULL),
    67     mPluginTitleLabel(NULL),
    66     mPluginTitleLabel(NULL),
    68     mWizardStackedWidget(NULL),
    67     mWizardStackedWidget(NULL),
    69     mBackAction(NULL),
    68     mBackAction(NULL),
    70     mMenustrip(NULL), 
       
    71     mPreviousView(NULL), 
    69     mPreviousView(NULL), 
    72     mCurrentView(NULL),
    70     mCurrentView(NULL)
    73     mPluginDisplayMode(PartialScreen) 
       
    74 {
    71 {
    75     mMainWindow = hbInstance->allMainWindows().at(0);
    72     mMainWindow = hbInstance->allMainWindows().at(0);
    76     mDocumentLoader = new HbDocumentLoader();
    73     mDocumentLoader = new HbDocumentLoader();
    77     mPluginView = new HbView();
    74     mPluginView = new HbView();
    78 
    75 
   121 
   118 
   122     int activeIndex = content()->activeWizard();
   119     int activeIndex = content()->activeWizard();
   123     mActiveWizard = content()->wizard(activeIndex);
   120     mActiveWizard = content()->wizard(activeIndex);
   124     
   121     
   125     mPluginView->setNavigationAction(mBackAction);
   122     mPluginView->setNavigationAction(mBackAction);
   126     // Make menustrip for testing purposes.
       
   127     if(!mMenustrip)
       
   128     {
       
   129         constructGrid();
       
   130     }
       
   131     mMenustrip->setVisible(true);
       
   132 
       
   133     connect(mBackAction, SIGNAL(triggered()),
   123     connect(mBackAction, SIGNAL(triggered()),
   134             this, SLOT(handleBackEvent()));
   124             this, SLOT(handleBackEvent()));
   135 
   125 
   136     setActiveWizardConnections();
   126     setActiveWizardConnections();
   137 
   127 
   150 void FtuWizardActivatedState::onExit(QEvent *event)
   140 void FtuWizardActivatedState::onExit(QEvent *event)
   151 {
   141 {
   152     QState::onExit(event);
   142     QState::onExit(event);
   153     mMainWindow->currentView()->takeMenu();
   143     mMainWindow->currentView()->takeMenu();
   154     disconnect(mBackAction, SIGNAL(triggered()),
   144     disconnect(mBackAction, SIGNAL(triggered()),
   155                this, SLOT(handleBackEvent()));
   145                    this, SLOT(handleBackEvent()));
       
   146     
       
   147     
       
   148     disconnect(mActiveWizard, SIGNAL(wizardDeactivated(FtuWizard *)),
       
   149                this, SLOT(handleGotoToC()));
   156     
   150     
   157     disconnect(mActiveWizard, SIGNAL(viewChanged(FtuWizard *, 
   151     disconnect(mActiveWizard, SIGNAL(viewChanged(FtuWizard *, 
   158                                                  QGraphicsWidget* )),
   152                                                  QGraphicsWidget* )),
   159                this, SLOT(changeWizardView(FtuWizard*, QGraphicsWidget*)));
   153                this, SLOT(changeWizardView(FtuWizard*, QGraphicsWidget*)));
   160     
   154     
   161     disconnect(mActiveWizard, SIGNAL(fullScreenModeRequested(FtuWizard *)),
   155 
   162                this, SLOT(enableFullScreenMode(FtuWizard*)));
   156     disconnect(mActiveWizard, SIGNAL(infoTextUpdated(FtuWizard *, QString )),
   163     
   157             this, SLOT(updateInfoText(FtuWizard *, QString)));
   164     disconnect(mActiveWizard, SIGNAL(partialScreenModeRequested(FtuWizard * )),
   158     
   165                this, SLOT(enablePartialScreenMode(FtuWizard*)));
   159     //disconnect from the existing wizard's updateMainMenu signal
   166 
   160     disconnect(mActiveWizard,SIGNAL(updateMainMenu(FtuWizard *, HbMenu * )),
       
   161             this,SLOT(updateMainMenu(FtuWizard *, HbMenu * )));
       
   162 }
       
   163 
       
   164 // ---------------------------------------------------------------------------
       
   165 // FtuWizardActivatedState::setActiveWizardConnections
       
   166 // ---------------------------------------------------------------------------
       
   167 //
       
   168 void FtuWizardActivatedState::setActiveWizardConnections()
       
   169 {
       
   170     // first disconnect possible old connections with active wizard
       
   171     disconnect(mActiveWizard, SIGNAL(wizardDeactivated(FtuWizard *)),
       
   172                    this, SLOT(handleGotoToC()));
       
   173     
       
   174     disconnect(mActiveWizard, SIGNAL(viewChanged(FtuWizard *, 
       
   175                                                  QGraphicsWidget* )),
       
   176                this, SLOT(changeWizardView(FtuWizard*, QGraphicsWidget*)));
       
   177     
   167     disconnect(mActiveWizard, SIGNAL(infoTextUpdated(FtuWizard *, QString )),
   178     disconnect(mActiveWizard, SIGNAL(infoTextUpdated(FtuWizard *, QString )),
   168             this, SLOT(updateInfoText(FtuWizard *, QString)));
   179             this, SLOT(updateInfoText(FtuWizard *, QString)));
   169     
   180     
   170     //disconnect from the existing existing wizard's updateMainMenu signal
   181     //disconnect from the existing existing wizard's updateMainMenu signal
   171     disconnect(mActiveWizard,SIGNAL(updateMainMenu(FtuWizard *, HbMenu * )),
   182     disconnect(mActiveWizard,SIGNAL(updateMainMenu(FtuWizard *, HbMenu * )),
   172             this,SLOT(updateMainMenu(FtuWizard *, HbMenu * )));
   183             this,SLOT(updateMainMenu(FtuWizard *, HbMenu * )));
   173 }
       
   174 
       
   175 // ---------------------------------------------------------------------------
       
   176 // FtuWizardActivatedState::setActiveWizardConnections
       
   177 // ---------------------------------------------------------------------------
       
   178 //
       
   179 void FtuWizardActivatedState::setActiveWizardConnections()
       
   180 {
       
   181     // first disconnect possible old connections with active wizard
       
   182     disconnect(mActiveWizard, SIGNAL(viewChanged(FtuWizard *, 
       
   183                                                  QGraphicsWidget* )),
       
   184                this, SLOT(changeWizardView(FtuWizard*, QGraphicsWidget*)));
       
   185     
       
   186     disconnect(mActiveWizard, SIGNAL(fullScreenModeRequested(FtuWizard *)),
       
   187                this, SLOT(enableFullScreenMode(FtuWizard*)));
       
   188     
       
   189     disconnect(mActiveWizard, SIGNAL(partialScreenModeRequested(FtuWizard * )),
       
   190                this, SLOT(enablePartialScreenMode(FtuWizard*)));
       
   191 
       
   192     disconnect(mActiveWizard, SIGNAL(infoTextUpdated(FtuWizard *, QString )),
       
   193             this, SLOT(updateInfoText(FtuWizard *, QString)));
       
   194     
       
   195     //disconnect from the existing existing wizard's updateMainMenu signal
       
   196     disconnect(mActiveWizard,SIGNAL(updateMainMenu(FtuWizard *, HbMenu * )),
       
   197             this,SLOT(updateMainMenu(FtuWizard *, HbMenu * )));
       
   198     
   184     
   199     // then connect new ones to active wizard
   185     // then connect new ones to active wizard
   200     connect(mActiveWizard, SIGNAL(viewChanged(FtuWizard *, QGraphicsWidget* )),
   186     connect(mActiveWizard, SIGNAL(viewChanged(FtuWizard *, QGraphicsWidget* )),
   201             this, SLOT(changeWizardView(FtuWizard*, QGraphicsWidget*)));
   187             this, SLOT(changeWizardView(FtuWizard*, QGraphicsWidget*)));
   202     
   188     
   203     connect(mActiveWizard, SIGNAL(fullScreenModeRequested(FtuWizard *)),
       
   204             this, SLOT(enableFullScreenMode(FtuWizard*)));
       
   205     
       
   206     connect(mActiveWizard, SIGNAL(partialScreenModeRequested(FtuWizard * )),
       
   207             this, SLOT(enablePartialScreenMode(FtuWizard*)));
       
   208     
       
   209     connect(mActiveWizard, SIGNAL(infoTextUpdated(FtuWizard *, QString )),
   189     connect(mActiveWizard, SIGNAL(infoTextUpdated(FtuWizard *, QString )),
   210             this, SLOT(updateInfoText(FtuWizard *, QString)));
   190             this, SLOT(updateInfoText(FtuWizard *, QString)));
   211     
   191     
   212     // connect to the updateMainMenu wizard signal
   192     // connect to the updateMainMenu wizard signal
   213     connect(mActiveWizard,SIGNAL(updateMainMenu(FtuWizard *, HbMenu * )),
   193     connect(mActiveWizard,SIGNAL(updateMainMenu(FtuWizard *, HbMenu * )),
   214             this,SLOT(updateMainMenu(FtuWizard *, HbMenu * )));
   194             this,SLOT(updateMainMenu(FtuWizard *, HbMenu * )));
       
   195     
       
   196     connect(mActiveWizard, SIGNAL(wizardDeactivated(FtuWizard *)),
       
   197                    this, SLOT(handleGotoToC()));
   215 }
   198 }
   216 
   199 
   217 // ---------------------------------------------------------------------------
   200 // ---------------------------------------------------------------------------
   218 // FtuWizardActivatedState::content
   201 // FtuWizardActivatedState::content
   219 // ---------------------------------------------------------------------------
   202 // ---------------------------------------------------------------------------
   234     {
   217     {
   235         emit backEventTriggered();
   218         emit backEventTriggered();
   236     }    
   219     }    
   237 }
   220 }
   238 
   221 
       
   222 void FtuWizardActivatedState::handleGotoToC()
       
   223     {
       
   224     emit backEventTriggered();
       
   225     }
   239 
   226 
   240 // ---------------------------------------------------------------------------
   227 // ---------------------------------------------------------------------------
   241 // FtuWizardActivatedState::updateMainMenu
   228 // FtuWizardActivatedState::updateMainMenu
   242 // ---------------------------------------------------------------------------
   229 // ---------------------------------------------------------------------------
   243 //
   230 //
   279             int index = wizards.indexOf(mActiveWizard);
   266             int index = wizards.indexOf(mActiveWizard);
   280             
   267             
   281             // temp solution to skip edge indexes - start
   268             // temp solution to skip edge indexes - start
   282             if (index == 0) { index++; }
   269             if (index == 0) { index++; }
   283             if (index == wizards.count()-1) { index--; }
   270             if (index == wizards.count()-1) { index--; }
   284             // temp solution to skip edge indexes - end  
       
   285                       
       
   286             // create model index for active wizard
       
   287             QModelIndex modelIndex = mMenustrip->model()->index(index, 0);
       
   288             // scroll to correct position in menustrip
       
   289             HbAbstractItemView::ScrollHint hint = HbAbstractItemView::PositionAtCenter;
       
   290             mMenustrip->scrollTo(modelIndex, hint);
       
   291         }        
   271         }        
   292     }
   272     }
   293 }
   273 }
   294 
   274 
   295 // ---------------------------------------------------------------------------
       
   296 // FtuWizardActivatedState::enableFullScreenMode
       
   297 // ---------------------------------------------------------------------------
       
   298 //
       
   299 void FtuWizardActivatedState::enableFullScreenMode(FtuWizard *caller)
       
   300 {
       
   301     if(caller == mActiveWizard)
       
   302     {
       
   303         mPluginDisplayMode = FullScreen;
       
   304         // Remove menustrip
       
   305 		mMenustrip->setVisible(false);
       
   306         caller->resizeWizard(calculateWizardGeometry()); 
       
   307     }    
       
   308 }
       
   309 
       
   310 // ---------------------------------------------------------------------------
       
   311 // FtuWizardActivatedState::enablePartialScreenMode
       
   312 // ---------------------------------------------------------------------------
       
   313 //
       
   314 void FtuWizardActivatedState::enablePartialScreenMode(FtuWizard *caller)
       
   315 {
       
   316     if(caller == mActiveWizard)
       
   317     {
       
   318         mPluginDisplayMode = PartialScreen;
       
   319         mMenustrip->setVisible(true);
       
   320         caller->resizeWizard(calculateWizardGeometry());
       
   321     }
       
   322 }
       
   323 
   275 
   324 // ---------------------------------------------------------------------------
   276 // ---------------------------------------------------------------------------
   325 // FtuWizardActivatedState::updateInfoText
   277 // FtuWizardActivatedState::updateInfoText
   326 // ---------------------------------------------------------------------------
   278 // ---------------------------------------------------------------------------
   327 //
   279 //
   339 // ---------------------------------------------------------------------------
   291 // ---------------------------------------------------------------------------
   340 //
   292 //
   341 HbMainWindow* FtuWizardActivatedState::mainWindow()
   293 HbMainWindow* FtuWizardActivatedState::mainWindow()
   342 {
   294 {
   343     return hbInstance->allMainWindows().at(0);
   295     return hbInstance->allMainWindows().at(0);
   344 }
       
   345 
       
   346 // ---------------------------------------------------------------------------
       
   347 // FtuWizardActivatedState::constructGrid
       
   348 // ---------------------------------------------------------------------------
       
   349 //
       
   350 void FtuWizardActivatedState::constructGrid()
       
   351 {
       
   352     // fetch grid view from docml
       
   353     mMenustrip = qobject_cast<HbGridView *>(mDocumentLoader->findWidget(WIZARD_GRID_VIEW));
       
   354     // set row amount for grid
       
   355     mMenustrip->setRowCount(gridRowCount);
       
   356 
       
   357     mMenustrip->setScrollDirections(Qt::Horizontal);
       
   358 
       
   359     FtuContentService* ftuContentService = content();
       
   360     // get wizards
       
   361     QList<FtuWizard*> wizards = ftuContentService->wizards();
       
   362     
       
   363     QStandardItemModel* model = new QStandardItemModel(this);
       
   364     
       
   365     for(int i = 0 ; i < wizards.size() ; ++i)
       
   366     {
       
   367         // get wizard settings
       
   368         const FtuWizardSetting& settings = wizards.at(i)->wizardSettings();
       
   369         QStandardItem* item = new QStandardItem();
       
   370         HbIcon icon(settings.mMenustripDefaultIcon.absoluteFilePath());
       
   371 
       
   372 //      item->setBackground(QBrush(Qt::lightGray));
       
   373         item->setData(icon, Qt::DecorationRole);
       
   374         
       
   375         QStringList data;
       
   376         data << settings.mMenustripLabel;
       
   377         
       
   378         item->setData(QVariant(data), Qt::DisplayRole);
       
   379 
       
   380         model->appendRow(item);
       
   381     }
       
   382     // set above defined model for menustrip
       
   383     mMenustrip->setModel(model);
       
   384 
       
   385     connect(mMenustrip, SIGNAL(activated(const QModelIndex)),
       
   386             this, SLOT(activateWizard(const QModelIndex)));
       
   387 }
   296 }
   388 
   297 
   389 // ---------------------------------------------------------------------------
   298 // ---------------------------------------------------------------------------
   390 // FtuWizardActivatedState::activateWizard
   299 // FtuWizardActivatedState::activateWizard
   391 // ---------------------------------------------------------------------------
   300 // ---------------------------------------------------------------------------
   423                 mActiveWizard = content()->wizard(prevWizardIndex);
   332                 mActiveWizard = content()->wizard(prevWizardIndex);
   424                 setActiveWizardConnections();
   333                 setActiveWizardConnections();
   425                 mActiveWizard->activateWizard();
   334                 mActiveWizard->activateWizard();
   426             }
   335             }
   427         }
   336         }
   428         
       
   429         // temp solution to skip edge indexes - start
       
   430         if (wizardIndex == 0) { wizardIndex++; }
       
   431         if (wizardIndex == content()->wizards().count()-1) { wizardIndex--; }
       
   432         QModelIndex modelIndex = mMenustrip->model()->index(wizardIndex, 0);
       
   433         // temp solution to skip edge indexes - end         
       
   434               
       
   435         HbAbstractItemView::ScrollHint hint = HbAbstractItemView::PositionAtCenter;
       
   436         // scroll to correct position in menustrip
       
   437         mMenustrip->scrollTo(modelIndex, hint);
       
   438     }
   337     }
   439 }
   338 }
   440 
   339 
   441 // ---------------------------------------------------------------------------
   340 // ---------------------------------------------------------------------------
   442 // FtuWizardActivatedState::calculateWizardGeometry
   341 // FtuWizardActivatedState::calculateWizardGeometry
   444 //
   343 //
   445 QRectF FtuWizardActivatedState::calculateWizardGeometry()
   344 QRectF FtuWizardActivatedState::calculateWizardGeometry()
   446 {
   345 {
   447 	QRectF widgetRect = mWizardStackedWidget->geometry();
   346 	QRectF widgetRect = mWizardStackedWidget->geometry();
   448 	QRectF pluginRect = mPluginView->geometry();	
   347 	QRectF pluginRect = mPluginView->geometry();	
   449     if(mPluginDisplayMode == FullScreen)
   348 	pluginRect.setSize(QSizeF(widgetRect.width(),
   450     {		
   349 	                                widgetRect.height()));
   451 		pluginRect.setSize(QSizeF(widgetRect.width(),
       
   452 								  (widgetRect.height() +
       
   453 						           mMenustrip->geometry().height())));
       
   454     }
       
   455 	else
       
   456 	{	
       
   457 		pluginRect.setSize(QSizeF(widgetRect.width(),
       
   458 			                      widgetRect.height()));	
       
   459 	}
       
   460 
       
   461     return pluginRect;
   350     return pluginRect;
   462 }
   351 }