homescreenapp/stateplugins/hshomescreenstateplugin/src/hsidlestate.cpp
changeset 69 87476091b3f5
parent 63 52b0f64eeb51
child 71 1db7cc813a4e
equal deleted inserted replaced
67:474929a40a0f 69:87476091b3f5
    40 #include "hsidlestate.h"
    40 #include "hsidlestate.h"
    41 #include "hsidlewidget.h"
    41 #include "hsidlewidget.h"
    42 #include "hsdomainmodeldatastructures.h"
    42 #include "hsdomainmodeldatastructures.h"
    43 #include "hsscene.h"
    43 #include "hsscene.h"
    44 #include "hspage.h"
    44 #include "hspage.h"
       
    45 #include "hspagevisual.h"
    45 #include "hswidgethost.h"
    46 #include "hswidgethost.h"
       
    47 #include "hswidgethostvisual.h"
    46 #include "hswallpaper.h"
    48 #include "hswallpaper.h"
    47 #include "hswallpaperselectionstate.h"
    49 #include "hswallpaperselectionstate.h"
    48 #include "hstrashbinwidget.h"
    50 #include "hstrashbinwidget.h"
    49 #include "hspageindicator.h"
    51 #include "hspageindicator.h"
    50 #include "hsmenueventfactory.h"
    52 #include "hsmenueventfactory.h"
    51 #include "hshomescreenstatecommon.h"
    53 #include "hshomescreenstatecommon.h"
    52 #include "hstitleresolver.h"
    54 #include "hstitleresolver.h"
    53 #include "hsmenuservice.h"
    55 #include "hsmenuservice.h"
    54 #include "hsgui.h"
       
    55 #include "hsconfiguration.h"
    56 #include "hsconfiguration.h"
    56 #include "hsmessageboxwrapper.h"
    57 #include "hsmessageboxwrapper.h"
    57 #include "hspropertyanimationwrapper.h"
    58 #include "hspropertyanimationwrapper.h"
       
    59 #include "hsgui.h"
       
    60 
       
    61 
       
    62 namespace
       
    63 {
       
    64   
       
    65     //User adds a new page to home screen
       
    66     const char hsLocTextId_OptionsMenu_AddPage[] = "txt_homescreen_opt_add_page";
       
    67 
       
    68     //User removes page from home screen
       
    69     const char hsLocTextId_OptionsMenu_RemovePage[] = "txt_homescreen_opt_remove_page";
       
    70 
       
    71     //Sends request to all widgets to enable data connections
       
    72     const char hsLocTextId_OptionsMenu_HsToOnline[] = "txt_homescreen_opt_home_screen_to_online";
       
    73 
       
    74     //Sends request to all widgets to disable data connections
       
    75     const char hsLocTextId_OptionsMenu_HsToOffline[] = "txt_homescreen_opt_home_screen_to_offline";
       
    76 
       
    77     //Home screen canvas menu item for opening picture gallery
       
    78     const char hsLocTextId_ContextMenu_ChangeWallpaper[] = "txt_homescreen_list_change_wallpaper";
       
    79 
       
    80     //Home screen canvas menu item for opening Application library
       
    81     const char hsLocTextId_ContextMenu_AddContent[] = "txt_homescreen_list_add_content";
       
    82 
       
    83     //Home screen options menu item for opening Task switcher
       
    84     const char hsLocTextId_OptionsMenu_TaskSwitcher[] = "txt_homescreen_opt_task_switcher";
       
    85 
       
    86     //Heading text in confirmation dialog while removing page with content
       
    87     const char hsLocTextId_Title_RemovePage[] = "txt_homescreen_title_remove_page";
       
    88 
       
    89     //Text in confirmation dialog while removing page with content
       
    90     const char hsLocTextId_Confirmation_RemovePage[] = "txt_homescreen_info_page_and_content_will_be_remov";
       
    91 }
    58 
    92 
    59 // Helper macros for connecting state entry and exit actions.
    93 // Helper macros for connecting state entry and exit actions.
    60 #define ENTRY_ACTION(state, action) \
    94 #define ENTRY_ACTION(state, action) \
    61     connect(state, SIGNAL(entered()), SLOT(action()));
    95     connect(state, SIGNAL(entered()), SLOT(action()));
    62 #define EXIT_ACTION(state, action) \
    96 #define EXIT_ACTION(state, action) \
    63     connect(state, SIGNAL(exited()), SLOT(action()));
    97     connect(state, SIGNAL(exited()), SLOT(action()));
    64 
    98 
    65 namespace
    99 
    66 {
       
    67     const char gApplicationLibraryIconName[] = "qtg_mono_applications_all";
       
    68 
       
    69     //User adds a new page to home screen
       
    70     const char hsLocTextId_OptionsMenu_AddPage[] = "txt_homescreen_opt_add_page";
       
    71 
       
    72     //User removes page from home screen
       
    73     const char hsLocTextId_OptionsMenu_RemovePage[] = "txt_homescreen_opt_remove_page";
       
    74 
       
    75     //Sends request to all widgets to enable data connections
       
    76     const char hsLocTextId_OptionsMenu_HsToOnline[] = "txt_homescreen_opt_home_screen_to_online";
       
    77 
       
    78     //Sends request to all widgets to disable data connections
       
    79     const char hsLocTextId_OptionsMenu_HsToOffline[] = "txt_homescreen_opt_home_screen_to_offline";
       
    80 
       
    81     //Home screen canvas menu item for opening picture gallery
       
    82     const char hsLocTextId_ContextMenu_ChangeWallpaper[] = "txt_homescreen_list_change_wallpaper";
       
    83 
       
    84     //Home screen canvas menu item for opening Application library
       
    85     const char hsLocTextId_ContextMenu_AddContent[] = "txt_homescreen_list_add_content";
       
    86 
       
    87     //Home screen options menu item for opening Task switcher
       
    88     const char hsLocTextId_OptionsMenu_TaskSwitcher[] = "txt_homescreen_opt_task_switcher";
       
    89 
       
    90     //Heading text in confirmation dialog while removing page with content
       
    91     const char hsLocTextId_Title_RemovePage[] = "txt_homescreen_title_remove_page";
       
    92 
       
    93     //Text in confirmation dialog while removing page with content
       
    94     const char hsLocTextId_Confirmation_RemovePage[] = "txt_homescreen_info_page_and_content_will_be_remov";
       
    95 
       
    96     //Button in confirmation dialog while removing page with content
       
    97     //const char hsLocTextId_ConfirmationButton_Ok[] = "txt_homescreen_button_ok";
       
    98 
       
    99     //Button in confirmation dialog while removing page with content
       
   100     //const char hsLocTextId_ConfirmationButton_Cancel[] = "txt_homescreen_button_cancel";
       
   101 }
       
   102 
   100 
   103 /*!
   101 /*!
   104     \class HsIdleState
   102     \class HsIdleState
   105     \ingroup group_hshomescreenstateplugin
   103     \ingroup group_hshomescreenstateplugin
   106     \brief Controller part of the home screen idle state.
   104     \brief Controller part of the home screen idle state.
   115     Constructs a new idle state with the given \a parent.
   113     Constructs a new idle state with the given \a parent.
   116 */
   114 */
   117 HsIdleState::HsIdleState(QState *parent)
   115 HsIdleState::HsIdleState(QState *parent)
   118   : QState(parent),
   116   : QState(parent),
   119     mNavigationAction(0), 
   117     mNavigationAction(0), 
   120     mUiWidget(0),
       
   121     mTitleResolver(0),
   118     mTitleResolver(0),
   122     mZoneAnimation(0),
       
   123     mAllowZoneAnimation(false),
   119     mAllowZoneAnimation(false),
   124     mPageChangeAnimation(0),
       
   125     mContinuousFeedback(0),
   120     mContinuousFeedback(0),
   126     mTrashBinFeedbackAlreadyPlayed(false),
   121     mTrashBinFeedbackAlreadyPlayed(false),
   127     mDeltaX(0),
   122     mDeltaX(0),
   128     mSceneMenu(0)
   123     mSceneMenu(0)
   129 #ifdef Q_OS_SYMBIAN
   124 #ifdef Q_OS_SYMBIAN
   147 /*!
   142 /*!
   148     Destroys this idle state.
   143     Destroys this idle state.
   149 */
   144 */
   150 HsIdleState::~HsIdleState()
   145 HsIdleState::~HsIdleState()
   151 {
   146 {
   152     if (mZoneAnimation) {
       
   153         mZoneAnimation->stop();
       
   154         delete mZoneAnimation;
       
   155     }
       
   156     if (mPageChangeAnimation) {
       
   157         mPageChangeAnimation->stop();
       
   158         delete mPageChangeAnimation;
       
   159     }
       
   160     
       
   161     // TODO: Uncomment when updated API available
   147     // TODO: Uncomment when updated API available
   162     //delete mContinuousFeedback;
   148     //delete mContinuousFeedback;
   163 }
   149 }
   164 
   150 
   165 /*!
   151 /*!
   319     EXIT_ACTION(state_moveScene, action_moveScene_disconnectGestureHandlers)
   305     EXIT_ACTION(state_moveScene, action_moveScene_disconnectGestureHandlers)
   320     
   306     
   321     ENTRY_ACTION(state_addPage, action_addPage_addPage)
   307     ENTRY_ACTION(state_addPage, action_addPage_addPage)
   322     
   308     
   323     ENTRY_ACTION(state_preRemovePage, action_preRemovePage_showQuery)
   309     ENTRY_ACTION(state_preRemovePage, action_preRemovePage_showQuery)
       
   310     EXIT_ACTION(state_preRemovePage, action_preRemovePage_exit);
   324 
   311 
   325     ENTRY_ACTION(state_removePage, action_removePage_startRemovePageAnimation)
   312     ENTRY_ACTION(state_removePage, action_removePage_startRemovePageAnimation)
   326     EXIT_ACTION(state_removePage, action_removePage_removePage)
   313     EXIT_ACTION(state_removePage, action_removePage_removePage)
   327 
   314 
   328     ENTRY_ACTION(state_toggleConnection, action_toggleConnection_toggleConnection)
   315     ENTRY_ACTION(state_toggleConnection, action_toggleConnection_toggleConnection)
   331 /*!
   318 /*!
   332     Computes the page layer x position based on the given \a pageIndex.
   319     Computes the page layer x position based on the given \a pageIndex.
   333 */
   320 */
   334 qreal HsIdleState::pageLayerXPos(int pageIndex) const
   321 qreal HsIdleState::pageLayerXPos(int pageIndex) const
   335 {
   322 {
   336     return -pageIndex * HsScene::mainWindow()->layoutRect().width();
   323     return -pageIndex * HsGui::instance()->layoutRect().width();
   337 }
   324 }
   338 
   325 
   339 /*!
   326 /*!
   340     Starts the page change animation based on the given \a targetPageIndex
   327     Starts the page change animation based on the given \a targetPageIndex
   341     and \a duration.
   328     and \a duration.
   342 */
   329 */
   343 void HsIdleState::startPageChangeAnimation(int targetPageIndex, int duration)
   330 void HsIdleState::startPageChangeAnimation(int targetPageIndex, int duration)
   344 {
   331 {
   345     if (mPageChangeAnimation->isRunning()) {
   332     HsPropertyAnimationWrapper *animation = HsGui::instance()->pageChangeAnimation();
   346         mPageChangeAnimation->stop();
   333     if (animation->isRunning()) {
       
   334         animation->stop();
   347     }        
   335     }        
   348     mPageChangeAnimation->disconnect(this);
   336     animation->disconnect(this);
   349     mPageChangeAnimation->setEndValue(pageLayerXPos(targetPageIndex));
   337     animation->setEndValue(pageLayerXPos(targetPageIndex));
   350     mPageChangeAnimation->setDuration(duration);
   338     animation->setDuration(duration);
   351     connect(mPageChangeAnimation,
   339     connect(animation,
   352             SIGNAL(finished()),
   340             SIGNAL(finished()),
   353             SLOT(pageChangeAnimationFinished()), 
   341             SLOT(pageChangeAnimationFinished()), 
   354             Qt::UniqueConnection);
   342             Qt::UniqueConnection);
   355     mPageChangeAnimation->start();
   343     animation->start();
   356     
   344     
   357     HbInstantFeedback::play(HSCONFIGURATION_GET(pageChangeFeedbackEffect));
   345     HbInstantFeedback::play(HSCONFIGURATION_GET(pageChangeFeedbackEffect));
   358     
   346     
   359     mUiWidget->showPageIndicator();
   347     HsGui::instance()->idleWidget()->showPageIndicator();
   360     mUiWidget->setActivePage(targetPageIndex);
   348     HsGui::instance()->idleWidget()->setActivePage(targetPageIndex);
   361 }
   349 }
   362 
   350 
   363 /*!
   351 /*!
   364     Starts the page change zone animation (crawling) based on the given a\ duration
   352     Starts the page change zone animation (crawling) based on the given a\ duration
   365 */
   353 */
   377     } else {
   365     } else {
   378         return;
   366         return;
   379     }
   367     }
   380 
   368 
   381     int bounceEffect = HSCONFIGURATION_GET(bounceEffect);
   369     int bounceEffect = HSCONFIGURATION_GET(bounceEffect);
       
   370     
       
   371     HsPropertyAnimationWrapper *pageCrawlingAnimation =
       
   372         HsGui::instance()->pageCrawlingAnimation();
   382 
   373 
   383     if (isInLeftPageChangeZone()) {
   374     if (isInLeftPageChangeZone()) {
   384         mZoneAnimation->setEndValue(pageLayerXPos(scene->activePageIndex()) + bounceEffect);
   375         pageCrawlingAnimation->setEndValue(pageLayerXPos(scene->activePageIndex()) + bounceEffect);
   385     } else {
   376     } else {
   386         mZoneAnimation->setEndValue(pageLayerXPos(scene->activePageIndex()) - bounceEffect);
   377         pageCrawlingAnimation->setEndValue(pageLayerXPos(scene->activePageIndex()) - bounceEffect);
   387     }
   378     }
   388     mZoneAnimation->setDuration(duration);
   379     pageCrawlingAnimation->setDuration(duration);
   389     mZoneAnimation->setDirection(QAbstractAnimation::Forward);
   380     pageCrawlingAnimation->setForward();
   390 
   381 
   391     connect(mZoneAnimation,
   382     connect(pageCrawlingAnimation,
   392             SIGNAL(finished()),
   383             SIGNAL(finished()),
   393             SLOT(zoneAnimationFinished()),
   384             SLOT(zoneAnimationFinished()),
   394             Qt::UniqueConnection);
   385             Qt::UniqueConnection);
   395     
   386     
   396     mZoneAnimation->start();
   387     pageCrawlingAnimation->start();
   397 }
   388 }
   398 
   389 
   399 /*!
   390 /*!
   400     Checks if the active widget is located inside the left or right
   391     Checks if the active widget is located inside the left or right
   401     page change zone.
   392     page change zone.
   419     Checks if touch point in the active widget is located inside the right
   410     Checks if touch point in the active widget is located inside the right
   420     page change zone.
   411     page change zone.
   421 */
   412 */
   422 bool HsIdleState::isInRightPageChangeZone()
   413 bool HsIdleState::isInRightPageChangeZone()
   423 {
   414 {
   424     qreal pageWidth = HsScene::mainWindow()->layoutRect().width();
   415     qreal pageWidth = HsGui::instance()->layoutRect().width();
   425     return mWidgetHotSpot.x() > pageWidth - HSCONFIGURATION_GET(pageChangeZoneWidth);
   416     return mWidgetHotSpot.x() > pageWidth - HSCONFIGURATION_GET(pageChangeZoneWidth);
   426 }
   417 }
   427 
   418 
   428 /*!
   419 /*!
   429     Inserts new page at index position \a pageIndex in the scene.
   420     Inserts new page at index position \a pageIndex in the scene.
   433     HsPageData data;
   424     HsPageData data;
   434     data.indexPosition = pageIndex;
   425     data.indexPosition = pageIndex;
   435     HsPage *page = HsPage::createInstance(data);
   426     HsPage *page = HsPage::createInstance(data);
   436     page->load();
   427     page->load();
   437     HsScene::instance()->addPage(page);
   428     HsScene::instance()->addPage(page);
   438     mUiWidget->insertPage(pageIndex, page);
   429     HsGui::instance()->idleWidget()->insertPage(pageIndex, page);
   439 }
   430 }
   440 
   431 
   441 /*!
   432 /*!
   442     Checks if page change zone animation needs to be started or stopped
   433     Checks if page change zone animation needs to be started or stopped
   443 */
   434 */
   444 void HsIdleState::updateZoneAnimation()
   435 void HsIdleState::updateZoneAnimation()
   445 {
   436 {
       
   437     HsPropertyAnimationWrapper *pageCrawlingAnimation = 
       
   438         HsGui::instance()->pageCrawlingAnimation();
       
   439 
   446     if (!mAllowZoneAnimation) {
   440     if (!mAllowZoneAnimation) {
   447         mZoneAnimation->stop();
   441         pageCrawlingAnimation->stop();
   448     } else if (isInPageChangeZone()) {
   442     } else if (isInPageChangeZone()) {
   449         // should we start it
   443         // should we start it
   450         if (mZoneAnimation->state() == QAbstractAnimation::Stopped &&
   444         if (!pageCrawlingAnimation->isRunning() &&
   451             !mPageChangeAnimation->isRunning()) {
   445             !HsGui::instance()->pageChangeAnimation()->isRunning()) {
   452             startPageChangeZoneAnimation(HSCONFIGURATION_GET(pageChangeZoneAnimationDuration));
   446             startPageChangeZoneAnimation(HSCONFIGURATION_GET(pageChangeZoneAnimationDuration));
   453         } 
   447         } 
   454     } else if (mZoneAnimation->state() == QAbstractAnimation::Running) {
   448     } else if (pageCrawlingAnimation->isRunning()) {
   455         // Not in zone, but still running     
   449         // Not in zone, but still running     
   456         if (mZoneAnimation->direction() == QAbstractAnimation::Forward){
   450         if (pageCrawlingAnimation->isForward()){
   457             // reverse
   451             // reverse
   458             mZoneAnimation->setDuration(HSCONFIGURATION_GET(pageChangeZoneReverseAnimationDuration));
   452             pageCrawlingAnimation->setDuration(HSCONFIGURATION_GET(pageChangeZoneReverseAnimationDuration));
   459             mZoneAnimation->setDirection(QAbstractAnimation::Backward);
   453             pageCrawlingAnimation->setBackward();
   460         } 
   454         } 
   461     } 
   455     } 
   462 }
   456 }
   463 
   457 
   464 /*!
   458 /*!
   465     Selects which trash bin icon is shown or not shown at all
   459     Selects which trash bin icon is shown or not shown at all
   466 */
   460 */
   467 void HsIdleState::showTrashBin()
   461 void HsIdleState::showTrashBin()
   468 {
   462 {
   469     if (mUiWidget->trashBin()->isUnderMouse()) {
   463     if (HsGui::instance()->idleWidget()->trashBin()->isUnderMouse()) {
   470         if (!mTrashBinFeedbackAlreadyPlayed) {
   464         if (!mTrashBinFeedbackAlreadyPlayed) {
   471             HbInstantFeedback::play(HSCONFIGURATION_GET(widgetOverTrashbinFeedbackEffect));
   465             HbInstantFeedback::play(HSCONFIGURATION_GET(widgetOverTrashbinFeedbackEffect));
   472             mTrashBinFeedbackAlreadyPlayed = true;
   466             mTrashBinFeedbackAlreadyPlayed = true;
   473         }
   467         }
   474         mUiWidget->trashBin()->activate();
   468         HsGui::instance()->idleWidget()->trashBin()->activate();
   475     } else {
   469     } else {
   476         mUiWidget->trashBin()->deactivate();
   470         HsGui::instance()->idleWidget()->trashBin()->deactivate();
   477         mTrashBinFeedbackAlreadyPlayed = false;
   471         mTrashBinFeedbackAlreadyPlayed = false;
   478     }
   472     }
   479 
   473 
   480     if (!mUiWidget->pageIndicator()->isAnimationRunning()) {
   474     if (!HsGui::instance()->idleWidget()->pageIndicator()->isAnimationRunning()) {
   481         mUiWidget->showTrashBin();
   475         HsGui::instance()->idleWidget()->showTrashBin();
   482     }
   476     }
   483 }
   477 }
   484 
   478 
   485 /*!
   479 /*!
   486     If called for the first time, setups the idle view.
   480     If called for the first time, setups the idle view.
   487     Updates the soft key action and sets the idle view
   481     Updates the soft key action and sets the idle view
   488     as the current view to the main window.
   482     as the current view to the main window.
   489 */
   483 */
   490 void HsIdleState::action_idle_setupView()
   484 void HsIdleState::action_idle_setupView()
   491 {
   485 {
   492     HbView *idleView = HsGui::idleView();
   486     HsGui::instance()->setupIdleUi();
   493     if (!idleView) {
   487     connect(HsGui::instance(),SIGNAL(navigateToApplibrary()),SIGNAL(event_applicationLibrary()),Qt::UniqueConnection);
   494         mUiWidget = new HsIdleWidget;
   488 
   495         idleView = HsScene::mainWindow()->addView(mUiWidget);
       
   496         idleView->setContentFullScreen();
       
   497 
       
   498         mNavigationAction = new HbAction(this);
       
   499         mNavigationAction->setIcon(HbIcon(gApplicationLibraryIconName));
       
   500         mNavigationAction->setObjectName("applib_navigation_action");
       
   501         connect(mNavigationAction, SIGNAL(triggered()), SIGNAL(event_applicationLibrary()));
       
   502         idleView->setNavigationAction(mNavigationAction);
       
   503 
       
   504         HsGui::setIdleView(idleView);
       
   505         
       
   506         delete mPageChangeAnimation;
       
   507         mPageChangeAnimation = NULL;
       
   508         mPageChangeAnimation = new HsPropertyAnimationWrapper;
       
   509         mPageChangeAnimation->setTargetObject(mUiWidget);
       
   510         mPageChangeAnimation->setPropertyName("sceneX"); 
       
   511         delete mZoneAnimation;
       
   512         mZoneAnimation = NULL;
       
   513         mZoneAnimation = new QPropertyAnimation(mUiWidget, "sceneX");
       
   514        
       
   515     }
       
   516 
       
   517     HsScene::mainWindow()->setCurrentView(idleView);
       
   518 }
   489 }
   519 
   490 
   520 /*!
   491 /*!
   521     Sets the idle view's title.
   492     Sets the idle view's title.
   522 */
   493 */
   532     Updates the idle view's title.
   503     Updates the idle view's title.
   533 */
   504 */
   534 void HsIdleState::onTitleChanged(QString title)
   505 void HsIdleState::onTitleChanged(QString title)
   535 {
   506 {
   536     qDebug() << "HsIdleState::onTitleChanged() to title: " << title;
   507     qDebug() << "HsIdleState::onTitleChanged() to title: " << title;
   537     HsGui::idleView()->setTitle(title);
   508     HsGui::instance()->idleView()->setTitle(title);
   538 }
   509 }
   539 
   510 
   540 /*!
   511 /*!
   541 
   512 
   542 */
   513 */
   609 
   580 
   610     mDeltaX = gesture->sceneOffset().x();
   581     mDeltaX = gesture->sceneOffset().x();
   611 
   582 
   612     HsScene *scene = HsScene::instance();
   583     HsScene *scene = HsScene::instance();
   613     int bounceEffect = HSCONFIGURATION_GET(bounceEffect);
   584     int bounceEffect = HSCONFIGURATION_GET(bounceEffect);
   614     qreal x = qBound(pageLayerXPos(scene->pages().count() - 1) - bounceEffect / 2 / mUiWidget->parallaxFactor(),
   585     qreal x = qBound(pageLayerXPos(scene->pages().count() - 1) - bounceEffect / 2 / HsGui::instance()->idleWidget()->parallaxFactor(),
   615                      pageLayerXPos(scene->activePageIndex()) + mDeltaX,
   586                      pageLayerXPos(scene->activePageIndex()) + mDeltaX,
   616                      pageLayerXPos(0) + (bounceEffect / 2 / mUiWidget->parallaxFactor()));
   587                      pageLayerXPos(0) + (bounceEffect / 2 / HsGui::instance()->idleWidget()->parallaxFactor()));
   617 
   588 
   618     mUiWidget->setSceneX(x);
   589     HsGui::instance()->idleWidget()->setSceneX(x);
   619 }
   590 }
   620  
   591  
   621 void HsIdleState::onPagePanFinished(QGestureEvent *event)
   592 void HsIdleState::onPagePanFinished(QGestureEvent *event)
   622 {
   593 {
   623     HbPanGesture *gesture = qobject_cast<HbPanGesture *>(
   594     HbPanGesture *gesture = qobject_cast<HbPanGesture *>(
   639     HsScene *scene = HsScene::instance();
   610     HsScene *scene = HsScene::instance();
   640     scene->setActiveWidget(widget);
   611     scene->setActiveWidget(widget);
   641     
   612     
   642     mWidgetHotSpot = qobject_cast<HbTapAndHoldGesture *>(
   613     mWidgetHotSpot = qobject_cast<HbTapAndHoldGesture *>(
   643         event->gesture(Qt::TapAndHoldGesture))->scenePosition();
   614         event->gesture(Qt::TapAndHoldGesture))->scenePosition();
   644     mWidgetHotSpotOffset = mWidgetHotSpot - widget->pos();
   615     mWidgetHotSpotOffset = mWidgetHotSpot - widget->visual()->pos();
   645     
   616     
   646     emit event_moveWidget();
   617     emit event_moveWidget();
   647 }
   618 }
   648  
   619  
   649 void HsIdleState::onWidgetMoveUpdated(const QPointF &scenePos, HsWidgetHost *widget)
   620 void HsIdleState::onWidgetMoveUpdated(const QPointF &scenePos, HsWidgetHost *widget)
   650 {
   621 {
   651     QRectF widgetRect = widget->geometry();
   622     QRectF widgetRect = widget->visual()->geometry();
   652 
   623 
   653     // Move widget to updated position.
   624     // Move widget to updated position.
   654     mWidgetHotSpot = scenePos;
   625     mWidgetHotSpot = scenePos;
   655     widgetRect.moveTopLeft(mWidgetHotSpot - mWidgetHotSpotOffset);
   626     widgetRect.moveTopLeft(mWidgetHotSpot - mWidgetHotSpotOffset);
   656 
   627 
   657     // When moving widget can go over the pages left border.
   628     // When moving widget can go over the pages left border.
   658     qreal lowerBoundX = -widgetRect.width();
   629     qreal lowerBoundX = -widgetRect.width();
   659 
   630 
   660     // When moving widget can go over the pages right border.
   631     // When moving widget can go over the pages right border.
   661     QRectF pageRect = HsGui::idleView()->rect();
   632     QRectF pageRect = HsGui::instance()->idleView()->rect();
   662     qreal upperBoundX = pageRect.width();
   633     qreal upperBoundX = pageRect.width();
   663 
   634 
   664     // When moving widget can go under the chrome at the pages upper border.
   635     // When moving widget can go under the chrome at the pages upper border.
   665     // Notice that chrome height is 64 pixels.
   636     // Notice that chrome height is 64 pixels.
   666     qreal lowerBoundY = qreal(64) - widgetRect.height();
   637     qreal lowerBoundY = qreal(64) - widgetRect.height();
   671     qreal widgetX = qBound(lowerBoundX, widgetRect.x(), upperBoundX);
   642     qreal widgetX = qBound(lowerBoundX, widgetRect.x(), upperBoundX);
   672     qreal widgetY = qBound(lowerBoundY, widgetRect.y(), upperBoundY);
   643     qreal widgetY = qBound(lowerBoundY, widgetRect.y(), upperBoundY);
   673 
   644 
   674     // If using ItemClipsChildrenToShape-flag in widgethost then
   645     // If using ItemClipsChildrenToShape-flag in widgethost then
   675     // setPos does not update position here, however setGeometry does it, QT bug?
   646     // setPos does not update position here, however setGeometry does it, QT bug?
   676     widget->setGeometry(widgetX, widgetY, widgetRect.width(), widgetRect.height());
   647     widget->visual()->setGeometry(widgetX, widgetY, widgetRect.width(), widgetRect.height());
   677     
   648     
   678     if (HSCONFIGURATION_GET(isSnapEnabled)) {
   649     if (HSCONFIGURATION_GET(isSnapEnabled)) {
   679         mSnapResult = HsWidgetPositioningOnWidgetMove::instance()->run(widget->sceneBoundingRect());
   650         mSnapResult = HsWidgetPositioningOnWidgetMove::instance()->run(widget->visual()->sceneBoundingRect());
   680 
   651 
   681         if (HSCONFIGURATION_GET(isSnapEffectsEnabled)) {
   652         if (HSCONFIGURATION_GET(isSnapEffectsEnabled)) {
   682             if (mSnapResult.hasHorizontalSnap) {
   653             if (mSnapResult.hasHorizontalSnap) {
   683                 showVerticalLine();
   654                 showVerticalLine();
   684             }
   655             }
   757 {   
   728 {   
   758     HsScene *scene = HsScene::instance();
   729     HsScene *scene = HsScene::instance();
   759     QApplication::instance()->installEventFilter(scene);
   730     QApplication::instance()->installEventFilter(scene);
   760     scene->activePage()->showWidgets();
   731     scene->activePage()->showWidgets();
   761     qreal x = pageLayerXPos(scene->activePageIndex());
   732     qreal x = pageLayerXPos(scene->activePageIndex());
   762     mUiWidget->setSceneX(x);
   733     HsGui::instance()->idleWidget()->setSceneX(x);
   763 }
   734 }
   764 
   735 
   765 /*!
   736 /*!
   766     Connects the orientation change event handler.
   737     Connects the orientation change event handler.
   767 */
   738 */
   768 void HsIdleState::action_idle_connectOrientationChangeEventHandler()
   739 void HsIdleState::action_idle_connectOrientationChangeEventHandler()
   769 {
   740 {
   770     connect(HsScene::mainWindow(),
   741     connect(HsGui::instance(),
   771         SIGNAL(orientationChanged(Qt::Orientation)),
   742         SIGNAL(orientationChanged(Qt::Orientation)),
   772         SLOT(action_idle_orientationChanged()));
   743         SLOT(action_idle_orientationChanged()));
   773 }
   744 }
   774 
   745 
   775 void HsIdleState::action_idle_orientationChanged()
   746 void HsIdleState::action_idle_orientationChanged()
   812 void HsIdleState::action_idle_cleanupView()
   783 void HsIdleState::action_idle_cleanupView()
   813 {
   784 {
   814     HsScene *scene = HsScene::instance();
   785     HsScene *scene = HsScene::instance();
   815     QApplication::instance()->removeEventFilter(scene);
   786     QApplication::instance()->removeEventFilter(scene);
   816     scene->activePage()->hideWidgets();
   787     scene->activePage()->hideWidgets();
   817 
   788     
       
   789     HsGui::instance()->disconnect(this,SIGNAL(event_applicationLibrary()));
   818     //Close options menu on view change
   790     //Close options menu on view change
   819     HsGui::idleView()->setMenu(NULL);
   791     HsGui::instance()->idleView()->setMenu(NULL);
   820 
   792 
   821     //Close context menu on view change
   793     //Close context menu on view change
   822     if (mSceneMenu) {
   794     if (mSceneMenu) {
   823         mSceneMenu->close();
   795         mSceneMenu->close();
   824     }
   796     }
   827 /*!
   799 /*!
   828     Disconnects the orientation change event handler.
   800     Disconnects the orientation change event handler.
   829 */
   801 */
   830 void HsIdleState::action_idle_disconnectOrientationChangeEventHandler()
   802 void HsIdleState::action_idle_disconnectOrientationChangeEventHandler()
   831 {
   803 {
   832     disconnect(HsScene::mainWindow(),
   804     disconnect(HsGui::instance(),
   833         SIGNAL(orientationChanged(Qt::Orientation)),
   805         SIGNAL(orientationChanged(Qt::Orientation)),
   834         this, SLOT(action_idle_orientationChanged()));
   806         this, SLOT(action_idle_orientationChanged()));
   835 }
   807 }
   836 
   808 
   837 /*!
   809 /*!
   882     } else {
   854     } else {
   883         menu->addAction(hbTrId(hsLocTextId_OptionsMenu_HsToOnline),
   855         menu->addAction(hbTrId(hsLocTextId_OptionsMenu_HsToOnline),
   884             this, SIGNAL(event_toggleConnection()));
   856             this, SIGNAL(event_toggleConnection()));
   885     }
   857     }
   886 
   858 
   887     HsGui::idleView()->setMenu(menu);
   859     HsGui::instance()->idleView()->setMenu(menu);
   888 }
   860 }
   889 
   861 
   890 void HsIdleState::action_waitInput_connectGestureHandlers()
   862 void HsIdleState::action_waitInput_connectGestureHandlers()
   891 {
   863 {
   892     HsScene *scene = HsScene::instance();
   864     HsScene *scene = HsScene::instance();
   931 */
   903 */
   932 void HsIdleState::action_moveWidget_reparentToControlLayer()
   904 void HsIdleState::action_moveWidget_reparentToControlLayer()
   933 {
   905 {
   934     HsWidgetHost *widget = HsScene::instance()->activeWidget();
   906     HsWidgetHost *widget = HsScene::instance()->activeWidget();
   935     Q_ASSERT(widget);
   907     Q_ASSERT(widget);
   936     widget->setParentItem(mUiWidget->controlLayer());
   908     widget->visual()->setParentItem(HsGui::instance()->idleWidget()->controlLayer());
   937 
   909 
   938     mUiWidget->showTrashBin();
   910     HsGui::instance()->idleWidget()->showTrashBin();
   939 }
   911 }
   940 
   912 
   941 /*!
   913 /*!
   942     Starts the widget drag effect.
   914     Starts the widget drag effect.
   943 */
   915 */
  1011     foreach (HsWidgetHost* widget, activePage->widgets()) {
   983     foreach (HsWidgetHost* widget, activePage->widgets()) {
  1012         //If the above function returns the active widget, skip over it as widget and mMovingRect represent same widget.
   984         //If the above function returns the active widget, skip over it as widget and mMovingRect represent same widget.
  1013         if (widget == activeWidget) {
   985         if (widget == activeWidget) {
  1014            continue;
   986            continue;
  1015         }
   987         }
  1016         QRectF widgetRect = widget->geometry();
   988         QRectF widgetRect = widget->visual()->geometry();
  1017         incativeWidgetRects.append(widgetRect);
   989         incativeWidgetRects.append(widgetRect);
  1018     }
   990     }
  1019     return incativeWidgetRects;
   991     return incativeWidgetRects;
  1020 }
   992 }
  1021 
   993 
  1022 /*!
   994 /*!
  1023     Reparents the active widget to the active page.
   995     Reparents the active widget to the active page.
  1024 */
   996 */
  1025 void HsIdleState::action_moveWidget_reparentToPage()
   997 void HsIdleState::action_moveWidget_reparentToPage()
  1026 {
   998 {
  1027     if (mZoneAnimation
   999     HsPropertyAnimationWrapper *pageCrawlingAnimation =
  1028         && mZoneAnimation->state() == QAbstractAnimation::Running
  1000         HsGui::instance()->pageCrawlingAnimation();
  1029         && mZoneAnimation->direction() == QAbstractAnimation::Forward) {
  1001     if (pageCrawlingAnimation->isRunning()&& 
  1030         mZoneAnimation->setDuration(HSCONFIGURATION_GET(pageChangeZoneReverseAnimationDuration));
  1002         pageCrawlingAnimation->isForward()) {
  1031         mZoneAnimation->setDirection(QAbstractAnimation::Backward);
  1003 
       
  1004         pageCrawlingAnimation->setDuration(HSCONFIGURATION_GET(pageChangeZoneReverseAnimationDuration));
       
  1005         pageCrawlingAnimation->setBackward();
  1032     }
  1006     }
  1033 
  1007 
  1034     HsScene *scene = HsScene::instance();
  1008     HsScene *scene = HsScene::instance();
  1035     HsPage *page = scene->activePage();
  1009     HsPage *page = scene->activePage();
  1036     HsWidgetHost *widget = scene->activeWidget();
  1010     HsWidgetHost *widget = scene->activeWidget();
  1037 
  1011 
  1038     if (mUiWidget->trashBin()->isUnderMouse()) {
  1012     if (HsGui::instance()->idleWidget()->trashBin()->isUnderMouse()) {
  1039         HbInstantFeedback::play(HSCONFIGURATION_GET(widgetDropToTrashbinFeedbackEffect));
  1013         HbInstantFeedback::play(HSCONFIGURATION_GET(widgetDropToTrashbinFeedbackEffect));
  1040         widget->page()->removeWidget(widget);
  1014         widget->page()->removeWidget(widget);
  1041         widget->remove();
  1015         widget->remove();
  1042         scene->setActiveWidget(0);
  1016         scene->setActiveWidget(0);
  1043     } else {
  1017     } else {
  1044         if (widget->page() != page) {
  1018         if (widget->page() != page) {
  1045             widget->page()->removeWidget(widget);
  1019             widget->page()->removeWidget(widget);
  1046             page->addExistingWidget(widget);
  1020             page->addExistingWidget(widget);
  1047             if (HsScene::orientation() == Qt::Horizontal) {
  1021             if (HsGui::instance()->orientation() == Qt::Horizontal) {
  1048                 widget->removePresentation(Qt::Vertical);
  1022                 widget->removePresentation(Qt::Vertical);
  1049             } else {
  1023             } else {
  1050                 widget->removePresentation(Qt::Horizontal);
  1024                 widget->removePresentation(Qt::Horizontal);
  1051             }
  1025             }
  1052         }
  1026         }
  1053 
  1027 
  1054         //Set the snap position of the widget and save the position
  1028         //Set the snap position of the widget and save the position
  1055         QRectF widgetRect = widget->geometry();
  1029         QRectF widgetRect = widget->visual()->geometry();
  1056         if (mSnapResult.hasHorizontalSnap) {
  1030         if (mSnapResult.hasHorizontalSnap) {
  1057             widgetRect.moveLeft(mSnapResult.horizontalSnapPosition);
  1031             widgetRect.moveLeft(mSnapResult.horizontalSnapPosition);
  1058         }
  1032         }
  1059         if (mSnapResult.hasVerticalSnap) {
  1033         if (mSnapResult.hasVerticalSnap) {
  1060             widgetRect.moveTop(mSnapResult.verticalSnapPosition);
  1034             widgetRect.moveTop(mSnapResult.verticalSnapPosition);
  1061         }
  1035         }
  1062 
  1036 
  1063         QPointF adjustedWidgetPosition = page->adjustedWidgetPosition(widgetRect);
  1037         QPointF adjustedWidgetPosition = page->adjustedWidgetPosition(widgetRect);
  1064         widget->setPos(adjustedWidgetPosition);
  1038         widget->visual()->setPos(adjustedWidgetPosition);
  1065 
  1039 
  1066         widget->savePresentation();
  1040         widget->savePresentation();
  1067         page->updateZValues();
  1041         page->updateZValues();
  1068     }
  1042     }
  1069 
  1043 
  1070     widget->setParentItem(HsScene::instance()->activePage());
  1044     widget->visual()->setParentItem(HsScene::instance()->activePage()->visual());
  1071 
  1045 
  1072     mUiWidget->showPageIndicator();
  1046     HsGui::instance()->idleWidget()->showPageIndicator();
  1073 }
  1047 }
  1074 
  1048 
  1075 /*!
  1049 /*!
  1076     Starts the widget drop effect.
  1050     Starts the widget drop effect.
  1077 */
  1051 */
  1138     Moves to the nearest page.
  1112     Moves to the nearest page.
  1139 */
  1113 */
  1140 void HsIdleState::action_moveScene_moveToNearestPage()
  1114 void HsIdleState::action_moveScene_moveToNearestPage()
  1141 {
  1115 {
  1142     QList<HsPage *> pages = HsScene::instance()->pages();
  1116     QList<HsPage *> pages = HsScene::instance()->pages();
  1143     QSizeF pageSize = pages.first()->size();
  1117     QSizeF pageSize = pages.first()->visual()->size();
  1144 
  1118 
  1145     int pageIndex = HsScene::instance()->activePageIndex();
  1119     int pageIndex = HsScene::instance()->activePageIndex();
  1146 
  1120 
  1147     if (mDeltaX < -HSCONFIGURATION_GET(pageChangePanDistanceInPixels)) {
  1121     if (mDeltaX < -HSCONFIGURATION_GET(pageChangePanDistanceInPixels)) {
  1148         pageIndex = qMin(pageIndex + 1, pages.count() - 1);
  1122         pageIndex = qMin(pageIndex + 1, pages.count() - 1);
  1150         pageIndex = qMax(pageIndex - 1, 0);
  1124         pageIndex = qMax(pageIndex - 1, 0);
  1151     }
  1125     }
  1152 
  1126 
  1153     HsScene::instance()->setActivePageIndex(pageIndex);
  1127     HsScene::instance()->setActivePageIndex(pageIndex);
  1154 
  1128 
       
  1129     HsPage *page = HsScene::instance()->activePage();
       
  1130     if (page) {
       
  1131         QList<HsWidgetHost *> widgets = page->newWidgets();
       
  1132         if (!widgets.isEmpty()) {
       
  1133             foreach (HsWidgetHost *widget, widgets) {
       
  1134                 widget->startWidget();
       
  1135             }
       
  1136         }
       
  1137     page->layoutNewWidgets();
       
  1138     }
       
  1139 
  1155     startPageChangeAnimation(pageIndex, HSCONFIGURATION_GET(pageChangeAnimationDuration));
  1140     startPageChangeAnimation(pageIndex, HSCONFIGURATION_GET(pageChangeAnimationDuration));
  1156 }
  1141 }
  1157 
  1142 
  1158 void HsIdleState::action_moveScene_disconnectGestureHandlers()
  1143 void HsIdleState::action_moveScene_disconnectGestureHandlers()
  1159 {
  1144 {
  1169     HsScene *scene = HsScene::instance();
  1154     HsScene *scene = HsScene::instance();
  1170 	int pageIndex = scene->activePageIndex() + 1;
  1155 	int pageIndex = scene->activePageIndex() + 1;
  1171     addPageToScene(pageIndex);
  1156     addPageToScene(pageIndex);
  1172     scene->setActivePageIndex(pageIndex);
  1157     scene->setActivePageIndex(pageIndex);
  1173     startPageChangeAnimation(pageIndex, HSCONFIGURATION_GET(newPageAddedAnimationDuration));
  1158     startPageChangeAnimation(pageIndex, HSCONFIGURATION_GET(newPageAddedAnimationDuration));
  1174     mUiWidget->pageIndicator()->addItem(pageIndex);
  1159     HsGui::instance()->idleWidget()->pageIndicator()->addItem(pageIndex);
  1175     mUiWidget->showPageIndicator();
  1160     HsGui::instance()->idleWidget()->showPageIndicator();
  1176 }
  1161 }
  1177 
  1162 
       
  1163 /*!
       
  1164     Displays a confirmation query before page is removed if there are widgets on page 
       
  1165 */
  1178 void HsIdleState::action_preRemovePage_showQuery()
  1166 void HsIdleState::action_preRemovePage_showQuery()
  1179 {
  1167 {
  1180     HsScene *scene = HsScene::instance();
  1168     HsScene *scene = HsScene::instance();
  1181     HsPage *page = scene->activePage();
  1169     HsPage *page = scene->activePage();
  1182 
  1170 
  1194         emit event_removePage();
  1182         emit event_removePage();
  1195     }
  1183     }
  1196 }
  1184 }
  1197 
  1185 
  1198 /*!
  1186 /*!
       
  1187     Make sure confirmation query gets closed if user exits preRemovePage state e.g. by pressing application key
       
  1188 */
       
  1189 void HsIdleState::action_preRemovePage_exit()
       
  1190 {
       
  1191     if (mMessageBoxWrapper) {
       
  1192         mMessageBoxWrapper->close();
       
  1193     }
       
  1194 }
       
  1195 
       
  1196 /*!
  1199     Start remove page animation.
  1197     Start remove page animation.
  1200 */
  1198 */
  1201 void HsIdleState::action_removePage_startRemovePageAnimation()
  1199 void HsIdleState::action_removePage_startRemovePageAnimation()
  1202 {
  1200 {
  1203     HsScene *scene = HsScene::instance();
  1201     HsScene *scene = HsScene::instance();
  1208     int nextPageIndex(pageToRemoveIndex);
  1206     int nextPageIndex(pageToRemoveIndex);
  1209     nextPageIndex++;
  1207     nextPageIndex++;
  1210     if (isLastPage) {
  1208     if (isLastPage) {
  1211         nextPageIndex--; 
  1209         nextPageIndex--; 
  1212     }
  1210     }
  1213     
  1211     HsPropertyAnimationWrapper *animation = HsGui::instance()->pageChangeAnimation();
  1214     if (mPageChangeAnimation->isRunning()) {
  1212     if (animation->isRunning()) {
  1215         mPageChangeAnimation->stop();
  1213         animation->stop();
  1216     }
  1214     }
  1217     mPageChangeAnimation->disconnect(this);
  1215     animation->disconnect(this);
  1218     connect(mPageChangeAnimation,
  1216     connect(animation,
  1219             SIGNAL(finished()),
  1217             SIGNAL(finished()),
  1220             SIGNAL(event_waitInput()), 
  1218             SIGNAL(event_waitInput()), 
  1221             Qt::UniqueConnection);
  1219             Qt::UniqueConnection);
  1222     mPageChangeAnimation->setEndValue(pageLayerXPos(nextPageIndex));
  1220     animation->setEndValue(pageLayerXPos(nextPageIndex));
  1223     mPageChangeAnimation->setDuration(HSCONFIGURATION_GET(pageRemovedAnimationDuration));
  1221     animation->setDuration(HSCONFIGURATION_GET(pageRemovedAnimationDuration));
  1224    
  1222    
  1225     mPageChangeAnimation->start();
  1223     animation->start();
  1226     
  1224     
  1227     HbInstantFeedback::play(HSCONFIGURATION_GET(pageChangeFeedbackEffect));
  1225     HbInstantFeedback::play(HSCONFIGURATION_GET(pageChangeFeedbackEffect));
  1228     
  1226     
  1229 }
  1227 }
  1230 
  1228 
  1231 /*!
  1229 /*!
  1232     Removes an existing page from the scene.
  1230     Removes an existing page from the scene.
  1233 */
  1231 */
  1234 void HsIdleState::action_removePage_removePage()
  1232 void HsIdleState::action_removePage_removePage()
  1235 {
  1233 {
  1236     if (mPageChangeAnimation->isRunning()) {
  1234     HsIdleWidget *idleWidget = HsGui::instance()->idleWidget();
  1237         mPageChangeAnimation->stop();
  1235     HsPropertyAnimationWrapper *animation = HsGui::instance()->pageChangeAnimation();
  1238     }
       
  1239     HsScene *scene = HsScene::instance();
  1236     HsScene *scene = HsScene::instance();
  1240     HsPage *pageToRemove = scene->activePage();
  1237     HsPage *pageToRemove = scene->activePage();
  1241     
  1238 
       
  1239     if (animation->isRunning()) {
       
  1240         animation->stop();
       
  1241     }
  1242     // remove from ui
  1242     // remove from ui
  1243     mUiWidget->removePage(pageToRemove->pageIndex());
  1243     idleWidget->removePage(pageToRemove->pageIndex());
  1244     mUiWidget->showPageIndicator();
  1244     idleWidget->showPageIndicator();
  1245     // update data model
  1245     // update data model
  1246     HsScene::instance()->removePage(pageToRemove);
  1246     scene->removePage(pageToRemove);
  1247     // Take new active page (previous was removed) and move scene to right position
  1247     // Take new active page (previous was removed) and move scene to right position
  1248     qreal x = pageLayerXPos(scene->activePageIndex());
  1248     qreal x = pageLayerXPos(scene->activePageIndex());
  1249     mUiWidget->setSceneX(x);
  1249     idleWidget->setSceneX(x);
  1250     // delete it   
  1250     // delete it   
  1251     pageToRemove->deleteLater();
  1251     pageToRemove->deleteLater();
  1252    
  1252    
  1253 }
  1253 }
  1254 /*!
  1254 /*!
  1281  */
  1281  */
  1282 void HsIdleState::zoneAnimationFinished()
  1282 void HsIdleState::zoneAnimationFinished()
  1283 {
  1283 {
  1284     HsScene *scene = HsScene::instance();
  1284     HsScene *scene = HsScene::instance();
  1285     int pageIndex = scene->activePageIndex();
  1285     int pageIndex = scene->activePageIndex();
  1286 
  1286     HsGui *gui(HsGui::instance());
  1287     if (mZoneAnimation->direction() == QAbstractAnimation::Forward) {
  1287     if (gui->pageCrawlingAnimation()->isForward()) {
  1288         if (isInLeftPageChangeZone() &&
  1288         if (isInLeftPageChangeZone() &&
  1289             0 < pageIndex) {
  1289             0 < pageIndex) {
  1290             --pageIndex;
  1290             --pageIndex;
  1291         } else if (isInRightPageChangeZone() &&
  1291         } else if (isInRightPageChangeZone() &&
  1292                    pageIndex < scene->pages().count()) {
  1292                    pageIndex < scene->pages().count()) {
  1293             ++pageIndex;
  1293             ++pageIndex;
  1294         }
  1294         }
  1295         if (pageIndex == scene->pages().count()) {
  1295         if (pageIndex == scene->pages().count()) {
  1296             if (pageIndex < HSCONFIGURATION_GET(maximumPageCount)) {
  1296             if (pageIndex < HSCONFIGURATION_GET(maximumPageCount)) {
  1297                 addPageToScene(pageIndex);
  1297                 addPageToScene(pageIndex);
  1298                 mUiWidget->showPageIndicator();
  1298                 gui->idleWidget()->showPageIndicator();
  1299                 mUiWidget->pageIndicator()->addItem(pageIndex);
  1299                 gui->idleWidget()->pageIndicator()->addItem(pageIndex);
  1300             }
  1300             }
  1301         }
  1301         }
  1302         scene->setActivePageIndex(pageIndex);
  1302         scene->setActivePageIndex(pageIndex);
  1303         startPageChangeAnimation(pageIndex, HSCONFIGURATION_GET(pageChangeAnimationDuration));
  1303         startPageChangeAnimation(pageIndex, HSCONFIGURATION_GET(pageChangeAnimationDuration));
  1304     } else {
  1304     } else {
  1305         scene->setActivePageIndex(pageIndex);
  1305         scene->setActivePageIndex(pageIndex);
  1306         mUiWidget->setActivePage(pageIndex);
  1306         gui->idleWidget()->setActivePage(pageIndex);
  1307     }
  1307     }
  1308 }
  1308 }
  1309 
  1309 
  1310 /*!
  1310 /*!
  1311     Page change animation has been finished.
  1311     Page change animation has been finished.
  1321 */
  1321 */
  1322 void HsIdleState::updatePagePresentationToWidgetSnap()
  1322 void HsIdleState::updatePagePresentationToWidgetSnap()
  1323 {
  1323 {
  1324     QRectF containerRect = HsScene::instance()->activePage()->contentGeometry();
  1324     QRectF containerRect = HsScene::instance()->activePage()->contentGeometry();
  1325     HsWidgetHost *activeWidget = HsScene::instance()->activeWidget();
  1325     HsWidgetHost *activeWidget = HsScene::instance()->activeWidget();
  1326     HsWidgetPositioningOnWidgetMove::instance()->setPagePresentation(containerRect, createInactiveWidgetRects(), activeWidget->geometry());
  1326     HsWidgetPositioningOnWidgetMove::instance()->setPagePresentation(
       
  1327         containerRect, createInactiveWidgetRects(), activeWidget->visual()->geometry());
  1327 }
  1328 }
  1328 
  1329 
  1329 /*!
  1330 /*!
  1330     Reset Snap position, hide the snap lines
  1331     Reset Snap position, hide the snap lines
  1331 */
  1332 */
  1350         //As the Vertical Line position is at the same place,
  1351         //As the Vertical Line position is at the same place,
  1351         //the timer was started when vertical line positions were at different locations
  1352         //the timer was started when vertical line positions were at different locations
  1352         //the line will be shown when the timer expires.
  1353         //the line will be shown when the timer expires.
  1353         //If timer has already expired, just show the line, which is redrawn to new geometry.
  1354         //If timer has already expired, just show the line, which is redrawn to new geometry.
  1354         if (!mVerticalSnapLineTimer.isActive()) {
  1355         if (!mVerticalSnapLineTimer.isActive()) {
  1355             mUiWidget->showVerticalSnapLine(mSnapResult.verticalSnapLine);
  1356             HsGui::instance()->idleWidget()->showVerticalSnapLine(mSnapResult.verticalSnapLine);
  1356         }
  1357         }
  1357     }
  1358     }
  1358 }
  1359 }
  1359 
  1360 
  1360 /*!
  1361 /*!
  1361     Timer for showing the Vertical line expires
  1362     Timer for showing the Vertical line expires
  1362 */
  1363 */
  1363 void HsIdleState::onVerticalSnapLineTimerTimeout()
  1364 void HsIdleState::onVerticalSnapLineTimerTimeout()
  1364 {
  1365 {
  1365     mUiWidget->showVerticalSnapLine(mSnapResult.verticalSnapLine);
  1366     HsGui::instance()->idleWidget()->showVerticalSnapLine(mSnapResult.verticalSnapLine);
  1366 }
  1367 }
  1367 
  1368 
  1368 /*!
  1369 /*!
  1369     Hide the Vertical line for Snap guidance
  1370     Hide the Vertical line for Snap guidance
  1370 */
  1371 */
  1371 void HsIdleState::hideVerticalLine()
  1372 void HsIdleState::hideVerticalLine()
  1372 {
  1373 {
  1373     mUiWidget->hideVerticalSnapLine();
  1374     HsGui::instance()->idleWidget()->hideVerticalSnapLine();
  1374     mVerticalSnapLineTimer.stop();
  1375     mVerticalSnapLineTimer.stop();
  1375 }
  1376 }
  1376 
  1377 
  1377 /*!
  1378 /*!
  1378     Show the Horizontal line for Snap guidance
  1379     Show the Horizontal line for Snap guidance
  1383         hideHorizontalLine();
  1384         hideHorizontalLine();
  1384         mHorizontalSnapLineTimer.start();
  1385         mHorizontalSnapLineTimer.start();
  1385     }
  1386     }
  1386     else {
  1387     else {
  1387         if (!mHorizontalSnapLineTimer.isActive()) {
  1388         if (!mHorizontalSnapLineTimer.isActive()) {
  1388             mUiWidget->showHorizontalSnapLine(mSnapResult.horizontalSnapLine);
  1389             HsGui::instance()->idleWidget()->showHorizontalSnapLine(mSnapResult.horizontalSnapLine);
  1389         }
  1390         }
  1390     }
  1391     }
  1391 }
  1392 }
  1392 
  1393 
  1393 /*!
  1394 /*!
  1394     Timer for showing the Horizontal line expires
  1395     Timer for showing the Horizontal line expires
  1395 */
  1396 */
  1396 void HsIdleState::onHorizontalSnapLineTimerTimeout()
  1397 void HsIdleState::onHorizontalSnapLineTimerTimeout()
  1397 {
  1398 {
  1398     mUiWidget->showHorizontalSnapLine(mSnapResult.horizontalSnapLine);
  1399     HsGui::instance()->idleWidget()->showHorizontalSnapLine(mSnapResult.horizontalSnapLine);
  1399 }
  1400 }
  1400 
  1401 
  1401 /*!
  1402 /*!
  1402     Hide the Horizontal line for Snap guidance
  1403     Hide the Horizontal line for Snap guidance
  1403 */
  1404 */
  1404 void HsIdleState::hideHorizontalLine()
  1405 void HsIdleState::hideHorizontalLine()
  1405 {
  1406 {
  1406     mUiWidget->hideHorizontalSnapLine();
  1407     HsGui::instance()->idleWidget()->hideHorizontalSnapLine();
  1407     mHorizontalSnapLineTimer.stop();
  1408     mHorizontalSnapLineTimer.stop();
  1408 }
  1409 }
  1409 
  1410 
  1410 /*!
  1411 /*!
  1411     Handles updating the Snap algorithm with page presentation on page change
  1412     Handles updating the Snap algorithm with page presentation on page change