calendarui/views/src/calenpreviewpane.cpp
changeset 32 ea672fcb0ea0
parent 23 fd30d51f876b
child 49 5de72ea7a065
--- a/calendarui/views/src/calenpreviewpane.cpp	Fri May 14 15:51:09 2010 +0300
+++ b/calendarui/views/src/calenpreviewpane.cpp	Thu May 27 12:51:15 2010 +0300
@@ -27,6 +27,8 @@
 #include <hbframedrawer.h>
 #include <hbfontspec.h>
 #include <hbcolorscheme.h>
+#include <hbtapgesture.h>
+#include <hbpangesture.h>
 #include <agendautil.h>
 #include <agendaentry.h>
 
@@ -42,7 +44,7 @@
 
 // Macros
 #define TWO_SECONDS_TIMER 2000 // millseconds
-#define SCROLLING_SPEED 50
+#define SCROLLING_SPEED 10
 
 static const QString EMPTYSTRING(" ");
 
@@ -59,6 +61,8 @@
 	mIsNoEntriesAdded = true;
 	mIsGestureHandled = false;
 	mNoEntriesLabel = 0;
+	mHtDiff = 0.0;
+	mScrollDuration = 0;
 	setAcceptDrops(true);
 	setScrollDirections(Qt::Vertical);
 	setVerticalScrollBarPolicy(HbScrollArea::ScrollBarAlwaysOff);
@@ -101,7 +105,7 @@
 	GetInstanceListL();
 	
 	// Get the content of the scroll area
-	QGraphicsWidget* content = this->contentWidget();
+	QGraphicsWidget* content = contentWidget();
 	// Adjust the layout
 	QGraphicsLinearLayout* layout = static_cast<QGraphicsLinearLayout *>
 															(content->layout());
@@ -154,11 +158,16 @@
 				// No summary display "No subject"
 				summary.append(hbTrId("txt_calendar_dblist_unnamed"));
 			}
-			QDateTime startTime = mInstanceArray[i].startTime();
-			HbExtendedLocale systemLocale =HbExtendedLocale::system();
-			QString start = systemLocale.format(startTime.time(), 
-			                                    r_qtn_time_usual_with_zero);
-			start.append(EMPTYSTRING);
+			// Chcek the entry type, based on the type display time field in
+			// preview pane.
+			QString start;
+			if(mInstanceArray[i].type() != AgendaEntry::TypeTodo ) {
+				QDateTime startTime = mInstanceArray[i].startTime();
+				HbExtendedLocale systemLocale =HbExtendedLocale::system();
+				start = systemLocale.format(startTime.time(), 
+				                                    r_qtn_time_usual_with_zero);
+				start.append(EMPTYSTRING);	
+			}
 			// Append summary to start time
 			QString text = start.append(summary);
 			label->setPlainText(text);
@@ -259,17 +268,30 @@
 	mTwoSecTimer->stop();
 	disconnect(mTwoSecTimer, SIGNAL(timeout()), 
 										   this, SLOT(onTwoSecondsTimeout()));
-	// Start the scrolling in the proper direction
+	
+	// Calculate the timer and the height difference of pane and its content
+	if (!mScrollDuration) {
+        qreal contentHeight = contentWidget()->size().height();
+        qreal paneHeight = size().height();
+        mHtDiff = contentHeight - paneHeight;
+        if (mHtDiff > 0) { // content is more than widget height, we need to scroll
+            mScrollDuration = mHtDiff / SCROLLING_SPEED;
+        }
+	}
+	
+    // Start the scrolling in the proper direction
 	if (mScrollDirection == up) {
 		// Start scrolling upwards
 		mScrollDirection = down;
 		mNumOfScrolls++;
-		upGesture(SCROLLING_SPEED);
+		QPointF targetPos(0.0, -mHtDiff);
+        scrollContentsTo(-targetPos, mScrollDuration * 1000);
 	} else if (mScrollDirection == down) {
 		mScrollDirection = up;
 		mNumOfScrolls++;
 		// Start scrolling downwards
-		downGesture(SCROLLING_SPEED);
+		QPointF targetPos(0.0, 0.0);
+        scrollContentsTo(targetPos, mScrollDuration * 1000);
 	}
 }
 
@@ -290,44 +312,35 @@
 }
 
 /*!
- Function to listen mouse press events
+    Function to listen for all gestures
  */
-void CalenPreviewPane::mousePressEvent(QGraphicsSceneMouseEvent* event)
-{
-	mIsGestureHandled = false;
-	mPressedPos = event->pos();
-	event->accept();
-}
-
-/*!
- Function to listen mouse release events
- */
-void CalenPreviewPane::mouseReleaseEvent(QGraphicsSceneMouseEvent* event)
+void CalenPreviewPane::gestureEvent(QGestureEvent *event)
 {
-	qreal posDiff = mPressedPos.x()-event->pos().x();
-	if (abs(posDiff) < 50 && !mIsGestureHandled) {
-		// Preview pane tapped
-		mServices.IssueCommandL(ECalenDayView);
-	}
-	event->accept();
-}
-
-/*!
- Function to listen mouse move events
- */
-void CalenPreviewPane::mouseMoveEvent(QGraphicsSceneMouseEvent* event)
-{
-	qreal posDiff = mPressedPos.x()-event->pos().x();
-	if (posDiff < -50) {
-		mIsGestureHandled = true;
-		// right gesture
-		mView->handlePreviewPaneGesture(true);
-	} else if (posDiff > 50) {
-		mIsGestureHandled = true;
-		// left gesture
-		mView->handlePreviewPaneGesture(false);
-	}
-	event->accept();
+    if(HbPanGesture *gesture = qobject_cast<HbPanGesture *>(event->gesture(Qt::PanGesture))) {
+        if (gesture->state() == Qt::GestureStarted) {
+            // Get to know the direction of the gesture
+        	QPointF delta = gesture->sceneDelta();
+            if (delta.x() > 20) {
+                mIsGestureHandled = true;
+                // right gesture
+                mView->handlePreviewPaneGesture(true);
+                event->accept(Qt::PanGesture);
+            } else if (delta.x() < -20){
+                mIsGestureHandled = true;
+                // left gesture
+                mView->handlePreviewPaneGesture(false);
+                event->accept(Qt::PanGesture);
+            }
+        }
+    } else if(HbTapGesture *gesture = qobject_cast<HbTapGesture *>(event->gesture(Qt::TapGesture))) {
+        if (gesture->state() == Qt::GestureFinished) {
+            if (gesture->tapStyleHint() == HbTapGesture::Tap) {
+                // Preview pane tapped
+                mServices.IssueCommandL(ECalenDayView);
+                event->accept(Qt::TapGesture);
+            }
+        }
+    }
 }
 
 /*!