44 /*! |
44 /*! |
45 \class HsIdleWidget |
45 \class HsIdleWidget |
46 \ingroup group_hshomescreenstateplugin |
46 \ingroup group_hshomescreenstateplugin |
47 \brief View part of the home screen idle state. |
47 \brief View part of the home screen idle state. |
48 |
48 |
49 Maintains the idle view ui layers and takes care of |
49 Maintains the idle view ui layers and takes care of |
50 receiving user input and communicating it to the idle |
50 receiving user input and communicating it to the idle |
51 state for further processing. |
51 state for further processing. |
52 */ |
52 */ |
53 |
53 |
54 /*! |
54 /*! |
55 Constructs a new idle widget with the given \a parent. |
55 Constructs a new idle widget with the given \a parent. |
56 */ |
56 */ |
57 HsIdleWidget::HsIdleWidget(QGraphicsItem *parent) |
57 HsIdleWidget::HsIdleWidget(QGraphicsItem *parent) |
58 : HbWidget(parent), |
58 : HbWidget(parent), |
59 mControlLayer(0), mPageLayer(0), mSceneLayer(0), |
59 mControlLayer(0), mPageLayer(0), mPageWallpaperLayer(0), |
60 mDelayedPressEvent(0), |
60 mSceneLayer(0), mDelayedPressEvent(0), |
61 mTrashBin(0), mPageIndicator(0) |
61 mTrashBin(0), mPageIndicator(0) |
62 { |
62 { |
63 setFlag(ItemHasNoContents); |
63 setFlag(ItemHasNoContents); |
64 |
64 |
65 loadControlLayer(); |
65 loadControlLayer(); |
66 |
66 |
67 QGraphicsLinearLayout *linearLayout = 0; |
67 QGraphicsLinearLayout *linearLayout = 0; |
68 |
68 |
69 linearLayout = new QGraphicsLinearLayout(Qt::Horizontal); |
69 linearLayout = new QGraphicsLinearLayout(Qt::Horizontal); |
70 linearLayout->setContentsMargins(0, 0, 0, 0); |
70 linearLayout->setContentsMargins(0, 0, 0, 0); |
71 linearLayout->setSpacing(0); |
71 linearLayout->setSpacing(0); |
72 mPageLayer = new HbWidget(this); |
72 mPageLayer = new HbWidget(this); |
73 mPageLayer->setLayout(linearLayout); |
73 mPageLayer->setLayout(linearLayout); |
74 mPageLayer->setZValue(1); |
74 mPageLayer->setZValue(2); |
|
75 |
|
76 linearLayout = new QGraphicsLinearLayout(Qt::Horizontal); |
|
77 linearLayout->setContentsMargins(0, 0, 0, 0); |
|
78 linearLayout->setSpacing(0); |
|
79 mPageWallpaperLayer = new HbWidget(this); |
|
80 mPageWallpaperLayer->setLayout(linearLayout); |
|
81 mPageWallpaperLayer->setZValue(1); |
75 |
82 |
76 linearLayout = new QGraphicsLinearLayout(Qt::Horizontal); |
83 linearLayout = new QGraphicsLinearLayout(Qt::Horizontal); |
77 linearLayout->setContentsMargins(0, 0, 0, 0); |
84 linearLayout->setContentsMargins(0, 0, 0, 0); |
78 linearLayout->setSpacing(0); |
85 linearLayout->setSpacing(0); |
79 mSceneLayer = new HbWidget(this); |
86 mSceneLayer = new HbWidget(this); |
92 foreach (HsPage *page, pages) { |
99 foreach (HsPage *page, pages) { |
93 page->setParentItem(0); |
100 page->setParentItem(0); |
94 if (page->scene()) { |
101 if (page->scene()) { |
95 page->scene()->removeItem(page); |
102 page->scene()->removeItem(page); |
96 } |
103 } |
97 } |
104 HsWallpaper *pageWallpaper = page->wallpaper(); |
98 |
105 if (pageWallpaper) { |
99 HsWallpaper *wallpaper = HsScene::instance()->wallpaper(); |
106 pageWallpaper->setParentItem(0); |
100 wallpaper->setParentItem(0); |
107 if (pageWallpaper->scene()) { |
101 if (wallpaper->scene()) { |
108 pageWallpaper->scene()->removeItem(pageWallpaper); |
102 wallpaper->scene()->removeItem(wallpaper); |
109 } |
|
110 } |
|
111 } |
|
112 |
|
113 HsWallpaper *sceneWallpaper = HsScene::instance()->wallpaper(); |
|
114 if (sceneWallpaper) { |
|
115 sceneWallpaper->setParentItem(0); |
|
116 if (sceneWallpaper->scene()) { |
|
117 sceneWallpaper->scene()->removeItem(sceneWallpaper); |
|
118 } |
|
119 } |
|
120 } |
|
121 |
|
122 qreal HsIdleWidget::sceneX() const |
|
123 { |
|
124 return mPageLayer->x(); |
|
125 } |
|
126 |
|
127 void HsIdleWidget::setSceneX(qreal x) |
|
128 { |
|
129 if (HSCONFIGURATION_GET(sceneType) == HsConfiguration::SceneWallpaper) { |
|
130 mPageLayer->setX(x); |
|
131 mSceneLayer->setX((parallaxFactor() * x) - HSCONFIGURATION_GET(bounceEffect) / 2); |
|
132 } else { |
|
133 mPageLayer->setX(x); |
|
134 mPageWallpaperLayer->setX(x); |
103 } |
135 } |
104 } |
136 } |
105 |
137 |
106 /*! |
138 /*! |
107 Layouts the ui layers according to the given \a rect. |
139 Layouts the ui layers according to the given \a rect. |
111 int n = HsScene::instance()->pages().count(); |
143 int n = HsScene::instance()->pages().count(); |
112 QRectF layoutRect(HsScene::instance()->mainWindow()->layoutRect()); |
144 QRectF layoutRect(HsScene::instance()->mainWindow()->layoutRect()); |
113 if (layoutRect == rect || (layoutRect.height() == rect.width() && layoutRect.width() == rect.height())) { |
145 if (layoutRect == rect || (layoutRect.height() == rect.width() && layoutRect.width() == rect.height())) { |
114 mControlLayer->resize(rect.size()); |
146 mControlLayer->resize(rect.size()); |
115 mPageLayer->resize(n * rect.width(), rect.height()); |
147 mPageLayer->resize(n * rect.width(), rect.height()); |
116 mSceneLayer->resize(2 * rect.width() + HsConfiguration::bounceEffect(), rect.height()); |
148 if (HSCONFIGURATION_GET(sceneType) == HsConfiguration::PageWallpapers) { |
|
149 mPageWallpaperLayer->resize(n * rect.width(), rect.height()); |
|
150 } |
|
151 mSceneLayer->resize(2 * rect.width() + HSCONFIGURATION_GET(bounceEffect), rect.height()); |
117 HbWidget::setGeometry(rect); |
152 HbWidget::setGeometry(rect); |
118 } else { |
153 } else { |
119 QRectF sceneRect = mapToScene(rect).boundingRect(); |
154 QRectF sceneRect = mapToScene(rect).boundingRect(); |
120 sceneRect.setTop(-sceneRect.top()); |
155 sceneRect.setTop(-sceneRect.top()); |
121 HbWidget::setGeometry(sceneRect); |
156 HbWidget::setGeometry(sceneRect); |
139 */ |
174 */ |
140 void HsIdleWidget::sendDelayedPress() |
175 void HsIdleWidget::sendDelayedPress() |
141 { |
176 { |
142 if (mDelayedPressEvent) { |
177 if (mDelayedPressEvent) { |
143 QApplication::sendEvent(HsScene::mainWindow()->viewport(), mDelayedPressEvent); |
178 QApplication::sendEvent(HsScene::mainWindow()->viewport(), mDelayedPressEvent); |
144 clearDelayedPress(); |
179 clearDelayedPress(); |
145 } |
180 } |
146 } |
181 } |
147 |
182 |
148 /*! |
183 /*! |
149 Deletes the stored mouse press event. |
184 Deletes the stored mouse press event. |
150 */ |
185 */ |
151 void HsIdleWidget::clearDelayedPress() |
186 void HsIdleWidget::clearDelayedPress() |
152 { |
187 { |
153 if (mDelayedPressEvent) { |
188 if (mDelayedPressEvent) { |
154 delete mDelayedPressEvent; |
189 delete mDelayedPressEvent; |
155 mDelayedPressEvent = 0; |
190 mDelayedPressEvent = 0; |
156 } |
191 } |
157 } |
192 } |
158 |
193 |
159 /*! |
194 /*! |
160 Sets the active page \a index to the page |
195 Sets the active page \a index to the page |
161 indicator. |
196 indicator. |
162 */ |
197 */ |
163 void HsIdleWidget::setActivePage(int index) |
198 void HsIdleWidget::setActivePage(int index) |
164 { |
199 { |
165 mPageIndicator->setActiveItemIndex(index); |
200 mPageIndicator->setActiveItemIndex(index); |
169 Inserts the given \a page at index position |
204 Inserts the given \a page at index position |
170 \a index in the page layer. |
205 \a index in the page layer. |
171 */ |
206 */ |
172 void HsIdleWidget::insertPage(int index, HsPage *page) |
207 void HsIdleWidget::insertPage(int index, HsPage *page) |
173 { |
208 { |
174 QGraphicsLinearLayout *layout = |
209 QGraphicsLinearLayout *layout = |
175 static_cast<QGraphicsLinearLayout *>(mPageLayer->layout()); |
210 static_cast<QGraphicsLinearLayout *>(mPageLayer->layout()); |
176 layout->insertItem(index, page); |
211 layout->insertItem(index, page); |
177 mPageLayer->resize( |
212 mPageLayer->resize( |
178 layout->count() * size().width(), size().height()); |
213 layout->count() * size().width(), size().height()); |
|
214 |
|
215 if (HSCONFIGURATION_GET(sceneType) == HsConfiguration::PageWallpapers) { |
|
216 QGraphicsLinearLayout *layout = |
|
217 static_cast<QGraphicsLinearLayout *>(mPageWallpaperLayer->layout()); |
|
218 layout->insertItem(index, page->wallpaper()); |
|
219 mPageWallpaperLayer->resize( |
|
220 layout->count() * size().width(), size().height()); |
|
221 } |
179 } |
222 } |
180 |
223 |
181 /*! |
224 /*! |
182 Removes the page at index position |
225 Removes the page at index position |
183 \a index in the page layer. |
226 \a index in the page layer. |
184 */ |
227 */ |
185 void HsIdleWidget::removePage(int index) |
228 void HsIdleWidget::removePage(int index) |
186 { |
229 { |
187 QGraphicsLinearLayout *layout = |
230 QGraphicsLinearLayout *layout = |
188 static_cast<QGraphicsLinearLayout *>(mPageLayer->layout()); |
231 static_cast<QGraphicsLinearLayout *>(mPageLayer->layout()); |
189 layout->removeAt(index); |
232 layout->removeAt(index); |
190 mPageLayer->resize( |
233 mPageLayer->resize( |
191 layout->count() * size().width(), size().height()); |
234 layout->count() * size().width(), size().height()); |
|
235 |
|
236 if (HSCONFIGURATION_GET(sceneType) == HsConfiguration::PageWallpapers) { |
|
237 QGraphicsLinearLayout *layout = |
|
238 static_cast<QGraphicsLinearLayout *>(mPageWallpaperLayer->layout()); |
|
239 layout->removeAt(index); |
|
240 mPageWallpaperLayer->resize( |
|
241 layout->count() * size().width(), size().height()); |
|
242 } |
192 } |
243 } |
193 |
244 |
194 /*! |
245 /*! |
195 \fn HsIdleWidget::controlLayer() const |
246 \fn HsIdleWidget::controlLayer() const |
196 |
247 |
223 |
274 |
224 /*! |
275 /*! |
225 \fn HsIdleWidget::mousePressed(QGraphicsItem *, QGraphicsSceneMouseEvent *, bool &) |
276 \fn HsIdleWidget::mousePressed(QGraphicsItem *, QGraphicsSceneMouseEvent *, bool &) |
226 |
277 |
227 The idle state connects to this signal for handling mouse |
278 The idle state connects to this signal for handling mouse |
228 press events. It filters events for the item \a watched. |
279 press events. It filters events for the item \a watched. |
229 \a event is the filtered event. Sets the \a filtered true |
280 \a event is the filtered event. Sets the \a filtered true |
230 if the event was filtered by this handler. |
281 if the event was filtered by this handler. |
231 */ |
282 */ |
232 |
283 |
233 /*! |
284 /*! |
234 \fn HsIdleWidget::mouseMoved(QGraphicsItem *, QGraphicsSceneMouseEvent *, bool &) |
285 \fn HsIdleWidget::mouseMoved(QGraphicsItem *, QGraphicsSceneMouseEvent *, bool &) |
235 |
286 |
236 The idle state connects to this signal for handling mouse |
287 The idle state connects to this signal for handling mouse |
237 move events. It filters events for the item \a watched. |
288 move events. It filters events for the item \a watched. |
238 \a event is the filtered event. Sets the \a filtered true |
289 \a event is the filtered event. Sets the \a filtered true |
239 if the event was filtered by this handler. |
290 if the event was filtered by this handler. |
240 */ |
291 */ |
241 |
292 |
242 /*! |
293 /*! |
243 \fn HsIdleWidget::mouseReleased(QGraphicsItem *, QGraphicsSceneMouseEvent *, bool &) |
294 \fn HsIdleWidget::mouseReleased(QGraphicsItem *, QGraphicsSceneMouseEvent *, bool &) |
244 |
295 |
245 The idle state connects to this signal for handling mouse |
296 The idle state connects to this signal for handling mouse |
246 release events. It filters events for the item \a watched. |
297 release events. It filters events for the item \a watched. |
247 \a event is the filtered event. Sets the \a filtered true |
298 \a event is the filtered event. Sets the \a filtered true |
248 if the event was filtered by this handler. |
299 if the event was filtered by this handler. |
249 */ |
300 */ |
250 |
301 |
251 /*! |
302 /*! |
252 Sets the trashbin visible and hides the page indicator. |
303 Sets the trashbin visible and hides the page indicator. |
254 void HsIdleWidget::showTrashBin() |
305 void HsIdleWidget::showTrashBin() |
255 { |
306 { |
256 mPageIndicator->hide(); |
307 mPageIndicator->hide(); |
257 mTrashBin->show(); |
308 mTrashBin->show(); |
258 } |
309 } |
259 |
310 |
260 /*! |
311 /*! |
261 Sets the page indicator visible and hides the trashbin. |
312 Sets the page indicator visible and hides the trashbin. |
262 */ |
313 */ |
263 void HsIdleWidget::showPageIndicator() |
314 void HsIdleWidget::showPageIndicator() |
264 { |
315 { |
265 mTrashBin->hide(); |
316 mTrashBin->hide(); |
266 mTrashBin->deactivate(); |
317 mTrashBin->deactivate(); |
267 mPageIndicator->setSpacing(HsConfiguration::pageIndicatorSpacing()); // for usability optimization widget, can be removed later on |
318 mPageIndicator->setSpacing(HSCONFIGURATION_GET(pageIndicatorSpacing)); // for usability optimization widget, can be removed later on |
268 mPageIndicator->setVisible(1 < mPageIndicator->itemCount()); |
319 mPageIndicator->setVisible(1 < mPageIndicator->itemCount()); |
269 } |
320 } |
270 |
321 |
271 /*! |
322 /*! |
272 Filters the main window's graphics scene (\a object) \a event. |
323 Filters the main window's graphics scene (\a object) \a event. |
273 */ |
324 */ |
274 bool HsIdleWidget::eventFilter(QObject *object, QEvent *event) |
325 bool HsIdleWidget::eventFilter(QObject *object, QEvent *event) |
275 { |
326 { |
276 Q_UNUSED(object) |
327 Q_UNUSED(object) |
277 |
328 |
278 if (HbVkbHost::activeVkbHost()) { |
|
279 setFiltersChildEvents(false); |
|
280 return false; |
|
281 } |
|
282 |
|
283 bool filtered = false; |
329 bool filtered = false; |
284 |
330 |
285 switch (event->type()) { |
331 switch (event->type()) { |
286 case QEvent::GraphicsSceneMousePress: |
332 case QEvent::GraphicsSceneMousePress: |
|
333 if (HbVkbHost::activeVkbHost()) { |
|
334 setFiltersChildEvents(false); |
|
335 break; |
|
336 } |
287 if (mDelayedPressEvent && |
337 if (mDelayedPressEvent && |
288 scene()->mouseGrabberItem()) { |
338 scene()->mouseGrabberItem()) { |
289 scene()->mouseGrabberItem()->ungrabMouse(); |
339 scene()->mouseGrabberItem()->ungrabMouse(); |
290 } |
340 } |
291 setFiltersChildEvents(!mDelayedPressEvent); |
341 setFiltersChildEvents(!mDelayedPressEvent); |
292 break; |
342 break; |
293 case QEvent::GraphicsSceneMouseMove: |
343 case QEvent::GraphicsSceneMouseMove: |
294 emit mouseMoved(0, static_cast<QGraphicsSceneMouseEvent *>(event), filtered); |
344 emit mouseMoved(0, static_cast<QGraphicsSceneMouseEvent *>(event), filtered); |
295 break; |
345 break; |
296 case QEvent::GraphicsSceneMouseRelease: |
346 case QEvent::GraphicsSceneMouseRelease: |
297 setItemsFocusable(); |
|
298 emit mouseReleased(0, static_cast<QGraphicsSceneMouseEvent *>(event), filtered); |
347 emit mouseReleased(0, static_cast<QGraphicsSceneMouseEvent *>(event), filtered); |
299 if (filtered && scene()->mouseGrabberItem()) { |
348 if (filtered && scene()->mouseGrabberItem()) { |
300 scene()->mouseGrabberItem()->ungrabMouse(); |
349 scene()->mouseGrabberItem()->ungrabMouse(); |
301 } |
350 } |
302 break; |
351 break; |
303 default: |
352 default: |
304 break; |
353 break; |
305 } |
354 } |
306 |
355 |
334 void HsIdleWidget::polishEvent() |
380 void HsIdleWidget::polishEvent() |
335 { |
381 { |
336 HsScene *scene = HsScene::instance(); |
382 HsScene *scene = HsScene::instance(); |
337 Q_ASSERT(scene); |
383 Q_ASSERT(scene); |
338 |
384 |
339 QGraphicsLinearLayout *layout = |
385 QGraphicsLinearLayout *pageLayout = |
340 static_cast<QGraphicsLinearLayout *>(mPageLayer->layout()); |
386 static_cast<QGraphicsLinearLayout *>(mPageLayer->layout()); |
|
387 |
341 QList<HsPage *> pages = scene->pages(); |
388 QList<HsPage *> pages = scene->pages(); |
|
389 |
342 foreach (HsPage *page, pages) { |
390 foreach (HsPage *page, pages) { |
343 layout->addItem(page); |
391 pageLayout->addItem(page); |
344 } |
392 if (HSCONFIGURATION_GET(sceneType) == HsConfiguration::PageWallpapers) { |
345 |
393 QGraphicsLinearLayout *pageWallpaperLayout = |
346 layout = static_cast<QGraphicsLinearLayout *>(mSceneLayer->layout()); |
394 static_cast<QGraphicsLinearLayout *>(mPageWallpaperLayer->layout()); |
347 HsWallpaper *wallpaper = HsScene::instance()->wallpaper(); |
395 pageWallpaperLayout->addItem(page->wallpaper()); |
348 layout->addItem(wallpaper); |
396 } |
|
397 } |
|
398 if (HSCONFIGURATION_GET(sceneType) == HsConfiguration::SceneWallpaper) { |
|
399 QGraphicsLinearLayout *sceneLayout = |
|
400 static_cast<QGraphicsLinearLayout *>(mSceneLayer->layout()); |
|
401 HsWallpaper *wallpaper = HsScene::instance()->wallpaper(); |
|
402 sceneLayout->addItem(wallpaper); |
|
403 } |
349 |
404 |
350 mPageIndicator->initialize(pages.count(), scene->activePageIndex()); |
405 mPageIndicator->initialize(pages.count(), scene->activePageIndex()); |
351 showPageIndicator(); |
406 showPageIndicator(); |
352 |
407 |
353 HsScene::mainWindow()->scene()->installEventFilter(this); |
408 HsScene::mainWindow()->scene()->installEventFilter(this); |
374 loader.load(file, &loaded); |
429 loader.load(file, &loaded); |
375 if (!loaded) { |
430 if (!loaded) { |
376 loader.load(fallbackPath, &loaded); |
431 loader.load(fallbackPath, &loaded); |
377 } |
432 } |
378 } else { |
433 } else { |
379 loader.load(fallbackPath, &loaded); |
434 loader.load(fallbackPath, &loaded); |
380 } |
435 } |
381 |
436 |
382 if (loaded) { |
437 if (loaded) { |
383 mControlLayer = qobject_cast<HbWidget *>(loader.findWidget(gControlLayerName)); |
438 mControlLayer = qobject_cast<HbWidget *>(loader.findWidget(gControlLayerName)); |
384 mControlLayer->setZValue(2); |
439 mControlLayer->setZValue(3); |
385 mControlLayer->setParentItem(this); |
440 mControlLayer->setParentItem(this); |
386 |
441 |
387 mTrashBin = qobject_cast<HsTrashBinWidget *>(loader.findWidget(gTrashBinName)); |
442 mTrashBin = qobject_cast<HsTrashBinWidget *>(loader.findWidget(gTrashBinName)); |
388 mTrashBin->setZValue(1e6); |
443 mTrashBin->setZValue(1e6); |
389 |
444 |
392 } else { |
447 } else { |
393 // TODO: Handle error. |
448 // TODO: Handle error. |
394 } |
449 } |
395 } |
450 } |
396 |
451 |
397 /*! |
452 qreal HsIdleWidget::parallaxFactor() const |
398 Sets the items under the given mouse \a event scene position |
453 { |
399 unfocusable and stores the items. |
454 qreal clw = mControlLayer->size().width(); |
400 */ |
455 qreal slw = mSceneLayer->size().width() - HSCONFIGURATION_GET(bounceEffect); |
401 void HsIdleWidget::setItemsUnfocusable(QGraphicsSceneMouseEvent *event) |
456 int n = HsScene::instance()->pages().count(); |
402 { |
457 if (n < 2) { |
403 mFocusableItems.clear(); |
458 return 1; |
404 |
459 } else { |
405 if (!scene()) { |
460 return (slw - clw) / ((n - 1) * clw); |
406 return; |
461 } |
407 } |
462 } |
408 |
|
409 QList<QGraphicsItem *> items = scene()->items(event->scenePos()); |
|
410 if (items.isEmpty()) { |
|
411 return; |
|
412 } |
|
413 |
|
414 int i = 0; |
|
415 for (; i < items.count(); ++i) { |
|
416 if (mPageLayer->isAncestorOf(items[i])) { |
|
417 ++i; |
|
418 break; |
|
419 } |
|
420 } |
|
421 |
|
422 HsPage *page = HsScene::instance()->activePage(); |
|
423 QList<HsWidgetHost *> widgets = page->widgets(); |
|
424 |
|
425 for (; i < items.count(); ++i) { |
|
426 QGraphicsItem *item = items.at(i); |
|
427 if (page->isAncestorOf(item)) { |
|
428 foreach (HsWidgetHost *widget, widgets) { |
|
429 if ((item == widget || widget->isAncestorOf(item))&& item->isEnabled() && (item->flags() & QGraphicsItem::ItemIsFocusable)) { |
|
430 if (!item->isWidget() || static_cast<QGraphicsWidget *>(item)->focusPolicy() & Qt::ClickFocus) { |
|
431 item->setFlag(QGraphicsItem::ItemIsFocusable, false); |
|
432 mFocusableItems.append(item); |
|
433 } |
|
434 } |
|
435 } |
|
436 } |
|
437 } |
|
438 } |
|
439 |
|
440 /*! |
|
441 Sets the stored items focusable. |
|
442 */ |
|
443 void HsIdleWidget::setItemsFocusable() |
|
444 { |
|
445 foreach (QGraphicsItem *item, mFocusableItems) { |
|
446 item->setFlag(QGraphicsItem::ItemIsFocusable); |
|
447 } |
|
448 mFocusableItems.clear(); |
|
449 } |
|