calendarui/caleneditor/src/caleneditorcustomitem.cpp
changeset 45 b6db4fd4947b
parent 23 fd30d51f876b
child 51 0b38fc5b94c6
equal deleted inserted replaced
23:fd30d51f876b 45:b6db4fd4947b
    53 /*!
    53 /*!
    54 	Constructor.
    54 	Constructor.
    55 	\param parent The parent object.
    55 	\param parent The parent object.
    56  */
    56  */
    57 CalenEditorCustomItem::CalenEditorCustomItem(QGraphicsItem *parent)
    57 CalenEditorCustomItem::CalenEditorCustomItem(QGraphicsItem *parent)
    58 :HbDataFormViewItem(parent)
    58 :HbDataFormViewItem(parent),
       
    59  mPushButtonTime(NULL),
       
    60  mPushButtonDate(NULL),
       
    61  mRepeatUntilWidget(NULL),
       
    62  mReminderTimeWidget(NULL),
       
    63  mDatePicker(NULL),
       
    64  mTimePicker(NULL)
    59 {
    65 {
    60 	mMinDate = CalenDateUtils::minTime().date();
    66 	mMinDate = CalenDateUtils::minTime().date();
    61 	mMaxDate = CalenDateUtils::maxTime().date();
    67 	mMaxDate = CalenDateUtils::maxTime().date();
    62 	mMinTime.setHMS(0,0,0,0);
    68 	mMinTime.setHMS(0,0,0,0);
    63 	mMaxTime.setHMS(23,59,59,999);
    69 	mMaxTime.setHMS(23,59,59,999);
   111 
   117 
   112 
   118 
   113 		case CustomWidgetTo:
   119 		case CustomWidgetTo:
   114 		{
   120 		{
   115 		HbWidget *widgetBottom = new HbWidget();
   121 		HbWidget *widgetBottom = new HbWidget();
   116 		QGraphicsLinearLayout *layoutBottom = new QGraphicsLinearLayout(Qt::Horizontal);
   122 		QGraphicsLinearLayout *layoutBottom = 
       
   123 									new QGraphicsLinearLayout(Qt::Horizontal);
   117 		widgetBottom->setLayout(layoutBottom);
   124 		widgetBottom->setLayout(layoutBottom);
   118 
   125 
   119 		mPushButtonTime = new HbPushButton(this);
   126 		mPushButtonTime = new HbPushButton(this);
   120 		connect(mPushButtonTime, SIGNAL(clicked()),
   127 		connect(mPushButtonTime, SIGNAL(clicked()),
   121 											this, SLOT(handleTime()));
   128 											this, SLOT(handleTime()));
   131 		case CustomWidgetLocation:
   138 		case CustomWidgetLocation:
   132 		{
   139 		{
   133 			CalenEditorDocLoader editorLocationDocLoader;
   140 			CalenEditorDocLoader editorLocationDocLoader;
   134 			bool loadSuccess = false;
   141 			bool loadSuccess = false;
   135 
   142 
   136 			editorLocationDocLoader.load(CALEN_EDITOR_LOCATION_XML_FILE, &loadSuccess);
   143 			editorLocationDocLoader.load(CALEN_EDITOR_LOCATION_XML_FILE, 
       
   144 														&loadSuccess);
   137 			Q_ASSERT_X(loadSuccess, "caleneditor.cpp", 
   145 			Q_ASSERT_X(loadSuccess, "caleneditor.cpp", 
   138 		                                    "Unable to load caleneditor location view XML");
   146 								"Unable to load caleneditor location view XML");
   139 			HbWidget* widgetLocation = qobject_cast<HbWidget *> (editorLocationDocLoader.findWidget(CALEN_EDITOR_LOCATION));
   147 			HbWidget* widgetLocation = qobject_cast<HbWidget *> (
   140 		    
   148 					editorLocationDocLoader.findWidget(CALEN_EDITOR_LOCATION));
   141 			mLocationLineEdit = qobject_cast<HbLineEdit *>( editorLocationDocLoader.findWidget(CALEN_EDITOR_LOCATION_LINEEDIT));
   149 
       
   150 			mLocationLineEdit = qobject_cast<HbLineEdit *>( 
       
   151 									editorLocationDocLoader.findWidget(
       
   152 											CALEN_EDITOR_LOCATION_LINEEDIT));
   142 			mLocationLineEdit->setMinRows(1);
   153 			mLocationLineEdit->setMinRows(1);
   143 			mLocationLineEdit->setMaxRows(4);
   154 			mLocationLineEdit->setMaxRows(4);
   144 			mLocationPushButton = qobject_cast<HbPushButton*>(editorLocationDocLoader.findWidget(CALEN_EDITOR_LOCATION_PUSHBUTTON));
   155 			mLocationPushButton = qobject_cast<HbPushButton*>(
       
   156 									editorLocationDocLoader.findWidget(
       
   157 											CALEN_EDITOR_LOCATION_PUSHBUTTON));
   145 			mLocationPushButton->setIcon( HbIcon("qtg_mono_location"));
   158 			mLocationPushButton->setIcon( HbIcon("qtg_mono_location"));
   146 			
   159 			
   147 			connect(mLocationPushButton, SIGNAL(clicked()), this, SLOT(launchLocationPicker()));
   160 			connect(mLocationPushButton, SIGNAL(clicked()), this, 
       
   161 												SLOT(launchLocationPicker()));
   148 			connect(mLocationLineEdit, SIGNAL(textChanged(const QString)),
   162 			connect(mLocationLineEdit, SIGNAL(textChanged(const QString)),
   149 		                this, SLOT(handleLocationTextChange(const QString)));
   163 						this, SLOT(handleLocationTextChange(const QString)));
       
   164 						
       
   165 			connect(mLocationLineEdit, SIGNAL(editingFinished()),
       
   166 			            this, SLOT(handleEditingFinished()));
       
   167 			
   150 			return widgetLocation;
   168 			return widgetLocation;
   151 		}
   169 		}
   152 		
   170 		
   153 		case RepeatUntilOffset:
   171 		case RepeatUntilOffset:
   154 		{
   172 		{
   155 		mRepeatUntilWidget = new HbPushButton(this);
   173 		mRepeatUntilWidget = new HbPushButton(this);
   156 		return mRepeatUntilWidget;
   174 		return mRepeatUntilWidget;
   157 		}
   175 		}
   158 				
   176 				
   159 
   177 		case ReminderTimeOffset:
       
   178 		{
       
   179 			mReminderTimeWidget = new HbPushButton(this);
       
   180 			return mReminderTimeWidget;
       
   181 		}
       
   182 		
   160 		default:
   183 		default:
   161 			return 0;
   184 			return 0;
   162 	}
   185 	}
   163 }
   186 }
   164 /*!
   187 /*!
   198 		{
   221 		{
   199 			locationString.append(selectedLocation.mCity);
   222 			locationString.append(selectedLocation.mCity);
   200 			locationString.append(',');
   223 			locationString.append(',');
   201 		}
   224 		}
   202 		locationString.append(selectedLocation.mCountry);
   225 		locationString.append(selectedLocation.mCountry);
   203 		emit locationTextChanged(locationString);
   226 		emit locationTextChanged(locationString, selectedLocation.mLatitude, selectedLocation.mLongitude);
   204 		mLocationLineEdit->setText(locationString );
   227 		mLocationLineEdit->setText(locationString );
   205     }
   228     }
   206 }
   229 }
       
   230 
       
   231 /*!
       
   232 	Populates the date and time in proper formats on the buttons
       
   233  */
   207 void CalenEditorCustomItem::populateDateTime(QDateTime defaultDateTime, bool isFromItem)
   234 void CalenEditorCustomItem::populateDateTime(QDateTime defaultDateTime, bool isFromItem)
   208 {
   235 {
   209 	// Store the date and time to be shown
   236 	// Store the date and time to be shown
   210     mDate = defaultDateTime.date();
   237     mDate = defaultDateTime.date();
   211 	mTime = defaultDateTime.time();
   238 	mTime = defaultDateTime.time();
   212 	
   239 	
   213 	mIsFromItem = isFromItem;
   240 	mIsFromItem = isFromItem;
   214 	
   241 	
   215     mPushButtonDate->setText(mLocale.format(defaultDateTime.date(), 
   242     mPushButtonDate->setText(mLocale.format(defaultDateTime.date(), 
   216 	                                           r_qtn_date_usual_with_zero));
   243 												r_qtn_date_usual_with_zero));
   217 	mPushButtonTime->setText(mLocale.format(defaultDateTime.time(), 
   244 	mPushButtonTime->setText(mLocale.format(defaultDateTime.time(), 
   218 	                                           r_qtn_time_usual_with_zero));
   245 												r_qtn_time_usual_with_zero));
   219 }
   246 }
   220 
   247 
       
   248 /*!
       
   249 	Sets the location on the button
       
   250  */
   221 void CalenEditorCustomItem::populateLocation(QString location )
   251 void CalenEditorCustomItem::populateLocation(QString location )
   222 {
   252 {
   223 	mLocationLineEdit->setText( location );
   253 	mLocationLineEdit->setText( location );
   224    
   254 }
   225 }
   255 
   226 
   256 /*!
       
   257 	Sets the date range
       
   258  */
   227 void CalenEditorCustomItem::setDateRange(QDate start, QDate end)
   259 void CalenEditorCustomItem::setDateRange(QDate start, QDate end)
   228 {
   260 {
   229 	mMaxDate = end;
   261 	mMaxDate = end;
   230 	mMinDate = start;
   262 	mMinDate = start;
   231 	// Check if both are falling on same day
   263 	// Check if both are falling on same day
   234 			(mMaxDate.day() == mMinDate.day())) {
   266 			(mMaxDate.day() == mMinDate.day())) {
   235 		enableDateButton(false);
   267 		enableDateButton(false);
   236 	}
   268 	}
   237 }
   269 }
   238 
   270 
       
   271 /*!
       
   272 	Sets the time range
       
   273  */
   239 void CalenEditorCustomItem::setTimeRange(QTime start, QTime end)
   274 void CalenEditorCustomItem::setTimeRange(QTime start, QTime end)
   240 {
   275 {
   241 	mMaxTime = start;
   276 	mMaxTime = start;
   242 	mMinTime = end;
   277 	mMinTime = end;
   243 }
   278 }
   244 
   279 
       
   280 /*!
       
   281 	Enables the date button
       
   282  */
   245 void CalenEditorCustomItem::enableDateButton(bool value)
   283 void CalenEditorCustomItem::enableDateButton(bool value)
   246 {
   284 {
   247 	mPushButtonDate->setEnabled(value);
   285 	mPushButtonDate->setEnabled(value);
   248 }
   286 }
   249 
   287 
   250 
   288 /*!
       
   289 	Handles the location change
       
   290  */
   251 void CalenEditorCustomItem::handleLocationTextChange(QString location)
   291 void CalenEditorCustomItem::handleLocationTextChange(QString location)
   252 {
   292 {
   253 	emit locationTextChanged(location);
   293 	emit locationTextChanged(location);
   254 }
   294 }
   255 
   295 
   256 
   296 /*!
   257 
   297 	Handles the location editing finished
       
   298  */
       
   299 void CalenEditorCustomItem::handleEditingFinished()
       
   300 {
       
   301     emit locationEditingFinished();
       
   302 }
       
   303 
       
   304 /*!
       
   305 	Launches the date picker
       
   306  */
   258 void CalenEditorCustomItem::handleDate()
   307 void CalenEditorCustomItem::handleDate()
   259 {
   308 {
       
   309 	// Create a popup with datepicker for the user to select date.
       
   310 	HbDialog *popUp = new HbDialog();
       
   311 	popUp->setDismissPolicy(HbDialog::NoDismiss);
       
   312 	popUp->setTimeout(HbDialog::NoTimeout);
       
   313 	popUp->setAttribute( Qt::WA_DeleteOnClose, true );
       
   314 	
       
   315 	// Set the proper heading
       
   316 	if (mIsFromItem) {
       
   317 		popUp->setHeadingWidget(
       
   318 						new HbLabel(hbTrId("txt_calendar_title_start_date")));
       
   319 	}else {
       
   320 		popUp->setHeadingWidget(
       
   321 						new HbLabel(hbTrId("txt_calendar_title_end_date")));
       
   322 	}
   260 	// Create a date picker
   323 	// Create a date picker
   261 	mDatePicker = new HbDateTimePicker(mDate, this);
   324 	if(mDatePicker) {
       
   325 		mDatePicker = NULL;
       
   326 	}
       
   327 	mDatePicker = new HbDateTimePicker(mDate, popUp);
   262 	mDatePicker->setMinimumDate(mMinDate);
   328 	mDatePicker->setMinimumDate(mMinDate);
   263 	mDatePicker->setMaximumDate(mMaxDate);
   329 	mDatePicker->setMaximumDate(mMaxDate);
   264 
   330 	mDatePicker->setDate(mDate);
   265 	// Create a popup with datepicker for the user to select date.
   331 	popUp->setContentWidget(mDatePicker);
   266 	HbDialog popUp;
   332 	HbAction *okAction = new HbAction(hbTrId("txt_common_button_ok"), popUp);
   267 	popUp.setDismissPolicy(HbDialog::NoDismiss);
   333 	popUp->addAction(okAction);
   268 	popUp.setTimeout(HbDialog::NoTimeout);
   334 	connect(okAction, SIGNAL(triggered()), this, SLOT(saveDate()));
       
   335 	popUp->addAction(new HbAction(hbTrId("txt_common_button_cancel"), popUp));
       
   336 	popUp->open();
       
   337 }
       
   338 
       
   339 /*!
       
   340 	Launches the time picker
       
   341  */
       
   342 void CalenEditorCustomItem::handleTime()
       
   343 {
       
   344 	// Create a popup with time picker for the user to select time.
       
   345 	HbDialog *popUp = new HbDialog();
       
   346 	popUp->setDismissPolicy(HbDialog::NoDismiss);
       
   347 	popUp->setTimeout(HbDialog::NoTimeout);
       
   348 	popUp->setAttribute( Qt::WA_DeleteOnClose, true );
   269 	
   349 	
   270 	// Set the proper heading
   350 	// Set the proper heading
   271 	if (mIsFromItem) {
   351 	if (mIsFromItem) {
   272         popUp.setHeadingWidget(new HbLabel(hbTrId("txt_calendar_title_start_date")));   
   352 		popUp->setHeadingWidget(
   273     }else {
   353 					new HbLabel(hbTrId("txt_calendar_title_start_time")));
   274         popUp.setHeadingWidget(new HbLabel(hbTrId("txt_calendar_title_end_date")));
   354 	}else {
   275     }
   355 		popUp->setHeadingWidget(
   276 
   356 					new HbLabel(hbTrId("txt_calendar_title_end_time")));
   277 	popUp.setContentWidget(mDatePicker);
   357 	}
   278 	HbAction *okAction = new HbAction(hbTrId("txt_common_button_ok"));
       
   279 	popUp.setPrimaryAction(okAction);
       
   280 	connect(okAction, SIGNAL(triggered()), this, SLOT(saveDate()));
       
   281 	connect(okAction, SIGNAL(triggered()), &popUp, SLOT(close()));
       
   282 	popUp.setSecondaryAction(new HbAction(hbTrId("txt_common_button_cancel")));
       
   283 	popUp.exec();
       
   284 }
       
   285 
       
   286 void CalenEditorCustomItem::handleTime()
       
   287 {
       
   288 	// Create a time picker.
   358 	// Create a time picker.
   289 	mTimePicker = new HbDateTimePicker(mTime, this);
   359 	if(mTimePicker) {
       
   360 		mTimePicker = NULL;
       
   361 	}
       
   362 	mTimePicker = new HbDateTimePicker(mTime, popUp);
       
   363 	
   290 	if(mLocale.timeStyle() == HbExtendedLocale::Time12) {
   364 	if(mLocale.timeStyle() == HbExtendedLocale::Time12) {
   291 		mTimePicker->setDisplayFormat("hh:mm ap");	
   365 		mTimePicker->setDisplayFormat("hh:mm ap");	
   292 	}else {
   366 	}else {
   293 		mTimePicker->setDisplayFormat("hh:mm");
   367 		mTimePicker->setDisplayFormat("hh:mm");
   294 	}
   368 	}
   295 	mTimePicker->setTime(mTime);
   369 	mTimePicker->setTime(mTime);
   296 	// Create a popup with time picker for the user to select time.
   370 	popUp->setContentWidget(mTimePicker);
   297 	HbDialog popUp;
   371 
   298 	popUp.setDismissPolicy(HbDialog::NoDismiss);
   372 	HbAction *okAction = new HbAction(hbTrId("txt_common_button_ok"), popUp);
   299 	popUp.setTimeout(HbDialog::NoTimeout);
   373 	popUp->addAction(okAction);
   300 	
       
   301 	// Set the proper heading
       
   302     if (mIsFromItem) {
       
   303         popUp.setHeadingWidget(new HbLabel(hbTrId("txt_calendar_title_start_time")));   
       
   304     }else {
       
   305         popUp.setHeadingWidget(new HbLabel(hbTrId("txt_calendar_title_end_time")));
       
   306     }
       
   307     
       
   308 	popUp.setContentWidget(mTimePicker);
       
   309 	HbAction *okAction = new HbAction(hbTrId("txt_common_button_ok"));
       
   310 	popUp.setPrimaryAction(okAction);
       
   311 	connect(okAction, SIGNAL(triggered()), this, SLOT(saveTime()));
   374 	connect(okAction, SIGNAL(triggered()), this, SLOT(saveTime()));
   312 	connect(okAction, SIGNAL(triggered()), &popUp, SLOT(close()));
   375 	popUp->addAction(new HbAction(hbTrId("txt_common_button_cancel"), popUp));
   313 	popUp.setSecondaryAction(new HbAction(hbTrId("txt_common_button_cancel"), &popUp));
   376 	popUp->open();
   314 	popUp.exec();
       
   315 }
   377 }
   316 
   378 
   317 /*!
   379 /*!
   318 	Save the start date of the event.
   380 	Save the start date of the event.
   319  */
   381  */
   351 	// Set FromTime filed Read-Only/Editable 
   413 	// Set FromTime filed Read-Only/Editable 
   352 	mPushButtonTime->setEnabled(enableTimeFiles);
   414 	mPushButtonTime->setEnabled(enableTimeFiles);
   353 	
   415 	
   354 	// Set FromTime in Editor
   416 	// Set FromTime in Editor
   355 	mPushButtonTime->setText(mLocale.format(fromDateTime.time(),r_qtn_time_usual_with_zero));
   417 	mPushButtonTime->setText(mLocale.format(fromDateTime.time(),r_qtn_time_usual_with_zero));
       
   418 	
       
   419 	// Store the time
       
   420     mTime = fromDateTime.time();
       
   421 }
       
   422 
       
   423 /*!
       
   424 	Disable Date field.
       
   425  */
       
   426 void CalenEditorCustomItem::disableFromToDateField()
       
   427 {
       
   428 	// disable the date field.
       
   429 	mPushButtonDate->setEnabled(false);
   356 }
   430 }
   357 
   431 
   358 /*!
   432 /*!
   359 	Enable/Desable ToTime filed and update time value
   433 	Enable/Desable ToTime filed and update time value
   360  */
   434  */
   362 {
   436 {
   363 	// Set ToTime filed Read-Only/Editable 
   437 	// Set ToTime filed Read-Only/Editable 
   364 	mPushButtonTime->setEnabled(enableTimeFiles);
   438 	mPushButtonTime->setEnabled(enableTimeFiles);
   365 	
   439 	
   366 	// Set ToTime in Editor
   440 	// Set ToTime in Editor
   367 	mPushButtonTime->setText(mLocale.format(toDateTime.time(),r_qtn_time_usual_with_zero));
   441 	mPushButtonTime->setText(mLocale.format(
       
   442 							toDateTime.time(),r_qtn_time_usual_with_zero));
       
   443 	
       
   444 	// Store the time
       
   445 	mTime = toDateTime.time();
   368 }
   446 }
   369 
   447 
   370 /*!
   448 /*!
   371    OverRide from DataFrom
   449    OverRide from DataFrom
   372  */
   450  */
   375     HbDataFormModelItem::DataItemType itemType = 
   453     HbDataFormModelItem::DataItemType itemType = 
   376         static_cast<HbDataFormModelItem::DataItemType>(
   454         static_cast<HbDataFormModelItem::DataItemType>(
   377         index.data(HbDataFormModelItem::ItemTypeRole).toInt());
   455         index.data(HbDataFormModelItem::ItemTypeRole).toInt());
   378 
   456 
   379     if(itemType == CustomWidgetFrom || itemType == CustomWidgetTo || itemType == RepeatUntilOffset 
   457     if(itemType == CustomWidgetFrom || itemType == CustomWidgetTo || itemType == RepeatUntilOffset 
   380 			|| itemType == CustomWidgetLocation ) {
   458 			|| itemType == CustomWidgetLocation || itemType == ReminderTimeOffset ) {
   381         return true;
   459         return true;
   382     } else {
   460     } else {
   383         return false;
   461         return false;
   384     }
   462     }
   385 }
   463 }
   398     	case RepeatUntilOffset:
   476     	case RepeatUntilOffset:
   399     	{
   477     	{
   400     		mRepeatUntilWidget->setText(modelItem->contentWidgetData("text").toString());
   478     		mRepeatUntilWidget->setText(modelItem->contentWidgetData("text").toString());
   401     	}
   479     	}
   402     	break;
   480     	break;
       
   481     	
       
   482     	case ReminderTimeOffset:
       
   483     	{
       
   484     		mReminderTimeWidget->setText(modelItem->contentWidgetData("text").toString());
       
   485     	}
       
   486     	break;
   403     }
   487     }
   404 }
   488 }
   405 
   489 
       
   490 QDateTime CalenEditorCustomItem::getDateTime()
       
   491 {
       
   492     return QDateTime(mDate, mTime);
       
   493 }
       
   494 
   406 Q_IMPLEMENT_USER_METATYPE(QLocationPickerItem)
   495 Q_IMPLEMENT_USER_METATYPE(QLocationPickerItem)
   407 
   496 
   408 // End of file	--Don't remove this.
   497 // End of file	--Don't remove this.