|
1 /* |
|
2 * Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: CalenDayView class definition. |
|
15 * |
|
16 */ |
|
17 |
|
18 //system includes |
|
19 #include <QDateTime> |
|
20 #include <QGraphicsLinearLayout> |
|
21 #include <xqsettingsmanager.h> |
|
22 #include <hbaction.h> |
|
23 #include <hbmenu.h> |
|
24 #include <hbmainwindow.h> |
|
25 #include <hbmodeliterator.h> |
|
26 #include <hbstyleloader.h> |
|
27 #include <hbgroupbox.h> |
|
28 #include <hbextendedlocale.h> |
|
29 #include <agendautil.h> |
|
30 //user includes |
|
31 #include "calendayview.h" |
|
32 #include "calencontext.h" |
|
33 #include "calenservices.h" |
|
34 #include "calendocloader.h" |
|
35 #include "calendateutils.h" //useful date/time utils |
|
36 #include "calendaycontentscrollarea.h" |
|
37 #include "calendaycontentwidget.h" |
|
38 #include "calendayhourscrollarea.h" |
|
39 #include "calendaymodelmanager.h" |
|
40 #include "CalenUid.h" |
|
41 #include "CalendarPrivateCRKeys.h" |
|
42 #include "calenpluginlabel.h" |
|
43 #include "calendaymodel.h" |
|
44 |
|
45 //constants |
|
46 |
|
47 // ----------------------------------------------------------------------------- |
|
48 // CalenDayView() |
|
49 // Constructor. |
|
50 // ----------------------------------------------------------------------------- |
|
51 // |
|
52 CalenDayView::CalenDayView(MCalenServices &services) : |
|
53 CalenNativeView(services), mContentScrollArea(NULL), mContentWidget(NULL), |
|
54 mHourScrollArea(NULL), mSettingsManager(NULL), |
|
55 mRegionalInfo(XQSettingsKey::TargetCentralRepository, KCRUidCalendar, |
|
56 KCalendarShowRegionalInfo), |
|
57 mServices(services), mRegionalInfoGroupBox(NULL), mGoToTodayMenuAction(NULL) |
|
58 { |
|
59 setupMenu(); |
|
60 |
|
61 // Create model manager |
|
62 mModelManager = new CalenDayModelManager(mServices, true, this); |
|
63 |
|
64 mVLayout = new QGraphicsLinearLayout(Qt::Vertical, NULL); |
|
65 mVLayout->setContentsMargins(0.0, 0.0, 0.0, 0.0); |
|
66 mVLayout->setSpacing(0.0); |
|
67 |
|
68 // Create heading label and insert into layout |
|
69 mHeadingLabel = new HbGroupBox(); |
|
70 HbEffect::add(mHeadingLabel, ":/fade_out.fxml", "fadeOut"); |
|
71 HbEffect::add(mHeadingLabel, ":/fade_in.fxml", "fadeIn"); |
|
72 |
|
73 mSettingsManager = new XQSettingsManager(this); |
|
74 |
|
75 // Add day info |
|
76 mVLayout->addItem(mHeadingLabel); |
|
77 |
|
78 //show regional info if set so |
|
79 showRegionalInformationFadeIn(); |
|
80 mSettingsManager->startMonitoring(mRegionalInfo); |
|
81 |
|
82 // Put hour scroll area and content scroll area into horizontal layout |
|
83 QGraphicsLinearLayout *hLayout = new QGraphicsLinearLayout(Qt::Horizontal, NULL); |
|
84 hLayout->setContentsMargins(0.0, 0.0, 0.0, 0.0); |
|
85 hLayout->setSpacing(0.0); |
|
86 |
|
87 // Create scroll area for content (events) |
|
88 mContentScrollArea = new CalenDayContentScrollArea(this); |
|
89 |
|
90 // Create and apply central widget for scroll area |
|
91 mContentWidget = new CalenDayContentWidget(*mModelManager, mContentScrollArea); |
|
92 mContentScrollArea->setContentWidget(mContentWidget); |
|
93 |
|
94 // Create scroll area for hour elements |
|
95 mHourScrollArea = new CalenDayHourScrollArea(this); |
|
96 |
|
97 hLayout->addItem(mHourScrollArea); |
|
98 hLayout->addItem(mContentScrollArea); |
|
99 |
|
100 mVLayout->addItem(hLayout); |
|
101 setLayout(mVLayout); |
|
102 |
|
103 setupSlots(); |
|
104 |
|
105 //setup Back functionality |
|
106 if (ECalenDayView != mServices.getFirstView()) { |
|
107 HbAction* action = new HbAction(Hb::BackNaviAction, this); |
|
108 setNavigationAction(action); |
|
109 // Connect to the signal triggered by clicking on back button. |
|
110 connect(action, SIGNAL(triggered()), this, SLOT(onBack())); |
|
111 } |
|
112 |
|
113 HbStyleLoader::registerFilePath(":/calendayhourelement.css"); |
|
114 HbStyleLoader::registerFilePath(":/calendayhourelement.widgetml"); |
|
115 HbStyleLoader::registerFilePath(":/calendayitem.css"); |
|
116 HbStyleLoader::registerFilePath(":/calendayitem.widgetml"); |
|
117 } |
|
118 |
|
119 // ----------------------------------------------------------------------------- |
|
120 // ~CalenDayView() |
|
121 // Destructor. |
|
122 // ----------------------------------------------------------------------------- |
|
123 // |
|
124 CalenDayView::~CalenDayView() |
|
125 { |
|
126 mSettingsManager->stopMonitoring(mRegionalInfo); |
|
127 } |
|
128 |
|
129 // ----------------------------------------------------------------------------- |
|
130 // onLocaleChanged() |
|
131 // Handles locale change. |
|
132 // ----------------------------------------------------------------------------- |
|
133 // |
|
134 void CalenDayView::onLocaleChanged(int reason) |
|
135 { |
|
136 Q_UNUSED( reason ) |
|
137 } |
|
138 |
|
139 // ----------------------------------------------------------------------------- |
|
140 // From CalenView |
|
141 // doPopulation() |
|
142 // Handles view (re)population. |
|
143 // ----------------------------------------------------------------------------- |
|
144 // |
|
145 void CalenDayView::doPopulation() |
|
146 { |
|
147 // Triggers fading effect for heading label |
|
148 getCurrentDate(); |
|
149 HbEffect::start(mHeadingLabel, "fadeOut", this, "setHeadingText"); |
|
150 |
|
151 mModelManager->refreshAllModels(); |
|
152 //Set date and time for hour scroll area. |
|
153 //It's later used by hour element to display timeline |
|
154 mHourScrollArea->setDateTime(mDate); |
|
155 |
|
156 //set in menu go to today visible |
|
157 QDateTime currentDateTime = QDateTime::currentDateTime(); |
|
158 if (mGoToTodayMenuAction and currentDateTime.date() == mDate.date()) { |
|
159 mGoToTodayMenuAction->setVisible(false); |
|
160 } |
|
161 else if(mGoToTodayMenuAction) { |
|
162 mGoToTodayMenuAction->setVisible(true); |
|
163 } |
|
164 |
|
165 setupViewport(); |
|
166 |
|
167 populationComplete(); |
|
168 } |
|
169 |
|
170 // ----------------------------------------------------------------------------- |
|
171 // From CalenView |
|
172 // populationComplete() |
|
173 // Informs the organizer that the view's population is complete. |
|
174 // ----------------------------------------------------------------------------- |
|
175 // |
|
176 void CalenDayView::populationComplete() |
|
177 { |
|
178 CalenNativeView::populationComplete(); |
|
179 } |
|
180 |
|
181 // ----------------------------------------------------------------------------- |
|
182 // From MCalenNotificationHandler |
|
183 // HandleNotification() |
|
184 // The function handles calendar notifications. |
|
185 // ----------------------------------------------------------------------------- |
|
186 // |
|
187 void CalenDayView::HandleNotification(const TCalenNotification notification) |
|
188 { |
|
189 Q_UNUSED( notification ) |
|
190 } |
|
191 |
|
192 // ----------------------------------------------------------------------------- |
|
193 // setupView() |
|
194 // Sets up the view accroding to the 'xml' |
|
195 // ----------------------------------------------------------------------------- |
|
196 // |
|
197 void CalenDayView::setupView(CalenDocLoader* docLoader) |
|
198 { |
|
199 Q_UNUSED( docLoader ) |
|
200 } |
|
201 |
|
202 //private slots |
|
203 |
|
204 // ----------------------------------------------------------------------------- |
|
205 // onBack() |
|
206 // Handles 'back' functionality; |
|
207 // ----------------------------------------------------------------------------- |
|
208 // |
|
209 void CalenDayView::onBack() |
|
210 { |
|
211 TRAP_IGNORE(mServices.IssueCommandL(ECalenMonthView)); |
|
212 } |
|
213 |
|
214 // ----------------------------------------------------------------------------- |
|
215 // dayChange() |
|
216 // ----------------------------------------------------------------------------- |
|
217 // |
|
218 void CalenDayView::dayChangeStarted(CalenScrollDirection direction) |
|
219 { |
|
220 if (direction == ECalenScrollToNext) { |
|
221 mDate = mDate.addDays(1); |
|
222 } |
|
223 else { |
|
224 mDate = mDate.addDays(-1); |
|
225 } |
|
226 |
|
227 //set in menu go to today visible |
|
228 QDateTime currentDateTime = QDateTime::currentDateTime(); |
|
229 if (mGoToTodayMenuAction and currentDateTime.date() == mDate.date()) { |
|
230 mGoToTodayMenuAction->setVisible(false); |
|
231 } |
|
232 else if(mGoToTodayMenuAction) { |
|
233 mGoToTodayMenuAction->setVisible(true); |
|
234 } |
|
235 |
|
236 // Triggers fading effect for heading label. |
|
237 HbEffect::start(mHeadingLabel, "fadeOut", this, "setHeadingText"); |
|
238 HbEffect::start(mRegionalInfoGroupBox, "fadeOut", this, "showRegionalInformation"); |
|
239 |
|
240 mServices.Context().setFocusDate(mDate); |
|
241 } |
|
242 |
|
243 // ----------------------------------------------------------------------------- |
|
244 // dayChanged() |
|
245 // ----------------------------------------------------------------------------- |
|
246 // |
|
247 void CalenDayView::dayChanged(CalenScrollDirection direction) |
|
248 { |
|
249 mModelManager->viewsScrollingFinished(direction); |
|
250 mHourScrollArea->setDateTime(mDate); |
|
251 } |
|
252 |
|
253 // ----------------------------------------------------------------------------- |
|
254 // getCurrentDate() |
|
255 // ----------------------------------------------------------------------------- |
|
256 // |
|
257 void CalenDayView::getCurrentDate() |
|
258 { |
|
259 mDate = CalenNativeView::mServices.Context().focusDateAndTime(); |
|
260 } |
|
261 |
|
262 // ----------------------------------------------------------------------------- |
|
263 // setupMenu() |
|
264 // ----------------------------------------------------------------------------- |
|
265 // |
|
266 void CalenDayView::setupMenu() |
|
267 { |
|
268 menu()->addAction(hbTrId("txt_calendar_opt_new_event"), this, SLOT(runNewMeeting())); |
|
269 //get pointer to this position, because need to change visibility |
|
270 mGoToTodayMenuAction = menu()->addAction(hbTrId("txt_calendar_opt_go_to_today"), this, SLOT(runGoToToday())); |
|
271 menu()->addAction(hbTrId("txt_calendar_opt_go_to_date"), this, SLOT(goToDate())); |
|
272 //TODO: Add id for this text |
|
273 //"Switch to Agenda view" |
|
274 menu()->addAction(hbTrId("txt_calendar_opt_switch_to_agenda_view"), this, SLOT(runChangeToAgendaView())); |
|
275 //TODO: Add id for this text (lunar data) |
|
276 //"Show lunar data" |
|
277 if (pluginEnabled()) |
|
278 { |
|
279 menu()->addAction(hbTrId("txt_calendar_opt_show_lunar_data"), this, SLOT(runLunarData())); |
|
280 } |
|
281 menu()->addAction(hbTrId("txt_calendar_opt_settings"), this, SLOT(launchSettingsView())); |
|
282 } |
|
283 |
|
284 /*! |
|
285 \brief Ot change Day view to Agenda View |
|
286 */ |
|
287 void CalenDayView::runChangeToAgendaView() |
|
288 { |
|
289 changeView(ECalenAgendaView); |
|
290 } |
|
291 |
|
292 /*! |
|
293 \brief Shows lunar data in popup box |
|
294 */ |
|
295 void CalenDayView::runLunarData() |
|
296 { |
|
297 TRAP_IGNORE(mServices.IssueCommandL(ECalenRegionalPluginTapEvent)); |
|
298 } |
|
299 |
|
300 // ----------------------------------------------------------------------------- |
|
301 // setupSlots() |
|
302 // ----------------------------------------------------------------------------- |
|
303 // |
|
304 void CalenDayView::setupSlots() |
|
305 { |
|
306 // Connecting other view-related signals/slots |
|
307 connect(mContentScrollArea, |
|
308 SIGNAL(scrollAreaMoveStarted(CalenScrollDirection)), this, |
|
309 SLOT(dayChangeStarted(CalenScrollDirection))); |
|
310 |
|
311 connect(mContentScrollArea, |
|
312 SIGNAL(scrollAreaMoveFinished(CalenScrollDirection)), mContentWidget, |
|
313 SLOT(relayoutWidgets(CalenScrollDirection))); |
|
314 |
|
315 connect(mContentWidget, SIGNAL( |
|
316 widgetsRelayoutFinished(CalenScrollDirection)), mContentScrollArea, |
|
317 SLOT(scrollToMiddleWidget())); |
|
318 |
|
319 connect(mContentWidget, |
|
320 SIGNAL(widgetsRelayoutFinished(CalenScrollDirection)), this, |
|
321 SLOT(dayChanged(CalenScrollDirection))); |
|
322 |
|
323 connect(mContentWidget, SIGNAL(scrollPositionChanged(const QPointF &)), |
|
324 mHourScrollArea, SLOT(scrollVertically(const QPointF &))); |
|
325 |
|
326 connect(mHourScrollArea, SIGNAL(scrollPositionChanged(const QPointF &)), |
|
327 mContentWidget, SLOT(widgetScrolled(const QPointF &))); |
|
328 |
|
329 connect(mSettingsManager, SIGNAL(valueChanged(XQSettingsKey, QVariant)), |
|
330 this, SLOT(showHideRegionalInformationChanged(XQSettingsKey, QVariant))); |
|
331 } |
|
332 |
|
333 // ----------------------------------------------------------------------------- |
|
334 // runNewMeeting() |
|
335 // ----------------------------------------------------------------------------- |
|
336 // |
|
337 void CalenDayView::runNewMeeting() |
|
338 { |
|
339 QDateTime dateTime(mDate); |
|
340 TRAP_IGNORE( |
|
341 dateTime.setTime(mServices.Context().defaultCalTimeForViewsL().time()); |
|
342 mServices.Context().setFocusDateAndTime(dateTime); |
|
343 mServices.IssueCommandL(ECalenNewMeeting) |
|
344 ); |
|
345 } |
|
346 |
|
347 // ----------------------------------------------------------------------------- |
|
348 // runGoToToday() |
|
349 // ----------------------------------------------------------------------------- |
|
350 // |
|
351 void CalenDayView::runGoToToday() |
|
352 { |
|
353 mServices.Context().setFocusDateAndTime(CalenDateUtils::today()); |
|
354 TRAP_IGNORE(mServices.IssueCommandL(ECalenGotoToday)); |
|
355 refreshViewOnGoToDate(); |
|
356 } |
|
357 |
|
358 |
|
359 // ----------------------------------------------------------------------------- |
|
360 // changeView() |
|
361 // ----------------------------------------------------------------------------- |
|
362 // |
|
363 void CalenDayView::changeView(TCalenCommandId viewId) |
|
364 { |
|
365 TRAP_IGNORE(mServices.IssueCommandL(viewId)); |
|
366 } |
|
367 |
|
368 // ---------------------------------------------------------------------------- |
|
369 // CalenDayView::setHeadingText |
|
370 // Sets heading text according to date from model and locale. |
|
371 // It's connected to modelReset signal |
|
372 // ---------------------------------------------------------------------------- |
|
373 // |
|
374 void CalenDayView::setHeadingText(const HbEffect::EffectStatus &status) |
|
375 { |
|
376 Q_UNUSED(status) |
|
377 |
|
378 // Format the date as per the device locale settings |
|
379 HbExtendedLocale systemLocale = HbExtendedLocale::system(); |
|
380 |
|
381 // Get localised name of the day from locale |
|
382 QString dayString = systemLocale.dayName(mDate.date().dayOfWeek()); |
|
383 // Append a single space |
|
384 dayString.append(" "); |
|
385 // Set the heading |
|
386 |
|
387 // Append the date which is formatted as per the locale |
|
388 mHeadingLabel->setHeading(hbTrId("txt_calendar_subhead_1_2").arg(dayString).arg( |
|
389 systemLocale.format(mDate.date(), r_qtn_date_usual_with_zero))); |
|
390 |
|
391 HbEffect::start(mHeadingLabel, "fadeIn"); |
|
392 } |
|
393 |
|
394 // ---------------------------------------------------------------------------- |
|
395 // CalenDayView::showHideRegionalInformation |
|
396 // To run effect on lunar data label |
|
397 // ---------------------------------------------------------------------------- |
|
398 // |
|
399 void CalenDayView::showRegionalInformation(const HbEffect::EffectStatus &status) |
|
400 { |
|
401 Q_UNUSED(status); |
|
402 showRegionalInformationFadeIn(); |
|
403 } |
|
404 |
|
405 // ---------------------------------------------------------------------------- |
|
406 // CalenDayView::showRegionalInformationFadeIn |
|
407 // To run effect on lunar data label and change text according to date change |
|
408 // ---------------------------------------------------------------------------- |
|
409 // |
|
410 void CalenDayView::showRegionalInformationFadeIn() |
|
411 { |
|
412 showHideRegionalInformationChanged(mRegionalInfo, 3); |
|
413 HbEffect::start(mRegionalInfoGroupBox, "fadeIn"); |
|
414 } |
|
415 |
|
416 // ---------------------------------------------------------------------------- |
|
417 // CalenDayView::showHideRegionalInformationChanged |
|
418 // To Show and hide regional plugin label depends upon settings |
|
419 // ---------------------------------------------------------------------------- |
|
420 // |
|
421 void CalenDayView::showHideRegionalInformationChanged(const XQSettingsKey& key, const QVariant&) |
|
422 { |
|
423 if (key.key() == mRegionalInfo.key()) |
|
424 { |
|
425 int showRegionalInfo = |
|
426 mSettingsManager->readItemValue(mRegionalInfo).toUInt(); |
|
427 |
|
428 if (showRegionalInfo) |
|
429 { |
|
430 QString *pluginString = pluginText(); |
|
431 if (pluginString) |
|
432 { |
|
433 if (!mRegionalInfoGroupBox) |
|
434 { |
|
435 mRegionalInfoGroupBox = new HbGroupBox(); |
|
436 CalenPluginLabel *regionalInfo = new CalenPluginLabel( |
|
437 mServices, this); |
|
438 HbEffect::add(mRegionalInfoGroupBox, ":/fade_out.fxml", |
|
439 "fadeOut"); |
|
440 HbEffect::add(mRegionalInfoGroupBox, ":/fade_in.fxml", "fadeIn"); |
|
441 |
|
442 // add margins to calenpluginlabel |
|
443 |
|
444 HbStyle style; |
|
445 HbDeviceProfile deviceProfile; |
|
446 qreal marginLeft = 0.0; |
|
447 qreal marginRight = 0.0; |
|
448 qreal marginTop = 0.0; |
|
449 qreal marginBottom = 0.0; |
|
450 style.parameter(QString("hb-param-margin-gene-left"), marginLeft, deviceProfile); |
|
451 style.parameter(QString("hb-param-margin-gene-right"), marginRight, deviceProfile); |
|
452 style.parameter(QString("hb-param-margin-gene-top"), marginTop, deviceProfile); |
|
453 style.parameter(QString("hb-param-margin-gene-bottom"), marginBottom, deviceProfile); |
|
454 |
|
455 regionalInfo->setContentsMargins(1, 1, 1, 1); |
|
456 |
|
457 // qreal width = mRegionalInfoGroupBox->size().width(); |
|
458 // qreal height = mRegionalInfoGroupBox->size().height() + marginTop + marginBottom; |
|
459 |
|
460 // mRegionalInfoGroupBox->resize(width, height); |
|
461 |
|
462 mRegionalInfoGroupBox->setContentWidget(regionalInfo); |
|
463 } |
|
464 |
|
465 if (pluginEnabled()) |
|
466 { |
|
467 HbLabel *pluginInfoLabel = qobject_cast<HbLabel *> ( |
|
468 mRegionalInfoGroupBox->contentWidget()); |
|
469 |
|
470 pluginInfoLabel->setPlainText(*pluginString); |
|
471 |
|
472 mVLayout->insertItem(1, mRegionalInfoGroupBox); |
|
473 } |
|
474 } |
|
475 } |
|
476 else |
|
477 { |
|
478 |
|
479 if (mRegionalInfoGroupBox) |
|
480 { |
|
481 mVLayout->removeItem(mRegionalInfoGroupBox); |
|
482 delete mRegionalInfoGroupBox; |
|
483 mRegionalInfoGroupBox = NULL; |
|
484 } |
|
485 } |
|
486 } |
|
487 } |
|
488 |
|
489 // ---------------------------------------------------------------------------- |
|
490 // CalenDayView::setupViewport |
|
491 // Scrolls view according to current day and events |
|
492 // ---------------------------------------------------------------------------- |
|
493 // |
|
494 void CalenDayView::setupViewport() |
|
495 { |
|
496 QDateTime currentTime = QDateTime::currentDateTime(); |
|
497 |
|
498 //Filter flags (only timed events) |
|
499 AgendaUtil::FilterFlags filter = AgendaUtil::FilterFlags( |
|
500 AgendaUtil::IncludeAppointments ); |
|
501 QList<AgendaEntry> list; |
|
502 // Fetch the instance list from the agenda interface |
|
503 list = mServices.agendaInterface()->fetchEntriesInRange(currentTime, currentTime, filter); |
|
504 |
|
505 // If we have event in current day and hour, scroll to this event |
|
506 if(mDate.date() == currentTime.date() && !list.isEmpty()){ |
|
507 int hourToScrollTo(list.first().startTime().time().hour()); |
|
508 mHourScrollArea->scrollToHour(hourToScrollTo); |
|
509 } |
|
510 else{ |
|
511 //Scroll view to 7am |
|
512 mHourScrollArea->scrollToHour(7); |
|
513 } |
|
514 } |
|
515 |
|
516 //End of File |