calendarui/views/src/calenpreviewpane.cpp
changeset 50 579cc610882e
parent 49 5de72ea7a065
child 58 ef813d54df51
equal deleted inserted replaced
49:5de72ea7a065 50:579cc610882e
    43 #include "calenmonthview.h"
    43 #include "calenmonthview.h"
    44 
    44 
    45 // Macros
    45 // Macros
    46 #define TWO_SECONDS_TIMER 2000 // millseconds
    46 #define TWO_SECONDS_TIMER 2000 // millseconds
    47 #define SCROLLING_SPEED 10
    47 #define SCROLLING_SPEED 10
       
    48 #define MAX_PAN_DIRECTION_THRESHOLD 50
       
    49 #define MIN_PAN_DIRECTION_THRESHOLD 20
    48 
    50 
    49 static const QString EMPTYSTRING(" ");
    51 static const QString EMPTYSTRING(" ");
    50 
    52 
    51 /*!
    53 /*!
    52  Constructor
    54  Constructor
   313  */
   315  */
   314 void CalenPreviewPane::gestureEvent(QGestureEvent *event)
   316 void CalenPreviewPane::gestureEvent(QGestureEvent *event)
   315 {
   317 {
   316     if(HbPanGesture *gesture = qobject_cast<HbPanGesture *>(event->gesture(Qt::PanGesture))) {
   318     if(HbPanGesture *gesture = qobject_cast<HbPanGesture *>(event->gesture(Qt::PanGesture))) {
   317         if (gesture->state() == Qt::GestureStarted) {
   319         if (gesture->state() == Qt::GestureStarted) {
       
   320             // TODO: This work aroung till framework provides an api
       
   321             // to know the direciton of the pan, until then we need
       
   322             // calculate the direction explicitly
   318             // Get to know the direction of the gesture
   323             // Get to know the direction of the gesture
   319         	QPointF delta = gesture->sceneDelta();
   324             QPointF delta = gesture->delta();
   320             if (delta.x() > 20) {
   325             if (abs(delta.y()) > MAX_PAN_DIRECTION_THRESHOLD) {
   321                 mIsGestureHandled = true;
   326                 // Now see if y coord diff has crossed threshold
   322                 // right gesture
   327                 if (delta.x() > MAX_PAN_DIRECTION_THRESHOLD) {
   323                 mView->handlePreviewPaneGesture(true);
   328                     mIsGestureHandled = true;
   324                 event->accept(Qt::PanGesture);
   329                     // right gesture
   325             } else if (delta.x() < -20){
   330                     mView->handlePreviewPaneGesture(true);
   326                 mIsGestureHandled = true;
   331                     event->accept(Qt::PanGesture);
   327                 // left gesture
   332                 } else if (delta.x() < -MAX_PAN_DIRECTION_THRESHOLD){
   328                 mView->handlePreviewPaneGesture(false);
   333                     mIsGestureHandled = true;
   329                 event->accept(Qt::PanGesture);
   334                     // left gesture
       
   335                     mView->handlePreviewPaneGesture(false);
       
   336                     event->accept(Qt::PanGesture);
       
   337                 } else {
       
   338                     event->accept(Qt::PanGesture);
       
   339                     return;
       
   340                 }
       
   341             } else if (abs(delta.y()) < MAX_PAN_DIRECTION_THRESHOLD) {
       
   342                if (delta.x() > MIN_PAN_DIRECTION_THRESHOLD) {
       
   343                    mIsGestureHandled = true;
       
   344                    // right gesture
       
   345                    mView->handlePreviewPaneGesture(true);
       
   346                    event->accept(Qt::PanGesture);
       
   347                } else if (delta.x() < -MIN_PAN_DIRECTION_THRESHOLD){
       
   348                    mIsGestureHandled = true;
       
   349                    // left gesture
       
   350                    mView->handlePreviewPaneGesture(false);
       
   351                    event->accept(Qt::PanGesture);
       
   352                }else {
       
   353                    event->accept(Qt::PanGesture);
       
   354                    return;
       
   355                }
   330             }
   356             }
   331         }
   357         }
   332     } else if(HbTapGesture *gesture = qobject_cast<HbTapGesture *>(event->gesture(Qt::TapGesture))) {
   358     } else if(HbTapGesture *gesture = qobject_cast<HbTapGesture *>(event->gesture(Qt::TapGesture))) {
   333         if (gesture->state() == Qt::GestureFinished) {
   359         if (gesture->state() == Qt::GestureFinished) {
   334             if (gesture->tapStyleHint() == HbTapGesture::Tap) {
   360             if (gesture->tapStyleHint() == HbTapGesture::Tap) {
   335                 // Preview pane tapped
   361                 // Preview pane tapped
   336                 mServices.IssueCommandL(ECalenDayView);
   362                 mServices.IssueCommandL(ECalenAgendaView);
   337                 event->accept(Qt::TapGesture);
   363                 event->accept(Qt::TapGesture);
   338             }
   364             }
   339         }
   365         }
   340     }
   366     }
   341 }
   367 }