calendarui/views/src/calenmonthgrid.cpp
changeset 23 fd30d51f876b
parent 18 c198609911f9
child 26 a949c2543c15
child 45 b6db4fd4947b
equal deleted inserted replaced
18:c198609911f9 23:fd30d51f876b
    20 #include <hbmenu.h>
    20 #include <hbmenu.h>
    21 #include <hbaction.h>
    21 #include <hbaction.h>
    22 #include <hbmainwindow.h>
    22 #include <hbmainwindow.h>
    23 #include <hbgridview.h>
    23 #include <hbgridview.h>
    24 #include <hbabstractviewitem.h>
    24 #include <hbabstractviewitem.h>
       
    25 #include <hbstyleloader.h>
    25 #include <hbcolorscheme.h>
    26 #include <hbcolorscheme.h>
    26 
    27 
    27 // User includes
    28 // User includes
    28 #include "calenmonthgrid.h"
    29 #include "calenmonthgrid.h"
    29 #include "calengriditemprototype.h"
    30 #include "calengriditemprototype.h"
    32 #include "calendateutils.h"
    33 #include "calendateutils.h"
    33 #include "calencommon.h"
    34 #include "calencommon.h"
    34 
    35 
    35 // Constants
    36 // Constants
    36 #define SCROLL_SPEEED 1000 
    37 #define SCROLL_SPEEED 1000 
       
    38 #define GRIDLINE_WIDTH 0.075 //units
    37 
    39 
    38 /*!
    40 /*!
    39  \class CalenMonthGrid
    41  \class CalenMonthGrid
    40 
    42 
    41  Implements the month grid
    43  Implements the month grid
    51 	mIsPanGesture(false),
    53 	mIsPanGesture(false),
    52 	mIsAtomicScroll(true),
    54 	mIsAtomicScroll(true),
    53 	mView(NULL),
    55 	mView(NULL),
    54 	mCurrentRow(0),
    56 	mCurrentRow(0),
    55 	mIsNonActiveDayFocused(false),
    57 	mIsNonActiveDayFocused(false),
    56 	mIgnoreItemActivated(false)
    58 	mIgnoreItemActivated(false),
       
    59 	mGridBorderColor(Qt::gray)
    57 {
    60 {
    58 	setScrollDirections(Qt::Vertical);
    61 	setScrollDirections(Qt::Vertical);
    59 	setRowCount(KNumOfVisibleRows);
    62 	setRowCount(KNumOfVisibleRows);
    60 	setColumnCount(KCalenDaysInWeek);
    63 	setColumnCount(KCalenDaysInWeek);
    61 	setLongPressEnabled(false);
    64 	setLongPressEnabled(false);
    62 	setItemRecycling(false);
    65 	setItemRecycling(false);
    63 	setSelectionMode(HbGridView::NoSelection);
    66 	setSelectionMode(HbGridView::NoSelection);
    64 	setUniformItemSizes(true);
    67 	setUniformItemSizes(true);
    65 	setVerticalScrollBarPolicy(HbScrollArea::ScrollBarAlwaysOff);
    68 	setVerticalScrollBarPolicy(HbScrollArea::ScrollBarAlwaysOff);
    66 	setClampingStyle(HbScrollArea::StrictClamping );
    69 	setClampingStyle(HbScrollArea::StrictClamping );
    67 	CalenGridItemPrototype *gridItemPrototype = new CalenGridItemPrototype(this);
    70 	
    68 	setItemPrototype(gridItemPrototype);
    71 	// Get the content widget of the scroll area to draw the grid lines
       
    72 	mContentWidget = contentWidget();
       
    73 	
       
    74 	// Get the color of the grid lines
       
    75 	mGridLineColor = HbColorScheme::color("qtc_cal_grid_line");
       
    76 	
       
    77 	// Create the prototype
       
    78 	CalenGridItemPrototype* gridItemPrototype = new CalenGridItemPrototype(this);
       
    79 	// Create the model
    69 	mModel = new QStandardItemModel(14*KCalenDaysInWeek, 1, this);
    80 	mModel = new QStandardItemModel(14*KCalenDaysInWeek, 1, this);
    70 	setModel(mModel);
    81 	// Set the mode and the prototype
       
    82 	setModel(mModel,gridItemPrototype);
       
    83 	
       
    84 	// Register the widgetml and css files
       
    85 	HbStyleLoader::registerFilePath(":/");
       
    86 	
       
    87 	// Set the layout name
       
    88 	setLayoutName("calendarCustomGridItem");
       
    89 	
    71 	connect(this, SIGNAL(scrollingEnded()), this,
    90 	connect(this, SIGNAL(scrollingEnded()), this,
    72 			SLOT(scrollingFinished()));
    91 			SLOT(scrollingFinished()));
    73 	
    92 	
    74 	// Connect to item activated signal
    93 	// Connect to item activated signal
    75 	connect(this, SIGNAL(activated(const QModelIndex &)), this,
    94 	connect(this, SIGNAL(activated(const QModelIndex &)), this,
   107 	} else if (countDiff > 0) {
   126 	} else if (countDiff > 0) {
   108 		// Add the necessary number of rows
   127 		// Add the necessary number of rows
   109 		mModel->insertRows(rowCount,countDiff);
   128 		mModel->insertRows(rowCount,countDiff);
   110 	}
   129 	}
   111 	QDateTime currDate = mView->getCurrentDay();
   130 	QDateTime currDate = mView->getCurrentDay();
       
   131 	QDateTime currDateTime = CalenDateUtils::beginningOfDay(currDate);
   112 	QDateTime activeDay = mView->getActiveDay();
   132 	QDateTime activeDay = mView->getActiveDay();
       
   133 	QDateTime activeDateTime = CalenDateUtils::beginningOfDay(activeDay);
       
   134 	
   113 	QModelIndex currentIndex;
   135 	QModelIndex currentIndex;
       
   136 	
       
   137 	// Get the default text color to be set
       
   138 	QColor textColor = HbColorScheme::color("qtc_cal_month_notactive_dates");
       
   139 	HbExtendedLocale locale = HbExtendedLocale::system();
   114 	for (int i = 0; i < dataCount; i++) {
   140 	for (int i = 0; i < dataCount; i++) {
   115 		QDateTime dateTime = monthDataArray[i].Day();
   141 		QDateTime dateTime = monthDataArray[i].Day();
   116 		currentIndex = mModel->index(i, 0);
   142 		currentIndex = mModel->index(i, 0);
   117 		HbExtendedLocale locale = HbExtendedLocale::system();
       
   118 		// Get the localised string for the day
   143 		// Get the localised string for the day
   119 		QString date = locale.toString(dateTime.date().day());
   144 		QString date = locale.toString(dateTime.date().day());
   120 		mModel->itemFromIndex(currentIndex)->setData(date,
   145 		
   121 									 CalendarNamespace::CalendarMonthDayRole);
   146 		// Create the variant list to contain the date to depict a grid item
       
   147 		QVariantList itemData;
       
   148 		
       
   149 		// NOTE: Add the data in the order mentioned in the 
       
   150 		// CalendarNamespace::DataRole enum. Dont change the order.
       
   151 		itemData << date; 
   122 		
   152 		
   123 		// Check for active day
   153 		// Check for active day
   124 		if (CalenDateUtils::beginningOfDay(activeDay)
   154 		if (activeDateTime == CalenDateUtils::beginningOfDay(dateTime)) {
   125 		        == CalenDateUtils::beginningOfDay(dateTime)) {
       
   126 			mCurrentRow = currentIndex.row();
   155 			mCurrentRow = currentIndex.row();
   127 			// Set the focus icon
   156 			// Set the focus icon
   128 			mModel->itemFromIndex(currentIndex)->setData(
   157 			itemData << QString("qtg_fr_cal_focused_day_ind");
   129 									QString("qtg_fr_cal_focused_day_ind"),
       
   130 									CalendarNamespace::CalendarMonthFocusRole);
       
   131 		} else {
   158 		} else {
   132 			// reset the highlight
   159 			// reset the highlight
   133 			mModel->itemFromIndex(currentIndex)->setData(
   160 			itemData << QString("");
   134 								QString(""),
       
   135 								CalendarNamespace::CalendarMonthFocusRole);
       
   136 		}
   161 		}
   137 
   162 
   138 		// Check for current day
   163 		// Check for current day
   139 		if (CalenDateUtils::beginningOfDay(currDate)
   164 		if (currDateTime == CalenDateUtils::beginningOfDay(dateTime)) {
   140 		        == CalenDateUtils::beginningOfDay(dateTime)) {
       
   141 			// Set the underline icon
   165 			// Set the underline icon
   142 			mModel->itemFromIndex(currentIndex)->setData(true,
   166 			itemData << true;
   143 								CalendarNamespace::CalendarMonthUnderlineRole);
   167 		} else {			
   144 		} else {
   168 			itemData << false;
   145 			mModel->itemFromIndex(currentIndex)->setData(false,
   169 		}
   146 								CalendarNamespace::CalendarMonthUnderlineRole);
       
   147 		}
       
   148 
       
   149 		// Reset the event indicator attribute
       
   150 		mModel->itemFromIndex(currentIndex)->setData(QString(""),
       
   151 									 CalendarNamespace::CalendarMonthEventRole);
       
   152 
   170 
   153 		// Check for events
   171 		// Check for events
   154 		if (monthDataArray[i].HasEvents()) {
   172 		if (monthDataArray[i].HasEvents()) {
   155 			// Set the underline icon
   173 			// Set the underline icon
   156 			mModel->itemFromIndex(currentIndex)->setData(QString(
   174 			itemData << QString("qtg_graf_cal_event_ind");
   157 									"qtg_graf_cal_event_ind"),
   175 		} else {
   158 									CalendarNamespace::CalendarMonthEventRole);
   176 			itemData << QString("");
   159 		}
   177 		}
   160 		// Check if this item falls on seventh column
   178 		
   161 		if ((i % KCalenDaysInWeek) == 6) {
   179 		// Add default text color
   162 			// Set the seventh column role
   180 		itemData << textColor;
   163 			mModel->itemFromIndex(currentIndex)->setData(true,
   181 		mModel->itemFromIndex(currentIndex)->setData(itemData);
   164 								CalendarNamespace::CalendarMonthSeventhColumn);
       
   165 		}
       
   166 	}
   182 	}
   167 	mMonthDataArray = monthDataArray;
   183 	mMonthDataArray = monthDataArray;
   168 	
   184 	
   169 	// Get the active month
   185 	// Get the active month
   170 	QDateTime activeDate = mView->getActiveDay();
   186 	QDateTime activeDate = mView->getActiveDay();
   171 	// Set the text color properly
   187 	// Set the text color properly
   172 	setActiveDates(activeDate);
   188 	setActiveDates(activeDate.date());
   173 	
   189 	
   174 	// Reset the view and update it again
   190 	// NOTE: To make sure that we always display proper month,
   175 	reset();
   191 	// two calls have been  made to scrollTo(), one with top
   176 	update();
   192 	// visible item and other with bottom visible item
   177 	
   193     // Calculate the first visible item in the grid
   178 	// Calculate the last visible item in the grid
   194     QModelIndex firstVisibleIndex = mModel->index(indexToBeScrolled - 
   179 	QModelIndex index = mModel->index(indexToBeScrolled, 0);
   195                                         (KNumOfVisibleRows * KCalenDaysInWeek - 1), 0);
   180 	scrollTo(index);
   196     scrollTo(firstVisibleIndex);
       
   197     
       
   198     
       
   199     // Calculate the last visible item in the grid
       
   200     QModelIndex lastVisibleIndex = mModel->index(indexToBeScrolled, 0);
       
   201     scrollTo(lastVisibleIndex);
   181 }
   202 }
   182 
   203 
   183 /*!
   204 /*!
   184  Listens for down gesture
   205  Listens for down gesture
   185  */
   206  */
   186 void CalenMonthGrid::downGesture (int value)
   207 void CalenMonthGrid::downGesture (int value)
   187 {
   208 {
   188 	Q_UNUSED(value)	
   209 	Q_UNUSED(value)	
   189 	mDirection = down;
   210 	mDirection = down;
       
   211 	// Before we start scrolling, setthe active text color to previous month
       
   212 	QDateTime activeDate = mView->getActiveDay();
       
   213 	setActiveDates(activeDate.addMonths(-1).date());
   190 	HbScrollArea::downGesture(SCROLL_SPEEED);
   214 	HbScrollArea::downGesture(SCROLL_SPEEED);
   191 }
   215 }
   192 
   216 
   193 /*!
   217 /*!
   194  Listens for Up gesture
   218  Listens for Up gesture
   195  */
   219  */
   196 void CalenMonthGrid::upGesture (int value)
   220 void CalenMonthGrid::upGesture (int value)
   197 {
   221 {
   198 	Q_UNUSED(value)	
   222 	Q_UNUSED(value)	
   199 	mDirection = up;
   223 	mDirection = up;
       
   224 	// Before we start scrolling, setthe active text color to future month
       
   225 	QDateTime activeDate = mView->getActiveDay();
       
   226 	setActiveDates(activeDate.addMonths(1).date());
   200 	HbScrollArea::upGesture(SCROLL_SPEEED);
   227 	HbScrollArea::upGesture(SCROLL_SPEEED);
   201 }
   228 }
   202 
   229 
   203 /*!
   230 /*!
   204  Function to listen mouse press events
   231  Function to listen mouse press events
   270 			// Make a request for upgesture
   297 			// Make a request for upgesture
   271 			downGesture(SCROLL_SPEEED);
   298 			downGesture(SCROLL_SPEEED);
   272 			return; // return immediately
   299 			return; // return immediately
   273 		}
   300 		}
   274 	} else if(!mIsAtomicScroll) {
   301 	} else if(!mIsAtomicScroll) {
   275 		if (mDirection == down) {
       
   276 			// Before we start scrolling, setthe active text color to previous month
       
   277 			QDateTime activeDate = mView->getActiveDay();
       
   278 			if (!mIsNonActiveDayFocused) {
       
   279 				activeDate = activeDate.addMonths(-1);
       
   280 			}
       
   281 			setActiveDates(activeDate);
       
   282 		} else if (mDirection == up) {
       
   283 			// Before we start scrolling, setthe active text color to previous month
       
   284 			QDateTime activeDate = mView->getActiveDay();
       
   285 			if (!mIsNonActiveDayFocused) {
       
   286 				activeDate = activeDate.addMonths(1);
       
   287 			}
       
   288 			setActiveDates(activeDate);
       
   289 		}
       
   290 		// Before we do anything, set the focus to proper date
   302 		// Before we do anything, set the focus to proper date
   291 		// Set it only when non active day was focussed. When inactive day
   303 		// Set it only when non active day was focussed. When inactive day
   292 		// was focussed, we need to focus the same day
   304 		// was focussed, we need to focus the same day
   293 		if (!mIsNonActiveDayFocused) {
   305 		if (!mIsNonActiveDayFocused) {
   294 			setFocusToProperDay();
   306 			setFocusToProperDay();
   318  */
   330  */
   319 void CalenMonthGrid::prependRows()
   331 void CalenMonthGrid::prependRows()
   320 {
   332 {
   321 	mIsNonActiveDayFocused = false;
   333 	mIsNonActiveDayFocused = false;
   322 	QDateTime currDate = mView->getCurrentDay();
   334 	QDateTime currDate = mView->getCurrentDay();
       
   335 	QDateTime currDateTime = CalenDateUtils::beginningOfDay( currDate );
   323 	int rowsInFutMonthEarlier = mView->rowsInFutMonth();
   336 	int rowsInFutMonthEarlier = mView->rowsInFutMonth();
   324 	int rowsInPrevMonthEarlier = mView->rowsInPrevMonth();
   337 	int rowsInPrevMonthEarlier = mView->rowsInPrevMonth();
   325 	
   338 	
   326 	// Get the updated dates from the view
   339 	// Get the updated dates from the view
   327 	mView->updateModelWithPrevMonth();
   340 	mView->updateModelWithPrevMonth();
   339 	
   352 	
   340 	count = mModel->rowCount();
   353 	count = mModel->rowCount();
   341 	
   354 	
   342 	// Add the new days
   355 	// Add the new days
   343 	int countToBeAdded = rowsInPrevMonth * KCalenDaysInWeek;
   356 	int countToBeAdded = rowsInPrevMonth * KCalenDaysInWeek;
       
   357 	
   344 	mModel->insertRows(0, countToBeAdded);
   358 	mModel->insertRows(0, countToBeAdded);
   345 	count = mModel->rowCount();
   359 	count = mModel->rowCount();
       
   360 	
       
   361 	// Get the default text color to be set
       
   362 	QColor textColor = HbColorScheme::color("qtc_cal_month_notactive_dates");
       
   363 	HbExtendedLocale locale = HbExtendedLocale::system();
       
   364 	
   346 	for (int i = 0; i < countToBeAdded; i++) {
   365 	for (int i = 0; i < countToBeAdded; i++) {
   347 		QDateTime dateTime = monthDataList[i].Day();
   366 		QDateTime dateTime = monthDataList[i].Day();
   348 		int date = dateTime.date().day();
   367 		
       
   368 		// Get the localised string for the day
       
   369 		QString date = locale.toString(dateTime.date().day());
   349 		QModelIndex currentIndex = mModel->index(i, 0);
   370 		QModelIndex currentIndex = mModel->index(i, 0);
   350 		mModel->itemFromIndex(currentIndex)->setData(date,
   371 		
   351 									 CalendarNamespace::CalendarMonthDayRole);
   372 		// Create the variant list to contain the date to depict a grid item
   352 		// Check for current date
   373 		QVariantList itemData;
   353 		if (CalenDateUtils::beginningOfDay( currDate ) == 
   374 		
   354 				CalenDateUtils::beginningOfDay( dateTime )) {
   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 )) {
   355 			// Set the underline icon
   384 			// Set the underline icon
   356 			mModel->setData(mModel->index(i, 0), true,
   385 			itemData << true;
   357 							CalendarNamespace::CalendarMonthUnderlineRole);
   386 		} else {
   358 		}
   387 			itemData << false;
       
   388 		}
       
   389 		
       
   390 		// Update the event indicators
   359 		if (monthDataList[i].HasEvents()) {
   391 		if (monthDataList[i].HasEvents()) {
   360 			// Set the underline icon
   392 			// Set the event indicator icon
   361 			mModel->setData(mModel->index(i, 0), 
   393 			itemData << QString("qtg_graf_cal_event_ind");
   362 						QString("qtg_graf_cal_event_ind"),
   394 		} else {
   363 						CalendarNamespace::CalendarMonthEventRole);
   395 			itemData << QString("");
   364 		}
   396 		}
   365 		
   397 		
   366 		// Check if this item falls on seventh column
   398 		// Add default text color
   367 		if ((i%KCalenDaysInWeek) == 6) {
   399 		
   368 			// Set the seventh column role
   400 		itemData << textColor;
   369 			mModel->setData(mModel->index(i, 0), true,
   401 		
   370 							CalendarNamespace::CalendarMonthSeventhColumn);
   402 		// Set the data to model
   371 		}
   403 		mModel->itemFromIndex(currentIndex)->setData(itemData);
   372 	}
   404 	}
   373 	
   405 	
   374 	// Update the mCurrentRow
   406 	// Update the mCurrentRow
   375 	mCurrentRow += countToBeAdded;
   407 	mCurrentRow += countToBeAdded;
   376 	// Scroll to proper index
   408 	// Scroll to proper index
   398  */
   430  */
   399 void CalenMonthGrid::appendRows()
   431 void CalenMonthGrid::appendRows()
   400 {
   432 {
   401 	mIsNonActiveDayFocused = false;
   433 	mIsNonActiveDayFocused = false;
   402 	QDateTime currDate = mView->getCurrentDay();
   434 	QDateTime currDate = mView->getCurrentDay();
       
   435 	QDateTime currDateTime = CalenDateUtils::beginningOfDay( currDate );
   403 	int rowsInFutMonth = mView->rowsInFutMonth();
   436 	int rowsInFutMonth = mView->rowsInFutMonth();
   404 	int rowsInPrevMonth = mView->rowsInPrevMonth();
   437 	int rowsInPrevMonth = mView->rowsInPrevMonth();
   405 	// remove the cells in the previous month
   438 	// remove the cells in the previous month
   406 	int countToBeDeleted = rowsInPrevMonth * KCalenDaysInWeek;
   439 	int countToBeDeleted = rowsInPrevMonth * KCalenDaysInWeek;
   407 		
   440 		
   412 	// Get the updated rows to be inserted
   445 	// Get the updated rows to be inserted
   413 	rowsInPrevMonth = mView->rowsInPrevMonth();
   446 	rowsInPrevMonth = mView->rowsInPrevMonth();
   414 	rowsInFutMonth = mView->rowsInFutMonth();
   447 	rowsInFutMonth = mView->rowsInFutMonth();
   415 	int countToBeAdded = rowsInFutMonth * KCalenDaysInWeek;
   448 	int countToBeAdded = rowsInFutMonth * KCalenDaysInWeek;
   416 	int lastVisibleIndex = monthDataList.count() - countToBeAdded;
   449 	int lastVisibleIndex = monthDataList.count() - countToBeAdded;
       
   450 	
   417 	int rowCount = mModel->rowCount();
   451 	int rowCount = mModel->rowCount();
   418 	mModel->insertRows(rowCount, countToBeAdded);
   452 	mModel->insertRows(rowCount, countToBeAdded);
       
   453 	
       
   454 	// Get the default text color to be set
       
   455 	QColor textColor = HbColorScheme::color("qtc_cal_month_notactive_dates");
   419 	for (int i = 0; i < countToBeAdded; i++) {
   456 	for (int i = 0; i < countToBeAdded; i++) {
   420 		QMap<int, QVariant> data;
   457 		QMap<int, QVariant> data;
   421 		QModelIndex currentIndex = mModel->index(i, 0);
   458 		QModelIndex currentIndex = mModel->index(rowCount + i, 0);
   422 				
   459 				
   423 		QDateTime dateTime = monthDataList[lastVisibleIndex + i].Day();
   460 		QDateTime dateTime = monthDataList[lastVisibleIndex + i].Day();
   424 		int date = dateTime.date().day();
   461 		HbExtendedLocale locale = HbExtendedLocale::system();
       
   462 		// Get the localised string for the day
       
   463 		QString date = locale.toString(dateTime.date().day());
   425 		data.insert(CalendarNamespace::CalendarMonthDayRole, date);
   464 		data.insert(CalendarNamespace::CalendarMonthDayRole, date);
   426 		mModel->setItemData(mModel->index(rowCount + i, 0), data);
   465 		
   427 		// Check for active day
   466 		// Create the variant list to contain the date to depict a grid item
   428 		if  (CalenDateUtils::beginningOfDay( currDate ) == 
   467 		QVariantList itemData;
   429 				CalenDateUtils::beginningOfDay( dateTime )) {
   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 )) {
   430 			// Set the underline icon
   478 			// Set the underline icon
   431 			mModel->setData(mModel->index(rowCount + i, 0),true,
   479 			itemData << true;
   432 							CalendarNamespace::CalendarMonthUnderlineRole);
   480 		} else {
       
   481 			itemData << false;
   433 		}
   482 		}
   434 		
   483 		
   435 		// Update the event indicators
   484 		// Update the event indicators
   436 		if (monthDataList[lastVisibleIndex + i].HasEvents()) {
   485 		if (monthDataList[lastVisibleIndex + i].HasEvents()) {
   437 			// Set the underline icon
   486 			// Set the underline icon
   438 			mModel->setData(mModel->index(rowCount + i, 0), 
   487 			itemData << QString("qtg_graf_cal_event_ind");
   439 						QString("qtg_graf_cal_event_ind"),
   488 		} else {
   440 						CalendarNamespace::CalendarMonthEventRole);
   489 			itemData << QString("");
   441 		}
   490 		}
   442 		
   491 		
   443 		if ((i%KCalenDaysInWeek) == 6) {
   492 		// Add default text color
   444 			// Set the seventh column role
   493 		itemData << textColor;
   445 			mModel->setData(mModel->index(rowCount + i, 0), true,
   494 				
   446 							CalendarNamespace::CalendarMonthSeventhColumn);
   495 		// Set the data to model
   447 		}
   496 		mModel->itemFromIndex(currentIndex)->setData(itemData);
   448 	}
   497 	}
   449 	
   498 	
   450 	// Update the mCurrentRow
   499 	// Update the mCurrentRow
   451 	mCurrentRow -= (countToBeDeleted);
   500 	mCurrentRow -= (countToBeDeleted);
   452 	
       
   453 	mIsAtomicScroll = true;
       
   454 	for (int i = 0; i < countToBeDeleted; i++) {
   501 	for (int i = 0; i < countToBeDeleted; i++) {
   455 		mModel->removeRow(0);
   502 		mModel->removeRow(0);
   456 	}
   503 	}
       
   504 	mIsAtomicScroll = true;
       
   505 	
   457 	// Calculate the proper index to be scrolled to
   506 	// Calculate the proper index to be scrolled to
   458 	int itemToBeScrolled = rowsInPrevMonth * KCalenDaysInWeek;
   507 	int itemToBeScrolled = rowsInPrevMonth * KCalenDaysInWeek;
   459 	QModelIndex indexToBeScrolled = mModel->index(itemToBeScrolled, 0);
   508 	QModelIndex indexToBeScrolled = mModel->index(itemToBeScrolled, 0);
   460 	scrollTo(indexToBeScrolled);
   509 	scrollTo(indexToBeScrolled);
   461 }
   510 }
   473 	// Check if the same item has been tapped twice
   522 	// Check if the same item has been tapped twice
   474 	if (mCurrentRow == index.row()) {
   523 	if (mCurrentRow == index.row()) {
   475 		// Launch the agenda view
   524 		// Launch the agenda view
   476 		mView->launchDayView();
   525 		mView->launchDayView();
   477 	} else {
   526 	} else {
   478 		// Reset the focus attribute to this item
   527 		// Reset the focus attribute to this item		
   479 		mModel->setData(mModel->index(mCurrentRow,0), QString(""),
   528 		QModelIndex itemIndex = mModel->index(mCurrentRow,0);
   480 									CalendarNamespace::CalendarMonthFocusRole);
   529 		QVariant itemData = itemIndex.data(Qt::UserRole + 1);
       
   530 		QVariantList list = itemData.toList();
       
   531 		list.replace(CalendarNamespace::CalendarMonthFocusRole, QString(""));
       
   532 		mModel->itemFromIndex(itemIndex)->setData(list);
   481 		
   533 		
   482 		// Inform view to update the context and preview panes
   534 		// Inform view to update the context and preview panes
   483 		mCurrentRow = index.row();
   535 		mCurrentRow = index.row();
   484 		mModel->setData(mModel->index(mCurrentRow,0), 
   536 		itemIndex = mModel->index(mCurrentRow,0);
   485 									QString("qtg_fr_cal_focused_day_ind"),
   537 		itemData = itemIndex.data(Qt::UserRole + 1);
   486 									CalendarNamespace::CalendarMonthFocusRole);
   538 		list = itemData.toList();
       
   539 		list.replace(CalendarNamespace::CalendarMonthFocusRole, 
       
   540 						 QString("qtg_fr_cal_focused_day_ind"));
       
   541 		mModel->itemFromIndex(itemIndex)->setData(list);
   487 		// Check if inactive date is tapped
   542 		// Check if inactive date is tapped
   488 		QList<CalenMonthData> list = mView->monthDataList();
   543 		QDateTime activeMonth = mView->getActiveDay();
   489 		if(!list[mCurrentRow].isActive()){
   544 		int month = activeMonth.date().month();
       
   545 		if(month != mMonthDataArray[mCurrentRow].Day().date().month()){
   490 			// Set the flag
   546 			// Set the flag
   491 			mIsNonActiveDayFocused = true;
   547 			mIsNonActiveDayFocused = true;
   492 			mNonActiveFocusedDay = list[mCurrentRow].Day();
   548 			mNonActiveFocusedDay = mMonthDataArray[mCurrentRow].Day();
   493 			
   549 			
   494 			// Get the current active month
   550 			// Get the current active month
   495 			QDateTime activeMonth = mView->getActiveDay();
   551 			QDateTime activeMonth = mView->getActiveDay();
   496 			// Add one month to it
   552 			// Add one month to it
   497 			activeMonth = activeMonth.addMonths(1);
   553 			activeMonth = activeMonth.addMonths(1);
   527 	} else if (mDirection == down) {
   583 	} else if (mDirection == down) {
   528 		dateToBeFocussed = oldFocussedDate.addMonths(-1); // substract the month
   584 		dateToBeFocussed = oldFocussedDate.addMonths(-1); // substract the month
   529 		indexEnd = (rowsInPrevMonth + 1) * KCalenDaysInWeek;
   585 		indexEnd = (rowsInPrevMonth + 1) * KCalenDaysInWeek;
   530 	}
   586 	}
   531 	// Reset the focus attribute to earlier current item
   587 	// Reset the focus attribute to earlier current item
   532 	mModel->setData(mModel->index(mCurrentRow,0), QString(""),
   588 	QModelIndex index = mModel->index(mCurrentRow,0);
   533 								CalendarNamespace::CalendarMonthFocusRole);
   589 	QVariant itemData = index.data(Qt::UserRole + 1);
       
   590 	QVariantList list = itemData.toList();
       
   591 	list.replace(CalendarNamespace::CalendarMonthFocusRole, QString(""));
       
   592 	mModel->itemFromIndex(index)->setData(list);
       
   593 	
   534 	// Search for this date in the model
   594 	// Search for this date in the model
   535 	for (int i = indexStart; i <= indexEnd; i++) {
   595 	for (int i = indexStart; i <= indexEnd; i++) {
   536 		if (monthDataList[i].Day().date() == dateToBeFocussed.date()) {
   596 		if (monthDataList[i].Day().date() == dateToBeFocussed.date()) {
   537 			mModel->setData(mModel->index(i,0), 
   597 			index = mModel->index(i,0);
   538 								QString("qtg_fr_cal_focused_day_ind"),
   598 			itemData = index.data(Qt::UserRole + 1);
   539 								CalendarNamespace::CalendarMonthFocusRole);
   599 			list = itemData.toList();
       
   600 			list.replace(CalendarNamespace::CalendarMonthFocusRole,
       
   601 							 QString("qtg_fr_cal_focused_day_ind"));
       
   602 			mModel->itemFromIndex(index)->setData(list);
   540 			mCurrentRow = i;
   603 			mCurrentRow = i;
   541 			mView->setContextForActiveDay(i);
   604 			mView->setContextForActiveDay(i);
   542 			break;
   605 			break;
   543 		}
   606 		}
   544 	}
   607 	}
   545 }
   608 }
   546 
   609 
   547 /*!
   610 /*!
   548  Sets the appropriate text colot depending upon the active dates
   611  Sets the appropriate text color depending upon the active dates
   549  */
   612  */
   550 void CalenMonthGrid::setActiveDates(QDateTime activeDate)
   613 void CalenMonthGrid::setActiveDates(QDate activeDate)
   551 {
   614 {
   552 	int month = activeDate.date().month();
   615 	// By default, text color will be set as inactive date color
   553 	for (int i = 0; i < mMonthDataArray.count(); i++) {
   616 	// set active date color only for the dates that fall in current month
   554 	    QColor textColor;
   617 	// So, in the whole data array, start from where the current month starts
   555 	    if (month == mMonthDataArray[i].Day().date().month()) {
   618 	// and stop the loop where it the current month ends
   556 			// Set the active text color
   619 	
   557 			textColor = HbColorScheme::color("qtc_cal_month_active_dates");
   620 	int start = 0;
   558 		} else {
   621 	int end = mMonthDataArray.count();
   559 			// Set the inactive text color
   622 	
   560 			textColor = HbColorScheme::color("qtc_cal_month_notactive_dates");
   623 	// Calculate the start and end values
   561 		}
   624 	QDate firstDateInGrid = mView->firstDayOfGrid().date();
   562 		if (textColor.isValid()) {
   625 	
   563 		    mModel->setData(mModel->index(i,0), textColor,
   626 	// Get the date where active month starts
   564 		                    CalendarNamespace::CalendarMonthTextColorRole);
   627 	QDate startOfActiveMonth(activeDate.year(), activeDate.month(),1);
       
   628 	// Number of days frm start of the grid to start of the month
       
   629 	start = firstDateInGrid.daysTo(startOfActiveMonth);
       
   630 	
       
   631 	// Get the date where active month ends
       
   632 	QDate endOfActiveMonth = startOfActiveMonth.addDays(
       
   633 													activeDate.daysInMonth());
       
   634 	// Number of days frm start of the grid to end of the month
       
   635 	end = firstDateInGrid.daysTo(endOfActiveMonth);
       
   636 	
       
   637 	// Set the active text color
       
   638 	QColor textColor = HbColorScheme::color("qtc_cal_month_active_dates");
       
   639 	if (textColor.isValid()) {
       
   640 		for (int i = start; i < end; i++) {	
       
   641 			QModelIndex index = mModel->index(i,0);
       
   642 			QVariant itemData = index.data(Qt::UserRole + 1);
       
   643 			QVariantList list = itemData.toList();
       
   644 			list.replace(CalendarNamespace::CalendarMonthTextColorRole, textColor);
       
   645 			mModel->itemFromIndex(index)->setData(list);
       
   646 		}
       
   647 	}
       
   648 	
       
   649 	// Now set the inactive text color to those which were active before the swipe
       
   650 	if (mDirection == invalid) {
       
   651 		// no need to do anything as other dates will be in inactive dates color
       
   652 		return;
       
   653 	}
       
   654 	
       
   655 	if (mDirection == up) {
       
   656 		// Came here as user did up gesture
       
   657 		// Get the activeDate that was set before the swipe
       
   658 		activeDate = activeDate.addMonths(-1);
       
   659 		
       
   660 		// Get the date where active month starts
       
   661 		startOfActiveMonth = QDate(activeDate.year(), activeDate.month(),1);
       
   662 		// Number of days frm start of the grid to start of the month
       
   663 		start = firstDateInGrid.daysTo(startOfActiveMonth);
       
   664 		
       
   665 		// Get the date where active month ends
       
   666 		QDate endOfActiveMonth = startOfActiveMonth.addDays(activeDate.daysInMonth());
       
   667 		// Number of days frm start of the grid to end of the month
       
   668 		end = firstDateInGrid.daysTo(endOfActiveMonth);
       
   669 	} else if (mDirection == down) {
       
   670 		// Came here as user did down gesture
       
   671 		// Get the activeDate that was set before the swipe
       
   672 		activeDate = activeDate.addMonths(1);
       
   673 		
       
   674 		// Get the activeDate that was set before the swipe
       
   675 		startOfActiveMonth = QDate(activeDate.year(), activeDate.month(),1); 
       
   676 		// Number of days frm start of the grid to start of the month
       
   677 		start = firstDateInGrid.daysTo(startOfActiveMonth);
       
   678 		
       
   679 		// Get the date where active month ends
       
   680 		QDate endOfActiveMonth = startOfActiveMonth.addDays(activeDate.daysInMonth());
       
   681 		// Number of days frm start of the grid to end of the month
       
   682 		end = firstDateInGrid.daysTo(endOfActiveMonth);
       
   683 	}
       
   684 	
       
   685 	// Set the inactive text color
       
   686 	textColor = HbColorScheme::color("qtc_cal_month_notactive_dates");
       
   687 	if (textColor.isValid()) {
       
   688 		for (int i = start; i < end; i++) {		
       
   689 			QModelIndex index = mModel->index(i,0);
       
   690 			QVariant itemData = index.data(Qt::UserRole + 1);
       
   691 			QVariantList list = itemData.toList();
       
   692 			list.replace(CalendarNamespace::CalendarMonthTextColorRole, textColor);
       
   693 			mModel->itemFromIndex(index)->setData(list);
   565 		}
   694 		}
   566 	}
   695 	}
   567 }
   696 }
   568 
   697 
   569 /*!
   698 /*!
   589 {
   718 {
   590     Q_UNUSED(newOrientation)
   719     Q_UNUSED(newOrientation)
   591 	// We are overriding this function to avoid the default behavior of
   720 	// We are overriding this function to avoid the default behavior of
   592 	// hbgridview on orientation change as it swaps the row and column counts
   721 	// hbgridview on orientation change as it swaps the row and column counts
   593 }
   722 }
       
   723 
       
   724 /*!
       
   725  Paint function to draw grid lines
       
   726  */
       
   727 void CalenMonthGrid::paint(QPainter* painter,
       
   728                           const QStyleOptionGraphicsItem* option,
       
   729                           QWidget* widget)
       
   730 {
       
   731 	Q_UNUSED(option);
       
   732 	Q_UNUSED(widget);
       
   733 	
       
   734 	// Set the required attributes to the pen
       
   735 	QPen pen;
       
   736 	pen.setStyle(Qt::SolidLine);
       
   737 	pen.setWidth(GRIDLINE_WIDTH);
       
   738 	if (mGridLineColor.isValid()) {
       
   739 		pen.setBrush(mGridLineColor);
       
   740 	} else {
       
   741 		pen.setBrush(mGridBorderColor);
       
   742 	}
       
   743 	// Set the pen to the painter
       
   744 	painter->setPen(pen);
       
   745 	
       
   746 	// Get the sizes of content widget
       
   747 	qreal contentHeight = mContentWidget->size().height();
       
   748 	qreal contentWidth = mContentWidget->size().width();
       
   749 	
       
   750 	// Get the num of rows
       
   751 	int numOfRows = mModel->rowCount() / KCalenDaysInWeek;
       
   752 	// Draw horizontal lines
       
   753 	qreal rowWidth = contentHeight / numOfRows;
       
   754 	
       
   755 	QPointF startPoint = mContentWidget->pos();
       
   756 	QPointF endPoint(startPoint.x() + contentWidth, 
       
   757 	                 startPoint.y());
       
   758 	
       
   759 	// 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
       
   761 	// Painter draws the line for first two points in the list and then second 
       
   762 	// line for next two points in the list like that. Hence, list should 
       
   763 	// contain even number of points
       
   764 	QVector<QPointF> pointList;
       
   765 	for (int i = 0; i < numOfRows; i++) {
       
   766 		pointList.append(QPointF(startPoint.x(), 
       
   767 		                         startPoint.y() + (i * rowWidth)));
       
   768 		pointList.append(QPointF(endPoint.x(), endPoint.y() + (i * rowWidth)));
       
   769 	}
       
   770 	
       
   771 	// Draw vertical lines
       
   772 	qreal colWidth = contentWidth / KCalenDaysInWeek;
       
   773 	endPoint = QPointF(startPoint.x(), 
       
   774 	                   startPoint.y() + contentHeight);
       
   775 	for (int i = 1; i < KCalenDaysInWeek; i++) {
       
   776 		pointList.append(QPointF(startPoint.x() + (i * colWidth), 
       
   777 		                         startPoint.y()));
       
   778 		pointList.append(QPointF(endPoint.x() + (i * colWidth), endPoint.y()));
       
   779 	}
       
   780 	
       
   781 	// Draw the lines for the points in the vector list
       
   782 	painter->drawLines(pointList);
       
   783 }
       
   784 
   594 // End of File
   785 // End of File