calendarui/views/src/calenmonthgrid.cpp
changeset 26 a949c2543c15
parent 23 fd30d51f876b
child 32 ea672fcb0ea0
equal deleted inserted replaced
23:fd30d51f876b 26:a949c2543c15
    14  * Description: Definition file for class CalenMonthGrid.
    14  * Description: Definition file for class CalenMonthGrid.
    15  *
    15  *
    16  */
    16  */
    17 
    17 
    18 // System includes
    18 // System includes
    19 #include <qtimer.h>
       
    20 #include <hbmenu.h>
       
    21 #include <hbaction.h>
       
    22 #include <hbmainwindow.h>
       
    23 #include <hbgridview.h>
    19 #include <hbgridview.h>
    24 #include <hbabstractviewitem.h>
    20 #include <hbabstractviewitem.h>
    25 #include <hbstyleloader.h>
    21 #include <hbstyleloader.h>
    26 #include <hbcolorscheme.h>
    22 #include <hbcolorscheme.h>
    27 
    23 
    32 #include "calenmonthview.h"
    28 #include "calenmonthview.h"
    33 #include "calendateutils.h"
    29 #include "calendateutils.h"
    34 #include "calencommon.h"
    30 #include "calencommon.h"
    35 
    31 
    36 // Constants
    32 // Constants
    37 #define SCROLL_SPEEED 1000 
    33 #define SCROLL_SPEEED 2000 
    38 #define GRIDLINE_WIDTH 0.075 //units
    34 #define GRIDLINE_WIDTH 0.075 //units
    39 
    35 
    40 /*!
    36 /*!
    41  \class CalenMonthGrid
    37  \class CalenMonthGrid
    42 
    38 
    64 	setLongPressEnabled(false);
    60 	setLongPressEnabled(false);
    65 	setItemRecycling(false);
    61 	setItemRecycling(false);
    66 	setSelectionMode(HbGridView::NoSelection);
    62 	setSelectionMode(HbGridView::NoSelection);
    67 	setUniformItemSizes(true);
    63 	setUniformItemSizes(true);
    68 	setVerticalScrollBarPolicy(HbScrollArea::ScrollBarAlwaysOff);
    64 	setVerticalScrollBarPolicy(HbScrollArea::ScrollBarAlwaysOff);
    69 	setClampingStyle(HbScrollArea::StrictClamping );
    65 	setClampingStyle(HbScrollArea::StrictClamping);
       
    66 	setEnabledAnimations(HbAbstractItemView::None);
       
    67 	resetTransform();
    70 	
    68 	
    71 	// Get the content widget of the scroll area to draw the grid lines
    69 	// Get the content widget of the scroll area to draw the grid lines
    72 	mContentWidget = contentWidget();
    70 	mContentWidget = contentWidget();
    73 	
    71 	
    74 	// Get the color of the grid lines
    72 	// Get the all required colors 
       
    73 	// Color of the grid lines
    75 	mGridLineColor = HbColorScheme::color("qtc_cal_grid_line");
    74 	mGridLineColor = HbColorScheme::color("qtc_cal_grid_line");
    76 	
    75 	
    77 	// Create the prototype
    76 	// Get the localised dates well before
    78 	CalenGridItemPrototype* gridItemPrototype = new CalenGridItemPrototype(this);
    77 	// TODO: Need to update the mLocalisedDates when user changes the
    79 	// Create the model
    78 	// phone language keeping calendar application in background
    80 	mModel = new QStandardItemModel(14*KCalenDaysInWeek, 1, this);
    79 	HbExtendedLocale locale = HbExtendedLocale::system();
    81 	// Set the mode and the prototype
    80 	for (int i = 1; i <= 31; i++) {
    82 	setModel(mModel,gridItemPrototype);
    81 		mLocalisedDates.append(locale.toString(i));
    83 	
    82 	}
    84 	// Register the widgetml and css files
    83 	
    85 	HbStyleLoader::registerFilePath(":/");
    84 	// Connect to scrolling finished signal
    86 	
       
    87 	// Set the layout name
       
    88 	setLayoutName("calendarCustomGridItem");
       
    89 	
       
    90 	connect(this, SIGNAL(scrollingEnded()), this,
    85 	connect(this, SIGNAL(scrollingEnded()), this,
    91 			SLOT(scrollingFinished()));
    86 			SLOT(scrollingFinished()));
    92 	
    87 	
    93 	// Connect to item activated signal
    88 	// Connect to item activated signal
    94 	connect(this, SIGNAL(activated(const QModelIndex &)), this,
    89 	connect(this, SIGNAL(activated(const QModelIndex &)), this,
    98 /*!
    93 /*!
    99  Destructor
    94  Destructor
   100  */
    95  */
   101 CalenMonthGrid::~CalenMonthGrid()
    96 CalenMonthGrid::~CalenMonthGrid()
   102 {
    97 {
       
    98 	// Nothing Yet
   103 }
    99 }
   104 
   100 
   105 /*!
   101 /*!
   106  Stores the view pointer
   102  Stores the view pointer
   107  */
   103  */
   112 
   108 
   113 /*!
   109 /*!
   114  Updates the model with the proper dates and sets the required user roles
   110  Updates the model with the proper dates and sets the required user roles
   115  */
   111  */
   116 void CalenMonthGrid::updateMonthGridModel(QList<CalenMonthData> &monthDataArray,
   112 void CalenMonthGrid::updateMonthGridModel(QList<CalenMonthData> &monthDataArray,
   117                         int indexToBeScrolled)
   113                         int indexToBeScrolled, bool isFirstTime)
   118 {
   114 {
   119 	// Check the counts
   115 	int loopStart = 0;
   120 	int dataCount = monthDataArray.count();
   116 	int loopEnd = monthDataArray.count();
   121 	int rowCount = mModel->rowCount();
   117 	if (isFirstTime) {
   122 	int countDiff = dataCount - rowCount;
   118 		// Create the model with only 42 items as visible to the user
   123 	if (countDiff < 0) {
   119 		mModel = new QStandardItemModel(KCalenDaysInWeek * KNumOfVisibleRows, 
   124 		// Delete extra rows in the model
   120 		                                1, this);
   125 		mModel->removeRows(dataCount,abs(countDiff));
   121 		loopStart = (mView->rowsInPrevMonth()) * KCalenDaysInWeek;
   126 	} else if (countDiff > 0) {
   122 		loopEnd = loopStart + (KCalenDaysInWeek * KNumOfVisibleRows);
   127 		// Add the necessary number of rows
   123 	} else {
   128 		mModel->insertRows(rowCount,countDiff);
   124 		// Block the signals generated by model, this is being done as
   129 	}
   125 		// we want to avoid the overload of view listening to signals
       
   126 		mModel->blockSignals(true);
       
   127 		
       
   128 		// Check the counts
       
   129 		int dataCount = monthDataArray.count();
       
   130 		int rowCount = mModel->rowCount();
       
   131 		int countDiff = dataCount - rowCount;
       
   132 		if (countDiff < 0) {
       
   133 			// Delete extra rows in the model
       
   134 			mModel->removeRows(dataCount,abs(countDiff));
       
   135 		} else if (countDiff > 0) {
       
   136 			// Add the necessary number of rows
       
   137 			mModel->insertRows(rowCount,countDiff);
       
   138 		}
       
   139 		loopEnd = dataCount;
       
   140 	}
       
   141 	
   130 	QDateTime currDate = mView->getCurrentDay();
   142 	QDateTime currDate = mView->getCurrentDay();
   131 	QDateTime currDateTime = CalenDateUtils::beginningOfDay(currDate);
   143 	QDateTime currDateTime = CalenDateUtils::beginningOfDay(currDate);
   132 	QDateTime activeDay = mView->getActiveDay();
   144 	QDateTime activeDay = mView->getActiveDay();
   133 	QDateTime activeDateTime = CalenDateUtils::beginningOfDay(activeDay);
   145 	QDateTime activeDateTime = CalenDateUtils::beginningOfDay(activeDay);
   134 	
   146 	
   135 	QModelIndex currentIndex;
   147 	QModelIndex currentIndex;
   136 	
   148 	int modelIndex = 0;
   137 	// Get the default text color to be set
   149 	for (int i = loopStart; i < loopEnd; i++) {
   138 	QColor textColor = HbColorScheme::color("qtc_cal_month_notactive_dates");
       
   139 	HbExtendedLocale locale = HbExtendedLocale::system();
       
   140 	for (int i = 0; i < dataCount; i++) {
       
   141 		QDateTime dateTime = monthDataArray[i].Day();
   150 		QDateTime dateTime = monthDataArray[i].Day();
   142 		currentIndex = mModel->index(i, 0);
   151 		currentIndex = mModel->index(modelIndex++, 0);
   143 		// Get the localised string for the day
       
   144 		QString date = locale.toString(dateTime.date().day());
       
   145 		
   152 		
   146 		// Create the variant list to contain the date to depict a grid item
   153 		// Create the variant list to contain the date to depict a grid item
   147 		QVariantList itemData;
   154 		QVariantList itemData;
   148 		
   155 		
   149 		// NOTE: Add the data in the order mentioned in the 
   156 		// !!!NOTE!!!: Add the data in the order mentioned in the 
   150 		// CalendarNamespace::DataRole enum. Dont change the order.
   157 		// CalendarNamespace::DataRole enum. Dont change the order.
   151 		itemData << date; 
   158 		itemData << mLocalisedDates.at(dateTime.date().day()-1); 
   152 		
   159 		
   153 		// Check for active day
   160 		// Check for active day
   154 		if (activeDateTime == CalenDateUtils::beginningOfDay(dateTime)) {
   161 		if (activeDateTime == CalenDateUtils::beginningOfDay(dateTime)) {
   155 			mCurrentRow = currentIndex.row();
   162 			mCurrentRow = i;
   156 			// Set the focus icon
   163 			// Set the focus attribute to true
   157 			itemData << QString("qtg_fr_cal_focused_day_ind");
   164 			itemData << true;
   158 		} else {
   165 		} else {
   159 			// reset the highlight
   166 			// reset the highlight
   160 			itemData << QString("");
   167 			itemData << false;
   161 		}
   168 		}
   162 
   169 
   163 		// Check for current day
   170 		// Check for current day
   164 		if (currDateTime == CalenDateUtils::beginningOfDay(dateTime)) {
   171 		if (currDateTime == CalenDateUtils::beginningOfDay(dateTime)) {
   165 			// Set the underline icon
   172 			// Set the underline attribute to true
   166 			itemData << true;
   173 			itemData << true;
   167 		} else {			
   174 		} else {			
   168 			itemData << false;
   175 			itemData << false;
   169 		}
   176 		}
   170 
   177 
   171 		// Check for events
   178 		// Check for events
   172 		if (monthDataArray[i].HasEvents()) {
   179 		if (monthDataArray[i].HasEvents()) {
   173 			// Set the underline icon
   180 			// Set the event indicator attribute
   174 			itemData << QString("qtg_graf_cal_event_ind");
   181 			itemData << true;
   175 		} else {
   182 		} else {
   176 			itemData << QString("");
   183 			itemData << false;
   177 		}
   184 		}
   178 		
   185 		
   179 		// Add default text color
   186 		// Add default text color
   180 		itemData << textColor;
   187 		if (monthDataArray[i].isActive()) {
       
   188 			itemData << true;
       
   189 		} else {
       
   190 			itemData << false;
       
   191 		}
   181 		mModel->itemFromIndex(currentIndex)->setData(itemData);
   192 		mModel->itemFromIndex(currentIndex)->setData(itemData);
   182 	}
   193 	}
       
   194 	
       
   195 	if (isFirstTime) {
       
   196 		// Color of the today indicator
       
   197 		QColor todayIndColor = HbColorScheme::color("qtc_cal_month_current_day");
       
   198 		// Color of the active dates
       
   199 		QColor mActiveTextColor = 
       
   200 								HbColorScheme::color("qtc_cal_month_active_dates");
       
   201 		// Color of the inactive dates
       
   202 		QColor mInActiveTextColor = 
       
   203 							HbColorScheme::color("qtc_cal_month_notactive_dates");
       
   204 		
       
   205 		// Create the prototype
       
   206 		CalenGridItemPrototype* gridItemPrototype = new CalenGridItemPrototype(
       
   207 						todayIndColor, mActiveTextColor, mInActiveTextColor, this);
       
   208 		
       
   209 		// Set the mode and the prototype
       
   210 		setModel(mModel,gridItemPrototype);
       
   211 		
       
   212 		// Register the widgetml and css files
       
   213 		HbStyleLoader::registerFilePath(":/");
       
   214 		
       
   215 		// Set the layout name
       
   216 		setLayoutName("calendarCustomGridItem");
       
   217 	} else {
       
   218 		// Since, we have finished setData, Now unblock the signals
       
   219 		mModel->blockSignals(false);
       
   220 		
       
   221 		// Since till now, we had blocked signals being generated frm the mode
       
   222 		// view will be unaware of the items that we added. Hence, inform the view
       
   223 		// explicitly in one shot
       
   224 		QModelIndex leftIndex = mModel->index(0, 0);
       
   225 		QModelIndex rightIndex = mModel->index(loopEnd-1, 0);
       
   226 		dataChanged(leftIndex, rightIndex);
       
   227 		
       
   228 		// NOTE: To make sure that we always display proper month,
       
   229 		// two calls have been  made to scrollTo(), one with top
       
   230 		// visible item and other with bottom visible item
       
   231 		// Calculate the first visible item in the grid
       
   232 		QModelIndex firstVisibleIndex = mModel->index(indexToBeScrolled - 
       
   233 								(KNumOfVisibleRows * KCalenDaysInWeek - 1), 0);
       
   234 		scrollTo(firstVisibleIndex);
       
   235 		
       
   236 		
       
   237 		// Calculate the last visible item in the grid
       
   238 		QModelIndex lastVisibleIndex = mModel->index(indexToBeScrolled, 0);
       
   239 		scrollTo(lastVisibleIndex);
       
   240 	}
   183 	mMonthDataArray = monthDataArray;
   241 	mMonthDataArray = monthDataArray;
   184 	
   242 }
   185 	// Get the active month
   243 
   186 	QDateTime activeDate = mView->getActiveDay();
   244 /*!
   187 	// Set the text color properly
   245 	Updates the view with jprevious month dates when calendar is opened for the 
   188 	setActiveDates(activeDate.date());
   246 	first time to improve the opening time
   189 	
   247  */
   190 	// NOTE: To make sure that we always display proper month,
   248 void CalenMonthGrid::updateMonthGridWithInActiveMonths(
   191 	// two calls have been  made to scrollTo(), one with top
   249 										QList<CalenMonthData> &monthDataArray)
   192 	// visible item and other with bottom visible item
   250 {	
   193     // Calculate the first visible item in the grid
   251 	mMonthDataArray = monthDataArray;
   194     QModelIndex firstVisibleIndex = mModel->index(indexToBeScrolled - 
   252 		
   195                                         (KNumOfVisibleRows * KCalenDaysInWeek - 1), 0);
   253 	// Prepend the required rows
   196     scrollTo(firstVisibleIndex);
   254 	handlePrependingRows(monthDataArray);
   197     
   255 	
   198     
   256 	// Append the required rows
   199     // Calculate the last visible item in the grid
   257 	handleAppendingRows(monthDataArray);
   200     QModelIndex lastVisibleIndex = mModel->index(indexToBeScrolled, 0);
   258 	
   201     scrollTo(lastVisibleIndex);
   259 	int rowsInPrevMonth = mView->rowsInPrevMonth();
       
   260 	
       
   261 	// Calculate the proper index to be scrolled to
       
   262 	int itemToBeScrolled = rowsInPrevMonth * KCalenDaysInWeek;
       
   263 	QModelIndex indexToBeScrolled = mModel->index(itemToBeScrolled, 0);
       
   264 	mIsAtomicScroll = true;
       
   265 	scrollTo(indexToBeScrolled);
       
   266 		
       
   267 	// Scroll to proper index
       
   268 	itemToBeScrolled = ((rowsInPrevMonth + KNumOfVisibleRows) * 
       
   269 								   KCalenDaysInWeek) - 1;
       
   270 	indexToBeScrolled = mModel->index(itemToBeScrolled, 0);
       
   271 	mIsAtomicScroll = true;
       
   272 	scrollTo(indexToBeScrolled);
       
   273 }
       
   274 
       
   275 /*!
       
   276 	Updates the view with just event indicators
       
   277  */
       
   278 void CalenMonthGrid::updateMonthGridWithEventIndicators(
       
   279 										QList<CalenMonthData> &monthDataArray)
       
   280 {
       
   281 	mMonthDataArray = monthDataArray;
       
   282 	for(int i = 0; i < monthDataArray.count(); i++) {
       
   283 		// Check if the day has events
       
   284 		if (monthDataArray[i].HasEvents()) {
       
   285 			QModelIndex itemIndex = mModel->index(i,0);
       
   286 			QVariant itemData = itemIndex.data(Qt::UserRole + 1);
       
   287 			QVariantList list = itemData.toList();
       
   288 			list.replace(CalendarNamespace::CalendarMonthEventRole, true);
       
   289 			mModel->itemFromIndex(itemIndex)->setData(list);
       
   290 		}
       
   291 	}
   202 }
   292 }
   203 
   293 
   204 /*!
   294 /*!
   205  Listens for down gesture
   295  Listens for down gesture
   206  */
   296  */
   207 void CalenMonthGrid::downGesture (int value)
   297 void CalenMonthGrid::downGesture (int value)
   208 {
   298 {
   209 	Q_UNUSED(value)	
   299 	Q_UNUSED(value)	
   210 	mDirection = down;
   300 	mDirection = down;
   211 	// Before we start scrolling, setthe active text color to previous month
   301 	mIsAtomicScroll = false;
   212 	QDateTime activeDate = mView->getActiveDay();
   302 	setAttribute(Hb::InteractionDisabled);
   213 	setActiveDates(activeDate.addMonths(-1).date());
   303 	
   214 	HbScrollArea::downGesture(SCROLL_SPEEED);
   304 	// pass it to parent
       
   305 	HbScrollArea::downGesture(value);
   215 }
   306 }
   216 
   307 
   217 /*!
   308 /*!
   218  Listens for Up gesture
   309  Listens for Up gesture
   219  */
   310  */
   220 void CalenMonthGrid::upGesture (int value)
   311 void CalenMonthGrid::upGesture (int value)
   221 {
   312 {
   222 	Q_UNUSED(value)	
   313 	Q_UNUSED(value)	
   223 	mDirection = up;
   314 	mDirection = up;
   224 	// Before we start scrolling, setthe active text color to future month
   315 	mIsAtomicScroll = false;
   225 	QDateTime activeDate = mView->getActiveDay();
   316 	setAttribute(Hb::InteractionDisabled);
   226 	setActiveDates(activeDate.addMonths(1).date());
   317 	
   227 	HbScrollArea::upGesture(SCROLL_SPEEED);
   318 	// pass it to parent
       
   319 	HbScrollArea::upGesture(value);
       
   320 	
   228 }
   321 }
   229 
   322 
   230 /*!
   323 /*!
   231  Function to listen mouse press events
   324  Function to listen mouse press events
   232  */
   325  */
   255 /*!
   348 /*!
   256  Listens for pan gesture
   349  Listens for pan gesture
   257  */
   350  */
   258 void  CalenMonthGrid::panGesture(const QPointF &  delta)
   351 void  CalenMonthGrid::panGesture(const QPointF &  delta)
   259 {
   352 {
       
   353 	setAttribute(Hb::InteractionDisabled);
       
   354 	mIsAtomicScroll = false;
   260 	if (!mIsPanGesture) {
   355 	if (!mIsPanGesture) {
   261 		mIsPanGesture = true;
   356 		mIsPanGesture = true;
   262 		mIgnoreItemActivated = true;
   357 		mIgnoreItemActivated = true;
   263 		
   358 		mStartPos = mContentWidget->pos();
   264 		// Get to know the direction of the gesture
   359 		// Get to know the direction of the gesture
   265 		if (delta.y() > 0) {
   360 		if (delta.y() > 0) {
   266 			mDirection = down;
   361 			mDirection = down;
   267 		} else {
   362 		} else {
   268 			mDirection = up;
   363 			mDirection = up;
   269 		}
   364 		}
   270 	} else { // This case is when user changes the direction while panning
   365 	}
   271 		// without lifting the finger
   366 	
   272 		// Check if direction has changed
       
   273 		if (((delta.y() > 0) && (mDirection == up))
       
   274 			|| ((delta.y() < 0) && (mDirection == down))) {
       
   275 			// Direction has changed, ignore this pan
       
   276 			return;
       
   277 		}
       
   278 	}
       
   279 	// Call the parent class to perform the pan gesture
   367 	// Call the parent class to perform the pan gesture
   280 	// When scrolling finished, month grid will adjust to show the proper month
   368 	// When scrolling finished, month grid will adjust to show the proper month
   281 	HbScrollArea::panGesture(delta);
   369 	HbScrollArea::panGesture(delta);
   282 }
   370 }
   283 
   371 
   286  */
   374  */
   287 void CalenMonthGrid::scrollingFinished()
   375 void CalenMonthGrid::scrollingFinished()
   288 {
   376 {
   289 	
   377 	
   290 	if (mIsPanGesture) {
   378 	if (mIsPanGesture) {
   291 		mIsPanGesture = false;
   379 		handlePanGestureFinished();
   292 		if (mDirection == up) {
       
   293 			// Make a request for upgesture
       
   294 			upGesture(SCROLL_SPEEED);
       
   295 			return; // return immediately
       
   296 		} else if (mDirection == down) {
       
   297 			// Make a request for upgesture
       
   298 			downGesture(SCROLL_SPEEED);
       
   299 			return; // return immediately
       
   300 		}
       
   301 	} else if(!mIsAtomicScroll) {
   380 	} else if(!mIsAtomicScroll) {
   302 		// Before we do anything, set the focus to proper date
   381 		QDateTime activeDate = mView->getActiveDay();
   303 		// Set it only when non active day was focussed. When inactive day
   382 		if(mDirection == down) { // down gesture
   304 		// was focussed, we need to focus the same day
   383 			if (!mIsNonActiveDayFocused) {
   305 		if (!mIsNonActiveDayFocused) {
   384 				setActiveDates(activeDate.addMonths(-1).date());
   306 			setFocusToProperDay();
   385 			}
   307 		}
   386 			prependRows();
   308 		// To improve the performance, lets start the timer for 10 ms, 
   387 		} else if (mDirection == up) { //up gesture
   309 		// return immediately and do the other things after that
   388 			if (!mIsNonActiveDayFocused) {
   310 		QTimer::singleShot(10, this, SLOT(timerExpired()));
   389 				setActiveDates(activeDate.addMonths(1).date());
       
   390 			}
       
   391 			appendRows();
       
   392 		}
       
   393 		mDirection = invalid;
   311 	} else {
   394 	} else {
   312         mIsAtomicScroll = false;
   395         mIsAtomicScroll = false;
   313 	}
   396 	}
   314 	mIgnoreItemActivated = false;
   397 	mIgnoreItemActivated = false;
   315 }
   398 	setAttribute(Hb::InteractionDisabled, false);
   316 
   399 }
   317 void CalenMonthGrid::timerExpired()
   400 
   318 {
   401 /*!
   319 	if(mDirection == down) { // down gesture
   402  Function to handle completion of pan gesture
   320 		prependRows();
   403  */
   321 	} else if (mDirection == up) { //up gesture
   404 void CalenMonthGrid::handlePanGestureFinished()
   322 		appendRows();
   405 {
   323 	}
   406 	mIsPanGesture = false;
   324 	mDirection = invalid;
   407 	// Get the first item that is visible
       
   408 	QList<HbAbstractViewItem *> list = visibleItems();
       
   409 	HbAbstractViewItem* item = list[0];
       
   410 	QModelIndex modelIndex = item->modelIndex();
       
   411 	
       
   412 	// Get the date which is visible at the above row
       
   413 	QDateTime date = mMonthDataArray[modelIndex.row()].Day();
       
   414 	
       
   415 	// Check if this date belong to current active month or 
       
   416 	// previous month else future month
       
   417 	QDateTime activeMonth = mView->getActiveDay();
       
   418 	QDateTime prevMonth = activeMonth.addMonths(-1);
       
   419 	QDateTime nextMonth = activeMonth.addMonths(1);
       
   420 	int month = date.date().month();
       
   421 	if (month == activeMonth.date().month()) {
       
   422 		// Then pan is completed on current month
       
   423 		// Check if the date is more than half of the current month or it is
       
   424 		// more than or equal to half of the future month
       
   425 		if (date.date().day() > (activeMonth.date().daysInMonth()) / 2 ||
       
   426 				date.addDays(KNumOfVisibleRows*KCalenDaysInWeek).date().day() >=
       
   427 				(prevMonth.date().daysInMonth()) / 2) {
       
   428 			// up gesture to bring the next month
       
   429 			upGesture(SCROLL_SPEEED);
       
   430 		} else {
       
   431 			// we should again show the current month by scrolling downwards
       
   432 			mDirection = down;
       
   433 			mIsAtomicScroll = true;
       
   434 			scrollContentsTo(-mStartPos,500);
       
   435 		}
       
   436 	} else if (month == prevMonth.date().month()) {
       
   437 		// first visible item belongs to previous month
       
   438 		// Check if the date is more than half of the previous month
       
   439 		if (date.date().day() > (prevMonth.date().daysInMonth()) / 2) {
       
   440 			// we should again show the current month by scrolling upwards
       
   441 			mDirection = up;
       
   442 			mIsAtomicScroll = true;
       
   443 			scrollContentsTo(-mStartPos,500);
       
   444 		} else {
       
   445 			// down gesture to show the previous month
       
   446 			downGesture(SCROLL_SPEEED);
       
   447 		}
       
   448 	} else if (month == nextMonth.date().month()) {
       
   449 		// first visible item belongs to next month
       
   450 		// Check if the date is more than half of the next month
       
   451 		if (date.date().day() > (nextMonth.date().daysInMonth()) / 2) {
       
   452 			// up gesture to bring the next month
       
   453 			upGesture(SCROLL_SPEEED);
       
   454 		} else {
       
   455 			// we should again show the current month by scrolling upwards
       
   456 			mDirection = invalid;
       
   457 			scrollContentsTo(-mStartPos,500);
       
   458 		}
       
   459 	}
   325 }
   460 }
   326 
   461 
   327 /*!
   462 /*!
   328  Called when down gesture is performed. Adds the new previous month details
   463  Called when down gesture is performed. Adds the new previous month details
   329  to the model
   464  to the model
   330  */
   465  */
   331 void CalenMonthGrid::prependRows()
   466 void CalenMonthGrid::prependRows()
   332 {
   467 {
       
   468 	// Before we do anything, set the focus to proper date
       
   469 	// Set it only when non active day was focussed. When inactive day
       
   470 	// was focussed, we need to focus the same day
       
   471 	if (!mIsNonActiveDayFocused) {
       
   472 		setFocusToProperDay();
       
   473 	}
       
   474 	
       
   475 	// Block the signals generated by model, this is being done as
       
   476 	// we want to avoid the overload of view listening to signals
       
   477 	mModel->blockSignals(true);
       
   478 		
   333 	mIsNonActiveDayFocused = false;
   479 	mIsNonActiveDayFocused = false;
   334 	QDateTime currDate = mView->getCurrentDay();
   480 	
   335 	QDateTime currDateTime = CalenDateUtils::beginningOfDay( currDate );
       
   336 	int rowsInFutMonthEarlier = mView->rowsInFutMonth();
   481 	int rowsInFutMonthEarlier = mView->rowsInFutMonth();
   337 	int rowsInPrevMonthEarlier = mView->rowsInPrevMonth();
   482 	int rowsInPrevMonthEarlier = mView->rowsInPrevMonth();
       
   483 	
       
   484 	// remove the cells in the future month
       
   485 	int deleteFromIndex = (rowsInPrevMonthEarlier + KNumOfVisibleRows) * KCalenDaysInWeek;
       
   486 	int numOfIndices = rowsInFutMonthEarlier * KCalenDaysInWeek;
   338 	
   487 	
   339 	// Get the updated dates from the view
   488 	// Get the updated dates from the view
   340 	mView->updateModelWithPrevMonth();
   489 	mView->updateModelWithPrevMonth();
   341 	QList<CalenMonthData > monthDataList = mView->monthDataList();
   490 	QList<CalenMonthData > monthDataList = mView->monthDataList();
   342 	mMonthDataArray = monthDataList;
   491 	mMonthDataArray = monthDataList;
   343 	int listCount = monthDataList.count();
   492 	
   344 	// Get the updated rows to be inserted
   493 	// Prepend the required rows
       
   494 	handlePrependingRows(monthDataList);
       
   495 		
       
   496 	// Since, we have finished setData, Now unblock the signals
       
   497 	mModel->blockSignals(false);
       
   498 	
   345 	int rowsInPrevMonth = mView->rowsInPrevMonth();
   499 	int rowsInPrevMonth = mView->rowsInPrevMonth();
   346 	int rowsInFutMonth = mView->rowsInFutMonth();
       
   347 	
       
   348 	// remove the cells in the future month
       
   349 	int deleteFromIndex = (rowsInPrevMonthEarlier + KNumOfVisibleRows) * KCalenDaysInWeek;
       
   350 	int numOfIndices = rowsInFutMonthEarlier * KCalenDaysInWeek;
       
   351 	int count = mModel->rowCount();
       
   352 	
       
   353 	count = mModel->rowCount();
       
   354 	
       
   355 	// Add the new days
       
   356 	int countToBeAdded = rowsInPrevMonth * KCalenDaysInWeek;
   500 	int countToBeAdded = rowsInPrevMonth * KCalenDaysInWeek;
   357 	
   501 		
   358 	mModel->insertRows(0, countToBeAdded);
   502 	// Since till now, we had blocked signals being generated frm the model
   359 	count = mModel->rowCount();
   503 	// view will be unaware of the items that we added. Hence, inform the view
   360 	
   504 	// explicitly in one shot
   361 	// Get the default text color to be set
   505 	QModelIndex leftIndex = mModel->index(0, 0);
   362 	QColor textColor = HbColorScheme::color("qtc_cal_month_notactive_dates");
   506 	QModelIndex rightIndex = mModel->index(countToBeAdded-1, 0);
   363 	HbExtendedLocale locale = HbExtendedLocale::system();
   507 	dataChanged(leftIndex, rightIndex);
   364 	
   508 		
   365 	for (int i = 0; i < countToBeAdded; i++) {
       
   366 		QDateTime dateTime = monthDataList[i].Day();
       
   367 		
       
   368 		// Get the localised string for the day
       
   369 		QString date = locale.toString(dateTime.date().day());
       
   370 		QModelIndex currentIndex = mModel->index(i, 0);
       
   371 		
       
   372 		// Create the variant list to contain the date to depict a grid item
       
   373 		QVariantList itemData;
       
   374 		
       
   375 		// NOTE: Add the data in the order mentioned in the 
       
   376 		// CalendarNamespace::DataRole enum. Dont change the order.
       
   377 		itemData << date;
       
   378 				
       
   379 		// Diable the focus role
       
   380 		itemData << QString("");
       
   381 		
       
   382 		// Check for current day
       
   383 		if  (currDateTime == CalenDateUtils::beginningOfDay( dateTime )) {
       
   384 			// Set the underline icon
       
   385 			itemData << true;
       
   386 		} else {
       
   387 			itemData << false;
       
   388 		}
       
   389 		
       
   390 		// Update the event indicators
       
   391 		if (monthDataList[i].HasEvents()) {
       
   392 			// Set the event indicator icon
       
   393 			itemData << QString("qtg_graf_cal_event_ind");
       
   394 		} else {
       
   395 			itemData << QString("");
       
   396 		}
       
   397 		
       
   398 		// Add default text color
       
   399 		
       
   400 		itemData << textColor;
       
   401 		
       
   402 		// Set the data to model
       
   403 		mModel->itemFromIndex(currentIndex)->setData(itemData);
       
   404 	}
       
   405 	
       
   406 	// Update the mCurrentRow
       
   407 	mCurrentRow += countToBeAdded;
       
   408 	// Scroll to proper index
       
   409 	int itemToBeScrolled = ((rowsInPrevMonth + KNumOfVisibleRows) * 
       
   410 								   KCalenDaysInWeek) - 1;
       
   411 	QModelIndex indexToBeScrolled = mModel->index(itemToBeScrolled, 0);
       
   412 	QMap<int, QVariant> data;
       
   413 	data = mModel->itemData(indexToBeScrolled);
       
   414 	QVariant value = data.value(Qt::DisplayRole);
       
   415 	int date = value.toInt();
       
   416 	mIsAtomicScroll = true;
       
   417 	scrollTo(indexToBeScrolled);
       
   418 	
       
   419 	// Now remove the necessary items frm the model
   509 	// Now remove the necessary items frm the model
   420 	mModel->removeRows(deleteFromIndex+countToBeAdded, numOfIndices);
   510 	mModel->removeRows(deleteFromIndex+countToBeAdded, numOfIndices);
   421 	mIsAtomicScroll = true;
   511 	mIsAtomicScroll = true;
   422 	itemToBeScrolled = rowsInPrevMonth * KCalenDaysInWeek;
   512 	int itemToBeScrolled = rowsInPrevMonth * KCalenDaysInWeek;
       
   513 	QModelIndex indexToBeScrolled  = mModel->index(itemToBeScrolled, 0);
       
   514 	scrollTo(indexToBeScrolled);
       
   515 	
       
   516 	// Scroll to proper index
       
   517 	itemToBeScrolled = ((rowsInPrevMonth + KNumOfVisibleRows) * 
       
   518 								   KCalenDaysInWeek) - 1;
   423 	indexToBeScrolled = mModel->index(itemToBeScrolled, 0);
   519 	indexToBeScrolled = mModel->index(itemToBeScrolled, 0);
       
   520 	mIsAtomicScroll = true;
   424 	scrollTo(indexToBeScrolled);
   521 	scrollTo(indexToBeScrolled);
       
   522 	// Update the mCurrentRow
       
   523 	mCurrentRow += countToBeAdded;
       
   524 }
       
   525 
       
   526 /*!
       
   527 	Helper function that prepends the required rows to the model
       
   528  */
       
   529 void CalenMonthGrid::handlePrependingRows(QList<CalenMonthData > &monthDataList)
       
   530 {
       
   531 	QDateTime currDate = mView->getCurrentDay();
       
   532 	QDateTime currDateTime = CalenDateUtils::beginningOfDay( currDate );
       
   533 	int rowsInPrevMonth = mView->rowsInPrevMonth();
       
   534 	// Add the new days
       
   535 	int countToBeAdded = rowsInPrevMonth * KCalenDaysInWeek;
       
   536 	
       
   537 	mModel->insertRows(0, countToBeAdded);
       
   538 	
       
   539 	for (int i = 0; i < countToBeAdded; i++) {
       
   540 		QDateTime dateTime = monthDataList[i].Day();
       
   541 		
       
   542 		// Get the localised string for the day
       
   543 		QModelIndex currentIndex = mModel->index(i, 0);
       
   544 		
       
   545 		// Create the variant list to contain the date to depict a grid item
       
   546 		QVariantList itemData;
       
   547 		
       
   548 		// NOTE: Add the data in the order mentioned in the 
       
   549 		// CalendarNamespace::DataRole enum. Dont change the order.
       
   550 		itemData << mLocalisedDates.at(dateTime.date().day()-1);;
       
   551 				
       
   552 		// Disable the focus role
       
   553 		itemData << false;
       
   554 		
       
   555 		// Check for current day
       
   556 		if  (currDateTime == CalenDateUtils::beginningOfDay( dateTime )) {
       
   557 			// Set the underline icon attribute
       
   558 			itemData << true;
       
   559 		} else {
       
   560 			itemData << false;
       
   561 		}
       
   562 		
       
   563 		// Update the event indicators
       
   564 		if (monthDataList[i].HasEvents()) {
       
   565 			// Set the event indicator attribute
       
   566 			itemData << true;
       
   567 		} else {
       
   568 			itemData << false;
       
   569 		}
       
   570 		
       
   571 		// Add default text color
       
   572 		itemData << false;
       
   573 		
       
   574 		// Set the data to model
       
   575 		mModel->itemFromIndex(currentIndex)->setData(itemData);
       
   576 	}
   425 }
   577 }
   426 
   578 
   427 /*!
   579 /*!
   428  Called when Up gwsture is performed. Adds the new future month details
   580  Called when Up gwsture is performed. Adds the new future month details
   429  to the model
   581  to the model
   430  */
   582  */
   431 void CalenMonthGrid::appendRows()
   583 void CalenMonthGrid::appendRows()
   432 {
   584 {
       
   585 	// Before we do anything, set the focus to proper date
       
   586 	// Set it only when non active day was focussed. When inactive day
       
   587 	// was focussed, we need to focus the same day
       
   588 	if (!mIsNonActiveDayFocused) {
       
   589 		setFocusToProperDay();
       
   590 	}
       
   591 	
       
   592 	// Block the signals generated by model, this is being done as
       
   593 	// we want to avoid the overload of view listening to signals
       
   594 	mModel->blockSignals(true);
       
   595 	
   433 	mIsNonActiveDayFocused = false;
   596 	mIsNonActiveDayFocused = false;
   434 	QDateTime currDate = mView->getCurrentDay();
   597 	
   435 	QDateTime currDateTime = CalenDateUtils::beginningOfDay( currDate );
       
   436 	int rowsInFutMonth = mView->rowsInFutMonth();
   598 	int rowsInFutMonth = mView->rowsInFutMonth();
   437 	int rowsInPrevMonth = mView->rowsInPrevMonth();
   599 	int rowsInPrevMonth = mView->rowsInPrevMonth();
   438 	// remove the cells in the previous month
   600 	// remove the cells in the previous month
   439 	int countToBeDeleted = rowsInPrevMonth * KCalenDaysInWeek;
   601 	int countToBeDeleted = rowsInPrevMonth * KCalenDaysInWeek;
   440 		
   602 		
   441 	// Get the updated dates from the view
   603 	// Get the updated dates from the view
   442 	mView->updateModelWithFutureMonth();
   604 	mView->updateModelWithFutureMonth();
   443 	QList<CalenMonthData > monthDataList = mView->monthDataList();
   605 	QList<CalenMonthData > monthDataList = mView->monthDataList();
   444 	mMonthDataArray = monthDataList;
   606 	mMonthDataArray = monthDataList;
   445 	// Get the updated rows to be inserted
   607 	
   446 	rowsInPrevMonth = mView->rowsInPrevMonth();
   608 	// Get the model count before we add any rows into the mode
   447 	rowsInFutMonth = mView->rowsInFutMonth();
       
   448 	int countToBeAdded = rowsInFutMonth * KCalenDaysInWeek;
       
   449 	int lastVisibleIndex = monthDataList.count() - countToBeAdded;
       
   450 	
       
   451 	int rowCount = mModel->rowCount();
   609 	int rowCount = mModel->rowCount();
   452 	mModel->insertRows(rowCount, countToBeAdded);
   610 	// Append the required rows
   453 	
   611 	handleAppendingRows(monthDataList);
   454 	// Get the default text color to be set
   612 	
   455 	QColor textColor = HbColorScheme::color("qtc_cal_month_notactive_dates");
   613 	// Since, we have finished setData, Now unblock the signals
   456 	for (int i = 0; i < countToBeAdded; i++) {
   614 	mModel->blockSignals(false);
   457 		QMap<int, QVariant> data;
   615 	
   458 		QModelIndex currentIndex = mModel->index(rowCount + i, 0);
   616 	// Since till now, we had blocked signals being generated frm the mode
   459 				
   617 	// view will be unaware of the items that we added. Hence, inform the view
   460 		QDateTime dateTime = monthDataList[lastVisibleIndex + i].Day();
   618 	// explicitly in one shot
   461 		HbExtendedLocale locale = HbExtendedLocale::system();
   619 	QModelIndex leftIndex = mModel->index(rowCount-1, 0);
   462 		// Get the localised string for the day
   620 	QModelIndex rightIndex = mModel->index(mModel->rowCount()-1, 0);
   463 		QString date = locale.toString(dateTime.date().day());
   621 	dataChanged(leftIndex, rightIndex);
   464 		data.insert(CalendarNamespace::CalendarMonthDayRole, date);
   622 		
   465 		
       
   466 		// Create the variant list to contain the date to depict a grid item
       
   467 		QVariantList itemData;
       
   468 		
       
   469 		// NOTE: Add the data in the order mentioned in the 
       
   470 		// CalendarNamespace::DataRole enum. Dont change the order.
       
   471 		itemData << date;
       
   472 		
       
   473 		// Disable the focus role
       
   474 		itemData << QString("");
       
   475 		
       
   476 		// Check for current day
       
   477 		if (currDateTime == CalenDateUtils::beginningOfDay( dateTime )) {
       
   478 			// Set the underline icon
       
   479 			itemData << true;
       
   480 		} else {
       
   481 			itemData << false;
       
   482 		}
       
   483 		
       
   484 		// Update the event indicators
       
   485 		if (monthDataList[lastVisibleIndex + i].HasEvents()) {
       
   486 			// Set the underline icon
       
   487 			itemData << QString("qtg_graf_cal_event_ind");
       
   488 		} else {
       
   489 			itemData << QString("");
       
   490 		}
       
   491 		
       
   492 		// Add default text color
       
   493 		itemData << textColor;
       
   494 				
       
   495 		// Set the data to model
       
   496 		mModel->itemFromIndex(currentIndex)->setData(itemData);
       
   497 	}
       
   498 	
       
   499 	// Update the mCurrentRow
   623 	// Update the mCurrentRow
   500 	mCurrentRow -= (countToBeDeleted);
   624 	mCurrentRow -= (countToBeDeleted);
   501 	for (int i = 0; i < countToBeDeleted; i++) {
   625 	for (int i = 0; i < countToBeDeleted; i++) {
   502 		mModel->removeRow(0);
   626 		mModel->removeRow(0);
   503 	}
   627 	}
       
   628 	
   504 	mIsAtomicScroll = true;
   629 	mIsAtomicScroll = true;
       
   630 	
       
   631 	rowsInFutMonth = mView->rowsInFutMonth();
       
   632 	rowsInPrevMonth = mView->rowsInPrevMonth();
   505 	
   633 	
   506 	// Calculate the proper index to be scrolled to
   634 	// Calculate the proper index to be scrolled to
   507 	int itemToBeScrolled = rowsInPrevMonth * KCalenDaysInWeek;
   635 	int itemToBeScrolled = rowsInPrevMonth * KCalenDaysInWeek;
   508 	QModelIndex indexToBeScrolled = mModel->index(itemToBeScrolled, 0);
   636 	QModelIndex indexToBeScrolled = mModel->index(itemToBeScrolled, 0);
   509 	scrollTo(indexToBeScrolled);
   637 	scrollTo(indexToBeScrolled);
       
   638 	
       
   639 	itemToBeScrolled = ((rowsInPrevMonth + KNumOfVisibleRows) * 
       
   640 									   KCalenDaysInWeek) - 1;
       
   641 	indexToBeScrolled = mModel->index(itemToBeScrolled, 0);
       
   642 	mIsAtomicScroll = true;
       
   643 	scrollTo(indexToBeScrolled);
       
   644 }
       
   645 
       
   646 /*!
       
   647 	Helper function that appends the required rows to the model
       
   648  */
       
   649 void CalenMonthGrid::handleAppendingRows(QList<CalenMonthData > &monthDataList)
       
   650 {
       
   651 	QDateTime currDate = mView->getCurrentDay();
       
   652 	QDateTime currDateTime = CalenDateUtils::beginningOfDay( currDate );
       
   653 	int rowsInFutMonth = mView->rowsInFutMonth();
       
   654 	int countToBeAdded = rowsInFutMonth * KCalenDaysInWeek;
       
   655 	int lastVisibleIndex = monthDataList.count() - countToBeAdded;
       
   656 	
       
   657 	int rowCount = mModel->rowCount();
       
   658 	mModel->insertRows(rowCount, countToBeAdded);
       
   659 	
       
   660 	for (int i = 0; i < countToBeAdded; i++) {
       
   661 		QModelIndex currentIndex = mModel->index(rowCount + i, 0);
       
   662 				
       
   663 		QDateTime dateTime = monthDataList[lastVisibleIndex + i].Day();
       
   664 		
       
   665 		// Create the variant list to contain the date to depict a grid item
       
   666 		QVariantList itemData;
       
   667 		
       
   668 		// NOTE: Add the data in the order mentioned in the 
       
   669 		// CalendarNamespace::DataRole enum. Dont change the order.
       
   670 		itemData << mLocalisedDates.at(dateTime.date().day()-1);;
       
   671 		
       
   672 		// Disable the focus role
       
   673 		itemData << false;
       
   674 		
       
   675 		// Check for current day
       
   676 		if (currDateTime == CalenDateUtils::beginningOfDay( dateTime )) {
       
   677 			// Set the underline icon attribute
       
   678 			itemData << true;
       
   679 		} else {
       
   680 			itemData << false;
       
   681 		}
       
   682 		
       
   683 		// Update the event indicators
       
   684 		if (monthDataList[lastVisibleIndex + i].HasEvents()) {
       
   685 			// Set the event indicator attribute
       
   686 			itemData << true;
       
   687 		} else {
       
   688 			itemData << false;
       
   689 		}
       
   690 		
       
   691 		// Add default text color
       
   692 		itemData << false;
       
   693 				
       
   694 		// Set the data to model
       
   695 		mModel->itemFromIndex(currentIndex)->setData(itemData);
       
   696 	}
   510 }
   697 }
   511 
   698 
   512 /*!
   699 /*!
   513  Slot to handle when a particular grid item is tapped
   700  Slot to handle when a particular grid item is tapped
   514  */
   701  */
   526 	} else {
   713 	} else {
   527 		// Reset the focus attribute to this item		
   714 		// Reset the focus attribute to this item		
   528 		QModelIndex itemIndex = mModel->index(mCurrentRow,0);
   715 		QModelIndex itemIndex = mModel->index(mCurrentRow,0);
   529 		QVariant itemData = itemIndex.data(Qt::UserRole + 1);
   716 		QVariant itemData = itemIndex.data(Qt::UserRole + 1);
   530 		QVariantList list = itemData.toList();
   717 		QVariantList list = itemData.toList();
   531 		list.replace(CalendarNamespace::CalendarMonthFocusRole, QString(""));
   718 		list.replace(CalendarNamespace::CalendarMonthFocusRole, false);
   532 		mModel->itemFromIndex(itemIndex)->setData(list);
   719 		mModel->itemFromIndex(itemIndex)->setData(list);
   533 		
   720 		
   534 		// Inform view to update the context and preview panes
   721 		// Inform view to update the context and preview panes
   535 		mCurrentRow = index.row();
   722 		mCurrentRow = index.row();
   536 		itemIndex = mModel->index(mCurrentRow,0);
   723 		itemIndex = mModel->index(mCurrentRow,0);
   537 		itemData = itemIndex.data(Qt::UserRole + 1);
   724 		itemData = itemIndex.data(Qt::UserRole + 1);
   538 		list = itemData.toList();
   725 		list = itemData.toList();
   539 		list.replace(CalendarNamespace::CalendarMonthFocusRole, 
   726 		list.replace(CalendarNamespace::CalendarMonthFocusRole, 
   540 						 QString("qtg_fr_cal_focused_day_ind"));
   727 								 true);
   541 		mModel->itemFromIndex(itemIndex)->setData(list);
   728 		mModel->itemFromIndex(itemIndex)->setData(list);
   542 		// Check if inactive date is tapped
   729 		// Check if inactive date is tapped
   543 		QDateTime activeMonth = mView->getActiveDay();
   730 		QDateTime activeMonth = mView->getActiveDay();
   544 		int month = activeMonth.date().month();
   731 		int month = activeMonth.date().month();
   545 		if(month != mMonthDataArray[mCurrentRow].Day().date().month()){
   732 		if(month != mMonthDataArray[mCurrentRow].Day().date().month()){
   546 			// Set the flag
   733 			// Set the flag
   547 			mIsNonActiveDayFocused = true;
   734 			mIsNonActiveDayFocused = true;
   548 			mNonActiveFocusedDay = mMonthDataArray[mCurrentRow].Day();
   735 			mNonActiveFocusedDay = mMonthDataArray[mCurrentRow].Day();
   549 			
   736 			
   550 			// Get the current active month
   737 			// Add one month to active month
   551 			QDateTime activeMonth = mView->getActiveDay();
       
   552 			// Add one month to it
       
   553 			activeMonth = activeMonth.addMonths(1);
   738 			activeMonth = activeMonth.addMonths(1);
   554 			if (activeMonth.date().month() == 
   739 			if (activeMonth.date().month() == 
   555 				mNonActiveFocusedDay.date().month()) {
   740 				mNonActiveFocusedDay.date().month()) {
       
   741 				mDirection = up;
   556 				// up gesture
   742 				// up gesture
   557 				upGesture(SCROLL_SPEEED);
   743 				upGesture(SCROLL_SPEEED);
       
   744 				setActiveDates(activeMonth.date());
   558 			} else {
   745 			} else {
       
   746 				mDirection = down;
   559 				// down gesture
   747 				// down gesture
   560 				downGesture(SCROLL_SPEEED);
   748 				downGesture(SCROLL_SPEEED);
       
   749 				setActiveDates(activeMonth.addMonths(-2).date());
   561 			}
   750 			}
   562 		} 
   751 		} 
   563 		mView->setContextForActiveDay(index.row());
   752 		mView->setContextForActiveDay(index.row());
   564 	}
   753 	}
   565 }
   754 }
   586 	}
   775 	}
   587 	// Reset the focus attribute to earlier current item
   776 	// Reset the focus attribute to earlier current item
   588 	QModelIndex index = mModel->index(mCurrentRow,0);
   777 	QModelIndex index = mModel->index(mCurrentRow,0);
   589 	QVariant itemData = index.data(Qt::UserRole + 1);
   778 	QVariant itemData = index.data(Qt::UserRole + 1);
   590 	QVariantList list = itemData.toList();
   779 	QVariantList list = itemData.toList();
   591 	list.replace(CalendarNamespace::CalendarMonthFocusRole, QString(""));
   780 	list.replace(CalendarNamespace::CalendarMonthFocusRole, false);
   592 	mModel->itemFromIndex(index)->setData(list);
   781 	mModel->itemFromIndex(index)->setData(list);
   593 	
   782 	
   594 	// Search for this date in the model
   783 	// Search for this date in the model
   595 	for (int i = indexStart; i <= indexEnd; i++) {
   784 	for (int i = indexStart; i <= indexEnd; i++) {
   596 		if (monthDataList[i].Day().date() == dateToBeFocussed.date()) {
   785 		if (monthDataList[i].Day().date() == dateToBeFocussed.date()) {
   597 			index = mModel->index(i,0);
   786 			index = mModel->index(i,0);
   598 			itemData = index.data(Qt::UserRole + 1);
   787 			itemData = index.data(Qt::UserRole + 1);
   599 			list = itemData.toList();
   788 			list = itemData.toList();
   600 			list.replace(CalendarNamespace::CalendarMonthFocusRole,
   789 			list.replace(CalendarNamespace::CalendarMonthFocusRole,
   601 							 QString("qtg_fr_cal_focused_day_ind"));
   790 										 true);
   602 			mModel->itemFromIndex(index)->setData(list);
   791 			mModel->itemFromIndex(index)->setData(list);
   603 			mCurrentRow = i;
   792 			mCurrentRow = i;
   604 			mView->setContextForActiveDay(i);
   793 			mView->setContextForActiveDay(i);
   605 			break;
   794 			break;
   606 		}
   795 		}
   633 													activeDate.daysInMonth());
   822 													activeDate.daysInMonth());
   634 	// Number of days frm start of the grid to end of the month
   823 	// Number of days frm start of the grid to end of the month
   635 	end = firstDateInGrid.daysTo(endOfActiveMonth);
   824 	end = firstDateInGrid.daysTo(endOfActiveMonth);
   636 	
   825 	
   637 	// Set the active text color
   826 	// Set the active text color
   638 	QColor textColor = HbColorScheme::color("qtc_cal_month_active_dates");
   827 	for (int i = start; i < end; i++) {	
   639 	if (textColor.isValid()) {
   828 		QModelIndex index = mModel->index(i,0);
   640 		for (int i = start; i < end; i++) {	
   829 		QVariant itemData = index.data(Qt::UserRole + 1);
   641 			QModelIndex index = mModel->index(i,0);
   830 		QVariantList list = itemData.toList();
   642 			QVariant itemData = index.data(Qt::UserRole + 1);
   831 		list.replace(CalendarNamespace::CalendarMonthTextColorRole, true);
   643 			QVariantList list = itemData.toList();
   832 		mModel->itemFromIndex(index)->setData(list);
   644 			list.replace(CalendarNamespace::CalendarMonthTextColorRole, textColor);
       
   645 			mModel->itemFromIndex(index)->setData(list);
       
   646 		}
       
   647 	}
   833 	}
   648 	
   834 	
   649 	// Now set the inactive text color to those which were active before the swipe
   835 	// Now set the inactive text color to those which were active before the swipe
   650 	if (mDirection == invalid) {
   836 	if (mDirection == invalid) {
   651 		// no need to do anything as other dates will be in inactive dates color
   837 		// no need to do anything as other dates will be in inactive dates color
   681 		// Number of days frm start of the grid to end of the month
   867 		// Number of days frm start of the grid to end of the month
   682 		end = firstDateInGrid.daysTo(endOfActiveMonth);
   868 		end = firstDateInGrid.daysTo(endOfActiveMonth);
   683 	}
   869 	}
   684 	
   870 	
   685 	// Set the inactive text color
   871 	// Set the inactive text color
   686 	textColor = HbColorScheme::color("qtc_cal_month_notactive_dates");
   872 	for (int i = start; i < end; i++) {		
   687 	if (textColor.isValid()) {
   873 		QModelIndex index = mModel->index(i,0);
   688 		for (int i = start; i < end; i++) {		
   874 		QVariant itemData = index.data(Qt::UserRole + 1);
   689 			QModelIndex index = mModel->index(i,0);
   875 		QVariantList list = itemData.toList();
   690 			QVariant itemData = index.data(Qt::UserRole + 1);
   876 		list.replace(CalendarNamespace::CalendarMonthTextColorRole, false);
   691 			QVariantList list = itemData.toList();
   877 		mModel->itemFromIndex(index)->setData(list);
   692 			list.replace(CalendarNamespace::CalendarMonthTextColorRole, textColor);
       
   693 			mModel->itemFromIndex(index)->setData(list);
       
   694 		}
       
   695 	}
   878 	}
   696 }
   879 }
   697 
   880 
   698 /*!
   881 /*!
   699  To get current foucsed index of monthGrid
   882  To get current foucsed index of monthGrid
   728                           const QStyleOptionGraphicsItem* option,
   911                           const QStyleOptionGraphicsItem* option,
   729                           QWidget* widget)
   912                           QWidget* widget)
   730 {
   913 {
   731 	Q_UNUSED(option);
   914 	Q_UNUSED(option);
   732 	Q_UNUSED(widget);
   915 	Q_UNUSED(widget);
       
   916 	painter->setRenderHint(QPainter::NonCosmeticDefaultPen);
   733 	
   917 	
   734 	// Set the required attributes to the pen
   918 	// Set the required attributes to the pen
   735 	QPen pen;
   919 	QPen pen;
   736 	pen.setStyle(Qt::SolidLine);
   920 	pen.setStyle(Qt::SolidLine);
   737 	pen.setWidth(GRIDLINE_WIDTH);
   921 	pen.setWidth(GRIDLINE_WIDTH);
   744 	painter->setPen(pen);
   928 	painter->setPen(pen);
   745 	
   929 	
   746 	// Get the sizes of content widget
   930 	// Get the sizes of content widget
   747 	qreal contentHeight = mContentWidget->size().height();
   931 	qreal contentHeight = mContentWidget->size().height();
   748 	qreal contentWidth = mContentWidget->size().width();
   932 	qreal contentWidth = mContentWidget->size().width();
   749 	
   933 	qreal rowWidth = 0.0;
   750 	// Get the num of rows
   934 	int numOfRows = 0;
   751 	int numOfRows = mModel->rowCount() / KCalenDaysInWeek;
       
   752 	// Draw horizontal lines
       
   753 	qreal rowWidth = contentHeight / numOfRows;
       
   754 	
       
   755 	QPointF startPoint = mContentWidget->pos();
   935 	QPointF startPoint = mContentWidget->pos();
       
   936 	
       
   937 	// NOTE!!!: There is a filcker when we blindly draw equally spaced lines
       
   938 	// on complete content widget when scrolling is finished. This happens only
       
   939 	// when content widget size is changed due to the change in total number
       
   940 	// of rows when we append or prepend rows. Hence, to avoid this, we draw
       
   941 	// lines on complete content widget only when it is scrolling.
       
   942 	// That means, as soon as scrolling is finished, we will end up drawing 
       
   943 	// only 6 lines that are visible to the user.
       
   944 	if (mDirection == invalid) {
       
   945 		// Start point is left most point on the screen
       
   946 		startPoint = QPointF(0,0);
       
   947 		rowWidth = size().height() / KNumOfVisibleRows;
       
   948 		numOfRows = KNumOfVisibleRows;
       
   949 	} else {
       
   950 		// Get the num of rows
       
   951 		numOfRows = mModel->rowCount() / KCalenDaysInWeek;
       
   952 		// Draw horizontal lines
       
   953 		rowWidth = contentHeight / numOfRows;
       
   954 	}
       
   955 	
   756 	QPointF endPoint(startPoint.x() + contentWidth, 
   956 	QPointF endPoint(startPoint.x() + contentWidth, 
   757 	                 startPoint.y());
   957 	                 startPoint.y());
   758 	
   958 	
   759 	// Create the list of points for which lines have to be drawn
   959 	// Create the list of points for which lines have to be drawn
   760 	// List should have even number of points so that it draws all the lines
   960 	// List should have even number of points so that it draws all the lines