30 #include "hswallpaper.h" |
30 #include "hswallpaper.h" |
31 #include "hstrashbinwidget.h" |
31 #include "hstrashbinwidget.h" |
32 #include "hspageindicator.h" |
32 #include "hspageindicator.h" |
33 #include "hsdocumentloader.h" |
33 #include "hsdocumentloader.h" |
34 #include "hsconfiguration.h" |
34 #include "hsconfiguration.h" |
|
35 #include "hsapp_defs.h" |
|
36 #include "hssnapline.h" |
35 |
37 |
36 namespace |
38 namespace |
37 { |
39 { |
38 const char gControlLayerDocmlName[] = "controllayer.docml"; |
40 const char gControlLayerDocmlName[] = "controllayer.docml"; |
39 const char gControlLayerName[] = "controlLayer"; |
41 const char gControlLayerName[] = "controlLayer"; |
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), mPageWallpaperLayer(0), |
61 mControlLayer(0), mPageLayer(0), mPageWallpaperLayer(0), |
60 mSceneLayer(0), 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 |
135 } |
136 } |
136 } |
137 } |
137 |
138 |
138 /*! |
139 /*! |
139 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). |
140 */ |
146 */ |
141 void HsIdleWidget::setGeometry(const QRectF &rect) |
147 void HsIdleWidget::setGeometry(const QRectF &rect) |
142 { |
148 { |
|
149 |
143 int n = HsScene::instance()->pages().count(); |
150 int n = HsScene::instance()->pages().count(); |
144 QRectF layoutRect(HsScene::instance()->mainWindow()->layoutRect()); |
151 QRectF layoutRect(HsScene::instance()->mainWindow()->layoutRect()); |
145 if (layoutRect == rect || (layoutRect.height() == rect.width() && layoutRect.width() == rect.height())) { |
152 if (layoutRect == rect || (layoutRect.height() == rect.width() && layoutRect.width() == rect.height())) { |
146 mControlLayer->resize(rect.size()); |
153 mControlLayer->resize(rect.size()); |
147 mPageLayer->resize(n * rect.width(), rect.height()); |
154 mPageLayer->resize(n * rect.width(), rect.height()); |
148 if (HSCONFIGURATION_GET(sceneType) == HsConfiguration::PageWallpapers) { |
155 if (HSCONFIGURATION_GET(sceneType) == HsConfiguration::PageWallpapers) { |
149 mPageWallpaperLayer->resize(n * rect.width(), rect.height()); |
156 mPageWallpaperLayer->resize(n * rect.width(), rect.height()); |
150 } |
157 } |
151 mSceneLayer->resize(2 * rect.width() + HSCONFIGURATION_GET(bounceEffect), rect.height()); |
158 mSceneLayer->resize(2 * rect.width() + HSCONFIGURATION_GET(bounceEffect), rect.height()); |
152 HbWidget::setGeometry(rect); |
159 HbWidget::setGeometry(rect); |
153 } else { |
160 } else { |
154 QRectF sceneRect = mapToScene(rect).boundingRect(); |
161 QRectF sceneRect = mapToScene(rect).boundingRect(); |
155 sceneRect.setTop(-sceneRect.top()); |
162 // HbView is a container item for widget, thus 0,0 is relative to view's position. |
156 HbWidget::setGeometry(sceneRect); |
163 // Lift rect by offset. Fullscreen view is in 0,0 position in scene coordinates otherwise |
157 } |
164 // it's e.g 0,68 (statuspane being at 0,0 and view at 0,68) |
158 } |
165 sceneRect.setTop(-sceneRect.top()); |
159 |
166 HbWidget::setGeometry(sceneRect); |
160 /*! |
|
161 Stores the given mouse press \a event. |
|
162 */ |
|
163 void HsIdleWidget::captureDelayedPress(QGraphicsSceneMouseEvent *event) |
|
164 { |
|
165 if (event) { |
|
166 mDelayedPressEvent = new QMouseEvent(QEvent::MouseButtonPress, |
|
167 event->scenePos().toPoint(), Qt::LeftButton, Qt::LeftButton, Qt::NoModifier); |
|
168 mDelayedPressEvent->setAccepted(false); |
|
169 } |
|
170 } |
|
171 |
|
172 /*! |
|
173 Sends the stored mouse press event. |
|
174 */ |
|
175 void HsIdleWidget::sendDelayedPress() |
|
176 { |
|
177 if (mDelayedPressEvent) { |
|
178 QApplication::sendEvent(HsScene::mainWindow()->viewport(), mDelayedPressEvent); |
|
179 clearDelayedPress(); |
|
180 } |
|
181 } |
|
182 |
|
183 /*! |
|
184 Deletes the stored mouse press event. |
|
185 */ |
|
186 void HsIdleWidget::clearDelayedPress() |
|
187 { |
|
188 if (mDelayedPressEvent) { |
|
189 delete mDelayedPressEvent; |
|
190 mDelayedPressEvent = 0; |
|
191 } |
167 } |
192 } |
168 } |
193 |
169 |
194 /*! |
170 /*! |
195 Sets the active page \a index to the page |
171 Sets the active page \a index to the page |
271 |
247 |
272 Returns the page indicator widget. |
248 Returns the page indicator widget. |
273 */ |
249 */ |
274 |
250 |
275 /*! |
251 /*! |
276 \fn HsIdleWidget::mousePressed(QGraphicsItem *, QGraphicsSceneMouseEvent *, bool &) |
|
277 |
|
278 The idle state connects to this signal for handling mouse |
|
279 press events. It filters events for the item \a watched. |
|
280 \a event is the filtered event. Sets the \a filtered true |
|
281 if the event was filtered by this handler. |
|
282 */ |
|
283 |
|
284 /*! |
|
285 \fn HsIdleWidget::mouseMoved(QGraphicsItem *, QGraphicsSceneMouseEvent *, bool &) |
|
286 |
|
287 The idle state connects to this signal for handling mouse |
|
288 move events. It filters events for the item \a watched. |
|
289 \a event is the filtered event. Sets the \a filtered true |
|
290 if the event was filtered by this handler. |
|
291 */ |
|
292 |
|
293 /*! |
|
294 \fn HsIdleWidget::mouseReleased(QGraphicsItem *, QGraphicsSceneMouseEvent *, bool &) |
|
295 |
|
296 The idle state connects to this signal for handling mouse |
|
297 release events. It filters events for the item \a watched. |
|
298 \a event is the filtered event. Sets the \a filtered true |
|
299 if the event was filtered by this handler. |
|
300 */ |
|
301 |
|
302 /*! |
|
303 Sets the trashbin visible and hides the page indicator. |
252 Sets the trashbin visible and hides the page indicator. |
304 */ |
253 */ |
305 void HsIdleWidget::showTrashBin() |
254 void HsIdleWidget::showTrashBin() |
306 { |
255 { |
307 mPageIndicator->hide(); |
256 mPageIndicator->hide(); |
318 mPageIndicator->setSpacing(HSCONFIGURATION_GET(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 |
319 mPageIndicator->setVisible(1 < mPageIndicator->itemCount()); |
268 mPageIndicator->setVisible(1 < mPageIndicator->itemCount()); |
320 } |
269 } |
321 |
270 |
322 /*! |
271 /*! |
323 Filters the main window's graphics scene (\a object) \a event. |
272 Shows the Vertical snapping lines showing the guidance |
324 */ |
273 */ |
325 bool HsIdleWidget::eventFilter(QObject *object, QEvent *event) |
274 void HsIdleWidget::showVerticalSnapLine(const QLineF &snapLine) |
326 { |
275 { |
327 Q_UNUSED(object) |
276 QVariantHash snapConfiguration; |
328 |
277 snapConfiguration[SNAPLINEFADEINDURATION] = QString::number(HSCONFIGURATION_GET(snapLineFadeInDuration)); |
329 bool filtered = false; |
278 snapConfiguration[SNAPLINEFADEOUTDURATION] = QString::number(HSCONFIGURATION_GET(snapLineFadeOutDuration)); |
330 |
279 |
331 switch (event->type()) { |
280 mVerticalSnapLine->setConfiguration(snapConfiguration); |
332 case QEvent::GraphicsSceneMousePress: |
281 mVerticalSnapLine->showLine(snapLine); |
333 if (HbVkbHost::activeVkbHost()) { |
282 } |
334 setFiltersChildEvents(false); |
283 |
335 break; |
284 /*! |
336 } |
285 Shows the Horizontal snapping lines showing the guidance |
337 if (mDelayedPressEvent && |
286 */ |
338 scene()->mouseGrabberItem()) { |
287 void HsIdleWidget::showHorizontalSnapLine(const QLineF &snapLine) |
339 scene()->mouseGrabberItem()->ungrabMouse(); |
288 { |
340 } |
289 QVariantHash snapConfiguration; |
341 setFiltersChildEvents(!mDelayedPressEvent); |
290 snapConfiguration[SNAPLINEFADEINDURATION] = QString::number(HSCONFIGURATION_GET(snapLineFadeInDuration)); |
342 break; |
291 snapConfiguration[SNAPLINEFADEOUTDURATION] = QString::number(HSCONFIGURATION_GET(snapLineFadeOutDuration)); |
343 case QEvent::GraphicsSceneMouseMove: |
292 |
344 emit mouseMoved(0, static_cast<QGraphicsSceneMouseEvent *>(event), filtered); |
293 mHorizontalSnapLine->setConfiguration(snapConfiguration); |
345 break; |
294 mHorizontalSnapLine->showLine(snapLine); |
346 case QEvent::GraphicsSceneMouseRelease: |
295 } |
347 emit mouseReleased(0, static_cast<QGraphicsSceneMouseEvent *>(event), filtered); |
296 |
348 if (filtered && scene()->mouseGrabberItem()) { |
297 /*! |
349 scene()->mouseGrabberItem()->ungrabMouse(); |
298 Hides the Vertical snapping line showing the guidance |
350 } |
299 */ |
351 break; |
300 void HsIdleWidget::hideVerticalSnapLine() |
352 default: |
301 { |
353 break; |
302 mVerticalSnapLine->hideLine(); |
354 } |
303 } |
355 |
304 |
356 return filtered; |
305 /*! |
357 } |
306 Hides the Horizontal snapping line showing the guidance |
358 |
307 */ |
359 /*! |
308 void HsIdleWidget::hideHorizontalSnapLine() |
360 Filters events for the item \a watched. \a event is the filtered event. |
309 { |
361 */ |
310 mHorizontalSnapLine->hideLine(); |
362 bool HsIdleWidget::sceneEventFilter(QGraphicsItem *watched, QEvent *event) |
|
363 { |
|
364 bool filtered = false; |
|
365 |
|
366 switch (event->type()) { |
|
367 case QEvent::GraphicsSceneMousePress: |
|
368 emit mousePressed(watched, static_cast<QGraphicsSceneMouseEvent *>(event), filtered); |
|
369 break; |
|
370 default: |
|
371 break; |
|
372 } |
|
373 |
|
374 return filtered; |
|
375 } |
311 } |
376 |
312 |
377 /*! |
313 /*! |
378 Reimplements QGraphicsWidget::polishEvent(). |
314 Reimplements QGraphicsWidget::polishEvent(). |
379 */ |
315 */ |
442 mTrashBin = qobject_cast<HsTrashBinWidget *>(loader.findWidget(gTrashBinName)); |
378 mTrashBin = qobject_cast<HsTrashBinWidget *>(loader.findWidget(gTrashBinName)); |
443 mTrashBin->setZValue(1e6); |
379 mTrashBin->setZValue(1e6); |
444 |
380 |
445 mPageIndicator = qobject_cast<HsPageIndicator *>(loader.findWidget(gPageIndicatorName)); |
381 mPageIndicator = qobject_cast<HsPageIndicator *>(loader.findWidget(gPageIndicatorName)); |
446 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); |
447 } else { |
390 } else { |
448 // TODO: Handle error. |
391 // TODO: Handle error. |
449 } |
392 } |
450 } |
393 } |
451 |
394 |