calendarui/views/src/calenmonthgrid.cpp
changeset 26 a949c2543c15
parent 23 fd30d51f876b
child 32 ea672fcb0ea0
--- a/calendarui/views/src/calenmonthgrid.cpp	Mon May 03 12:30:32 2010 +0300
+++ b/calendarui/views/src/calenmonthgrid.cpp	Fri May 14 15:51:09 2010 +0300
@@ -16,10 +16,6 @@
  */
 
 // System includes
-#include <qtimer.h>
-#include <hbmenu.h>
-#include <hbaction.h>
-#include <hbmainwindow.h>
 #include <hbgridview.h>
 #include <hbabstractviewitem.h>
 #include <hbstyleloader.h>
@@ -34,7 +30,7 @@
 #include "calencommon.h"
 
 // Constants
-#define SCROLL_SPEEED 1000 
+#define SCROLL_SPEEED 2000 
 #define GRIDLINE_WIDTH 0.075 //units
 
 /*!
@@ -66,27 +62,26 @@
 	setSelectionMode(HbGridView::NoSelection);
 	setUniformItemSizes(true);
 	setVerticalScrollBarPolicy(HbScrollArea::ScrollBarAlwaysOff);
-	setClampingStyle(HbScrollArea::StrictClamping );
+	setClampingStyle(HbScrollArea::StrictClamping);
+	setEnabledAnimations(HbAbstractItemView::None);
+	resetTransform();
 	
 	// Get the content widget of the scroll area to draw the grid lines
 	mContentWidget = contentWidget();
 	
-	// Get the color of the grid lines
+	// Get the all required colors 
+	// Color of the grid lines
 	mGridLineColor = HbColorScheme::color("qtc_cal_grid_line");
 	
-	// Create the prototype
-	CalenGridItemPrototype* gridItemPrototype = new CalenGridItemPrototype(this);
-	// Create the model
-	mModel = new QStandardItemModel(14*KCalenDaysInWeek, 1, this);
-	// Set the mode and the prototype
-	setModel(mModel,gridItemPrototype);
+	// Get the localised dates well before
+	// TODO: Need to update the mLocalisedDates when user changes the
+	// phone language keeping calendar application in background
+	HbExtendedLocale locale = HbExtendedLocale::system();
+	for (int i = 1; i <= 31; i++) {
+		mLocalisedDates.append(locale.toString(i));
+	}
 	
-	// Register the widgetml and css files
-	HbStyleLoader::registerFilePath(":/");
-	
-	// Set the layout name
-	setLayoutName("calendarCustomGridItem");
-	
+	// Connect to scrolling finished signal
 	connect(this, SIGNAL(scrollingEnded()), this,
 			SLOT(scrollingFinished()));
 	
@@ -100,6 +95,7 @@
  */
 CalenMonthGrid::~CalenMonthGrid()
 {
+	// Nothing Yet
 }
 
 /*!
@@ -114,55 +110,66 @@
  Updates the model with the proper dates and sets the required user roles
  */
 void CalenMonthGrid::updateMonthGridModel(QList<CalenMonthData> &monthDataArray,
-                        int indexToBeScrolled)
+                        int indexToBeScrolled, bool isFirstTime)
 {
-	// Check the counts
-	int dataCount = monthDataArray.count();
-	int rowCount = mModel->rowCount();
-	int countDiff = dataCount - rowCount;
-	if (countDiff < 0) {
-		// Delete extra rows in the model
-		mModel->removeRows(dataCount,abs(countDiff));
-	} else if (countDiff > 0) {
-		// Add the necessary number of rows
-		mModel->insertRows(rowCount,countDiff);
+	int loopStart = 0;
+	int loopEnd = monthDataArray.count();
+	if (isFirstTime) {
+		// Create the model with only 42 items as visible to the user
+		mModel = new QStandardItemModel(KCalenDaysInWeek * KNumOfVisibleRows, 
+		                                1, this);
+		loopStart = (mView->rowsInPrevMonth()) * KCalenDaysInWeek;
+		loopEnd = loopStart + (KCalenDaysInWeek * KNumOfVisibleRows);
+	} else {
+		// Block the signals generated by model, this is being done as
+		// we want to avoid the overload of view listening to signals
+		mModel->blockSignals(true);
+		
+		// Check the counts
+		int dataCount = monthDataArray.count();
+		int rowCount = mModel->rowCount();
+		int countDiff = dataCount - rowCount;
+		if (countDiff < 0) {
+			// Delete extra rows in the model
+			mModel->removeRows(dataCount,abs(countDiff));
+		} else if (countDiff > 0) {
+			// Add the necessary number of rows
+			mModel->insertRows(rowCount,countDiff);
+		}
+		loopEnd = dataCount;
 	}
+	
 	QDateTime currDate = mView->getCurrentDay();
 	QDateTime currDateTime = CalenDateUtils::beginningOfDay(currDate);
 	QDateTime activeDay = mView->getActiveDay();
 	QDateTime activeDateTime = CalenDateUtils::beginningOfDay(activeDay);
 	
 	QModelIndex currentIndex;
-	
-	// Get the default text color to be set
-	QColor textColor = HbColorScheme::color("qtc_cal_month_notactive_dates");
-	HbExtendedLocale locale = HbExtendedLocale::system();
-	for (int i = 0; i < dataCount; i++) {
+	int modelIndex = 0;
+	for (int i = loopStart; i < loopEnd; i++) {
 		QDateTime dateTime = monthDataArray[i].Day();
-		currentIndex = mModel->index(i, 0);
-		// Get the localised string for the day
-		QString date = locale.toString(dateTime.date().day());
+		currentIndex = mModel->index(modelIndex++, 0);
 		
 		// Create the variant list to contain the date to depict a grid item
 		QVariantList itemData;
 		
-		// NOTE: Add the data in the order mentioned in the 
+		// !!!NOTE!!!: Add the data in the order mentioned in the 
 		// CalendarNamespace::DataRole enum. Dont change the order.
-		itemData << date; 
+		itemData << mLocalisedDates.at(dateTime.date().day()-1); 
 		
 		// Check for active day
 		if (activeDateTime == CalenDateUtils::beginningOfDay(dateTime)) {
-			mCurrentRow = currentIndex.row();
-			// Set the focus icon
-			itemData << QString("qtg_fr_cal_focused_day_ind");
+			mCurrentRow = i;
+			// Set the focus attribute to true
+			itemData << true;
 		} else {
 			// reset the highlight
-			itemData << QString("");
+			itemData << false;
 		}
 
 		// Check for current day
 		if (currDateTime == CalenDateUtils::beginningOfDay(dateTime)) {
-			// Set the underline icon
+			// Set the underline attribute to true
 			itemData << true;
 		} else {			
 			itemData << false;
@@ -170,35 +177,118 @@
 
 		// Check for events
 		if (monthDataArray[i].HasEvents()) {
-			// Set the underline icon
-			itemData << QString("qtg_graf_cal_event_ind");
+			// Set the event indicator attribute
+			itemData << true;
 		} else {
-			itemData << QString("");
+			itemData << false;
 		}
 		
 		// Add default text color
-		itemData << textColor;
+		if (monthDataArray[i].isActive()) {
+			itemData << true;
+		} else {
+			itemData << false;
+		}
 		mModel->itemFromIndex(currentIndex)->setData(itemData);
 	}
+	
+	if (isFirstTime) {
+		// Color of the today indicator
+		QColor todayIndColor = HbColorScheme::color("qtc_cal_month_current_day");
+		// Color of the active dates
+		QColor mActiveTextColor = 
+								HbColorScheme::color("qtc_cal_month_active_dates");
+		// Color of the inactive dates
+		QColor mInActiveTextColor = 
+							HbColorScheme::color("qtc_cal_month_notactive_dates");
+		
+		// Create the prototype
+		CalenGridItemPrototype* gridItemPrototype = new CalenGridItemPrototype(
+						todayIndColor, mActiveTextColor, mInActiveTextColor, this);
+		
+		// Set the mode and the prototype
+		setModel(mModel,gridItemPrototype);
+		
+		// Register the widgetml and css files
+		HbStyleLoader::registerFilePath(":/");
+		
+		// Set the layout name
+		setLayoutName("calendarCustomGridItem");
+	} else {
+		// Since, we have finished setData, Now unblock the signals
+		mModel->blockSignals(false);
+		
+		// Since till now, we had blocked signals being generated frm the mode
+		// view will be unaware of the items that we added. Hence, inform the view
+		// explicitly in one shot
+		QModelIndex leftIndex = mModel->index(0, 0);
+		QModelIndex rightIndex = mModel->index(loopEnd-1, 0);
+		dataChanged(leftIndex, rightIndex);
+		
+		// NOTE: To make sure that we always display proper month,
+		// two calls have been  made to scrollTo(), one with top
+		// visible item and other with bottom visible item
+		// Calculate the first visible item in the grid
+		QModelIndex firstVisibleIndex = mModel->index(indexToBeScrolled - 
+								(KNumOfVisibleRows * KCalenDaysInWeek - 1), 0);
+		scrollTo(firstVisibleIndex);
+		
+		
+		// Calculate the last visible item in the grid
+		QModelIndex lastVisibleIndex = mModel->index(indexToBeScrolled, 0);
+		scrollTo(lastVisibleIndex);
+	}
 	mMonthDataArray = monthDataArray;
+}
+
+/*!
+	Updates the view with jprevious month dates when calendar is opened for the 
+	first time to improve the opening time
+ */
+void CalenMonthGrid::updateMonthGridWithInActiveMonths(
+										QList<CalenMonthData> &monthDataArray)
+{	
+	mMonthDataArray = monthDataArray;
+		
+	// Prepend the required rows
+	handlePrependingRows(monthDataArray);
 	
-	// Get the active month
-	QDateTime activeDate = mView->getActiveDay();
-	// Set the text color properly
-	setActiveDates(activeDate.date());
+	// Append the required rows
+	handleAppendingRows(monthDataArray);
+	
+	int rowsInPrevMonth = mView->rowsInPrevMonth();
 	
-	// NOTE: To make sure that we always display proper month,
-	// two calls have been  made to scrollTo(), one with top
-	// visible item and other with bottom visible item
-    // Calculate the first visible item in the grid
-    QModelIndex firstVisibleIndex = mModel->index(indexToBeScrolled - 
-                                        (KNumOfVisibleRows * KCalenDaysInWeek - 1), 0);
-    scrollTo(firstVisibleIndex);
-    
-    
-    // Calculate the last visible item in the grid
-    QModelIndex lastVisibleIndex = mModel->index(indexToBeScrolled, 0);
-    scrollTo(lastVisibleIndex);
+	// Calculate the proper index to be scrolled to
+	int itemToBeScrolled = rowsInPrevMonth * KCalenDaysInWeek;
+	QModelIndex indexToBeScrolled = mModel->index(itemToBeScrolled, 0);
+	mIsAtomicScroll = true;
+	scrollTo(indexToBeScrolled);
+		
+	// Scroll to proper index
+	itemToBeScrolled = ((rowsInPrevMonth + KNumOfVisibleRows) * 
+								   KCalenDaysInWeek) - 1;
+	indexToBeScrolled = mModel->index(itemToBeScrolled, 0);
+	mIsAtomicScroll = true;
+	scrollTo(indexToBeScrolled);
+}
+
+/*!
+	Updates the view with just event indicators
+ */
+void CalenMonthGrid::updateMonthGridWithEventIndicators(
+										QList<CalenMonthData> &monthDataArray)
+{
+	mMonthDataArray = monthDataArray;
+	for(int i = 0; i < monthDataArray.count(); i++) {
+		// Check if the day has events
+		if (monthDataArray[i].HasEvents()) {
+			QModelIndex itemIndex = mModel->index(i,0);
+			QVariant itemData = itemIndex.data(Qt::UserRole + 1);
+			QVariantList list = itemData.toList();
+			list.replace(CalendarNamespace::CalendarMonthEventRole, true);
+			mModel->itemFromIndex(itemIndex)->setData(list);
+		}
+	}
 }
 
 /*!
@@ -208,10 +298,11 @@
 {
 	Q_UNUSED(value)	
 	mDirection = down;
-	// Before we start scrolling, setthe active text color to previous month
-	QDateTime activeDate = mView->getActiveDay();
-	setActiveDates(activeDate.addMonths(-1).date());
-	HbScrollArea::downGesture(SCROLL_SPEEED);
+	mIsAtomicScroll = false;
+	setAttribute(Hb::InteractionDisabled);
+	
+	// pass it to parent
+	HbScrollArea::downGesture(value);
 }
 
 /*!
@@ -221,10 +312,12 @@
 {
 	Q_UNUSED(value)	
 	mDirection = up;
-	// Before we start scrolling, setthe active text color to future month
-	QDateTime activeDate = mView->getActiveDay();
-	setActiveDates(activeDate.addMonths(1).date());
-	HbScrollArea::upGesture(SCROLL_SPEEED);
+	mIsAtomicScroll = false;
+	setAttribute(Hb::InteractionDisabled);
+	
+	// pass it to parent
+	HbScrollArea::upGesture(value);
+	
 }
 
 /*!
@@ -257,25 +350,20 @@
  */
 void  CalenMonthGrid::panGesture(const QPointF &  delta)
 {
+	setAttribute(Hb::InteractionDisabled);
+	mIsAtomicScroll = false;
 	if (!mIsPanGesture) {
 		mIsPanGesture = true;
 		mIgnoreItemActivated = true;
-		
+		mStartPos = mContentWidget->pos();
 		// Get to know the direction of the gesture
 		if (delta.y() > 0) {
 			mDirection = down;
 		} else {
 			mDirection = up;
 		}
-	} else { // This case is when user changes the direction while panning
-		// without lifting the finger
-		// Check if direction has changed
-		if (((delta.y() > 0) && (mDirection == up))
-			|| ((delta.y() < 0) && (mDirection == down))) {
-			// Direction has changed, ignore this pan
-			return;
-		}
 	}
+	
 	// Call the parent class to perform the pan gesture
 	// When scrolling finished, month grid will adjust to show the proper month
 	HbScrollArea::panGesture(delta);
@@ -288,40 +376,87 @@
 {
 	
 	if (mIsPanGesture) {
-		mIsPanGesture = false;
-		if (mDirection == up) {
-			// Make a request for upgesture
-			upGesture(SCROLL_SPEEED);
-			return; // return immediately
-		} else if (mDirection == down) {
-			// Make a request for upgesture
-			downGesture(SCROLL_SPEEED);
-			return; // return immediately
+		handlePanGestureFinished();
+	} else if(!mIsAtomicScroll) {
+		QDateTime activeDate = mView->getActiveDay();
+		if(mDirection == down) { // down gesture
+			if (!mIsNonActiveDayFocused) {
+				setActiveDates(activeDate.addMonths(-1).date());
+			}
+			prependRows();
+		} else if (mDirection == up) { //up gesture
+			if (!mIsNonActiveDayFocused) {
+				setActiveDates(activeDate.addMonths(1).date());
+			}
+			appendRows();
 		}
-	} else if(!mIsAtomicScroll) {
-		// 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
-		if (!mIsNonActiveDayFocused) {
-			setFocusToProperDay();
-		}
-		// To improve the performance, lets start the timer for 10 ms, 
-		// return immediately and do the other things after that
-		QTimer::singleShot(10, this, SLOT(timerExpired()));
+		mDirection = invalid;
 	} else {
         mIsAtomicScroll = false;
 	}
 	mIgnoreItemActivated = false;
+	setAttribute(Hb::InteractionDisabled, false);
 }
 
-void CalenMonthGrid::timerExpired()
+/*!
+ Function to handle completion of pan gesture
+ */
+void CalenMonthGrid::handlePanGestureFinished()
 {
-	if(mDirection == down) { // down gesture
-		prependRows();
-	} else if (mDirection == up) { //up gesture
-		appendRows();
+	mIsPanGesture = false;
+	// Get the first item that is visible
+	QList<HbAbstractViewItem *> list = visibleItems();
+	HbAbstractViewItem* item = list[0];
+	QModelIndex modelIndex = item->modelIndex();
+	
+	// Get the date which is visible at the above row
+	QDateTime date = mMonthDataArray[modelIndex.row()].Day();
+	
+	// Check if this date belong to current active month or 
+	// previous month else future month
+	QDateTime activeMonth = mView->getActiveDay();
+	QDateTime prevMonth = activeMonth.addMonths(-1);
+	QDateTime nextMonth = activeMonth.addMonths(1);
+	int month = date.date().month();
+	if (month == activeMonth.date().month()) {
+		// Then pan is completed on current month
+		// Check if the date is more than half of the current month or it is
+		// more than or equal to half of the future month
+		if (date.date().day() > (activeMonth.date().daysInMonth()) / 2 ||
+				date.addDays(KNumOfVisibleRows*KCalenDaysInWeek).date().day() >=
+				(prevMonth.date().daysInMonth()) / 2) {
+			// up gesture to bring the next month
+			upGesture(SCROLL_SPEEED);
+		} else {
+			// we should again show the current month by scrolling downwards
+			mDirection = down;
+			mIsAtomicScroll = true;
+			scrollContentsTo(-mStartPos,500);
+		}
+	} else if (month == prevMonth.date().month()) {
+		// first visible item belongs to previous month
+		// Check if the date is more than half of the previous month
+		if (date.date().day() > (prevMonth.date().daysInMonth()) / 2) {
+			// we should again show the current month by scrolling upwards
+			mDirection = up;
+			mIsAtomicScroll = true;
+			scrollContentsTo(-mStartPos,500);
+		} else {
+			// down gesture to show the previous month
+			downGesture(SCROLL_SPEEED);
+		}
+	} else if (month == nextMonth.date().month()) {
+		// first visible item belongs to next month
+		// Check if the date is more than half of the next month
+		if (date.date().day() > (nextMonth.date().daysInMonth()) / 2) {
+			// up gesture to bring the next month
+			upGesture(SCROLL_SPEEED);
+		} else {
+			// we should again show the current month by scrolling upwards
+			mDirection = invalid;
+			scrollContentsTo(-mStartPos,500);
+		}
 	}
-	mDirection = invalid;
 }
 
 /*!
@@ -330,43 +465,81 @@
  */
 void CalenMonthGrid::prependRows()
 {
+	// 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
+	if (!mIsNonActiveDayFocused) {
+		setFocusToProperDay();
+	}
+	
+	// Block the signals generated by model, this is being done as
+	// we want to avoid the overload of view listening to signals
+	mModel->blockSignals(true);
+		
 	mIsNonActiveDayFocused = false;
-	QDateTime currDate = mView->getCurrentDay();
-	QDateTime currDateTime = CalenDateUtils::beginningOfDay( currDate );
+	
 	int rowsInFutMonthEarlier = mView->rowsInFutMonth();
 	int rowsInPrevMonthEarlier = mView->rowsInPrevMonth();
 	
+	// remove the cells in the future month
+	int deleteFromIndex = (rowsInPrevMonthEarlier + KNumOfVisibleRows) * KCalenDaysInWeek;
+	int numOfIndices = rowsInFutMonthEarlier * KCalenDaysInWeek;
+	
 	// Get the updated dates from the view
 	mView->updateModelWithPrevMonth();
 	QList<CalenMonthData > monthDataList = mView->monthDataList();
 	mMonthDataArray = monthDataList;
-	int listCount = monthDataList.count();
-	// Get the updated rows to be inserted
-	int rowsInPrevMonth = mView->rowsInPrevMonth();
-	int rowsInFutMonth = mView->rowsInFutMonth();
+	
+	// Prepend the required rows
+	handlePrependingRows(monthDataList);
+		
+	// Since, we have finished setData, Now unblock the signals
+	mModel->blockSignals(false);
 	
-	// remove the cells in the future month
-	int deleteFromIndex = (rowsInPrevMonthEarlier + KNumOfVisibleRows) * KCalenDaysInWeek;
-	int numOfIndices = rowsInFutMonthEarlier * KCalenDaysInWeek;
-	int count = mModel->rowCount();
+	int rowsInPrevMonth = mView->rowsInPrevMonth();
+	int countToBeAdded = rowsInPrevMonth * KCalenDaysInWeek;
+		
+	// Since till now, we had blocked signals being generated frm the model
+	// view will be unaware of the items that we added. Hence, inform the view
+	// explicitly in one shot
+	QModelIndex leftIndex = mModel->index(0, 0);
+	QModelIndex rightIndex = mModel->index(countToBeAdded-1, 0);
+	dataChanged(leftIndex, rightIndex);
+		
+	// Now remove the necessary items frm the model
+	mModel->removeRows(deleteFromIndex+countToBeAdded, numOfIndices);
+	mIsAtomicScroll = true;
+	int itemToBeScrolled = rowsInPrevMonth * KCalenDaysInWeek;
+	QModelIndex indexToBeScrolled  = mModel->index(itemToBeScrolled, 0);
+	scrollTo(indexToBeScrolled);
 	
-	count = mModel->rowCount();
-	
+	// Scroll to proper index
+	itemToBeScrolled = ((rowsInPrevMonth + KNumOfVisibleRows) * 
+								   KCalenDaysInWeek) - 1;
+	indexToBeScrolled = mModel->index(itemToBeScrolled, 0);
+	mIsAtomicScroll = true;
+	scrollTo(indexToBeScrolled);
+	// Update the mCurrentRow
+	mCurrentRow += countToBeAdded;
+}
+
+/*!
+	Helper function that prepends the required rows to the model
+ */
+void CalenMonthGrid::handlePrependingRows(QList<CalenMonthData > &monthDataList)
+{
+	QDateTime currDate = mView->getCurrentDay();
+	QDateTime currDateTime = CalenDateUtils::beginningOfDay( currDate );
+	int rowsInPrevMonth = mView->rowsInPrevMonth();
 	// Add the new days
 	int countToBeAdded = rowsInPrevMonth * KCalenDaysInWeek;
 	
 	mModel->insertRows(0, countToBeAdded);
-	count = mModel->rowCount();
-	
-	// Get the default text color to be set
-	QColor textColor = HbColorScheme::color("qtc_cal_month_notactive_dates");
-	HbExtendedLocale locale = HbExtendedLocale::system();
 	
 	for (int i = 0; i < countToBeAdded; i++) {
 		QDateTime dateTime = monthDataList[i].Day();
 		
 		// Get the localised string for the day
-		QString date = locale.toString(dateTime.date().day());
 		QModelIndex currentIndex = mModel->index(i, 0);
 		
 		// Create the variant list to contain the date to depict a grid item
@@ -374,14 +547,14 @@
 		
 		// NOTE: Add the data in the order mentioned in the 
 		// CalendarNamespace::DataRole enum. Dont change the order.
-		itemData << date;
+		itemData << mLocalisedDates.at(dateTime.date().day()-1);;
 				
-		// Diable the focus role
-		itemData << QString("");
+		// Disable the focus role
+		itemData << false;
 		
 		// Check for current day
 		if  (currDateTime == CalenDateUtils::beginningOfDay( dateTime )) {
-			// Set the underline icon
+			// Set the underline icon attribute
 			itemData << true;
 		} else {
 			itemData << false;
@@ -389,39 +562,18 @@
 		
 		// Update the event indicators
 		if (monthDataList[i].HasEvents()) {
-			// Set the event indicator icon
-			itemData << QString("qtg_graf_cal_event_ind");
+			// Set the event indicator attribute
+			itemData << true;
 		} else {
-			itemData << QString("");
+			itemData << false;
 		}
 		
 		// Add default text color
-		
-		itemData << textColor;
+		itemData << false;
 		
 		// Set the data to model
 		mModel->itemFromIndex(currentIndex)->setData(itemData);
 	}
-	
-	// Update the mCurrentRow
-	mCurrentRow += countToBeAdded;
-	// Scroll to proper index
-	int itemToBeScrolled = ((rowsInPrevMonth + KNumOfVisibleRows) * 
-								   KCalenDaysInWeek) - 1;
-	QModelIndex indexToBeScrolled = mModel->index(itemToBeScrolled, 0);
-	QMap<int, QVariant> data;
-	data = mModel->itemData(indexToBeScrolled);
-	QVariant value = data.value(Qt::DisplayRole);
-	int date = value.toInt();
-	mIsAtomicScroll = true;
-	scrollTo(indexToBeScrolled);
-	
-	// Now remove the necessary items frm the model
-	mModel->removeRows(deleteFromIndex+countToBeAdded, numOfIndices);
-	mIsAtomicScroll = true;
-	itemToBeScrolled = rowsInPrevMonth * KCalenDaysInWeek;
-	indexToBeScrolled = mModel->index(itemToBeScrolled, 0);
-	scrollTo(indexToBeScrolled);
 }
 
 /*!
@@ -430,9 +582,19 @@
  */
 void CalenMonthGrid::appendRows()
 {
+	// 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
+	if (!mIsNonActiveDayFocused) {
+		setFocusToProperDay();
+	}
+	
+	// Block the signals generated by model, this is being done as
+	// we want to avoid the overload of view listening to signals
+	mModel->blockSignals(true);
+	
 	mIsNonActiveDayFocused = false;
-	QDateTime currDate = mView->getCurrentDay();
-	QDateTime currDateTime = CalenDateUtils::beginningOfDay( currDate );
+	
 	int rowsInFutMonth = mView->rowsInFutMonth();
 	int rowsInPrevMonth = mView->rowsInPrevMonth();
 	// remove the cells in the previous month
@@ -442,40 +604,77 @@
 	mView->updateModelWithFutureMonth();
 	QList<CalenMonthData > monthDataList = mView->monthDataList();
 	mMonthDataArray = monthDataList;
-	// Get the updated rows to be inserted
+	
+	// Get the model count before we add any rows into the mode
+	int rowCount = mModel->rowCount();
+	// Append the required rows
+	handleAppendingRows(monthDataList);
+	
+	// Since, we have finished setData, Now unblock the signals
+	mModel->blockSignals(false);
+	
+	// Since till now, we had blocked signals being generated frm the mode
+	// view will be unaware of the items that we added. Hence, inform the view
+	// explicitly in one shot
+	QModelIndex leftIndex = mModel->index(rowCount-1, 0);
+	QModelIndex rightIndex = mModel->index(mModel->rowCount()-1, 0);
+	dataChanged(leftIndex, rightIndex);
+		
+	// Update the mCurrentRow
+	mCurrentRow -= (countToBeDeleted);
+	for (int i = 0; i < countToBeDeleted; i++) {
+		mModel->removeRow(0);
+	}
+	
+	mIsAtomicScroll = true;
+	
+	rowsInFutMonth = mView->rowsInFutMonth();
 	rowsInPrevMonth = mView->rowsInPrevMonth();
-	rowsInFutMonth = mView->rowsInFutMonth();
+	
+	// Calculate the proper index to be scrolled to
+	int itemToBeScrolled = rowsInPrevMonth * KCalenDaysInWeek;
+	QModelIndex indexToBeScrolled = mModel->index(itemToBeScrolled, 0);
+	scrollTo(indexToBeScrolled);
+	
+	itemToBeScrolled = ((rowsInPrevMonth + KNumOfVisibleRows) * 
+									   KCalenDaysInWeek) - 1;
+	indexToBeScrolled = mModel->index(itemToBeScrolled, 0);
+	mIsAtomicScroll = true;
+	scrollTo(indexToBeScrolled);
+}
+
+/*!
+	Helper function that appends the required rows to the model
+ */
+void CalenMonthGrid::handleAppendingRows(QList<CalenMonthData > &monthDataList)
+{
+	QDateTime currDate = mView->getCurrentDay();
+	QDateTime currDateTime = CalenDateUtils::beginningOfDay( currDate );
+	int rowsInFutMonth = mView->rowsInFutMonth();
 	int countToBeAdded = rowsInFutMonth * KCalenDaysInWeek;
 	int lastVisibleIndex = monthDataList.count() - countToBeAdded;
 	
 	int rowCount = mModel->rowCount();
 	mModel->insertRows(rowCount, countToBeAdded);
 	
-	// Get the default text color to be set
-	QColor textColor = HbColorScheme::color("qtc_cal_month_notactive_dates");
 	for (int i = 0; i < countToBeAdded; i++) {
-		QMap<int, QVariant> data;
 		QModelIndex currentIndex = mModel->index(rowCount + i, 0);
 				
 		QDateTime dateTime = monthDataList[lastVisibleIndex + i].Day();
-		HbExtendedLocale locale = HbExtendedLocale::system();
-		// Get the localised string for the day
-		QString date = locale.toString(dateTime.date().day());
-		data.insert(CalendarNamespace::CalendarMonthDayRole, date);
 		
 		// Create the variant list to contain the date to depict a grid item
 		QVariantList itemData;
 		
 		// NOTE: Add the data in the order mentioned in the 
 		// CalendarNamespace::DataRole enum. Dont change the order.
-		itemData << date;
+		itemData << mLocalisedDates.at(dateTime.date().day()-1);;
 		
 		// Disable the focus role
-		itemData << QString("");
+		itemData << false;
 		
 		// Check for current day
 		if (currDateTime == CalenDateUtils::beginningOfDay( dateTime )) {
-			// Set the underline icon
+			// Set the underline icon attribute
 			itemData << true;
 		} else {
 			itemData << false;
@@ -483,30 +682,18 @@
 		
 		// Update the event indicators
 		if (monthDataList[lastVisibleIndex + i].HasEvents()) {
-			// Set the underline icon
-			itemData << QString("qtg_graf_cal_event_ind");
+			// Set the event indicator attribute
+			itemData << true;
 		} else {
-			itemData << QString("");
+			itemData << false;
 		}
 		
 		// Add default text color
-		itemData << textColor;
+		itemData << false;
 				
 		// Set the data to model
 		mModel->itemFromIndex(currentIndex)->setData(itemData);
 	}
-	
-	// Update the mCurrentRow
-	mCurrentRow -= (countToBeDeleted);
-	for (int i = 0; i < countToBeDeleted; i++) {
-		mModel->removeRow(0);
-	}
-	mIsAtomicScroll = true;
-	
-	// Calculate the proper index to be scrolled to
-	int itemToBeScrolled = rowsInPrevMonth * KCalenDaysInWeek;
-	QModelIndex indexToBeScrolled = mModel->index(itemToBeScrolled, 0);
-	scrollTo(indexToBeScrolled);
 }
 
 /*!
@@ -528,7 +715,7 @@
 		QModelIndex itemIndex = mModel->index(mCurrentRow,0);
 		QVariant itemData = itemIndex.data(Qt::UserRole + 1);
 		QVariantList list = itemData.toList();
-		list.replace(CalendarNamespace::CalendarMonthFocusRole, QString(""));
+		list.replace(CalendarNamespace::CalendarMonthFocusRole, false);
 		mModel->itemFromIndex(itemIndex)->setData(list);
 		
 		// Inform view to update the context and preview panes
@@ -537,7 +724,7 @@
 		itemData = itemIndex.data(Qt::UserRole + 1);
 		list = itemData.toList();
 		list.replace(CalendarNamespace::CalendarMonthFocusRole, 
-						 QString("qtg_fr_cal_focused_day_ind"));
+								 true);
 		mModel->itemFromIndex(itemIndex)->setData(list);
 		// Check if inactive date is tapped
 		QDateTime activeMonth = mView->getActiveDay();
@@ -547,17 +734,19 @@
 			mIsNonActiveDayFocused = true;
 			mNonActiveFocusedDay = mMonthDataArray[mCurrentRow].Day();
 			
-			// Get the current active month
-			QDateTime activeMonth = mView->getActiveDay();
-			// Add one month to it
+			// Add one month to active month
 			activeMonth = activeMonth.addMonths(1);
 			if (activeMonth.date().month() == 
 				mNonActiveFocusedDay.date().month()) {
+				mDirection = up;
 				// up gesture
 				upGesture(SCROLL_SPEEED);
+				setActiveDates(activeMonth.date());
 			} else {
+				mDirection = down;
 				// down gesture
 				downGesture(SCROLL_SPEEED);
+				setActiveDates(activeMonth.addMonths(-2).date());
 			}
 		} 
 		mView->setContextForActiveDay(index.row());
@@ -588,7 +777,7 @@
 	QModelIndex index = mModel->index(mCurrentRow,0);
 	QVariant itemData = index.data(Qt::UserRole + 1);
 	QVariantList list = itemData.toList();
-	list.replace(CalendarNamespace::CalendarMonthFocusRole, QString(""));
+	list.replace(CalendarNamespace::CalendarMonthFocusRole, false);
 	mModel->itemFromIndex(index)->setData(list);
 	
 	// Search for this date in the model
@@ -598,7 +787,7 @@
 			itemData = index.data(Qt::UserRole + 1);
 			list = itemData.toList();
 			list.replace(CalendarNamespace::CalendarMonthFocusRole,
-							 QString("qtg_fr_cal_focused_day_ind"));
+										 true);
 			mModel->itemFromIndex(index)->setData(list);
 			mCurrentRow = i;
 			mView->setContextForActiveDay(i);
@@ -635,15 +824,12 @@
 	end = firstDateInGrid.daysTo(endOfActiveMonth);
 	
 	// Set the active text color
-	QColor textColor = HbColorScheme::color("qtc_cal_month_active_dates");
-	if (textColor.isValid()) {
-		for (int i = start; i < end; i++) {	
-			QModelIndex index = mModel->index(i,0);
-			QVariant itemData = index.data(Qt::UserRole + 1);
-			QVariantList list = itemData.toList();
-			list.replace(CalendarNamespace::CalendarMonthTextColorRole, textColor);
-			mModel->itemFromIndex(index)->setData(list);
-		}
+	for (int i = start; i < end; i++) {	
+		QModelIndex index = mModel->index(i,0);
+		QVariant itemData = index.data(Qt::UserRole + 1);
+		QVariantList list = itemData.toList();
+		list.replace(CalendarNamespace::CalendarMonthTextColorRole, true);
+		mModel->itemFromIndex(index)->setData(list);
 	}
 	
 	// Now set the inactive text color to those which were active before the swipe
@@ -683,15 +869,12 @@
 	}
 	
 	// Set the inactive text color
-	textColor = HbColorScheme::color("qtc_cal_month_notactive_dates");
-	if (textColor.isValid()) {
-		for (int i = start; i < end; i++) {		
-			QModelIndex index = mModel->index(i,0);
-			QVariant itemData = index.data(Qt::UserRole + 1);
-			QVariantList list = itemData.toList();
-			list.replace(CalendarNamespace::CalendarMonthTextColorRole, textColor);
-			mModel->itemFromIndex(index)->setData(list);
-		}
+	for (int i = start; i < end; i++) {		
+		QModelIndex index = mModel->index(i,0);
+		QVariant itemData = index.data(Qt::UserRole + 1);
+		QVariantList list = itemData.toList();
+		list.replace(CalendarNamespace::CalendarMonthTextColorRole, false);
+		mModel->itemFromIndex(index)->setData(list);
 	}
 }
 
@@ -730,6 +913,7 @@
 {
 	Q_UNUSED(option);
 	Q_UNUSED(widget);
+	painter->setRenderHint(QPainter::NonCosmeticDefaultPen);
 	
 	// Set the required attributes to the pen
 	QPen pen;
@@ -746,13 +930,29 @@
 	// Get the sizes of content widget
 	qreal contentHeight = mContentWidget->size().height();
 	qreal contentWidth = mContentWidget->size().width();
+	qreal rowWidth = 0.0;
+	int numOfRows = 0;
+	QPointF startPoint = mContentWidget->pos();
 	
-	// Get the num of rows
-	int numOfRows = mModel->rowCount() / KCalenDaysInWeek;
-	// Draw horizontal lines
-	qreal rowWidth = contentHeight / numOfRows;
+	// NOTE!!!: There is a filcker when we blindly draw equally spaced lines
+	// on complete content widget when scrolling is finished. This happens only
+	// when content widget size is changed due to the change in total number
+	// of rows when we append or prepend rows. Hence, to avoid this, we draw
+	// lines on complete content widget only when it is scrolling.
+	// That means, as soon as scrolling is finished, we will end up drawing 
+	// only 6 lines that are visible to the user.
+	if (mDirection == invalid) {
+		// Start point is left most point on the screen
+		startPoint = QPointF(0,0);
+		rowWidth = size().height() / KNumOfVisibleRows;
+		numOfRows = KNumOfVisibleRows;
+	} else {
+		// Get the num of rows
+		numOfRows = mModel->rowCount() / KCalenDaysInWeek;
+		// Draw horizontal lines
+		rowWidth = contentHeight / numOfRows;
+	}
 	
-	QPointF startPoint = mContentWidget->pos();
 	QPointF endPoint(startPoint.x() + contentWidth, 
 	                 startPoint.y());