calendarui/views/src/calenpreviewpane.cpp
changeset 55 2c54b51f39c4
parent 51 0b38fc5b94c6
child 57 bb2d3e476f29
equal deleted inserted replaced
51:0b38fc5b94c6 55:2c54b51f39c4
    27 #include <hbframedrawer.h>
    27 #include <hbframedrawer.h>
    28 #include <hbfontspec.h>
    28 #include <hbfontspec.h>
    29 #include <hbcolorscheme.h>
    29 #include <hbcolorscheme.h>
    30 #include <hbtapgesture.h>
    30 #include <hbtapgesture.h>
    31 #include <hbpangesture.h>
    31 #include <hbpangesture.h>
       
    32 #include <hbinstance.h>
       
    33 #include <hbinstantfeedback.h>
    32 #include <agendautil.h>
    34 #include <agendautil.h>
    33 #include <agendaentry.h>
    35 #include <agendaentry.h>
    34 
    36 
    35 //user includes
    37 //user includes
    36 #include "calenagendautils.h"
    38 #include "calenagendautils.h"
    49 
    51 
    50 // Macros
    52 // Macros
    51 #define TWO_SECONDS_TIMER 2000 // millseconds
    53 #define TWO_SECONDS_TIMER 2000 // millseconds
    52 #define SCROLLING_SPEED 10
    54 #define SCROLLING_SPEED 10
    53 #define MAX_PAN_DIRECTION_THRESHOLD 50
    55 #define MAX_PAN_DIRECTION_THRESHOLD 50
    54 #define MIN_PAN_DIRECTION_THRESHOLD 20
    56 #define MIN_PAN_DIRECTION_THRESHOLD 10
    55 
    57 
    56 static const QString EMPTYSTRING(" ");
    58 static const QString EMPTYSTRING(" ");
    57 
    59 
    58 /*!
    60 /*!
    59  Constructor
    61  Constructor
    78 	
    80 	
    79 	// Connect the scrollig finished signal
    81 	// Connect the scrollig finished signal
    80 	connect(this, SIGNAL(scrollingEnded()), this,
    82 	connect(this, SIGNAL(scrollingEnded()), this,
    81 				SLOT(scrollingFinished()));
    83 				SLOT(scrollingFinished()));
    82 	
    84 	
       
    85 	grabGesture(Qt::TapGesture);
       
    86 	grabGesture(Qt::PanGesture);
       
    87 
    83 	OstTraceFunctionExit0( CALENPREVIEWPANE_CALENPREVIEWPANE_EXIT );
    88 	OstTraceFunctionExit0( CALENPREVIEWPANE_CALENPREVIEWPANE_EXIT );
    84 }
    89 }
    85 
    90 
    86 /*!
    91 /*!
    87  Destructor
    92  Destructor
   174 				label = mLabelList.at(i);
   179 				label = mLabelList.at(i);
   175 				count--;
   180 				count--;
   176 			}
   181 			}
   177 			QString summary = mInstanceArray[i].summary();
   182 			QString summary = mInstanceArray[i].summary();
   178 			if(!summary.length()) {
   183 			if(!summary.length()) {
   179 				// No summary display "No subject"
   184 				// No summary display "Unnamed"
   180 				summary.append(hbTrId("txt_calendar_dblist_unnamed"));
   185 				summary.append(hbTrId("txt_calendar_preview_unnamed"));
   181 			}
   186 			}
   182 			// Check the entry type, based on the type display time field in
   187 			// Check the entry type, based on the type display time field in
   183 			// preview pane.
   188 			// preview pane.
   184 			QString start;
   189 			QString start;
   185 			if(mInstanceArray[i].type() != AgendaEntry::TypeTodo && 
   190 			if(mInstanceArray[i].type() != AgendaEntry::TypeTodo && 
   186 					mInstanceArray[i].type() != AgendaEntry::TypeAnniversary) {
   191 					mInstanceArray[i].type() != AgendaEntry::TypeAnniversary && 
       
   192 					mInstanceArray[i].type() != AgendaEntry::TypeEvent) {
   187 				QDateTime startTime = mInstanceArray[i].startTime();
   193 				QDateTime startTime = mInstanceArray[i].startTime();
       
   194 				// Check if event starts in past
       
   195 				checkStartTimeOfEvent(startTime);
   188 				HbExtendedLocale systemLocale =HbExtendedLocale::system();
   196 				HbExtendedLocale systemLocale =HbExtendedLocale::system();
   189 				start = systemLocale.format(startTime.time(), 
   197 				start = systemLocale.format(startTime.time(), 
   190 				                                    r_qtn_time_usual_with_zero);
   198 				                                    r_qtn_time_usual_with_zero);
   191 				start.append(EMPTYSTRING);	
   199 				start.append(EMPTYSTRING);	
   192 			}
   200 			}
   359 void CalenPreviewPane::gestureEvent(QGestureEvent *event)
   367 void CalenPreviewPane::gestureEvent(QGestureEvent *event)
   360 {
   368 {
   361     OstTraceFunctionEntry0( CALENPREVIEWPANE_GESTUREEVENT_ENTRY );
   369     OstTraceFunctionEntry0( CALENPREVIEWPANE_GESTUREEVENT_ENTRY );
   362     
   370     
   363     if(HbPanGesture *gesture = qobject_cast<HbPanGesture *>(event->gesture(Qt::PanGesture))) {
   371     if(HbPanGesture *gesture = qobject_cast<HbPanGesture *>(event->gesture(Qt::PanGesture))) {
   364         if (gesture->state() == Qt::GestureStarted) {
   372         if (gesture->state() == Qt::GestureUpdated) {
   365             // TODO: This work aroung till framework provides an api
   373             // TODO: This work around till framework provides an api
   366             // to know the direciton of the pan, until then we need
   374             // to know the direciton of the pan, until then we need
   367             // calculate the direction explicitly
   375             // calculate the direction explicitly
   368             // Get to know the direction of the gesture
   376             // Get to know the direction of the gesture
   369             QPointF delta = gesture->delta();
   377             QPointF delta = gesture->delta();
   370             if (abs(delta.y()) > MAX_PAN_DIRECTION_THRESHOLD) {
   378             // Check the current orientation of the device and
   371                 // Now see if y coord diff has crossed threshold
   379             // swap the vertical and horizontal distances in landscape
   372                 if (delta.x() > MAX_PAN_DIRECTION_THRESHOLD) {
   380             qreal horizontalDiff = 0.0;
       
   381             qreal verticalDiff = 0.0;
       
   382             if (hbInstance->allMainWindows().at(0)->orientation() == Qt::Vertical) {
       
   383                 horizontalDiff = delta.x();
       
   384                 verticalDiff = delta.y();
       
   385             } else {
       
   386                 horizontalDiff = delta.y();
       
   387                 verticalDiff = delta.x();
       
   388             }
       
   389             if (abs(verticalDiff) > MAX_PAN_DIRECTION_THRESHOLD) {
       
   390                 // Now see if x coord diff has crossed threshold
       
   391                 if (horizontalDiff > MAX_PAN_DIRECTION_THRESHOLD) {
   373                     mIsGestureHandled = true;
   392                     mIsGestureHandled = true;
   374                     // right gesture
   393                     // right gesture
   375                     mView->handlePreviewPaneGesture(true);
   394                     mView->handlePreviewPaneGesture(true);
   376                     event->accept(Qt::PanGesture);
   395                     event->accept(Qt::PanGesture);
   377                 } else if (delta.x() < -MAX_PAN_DIRECTION_THRESHOLD){
   396                 } else if (horizontalDiff < -MAX_PAN_DIRECTION_THRESHOLD){
   378                     mIsGestureHandled = true;
   397                     mIsGestureHandled = true;
   379                     // left gesture
   398                     // left gesture
   380                     mView->handlePreviewPaneGesture(false);
   399                     mView->handlePreviewPaneGesture(false);
   381                     event->accept(Qt::PanGesture);
   400                     event->accept(Qt::PanGesture);
   382                 } else {
   401                 } else {
   383                     event->accept(Qt::PanGesture);
   402                     event->accept(Qt::PanGesture);
   384                     OstTraceFunctionExit0( CALENPREVIEWPANE_GESTUREEVENT_EXIT );
   403                     OstTraceFunctionExit0( CALENPREVIEWPANE_GESTUREEVENT_EXIT );
   385                     return;
   404                     return;
   386                 }
   405                 }
   387             } else if (abs(delta.y()) < MAX_PAN_DIRECTION_THRESHOLD) {
   406             } else if (abs(verticalDiff) < MAX_PAN_DIRECTION_THRESHOLD) {
   388                if (delta.x() > MIN_PAN_DIRECTION_THRESHOLD) {
   407                if (horizontalDiff > MIN_PAN_DIRECTION_THRESHOLD) {
   389                    mIsGestureHandled = true;
   408                    mIsGestureHandled = true;
   390                    // right gesture
   409                    // right gesture
   391                    mView->handlePreviewPaneGesture(true);
   410                    mView->handlePreviewPaneGesture(true);
   392                    event->accept(Qt::PanGesture);
   411                    event->accept(Qt::PanGesture);
   393                } else if (delta.x() < -MIN_PAN_DIRECTION_THRESHOLD){
   412                } else if (horizontalDiff < -MIN_PAN_DIRECTION_THRESHOLD){
   394                    mIsGestureHandled = true;
   413                    mIsGestureHandled = true;
   395                    // left gesture
   414                    // left gesture
   396                    mView->handlePreviewPaneGesture(false);
   415                    mView->handlePreviewPaneGesture(false);
   397                    event->accept(Qt::PanGesture);
   416                    event->accept(Qt::PanGesture);
   398                }else {
   417                }else {
   400                    OstTraceFunctionExit0( DUP1_CALENPREVIEWPANE_GESTUREEVENT_EXIT );
   419                    OstTraceFunctionExit0( DUP1_CALENPREVIEWPANE_GESTUREEVENT_EXIT );
   401                    return;
   420                    return;
   402                }
   421                }
   403             }
   422             }
   404         }
   423         }
   405     } else if(HbTapGesture *gesture = qobject_cast<HbTapGesture *>(event->gesture(Qt::TapGesture))) {
   424     } else if(QTapGesture *tapGesture = qobject_cast<QTapGesture *>(event->gesture(Qt::TapGesture))) {
   406         if (gesture->state() == Qt::GestureFinished) {
   425         if (tapGesture && tapGesture->state() == Qt::GestureFinished) {
   407             if (gesture->tapStyleHint() == HbTapGesture::Tap) {
   426             	HbInstantFeedback::play(HbFeedback::Basic);
   408                 // Preview pane tapped
   427                 // Preview pane tapped
   409                 mServices.IssueCommandL(ECalenAgendaView);
   428                 mServices.IssueCommandL(ECalenAgendaView);
   410                 event->accept(Qt::TapGesture);
   429                 event->accept(Qt::TapGesture);
   411             }
       
   412         }
   430         }
   413     }
   431     }
   414     
   432     
   415     OstTraceFunctionExit0( DUP2_CALENPREVIEWPANE_GESTUREEVENT_EXIT );
   433     OstTraceFunctionExit0( DUP2_CALENPREVIEWPANE_GESTUREEVENT_EXIT );
   416 }
   434 }
   443 	}
   461 	}
   444 	
   462 	
   445 	OstTraceFunctionExit0( CALENPREVIEWPANE_STOPSCROLLING_EXIT );
   463 	OstTraceFunctionExit0( CALENPREVIEWPANE_STOPSCROLLING_EXIT );
   446 }
   464 }
   447 
   465 
       
   466 /*!
       
   467  Checks if the start time of the event falls on the date for which preview
       
   468  pane is being shown. If start time is in past, then time will be 12:00AM
       
   469  */
       
   470 void CalenPreviewPane::checkStartTimeOfEvent(QDateTime &dateTime)
       
   471 {
       
   472     // If event start time is in past
       
   473     if (dateTime.date() < mDate.date()) {
       
   474         // Set the time to 12:00AM of mDate
       
   475         dateTime.setDate(mDate.date());
       
   476         QTime time(0,0,0,0); // 0 means 12:00 AM
       
   477         dateTime.setTime(time);
       
   478     }
       
   479 }
       
   480 
   448 // End of file  --Don't remove this.
   481 // End of file  --Don't remove this.