homescreenapp/stateplugins/hshomescreenstateplugin/src/hsidlestate.cpp
changeset 96 458d8c8d9580
parent 92 6727c5d0afc7
equal deleted inserted replaced
92:6727c5d0afc7 96:458d8c8d9580
   226 {
   226 {
   227     // States
   227     // States
   228 
   228 
   229     QState *state_waitInput = new QState(this);
   229     QState *state_waitInput = new QState(this);
   230     setInitialState(state_waitInput);
   230     setInitialState(state_waitInput);
       
   231 
   231     QState *state_moveWidget = new QState(this);
   232     QState *state_moveWidget = new QState(this);
       
   233     QState *state_moveWidgetMoving = new QState(state_moveWidget);
       
   234     QState *state_moveWidgetDelete = new QState(state_moveWidget);
       
   235     state_moveWidget->setInitialState(state_moveWidgetMoving);
       
   236     
   232     QState *state_moveScene = new QState(this);
   237     QState *state_moveScene = new QState(this);
   233     HsWallpaperSelectionState *state_wallpaperSelectionState =
   238     HsWallpaperSelectionState *state_wallpaperSelectionState =
   234         new HsWallpaperSelectionState(this);
   239         new HsWallpaperSelectionState(this);
   235     QState *state_addPage = new QState(this);
   240     QState *state_addPage = new QState(this);
   236     QState *state_preRemovePage = new QState(this);
   241     QState *state_preRemovePage = new QState(this);
   250     state_waitInput->addTransition(
   255     state_waitInput->addTransition(
   251         this, SIGNAL(event_moveScene()), state_moveScene);
   256         this, SIGNAL(event_moveScene()), state_moveScene);
   252     state_waitInput->addTransition(
   257     state_waitInput->addTransition(
   253         this, SIGNAL(event_moveWidget()), state_moveWidget);
   258         this, SIGNAL(event_moveWidget()), state_moveWidget);
   254 
   259 
   255     state_moveWidget->addTransition(
   260     state_moveWidgetMoving->addTransition(
       
   261         this, SIGNAL(event_waitInput()), state_waitInput);
       
   262     state_moveWidgetMoving->addTransition(
       
   263         this, SIGNAL(event_MoveWidgetDelete()), state_moveWidgetDelete);
       
   264     state_moveWidgetDelete->addTransition(
   256         this, SIGNAL(event_waitInput()), state_waitInput);
   265         this, SIGNAL(event_waitInput()), state_waitInput);
   257 
   266 
   258     state_moveScene->addTransition(
   267     state_moveScene->addTransition(
   259         this, SIGNAL(event_waitInput()), state_waitInput);
   268         this, SIGNAL(event_waitInput()), state_waitInput);
   260 
   269 
   296     ENTRY_ACTION(state_moveWidget, action_moveWidget_reparentToControlLayer)
   305     ENTRY_ACTION(state_moveWidget, action_moveWidget_reparentToControlLayer)
   297     ENTRY_ACTION(state_moveWidget, action_moveWidget_startWidgetDragEffect)
   306     ENTRY_ACTION(state_moveWidget, action_moveWidget_startWidgetDragEffect)
   298     ENTRY_ACTION(state_moveWidget, action_moveWidget_connectGestureHandlers)
   307     ENTRY_ACTION(state_moveWidget, action_moveWidget_connectGestureHandlers)
   299     ENTRY_ACTION(state_moveWidget, action_moveWidget_connectOrientationChangeEventHandler)
   308     ENTRY_ACTION(state_moveWidget, action_moveWidget_connectOrientationChangeEventHandler)
   300     ENTRY_ACTION(state_moveWidget, action_moveWidget_setWidgetSnap)
   309     ENTRY_ACTION(state_moveWidget, action_moveWidget_setWidgetSnap)
   301 
       
   302     EXIT_ACTION(state_moveWidget, action_moveWidget_reparentToPage)
   310     EXIT_ACTION(state_moveWidget, action_moveWidget_reparentToPage)
   303     EXIT_ACTION(state_moveWidget, action_moveWidget_startWidgetDropEffect)
   311     EXIT_ACTION(state_moveWidget, action_moveWidget_startWidgetDropEffect)
       
   312     EXIT_ACTION(state_moveWidget, action_moveWidget_disableInteractive)
   304     EXIT_ACTION(state_moveWidget, action_moveWidget_disconnectGestureHandlers)
   313     EXIT_ACTION(state_moveWidget, action_moveWidget_disconnectGestureHandlers)
   305     EXIT_ACTION(state_moveWidget, action_moveWidget_disconnectOrientationChangeEventHandler)
   314     EXIT_ACTION(state_moveWidget, action_moveWidget_disconnectOrientationChangeEventHandler)
   306     EXIT_ACTION(state_moveWidget, action_moveWidget_preventZoneAnimation)
   315     EXIT_ACTION(state_moveWidget, action_moveWidget_preventZoneAnimation)
   307     EXIT_ACTION(state_moveWidget, action_moveWidget_deleteWidgetSnap)
   316     EXIT_ACTION(state_moveWidget, action_moveWidget_deleteWidgetSnap)
   308 
   317 
       
   318     ENTRY_ACTION(state_moveWidgetDelete, action_moveWidgetDelete_deleteWidgetOnTrashbin)
       
   319 
   309     ENTRY_ACTION(state_moveScene, action_moveScene_connectGestureHandlers)
   320     ENTRY_ACTION(state_moveScene, action_moveScene_connectGestureHandlers)
   310     EXIT_ACTION(state_moveScene, action_moveScene_moveToNearestPage)
   321     EXIT_ACTION(state_moveScene, action_moveScene_moveToNearestPage)
   311     EXIT_ACTION(state_moveScene, action_moveScene_disconnectGestureHandlers)
   322     EXIT_ACTION(state_moveScene, action_moveScene_disconnectGestureHandlers)
   312     
   323     
   313     ENTRY_ACTION(state_addPage, action_addPage_addPage)
   324     ENTRY_ACTION(state_addPage, action_addPage_addPage)
   333     Starts the page change animation based on the given \a targetPageIndex
   344     Starts the page change animation based on the given \a targetPageIndex
   334     and \a duration.
   345     and \a duration.
   335 */
   346 */
   336 void HsIdleState::startPageChangeAnimation(int targetPageIndex, int duration)
   347 void HsIdleState::startPageChangeAnimation(int targetPageIndex, int duration)
   337 {
   348 {
   338     hbInstance->allMainWindows().first()->setInteractive(false);
   349     if (!HsScene::instance()->activeWidget()) {
       
   350         hbInstance->allMainWindows().first()->setInteractive(false);
       
   351     }
   339     HsPropertyAnimationWrapper *animation = HsGui::instance()->pageChangeAnimation();
   352     HsPropertyAnimationWrapper *animation = HsGui::instance()->pageChangeAnimation();
   340     if (animation->isRunning()) {
   353     if (animation->isRunning()) {
   341         animation->stop();
   354         animation->stop();
   342     }        
   355     }        
   343     animation->disconnect(this);
   356     animation->disconnect(this);
   613 }
   626 }
   614 
   627 
   615 void HsIdleState::onWidgetTapStarted(QPointF point, HsWidgetHost *widget)
   628 void HsIdleState::onWidgetTapStarted(QPointF point, HsWidgetHost *widget)
   616 {
   629 {
   617     HsScene *scene = HsScene::instance();
   630     HsScene *scene = HsScene::instance();
   618     scene->setActiveWidget(widget);
       
   619     HsPage *page = scene->activePage();
   631     HsPage *page = scene->activePage();
   620     QMetaObject::invokeMethod(page, "updateZValues", Qt::QueuedConnection);
   632     QMetaObject::invokeMethod(page, "updateZValues", Qt::QueuedConnection);
   621     HbVkbHost::HbVkbStatus status = HbVkbHostBridge::instance()->keypadStatus();
   633     HbVkbHost::HbVkbStatus status = HbVkbHostBridge::instance()->keypadStatus();
   622     if ( status == HbVkbHost::HbVkbStatusOpened && !isEditor(point, widget) ) {
   634     if ( status == HbVkbHost::HbVkbStatusOpened && !isEditor(point, widget) ) {
   623         closeVirtualKeyboard();
   635         closeVirtualKeyboard();
   710  
   722  
   711 void HsIdleState::onWidgetMoveFinished(const QPointF &scenePos, HsWidgetHost *widget)
   723 void HsIdleState::onWidgetMoveFinished(const QPointF &scenePos, HsWidgetHost *widget)
   712 {
   724 {
   713     Q_UNUSED(scenePos)
   725     Q_UNUSED(scenePos)
   714     Q_UNUSED(widget)
   726     Q_UNUSED(widget)
   715     emit event_waitInput();
   727     emit event_MoveWidgetDelete();
   716 }
   728 }
   717 
   729 
   718 /*!
   730 /*!
   719     Lays out the active page's new widgets that were added
   731     Lays out the active page's new widgets that were added
   720     from the application library.
   732     from the application library.
   763 }
   775 }
   764 
   776 
   765 void HsIdleState::action_idle_orientationChanged()
   777 void HsIdleState::action_idle_orientationChanged()
   766 {
   778 {
   767     HsScene::instance()->activePage()->resetNewWidgets();
   779     HsScene::instance()->activePage()->resetNewWidgets();
       
   780     stopPageChangeAnimations();
   768     action_idle_showActivePage();
   781     action_idle_showActivePage();
   769 }
   782 }
   770 
   783 
   771 /*!
   784 /*!
   772     Installs the event filter.
   785     Installs the event filter.
  1039 {
  1052 {
  1040     HsPropertyAnimationWrapper *pageCrawlingAnimation =
  1053     HsPropertyAnimationWrapper *pageCrawlingAnimation =
  1041         HsGui::instance()->pageCrawlingAnimation();
  1054         HsGui::instance()->pageCrawlingAnimation();
  1042     if (pageCrawlingAnimation->isRunning()&& 
  1055     if (pageCrawlingAnimation->isRunning()&& 
  1043         pageCrawlingAnimation->isForward()) {
  1056         pageCrawlingAnimation->isForward()) {
  1044 
       
  1045         pageCrawlingAnimation->setDuration(HSCONFIGURATION_GET(pageChangeZoneReverseAnimationDuration));
  1057         pageCrawlingAnimation->setDuration(HSCONFIGURATION_GET(pageChangeZoneReverseAnimationDuration));
  1046         pageCrawlingAnimation->setBackward();
  1058         pageCrawlingAnimation->setBackward();
  1047     }
  1059     }
  1048 
  1060 
  1049     HsScene *scene = HsScene::instance();
  1061     HsScene *scene = HsScene::instance();
  1050     HsPage *page = scene->activePage();
  1062     HsPage *page = scene->activePage();
  1051     HsWidgetHost *widget = scene->activeWidget();
  1063     HsWidgetHost *widget = scene->activeWidget();
  1052 
  1064     
  1053     if (HsGui::instance()->idleWidget()->trashBin()->isUnderMouse()) {
  1065     if (widget) {
  1054         HbInstantFeedback::play(HSCONFIGURATION_GET(widgetDropToTrashbinFeedbackEffect));
       
  1055         widget->page()->removeWidget(widget);
       
  1056         widget->remove();
       
  1057         scene->setActiveWidget(0);
       
  1058     } else {
       
  1059         if (widget->page() != page) {
  1066         if (widget->page() != page) {
  1060             widget->page()->removeWidget(widget);
  1067             widget->page()->removeWidget(widget);
  1061             page->addExistingWidget(widget);
  1068             page->addExistingWidget(widget);
  1062             if (HsGui::instance()->orientation() == Qt::Horizontal) {
  1069             if (HsGui::instance()->orientation() == Qt::Horizontal) {
  1063                 widget->removePresentation(Qt::Vertical);
  1070                 widget->removePresentation(Qt::Vertical);
  1078         QPointF adjustedWidgetPosition = page->adjustedWidgetPosition(widgetRect);
  1085         QPointF adjustedWidgetPosition = page->adjustedWidgetPosition(widgetRect);
  1079         widget->visual()->setPos(adjustedWidgetPosition);
  1086         widget->visual()->setPos(adjustedWidgetPosition);
  1080 
  1087 
  1081         widget->savePresentation();
  1088         widget->savePresentation();
  1082         page->updateZValues();
  1089         page->updateZValues();
  1083     }
  1090 
  1084 
  1091         widget->visual()->setParentItem(HsScene::instance()->activePage()->visual());
  1085     widget->visual()->setParentItem(HsScene::instance()->activePage()->visual());
  1092     }
  1086 
       
  1087     HsGui::instance()->idleWidget()->showPageIndicator();
  1093     HsGui::instance()->idleWidget()->showPageIndicator();
       
  1094     
       
  1095     emit event_waitInput();
       
  1096 }
       
  1097 
       
  1098 
       
  1099 /*!
       
  1100     Reparents the active widget to the active page.
       
  1101 */
       
  1102 void HsIdleState::action_moveWidgetDelete_deleteWidgetOnTrashbin()
       
  1103 {
       
  1104     HsScene *scene = HsScene::instance();
       
  1105     HsWidgetHost *widget = scene->activeWidget();
       
  1106 
       
  1107     if ( widget && HsGui::instance()->idleWidget()->trashBin()->isUnderMouse() ) {
       
  1108         HbInstantFeedback::play(HSCONFIGURATION_GET(widgetDropToTrashbinFeedbackEffect));
       
  1109         widget->page()->removeWidget(widget);
       
  1110         widget->remove();
       
  1111         scene->setActiveWidget(0);
       
  1112     }
       
  1113     emit event_waitInput();
  1088 }
  1114 }
  1089 
  1115 
  1090 /*!
  1116 /*!
  1091     Starts the widget drop effect.
  1117     Starts the widget drop effect.
  1092 */
  1118 */
  1093 void HsIdleState::action_moveWidget_startWidgetDropEffect()
  1119 void HsIdleState::action_moveWidget_startWidgetDropEffect()
  1094 {
  1120 {
  1095     HsWidgetHost *widget = HsScene::instance()->activeWidget();
  1121     HsWidgetHost *widget = HsScene::instance()->activeWidget();
  1096     if (widget) {
  1122     if (widget) {
  1097         widget->startDropEffect();
  1123         widget->startDropEffect();
       
  1124     }
       
  1125 }
       
  1126 
       
  1127 /*!
       
  1128     Set interactive to false.
       
  1129 */
       
  1130 void HsIdleState::action_moveWidget_disableInteractive()
       
  1131 {
       
  1132     HsWidgetHost *widget = HsScene::instance()->activeWidget();
       
  1133     if (widget) {
       
  1134         HsPropertyAnimationWrapper *animation = HsGui::instance()->pageChangeAnimation();
       
  1135         if (animation->isRunning()) {
       
  1136             hbInstance->allMainWindows().first()->setInteractive(false);
       
  1137         }
       
  1138         HsScene::instance()->setActiveWidget(0);
  1098     }
  1139     }
  1099 }
  1140 }
  1100 
  1141 
  1101 /*!
  1142 /*!
  1102     Disconnects gesture handlers
  1143     Disconnects gesture handlers
  1510                 qobject_cast<QGraphicsWidget *>(widget->visual()->widget())->isAncestorOf(item);
  1551                 qobject_cast<QGraphicsWidget *>(widget->visual()->widget())->isAncestorOf(item);
  1511         }
  1552         }
  1512     }
  1553     }
  1513     return isWidgetEditor;
  1554     return isWidgetEditor;
  1514 }
  1555 }
       
  1556 
       
  1557 /*!
       
  1558     Stops page change and page crawling animations.
       
  1559 */
       
  1560 void HsIdleState::stopPageChangeAnimations()
       
  1561 {
       
  1562     HsPropertyAnimationWrapper *animation = HsGui::instance()->pageChangeAnimation();
       
  1563     if (animation->isRunning()) {
       
  1564         animation->stop();
       
  1565         hbInstance->allMainWindows().first()->setInteractive(true);
       
  1566     }        
       
  1567     animation->disconnect(this);
       
  1568     
       
  1569     HsPropertyAnimationWrapper *pageCrawlingAnimation = 
       
  1570         HsGui::instance()->pageCrawlingAnimation();
       
  1571 
       
  1572     if (pageCrawlingAnimation->isRunning()) {
       
  1573         pageCrawlingAnimation->stop();
       
  1574     }
       
  1575 }
       
  1576