39 #include "calenservices.h" |
41 #include "calenservices.h" |
40 #include "calenservices.h" |
42 #include "calenservices.h" |
41 #include "calencommon.h" |
43 #include "calencommon.h" |
42 #include "calenpreviewpane.h" |
44 #include "calenpreviewpane.h" |
43 #include "calenmonthview.h" |
45 #include "calenmonthview.h" |
|
46 #include "OstTraceDefinitions.h" |
|
47 #ifdef OST_TRACE_COMPILER_IN_USE |
|
48 #include "calenpreviewpaneTraces.h" |
|
49 #endif |
|
50 |
44 |
51 |
45 // Macros |
52 // Macros |
46 #define TWO_SECONDS_TIMER 2000 // millseconds |
53 #define TWO_SECONDS_TIMER 2000 // millseconds |
47 #define SCROLLING_SPEED 10 |
54 #define SCROLLING_SPEED 10 |
48 #define MAX_PAN_DIRECTION_THRESHOLD 50 |
55 #define MAX_PAN_DIRECTION_THRESHOLD 50 |
49 #define MIN_PAN_DIRECTION_THRESHOLD 20 |
56 #define MIN_PAN_DIRECTION_THRESHOLD 10 |
50 |
57 |
51 static const QString EMPTYSTRING(" "); |
58 static const QString EMPTYSTRING(" "); |
52 |
59 |
53 /*! |
60 /*! |
54 Constructor |
61 Constructor |
55 */ |
62 */ |
56 CalenPreviewPane::CalenPreviewPane(MCalenServices& services, |
63 CalenPreviewPane::CalenPreviewPane(MCalenServices& services, |
57 QGraphicsItem* parent) |
64 QGraphicsItem* parent) |
58 : HbScrollArea(parent),mServices(services) |
65 : HbScrollArea(parent),mServices(services) |
59 { |
66 { |
|
67 OstTraceFunctionEntry0( CALENPREVIEWPANE_CALENPREVIEWPANE_ENTRY ); |
|
68 |
60 // Create the timer |
69 // Create the timer |
61 mTwoSecTimer = new QTimer(this); |
70 mTwoSecTimer = new QTimer(this); |
62 mScrollDirection = invalid; |
71 mScrollDirection = invalid; |
63 mIsNoEntriesAdded = true; |
72 mIsNoEntriesAdded = true; |
64 mIsGestureHandled = false; |
73 mIsGestureHandled = false; |
70 setVerticalScrollBarPolicy(HbScrollArea::ScrollBarAlwaysOff); |
79 setVerticalScrollBarPolicy(HbScrollArea::ScrollBarAlwaysOff); |
71 |
80 |
72 // Connect the scrollig finished signal |
81 // Connect the scrollig finished signal |
73 connect(this, SIGNAL(scrollingEnded()), this, |
82 connect(this, SIGNAL(scrollingEnded()), this, |
74 SLOT(scrollingFinished())); |
83 SLOT(scrollingFinished())); |
|
84 |
|
85 grabGesture(Qt::TapGesture); |
|
86 grabGesture(Qt::PanGesture); |
|
87 |
|
88 OstTraceFunctionExit0( CALENPREVIEWPANE_CALENPREVIEWPANE_EXIT ); |
75 } |
89 } |
76 |
90 |
77 /*! |
91 /*! |
78 Destructor |
92 Destructor |
79 */ |
93 */ |
80 CalenPreviewPane::~CalenPreviewPane() |
94 CalenPreviewPane::~CalenPreviewPane() |
81 { |
95 { |
|
96 OstTraceFunctionEntry0( DUP1_CALENPREVIEWPANE_CALENPREVIEWPANE_ENTRY ); |
|
97 |
|
98 OstTraceFunctionExit0( DUP1_CALENPREVIEWPANE_CALENPREVIEWPANE_EXIT ); |
82 } |
99 } |
83 |
100 |
84 /*! |
101 /*! |
85 Stores the "No Entries for today" label |
102 Stores the "No Entries for today" label |
86 */ |
103 */ |
87 void CalenPreviewPane::setNoEntriesLabel(HbLabel* label) |
104 void CalenPreviewPane::setNoEntriesLabel(HbLabel* label) |
88 { |
105 { |
|
106 OstTraceFunctionEntry0( CALENPREVIEWPANE_SETNOENTRIESLABEL_ENTRY ); |
|
107 |
89 mNoEntriesLabel = label; |
108 mNoEntriesLabel = label; |
|
109 |
|
110 OstTraceFunctionExit0( CALENPREVIEWPANE_SETNOENTRIESLABEL_EXIT ); |
90 } |
111 } |
91 |
112 |
92 /*! |
113 /*! |
93 Populates the preview with proper data |
114 Populates the preview with proper data |
94 */ |
115 */ |
95 void CalenPreviewPane::populateLabel(QDateTime date) |
116 void CalenPreviewPane::populateLabel(QDateTime date) |
96 { |
117 { |
|
118 OstTraceFunctionEntry0( CALENPREVIEWPANE_POPULATELABEL_ENTRY ); |
|
119 |
97 mScrollDirection = up; |
120 mScrollDirection = up; |
98 |
121 |
99 // Scroll contents to zero position before we display to the user |
122 // Scroll contents to zero position before we display to the user |
100 // if it was scrolling already or timer was running |
123 // if it was scrolling already or timer was running |
101 mNumOfScrolls = 0; |
124 mNumOfScrolls = 0; |
230 AgendaUtil::IncludeEvents | |
262 AgendaUtil::IncludeEvents | |
231 AgendaUtil::IncludeIncompletedTodos | |
263 AgendaUtil::IncludeIncompletedTodos | |
232 AgendaUtil::IncludeReminders); |
264 AgendaUtil::IncludeReminders); |
233 mInstanceArray = mServices.agendaInterface()-> |
265 mInstanceArray = mServices.agendaInterface()-> |
234 createEntryIdListForDay(dayStart, filter); |
266 createEntryIdListForDay(dayStart, filter); |
|
267 |
|
268 OstTraceFunctionExit0( CALENPREVIEWPANE_GETINSTANCELISTL_EXIT ); |
235 } |
269 } |
236 |
270 |
237 /*! |
271 /*! |
238 Returns the date which this preview pane is representing |
272 Returns the date which this preview pane is representing |
239 */ |
273 */ |
240 QDateTime CalenPreviewPane::Date() |
274 QDateTime CalenPreviewPane::Date() |
241 { |
275 { |
|
276 OstTraceFunctionEntry0( CALENPREVIEWPANE_DATE_ENTRY ); |
|
277 |
|
278 OstTraceFunctionExit0( CALENPREVIEWPANE_DATE_EXIT ); |
242 return mDate; |
279 return mDate; |
243 } |
280 } |
244 |
281 |
245 /*! |
282 /*! |
246 Starts the auto scroll on the preview pane |
283 Starts the auto scroll on the preview pane |
247 */ |
284 */ |
248 void CalenPreviewPane::startAutoScroll() |
285 void CalenPreviewPane::startAutoScroll() |
249 { |
286 { |
|
287 OstTraceFunctionEntry0( CALENPREVIEWPANE_STARTAUTOSCROLL_ENTRY ); |
|
288 |
250 if (mIsNoEntriesAdded) { |
289 if (mIsNoEntriesAdded) { |
251 scrollContentsTo(QPointF(0.0,0.0)); |
290 scrollContentsTo(QPointF(0.0,0.0)); |
|
291 OstTraceFunctionExit0( CALENPREVIEWPANE_STARTAUTOSCROLL_EXIT ); |
252 return; |
292 return; |
253 } |
293 } |
254 |
294 |
255 // Start the 2 seconds timer |
295 // Start the 2 seconds timer |
256 mTwoSecTimer->setSingleShot(true); |
296 mTwoSecTimer->setSingleShot(true); |
257 connect(mTwoSecTimer, SIGNAL(timeout()), this, SLOT(onTwoSecondsTimeout())); |
297 connect(mTwoSecTimer, SIGNAL(timeout()), this, SLOT(onTwoSecondsTimeout())); |
258 mTwoSecTimer->start(TWO_SECONDS_TIMER); |
298 mTwoSecTimer->start(TWO_SECONDS_TIMER); |
|
299 |
|
300 OstTraceFunctionExit0( DUP1_CALENPREVIEWPANE_STARTAUTOSCROLL_EXIT ); |
259 } |
301 } |
260 |
302 |
261 /*! |
303 /*! |
262 Slot to handle two seconds timer time out |
304 Slot to handle two seconds timer time out |
263 Starts the scrolling animation in required direction |
305 Starts the scrolling animation in required direction |
264 */ |
306 */ |
265 void CalenPreviewPane::onTwoSecondsTimeout() |
307 void CalenPreviewPane::onTwoSecondsTimeout() |
266 { |
308 { |
|
309 OstTraceFunctionEntry0( CALENPREVIEWPANE_ONTWOSECONDSTIMEOUT_ENTRY ); |
|
310 |
267 mTwoSecTimer->stop(); |
311 mTwoSecTimer->stop(); |
268 disconnect(mTwoSecTimer, SIGNAL(timeout()), |
312 disconnect(mTwoSecTimer, SIGNAL(timeout()), |
269 this, SLOT(onTwoSecondsTimeout())); |
313 this, SLOT(onTwoSecondsTimeout())); |
270 |
314 |
271 // Calculate the timer and the height difference of pane and its content |
315 // Calculate the timer and the height difference of pane and its content |
290 mNumOfScrolls++; |
334 mNumOfScrolls++; |
291 // Start scrolling downwards |
335 // Start scrolling downwards |
292 QPointF targetPos(0.0, 0.0); |
336 QPointF targetPos(0.0, 0.0); |
293 scrollContentsTo(targetPos, mScrollDuration * 1000); |
337 scrollContentsTo(targetPos, mScrollDuration * 1000); |
294 } |
338 } |
|
339 |
|
340 OstTraceFunctionExit0( CALENPREVIEWPANE_ONTWOSECONDSTIMEOUT_EXIT ); |
295 } |
341 } |
296 |
342 |
297 /*! |
343 /*! |
298 Slot to handle scrolling finished |
344 Slot to handle scrolling finished |
299 Restarts the two seconds timer |
345 Restarts the two seconds timer |
300 */ |
346 */ |
301 void CalenPreviewPane::scrollingFinished() |
347 void CalenPreviewPane::scrollingFinished() |
302 { |
348 { |
|
349 OstTraceFunctionEntry0( CALENPREVIEWPANE_SCROLLINGFINISHED_ENTRY ); |
|
350 |
303 // If we are here because of calling scrollContentsTo() |
351 // If we are here because of calling scrollContentsTo() |
304 if (!mNumOfScrolls) { |
352 if (!mNumOfScrolls) { |
|
353 OstTraceFunctionExit0( CALENPREVIEWPANE_SCROLLINGFINISHED_EXIT ); |
305 return; |
354 return; |
306 } |
355 } |
307 // Now start the two seconds timer again |
356 // Now start the two seconds timer again |
308 mTwoSecTimer->setSingleShot(true); |
357 mTwoSecTimer->setSingleShot(true); |
309 connect(mTwoSecTimer, SIGNAL(timeout()), this, SLOT(onTwoSecondsTimeout())); |
358 connect(mTwoSecTimer, SIGNAL(timeout()), this, SLOT(onTwoSecondsTimeout())); |
310 mTwoSecTimer->start(TWO_SECONDS_TIMER); |
359 mTwoSecTimer->start(TWO_SECONDS_TIMER); |
|
360 |
|
361 OstTraceFunctionExit0( DUP1_CALENPREVIEWPANE_SCROLLINGFINISHED_EXIT ); |
311 } |
362 } |
312 |
363 |
313 /*! |
364 /*! |
314 Function to listen for all gestures |
365 Function to listen for all gestures |
315 */ |
366 */ |
316 void CalenPreviewPane::gestureEvent(QGestureEvent *event) |
367 void CalenPreviewPane::gestureEvent(QGestureEvent *event) |
317 { |
368 { |
|
369 OstTraceFunctionEntry0( CALENPREVIEWPANE_GESTUREEVENT_ENTRY ); |
|
370 |
318 if(HbPanGesture *gesture = qobject_cast<HbPanGesture *>(event->gesture(Qt::PanGesture))) { |
371 if(HbPanGesture *gesture = qobject_cast<HbPanGesture *>(event->gesture(Qt::PanGesture))) { |
319 if (gesture->state() == Qt::GestureStarted) { |
372 if (gesture->state() == Qt::GestureUpdated) { |
320 // TODO: This work aroung till framework provides an api |
373 // Check if effect is not yet completed, ignore the current gesture if it is |
|
374 if (mIsGestureHandled) { |
|
375 OstTraceFunctionExit0( CALENPREVIEWPANE_GESTUREEVENT_EXIT ); |
|
376 return; |
|
377 } |
|
378 // TODO: This work around till framework provides an api |
321 // to know the direciton of the pan, until then we need |
379 // to know the direciton of the pan, until then we need |
322 // calculate the direction explicitly |
380 // calculate the direction explicitly |
323 // Get to know the direction of the gesture |
381 // Get to know the direction of the gesture |
324 QPointF delta = gesture->delta(); |
382 QPointF delta = gesture->delta(); |
325 if (abs(delta.y()) > MAX_PAN_DIRECTION_THRESHOLD) { |
383 // Check the current orientation of the device and |
326 // Now see if y coord diff has crossed threshold |
384 // swap the vertical and horizontal distances in landscape |
327 if (delta.x() > MAX_PAN_DIRECTION_THRESHOLD) { |
385 qreal horizontalDiff = 0.0; |
|
386 qreal verticalDiff = 0.0; |
|
387 if (hbInstance->allMainWindows().at(0)->orientation() == Qt::Vertical) { |
|
388 horizontalDiff = delta.x(); |
|
389 verticalDiff = delta.y(); |
|
390 } else { |
|
391 horizontalDiff = delta.y(); |
|
392 verticalDiff = delta.x(); |
|
393 } |
|
394 if (abs(verticalDiff) > MAX_PAN_DIRECTION_THRESHOLD) { |
|
395 // Now see if x coord diff has crossed threshold |
|
396 if (horizontalDiff > MAX_PAN_DIRECTION_THRESHOLD) { |
328 mIsGestureHandled = true; |
397 mIsGestureHandled = true; |
329 // right gesture |
398 // right gesture |
330 mView->handlePreviewPaneGesture(true); |
399 mView->handlePreviewPaneGesture(true); |
331 event->accept(Qt::PanGesture); |
400 event->accept(Qt::PanGesture); |
332 } else if (delta.x() < -MAX_PAN_DIRECTION_THRESHOLD){ |
401 } else if (horizontalDiff < -MAX_PAN_DIRECTION_THRESHOLD){ |
333 mIsGestureHandled = true; |
402 mIsGestureHandled = true; |
334 // left gesture |
403 // left gesture |
335 mView->handlePreviewPaneGesture(false); |
404 mView->handlePreviewPaneGesture(false); |
336 event->accept(Qt::PanGesture); |
405 event->accept(Qt::PanGesture); |
337 } else { |
406 } else { |
338 event->accept(Qt::PanGesture); |
407 event->accept(Qt::PanGesture); |
|
408 OstTraceFunctionExit0( DUP1_CALENPREVIEWPANE_GESTUREEVENT_EXIT ); |
339 return; |
409 return; |
340 } |
410 } |
341 } else if (abs(delta.y()) < MAX_PAN_DIRECTION_THRESHOLD) { |
411 } else if (abs(verticalDiff) < MAX_PAN_DIRECTION_THRESHOLD) { |
342 if (delta.x() > MIN_PAN_DIRECTION_THRESHOLD) { |
412 if (horizontalDiff > MIN_PAN_DIRECTION_THRESHOLD) { |
343 mIsGestureHandled = true; |
413 mIsGestureHandled = true; |
344 // right gesture |
414 // right gesture |
345 mView->handlePreviewPaneGesture(true); |
415 mView->handlePreviewPaneGesture(true); |
346 event->accept(Qt::PanGesture); |
416 event->accept(Qt::PanGesture); |
347 } else if (delta.x() < -MIN_PAN_DIRECTION_THRESHOLD){ |
417 } else if (horizontalDiff < -MIN_PAN_DIRECTION_THRESHOLD){ |
348 mIsGestureHandled = true; |
418 mIsGestureHandled = true; |
349 // left gesture |
419 // left gesture |
350 mView->handlePreviewPaneGesture(false); |
420 mView->handlePreviewPaneGesture(false); |
351 event->accept(Qt::PanGesture); |
421 event->accept(Qt::PanGesture); |
352 }else { |
422 }else { |
353 event->accept(Qt::PanGesture); |
423 event->accept(Qt::PanGesture); |
|
424 OstTraceFunctionExit0( DUP2_CALENPREVIEWPANE_GESTUREEVENT_EXIT ); |
354 return; |
425 return; |
355 } |
426 } |
356 } |
427 } |
357 } |
428 } |
358 } else if(HbTapGesture *gesture = qobject_cast<HbTapGesture *>(event->gesture(Qt::TapGesture))) { |
429 } else if(QTapGesture *tapGesture = qobject_cast<QTapGesture *>(event->gesture(Qt::TapGesture))) { |
359 if (gesture->state() == Qt::GestureFinished) { |
430 if (tapGesture && tapGesture->state() == Qt::GestureFinished) { |
360 if (gesture->tapStyleHint() == HbTapGesture::Tap) { |
431 HbInstantFeedback::play(HbFeedback::Basic); |
361 // Preview pane tapped |
432 // Preview pane tapped |
362 mServices.IssueCommandL(ECalenAgendaView); |
433 mServices.IssueCommandL(ECalenAgendaView); |
363 event->accept(Qt::TapGesture); |
434 event->accept(Qt::TapGesture); |
364 } |
|
365 } |
435 } |
366 } |
436 } |
|
437 |
|
438 OstTraceFunctionExit0( DUP2_CALENPREVIEWPANE_GESTUREEVENT_EXIT ); |
367 } |
439 } |
368 |
440 |
369 /*! |
441 /*! |
370 Set monthview pointer |
442 Set monthview pointer |
371 */ |
443 */ |
372 void CalenPreviewPane::setView(CalenMonthView* view) |
444 void CalenPreviewPane::setView(CalenMonthView* view) |
373 { |
445 { |
|
446 OstTraceFunctionEntry0( CALENPREVIEWPANE_SETVIEW_ENTRY ); |
|
447 |
374 mView = view; |
448 mView = view; |
|
449 |
|
450 OstTraceFunctionExit0( CALENPREVIEWPANE_SETVIEW_EXIT ); |
375 } |
451 } |
376 |
452 |
377 /*! |
453 /*! |
378 Stops the auto scrolling |
454 Stops the auto scrolling |
379 */ |
455 */ |
380 void CalenPreviewPane::stopScrolling() |
456 void CalenPreviewPane::stopScrolling() |
381 { |
457 { |
|
458 OstTraceFunctionEntry0( CALENPREVIEWPANE_STOPSCROLLING_ENTRY ); |
|
459 |
382 if (isScrolling() || mTwoSecTimer->isActive()) { |
460 if (isScrolling() || mTwoSecTimer->isActive()) { |
383 scrollContentsTo(QPointF(0.0,0.0)); |
461 scrollContentsTo(QPointF(0.0,0.0)); |
384 |
462 |
385 // Call pan gesture with zero delta just to stop the scfrolling |
463 // Call pan gesture with zero delta just to stop the scfrolling |
386 HbScrollArea::panGesture(QPointF(0.0,0.0)); |
464 HbScrollArea::panGesture(QPointF(0.0,0.0)); |
387 mTwoSecTimer->stop(); |
465 mTwoSecTimer->stop(); |
388 } |
466 } |
|
467 |
|
468 OstTraceFunctionExit0( CALENPREVIEWPANE_STOPSCROLLING_EXIT ); |
|
469 } |
|
470 |
|
471 /*! |
|
472 Checks if the start time of the event falls on the date for which preview |
|
473 pane is being shown. If start time is in past, then time will be 12:00AM |
|
474 */ |
|
475 void CalenPreviewPane::checkStartTimeOfEvent(QDateTime &dateTime) |
|
476 { |
|
477 // If event start time is in past |
|
478 if (dateTime.date() < mDate.date()) { |
|
479 // Set the time to 12:00AM of mDate |
|
480 dateTime.setDate(mDate.date()); |
|
481 QTime time(0,0,0,0); // 0 means 12:00 AM |
|
482 dateTime.setTime(time); |
|
483 } |
|
484 } |
|
485 |
|
486 /*! |
|
487 Sets the effect beign handled flag to true |
|
488 */ |
|
489 void CalenPreviewPane::effectStarted() |
|
490 { |
|
491 mIsGestureHandled = true; |
|
492 } |
|
493 |
|
494 /*! |
|
495 Resets the effect beign handled flag to true |
|
496 */ |
|
497 void CalenPreviewPane::effectFinished() |
|
498 { |
|
499 mIsGestureHandled = false; |
389 } |
500 } |
390 |
501 |
391 // End of file --Don't remove this. |
502 // End of file --Don't remove this. |