homescreenapp/stateplugins/hshomescreenstateplugin/src/hsidlestate.cpp
changeset 36 cdae8c6c3876
parent 35 f9ce957a272c
child 39 4e8ebe173323
equal deleted inserted replaced
35:f9ce957a272c 36:cdae8c6c3876
    29 #include <HbAction>
    29 #include <HbAction>
    30 #include <HbIcon>
    30 #include <HbIcon>
    31 
    31 
    32 #include "hsidlestate.h"
    32 #include "hsidlestate.h"
    33 #include "hsidlewidget.h"
    33 #include "hsidlewidget.h"
       
    34 #include "hsdomainmodeldatastructures.h"
    34 #include "hsscene.h"
    35 #include "hsscene.h"
    35 #include "hspage.h"
    36 #include "hspage.h"
    36 #include "hswidgethost.h"
    37 #include "hswidgethost.h"
    37 #include "hswallpaper.h"
    38 #include "hswallpaper.h"
    38 #include "hspagedata.h"
       
    39 #include "hsselectbackgroundstate.h"
    39 #include "hsselectbackgroundstate.h"
    40 #include "hstrashbinwidget.h"
    40 #include "hstrashbinwidget.h"
    41 #include "hspageindicator.h"
    41 #include "hspageindicator.h"
    42 #include "hsapptranslator.h"
    42 #include "hsapptranslator.h"
    43 #include "hswidgetpositioningonorientationchange.h"
    43 #include "hswidgetpositioningonorientationchange.h"
    44 #include "hsmenueventfactory.h"
    44 #include "hsmenueventfactory.h"
       
    45 #include "hshomescreenstatecommon.h"
    45 
    46 
    46 // Helper macros for connecting state entry and exit actions.
    47 // Helper macros for connecting state entry and exit actions.
    47 #define ENTRY_ACTION(state, action) \
    48 #define ENTRY_ACTION(state, action) \
    48     connect(state, SIGNAL(entered()), SLOT(action()));
    49     connect(state, SIGNAL(entered()), SLOT(action()));
    49 #define EXIT_ACTION(state, action) \
    50 #define EXIT_ACTION(state, action) \
    50     connect(state, SIGNAL(exited()), SLOT(action()));
    51     connect(state, SIGNAL(exited()), SLOT(action()));
    51 
    52 
    52 // Helper macros for connecting and disconnecting mouse event handlers.
    53 // Helper macros for connecting and disconnecting mouse event handlers.
    53 #define CONNECT_MOUSE_EVENT_HANDLER(signal, slot) \
    54 #define CONNECT_MOUSE_EVENT_HANDLER(signal, slot) \
    54     connect(mUiWidget, SIGNAL(signal(QGraphicsItem*, QGraphicsSceneMouseEvent*, bool&)), \
    55     connect(mUiWidget, SIGNAL(signal(QGraphicsItem*,QGraphicsSceneMouseEvent*,bool&)), \
    55         SLOT(slot(QGraphicsItem*, QGraphicsSceneMouseEvent*, bool&)));
    56         SLOT(slot(QGraphicsItem*,QGraphicsSceneMouseEvent*,bool&)));
    56 #define DISCONNECT_MOUSE_EVENT_HANDLER(signal, slot) \
    57 #define DISCONNECT_MOUSE_EVENT_HANDLER(signal, slot) \
    57     disconnect(mUiWidget, SIGNAL(signal(QGraphicsItem*, QGraphicsSceneMouseEvent*, bool&)), \
    58     disconnect(mUiWidget, SIGNAL(signal(QGraphicsItem*,QGraphicsSceneMouseEvent*,bool&)), \
    58         this, SLOT(slot(QGraphicsItem*, QGraphicsSceneMouseEvent*, bool&)));
    59         this, SLOT(slot(QGraphicsItem*,QGraphicsSceneMouseEvent*,bool&)));
    59 
    60 
    60 
    61 
    61 namespace
    62 namespace
    62 {
    63 {
    63     const char APP_LIB_BUTTON[] = 
    64     const char gApplicationLibraryIconName[] = "qtg_mono_applications_all";
    64         "hs_applib_button.png";
    65     const char gAddPageTextName[]            = "txt_homescreen_opt_add_page";
    65     /*const char TXT_HOMESCREEN_TITLE_OFFLINE[] = 
    66     const char gRemovePageTextName[]         = "txt_homescreen_opt_remove_page";
    66         "txt_homescreen_title_offline";*/
    67     const char gToOnlineTextName[]           = "txt_homescreen_opt_home_screen_to_online";
    67     const char TXT_HOMESCREEN_OPT_ADD_PAGE[] = 
    68     const char gToOfflineTextName[]          = "txt_homescreen_opt_home_screen_to_offline";
    68         "txt_homescreen_opt_add_page";
    69     const char gChangeWallpaperTextName[]    = "txt_homescreen_list_change_wallpaper";
    69     const char TXT_HOMESCREEN_OPT_REMOVE_PAGE[] = 
    70     const char gAddContentTextName[]         = "txt_homescreen_list_add_content";
    70         "txt_homescreen_opt_remove_page";
    71     //const char gTitleOfflineTextName[]       = "txt_homescreen_title_offline";
    71     const char TXT_HOMESCREEN_OPT_HOME_SCREEN_TO_ONLINE[] = 
       
    72         "txt_homescreen_opt_home_screen_to_online";
       
    73     const char TXT_HOMESCREEN_OPT_HOME_SCREEN_TO_OFFLINE[] = 
       
    74         "txt_homescreen_opt_home_screen_to_offline";
       
    75     const char TXT_HOMESCREEN_LIST_CHANGE_WALLPAPER[] = 
       
    76         "txt_homescreen_list_change_wallpaper";
       
    77     const char TXT_HOMESCREEN_LIST_ADD_CONTENT[] = 
       
    78         "txt_homescreen_list_add_content";
       
    79 }
    72 }
    80 
    73 
    81 /*!
    74 /*!
    82     \class HsIdleState
    75     \class HsIdleState
    83     \ingroup group_hshomescreenstateplugin
    76     \ingroup group_hshomescreenstateplugin
    92 /*!
    85 /*!
    93     Constructs a new idle state with the given \a parent.
    86     Constructs a new idle state with the given \a parent.
    94 */
    87 */
    95 HsIdleState::HsIdleState(QState *parent)
    88 HsIdleState::HsIdleState(QState *parent)
    96   : QState(parent),
    89   : QState(parent),
    97     mView(0), mSoftKeyAction(0), mUiWidget(0),
    90     mView(0), mNavigationAction(0), mUiWidget(0),
    98     mTapAndHoldDistance(16),
    91     mTapAndHoldDistance(16),
    99     mPageChangeZoneWidth(60)
    92     mPageChangeZoneWidth(60)
   100 {
    93 {
   101     setupStates();
    94     setupStates();
   102     mTimer.setSingleShot(true);
    95     mTimer.setSingleShot(true);
   266 
   259 
   267     ENTRY_ACTION(state_moveWidget, action_moveWidget_reparentToControlLayer)
   260     ENTRY_ACTION(state_moveWidget, action_moveWidget_reparentToControlLayer)
   268     ENTRY_ACTION(state_moveWidget, action_moveWidget_startWidgetDragAnimation)
   261     ENTRY_ACTION(state_moveWidget, action_moveWidget_startWidgetDragAnimation)
   269     ENTRY_ACTION(state_moveWidget, action_moveWidget_connectMouseEventHandlers)
   262     ENTRY_ACTION(state_moveWidget, action_moveWidget_connectMouseEventHandlers)
   270     ENTRY_ACTION(state_moveWidget, action_moveWidget_connectGestureTimers)
   263     ENTRY_ACTION(state_moveWidget, action_moveWidget_connectGestureTimers)
       
   264 
   271     EXIT_ACTION(state_moveWidget, action_moveWidget_reparentToPage)
   265     EXIT_ACTION(state_moveWidget, action_moveWidget_reparentToPage)
   272     EXIT_ACTION(state_moveWidget, action_moveWidget_startWidgetDropAnimation)
   266     EXIT_ACTION(state_moveWidget, action_moveWidget_startWidgetDropAnimation)
   273     EXIT_ACTION(state_moveWidget, action_moveWidget_disconnectMouseEventHandlers)
   267     EXIT_ACTION(state_moveWidget, action_moveWidget_disconnectMouseEventHandlers)
   274     EXIT_ACTION(state_moveWidget, action_moveWidget_disconnectGestureTimers)
   268     EXIT_ACTION(state_moveWidget, action_moveWidget_disconnectGestureTimers)
   275 
   269 
   311     animation->setEndValue(pageLayerXPos(targetPageIndex));
   305     animation->setEndValue(pageLayerXPos(targetPageIndex));
   312     animation->setDuration(duration);
   306     animation->setDuration(duration);
   313     animationGroup->addAnimation(animation);
   307     animationGroup->addAnimation(animation);
   314 
   308 
   315     animation = new QPropertyAnimation(mUiWidget->sceneLayer(), "x");
   309     animation = new QPropertyAnimation(mUiWidget->sceneLayer(), "x");
   316     animation->setEndValue(parallaxFactor() * pageLayerXPos(targetPageIndex));
   310     animation->setEndValue((parallaxFactor() * pageLayerXPos(targetPageIndex)) - HSBOUNDARYEFFECT / 2);
   317     animation->setDuration(duration);
   311     animation->setDuration(duration);
   318     animationGroup->addAnimation(animation);
   312     animationGroup->addAnimation(animation);
   319         
   313         
   320     animationGroup->start(QAbstractAnimation::DeleteWhenStopped);
   314     animationGroup->start(QAbstractAnimation::DeleteWhenStopped);
   321 
   315 
   360     Inserts new page at index position \a pageIndex in the scene.
   354     Inserts new page at index position \a pageIndex in the scene.
   361 */
   355 */
   362 void HsIdleState::addPageToScene(int pageIndex)
   356 void HsIdleState::addPageToScene(int pageIndex)
   363 {
   357 {
   364     HsPageData data;
   358     HsPageData data;
   365     data.setIndex(pageIndex);
   359     data.indexPosition = pageIndex;
   366     HsPage *page = HsPage::createInstance(data);
   360     HsPage *page = HsPage::createInstance(data);
   367     page->load();
   361     page->load();
   368     HsScene::instance()->addPage(page);    
   362     HsScene::instance()->addPage(page);    
   369     mUiWidget->insertPage(pageIndex, page);
   363     mUiWidget->insertPage(pageIndex, page);
   370 }
   364 }
   374     page layer widths, and page count.
   368     page layer widths, and page count.
   375 */
   369 */
   376 qreal HsIdleState::parallaxFactor() const
   370 qreal HsIdleState::parallaxFactor() const
   377 {
   371 {
   378     qreal clw = mUiWidget->controlLayer()->size().width();
   372     qreal clw = mUiWidget->controlLayer()->size().width();
   379     qreal slw = mUiWidget->sceneLayer()->size().width();
   373     qreal slw = mUiWidget->sceneLayer()->size().width() - HSBOUNDARYEFFECT;
   380     int n = HsScene::instance()->pages().count();
   374     int n = HsScene::instance()->pages().count();
   381     if (n < 2) {
   375     if (n < 2) {
   382         return 1;
   376         return 1;
   383     } else {
   377     } else {
   384         return (slw - clw) / ((n - 1) * clw);
   378         return (slw - clw) / ((n - 1) * clw);
   410 {
   404 {
   411     if (!mView) {
   405     if (!mView) {
   412         mUiWidget = new HsIdleWidget;
   406         mUiWidget = new HsIdleWidget;
   413         mView = HsScene::mainWindow()->addView(mUiWidget);
   407         mView = HsScene::mainWindow()->addView(mUiWidget);
   414         mView->setContentFullScreen();
   408         mView->setContentFullScreen();
   415         mView->setTitle("Home Screen"/*hbTrId(TXT_HOMESCREEN_TITLE_OFFLINE)*/);
   409         mView->setTitle("Home Screen"/*hbTrId(gTitleOfflineTextName)*/);
   416         
   410         
   417         mSoftKeyAction = new HbAction(this);
   411         mNavigationAction = new HbAction(this);
   418         mSoftKeyAction->setIcon(HbIcon(APP_LIB_BUTTON));
   412         mNavigationAction->setIcon(HbIcon(gApplicationLibraryIconName));
   419         connect(mSoftKeyAction, SIGNAL(triggered()), SIGNAL(event_applicationLibrary()));
   413         connect(mNavigationAction, SIGNAL(triggered()), SIGNAL(event_applicationLibrary()));
       
   414         mView->setNavigationAction(mNavigationAction);
   420         
   415         
   421 #ifndef Q_OS_SYMBIAN
   416 #ifndef Q_OS_SYMBIAN
   422         connect(HsAppTranslator::instance(), 
   417         connect(HsAppTranslator::instance(), 
   423             SIGNAL(languageChanged()), SLOT(translateUi()));
   418             SIGNAL(languageChanged()), SLOT(translateUi()));
   424 #endif
   419 #endif
   425         // TODO: Workaround to Qt/Hb layouting bugs.
   420         // TODO: Workaround to Qt/Hb layouting bugs.
   426         QApplication::processEvents(QEventLoop::ExcludeUserInputEvents);
   421         QApplication::processEvents(QEventLoop::ExcludeUserInputEvents);
   427     }
   422     }
   428 
   423 
   429     HsScene::mainWindow()->addSoftKeyAction(Hb::SecondarySoftKey, mSoftKeyAction);
       
   430     HsScene::mainWindow()->setCurrentView(mView);
   424     HsScene::mainWindow()->setCurrentView(mView);
   431 }
   425 }
   432 
   426 
   433 /*!
   427 /*!
   434     Lays out the active page's new widgets that were added
   428     Lays out the active page's new widgets that were added
   450         widget->initializeWidget();
   444         widget->initializeWidget();
   451         widget->showWidget();
   445         widget->showWidget();
   452     }
   446     }
   453 
   447 
   454     page->layoutNewWidgets();
   448     page->layoutNewWidgets();
   455     page->resetNewWidgets();
   449 
   456 }
   450 }
   457 
   451 
   458 /*!
   452 /*!
   459     Moves the scene and page layers so that the active
   453     Moves the scene and page layers so that the active
   460     page is shown.
   454     page is shown.
   461 */
   455 */
   462 void HsIdleState::action_idle_showActivePage()
   456 void HsIdleState::action_idle_showActivePage()
   463 {
   457 {
   464     qreal x = pageLayerXPos(HsScene::instance()->activePageIndex());
   458     qreal x = pageLayerXPos(HsScene::instance()->activePageIndex());
   465     mUiWidget->pageLayer()->setX(x);
   459     mUiWidget->pageLayer()->setX(x);
   466     mUiWidget->sceneLayer()->setX(parallaxFactor() * x);
   460     mUiWidget->sceneLayer()->setX((parallaxFactor() * x) - HSBOUNDARYEFFECT / 2);
   467 }
   461 }
   468 
   462 
   469 /*!
   463 /*!
   470     Connects the orientation change event handler.
   464     Connects the orientation change event handler.
   471 */
   465 */
   479 /*!
   473 /*!
   480     Cleans up the idle view.
   474     Cleans up the idle view.
   481 */
   475 */
   482 void HsIdleState::action_idle_cleanupView()
   476 void HsIdleState::action_idle_cleanupView()
   483 {
   477 {
   484     HsScene::mainWindow()->removeSoftKeyAction(
       
   485         Hb::SecondarySoftKey, mSoftKeyAction);
       
   486 }
   478 }
   487 
   479 
   488 /*!
   480 /*!
   489     Disconnects the orientation change event handler.
   481     Disconnects the orientation change event handler.
   490 */
   482 */
   498 /*!
   490 /*!
   499     Updates the options menu content.
   491     Updates the options menu content.
   500 */
   492 */
   501 void HsIdleState::action_waitInput_updateOptionsMenu()
   493 void HsIdleState::action_waitInput_updateOptionsMenu()
   502 {
   494 {
       
   495     HsScene *scene = HsScene::instance();
       
   496 
   503     HbMenu *menu = new HbMenu();
   497     HbMenu *menu = new HbMenu();
   504     
   498     
   505     menu->addAction(hbTrId(TXT_HOMESCREEN_OPT_ADD_PAGE), 
   499     // Add page
   506         this, SIGNAL(event_addPage()));
   500     if (scene->pages().count() < scene->maximumPageCount()) {
   507     menu->addAction(hbTrId(TXT_HOMESCREEN_OPT_REMOVE_PAGE), 
   501         menu->addAction(hbTrId(gAddPageTextName), 
   508         this, SIGNAL(event_removePage()))->setEnabled(
   502             this, SIGNAL(event_addPage()));
   509         HsScene::instance()->activePage()->isRemovable());
   503     }
   510         
   504 
   511     if (HsScene::instance()->isOnline()) {
   505     // Remove page
   512         menu->addAction(hbTrId(TXT_HOMESCREEN_OPT_HOME_SCREEN_TO_OFFLINE),
   506     if (scene->activePage()->isRemovable()) {
       
   507         menu->addAction(hbTrId(gRemovePageTextName), 
       
   508             this, SIGNAL(event_removePage()));
       
   509     }
       
   510     
       
   511     // Online / Offline
       
   512     if (scene->isOnline()) {
       
   513         menu->addAction(hbTrId(gToOfflineTextName),
   513             this, SIGNAL(event_toggleConnection()));
   514             this, SIGNAL(event_toggleConnection()));
   514     } else {
   515     } else {
   515         menu->addAction(hbTrId(TXT_HOMESCREEN_OPT_HOME_SCREEN_TO_ONLINE),
   516         menu->addAction(hbTrId(gToOnlineTextName),
   516             this, SIGNAL(event_toggleConnection())); 
   517             this, SIGNAL(event_toggleConnection())); 
   517     }
   518     }
   518 
   519 
   519 #ifndef Q_OS_SYMBIAN
   520 #ifndef Q_OS_SYMBIAN
   520     menu->addAction(hbTrId("txt_homescreen_opt_switch_language"),
   521     menu->addAction(hbTrId("txt_homescreen_opt_switch_language"),
   726 void HsIdleState::action_sceneMenu_showMenu()
   727 void HsIdleState::action_sceneMenu_showMenu()
   727 {
   728 {
   728     HbMenu menu;
   729     HbMenu menu;
   729 
   730 
   730     HbAction *changeWallpaperAction = 
   731     HbAction *changeWallpaperAction = 
   731         menu.addAction(hbTrId(TXT_HOMESCREEN_LIST_CHANGE_WALLPAPER));
   732         menu.addAction(hbTrId(gChangeWallpaperTextName));
   732     HbAction *addContentAction = 
   733     HbAction *addContentAction = 
   733         menu.addAction(hbTrId(TXT_HOMESCREEN_LIST_ADD_CONTENT));
   734         menu.addAction(hbTrId(gAddContentTextName));
   734 
   735 
   735     HbAction *action = menu.exec(mSceneMenuPos);
   736     HbAction *action = menu.exec(mSceneMenuPos);
   736     if (action == changeWallpaperAction) {
   737     if (action == changeWallpaperAction) {
   737         emit event_selectSceneWallpaper();
   738         emit event_selectSceneWallpaper();
   738     } else if (action == addContentAction) {
   739     } else if (action == addContentAction) {
   754     HsScene *scene = HsScene::instance();    
   755     HsScene *scene = HsScene::instance();    
   755     int pageIndex = scene->pages().count();    
   756     int pageIndex = scene->pages().count();    
   756     addPageToScene(pageIndex);    
   757     addPageToScene(pageIndex);    
   757     scene->setActivePageIndex(pageIndex);
   758     scene->setActivePageIndex(pageIndex);
   758     startPageChangeAnimation(pageIndex, 700);
   759     startPageChangeAnimation(pageIndex, 700);
   759     mUiWidget->pageIndicator()->addItem(true, true);
   760     mUiWidget->pageIndicator()->addItem(pageIndex);
       
   761     mUiWidget->showPageIndicator();
   760 }
   762 }
   761 
   763 
   762 /*!
   764 /*!
   763     Removes an existing page from the scene.
   765     Removes an existing page from the scene.
   764 */
   766 */
   768     HsPage *page = scene->activePage();    
   770     HsPage *page = scene->activePage();    
   769     int pageIndex = scene->activePageIndex();
   771     int pageIndex = scene->activePageIndex();
   770 
   772 
   771     mUiWidget->removePage(pageIndex);
   773     mUiWidget->removePage(pageIndex);
   772     scene->removePage(page);
   774     scene->removePage(page);
   773     page->deleteFromDatabase();
       
   774     delete page;
   775     delete page;
   775 
   776 
   776     pageIndex = pageIndex == 0 ? 0 : pageIndex - 1;
   777     pageIndex = pageIndex == 0 ? 0 : pageIndex - 1;
   777     scene->setActivePageIndex(pageIndex);
   778     scene->setActivePageIndex(pageIndex);
   778 
   779 
   779     startPageChangeAnimation(pageIndex, 200);
   780     startPageChangeAnimation(pageIndex, 200);
   780 
   781 
   781     mUiWidget->pageIndicator()->removeItem();
   782     mUiWidget->pageIndicator()->removeItem(pageIndex);
   782     mUiWidget->setActivePage(pageIndex);
   783     mUiWidget->setActivePage(pageIndex);
       
   784     mUiWidget->showPageIndicator();
   783 }
   785 }
   784 
   786 
   785 /*!
   787 /*!
   786     Toggles the homescreen online/offline state.
   788     Toggles the homescreen online/offline state.
   787 */
   789 */
   841     if (!mTimer.isActive()) {
   843     if (!mTimer.isActive()) {
   842         return;
   844         return;
   843     }
   845     }
   844 
   846 
   845     QPointF point = 
   847     QPointF point = 
   846         event->screenPos() - event->buttonDownScreenPos(Qt::LeftButton);
   848         event->scenePos() - event->buttonDownScenePos(Qt::LeftButton);
   847     if (mTapAndHoldDistance < point.manhattanLength()) {
   849     if (mTapAndHoldDistance < point.manhattanLength()) {
   848         mTimer.stop();
   850         mTimer.stop();
   849         mUiWidget->sendDelayedPress();
   851         mUiWidget->sendDelayedPress();
   850     }
   852     }
   851 }
   853 }
   890     if (!mTimer.isActive()) {
   892     if (!mTimer.isActive()) {
   891         return;
   893         return;
   892     }
   894     }
   893 
   895 
   894     QPointF point = 
   896     QPointF point = 
   895         event->screenPos() - event->buttonDownScreenPos(Qt::LeftButton);
   897         event->scenePos() - event->buttonDownScenePos(Qt::LeftButton);
   896     if (mTapAndHoldDistance < point.manhattanLength()) {
   898     if (mTapAndHoldDistance < point.manhattanLength()) {
   897         mTimer.stop();
   899         mTimer.stop();
   898         mUiWidget->clearDelayedPress();
   900         mUiWidget->clearDelayedPress();
   899         emit event_moveScene();
   901         emit event_moveScene();
   900     }
   902     }
   934     Q_UNUSED(filtered)
   936     Q_UNUSED(filtered)
   935 
   937 
   936     HsWidgetHost *widget = HsScene::instance()->activeWidget();
   938     HsWidgetHost *widget = HsScene::instance()->activeWidget();
   937     Q_ASSERT(widget);
   939     Q_ASSERT(widget);
   938 
   940 
   939     QPointF delta(event->screenPos() - event->lastScreenPos());
   941     QPointF delta(event->scenePos() - event->lastScenePos());
   940     QRectF region =  mView->rect().adjusted(10, 55, -10, -10);
   942     QRectF region =  mView->rect().adjusted(10, 55, -10, -10);
   941     QPointF position = widget->geometry().center() + delta;
   943     QPointF position = widget->geometry().center() + delta;
   942     if (!region.contains(position)) {
   944     if (!region.contains(position)) {
   943         position.setX(qBound(region.left(), position.x(), region.right()));
   945         position.setX(qBound(region.left(), position.x(), region.right()));
   944         position.setY(qBound(region.top(), position.y(), region.bottom()));
   946         position.setY(qBound(region.top(), position.y(), region.bottom()));
   960         mUiWidget->trashBin()->activate();
   962         mUiWidget->trashBin()->activate();
   961     } else {
   963     } else {
   962         mUiWidget->trashBin()->deactivate();
   964         mUiWidget->trashBin()->deactivate();
   963     }
   965     }
   964 
   966 
   965     if (!mUiWidget->pageIndicator()->isAnimatingCurrentItemChange()) {
   967     if (!mUiWidget->pageIndicator()->isAnimationRunning()) {
   966         mUiWidget->showTrashBin();
   968         mUiWidget->showTrashBin();
   967     }
   969     }
   968 }
   970 }
   969 
   971 
   970 /*!
   972 /*!
  1021     Q_UNUSED(watched)
  1023     Q_UNUSED(watched)
  1022     Q_UNUSED(filtered)
  1024     Q_UNUSED(filtered)
  1023     
  1025     
  1024     HsScene *scene = HsScene::instance();
  1026     HsScene *scene = HsScene::instance();
  1025     qreal delta = 
  1027     qreal delta = 
  1026         event->screenPos().x() - event->buttonDownScreenPos(Qt::LeftButton).x();
  1028         event->scenePos().x() - event->buttonDownScenePos(Qt::LeftButton).x();
  1027     
  1029 
  1028     qreal x = qBound(pageLayerXPos(scene->pages().count() - 1),
  1030     qreal x = qBound(pageLayerXPos(scene->pages().count() - 1) - HSBOUNDARYEFFECT / 2 / parallaxFactor(),
  1029                      pageLayerXPos(scene->activePageIndex()) + delta,
  1031                      pageLayerXPos(scene->activePageIndex()) + delta,
  1030                      pageLayerXPos(0));
  1032                      pageLayerXPos(0) + (HSBOUNDARYEFFECT / 2 / parallaxFactor()) - qreal(0.5));
  1031     
  1033 
  1032     mUiWidget->pageLayer()->setX(x);
  1034     mUiWidget->pageLayer()->setX(x);
  1033     mUiWidget->sceneLayer()->setX(parallaxFactor() * x);
  1035     mUiWidget->sceneLayer()->setX((parallaxFactor() * x) - HSBOUNDARYEFFECT / 2);
  1034 }
  1036 }
  1035 
  1037 
  1036 /*!
  1038 /*!
  1037     Handles mouse release events for the moveScene state.
  1039     Handles mouse release events for the moveScene state.
  1038     Filters events for the item \a watched. \a event is the 
  1040     Filters events for the item \a watched. \a event is the 
  1049     QSizeF pageSize = pages.first()->size();
  1051     QSizeF pageSize = pages.first()->size();
  1050 
  1052 
  1051     int pageIndex = HsScene::instance()->activePageIndex();
  1053     int pageIndex = HsScene::instance()->activePageIndex();
  1052 
  1054 
  1053     QPointF delta(
  1055     QPointF delta(
  1054         event->screenPos() - event->buttonDownScreenPos(Qt::LeftButton));
  1056         event->scenePos() - event->buttonDownScenePos(Qt::LeftButton));
  1055     if (delta.x() < -pageSize.width() / 2) {
  1057     if (delta.x() < -pageSize.width() / 3) {
  1056         pageIndex = qMin(pageIndex + 1, pages.count() - 1);
  1058         pageIndex = qMin(pageIndex + 1, pages.count() - 1);
  1057     } else if(pageSize.width() / 2 < delta.x()) {
  1059     } else if (pageSize.width() / 3 < delta.x()) {
  1058         pageIndex = qMax(pageIndex - 1, 0);
  1060         pageIndex = qMax(pageIndex - 1, 0);
  1059     }
  1061     }
  1060 
  1062 
  1061     HsScene::instance()->setActivePageIndex(pageIndex);
  1063     HsScene::instance()->setActivePageIndex(pageIndex);
  1062     
  1064     
  1072 void HsIdleState::onOrientationChanged(Qt::Orientation orientation)
  1074 void HsIdleState::onOrientationChanged(Qt::Orientation orientation)
  1073 {
  1075 {
  1074     QList<HsPage *> pages = HsScene::instance()->pages();
  1076     QList<HsPage *> pages = HsScene::instance()->pages();
  1075     QList<HsWidgetHost *> widgets;
  1077     QList<HsWidgetHost *> widgets;
  1076     HsWidgetHost *widget = 0;
  1078     HsWidgetHost *widget = 0;
       
  1079     
       
  1080     const int KChromeHeight = 64; // TODO: get this somewhere
       
  1081     const int KWidgetAdjust = 10; // TODO: get this somewhere
  1077     
  1082     
  1078     for (int i = 0; i < pages.count(); ++i) {        
  1083     for (int i = 0; i < pages.count(); ++i) {        
  1079         widgets = pages[i]->widgets();
  1084         widgets = pages[i]->widgets();
  1080         for (int j = 0; j < widgets.count(); ++j) {
  1085         for (int j = 0; j < widgets.count(); ++j) {
  1081             widget = widgets[j];
  1086             widget = widgets[j];
  1082             HsWidgetPresentationData presentation = widget->widgetPresentation(orientation);
  1087             HsWidgetPresentationData presentation = widget->widgetPresentation(orientation);
  1083             if (presentation.id() < 0) {
  1088             if (presentation.widgetId < 0) {
  1084                 QList<QRectF> geometries = 
  1089                 QList<QRectF> geometries = 
  1085                     HsWidgetPositioningOnOrientationChange::instance()->convert(
  1090                     HsWidgetPositioningOnOrientationChange::instance()->convert(
  1086                         pages[i]->rect().adjusted(10, 10, -10, -10), QList<QRectF>() << widget->geometry(),
  1091                         QRectF(0, KChromeHeight, pages[i]->rect().height(), pages[i]->rect().width()-KChromeHeight).adjusted(KWidgetAdjust, KWidgetAdjust, -KWidgetAdjust, -KWidgetAdjust),
  1087                         QRectF(0, 0, pages[i]->rect().height() + 40, 
  1092                         QList<QRectF>() << widget->geometry(),
  1088                         pages[i]->rect().width() - 40).adjusted(10, 10, -10, -10));
  1093                         QRectF(0, KChromeHeight, pages[i]->rect().width(), pages[i]->rect().height()-KChromeHeight).adjusted(KWidgetAdjust, KWidgetAdjust, -KWidgetAdjust, -KWidgetAdjust));
  1089                 widget->setGeometry(geometries.first());
  1094                 widget->setGeometry(geometries.first());
  1090                 widget->setWidgetPresentation();
  1095                 widget->setWidgetPresentation();
  1091             } else {
  1096             } else {
  1092                 widget->setGeometry(QRectF(presentation.position(), presentation.size()));
  1097                 widget->setGeometry(presentation.geometry());
  1093                 widget->setZValue(presentation.zValue());
  1098                 widget->setZValue(presentation.zValue);
  1094             }
  1099             }
  1095         }
  1100         }
  1096     }
  1101     }
  1097     
  1102     
  1098     action_idle_showActivePage();
  1103     action_idle_showActivePage();
  1136     }
  1141     }
  1137 
  1142 
  1138     if (pageIndex == scene->pages().count()) {
  1143     if (pageIndex == scene->pages().count()) {
  1139         if (scene->pages().last()->widgets().isEmpty()) {
  1144         if (scene->pages().last()->widgets().isEmpty()) {
  1140             return;
  1145             return;
  1141         } else {
  1146         } else if (scene->pages().count() < scene->maximumPageCount()) {
  1142             addPageToScene(pageIndex);
  1147             addPageToScene(pageIndex);
  1143             mUiWidget->showPageIndicator();
  1148             mUiWidget->showPageIndicator();
  1144             mUiWidget->pageIndicator()->addItem(true);
  1149             mUiWidget->pageIndicator()->addItem(pageIndex);
       
  1150         } else {
       
  1151             return; 
  1145         }
  1152         }
  1146     }
  1153     }
  1147 
  1154 
  1148     scene->setActivePageIndex(pageIndex);
  1155     scene->setActivePageIndex(pageIndex);
  1149     startPageChangeAnimation(pageIndex, 200);
  1156     startPageChangeAnimation(pageIndex, 200);
  1190 /*!
  1197 /*!
  1191     Translates the home screen ui.
  1198     Translates the home screen ui.
  1192 */
  1199 */
  1193 void HsIdleState::translateUi()
  1200 void HsIdleState::translateUi()
  1194 {
  1201 {
  1195     mView->setTitle("Home Screen"/*hbTrId(TXT_HOMESCREEN_TITLE_OFFLINE)*/);
  1202     mView->setTitle("Home Screen"/*hbTrId(gTitleOfflineTextName)*/);
  1196     action_waitInput_updateOptionsMenu();
  1203     action_waitInput_updateOptionsMenu();
  1197 }
  1204 }
  1198 #ifdef COVERAGE_MEASUREMENT
  1205 #ifdef COVERAGE_MEASUREMENT
  1199 #pragma CTC ENDSKIP
  1206 #pragma CTC ENDSKIP
  1200 #endif //COVERAGE_MEASUREMENT
  1207 #endif //COVERAGE_MEASUREMENT