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 |
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 |
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 |
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"), |
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 */ |
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())); |
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 |
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(); |