calendarui/views/src/calenmonthgrid.cpp
changeset 58 ef813d54df51
parent 50 579cc610882e
child 68 a5a1242fd2e8
--- a/calendarui/views/src/calenmonthgrid.cpp	Tue Jul 06 14:14:56 2010 +0300
+++ b/calendarui/views/src/calenmonthgrid.cpp	Wed Aug 18 09:47:38 2010 +0300
@@ -22,7 +22,9 @@
 #include <hbcolorscheme.h>
 #include <hbpangesture.h>
 #include <hbswipegesture.h>
+#include <hbtapgesture.h>
 #include <hbdeviceprofile.h>
+#include <hbinstance.h>
 
 // User includes
 #include "calenmonthgrid.h"
@@ -32,6 +34,11 @@
 #include "calendateutils.h"
 #include "calencommon.h"
 #include "calenconstants.h"
+#include "OstTraceDefinitions.h"
+#ifdef OST_TRACE_COMPILER_IN_USE
+#include "calenmonthgridTraces.h"
+#endif
+
 
 // Constants
 #define SCROLL_SPEEED 3000 
@@ -60,6 +67,8 @@
 	mIgnoreItemActivated(false),
 	mGridBorderColor(Qt::gray)
 {
+    OstTraceFunctionEntry0( CALENMONTHGRID_CALENMONTHGRID_ENTRY );
+    
 	setScrollDirections(Qt::Vertical);
 	setRowCount(KNumOfVisibleRows);
 	setColumnCount(KCalenDaysInWeek);
@@ -92,6 +101,8 @@
 	// Connect to scrolling finished signal
 	connect(this, SIGNAL(scrollingEnded()), this,
 			SLOT(scrollingFinished()));
+	
+	OstTraceFunctionExit0( CALENMONTHGRID_CALENMONTHGRID_EXIT );
 }
 
 /*!
@@ -99,7 +110,11 @@
  */
 CalenMonthGrid::~CalenMonthGrid()
 {
+    OstTraceFunctionEntry0( DUP1_CALENMONTHGRID_CALENMONTHGRID_ENTRY );
+    
 	// Nothing Yet
+    
+    OstTraceFunctionExit0( DUP1_CALENMONTHGRID_CALENMONTHGRID_EXIT );
 }
 
 /*!
@@ -107,7 +122,11 @@
  */
 void CalenMonthGrid::setView(CalenMonthView *view)
 {
+    OstTraceFunctionEntry0( CALENMONTHGRID_SETVIEW_ENTRY );
+    
 	mView = view;
+	
+	OstTraceFunctionExit0( CALENMONTHGRID_SETVIEW_EXIT );
 }
 
 /*!
@@ -116,6 +135,8 @@
 void CalenMonthGrid::updateMonthGridModel(QList<CalenMonthData> &monthDataArray,
                         int indexToBeScrolled, bool isFirstTime)
 {
+    OstTraceFunctionEntry0( CALENMONTHGRID_UPDATEMONTHGRIDMODEL_ENTRY );
+    
 	int loopStart = 0;
 	int loopEnd = monthDataArray.count();
 	if (isFirstTime) {
@@ -242,7 +263,8 @@
 		QModelIndex lastVisibleIndex = mModel->index(indexToBeScrolled, 0);
 		scrollTo(lastVisibleIndex);
 	}
-	mMonthDataArray = monthDataArray;
+	
+	OstTraceFunctionExit0( CALENMONTHGRID_UPDATEMONTHGRIDMODEL_EXIT );
 }
 
 /*!
@@ -252,7 +274,7 @@
 void CalenMonthGrid::updateMonthGridWithInActiveMonths(
 										QList<CalenMonthData> &monthDataArray)
 {	
-	mMonthDataArray = monthDataArray;
+    OstTraceFunctionEntry0( CALENMONTHGRID_UPDATEMONTHGRIDWITHINACTIVEMONTHS_ENTRY );
 		
 	// Prepend the required rows
 	handlePrependingRows(monthDataArray);
@@ -282,6 +304,8 @@
 	// is tapped.
 	connect(this, SIGNAL(activated(const QModelIndex &)), this,
 						SLOT(itemActivated(const QModelIndex &)));
+	
+	OstTraceFunctionExit0( CALENMONTHGRID_UPDATEMONTHGRIDWITHINACTIVEMONTHS_EXIT );
 }
 
 /*!
@@ -290,8 +314,10 @@
 void CalenMonthGrid::updateMonthGridWithEventIndicators(
 										QList<CalenMonthData> &monthDataArray)
 {
-	mMonthDataArray = monthDataArray;
-	for(int i = 0; i < monthDataArray.count(); i++) {
+    OstTraceFunctionEntry0( CALENMONTHGRID_UPDATEMONTHGRIDWITHEVENTINDICATORS_ENTRY );
+    
+	int count(monthDataArray.count());
+	for(int i = 0; i < count; i++) {
 		// Check if the day has events
 		if (monthDataArray[i].HasEvents()) {
 			QModelIndex itemIndex = mModel->index(i,0);
@@ -301,6 +327,8 @@
 			mModel->itemFromIndex(itemIndex)->setData(list);
 		}
 	}
+	
+	OstTraceFunctionExit0( CALENMONTHGRID_UPDATEMONTHGRIDWITHEVENTINDICATORS_EXIT );
 }
 
 /*!
@@ -308,6 +336,8 @@
  */
 void CalenMonthGrid::downGesture()
 {
+    OstTraceFunctionEntry0( CALENMONTHGRID_DOWNGESTURE_ENTRY );
+    
     // Make sure that content widget is properly placed
     if (mIsNonActiveDayFocused) {
         mIsAtomicScroll = true;
@@ -320,6 +350,8 @@
     setAttribute(Hb::InteractionDisabled);
     QPointF targetPos(0.0, 0.0);
     scrollContentsTo(targetPos,500);
+    
+    OstTraceFunctionExit0( CALENMONTHGRID_DOWNGESTURE_EXIT );
 }
 
 /*!
@@ -327,6 +359,8 @@
  */
 void CalenMonthGrid::upGesture()
 {
+    OstTraceFunctionEntry0( CALENMONTHGRID_UPGESTURE_ENTRY );
+    
     // Make sure that content widget is properly placed
     if (mIsNonActiveDayFocused) {
         mIsAtomicScroll = true;
@@ -341,6 +375,7 @@
     QPointF targetPos(0.0, mStartPos.y() - size().height());
     scrollContentsTo(-targetPos,500);
 	
+    OstTraceFunctionExit0( CALENMONTHGRID_UPGESTURE_EXIT );
 }
 
 /*!
@@ -348,8 +383,12 @@
  */
 void CalenMonthGrid::mousePressEvent(QGraphicsSceneMouseEvent* event)
 {
+    OstTraceFunctionEntry0( CALENMONTHGRID_MOUSEPRESSEVENT_ENTRY );
+    
 	// Pass it to parent
 	HbGridView::mousePressEvent(event);
+	
+	OstTraceFunctionExit0( CALENMONTHGRID_MOUSEPRESSEVENT_EXIT );
 }
 
 /*!
@@ -357,6 +396,8 @@
  */
 void CalenMonthGrid::mouseReleaseEvent(QGraphicsSceneMouseEvent* event)
 {
+    OstTraceFunctionEntry0( CALENMONTHGRID_MOUSERELEASEEVENT_ENTRY );
+    
 	// Pass it grid view if pan gesture is not in progress else pass it to
 	// scrollarea. Problem here is, if we pass to gridview when panning, then 
 	// its emitting item activated signal simply becasue of which focus item
@@ -366,6 +407,8 @@
 	} else {
 		HbScrollArea::mouseReleaseEvent(event);
 	}
+	
+	OstTraceFunctionExit0( CALENMONTHGRID_MOUSERELEASEEVENT_EXIT );
 }
 
 /*!
@@ -373,6 +416,8 @@
  */
 void CalenMonthGrid::gestureEvent(QGestureEvent *event)
 {
+    OstTraceFunctionEntry0( CALENMONTHGRID_GESTUREEVENT_ENTRY );
+    
    if(HbPanGesture *gesture = qobject_cast<HbPanGesture *>(event->gesture(Qt::PanGesture))) {
         if (gesture->state() == Qt::GestureStarted) {
             setAttribute(Hb::InteractionDisabled);
@@ -388,31 +433,44 @@
                 // frm orbit side is made clever enough not to scroll in other direction
                 // apart frm the registered scroll direction
                 QPointF delta = gesture->delta();
-                if (abs(delta.x()) > MAX_PAN_DIRECTION_THRESHOLD) {
+                // Check the current orientation of the device and
+                // swap the vertical and horizontal distances in landscape
+                qreal horizontalDiff = 0.0;
+                qreal verticalDiff = 0.0;
+                if (hbInstance->allMainWindows().at(0)->orientation() == Qt::Vertical) {
+                    horizontalDiff = delta.x();
+                    verticalDiff = delta.y();
+                } else {
+                    horizontalDiff = delta.y();
+                    verticalDiff = delta.x();
+                }
+                if (abs(horizontalDiff) > MAX_PAN_DIRECTION_THRESHOLD) {
                     // Now see if y coord diff has crossed threshold
-                    if (delta.y() > MAX_PAN_DIRECTION_THRESHOLD) {
+                    if (verticalDiff > MAX_PAN_DIRECTION_THRESHOLD) {
                         mIsPanGesture = true;
                         mIgnoreItemActivated = true;
                         mDirection = down;
-                    } else if (delta.y() < -MAX_PAN_DIRECTION_THRESHOLD){
+                    } else if (verticalDiff < -MAX_PAN_DIRECTION_THRESHOLD){
                         mIsPanGesture = true;
                         mIgnoreItemActivated = true;
                         mDirection = up;
                     } else {
                         event->accept(Qt::PanGesture);
+                        OstTraceFunctionExit0( CALENMONTHGRID_GESTUREEVENT_EXIT );
                         return;
                     }
-                } else if (abs(delta.x()) < MAX_PAN_DIRECTION_THRESHOLD) {
-                   if (delta.y() > MIN_PAN_DIRECTION_THRESHOLD) {
+                } else if (abs(horizontalDiff) < MAX_PAN_DIRECTION_THRESHOLD) {
+                   if (verticalDiff > MIN_PAN_DIRECTION_THRESHOLD) {
                         mIsPanGesture = true;
                         mIgnoreItemActivated = true;
                         mDirection = down;
-                   } else if (delta.y() < -MIN_PAN_DIRECTION_THRESHOLD){
+                   } else if (verticalDiff < -MIN_PAN_DIRECTION_THRESHOLD){
                         mIsPanGesture = true;
                         mIgnoreItemActivated = true;
                         mDirection = up;
                    }else {
                        event->accept(Qt::PanGesture);
+                       OstTraceFunctionExit0( DUP1_CALENMONTHGRID_GESTUREEVENT_EXIT );
                        return;
                    }
                 } 
@@ -429,9 +487,20 @@
                 mDirection = up;
             } else {
                 event->accept(Qt::SwipeGesture);
+                OstTraceFunctionExit0( DUP2_CALENMONTHGRID_GESTUREEVENT_EXIT );
                 return;
             }
         }
+    } else if (HbTapGesture *gesture = qobject_cast<HbTapGesture *>(event->gesture(Qt::TapGesture))) {
+        if(gesture->state() == Qt::GestureFinished) {
+            // Check if scrolling is in progress
+            if (mDirection != invalid) {
+                // Set the pan flag to true so that grid adjusts to nearest
+                // month after tapping
+                mIsPanGesture = true;
+                handlePanGestureFinished();
+            }
+        }
     }
    
    if (mDirection!= invalid) {
@@ -439,6 +508,8 @@
         // When scrolling finished, month grid will adjust to show the proper month
         HbScrollArea::gestureEvent(event);
    }
+   
+   OstTraceFunctionExit0( DUP3_CALENMONTHGRID_GESTUREEVENT_EXIT );
 }
 
 /*!
@@ -446,6 +517,8 @@
  */
 void CalenMonthGrid::scrollingFinished()
 {
+    OstTraceFunctionEntry0( CALENMONTHGRID_SCROLLINGFINISHED_ENTRY );
+    
 	if (mIsPanGesture) {
 		handlePanGestureFinished();
 	} else if(!mIsAtomicScroll) {
@@ -468,6 +541,8 @@
 	}
 	mIgnoreItemActivated = false;
 	setAttribute(Hb::InteractionDisabled, false);
+	
+	OstTraceFunctionExit0( CALENMONTHGRID_SCROLLINGFINISHED_EXIT );
 }
 
 /*!
@@ -475,6 +550,8 @@
  */
 void CalenMonthGrid::handlePanGestureFinished()
 {
+    OstTraceFunctionEntry0( CALENMONTHGRID_HANDLEPANGESTUREFINISHED_ENTRY );
+    
 	mIsPanGesture = false;
 	// Get the first item that is visible
 	QList<HbAbstractViewItem *> list = visibleItems();
@@ -482,7 +559,8 @@
 	QModelIndex modelIndex = item->modelIndex();
 	
 	// Get the date which is visible at the above row
-	QDateTime date = mMonthDataArray[modelIndex.row()].Day();
+	QList<CalenMonthData>& monthDataArray = mView->monthDataList();
+	QDateTime date = monthDataArray[modelIndex.row()].Day();
 	
 	// Check if this date belong to current active month or 
 	// previous month else future month
@@ -540,6 +618,8 @@
 		// hence, scroll up to show the next month
 		upGesture();
 	}
+	
+	OstTraceFunctionExit0( CALENMONTHGRID_HANDLEPANGESTUREFINISHED_EXIT );
 }
 
 /*!
@@ -548,6 +628,8 @@
  */
 void CalenMonthGrid::prependRows()
 {
+    OstTraceFunctionEntry0( CALENMONTHGRID_PREPENDROWS_ENTRY );
+    
 	// Before we do anything, set the focus to proper date
 	// Set it only when non active day was focussed. When inactive day
 	// was focussed, we need to focus the same day
@@ -570,8 +652,7 @@
 	
 	// Get the updated dates from the view
 	mView->updateModelWithPrevMonth();
-	QList<CalenMonthData > monthDataList = mView->monthDataList();
-	mMonthDataArray = monthDataList;
+	QList<CalenMonthData >& monthDataList = mView->monthDataList();
 	
 	// Prepend the required rows
 	handlePrependingRows(monthDataList);
@@ -607,6 +688,8 @@
 	
 	// Update the sart position of the content widget
 	mStartPos = mContentWidget->pos();
+	
+	OstTraceFunctionExit0( CALENMONTHGRID_PREPENDROWS_EXIT );
 }
 
 /*!
@@ -614,6 +697,8 @@
  */
 void CalenMonthGrid::handlePrependingRows(QList<CalenMonthData > &monthDataList)
 {
+    OstTraceFunctionEntry0( CALENMONTHGRID_HANDLEPREPENDINGROWS_ENTRY );
+    
 	QDateTime currDate = mView->getCurrentDay();
 	QDateTime currDateTime = CalenDateUtils::beginningOfDay( currDate );
 	int rowsInPrevMonth = mView->rowsInPrevMonth();
@@ -660,6 +745,8 @@
 		// Set the data to model
 		mModel->itemFromIndex(currentIndex)->setData(itemData);
 	}
+	
+	OstTraceFunctionExit0( CALENMONTHGRID_HANDLEPREPENDINGROWS_EXIT );
 }
 
 /*!
@@ -668,6 +755,8 @@
  */
 void CalenMonthGrid::appendRows()
 {
+    OstTraceFunctionEntry0( CALENMONTHGRID_APPENDROWS_ENTRY );
+    
 	// Before we do anything, set the focus to proper date
 	// Set it only when non active day was focussed. When inactive day
 	// was focussed, we need to focus the same day
@@ -688,8 +777,7 @@
 		
 	// Get the updated dates from the view
 	mView->updateModelWithFutureMonth();
-	QList<CalenMonthData > monthDataList = mView->monthDataList();
-	mMonthDataArray = monthDataList;
+	QList<CalenMonthData >& monthDataList = mView->monthDataList();
 	
 	// Get the model count before we add any rows into the mode
 	int rowCount = mModel->rowCount();
@@ -730,6 +818,8 @@
 	
 	// Update the sart position of the content widget
     mStartPos = mContentWidget->pos();
+    
+    OstTraceFunctionExit0( CALENMONTHGRID_APPENDROWS_EXIT );
 }
 
 /*!
@@ -737,6 +827,8 @@
  */
 void CalenMonthGrid::handleAppendingRows(QList<CalenMonthData > &monthDataList)
 {
+    OstTraceFunctionEntry0( CALENMONTHGRID_HANDLEAPPENDINGROWS_ENTRY );
+    
 	QDateTime currDate = mView->getCurrentDay();
 	QDateTime currDateTime = CalenDateUtils::beginningOfDay( currDate );
 	int rowsInFutMonth = mView->rowsInFutMonth();
@@ -783,6 +875,8 @@
 		// Set the data to model
 		mModel->itemFromIndex(currentIndex)->setData(itemData);
 	}
+	
+	OstTraceFunctionExit0( CALENMONTHGRID_HANDLEAPPENDINGROWS_EXIT );
 }
 
 /*!
@@ -790,8 +884,11 @@
  */
 void CalenMonthGrid::itemActivated(const QModelIndex &index)
 {
+    OstTraceFunctionEntry0( CALENMONTHGRID_ITEMACTIVATED_ENTRY );
+    
 	if (mIgnoreItemActivated) {
 		mIgnoreItemActivated = false;
+		OstTraceFunctionExit0( CALENMONTHGRID_ITEMACTIVATED_EXIT );
 		return;
 	}
 	mIsNonActiveDayFocused = false;
@@ -804,6 +901,7 @@
 		QModelIndex itemIndex = mModel->index(mCurrentRow,0);
 		if(itemIndex.row() < 0 || itemIndex.row() >= mModel->rowCount() ||
 				itemIndex.column() < 0 || itemIndex.column() > mModel->columnCount()) {
+			OstTraceFunctionExit0( DUP1_CALENMONTHGRID_ITEMACTIVATED_EXIT );
 			return;
 		}
 		QVariant itemData = itemIndex.data(Qt::UserRole + 1);
@@ -822,10 +920,11 @@
 		// Check if inactive date is tapped
 		QDateTime activeMonth = mView->getActiveDay();
 		int month = activeMonth.date().month();
-		if(month != mMonthDataArray[mCurrentRow].Day().date().month()){
+		QList<CalenMonthData >& monthDataList = mView->monthDataList();
+		if(month != monthDataList[mCurrentRow].Day().date().month()){
 			// Set the flag
 			mIsNonActiveDayFocused = true;
-			mNonActiveFocusedDay = mMonthDataArray[mCurrentRow].Day();
+			mNonActiveFocusedDay = monthDataList[mCurrentRow].Day();
 			
 			// Add one month to active month
 			activeMonth = activeMonth.addMonths(1);
@@ -844,6 +943,8 @@
 		} 
 		mView->setContextForActiveDay(index.row());
 	}
+	
+	OstTraceFunctionExit0( DUP2_CALENMONTHGRID_ITEMACTIVATED_EXIT );
 }
 
 /*!
@@ -851,6 +952,8 @@
  */
 void CalenMonthGrid::setFocusToProperDay()
 {
+    OstTraceFunctionEntry0( CALENMONTHGRID_SETFOCUSTOPROPERDAY_ENTRY );
+    
 	// Calculate the new item to be focussed
 	QDateTime oldFocussedDate = mView->getActiveDay();
 	QList<CalenMonthData> monthDataList = mView->monthDataList();
@@ -887,6 +990,8 @@
 			break;
 		}
 	}
+	
+	OstTraceFunctionExit0( CALENMONTHGRID_SETFOCUSTOPROPERDAY_EXIT );
 }
 
 /*!
@@ -894,13 +999,16 @@
  */
 void CalenMonthGrid::setActiveDates(QDate activeDate)
 {
+    OstTraceFunctionEntry0( CALENMONTHGRID_SETACTIVEDATES_ENTRY );
+    
 	// By default, text color will be set as inactive date color
 	// set active date color only for the dates that fall in current month
 	// So, in the whole data array, start from where the current month starts
 	// and stop the loop where it the current month ends
 	
 	int start = 0;
-	int end = mMonthDataArray.count();
+	QList<CalenMonthData >& monthDataList = mView->monthDataList();
+	int end = monthDataList.count();
 	
 	// Calculate the start and end values
 	QDate firstDateInGrid = mView->firstDayOfGrid().date();
@@ -928,6 +1036,7 @@
 	// Now set the inactive text color to those which were active before the swipe
 	if (mDirection == invalid) {
 		// no need to do anything as other dates will be in inactive dates color
+		OstTraceFunctionExit0( CALENMONTHGRID_SETACTIVEDATES_EXIT );
 		return;
 	}
 	
@@ -969,6 +1078,8 @@
 		list.replace(CalendarNamespace::CalendarMonthTextColorRole, false);
 		mModel->itemFromIndex(index)->setData(list);
 	}
+	
+	OstTraceFunctionExit0( DUP1_CALENMONTHGRID_SETACTIVEDATES_EXIT );
 }
 
 /*!
@@ -976,6 +1087,9 @@
  */
 int CalenMonthGrid::getCurrentIndex()
 {
+    OstTraceFunctionEntry0( CALENMONTHGRID_GETCURRENTINDEX_ENTRY );
+    
+	OstTraceFunctionExit0( CALENMONTHGRID_GETCURRENTINDEX_EXIT );
 	return mCurrentRow;
 }
 
@@ -984,7 +1098,11 @@
  */
 void CalenMonthGrid::setCurrentIdex(int index)
 {
+    OstTraceFunctionEntry0( CALENMONTHGRID_SETCURRENTIDEX_ENTRY );
+    
 	itemActivated(mModel->index(index, 0));
+	
+	OstTraceFunctionExit0( CALENMONTHGRID_SETCURRENTIDEX_EXIT );
 }
 
 /*!
@@ -992,6 +1110,8 @@
  */
 void CalenMonthGrid::orientationChanged(Qt::Orientation newOrientation)
 {
+    OstTraceFunctionEntry0( CALENMONTHGRID_ORIENTATIONCHANGED_ENTRY );
+    
     Q_UNUSED(newOrientation)
 	// We are overriding this function to avoid the default behavior of
 	// hbgridview on orientation change as it swaps the row and column counts
@@ -1018,6 +1138,8 @@
 		mIsAtomicScroll = true;
 		scrollTo(indexToBeScrolled);
 	}
+	
+	OstTraceFunctionExit0( CALENMONTHGRID_ORIENTATIONCHANGED_EXIT );
 }
 
 /*!
@@ -1027,6 +1149,8 @@
                           const QStyleOptionGraphicsItem* option,
                           QWidget* widget)
 {
+    OstTraceFunctionEntry0( CALENMONTHGRID_PAINT_ENTRY );
+    
 	Q_UNUSED(option);
 	Q_UNUSED(widget);
 	painter->setRenderHint(QPainter::NonCosmeticDefaultPen);
@@ -1043,8 +1167,9 @@
 	} else {
 		pen.setBrush(mGridBorderColor);
 	}
-	//store the old pen first
-    QPen oldPen = painter->pen();
+	// Store the old pen
+	QPen oldPen = painter->pen();
+	
 	// Set the new pen to the painter
 	painter->setPen(pen);
 	
@@ -1082,8 +1207,10 @@
 	// Painter draws the line for first two points in the list and then second 
 	// line for next two points in the list like that. Hence, list should 
 	// contain even number of points
+	// Dont draw the first horizontal line as we have thick line seperator
+	// coming between day names and the month grid
 	QVector<QPointF> pointList;
-	for (int i = 0; i < numOfRows; i++) {
+	for (int i = 1; i < numOfRows; i++) {
 		pointList.append(QPointF(startPoint.x(), 
 		                         startPoint.y() + (i * rowWidth)));
 		pointList.append(QPointF(endPoint.x(), endPoint.y() + (i * rowWidth)));
@@ -1101,8 +1228,11 @@
 	
 	// Draw the lines for the points in the vector list
 	painter->drawLines(pointList);
+	
 	// Set the old pen back
 	painter->setPen(oldPen);
+	
+	OstTraceFunctionExit0( CALENMONTHGRID_PAINT_EXIT );
 }
 
 // End of File