44 /*! |
46 /*! |
45 \class HsIdleWidget |
47 \class HsIdleWidget |
46 \ingroup group_hshomescreenstateplugin |
48 \ingroup group_hshomescreenstateplugin |
47 \brief View part of the home screen idle state. |
49 \brief View part of the home screen idle state. |
48 |
50 |
49 Maintains the idle view ui layers and takes care of |
51 Maintains the idle view ui layers and takes care of |
50 receiving user input and communicating it to the idle |
52 receiving user input and communicating it to the idle |
51 state for further processing. |
53 state for further processing. |
52 */ |
54 */ |
53 |
55 |
54 /*! |
56 /*! |
55 Constructs a new idle widget with the given \a parent. |
57 Constructs a new idle widget with the given \a parent. |
56 */ |
58 */ |
57 HsIdleWidget::HsIdleWidget(QGraphicsItem *parent) |
59 HsIdleWidget::HsIdleWidget(QGraphicsItem *parent) |
58 : HbWidget(parent), |
60 : HbWidget(parent), |
59 mControlLayer(0), mPageLayer(0), mSceneLayer(0), |
61 mControlLayer(0), mPageLayer(0), mPageWallpaperLayer(0), |
60 mDelayedPressEvent(0), |
62 mSceneLayer(0), |
61 mTrashBin(0), mPageIndicator(0) |
63 mTrashBin(0), mPageIndicator(0), |
|
64 mHorizontalSnapLine(0), mVerticalSnapLine(0) |
62 { |
65 { |
63 setFlag(ItemHasNoContents); |
66 setFlag(ItemHasNoContents); |
64 |
67 |
65 loadControlLayer(); |
68 loadControlLayer(); |
66 |
69 |
67 QGraphicsLinearLayout *linearLayout = 0; |
70 QGraphicsLinearLayout *linearLayout = 0; |
68 |
71 |
69 linearLayout = new QGraphicsLinearLayout(Qt::Horizontal); |
72 linearLayout = new QGraphicsLinearLayout(Qt::Horizontal); |
70 linearLayout->setContentsMargins(0, 0, 0, 0); |
73 linearLayout->setContentsMargins(0, 0, 0, 0); |
71 linearLayout->setSpacing(0); |
74 linearLayout->setSpacing(0); |
72 mPageLayer = new HbWidget(this); |
75 mPageLayer = new HbWidget(this); |
73 mPageLayer->setLayout(linearLayout); |
76 mPageLayer->setLayout(linearLayout); |
74 mPageLayer->setZValue(1); |
77 mPageLayer->setZValue(2); |
|
78 |
|
79 linearLayout = new QGraphicsLinearLayout(Qt::Horizontal); |
|
80 linearLayout->setContentsMargins(0, 0, 0, 0); |
|
81 linearLayout->setSpacing(0); |
|
82 mPageWallpaperLayer = new HbWidget(this); |
|
83 mPageWallpaperLayer->setLayout(linearLayout); |
|
84 mPageWallpaperLayer->setZValue(1); |
75 |
85 |
76 linearLayout = new QGraphicsLinearLayout(Qt::Horizontal); |
86 linearLayout = new QGraphicsLinearLayout(Qt::Horizontal); |
77 linearLayout->setContentsMargins(0, 0, 0, 0); |
87 linearLayout->setContentsMargins(0, 0, 0, 0); |
78 linearLayout->setSpacing(0); |
88 linearLayout->setSpacing(0); |
79 mSceneLayer = new HbWidget(this); |
89 mSceneLayer = new HbWidget(this); |
84 /*! |
94 /*! |
85 Destroys this idle widget. |
95 Destroys this idle widget. |
86 */ |
96 */ |
87 HsIdleWidget::~HsIdleWidget() |
97 HsIdleWidget::~HsIdleWidget() |
88 { |
98 { |
89 clearDelayedPress(); |
|
90 |
|
91 QList<HsPage *> pages = HsScene::instance()->pages(); |
99 QList<HsPage *> pages = HsScene::instance()->pages(); |
92 foreach (HsPage *page, pages) { |
100 foreach (HsPage *page, pages) { |
93 page->setParentItem(0); |
101 page->setParentItem(0); |
94 if (page->scene()) { |
102 if (page->scene()) { |
95 page->scene()->removeItem(page); |
103 page->scene()->removeItem(page); |
96 } |
104 } |
97 } |
105 HsWallpaper *pageWallpaper = page->wallpaper(); |
98 |
106 if (pageWallpaper) { |
99 HsWallpaper *wallpaper = HsScene::instance()->wallpaper(); |
107 pageWallpaper->setParentItem(0); |
100 wallpaper->setParentItem(0); |
108 if (pageWallpaper->scene()) { |
101 if (wallpaper->scene()) { |
109 pageWallpaper->scene()->removeItem(pageWallpaper); |
102 wallpaper->scene()->removeItem(wallpaper); |
110 } |
|
111 } |
|
112 } |
|
113 |
|
114 HsWallpaper *sceneWallpaper = HsScene::instance()->wallpaper(); |
|
115 if (sceneWallpaper) { |
|
116 sceneWallpaper->setParentItem(0); |
|
117 if (sceneWallpaper->scene()) { |
|
118 sceneWallpaper->scene()->removeItem(sceneWallpaper); |
|
119 } |
|
120 } |
|
121 } |
|
122 |
|
123 qreal HsIdleWidget::sceneX() const |
|
124 { |
|
125 return mPageLayer->x(); |
|
126 } |
|
127 |
|
128 void HsIdleWidget::setSceneX(qreal x) |
|
129 { |
|
130 if (HSCONFIGURATION_GET(sceneType) == HsConfiguration::SceneWallpaper) { |
|
131 mPageLayer->setX(x); |
|
132 mSceneLayer->setX((parallaxFactor() * x) - HSCONFIGURATION_GET(bounceEffect) / 2); |
|
133 } else { |
|
134 mPageLayer->setX(x); |
|
135 mPageWallpaperLayer->setX(x); |
103 } |
136 } |
104 } |
137 } |
105 |
138 |
106 /*! |
139 /*! |
107 Layouts the ui layers according to the given \a rect. |
140 Layouts the ui layers according to the given \a rect. |
|
141 If given \a rect has different size than a fullscreen view, rect |
|
142 is lifted up by statuspane height. Normally HsIdleWidget position is 0,0 |
|
143 relative to it's parent container (HbView). This functionality tackles |
|
144 problem caused by HbStackedLayout which sets top most rect for all items |
|
145 (views) in a stack (not considering fullscreen mode). |
108 */ |
146 */ |
109 void HsIdleWidget::setGeometry(const QRectF &rect) |
147 void HsIdleWidget::setGeometry(const QRectF &rect) |
110 { |
148 { |
|
149 |
111 int n = HsScene::instance()->pages().count(); |
150 int n = HsScene::instance()->pages().count(); |
112 QRectF layoutRect(HsScene::instance()->mainWindow()->layoutRect()); |
151 QRectF layoutRect(HsScene::instance()->mainWindow()->layoutRect()); |
113 if (layoutRect == rect || (layoutRect.height() == rect.width() && layoutRect.width() == rect.height())) { |
152 if (layoutRect == rect || (layoutRect.height() == rect.width() && layoutRect.width() == rect.height())) { |
114 mControlLayer->resize(rect.size()); |
153 mControlLayer->resize(rect.size()); |
115 mPageLayer->resize(n * rect.width(), rect.height()); |
154 mPageLayer->resize(n * rect.width(), rect.height()); |
116 mSceneLayer->resize(2 * rect.width() + HsConfiguration::bounceEffect(), rect.height()); |
155 if (HSCONFIGURATION_GET(sceneType) == HsConfiguration::PageWallpapers) { |
117 HbWidget::setGeometry(rect); |
156 mPageWallpaperLayer->resize(n * rect.width(), rect.height()); |
118 } else { |
157 } |
119 QRectF sceneRect = mapToScene(rect).boundingRect(); |
158 mSceneLayer->resize(2 * rect.width() + HSCONFIGURATION_GET(bounceEffect), rect.height()); |
120 sceneRect.setTop(-sceneRect.top()); |
159 HbWidget::setGeometry(rect); |
121 HbWidget::setGeometry(sceneRect); |
160 } else { |
122 } |
161 QRectF sceneRect = mapToScene(rect).boundingRect(); |
123 } |
162 // HbView is a container item for widget, thus 0,0 is relative to view's position. |
124 |
163 // Lift rect by offset. Fullscreen view is in 0,0 position in scene coordinates otherwise |
125 /*! |
164 // it's e.g 0,68 (statuspane being at 0,0 and view at 0,68) |
126 Stores the given mouse press \a event. |
165 sceneRect.setTop(-sceneRect.top()); |
127 */ |
166 HbWidget::setGeometry(sceneRect); |
128 void HsIdleWidget::captureDelayedPress(QGraphicsSceneMouseEvent *event) |
167 } |
129 { |
168 } |
130 if (event) { |
169 |
131 mDelayedPressEvent = new QMouseEvent(QEvent::MouseButtonPress, |
170 /*! |
132 event->scenePos().toPoint(), Qt::LeftButton, Qt::LeftButton, Qt::NoModifier); |
171 Sets the active page \a index to the page |
133 mDelayedPressEvent->setAccepted(false); |
|
134 } |
|
135 } |
|
136 |
|
137 /*! |
|
138 Sends the stored mouse press event. |
|
139 */ |
|
140 void HsIdleWidget::sendDelayedPress() |
|
141 { |
|
142 if (mDelayedPressEvent) { |
|
143 QApplication::sendEvent(HsScene::mainWindow()->viewport(), mDelayedPressEvent); |
|
144 clearDelayedPress(); |
|
145 } |
|
146 } |
|
147 |
|
148 /*! |
|
149 Deletes the stored mouse press event. |
|
150 */ |
|
151 void HsIdleWidget::clearDelayedPress() |
|
152 { |
|
153 if (mDelayedPressEvent) { |
|
154 delete mDelayedPressEvent; |
|
155 mDelayedPressEvent = 0; |
|
156 } |
|
157 } |
|
158 |
|
159 /*! |
|
160 Sets the active page \a index to the page |
|
161 indicator. |
172 indicator. |
162 */ |
173 */ |
163 void HsIdleWidget::setActivePage(int index) |
174 void HsIdleWidget::setActivePage(int index) |
164 { |
175 { |
165 mPageIndicator->setActiveItemIndex(index); |
176 mPageIndicator->setActiveItemIndex(index); |
169 Inserts the given \a page at index position |
180 Inserts the given \a page at index position |
170 \a index in the page layer. |
181 \a index in the page layer. |
171 */ |
182 */ |
172 void HsIdleWidget::insertPage(int index, HsPage *page) |
183 void HsIdleWidget::insertPage(int index, HsPage *page) |
173 { |
184 { |
174 QGraphicsLinearLayout *layout = |
185 QGraphicsLinearLayout *layout = |
175 static_cast<QGraphicsLinearLayout *>(mPageLayer->layout()); |
186 static_cast<QGraphicsLinearLayout *>(mPageLayer->layout()); |
176 layout->insertItem(index, page); |
187 layout->insertItem(index, page); |
177 mPageLayer->resize( |
188 mPageLayer->resize( |
178 layout->count() * size().width(), size().height()); |
189 layout->count() * size().width(), size().height()); |
|
190 |
|
191 if (HSCONFIGURATION_GET(sceneType) == HsConfiguration::PageWallpapers) { |
|
192 QGraphicsLinearLayout *layout = |
|
193 static_cast<QGraphicsLinearLayout *>(mPageWallpaperLayer->layout()); |
|
194 layout->insertItem(index, page->wallpaper()); |
|
195 mPageWallpaperLayer->resize( |
|
196 layout->count() * size().width(), size().height()); |
|
197 } |
179 } |
198 } |
180 |
199 |
181 /*! |
200 /*! |
182 Removes the page at index position |
201 Removes the page at index position |
183 \a index in the page layer. |
202 \a index in the page layer. |
184 */ |
203 */ |
185 void HsIdleWidget::removePage(int index) |
204 void HsIdleWidget::removePage(int index) |
186 { |
205 { |
187 QGraphicsLinearLayout *layout = |
206 QGraphicsLinearLayout *layout = |
188 static_cast<QGraphicsLinearLayout *>(mPageLayer->layout()); |
207 static_cast<QGraphicsLinearLayout *>(mPageLayer->layout()); |
189 layout->removeAt(index); |
208 layout->removeAt(index); |
190 mPageLayer->resize( |
209 mPageLayer->resize( |
191 layout->count() * size().width(), size().height()); |
210 layout->count() * size().width(), size().height()); |
|
211 |
|
212 if (HSCONFIGURATION_GET(sceneType) == HsConfiguration::PageWallpapers) { |
|
213 QGraphicsLinearLayout *layout = |
|
214 static_cast<QGraphicsLinearLayout *>(mPageWallpaperLayer->layout()); |
|
215 layout->removeAt(index); |
|
216 mPageWallpaperLayer->resize( |
|
217 layout->count() * size().width(), size().height()); |
|
218 } |
192 } |
219 } |
193 |
220 |
194 /*! |
221 /*! |
195 \fn HsIdleWidget::controlLayer() const |
222 \fn HsIdleWidget::controlLayer() const |
196 |
223 |
217 |
244 |
218 /*! |
245 /*! |
219 \fn HsIdleWidget::pageIndicator() const |
246 \fn HsIdleWidget::pageIndicator() const |
220 |
247 |
221 Returns the page indicator widget. |
248 Returns the page indicator widget. |
222 */ |
|
223 |
|
224 /*! |
|
225 \fn HsIdleWidget::mousePressed(QGraphicsItem *, QGraphicsSceneMouseEvent *, bool &) |
|
226 |
|
227 The idle state connects to this signal for handling mouse |
|
228 press events. It filters events for the item \a watched. |
|
229 \a event is the filtered event. Sets the \a filtered true |
|
230 if the event was filtered by this handler. |
|
231 */ |
|
232 |
|
233 /*! |
|
234 \fn HsIdleWidget::mouseMoved(QGraphicsItem *, QGraphicsSceneMouseEvent *, bool &) |
|
235 |
|
236 The idle state connects to this signal for handling mouse |
|
237 move events. It filters events for the item \a watched. |
|
238 \a event is the filtered event. Sets the \a filtered true |
|
239 if the event was filtered by this handler. |
|
240 */ |
|
241 |
|
242 /*! |
|
243 \fn HsIdleWidget::mouseReleased(QGraphicsItem *, QGraphicsSceneMouseEvent *, bool &) |
|
244 |
|
245 The idle state connects to this signal for handling mouse |
|
246 release events. It filters events for the item \a watched. |
|
247 \a event is the filtered event. Sets the \a filtered true |
|
248 if the event was filtered by this handler. |
|
249 */ |
249 */ |
250 |
250 |
251 /*! |
251 /*! |
252 Sets the trashbin visible and hides the page indicator. |
252 Sets the trashbin visible and hides the page indicator. |
253 */ |
253 */ |
254 void HsIdleWidget::showTrashBin() |
254 void HsIdleWidget::showTrashBin() |
255 { |
255 { |
256 mPageIndicator->hide(); |
256 mPageIndicator->hide(); |
257 mTrashBin->show(); |
257 mTrashBin->show(); |
258 } |
258 } |
259 |
259 |
260 /*! |
260 /*! |
261 Sets the page indicator visible and hides the trashbin. |
261 Sets the page indicator visible and hides the trashbin. |
262 */ |
262 */ |
263 void HsIdleWidget::showPageIndicator() |
263 void HsIdleWidget::showPageIndicator() |
264 { |
264 { |
265 mTrashBin->hide(); |
265 mTrashBin->hide(); |
266 mTrashBin->deactivate(); |
266 mTrashBin->deactivate(); |
267 mPageIndicator->setSpacing(HsConfiguration::pageIndicatorSpacing()); // for usability optimization widget, can be removed later on |
267 mPageIndicator->setSpacing(HSCONFIGURATION_GET(pageIndicatorSpacing)); // for usability optimization widget, can be removed later on |
268 mPageIndicator->setVisible(1 < mPageIndicator->itemCount()); |
268 mPageIndicator->setVisible(1 < mPageIndicator->itemCount()); |
269 } |
269 } |
270 |
270 |
271 /*! |
271 /*! |
272 Filters the main window's graphics scene (\a object) \a event. |
272 Shows the Vertical snapping lines showing the guidance |
273 */ |
273 */ |
274 bool HsIdleWidget::eventFilter(QObject *object, QEvent *event) |
274 void HsIdleWidget::showVerticalSnapLine(const QLineF &snapLine) |
275 { |
275 { |
276 Q_UNUSED(object) |
276 QVariantHash snapConfiguration; |
277 |
277 snapConfiguration[SNAPLINEFADEINDURATION] = QString::number(HSCONFIGURATION_GET(snapLineFadeInDuration)); |
278 if (HbVkbHost::activeVkbHost()) { |
278 snapConfiguration[SNAPLINEFADEOUTDURATION] = QString::number(HSCONFIGURATION_GET(snapLineFadeOutDuration)); |
279 setFiltersChildEvents(false); |
279 |
280 return false; |
280 mVerticalSnapLine->setConfiguration(snapConfiguration); |
281 } |
281 mVerticalSnapLine->showLine(snapLine); |
282 |
282 } |
283 bool filtered = false; |
283 |
284 |
284 /*! |
285 switch (event->type()) { |
285 Shows the Horizontal snapping lines showing the guidance |
286 case QEvent::GraphicsSceneMousePress: |
286 */ |
287 if (mDelayedPressEvent && |
287 void HsIdleWidget::showHorizontalSnapLine(const QLineF &snapLine) |
288 scene()->mouseGrabberItem()) { |
288 { |
289 scene()->mouseGrabberItem()->ungrabMouse(); |
289 QVariantHash snapConfiguration; |
290 } |
290 snapConfiguration[SNAPLINEFADEINDURATION] = QString::number(HSCONFIGURATION_GET(snapLineFadeInDuration)); |
291 setFiltersChildEvents(!mDelayedPressEvent); |
291 snapConfiguration[SNAPLINEFADEOUTDURATION] = QString::number(HSCONFIGURATION_GET(snapLineFadeOutDuration)); |
292 break; |
292 |
293 case QEvent::GraphicsSceneMouseMove: |
293 mHorizontalSnapLine->setConfiguration(snapConfiguration); |
294 emit mouseMoved(0, static_cast<QGraphicsSceneMouseEvent *>(event), filtered); |
294 mHorizontalSnapLine->showLine(snapLine); |
295 break; |
295 } |
296 case QEvent::GraphicsSceneMouseRelease: |
296 |
297 setItemsFocusable(); |
297 /*! |
298 emit mouseReleased(0, static_cast<QGraphicsSceneMouseEvent *>(event), filtered); |
298 Hides the Vertical snapping line showing the guidance |
299 if (filtered && scene()->mouseGrabberItem()) { |
299 */ |
300 scene()->mouseGrabberItem()->ungrabMouse(); |
300 void HsIdleWidget::hideVerticalSnapLine() |
301 } |
301 { |
302 break; |
302 mVerticalSnapLine->hideLine(); |
303 default: |
303 } |
304 break; |
304 |
305 } |
305 /*! |
306 |
306 Hides the Horizontal snapping line showing the guidance |
307 return filtered; |
307 */ |
308 } |
308 void HsIdleWidget::hideHorizontalSnapLine() |
309 |
309 { |
310 /*! |
310 mHorizontalSnapLine->hideLine(); |
311 Filters events for the item \a watched. \a event is the filtered event. |
|
312 */ |
|
313 bool HsIdleWidget::sceneEventFilter(QGraphicsItem *watched, QEvent *event) |
|
314 { |
|
315 bool filtered = false; |
|
316 |
|
317 switch (event->type()) { |
|
318 case QEvent::GraphicsSceneMousePress: |
|
319 emit mousePressed(watched, static_cast<QGraphicsSceneMouseEvent *>(event), filtered); |
|
320 if (filtered) { |
|
321 setItemsUnfocusable(static_cast<QGraphicsSceneMouseEvent *>(event)); |
|
322 } |
|
323 break; |
|
324 default: |
|
325 break; |
|
326 } |
|
327 |
|
328 return filtered; |
|
329 } |
311 } |
330 |
312 |
331 /*! |
313 /*! |
332 Reimplements QGraphicsWidget::polishEvent(). |
314 Reimplements QGraphicsWidget::polishEvent(). |
333 */ |
315 */ |
334 void HsIdleWidget::polishEvent() |
316 void HsIdleWidget::polishEvent() |
335 { |
317 { |
336 HsScene *scene = HsScene::instance(); |
318 HsScene *scene = HsScene::instance(); |
337 Q_ASSERT(scene); |
319 Q_ASSERT(scene); |
338 |
320 |
339 QGraphicsLinearLayout *layout = |
321 QGraphicsLinearLayout *pageLayout = |
340 static_cast<QGraphicsLinearLayout *>(mPageLayer->layout()); |
322 static_cast<QGraphicsLinearLayout *>(mPageLayer->layout()); |
|
323 |
341 QList<HsPage *> pages = scene->pages(); |
324 QList<HsPage *> pages = scene->pages(); |
|
325 |
342 foreach (HsPage *page, pages) { |
326 foreach (HsPage *page, pages) { |
343 layout->addItem(page); |
327 pageLayout->addItem(page); |
344 } |
328 if (HSCONFIGURATION_GET(sceneType) == HsConfiguration::PageWallpapers) { |
345 |
329 QGraphicsLinearLayout *pageWallpaperLayout = |
346 layout = static_cast<QGraphicsLinearLayout *>(mSceneLayer->layout()); |
330 static_cast<QGraphicsLinearLayout *>(mPageWallpaperLayer->layout()); |
347 HsWallpaper *wallpaper = HsScene::instance()->wallpaper(); |
331 pageWallpaperLayout->addItem(page->wallpaper()); |
348 layout->addItem(wallpaper); |
332 } |
|
333 } |
|
334 if (HSCONFIGURATION_GET(sceneType) == HsConfiguration::SceneWallpaper) { |
|
335 QGraphicsLinearLayout *sceneLayout = |
|
336 static_cast<QGraphicsLinearLayout *>(mSceneLayer->layout()); |
|
337 HsWallpaper *wallpaper = HsScene::instance()->wallpaper(); |
|
338 sceneLayout->addItem(wallpaper); |
|
339 } |
349 |
340 |
350 mPageIndicator->initialize(pages.count(), scene->activePageIndex()); |
341 mPageIndicator->initialize(pages.count(), scene->activePageIndex()); |
351 showPageIndicator(); |
342 showPageIndicator(); |
352 |
343 |
353 HsScene::mainWindow()->scene()->installEventFilter(this); |
344 HsScene::mainWindow()->scene()->installEventFilter(this); |
374 loader.load(file, &loaded); |
365 loader.load(file, &loaded); |
375 if (!loaded) { |
366 if (!loaded) { |
376 loader.load(fallbackPath, &loaded); |
367 loader.load(fallbackPath, &loaded); |
377 } |
368 } |
378 } else { |
369 } else { |
379 loader.load(fallbackPath, &loaded); |
370 loader.load(fallbackPath, &loaded); |
380 } |
371 } |
381 |
372 |
382 if (loaded) { |
373 if (loaded) { |
383 mControlLayer = qobject_cast<HbWidget *>(loader.findWidget(gControlLayerName)); |
374 mControlLayer = qobject_cast<HbWidget *>(loader.findWidget(gControlLayerName)); |
384 mControlLayer->setZValue(2); |
375 mControlLayer->setZValue(3); |
385 mControlLayer->setParentItem(this); |
376 mControlLayer->setParentItem(this); |
386 |
377 |
387 mTrashBin = qobject_cast<HsTrashBinWidget *>(loader.findWidget(gTrashBinName)); |
378 mTrashBin = qobject_cast<HsTrashBinWidget *>(loader.findWidget(gTrashBinName)); |
388 mTrashBin->setZValue(1e6); |
379 mTrashBin->setZValue(1e6); |
389 |
380 |
390 mPageIndicator = qobject_cast<HsPageIndicator *>(loader.findWidget(gPageIndicatorName)); |
381 mPageIndicator = qobject_cast<HsPageIndicator *>(loader.findWidget(gPageIndicatorName)); |
391 mPageIndicator->setZValue(1e6); |
382 mPageIndicator->setZValue(1e6); |
|
383 |
|
384 |
|
385 mHorizontalSnapLine = new HsSnapLine(mControlLayer); |
|
386 mHorizontalSnapLine->setZValue(10); |
|
387 |
|
388 mVerticalSnapLine = new HsSnapLine(mControlLayer); |
|
389 mVerticalSnapLine->setZValue(10); |
392 } else { |
390 } else { |
393 // TODO: Handle error. |
391 // TODO: Handle error. |
394 } |
392 } |
395 } |
393 } |
396 |
394 |
397 /*! |
395 qreal HsIdleWidget::parallaxFactor() const |
398 Sets the items under the given mouse \a event scene position |
396 { |
399 unfocusable and stores the items. |
397 qreal clw = mControlLayer->size().width(); |
400 */ |
398 qreal slw = mSceneLayer->size().width() - HSCONFIGURATION_GET(bounceEffect); |
401 void HsIdleWidget::setItemsUnfocusable(QGraphicsSceneMouseEvent *event) |
399 int n = HsScene::instance()->pages().count(); |
402 { |
400 if (n < 2) { |
403 mFocusableItems.clear(); |
401 return 1; |
404 |
402 } else { |
405 if (!scene()) { |
403 return (slw - clw) / ((n - 1) * clw); |
406 return; |
404 } |
407 } |
405 } |
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 } |
|