18 // System includes |
18 // System includes |
19 #include <hbgridview.h> |
19 #include <hbgridview.h> |
20 #include <hbabstractviewitem.h> |
20 #include <hbabstractviewitem.h> |
21 #include <hbstyleloader.h> |
21 #include <hbstyleloader.h> |
22 #include <hbcolorscheme.h> |
22 #include <hbcolorscheme.h> |
|
23 #include <hbpangesture.h> |
|
24 #include <hbswipegesture.h> |
23 |
25 |
24 // User includes |
26 // User includes |
25 #include "calenmonthgrid.h" |
27 #include "calenmonthgrid.h" |
26 #include "calengriditemprototype.h" |
28 #include "calengriditemprototype.h" |
27 #include "calenmonthdata.h" |
29 #include "calenmonthdata.h" |
28 #include "calenmonthview.h" |
30 #include "calenmonthview.h" |
29 #include "calendateutils.h" |
31 #include "calendateutils.h" |
30 #include "calencommon.h" |
32 #include "calencommon.h" |
31 |
33 |
32 // Constants |
34 // Constants |
33 #define SCROLL_SPEEED 2000 |
35 #define SCROLL_SPEEED 3000 |
34 #define GRIDLINE_WIDTH 0.075 //units |
36 #define GRIDLINE_WIDTH 0.075 //units |
35 |
37 |
36 /*! |
38 /*! |
37 \class CalenMonthGrid |
39 \class CalenMonthGrid |
38 |
40 |
290 } |
297 } |
291 } |
298 } |
292 } |
299 } |
293 |
300 |
294 /*! |
301 /*! |
295 Listens for down gesture |
302 Scrolls the content dowmwards |
296 */ |
303 */ |
297 void CalenMonthGrid::downGesture (int value) |
304 void CalenMonthGrid::downGesture() |
298 { |
305 { |
299 Q_UNUSED(value) |
306 mDirection = down; |
300 mDirection = down; |
307 mIsAtomicScroll = false; |
301 mIsAtomicScroll = false; |
308 setAttribute(Hb::InteractionDisabled); |
302 setAttribute(Hb::InteractionDisabled); |
309 QPointF targetPos(0.0, 0.0); |
303 |
310 scrollContentsTo(targetPos,500); |
304 // pass it to parent |
311 } |
305 HbScrollArea::downGesture(value); |
312 |
306 } |
313 /*! |
307 |
314 Scrolls the content upwards |
308 /*! |
315 */ |
309 Listens for Up gesture |
316 void CalenMonthGrid::upGesture() |
310 */ |
317 { |
311 void CalenMonthGrid::upGesture (int value) |
318 mDirection = up; |
312 { |
319 mIsAtomicScroll = false; |
313 Q_UNUSED(value) |
320 setAttribute(Hb::InteractionDisabled); |
314 mDirection = up; |
321 QPointF targetPos(0.0, mStartPos.y() - size().height()); |
315 mIsAtomicScroll = false; |
322 scrollContentsTo(-targetPos,500); |
316 setAttribute(Hb::InteractionDisabled); |
|
317 |
|
318 // pass it to parent |
|
319 HbScrollArea::upGesture(value); |
|
320 |
323 |
321 } |
324 } |
322 |
325 |
323 /*! |
326 /*! |
324 Function to listen mouse press events |
327 Function to listen mouse press events |
325 */ |
328 */ |
326 void CalenMonthGrid::mousePressEvent(QGraphicsSceneMouseEvent* event) |
329 void CalenMonthGrid::mousePressEvent(QGraphicsSceneMouseEvent* event) |
327 { |
330 { |
328 mPressedPos = event->pos(); |
|
329 // Pass it to parent |
331 // Pass it to parent |
330 HbGridView::mousePressEvent(event); |
332 HbGridView::mousePressEvent(event); |
331 } |
333 } |
332 |
334 |
333 /*! |
335 /*! |
334 Function to listen mouse release events |
336 Function to listen mouse release events |
335 */ |
337 */ |
336 void CalenMonthGrid::mouseReleaseEvent(QGraphicsSceneMouseEvent* event) |
338 void CalenMonthGrid::mouseReleaseEvent(QGraphicsSceneMouseEvent* event) |
337 { |
339 { |
338 int posDiff = mPressedPos.y() - event->pos().y(); |
340 // Pass it grid view if pan gesture is not in progress else pass it to |
339 if (posDiff < -50) { |
341 // scrollarea. Problem here is, if we pass to gridview when panning, then |
340 mDirection = down; |
342 // its emitting item activated signal simply becasue of which focus item |
341 } else if (posDiff > 50){ |
343 // is getting changed when you finish the pan / shake |
342 mDirection = up; |
|
343 } |
|
344 // Pass it to parent |
|
345 HbGridView::mouseReleaseEvent(event); |
|
346 } |
|
347 |
|
348 /*! |
|
349 Listens for pan gesture |
|
350 */ |
|
351 void CalenMonthGrid::panGesture(const QPointF & delta) |
|
352 { |
|
353 setAttribute(Hb::InteractionDisabled); |
|
354 mIsAtomicScroll = false; |
|
355 if (!mIsPanGesture) { |
344 if (!mIsPanGesture) { |
356 mIsPanGesture = true; |
345 HbGridView::mouseReleaseEvent(event); |
357 mIgnoreItemActivated = true; |
346 } else { |
358 mStartPos = mContentWidget->pos(); |
347 HbScrollArea::mouseReleaseEvent(event); |
359 // Get to know the direction of the gesture |
348 } |
360 if (delta.y() > 0) { |
349 } |
361 mDirection = down; |
350 |
362 } else { |
351 /*! |
363 mDirection = up; |
352 Function to list for all the gesture events |
364 } |
353 */ |
365 } |
354 void CalenMonthGrid::gestureEvent(QGestureEvent *event) |
366 |
355 { |
367 // Call the parent class to perform the pan gesture |
356 if(HbPanGesture *gesture = qobject_cast<HbPanGesture *>(event->gesture(Qt::PanGesture))) { |
368 // When scrolling finished, month grid will adjust to show the proper month |
357 if (gesture->state() == Qt::GestureStarted) { |
369 HbScrollArea::panGesture(delta); |
358 setAttribute(Hb::InteractionDisabled); |
|
359 mIsAtomicScroll = false; |
|
360 if (!mIsPanGesture) { |
|
361 mIsPanGesture = true; |
|
362 mIgnoreItemActivated = true; |
|
363 mStartPos = mContentWidget->pos(); |
|
364 // Get to know the direction of the gesture |
|
365 QPointF velocity = gesture->velocity(); |
|
366 if (velocity.y() > 0) { |
|
367 mDirection = down; |
|
368 } else { |
|
369 mDirection = up; |
|
370 } |
|
371 } |
|
372 } else if(gesture->state() == Qt::GestureFinished) { |
|
373 // TODO: Need to handle here to avoid followOn animation |
|
374 } |
|
375 } else if(HbSwipeGesture *gesture = qobject_cast<HbSwipeGesture *>(event->gesture(Qt::SwipeGesture))) { |
|
376 if (gesture->state() == Qt::GestureStarted) { |
|
377 setAttribute(Hb::InteractionDisabled); |
|
378 mIsAtomicScroll = false; |
|
379 if (gesture->swipeAngle() > 250 && gesture->swipeAngle() < 290 && |
|
380 gesture->verticalDirection() == QSwipeGesture::Down) { |
|
381 mDirection = down; |
|
382 } else if (gesture->swipeAngle() > 70 && gesture->swipeAngle() < 110 && |
|
383 gesture->verticalDirection() == QSwipeGesture::Up) { |
|
384 mDirection = up; |
|
385 } |
|
386 } |
|
387 gesture->setSpeed(SCROLL_SPEEED); |
|
388 } |
|
389 |
|
390 // Call the parent class to perform the pan gesture |
|
391 // When scrolling finished, month grid will adjust to show the proper month |
|
392 HbScrollArea::gestureEvent(event); |
370 } |
393 } |
371 |
394 |
372 /*! |
395 /*! |
373 Gets called when scrolling finishes to update the model |
396 Gets called when scrolling finishes to update the model |
374 */ |
397 */ |
375 void CalenMonthGrid::scrollingFinished() |
398 void CalenMonthGrid::scrollingFinished() |
376 { |
399 { |
377 |
|
378 if (mIsPanGesture) { |
400 if (mIsPanGesture) { |
379 handlePanGestureFinished(); |
401 handlePanGestureFinished(); |
380 } else if(!mIsAtomicScroll) { |
402 } else if(!mIsAtomicScroll) { |
381 QDateTime activeDate = mView->getActiveDay(); |
403 QDateTime activeDate = mView->getActiveDay(); |
382 if(mDirection == down) { // down gesture |
404 if(mDirection == down) { // down gesture |
424 // more than or equal to half of the future month |
446 // more than or equal to half of the future month |
425 if (date.date().day() > (activeMonth.date().daysInMonth()) / 2 || |
447 if (date.date().day() > (activeMonth.date().daysInMonth()) / 2 || |
426 date.addDays(KNumOfVisibleRows*KCalenDaysInWeek).date().day() >= |
448 date.addDays(KNumOfVisibleRows*KCalenDaysInWeek).date().day() >= |
427 (prevMonth.date().daysInMonth()) / 2) { |
449 (prevMonth.date().daysInMonth()) / 2) { |
428 // up gesture to bring the next month |
450 // up gesture to bring the next month |
429 upGesture(SCROLL_SPEEED); |
451 upGesture(); |
430 } else { |
452 } else { |
431 // we should again show the current month by scrolling downwards |
453 // we should again show the current month by scrolling downwards |
432 mDirection = down; |
454 mDirection = down; |
433 mIsAtomicScroll = true; |
455 mIsAtomicScroll = true; |
|
456 setAttribute(Hb::InteractionDisabled); |
434 scrollContentsTo(-mStartPos,500); |
457 scrollContentsTo(-mStartPos,500); |
435 } |
458 } |
436 } else if (month == prevMonth.date().month()) { |
459 } else if (month == prevMonth.date().month()) { |
437 // first visible item belongs to previous month |
460 // first visible item belongs to previous month |
438 // Check if the date is more than half of the previous month |
461 // Check if the date is more than half of the previous month |
439 if (date.date().day() > (prevMonth.date().daysInMonth()) / 2) { |
462 if (date.date().day() > (prevMonth.date().daysInMonth()) / 2) { |
440 // we should again show the current month by scrolling upwards |
463 // we should again show the current month by scrolling upwards |
441 mDirection = up; |
464 mDirection = up; |
442 mIsAtomicScroll = true; |
465 mIsAtomicScroll = true; |
|
466 setAttribute(Hb::InteractionDisabled); |
443 scrollContentsTo(-mStartPos,500); |
467 scrollContentsTo(-mStartPos,500); |
444 } else { |
468 } else { |
445 // down gesture to show the previous month |
469 // down gesture to show the previous month |
446 downGesture(SCROLL_SPEEED); |
470 downGesture(); |
447 } |
471 } |
|
472 } else if (month == prevMonth.addMonths(-1).date().month()) { |
|
473 // first visible date belong to previous to previous month |
|
474 // hence, scroll down to bring the previous month |
|
475 downGesture(); |
448 } else if (month == nextMonth.date().month()) { |
476 } else if (month == nextMonth.date().month()) { |
449 // first visible item belongs to next month |
477 // first visible item belongs to next month |
450 // Check if the date is more than half of the next month |
478 // Check if the date is more than half of the next month |
451 if (date.date().day() > (nextMonth.date().daysInMonth()) / 2) { |
479 if (date.date().day() > (nextMonth.date().daysInMonth()) / 2) { |
452 // up gesture to bring the next month |
480 // up gesture to bring the next month |
453 upGesture(SCROLL_SPEEED); |
481 upGesture(); |
454 } else { |
482 } else { |
455 // we should again show the current month by scrolling upwards |
483 // we should again show the current month by scrolling upwards |
456 mDirection = invalid; |
484 mDirection = invalid; |
|
485 setAttribute(Hb::InteractionDisabled); |
457 scrollContentsTo(-mStartPos,500); |
486 scrollContentsTo(-mStartPos,500); |
458 } |
487 } |
|
488 } else if (month == nextMonth.addMonths(1).date().month()) { |
|
489 // first visible date belongs to next to next month |
|
490 // hence, scroll up to show the next month |
|
491 upGesture(); |
459 } |
492 } |
460 } |
493 } |
461 |
494 |
462 /*! |
495 /*! |
463 Called when down gesture is performed. Adds the new previous month details |
496 Called when down gesture is performed. Adds the new previous month details |
711 // Launch the agenda view |
750 // Launch the agenda view |
712 mView->launchDayView(); |
751 mView->launchDayView(); |
713 } else { |
752 } else { |
714 // Reset the focus attribute to this item |
753 // Reset the focus attribute to this item |
715 QModelIndex itemIndex = mModel->index(mCurrentRow,0); |
754 QModelIndex itemIndex = mModel->index(mCurrentRow,0); |
|
755 if(itemIndex.row() < 0 || itemIndex.row() >= mModel->rowCount() || |
|
756 itemIndex.column() < 0 || itemIndex.column() > mModel->columnCount()) { |
|
757 return; |
|
758 } |
716 QVariant itemData = itemIndex.data(Qt::UserRole + 1); |
759 QVariant itemData = itemIndex.data(Qt::UserRole + 1); |
717 QVariantList list = itemData.toList(); |
760 QVariantList list = itemData.toList(); |
718 list.replace(CalendarNamespace::CalendarMonthFocusRole, false); |
761 list.replace(CalendarNamespace::CalendarMonthFocusRole, false); |
719 mModel->itemFromIndex(itemIndex)->setData(list); |
762 mModel->itemFromIndex(itemIndex)->setData(list); |
720 |
763 |