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); |
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 */ |