calendarui/views/src/calenmonthview.cpp
changeset 55 2c54b51f39c4
parent 51 0b38fc5b94c6
child 57 bb2d3e476f29
equal deleted inserted replaced
51:0b38fc5b94c6 55:2c54b51f39c4
    54 #include "OstTraceDefinitions.h"
    54 #include "OstTraceDefinitions.h"
    55 #ifdef OST_TRACE_COMPILER_IN_USE
    55 #ifdef OST_TRACE_COMPILER_IN_USE
    56 #include "calenmonthviewTraces.h"
    56 #include "calenmonthviewTraces.h"
    57 #endif
    57 #endif
    58 
    58 
       
    59 // CONSTANTS
       
    60 #define WEEKNUMWIDTH 6.41604 // in units, need to update this value if it 
       
    61 								// is changed in the docml
    59 /*!
    62 /*!
    60  \class CalenMonthView
    63  \class CalenMonthView
    61 
    64 
    62  Class implementing calendar month view
    65  Class implementing calendar month view
    63  */
    66  */
   367 	// Get the day names layout
   370 	// Get the day names layout
   368 	QGraphicsLinearLayout *dayNamesLayout =
   371 	QGraphicsLinearLayout *dayNamesLayout =
   369 	        static_cast<QGraphicsLinearLayout *> (mDayNameWidget->layout());
   372 	        static_cast<QGraphicsLinearLayout *> (mDayNameWidget->layout());
   370 
   373 
   371 	if (KCalenDaysInWeek == dayNamesLayout->count()) {
   374 	if (KCalenDaysInWeek == dayNamesLayout->count()) {
   372 		// Add one item with text "Wk" in the day name grid
   375 		// Add one empty label in the day name grid
   373 		HbLabel *label = new HbLabel(mDayNameWidget);
   376 		HbLabel *label = new HbLabel(mDayNameWidget);
   374 
   377 
   375 		// Set the attributes same as that of other day names to make it
   378 		// Set the attributes same as that of other day names to make it
   376 		// look similar to the day names
   379 		// look similar to the day names
   377 		label->setPlainText(hbTrId("txt_calendar_grid_day_wk"));
   380 		label->setPlainText("");
   378 		label->setFont(mFirstDayLabel->font());
   381 		label->setFont(mFirstDayLabel->font());
   379 		label->setFontSpec(mFirstDayLabel->fontSpec());
   382 		label->setFontSpec(mFirstDayLabel->fontSpec());
   380 		label->setAlignment(mFirstDayLabel->alignment());
   383 		label->setAlignment(mFirstDayLabel->alignment());
   381 		label->setElideMode(mFirstDayLabel->elideMode());
   384 		label->setElideMode(mFirstDayLabel->elideMode());
   382 		label->setZValue(mFirstDayLabel->zValue());
   385 		label->setZValue(mFirstDayLabel->zValue());
   383 		label->setPreferredHeight(mFirstDayLabel->preferredHeight());
   386 		// Set the proper width to this empty label so that
   384 		label->setMinimumHeight(mFirstDayLabel->minimumHeight());
   387 		// day names are dislayed against the correct columns
   385 		label->setMaximumHeight(mFirstDayLabel->maximumHeight());
   388 		HbDeviceProfile deviceProf;
       
   389         qreal unitValue = deviceProf.unitValue();
       
   390         qreal widthInPixels = WEEKNUMWIDTH * unitValue;
       
   391         label->setPreferredWidth(widthInPixels);
       
   392         label->setMinimumWidth(widthInPixels);
       
   393         label->setMaximumWidth(widthInPixels);
       
   394         label->setContentsMargins(0,0,0,0);
   386 		
   395 		
   387 		// Add this label into layout
   396 		// Add this label into layout
   388 		dayNamesLayout->insertItem(0, label);
   397 		dayNamesLayout->insertItem(0, label);
   389 		dayNamesLayout->invalidate();
   398 		dayNamesLayout->invalidate();
   390 		dayNamesLayout->activate();
   399 		dayNamesLayout->activate();
   675  */
   684  */
   676 void CalenMonthView::addRemoveActionsInMenu()
   685 void CalenMonthView::addRemoveActionsInMenu()
   677 {
   686 {
   678     OstTraceFunctionEntry0( CALENMONTHVIEW_ADDREMOVEACTIONSINMENU_ENTRY );
   687     OstTraceFunctionEntry0( CALENMONTHVIEW_ADDREMOVEACTIONSINMENU_ENTRY );
   679 	HbAction* menuAction = mDeleteSubMenu->menuAction();
   688 	HbAction* menuAction = mDeleteSubMenu->menuAction();
   680 	// Check if there are no entries in the database
   689 	if (menuAction) {
   681 	if (mAgendaUtil->areNoEntriesInCalendar() && menuAction) {
   690         if (!mEntriesInDataBase && mAgendaUtil->areNoEntriesInCalendar()) {
   682 		// hide the delete entries option
   691             // hide the delete entries option
   683 		menuAction->setVisible(false);
   692             menuAction->setVisible(false);
   684 	} else if (menuAction) {
   693         } else {
   685 		// Show the option to delete
   694             mEntriesInDataBase = true;
   686 		menuAction->setVisible(true);
   695             // Show the option to delete
       
   696             menuAction->setVisible(true);
       
   697         }
   687 	}
   698 	}
   688 	
   699 	
   689 	// Check if we are population for current day, if yes then disable the
   700 	// Check if we are population for current day, if yes then disable the
   690 	// gototoday action
   701 	// gototoday action
   691 	if ((CalenDateUtils::today().date() == mDate.date()) && mGoToTodayAction) {
   702 	if ((CalenDateUtils::today().date() == mDate.date()) && mGoToTodayAction) {
   700  Populates the view
   711  Populates the view
   701  */
   712  */
   702 void CalenMonthView::doPopulation()
   713 void CalenMonthView::doPopulation()
   703 {
   714 {
   704     OstTraceFunctionEntry0( CALENMONTHVIEW_DOPOPULATION_ENTRY );
   715     OstTraceFunctionEntry0( CALENMONTHVIEW_DOPOPULATION_ENTRY );
   705 
   716     
   706  	// Get the layout and add the preview pane layout.
   717  	// Get the layout and add the preview pane layout.
   707 	QGraphicsLinearLayout* viewLayout = static_cast<QGraphicsLinearLayout *>
   718 	QGraphicsLinearLayout* viewLayout = static_cast<QGraphicsLinearLayout *>
   708 														(widget()->layout());
   719 														(widget()->layout());
   709 	if (viewLayout->count() == 1) {
   720 	if (viewLayout->count() == 1) {
   710 		// Count is 1 implies view has only month grid.
   721 		// Count is 1 implies view has only month grid.
   933 }
   944 }
   934 
   945 
   935 /*!
   946 /*!
   936  Returns the array of CalenMonthData items
   947  Returns the array of CalenMonthData items
   937  */
   948  */
   938 QList<CalenMonthData> CalenMonthView::monthDataList()
   949 QList<CalenMonthData>& CalenMonthView::monthDataList()
   939 {
   950 {
   940     OstTraceFunctionEntry0( CALENMONTHVIEW_MONTHDATALIST_ENTRY );
   951     OstTraceFunctionEntry0( CALENMONTHVIEW_MONTHDATALIST_ENTRY );
   941     
   952     
   942 	OstTraceFunctionExit0( CALENMONTHVIEW_MONTHDATALIST_EXIT );
   953 	OstTraceFunctionExit0( CALENMONTHVIEW_MONTHDATALIST_EXIT );
   943 	return mMonthDataArray;
   954 	return mMonthDataArray;
  1236 	int datesEventsCount = datesWithEvents.count();
  1247 	int datesEventsCount = datesWithEvents.count();
  1237 	for(int i(0); i < datesEventsCount; i++) {
  1248 	for(int i(0); i < datesEventsCount; i++) {
  1238 		int offset = mFirstDayOfGrid.date().daysTo(datesWithEvents.at(i));
  1249 		int offset = mFirstDayOfGrid.date().daysTo(datesWithEvents.at(i));
  1239 		mMonthDataArray[offset].SetHasEvents(true);
  1250 		mMonthDataArray[offset].SetHasEvents(true);
  1240 	}
  1251 	}
  1241 
       
  1242 	datesWithEvents.clear();
  1252 	datesWithEvents.clear();
       
  1253 	
       
  1254 	if (datesEventsCount) {
       
  1255         mEntriesInDataBase = true;
       
  1256 	}
  1243 	
  1257 	
  1244 	OstTraceFunctionExit0( CALENMONTHVIEW_POPULATEWITHINSTANCEVIEW_EXIT );
  1258 	OstTraceFunctionExit0( CALENMONTHVIEW_POPULATEWITHINSTANCEVIEW_EXIT );
  1245 }
  1259 }
  1246 
  1260 
  1247 /*!
  1261 /*!
  1270 		int offset = mFirstDayOfGrid.date().daysTo(datesWithEvents.at(i));
  1284 		int offset = mFirstDayOfGrid.date().daysTo(datesWithEvents.at(i));
  1271 		mMonthDataArray[offset].SetHasEvents(true);
  1285 		mMonthDataArray[offset].SetHasEvents(true);
  1272 	}
  1286 	}
  1273 	datesWithEvents.clear();
  1287 	datesWithEvents.clear();
  1274 	
  1288 	
       
  1289 	if (datesEventsCount) {
       
  1290         mEntriesInDataBase = true;
       
  1291     }
       
  1292 	
  1275 	OstTraceFunctionExit0( CALENMONTHVIEW_POPULATEPREVMONTH_EXIT );
  1293 	OstTraceFunctionExit0( CALENMONTHVIEW_POPULATEPREVMONTH_EXIT );
  1276 }
  1294 }
  1277 
  1295 
  1278 /*!
  1296 /*!
  1279  Parses the fetched entries for future month and 
  1297  Parses the fetched entries for future month and 
  1300 	for(int i(0); i < datesEventsCount; i++) {
  1318 	for(int i(0); i < datesEventsCount; i++) {
  1301 		int offset = mFirstDayOfGrid.date().daysTo(datesWithEvents.at(i));
  1319 		int offset = mFirstDayOfGrid.date().daysTo(datesWithEvents.at(i));
  1302 		mMonthDataArray[offset].SetHasEvents(true);
  1320 		mMonthDataArray[offset].SetHasEvents(true);
  1303 	}
  1321 	}
  1304 	datesWithEvents.clear();
  1322 	datesWithEvents.clear();
       
  1323 	
       
  1324 	if (datesEventsCount) {
       
  1325         mEntriesInDataBase = true;
       
  1326     }
  1305 	OstTraceFunctionExit0( CALENMONTHVIEW_POPULATENEXTMONTH_EXIT );
  1327 	OstTraceFunctionExit0( CALENMONTHVIEW_POPULATENEXTMONTH_EXIT );
  1306 }
  1328 }
  1307 
  1329 
  1308 /*!
  1330 /*!
  1309 	Function that gets called when instacne view is created, so that it can
  1331 	Function that gets called when instacne view is created, so that it can
  1476 void CalenMonthView::setDateToLabel()
  1498 void CalenMonthView::setDateToLabel()
  1477 {
  1499 {
  1478     OstTraceFunctionEntry0( CALENMONTHVIEW_SETDATETOLABEL_ENTRY );
  1500     OstTraceFunctionEntry0( CALENMONTHVIEW_SETDATETOLABEL_ENTRY );
  1479     
  1501     
  1480 	// Get the localised string for month name from system locale
  1502 	// Get the localised string for month name from system locale
  1481 	QString monthString = mLocale.monthName(mDate.date().month(), HbExtendedLocale::LongFormat);
  1503 	QString dateString = mLocale.monthName(mDate.date().month(), HbExtendedLocale::LongFormat);
  1482 	// Append a single space
  1504 	// Append a single space
  1483 	monthString.append(" ");
  1505 	dateString.append(" ");
  1484 	mLocale.setNumberOptions(QLocale::OmitGroupSeparator);
  1506 	mLocale.setNumberOptions(QLocale::OmitGroupSeparator);
  1485 	QString yearString = mLocale.toString(mDate.date().year());
  1507 	// Append the year string also
  1486 	mTitleLabel->setPlainText(hbTrId("txt_calendar_month_label_title_12").arg(monthString).arg(yearString));
  1508 	dateString.append(mLocale.toString(mDate.date().year()));
       
  1509 	mTitleLabel->setPlainText(dateString);
  1487 	
  1510 	
  1488 	OstTraceFunctionExit0( CALENMONTHVIEW_SETDATETOLABEL_EXIT );
  1511 	OstTraceFunctionExit0( CALENMONTHVIEW_SETDATETOLABEL_EXIT );
  1489 }
  1512 }
  1490 
  1513 
  1491 /*!
  1514 /*!
  1575  */
  1598  */
  1576 void CalenMonthView::onLocaleChanged(int reason)
  1599 void CalenMonthView::onLocaleChanged(int reason)
  1577 {
  1600 {
  1578     OstTraceFunctionEntry0( CALENMONTHVIEW_ONLOCALECHANGED_ENTRY );
  1601     OstTraceFunctionEntry0( CALENMONTHVIEW_ONLOCALECHANGED_ENTRY );
  1579     
  1602     
  1580 	Q_UNUSED(reason);
  1603     if ((reason & EChangesSystemTime) 
       
  1604     		|| (reason & EChangesMidnightCrossover)) {
       
  1605 		mCurrentDay = CalenDateUtils::today();
       
  1606 	}
  1581 	OstTraceFunctionExit0( CALENMONTHVIEW_ONLOCALECHANGED_EXIT );
  1607 	OstTraceFunctionExit0( CALENMONTHVIEW_ONLOCALECHANGED_EXIT );
  1582 }
  1608 }
  1583 
  1609 
  1584 /*!
  1610 /*!
  1585  Slot to handle left gesture effects completion
  1611  Slot to handle left gesture effects completion