|
1 /* |
|
2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * |
|
16 */ |
|
17 |
|
18 #include <QStateMachine> |
|
19 #include <QGraphicsSceneMouseEvent> |
|
20 #include <QGraphicsLinearLayout> |
|
21 #include <QParallelAnimationGroup> |
|
22 #include <QPropertyAnimation> |
|
23 #include <QApplication> |
|
24 #include <QDir> |
|
25 |
|
26 #include <HbMainWindow> |
|
27 #include <HbView> |
|
28 #include <HbMenu> |
|
29 #include <HbAction> |
|
30 #include <HbIcon> |
|
31 |
|
32 #include "hsidlestate.h" |
|
33 #include "hsidlewidget.h" |
|
34 #include "hsscene.h" |
|
35 #include "hspage.h" |
|
36 #include "hswidgethost.h" |
|
37 #include "hswallpaper.h" |
|
38 #include "hspagedata.h" |
|
39 #include "hsselectbackgroundstate.h" |
|
40 #include "hstrashbinwidget.h" |
|
41 #include "hspageindicator.h" |
|
42 #include "hsapptranslator.h" |
|
43 #include "hswidgetpositioningonorientationchange.h" |
|
44 #include "hsmenueventfactory.h" |
|
45 |
|
46 // Helper macros for connecting state entry and exit actions. |
|
47 #define ENTRY_ACTION(state, action) \ |
|
48 connect(state, SIGNAL(entered()), SLOT(action())); |
|
49 #define EXIT_ACTION(state, action) \ |
|
50 connect(state, SIGNAL(exited()), SLOT(action())); |
|
51 |
|
52 // Helper macros for connecting and disconnecting mouse event handlers. |
|
53 #define CONNECT_MOUSE_EVENT_HANDLER(signal, slot) \ |
|
54 connect(mUiWidget, SIGNAL(signal(QGraphicsItem*, QGraphicsSceneMouseEvent*, bool&)), \ |
|
55 SLOT(slot(QGraphicsItem*, QGraphicsSceneMouseEvent*, bool&))); |
|
56 #define DISCONNECT_MOUSE_EVENT_HANDLER(signal, slot) \ |
|
57 disconnect(mUiWidget, SIGNAL(signal(QGraphicsItem*, QGraphicsSceneMouseEvent*, bool&)), \ |
|
58 this, SLOT(slot(QGraphicsItem*, QGraphicsSceneMouseEvent*, bool&))); |
|
59 |
|
60 |
|
61 namespace |
|
62 { |
|
63 const char APP_LIB_BUTTON[] = |
|
64 "hs_applib_button.png"; |
|
65 /*const char TXT_HOMESCREEN_TITLE_OFFLINE[] = |
|
66 "txt_homescreen_title_offline";*/ |
|
67 const char TXT_HOMESCREEN_OPT_ADD_PAGE[] = |
|
68 "txt_homescreen_opt_add_page"; |
|
69 const char TXT_HOMESCREEN_OPT_REMOVE_PAGE[] = |
|
70 "txt_homescreen_opt_remove_page"; |
|
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 } |
|
80 |
|
81 /*! |
|
82 \class HsIdleState |
|
83 \ingroup group_hshomescreenstateplugin |
|
84 \brief Controller part of the home screen idle state. |
|
85 |
|
86 Controls the home screen idle state execution. See the |
|
87 state chart below for the state structure. |
|
88 |
|
89 \image html hsidlestate_statechart.png |
|
90 */ |
|
91 |
|
92 /*! |
|
93 Constructs a new idle state with the given \a parent. |
|
94 */ |
|
95 HsIdleState::HsIdleState(QState *parent) |
|
96 : QState(parent), |
|
97 mView(0), mSoftKeyAction(0), mUiWidget(0), |
|
98 mTapAndHoldDistance(16), |
|
99 mPageChangeZoneWidth(60) |
|
100 { |
|
101 setupStates(); |
|
102 mTimer.setSingleShot(true); |
|
103 } |
|
104 |
|
105 /*! |
|
106 Destroys this idle state. |
|
107 */ |
|
108 HsIdleState::~HsIdleState() |
|
109 { |
|
110 } |
|
111 |
|
112 /*! |
|
113 \fn HsIdleState::event_applicationLibrary() |
|
114 |
|
115 This signal initiates a transition to application library. |
|
116 */ |
|
117 |
|
118 /*! |
|
119 \fn HsIdleState::event_waitInput() |
|
120 |
|
121 This signal initiates a transition to the waitInput state. |
|
122 */ |
|
123 |
|
124 /*! |
|
125 \fn HsIdleState::event_widgetInteraction() |
|
126 |
|
127 This signal initiates a transition to the widgetInteraction state. |
|
128 */ |
|
129 |
|
130 /*! |
|
131 \fn HsIdleState::event_sceneInteraction() |
|
132 |
|
133 This signal initiates a transition to the sceneInteraction state. |
|
134 */ |
|
135 |
|
136 /*! |
|
137 \fn HsIdleState::event_moveWidget() |
|
138 |
|
139 This signal initiates a transition to the moveWidget state. |
|
140 */ |
|
141 |
|
142 /*! |
|
143 \fn HsIdleState::event_moveScene() |
|
144 |
|
145 This signal initiates a transition to the moveScene state. |
|
146 */ |
|
147 |
|
148 /*! |
|
149 \fn HsIdleState::event_sceneMenu() |
|
150 |
|
151 This signal initiates a transition to the sceneMenu state. |
|
152 */ |
|
153 |
|
154 /*! |
|
155 \fn HsIdleState::event_selectSceneWallpaper() |
|
156 |
|
157 This signal initiates a transition to the selectSceneWallpaper state. |
|
158 */ |
|
159 |
|
160 /*! |
|
161 \fn HsIdleState::event_addPage() |
|
162 |
|
163 This signal initiates a transition to the addPage state. |
|
164 */ |
|
165 |
|
166 /*! |
|
167 \fn HsIdleState::event_removePage() |
|
168 |
|
169 This signal initiates a transition to the removePage state. |
|
170 */ |
|
171 |
|
172 /*! |
|
173 \fn HsIdleState::event_toggleConnection() |
|
174 |
|
175 This signal initiates a transition to the toggleConnection state. |
|
176 */ |
|
177 |
|
178 /*! |
|
179 Creates the internal state structure and connects |
|
180 state entry and exit actions. |
|
181 */ |
|
182 void HsIdleState::setupStates() |
|
183 { |
|
184 // States |
|
185 |
|
186 QState *state_waitInput = new QState(this); |
|
187 setInitialState(state_waitInput); |
|
188 QState *state_widgetInteraction = new QState(this); |
|
189 QState *state_sceneInteraction = new QState(this); |
|
190 QState *state_moveWidget = new QState(this); |
|
191 QState *state_moveScene = new QState(this); |
|
192 QState *state_sceneMenu = new QState(this); |
|
193 HsSelectBackgroundState *state_selectSceneWallpaper = |
|
194 new HsSelectBackgroundState(this); |
|
195 QState *state_addPage = new QState(this); |
|
196 QState *state_removePage = new QState(this); |
|
197 QState *state_toggleConnection = new QState(this); |
|
198 |
|
199 // Transitions |
|
200 |
|
201 state_waitInput->addTransition( |
|
202 this, SIGNAL(event_widgetInteraction()), state_widgetInteraction); |
|
203 state_waitInput->addTransition( |
|
204 this, SIGNAL(event_sceneInteraction()), state_sceneInteraction); |
|
205 state_waitInput->addTransition( |
|
206 this, SIGNAL(event_addPage()), state_addPage); |
|
207 state_waitInput->addTransition( |
|
208 this, SIGNAL(event_removePage()), state_removePage); |
|
209 state_waitInput->addTransition( |
|
210 this, SIGNAL(event_toggleConnection()), state_toggleConnection); |
|
211 |
|
212 state_widgetInteraction->addTransition( |
|
213 this, SIGNAL(event_waitInput()), state_waitInput); |
|
214 state_widgetInteraction->addTransition( |
|
215 this, SIGNAL(event_moveWidget()), state_moveWidget); |
|
216 |
|
217 state_sceneInteraction->addTransition( |
|
218 this, SIGNAL(event_waitInput()), state_waitInput); |
|
219 state_sceneInteraction->addTransition( |
|
220 this, SIGNAL(event_moveScene()), state_moveScene); |
|
221 state_sceneInteraction->addTransition( |
|
222 this, SIGNAL(event_sceneMenu()), state_sceneMenu); |
|
223 |
|
224 state_moveWidget->addTransition( |
|
225 this, SIGNAL(event_waitInput()), state_waitInput); |
|
226 |
|
227 state_moveScene->addTransition( |
|
228 this, SIGNAL(event_waitInput()), state_waitInput); |
|
229 |
|
230 state_sceneMenu->addTransition( |
|
231 this, SIGNAL(event_waitInput()), state_waitInput); |
|
232 state_sceneMenu->addTransition( |
|
233 this, SIGNAL(event_selectSceneWallpaper()), state_selectSceneWallpaper); |
|
234 |
|
235 state_selectSceneWallpaper->addTransition( |
|
236 state_selectSceneWallpaper, SIGNAL(event_waitInput()), state_waitInput); |
|
237 |
|
238 state_addPage->addTransition(state_waitInput); |
|
239 |
|
240 state_removePage->addTransition(state_waitInput); |
|
241 |
|
242 state_toggleConnection->addTransition(state_waitInput); |
|
243 |
|
244 // Actions |
|
245 |
|
246 ENTRY_ACTION(this, action_idle_setupView) |
|
247 ENTRY_ACTION(this, action_idle_layoutNewWidgets) |
|
248 ENTRY_ACTION(this, action_idle_showActivePage) |
|
249 ENTRY_ACTION(this, action_idle_connectOrientationChangeEventHandler) |
|
250 EXIT_ACTION(this, action_idle_cleanupView) |
|
251 EXIT_ACTION(this, action_idle_disconnectOrientationChangeEventHandler) |
|
252 |
|
253 ENTRY_ACTION(state_waitInput, action_waitInput_updateOptionsMenu) |
|
254 ENTRY_ACTION(state_waitInput, action_waitInput_connectMouseEventHandlers) |
|
255 EXIT_ACTION(state_waitInput, action_waitInput_disconnectMouseEventHandlers) |
|
256 |
|
257 ENTRY_ACTION(state_widgetInteraction, action_widgetInteraction_connectMouseEventHandlers) |
|
258 ENTRY_ACTION(state_widgetInteraction, action_widgetInteraction_connectGestureTimers) |
|
259 EXIT_ACTION(state_widgetInteraction, action_widgetInteraction_disconnectMouseEventHandlers) |
|
260 EXIT_ACTION(state_widgetInteraction, action_widgetInteraction_disconnectGestureTimers) |
|
261 |
|
262 ENTRY_ACTION(state_sceneInteraction, action_sceneInteraction_connectMouseEventHandlers) |
|
263 ENTRY_ACTION(state_sceneInteraction, action_sceneInteraction_connectGestureTimers) |
|
264 EXIT_ACTION(state_sceneInteraction, action_sceneInteraction_disconnectMouseEventHandlers) |
|
265 EXIT_ACTION(state_sceneInteraction, action_sceneInteraction_disconnectGestureTimers) |
|
266 |
|
267 ENTRY_ACTION(state_moveWidget, action_moveWidget_reparentToControlLayer) |
|
268 ENTRY_ACTION(state_moveWidget, action_moveWidget_startWidgetDragAnimation) |
|
269 ENTRY_ACTION(state_moveWidget, action_moveWidget_connectMouseEventHandlers) |
|
270 ENTRY_ACTION(state_moveWidget, action_moveWidget_connectGestureTimers) |
|
271 EXIT_ACTION(state_moveWidget, action_moveWidget_reparentToPage) |
|
272 EXIT_ACTION(state_moveWidget, action_moveWidget_startWidgetDropAnimation) |
|
273 EXIT_ACTION(state_moveWidget, action_moveWidget_disconnectMouseEventHandlers) |
|
274 EXIT_ACTION(state_moveWidget, action_moveWidget_disconnectGestureTimers) |
|
275 |
|
276 ENTRY_ACTION(state_moveScene, action_moveScene_connectMouseEventHandlers) |
|
277 EXIT_ACTION(state_moveScene, action_moveScene_disconnectMouseEventHandlers) |
|
278 |
|
279 ENTRY_ACTION(state_sceneMenu, action_sceneMenu_showMenu) |
|
280 |
|
281 ENTRY_ACTION(state_addPage, action_disableUserInteraction) |
|
282 ENTRY_ACTION(state_addPage, action_addPage_addPage) |
|
283 EXIT_ACTION(state_addPage, action_enableUserInteraction) |
|
284 |
|
285 ENTRY_ACTION(state_removePage, action_disableUserInteraction) |
|
286 ENTRY_ACTION(state_removePage, action_removePage_removePage) |
|
287 EXIT_ACTION(state_removePage, action_enableUserInteraction) |
|
288 |
|
289 ENTRY_ACTION(state_toggleConnection, action_disableUserInteraction) |
|
290 ENTRY_ACTION(state_toggleConnection, action_toggleConnection_toggleConnection) |
|
291 EXIT_ACTION(state_toggleConnection, action_enableUserInteraction) |
|
292 } |
|
293 |
|
294 /*! |
|
295 Computes the page layer x position based on the given \a pageIndex. |
|
296 */ |
|
297 qreal HsIdleState::pageLayerXPos(int pageIndex) const |
|
298 { |
|
299 return -pageIndex * HsScene::mainWindow()->layoutRect().width() - 0.5; |
|
300 } |
|
301 |
|
302 /*! |
|
303 Starts the page change animation based on the given \a targetPageIndex |
|
304 and \a duration. |
|
305 */ |
|
306 void HsIdleState::startPageChangeAnimation(int targetPageIndex, int duration) |
|
307 { |
|
308 QParallelAnimationGroup *animationGroup = new QParallelAnimationGroup; |
|
309 |
|
310 QPropertyAnimation *animation = new QPropertyAnimation(mUiWidget->pageLayer(), "x"); |
|
311 animation->setEndValue(pageLayerXPos(targetPageIndex)); |
|
312 animation->setDuration(duration); |
|
313 animationGroup->addAnimation(animation); |
|
314 |
|
315 animation = new QPropertyAnimation(mUiWidget->sceneLayer(), "x"); |
|
316 animation->setEndValue(parallaxFactor() * pageLayerXPos(targetPageIndex)); |
|
317 animation->setDuration(duration); |
|
318 animationGroup->addAnimation(animation); |
|
319 |
|
320 animationGroup->start(QAbstractAnimation::DeleteWhenStopped); |
|
321 |
|
322 mUiWidget->showPageIndicator(); |
|
323 mUiWidget->setActivePage(targetPageIndex); |
|
324 } |
|
325 |
|
326 /*! |
|
327 Checks if the active widget is located inside the left or right |
|
328 page change zone. |
|
329 */ |
|
330 bool HsIdleState::isInPageChangeZone() |
|
331 { |
|
332 qreal widgetXPos = HsScene::instance()->activeWidget()->geometry().center().x(); |
|
333 qreal pageWidth = HsScene::mainWindow()->layoutRect().width(); |
|
334 return widgetXPos < mPageChangeZoneWidth || |
|
335 pageWidth - mPageChangeZoneWidth < widgetXPos; |
|
336 } |
|
337 |
|
338 /*! |
|
339 Checks if the active widget is located inside the left |
|
340 page change zone. |
|
341 */ |
|
342 bool HsIdleState::isInLeftPageChangeZone() |
|
343 { |
|
344 qreal widgetXPos = HsScene::instance()->activeWidget()->geometry().center().x(); |
|
345 return widgetXPos < mPageChangeZoneWidth; |
|
346 } |
|
347 |
|
348 /*! |
|
349 Checks if the active widget is located inside the right |
|
350 page change zone. |
|
351 */ |
|
352 bool HsIdleState::isInRightPageChangeZone() |
|
353 { |
|
354 qreal widgetXPos = HsScene::instance()->activeWidget()->geometry().center().x(); |
|
355 qreal pageWidth = HsScene::mainWindow()->layoutRect().width(); |
|
356 return pageWidth - mPageChangeZoneWidth < widgetXPos; |
|
357 } |
|
358 |
|
359 /*! |
|
360 Inserts new page at index position \a pageIndex in the scene. |
|
361 */ |
|
362 void HsIdleState::addPageToScene(int pageIndex) |
|
363 { |
|
364 HsPageData data; |
|
365 data.setIndex(pageIndex); |
|
366 HsPage *page = HsPage::createInstance(data); |
|
367 page->load(); |
|
368 HsScene::instance()->addPage(page); |
|
369 mUiWidget->insertPage(pageIndex, page); |
|
370 } |
|
371 |
|
372 /*! |
|
373 Computes the parallax factor based on the current scene and |
|
374 page layer widths, and page count. |
|
375 */ |
|
376 qreal HsIdleState::parallaxFactor() const |
|
377 { |
|
378 qreal clw = mUiWidget->controlLayer()->size().width(); |
|
379 qreal slw = mUiWidget->sceneLayer()->size().width(); |
|
380 int n = HsScene::instance()->pages().count(); |
|
381 if (n < 2) { |
|
382 return 1; |
|
383 } else { |
|
384 return (slw - clw) / ((n - 1) * clw); |
|
385 } |
|
386 } |
|
387 |
|
388 /*! |
|
389 Disables the main window user interaction. |
|
390 */ |
|
391 void HsIdleState::action_disableUserInteraction() |
|
392 { |
|
393 HsScene::mainWindow()->setInteractive(false); |
|
394 } |
|
395 |
|
396 /*! |
|
397 Enables the main window user interaction. |
|
398 */ |
|
399 void HsIdleState::action_enableUserInteraction() |
|
400 { |
|
401 HsScene::mainWindow()->setInteractive(true); |
|
402 } |
|
403 |
|
404 /*! |
|
405 If called for the first time, setups the idle view. |
|
406 Updates the soft key action and sets the idle view |
|
407 as the current view to the main window. |
|
408 */ |
|
409 void HsIdleState::action_idle_setupView() |
|
410 { |
|
411 if (!mView) { |
|
412 mUiWidget = new HsIdleWidget; |
|
413 mView = HsScene::mainWindow()->addView(mUiWidget); |
|
414 mView->setContentFullScreen(); |
|
415 mView->setTitle("Home Screen"/*hbTrId(TXT_HOMESCREEN_TITLE_OFFLINE)*/); |
|
416 |
|
417 mSoftKeyAction = new HbAction(this); |
|
418 mSoftKeyAction->setIcon(HbIcon(APP_LIB_BUTTON)); |
|
419 connect(mSoftKeyAction, SIGNAL(triggered()), SIGNAL(event_applicationLibrary())); |
|
420 |
|
421 #ifndef Q_OS_SYMBIAN |
|
422 connect(HsAppTranslator::instance(), |
|
423 SIGNAL(languageChanged()), SLOT(translateUi())); |
|
424 #endif |
|
425 // TODO: Workaround to Qt/Hb layouting bugs. |
|
426 QApplication::processEvents(QEventLoop::ExcludeUserInputEvents); |
|
427 } |
|
428 |
|
429 HsScene::mainWindow()->addSoftKeyAction(Hb::SecondarySoftKey, mSoftKeyAction); |
|
430 HsScene::mainWindow()->setCurrentView(mView); |
|
431 } |
|
432 |
|
433 /*! |
|
434 Lays out the active page's new widgets that were added |
|
435 from the application library. |
|
436 */ |
|
437 void HsIdleState::action_idle_layoutNewWidgets() |
|
438 { |
|
439 HsPage *page = HsScene::instance()->activePage(); |
|
440 if (!page) { |
|
441 return; |
|
442 } |
|
443 |
|
444 QList<HsWidgetHost *> widgets = page->newWidgets(); |
|
445 if (widgets.isEmpty()) { |
|
446 return; |
|
447 } |
|
448 |
|
449 foreach (HsWidgetHost *widget, widgets) { |
|
450 widget->initializeWidget(); |
|
451 widget->showWidget(); |
|
452 } |
|
453 |
|
454 page->layoutNewWidgets(); |
|
455 page->resetNewWidgets(); |
|
456 } |
|
457 |
|
458 /*! |
|
459 Moves the scene and page layers so that the active |
|
460 page is shown. |
|
461 */ |
|
462 void HsIdleState::action_idle_showActivePage() |
|
463 { |
|
464 qreal x = pageLayerXPos(HsScene::instance()->activePageIndex()); |
|
465 mUiWidget->pageLayer()->setX(x); |
|
466 mUiWidget->sceneLayer()->setX(parallaxFactor() * x); |
|
467 } |
|
468 |
|
469 /*! |
|
470 Connects the orientation change event handler. |
|
471 */ |
|
472 void HsIdleState::action_idle_connectOrientationChangeEventHandler() |
|
473 { |
|
474 connect(HsScene::mainWindow(), |
|
475 SIGNAL(orientationChanged(Qt::Orientation)), |
|
476 SLOT(onOrientationChanged(Qt::Orientation))); |
|
477 } |
|
478 |
|
479 /*! |
|
480 Cleans up the idle view. |
|
481 */ |
|
482 void HsIdleState::action_idle_cleanupView() |
|
483 { |
|
484 HsScene::mainWindow()->removeSoftKeyAction( |
|
485 Hb::SecondarySoftKey, mSoftKeyAction); |
|
486 } |
|
487 |
|
488 /*! |
|
489 Disconnects the orientation change event handler. |
|
490 */ |
|
491 void HsIdleState::action_idle_disconnectOrientationChangeEventHandler() |
|
492 { |
|
493 disconnect(HsScene::mainWindow(), |
|
494 SIGNAL(orientationChanged(Qt::Orientation)), |
|
495 this, SLOT(onOrientationChanged(Qt::Orientation))); |
|
496 } |
|
497 |
|
498 /*! |
|
499 Updates the options menu content. |
|
500 */ |
|
501 void HsIdleState::action_waitInput_updateOptionsMenu() |
|
502 { |
|
503 HbMenu *menu = new HbMenu(); |
|
504 |
|
505 menu->addAction(hbTrId(TXT_HOMESCREEN_OPT_ADD_PAGE), |
|
506 this, SIGNAL(event_addPage())); |
|
507 menu->addAction(hbTrId(TXT_HOMESCREEN_OPT_REMOVE_PAGE), |
|
508 this, SIGNAL(event_removePage()))->setEnabled( |
|
509 HsScene::instance()->activePage()->isRemovable()); |
|
510 |
|
511 if (HsScene::instance()->isOnline()) { |
|
512 menu->addAction(hbTrId(TXT_HOMESCREEN_OPT_HOME_SCREEN_TO_OFFLINE), |
|
513 this, SIGNAL(event_toggleConnection())); |
|
514 } else { |
|
515 menu->addAction(hbTrId(TXT_HOMESCREEN_OPT_HOME_SCREEN_TO_ONLINE), |
|
516 this, SIGNAL(event_toggleConnection())); |
|
517 } |
|
518 |
|
519 #ifndef Q_OS_SYMBIAN |
|
520 menu->addAction(hbTrId("txt_homescreen_opt_switch_language"), |
|
521 this, SLOT(switchLanguage())); |
|
522 #endif |
|
523 |
|
524 mView->setMenu(menu); |
|
525 } |
|
526 |
|
527 /*! |
|
528 Connects the waitInput state's mouse event handlers. |
|
529 */ |
|
530 void HsIdleState::action_waitInput_connectMouseEventHandlers() |
|
531 { |
|
532 CONNECT_MOUSE_EVENT_HANDLER(mousePressed, waitInput_onMousePressed) |
|
533 } |
|
534 |
|
535 /*! |
|
536 Disconnects the waitInput state's mouse event handlers. |
|
537 */ |
|
538 void HsIdleState::action_waitInput_disconnectMouseEventHandlers() |
|
539 { |
|
540 DISCONNECT_MOUSE_EVENT_HANDLER(mousePressed, waitInput_onMousePressed) |
|
541 } |
|
542 |
|
543 /*! |
|
544 Connects the widgetInteraction state's mouse event handlers. |
|
545 */ |
|
546 void HsIdleState::action_widgetInteraction_connectMouseEventHandlers() |
|
547 { |
|
548 CONNECT_MOUSE_EVENT_HANDLER(mouseMoved, widgetInteraction_onMouseMoved) |
|
549 CONNECT_MOUSE_EVENT_HANDLER(mouseReleased, widgetInteraction_onMouseReleased) |
|
550 } |
|
551 |
|
552 /*! |
|
553 Connects the widgetInteraction state's gesture timers. |
|
554 */ |
|
555 void HsIdleState::action_widgetInteraction_connectGestureTimers() |
|
556 { |
|
557 mTimer.setInterval(500); |
|
558 connect(&mTimer, SIGNAL(timeout()), |
|
559 SLOT(widgetInteraction_onTapAndHoldTimeout())); |
|
560 mTimer.start(); |
|
561 } |
|
562 |
|
563 /*! |
|
564 Disconnects the widgetInteraction state's mouse event handlers. |
|
565 */ |
|
566 void HsIdleState::action_widgetInteraction_disconnectMouseEventHandlers() |
|
567 { |
|
568 DISCONNECT_MOUSE_EVENT_HANDLER(mouseMoved, widgetInteraction_onMouseMoved) |
|
569 DISCONNECT_MOUSE_EVENT_HANDLER(mouseReleased, widgetInteraction_onMouseReleased) |
|
570 } |
|
571 |
|
572 /*! |
|
573 Disconnects the widgetInteraction state's gesture timers. |
|
574 */ |
|
575 void HsIdleState::action_widgetInteraction_disconnectGestureTimers() |
|
576 { |
|
577 disconnect(&mTimer, SIGNAL(timeout()), |
|
578 this, SLOT(widgetInteraction_onTapAndHoldTimeout())); |
|
579 } |
|
580 |
|
581 /*! |
|
582 Connects the sceneInteraction state's mouse event handlers. |
|
583 */ |
|
584 void HsIdleState::action_sceneInteraction_connectMouseEventHandlers() |
|
585 { |
|
586 CONNECT_MOUSE_EVENT_HANDLER(mouseMoved, sceneInteraction_onMouseMoved) |
|
587 CONNECT_MOUSE_EVENT_HANDLER(mouseReleased, sceneInteraction_onMouseReleased) |
|
588 } |
|
589 |
|
590 /*! |
|
591 Connects the sceneInteraction state's gesture timers. |
|
592 */ |
|
593 void HsIdleState::action_sceneInteraction_connectGestureTimers() |
|
594 { |
|
595 mTimer.setInterval(500); |
|
596 connect(&mTimer, SIGNAL(timeout()), |
|
597 SLOT(sceneInteraction_onTapAndHoldTimeout())); |
|
598 mTimer.start(); |
|
599 } |
|
600 |
|
601 /*! |
|
602 Disconnects the sceneInteraction state's mouse event handlers. |
|
603 */ |
|
604 void HsIdleState::action_sceneInteraction_disconnectMouseEventHandlers() |
|
605 { |
|
606 DISCONNECT_MOUSE_EVENT_HANDLER(mouseMoved, sceneInteraction_onMouseMoved) |
|
607 DISCONNECT_MOUSE_EVENT_HANDLER(mouseReleased, sceneInteraction_onMouseReleased) |
|
608 } |
|
609 |
|
610 /*! |
|
611 Disconnects the sceneInteraction state's gesture timers. |
|
612 */ |
|
613 void HsIdleState::action_sceneInteraction_disconnectGestureTimers() |
|
614 { |
|
615 disconnect(&mTimer, SIGNAL(timeout()), |
|
616 this, SLOT(sceneInteraction_onTapAndHoldTimeout())); |
|
617 } |
|
618 |
|
619 /*! |
|
620 Reparents the active widget to the control layer. |
|
621 */ |
|
622 void HsIdleState::action_moveWidget_reparentToControlLayer() |
|
623 { |
|
624 HsWidgetHost *widget = HsScene::instance()->activeWidget(); |
|
625 Q_ASSERT(widget); |
|
626 widget->setParentItem(mUiWidget->controlLayer()); |
|
627 |
|
628 mUiWidget->showTrashBin(); |
|
629 } |
|
630 |
|
631 /*! |
|
632 Starts the widget drag animation for the active widget. |
|
633 */ |
|
634 void HsIdleState::action_moveWidget_startWidgetDragAnimation() |
|
635 { |
|
636 HsWidgetHost *widget = HsScene::instance()->activeWidget(); |
|
637 Q_ASSERT(widget); |
|
638 widget->startDragAnimation(); |
|
639 } |
|
640 |
|
641 /*! |
|
642 Connects the moveWidget state's mouse event handlers. |
|
643 */ |
|
644 void HsIdleState::action_moveWidget_connectMouseEventHandlers() |
|
645 { |
|
646 CONNECT_MOUSE_EVENT_HANDLER(mouseMoved, moveWidget_onMouseMoved) |
|
647 CONNECT_MOUSE_EVENT_HANDLER(mouseReleased, moveWidget_onMouseReleased) |
|
648 } |
|
649 |
|
650 /*! |
|
651 Connects the moveWidget state's gesture timers. |
|
652 */ |
|
653 void HsIdleState::action_moveWidget_connectGestureTimers() |
|
654 { |
|
655 mTimer.setInterval(800); |
|
656 connect(&mTimer, SIGNAL(timeout()), |
|
657 SLOT(moveWidget_onHoldTimeout())); |
|
658 } |
|
659 |
|
660 /*! |
|
661 Reparents the active widget to the active page. |
|
662 */ |
|
663 void HsIdleState::action_moveWidget_reparentToPage() |
|
664 { |
|
665 HsWidgetHost *widget = HsScene::instance()->activeWidget(); |
|
666 if (widget) { |
|
667 widget->setParentItem(HsScene::instance()->activePage()); |
|
668 } |
|
669 |
|
670 mUiWidget->showPageIndicator(); |
|
671 } |
|
672 |
|
673 /*! |
|
674 Starts the widget drop animation for the active widget. |
|
675 */ |
|
676 void HsIdleState::action_moveWidget_startWidgetDropAnimation() |
|
677 { |
|
678 HsWidgetHost *widget = HsScene::instance()->activeWidget(); |
|
679 if (widget) { |
|
680 widget->startDropAnimation(); |
|
681 } |
|
682 } |
|
683 |
|
684 /*! |
|
685 Disconnects the moveWidget state's mouse event handlers. |
|
686 */ |
|
687 void HsIdleState::action_moveWidget_disconnectMouseEventHandlers() |
|
688 { |
|
689 DISCONNECT_MOUSE_EVENT_HANDLER(mouseMoved, moveWidget_onMouseMoved) |
|
690 DISCONNECT_MOUSE_EVENT_HANDLER(mouseReleased, moveWidget_onMouseReleased) |
|
691 } |
|
692 |
|
693 /*! |
|
694 Disconnects the moveWidget state's gesture timers. |
|
695 */ |
|
696 void HsIdleState::action_moveWidget_disconnectGestureTimers() |
|
697 { |
|
698 disconnect(&mTimer, SIGNAL(timeout()), |
|
699 this, SLOT(moveWidget_onHoldTimeout())); |
|
700 } |
|
701 |
|
702 /*! |
|
703 Connects the moveScene state's mouse event handlers. |
|
704 */ |
|
705 void HsIdleState::action_moveScene_connectMouseEventHandlers() |
|
706 { |
|
707 CONNECT_MOUSE_EVENT_HANDLER(mouseMoved, moveScene_onMouseMoved) |
|
708 CONNECT_MOUSE_EVENT_HANDLER(mouseReleased, moveScene_onMouseReleased) |
|
709 } |
|
710 |
|
711 /*! |
|
712 Disconnects the moveScene state's mouse event handlers. |
|
713 */ |
|
714 void HsIdleState::action_moveScene_disconnectMouseEventHandlers() |
|
715 { |
|
716 DISCONNECT_MOUSE_EVENT_HANDLER(mouseMoved, moveScene_onMouseMoved) |
|
717 DISCONNECT_MOUSE_EVENT_HANDLER(mouseReleased, moveScene_onMouseReleased) |
|
718 } |
|
719 |
|
720 #ifdef COVERAGE_MEASUREMENT |
|
721 #pragma CTC SKIP |
|
722 #endif //COVERAGE_MEASUREMENT |
|
723 /*! |
|
724 Shows the scene menu. |
|
725 */ |
|
726 void HsIdleState::action_sceneMenu_showMenu() |
|
727 { |
|
728 HbMenu menu; |
|
729 |
|
730 HbAction *changeWallpaperAction = |
|
731 menu.addAction(hbTrId(TXT_HOMESCREEN_LIST_CHANGE_WALLPAPER)); |
|
732 HbAction *addContentAction = |
|
733 menu.addAction(hbTrId(TXT_HOMESCREEN_LIST_ADD_CONTENT)); |
|
734 |
|
735 HbAction *action = menu.exec(mSceneMenuPos); |
|
736 if (action == changeWallpaperAction) { |
|
737 emit event_selectSceneWallpaper(); |
|
738 } else if (action == addContentAction) { |
|
739 machine()->postEvent( |
|
740 HsMenuEventFactory::createOpenAppLibraryEvent(AddHsMenuMode)); |
|
741 } else { |
|
742 emit event_waitInput(); |
|
743 } |
|
744 } |
|
745 #ifdef COVERAGE_MEASUREMENT |
|
746 #pragma CTC ENDSKIP |
|
747 #endif //COVERAGE_MEASUREMENT |
|
748 |
|
749 /*! |
|
750 Adds a new page to the scene. |
|
751 */ |
|
752 void HsIdleState::action_addPage_addPage() |
|
753 { |
|
754 HsScene *scene = HsScene::instance(); |
|
755 int pageIndex = scene->pages().count(); |
|
756 addPageToScene(pageIndex); |
|
757 scene->setActivePageIndex(pageIndex); |
|
758 startPageChangeAnimation(pageIndex, 700); |
|
759 mUiWidget->pageIndicator()->addItem(true, true); |
|
760 } |
|
761 |
|
762 /*! |
|
763 Removes an existing page from the scene. |
|
764 */ |
|
765 void HsIdleState::action_removePage_removePage() |
|
766 { |
|
767 HsScene *scene = HsScene::instance(); |
|
768 HsPage *page = scene->activePage(); |
|
769 int pageIndex = scene->activePageIndex(); |
|
770 |
|
771 mUiWidget->removePage(pageIndex); |
|
772 scene->removePage(page); |
|
773 page->deleteFromDatabase(); |
|
774 delete page; |
|
775 |
|
776 pageIndex = pageIndex == 0 ? 0 : pageIndex - 1; |
|
777 scene->setActivePageIndex(pageIndex); |
|
778 |
|
779 startPageChangeAnimation(pageIndex, 200); |
|
780 |
|
781 mUiWidget->pageIndicator()->removeItem(); |
|
782 mUiWidget->setActivePage(pageIndex); |
|
783 } |
|
784 |
|
785 /*! |
|
786 Toggles the homescreen online/offline state. |
|
787 */ |
|
788 void HsIdleState::action_toggleConnection_toggleConnection() |
|
789 { |
|
790 HsScene *scene = HsScene::instance(); |
|
791 scene->setOnline(!scene->isOnline()); |
|
792 } |
|
793 |
|
794 /*! |
|
795 Handles mouse press events for the waitInput state. |
|
796 Filters events for the item \a watched. \a event is the |
|
797 filtered event. Sets the \a filtered true if the event |
|
798 was filtered by this handler. |
|
799 */ |
|
800 void HsIdleState::waitInput_onMousePressed( |
|
801 QGraphicsItem *watched, QGraphicsSceneMouseEvent *event, bool &filtered) |
|
802 { |
|
803 filtered = true; |
|
804 |
|
805 HsScene *scene = HsScene::instance(); |
|
806 HsPage *page = scene->activePage(); |
|
807 QList<HsWidgetHost *> widgets = page->widgets(); |
|
808 |
|
809 if (mUiWidget->controlLayer() == watched || |
|
810 mUiWidget->controlLayer()->isAncestorOf(watched)) { |
|
811 filtered = false; |
|
812 return; |
|
813 } |
|
814 |
|
815 mUiWidget->captureDelayedPress(event); |
|
816 |
|
817 foreach (HsWidgetHost *widget, widgets) { |
|
818 if (widget == watched || widget->isAncestorOf(watched)) { |
|
819 scene->setActiveWidget(widget); |
|
820 emit event_widgetInteraction(); |
|
821 return; |
|
822 } |
|
823 } |
|
824 |
|
825 mSceneMenuPos = event->scenePos(); |
|
826 emit event_sceneInteraction(); |
|
827 } |
|
828 |
|
829 /*! |
|
830 Handles mouse move events for the widgetInteraction state. |
|
831 Filters events for the item \a watched. \a event is the |
|
832 filtered event. Sets the \a filtered true if the event |
|
833 was filtered by this handler. |
|
834 */ |
|
835 void HsIdleState::widgetInteraction_onMouseMoved( |
|
836 QGraphicsItem *watched, QGraphicsSceneMouseEvent *event, bool &filtered) |
|
837 { |
|
838 Q_UNUSED(watched) |
|
839 Q_UNUSED(filtered) |
|
840 |
|
841 if (!mTimer.isActive()) { |
|
842 return; |
|
843 } |
|
844 |
|
845 QPointF point = |
|
846 event->screenPos() - event->buttonDownScreenPos(Qt::LeftButton); |
|
847 if (mTapAndHoldDistance < point.manhattanLength()) { |
|
848 mTimer.stop(); |
|
849 mUiWidget->sendDelayedPress(); |
|
850 } |
|
851 } |
|
852 |
|
853 /*! |
|
854 Handles mouse release events for the widgetInteraction state. |
|
855 Filters events for the item \a watched. \a event is the |
|
856 filtered event. Sets the \a filtered true if the event |
|
857 was filtered by this handler. |
|
858 */ |
|
859 void HsIdleState::widgetInteraction_onMouseReleased( |
|
860 QGraphicsItem *watched, QGraphicsSceneMouseEvent *event, bool &filtered) |
|
861 { |
|
862 Q_UNUSED(watched) |
|
863 Q_UNUSED(event) |
|
864 Q_UNUSED(filtered) |
|
865 |
|
866 if (mTimer.isActive()) { |
|
867 mTimer.stop(); |
|
868 mUiWidget->sendDelayedPress(); |
|
869 } |
|
870 |
|
871 HsScene::instance()->activePage()->updateZValues(); |
|
872 |
|
873 emit event_waitInput(); |
|
874 } |
|
875 |
|
876 /*! |
|
877 Handles mouse move events for the sceneInteraction state. |
|
878 Filters events for the item \a watched. \a event is the |
|
879 filtered event. Sets the \a filtered true if the event |
|
880 was filtered by this handler. |
|
881 */ |
|
882 void HsIdleState::sceneInteraction_onMouseMoved( |
|
883 QGraphicsItem *watched, QGraphicsSceneMouseEvent *event, bool &filtered) |
|
884 { |
|
885 Q_UNUSED(watched) |
|
886 Q_UNUSED(filtered) |
|
887 |
|
888 mSceneMenuPos = event->scenePos(); |
|
889 |
|
890 if (!mTimer.isActive()) { |
|
891 return; |
|
892 } |
|
893 |
|
894 QPointF point = |
|
895 event->screenPos() - event->buttonDownScreenPos(Qt::LeftButton); |
|
896 if (mTapAndHoldDistance < point.manhattanLength()) { |
|
897 mTimer.stop(); |
|
898 mUiWidget->clearDelayedPress(); |
|
899 emit event_moveScene(); |
|
900 } |
|
901 } |
|
902 |
|
903 /*! |
|
904 Handles mouse release events for the sceneInteraction state. |
|
905 Filters events for the item \a watched. \a event is the |
|
906 filtered event. Sets the \a filtered true if the event |
|
907 was filtered by this handler. |
|
908 */ |
|
909 void HsIdleState::sceneInteraction_onMouseReleased( |
|
910 QGraphicsItem *watched, QGraphicsSceneMouseEvent *event, bool &filtered) |
|
911 { |
|
912 Q_UNUSED(watched) |
|
913 Q_UNUSED(event) |
|
914 Q_UNUSED(filtered) |
|
915 |
|
916 if (mTimer.isActive()) { |
|
917 mTimer.stop(); |
|
918 mUiWidget->sendDelayedPress(); |
|
919 } |
|
920 |
|
921 emit event_waitInput(); |
|
922 } |
|
923 |
|
924 /*! |
|
925 Handles mouse move events for the moveWidget state. |
|
926 Filters events for the item \a watched. \a event is the |
|
927 filtered event. Sets the \a filtered true if the event |
|
928 was filtered by this handler. |
|
929 */ |
|
930 void HsIdleState::moveWidget_onMouseMoved( |
|
931 QGraphicsItem *watched, QGraphicsSceneMouseEvent *event, bool &filtered) |
|
932 { |
|
933 Q_UNUSED(watched) |
|
934 Q_UNUSED(filtered) |
|
935 |
|
936 HsWidgetHost *widget = HsScene::instance()->activeWidget(); |
|
937 Q_ASSERT(widget); |
|
938 |
|
939 QPointF delta(event->screenPos() - event->lastScreenPos()); |
|
940 QRectF region = mView->rect().adjusted(10, 55, -10, -10); |
|
941 QPointF position = widget->geometry().center() + delta; |
|
942 if (!region.contains(position)) { |
|
943 position.setX(qBound(region.left(), position.x(), region.right())); |
|
944 position.setY(qBound(region.top(), position.y(), region.bottom())); |
|
945 } |
|
946 |
|
947 widget->setPos(position - widget->rect().center()); |
|
948 |
|
949 if (mTimer.isActive()) { |
|
950 if (mTapAndHoldDistance < delta.manhattanLength()) { |
|
951 mTimer.stop(); |
|
952 } |
|
953 } else { |
|
954 if (isInPageChangeZone()) { |
|
955 mTimer.start(); |
|
956 } |
|
957 } |
|
958 |
|
959 if (mUiWidget->trashBin()->isUnderMouse()) { |
|
960 mUiWidget->trashBin()->activate(); |
|
961 } else { |
|
962 mUiWidget->trashBin()->deactivate(); |
|
963 } |
|
964 |
|
965 if (!mUiWidget->pageIndicator()->isAnimatingCurrentItemChange()) { |
|
966 mUiWidget->showTrashBin(); |
|
967 } |
|
968 } |
|
969 |
|
970 /*! |
|
971 Handles mouse release events for the moveWidget state. |
|
972 Filters events for the item \a watched. \a event is the |
|
973 filtered event. Sets the \a filtered true if the event |
|
974 was filtered by this handler. |
|
975 */ |
|
976 void HsIdleState::moveWidget_onMouseReleased( |
|
977 QGraphicsItem *watched, QGraphicsSceneMouseEvent *event, bool &filtered) |
|
978 { |
|
979 Q_UNUSED(watched) |
|
980 Q_UNUSED(event) |
|
981 |
|
982 mTimer.stop(); |
|
983 |
|
984 HsScene *scene = HsScene::instance(); |
|
985 HsPage *page = scene->activePage(); |
|
986 HsWidgetHost *widget = scene->activeWidget(); |
|
987 |
|
988 if (mUiWidget->trashBin()->isUnderMouse()) { |
|
989 widget->page()->removeWidget(widget); |
|
990 widget->uninitializeWidget(); |
|
991 widget->deleteFromDatabase(); |
|
992 widget->deleteLater(); |
|
993 scene->setActiveWidget(0); |
|
994 } else { |
|
995 if (widget->page() != page) { |
|
996 widget->page()->removeWidget(widget); |
|
997 page->addExistingWidget(widget); |
|
998 if (HsScene::orientation() == Qt::Horizontal) { |
|
999 widget->deleteWidgetPresentation(Qt::Vertical); |
|
1000 } else { |
|
1001 widget->deleteWidgetPresentation(Qt::Horizontal); |
|
1002 } |
|
1003 } |
|
1004 widget->setWidgetPresentation(); |
|
1005 page->updateZValues(); |
|
1006 } |
|
1007 |
|
1008 filtered = true; |
|
1009 emit event_waitInput(); |
|
1010 } |
|
1011 |
|
1012 /*! |
|
1013 Handles mouse move events for the moveScene state. |
|
1014 Filters events for the item \a watched. \a event is the |
|
1015 filtered event. Sets the \a filtered true if the event |
|
1016 was filtered by this handler. |
|
1017 */ |
|
1018 void HsIdleState::moveScene_onMouseMoved( |
|
1019 QGraphicsItem *watched, QGraphicsSceneMouseEvent *event, bool &filtered) |
|
1020 { |
|
1021 Q_UNUSED(watched) |
|
1022 Q_UNUSED(filtered) |
|
1023 |
|
1024 HsScene *scene = HsScene::instance(); |
|
1025 qreal delta = |
|
1026 event->screenPos().x() - event->buttonDownScreenPos(Qt::LeftButton).x(); |
|
1027 |
|
1028 qreal x = qBound(pageLayerXPos(scene->pages().count() - 1), |
|
1029 pageLayerXPos(scene->activePageIndex()) + delta, |
|
1030 pageLayerXPos(0)); |
|
1031 |
|
1032 mUiWidget->pageLayer()->setX(x); |
|
1033 mUiWidget->sceneLayer()->setX(parallaxFactor() * x); |
|
1034 } |
|
1035 |
|
1036 /*! |
|
1037 Handles mouse release events for the moveScene state. |
|
1038 Filters events for the item \a watched. \a event is the |
|
1039 filtered event. Sets the \a filtered true if the event |
|
1040 was filtered by this handler. |
|
1041 */ |
|
1042 void HsIdleState::moveScene_onMouseReleased( |
|
1043 QGraphicsItem *watched, QGraphicsSceneMouseEvent *event, bool &filtered) |
|
1044 { |
|
1045 Q_UNUSED(watched) |
|
1046 Q_UNUSED(filtered) |
|
1047 |
|
1048 QList<HsPage *> pages = HsScene::instance()->pages(); |
|
1049 QSizeF pageSize = pages.first()->size(); |
|
1050 |
|
1051 int pageIndex = HsScene::instance()->activePageIndex(); |
|
1052 |
|
1053 QPointF delta( |
|
1054 event->screenPos() - event->buttonDownScreenPos(Qt::LeftButton)); |
|
1055 if (delta.x() < -pageSize.width() / 2) { |
|
1056 pageIndex = qMin(pageIndex + 1, pages.count() - 1); |
|
1057 } else if(pageSize.width() / 2 < delta.x()) { |
|
1058 pageIndex = qMax(pageIndex - 1, 0); |
|
1059 } |
|
1060 |
|
1061 HsScene::instance()->setActivePageIndex(pageIndex); |
|
1062 |
|
1063 startPageChangeAnimation(pageIndex, 200); |
|
1064 |
|
1065 emit event_waitInput(); |
|
1066 } |
|
1067 |
|
1068 /*! |
|
1069 Handles orientation change events. \a orientation is the |
|
1070 new orientation. |
|
1071 */ |
|
1072 void HsIdleState::onOrientationChanged(Qt::Orientation orientation) |
|
1073 { |
|
1074 QList<HsPage *> pages = HsScene::instance()->pages(); |
|
1075 QList<HsWidgetHost *> widgets; |
|
1076 HsWidgetHost *widget = 0; |
|
1077 |
|
1078 for (int i = 0; i < pages.count(); ++i) { |
|
1079 widgets = pages[i]->widgets(); |
|
1080 for (int j = 0; j < widgets.count(); ++j) { |
|
1081 widget = widgets[j]; |
|
1082 HsWidgetPresentationData presentation = widget->widgetPresentation(orientation); |
|
1083 if (presentation.id() < 0) { |
|
1084 QList<QRectF> geometries = |
|
1085 HsWidgetPositioningOnOrientationChange::instance()->convert( |
|
1086 pages[i]->rect().adjusted(10, 10, -10, -10), QList<QRectF>() << widget->geometry(), |
|
1087 QRectF(0, 0, pages[i]->rect().height() + 40, |
|
1088 pages[i]->rect().width() - 40).adjusted(10, 10, -10, -10)); |
|
1089 widget->setGeometry(geometries.first()); |
|
1090 widget->setWidgetPresentation(); |
|
1091 } else { |
|
1092 widget->setGeometry(QRectF(presentation.position(), presentation.size())); |
|
1093 widget->setZValue(presentation.zValue()); |
|
1094 } |
|
1095 } |
|
1096 } |
|
1097 |
|
1098 action_idle_showActivePage(); |
|
1099 } |
|
1100 |
|
1101 /*! |
|
1102 Handles tap-and-hold events for the widgetInteraction state. |
|
1103 */ |
|
1104 void HsIdleState::widgetInteraction_onTapAndHoldTimeout() |
|
1105 { |
|
1106 mUiWidget->clearDelayedPress(); |
|
1107 emit event_moveWidget(); |
|
1108 } |
|
1109 |
|
1110 /*! |
|
1111 Handles tap-and-hold events for the sceneInteraction state. |
|
1112 */ |
|
1113 void HsIdleState::sceneInteraction_onTapAndHoldTimeout() |
|
1114 { |
|
1115 mUiWidget->clearDelayedPress(); |
|
1116 emit event_sceneMenu(); |
|
1117 } |
|
1118 |
|
1119 /*! |
|
1120 Handles page change zone hold events for the moveWidget state. |
|
1121 */ |
|
1122 void HsIdleState::moveWidget_onHoldTimeout() |
|
1123 { |
|
1124 HsScene *scene = HsScene::instance(); |
|
1125 |
|
1126 int pageIndex = scene->activePageIndex(); |
|
1127 |
|
1128 if (isInLeftPageChangeZone() && |
|
1129 0 < pageIndex) { |
|
1130 --pageIndex; |
|
1131 } else if (isInRightPageChangeZone() && |
|
1132 pageIndex < scene->pages().count()) { |
|
1133 ++pageIndex; |
|
1134 } else { |
|
1135 return; |
|
1136 } |
|
1137 |
|
1138 if (pageIndex == scene->pages().count()) { |
|
1139 if (scene->pages().last()->widgets().isEmpty()) { |
|
1140 return; |
|
1141 } else { |
|
1142 addPageToScene(pageIndex); |
|
1143 mUiWidget->showPageIndicator(); |
|
1144 mUiWidget->pageIndicator()->addItem(true); |
|
1145 } |
|
1146 } |
|
1147 |
|
1148 scene->setActivePageIndex(pageIndex); |
|
1149 startPageChangeAnimation(pageIndex, 200); |
|
1150 } |
|
1151 |
|
1152 #ifndef Q_OS_SYMBIAN |
|
1153 #ifdef COVERAGE_MEASUREMENT |
|
1154 #pragma CTC SKIP |
|
1155 #endif //COVERAGE_MEASUREMENT |
|
1156 /*! |
|
1157 Switch the home screen language. |
|
1158 */ |
|
1159 void HsIdleState::switchLanguage() |
|
1160 { |
|
1161 QString locale; |
|
1162 QFile file("hslocale.txt"); |
|
1163 QTextStream stream(&file); |
|
1164 if (file.open(QIODevice::ReadWrite | QIODevice::Text)) { |
|
1165 QString word; |
|
1166 stream >> word; |
|
1167 if (!word.isEmpty()) { |
|
1168 locale = word; |
|
1169 } else { |
|
1170 locale = "en_US"; |
|
1171 } |
|
1172 } else { |
|
1173 locale = QLocale::system().name(); |
|
1174 } |
|
1175 |
|
1176 if (locale == "en_US") { |
|
1177 locale = "fi_FI"; |
|
1178 } else { |
|
1179 locale = "en_US"; |
|
1180 } |
|
1181 |
|
1182 file.seek(0); |
|
1183 stream << locale; |
|
1184 file.close(); |
|
1185 |
|
1186 QEvent event(QEvent::LocaleChange); |
|
1187 QApplication::sendEvent(qApp, &event); |
|
1188 } |
|
1189 |
|
1190 /*! |
|
1191 Translates the home screen ui. |
|
1192 */ |
|
1193 void HsIdleState::translateUi() |
|
1194 { |
|
1195 mView->setTitle("Home Screen"/*hbTrId(TXT_HOMESCREEN_TITLE_OFFLINE)*/); |
|
1196 action_waitInput_updateOptionsMenu(); |
|
1197 } |
|
1198 #ifdef COVERAGE_MEASUREMENT |
|
1199 #pragma CTC ENDSKIP |
|
1200 #endif //COVERAGE_MEASUREMENT |
|
1201 #endif // Q_OS_SYMBIAN |
|
1202 |
|
1203 // Undefine the helper macros. |
|
1204 #undef ENTRY_ACTION |
|
1205 #undef EXIT_ACTION |
|
1206 #undef CONNECT_MOUSE_EVENT_HANDLER |
|
1207 #undef DISCONNECT_MOUSE_EVENT_HANDLER |