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. |
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. |
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 */ |
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() |
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 */ |
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 |
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. |
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 |