1 /* |
|
2 * Copyright (c) 2009 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 implementation. |
|
15 * |
|
16 */ |
|
17 |
|
18 // System includes |
|
19 #include <QGraphicsSceneEvent> |
|
20 #include <hbmainwindow.h> |
|
21 #include <hbaction.h> |
|
22 |
|
23 // User includes |
|
24 #include "calendayview.h" |
|
25 #include "calendocloader.h" |
|
26 #include "calendayviewwidget.h" |
|
27 #include "calenservices.h" |
|
28 #include "calencommon.h" |
|
29 #include "calencontext.h" |
|
30 #include "calendateutils.h" |
|
31 |
|
32 // ---------------------------------------------------------------------------- |
|
33 // CalenDayView::CalenDayView |
|
34 // Rest of the details are commented in the header |
|
35 // ---------------------------------------------------------------------------- |
|
36 // |
|
37 CalenDayView::CalenDayView(MCalenServices &services): |
|
38 CalenNativeView(services), |
|
39 mSoftKeyAction(NULL), |
|
40 mGoToTodayAction(NULL), |
|
41 mActionTaken(false) |
|
42 { |
|
43 // No implementation yet |
|
44 } |
|
45 |
|
46 // ---------------------------------------------------------------------------- |
|
47 // CCalenDayView::~CalenDayView |
|
48 // Rest of the details are commented in the header |
|
49 // ---------------------------------------------------------------------------- |
|
50 // |
|
51 CalenDayView::~CalenDayView() |
|
52 { |
|
53 // No implementation yet |
|
54 } |
|
55 |
|
56 // ---------------------------------------------------------------------------- |
|
57 // CCalenDayView::setupView |
|
58 // Rest of the details are commented in the header |
|
59 // ---------------------------------------------------------------------------- |
|
60 // |
|
61 void CalenDayView::setupView(CalenDocLoader *docLoader) |
|
62 { |
|
63 if (!docLoader) { |
|
64 // Nothing can be done. Simply return |
|
65 return; |
|
66 } |
|
67 // Store the document loader for reference later |
|
68 mDocLoader = docLoader; |
|
69 |
|
70 // Listen to orientation change events |
|
71 connect(&(mServices.MainWindow()), SIGNAL(orientationChanged(Qt::Orientation)), |
|
72 this, SLOT(orientationChanged(Qt::Orientation))); |
|
73 |
|
74 // Get the pointer to the content widget |
|
75 mDayViewWidget = qobject_cast<CalenDayViewWidget*>(mDocLoader->findWidget(CALEN_DAYVIEW_WIDGET)); |
|
76 if (!mDayViewWidget) { |
|
77 qFatal("calendayview.cpp : Unable to find the content widget"); |
|
78 } |
|
79 mDayViewWidget->setupWidget(this); |
|
80 |
|
81 // Initialize all the menu and toolbar actions |
|
82 setupActions(); |
|
83 } |
|
84 |
|
85 // ---------------------------------------------------------------------------- |
|
86 // CCalenDayView::doPopulation |
|
87 // Rest of the details are commented in the header |
|
88 // ---------------------------------------------------------------------------- |
|
89 // |
|
90 void CalenDayView::doPopulation() |
|
91 { |
|
92 // The content widget has not been constructed. Don't do anything |
|
93 if (!mDayViewWidget) { |
|
94 return; |
|
95 } |
|
96 // Get the day for which this view is being shown from the context |
|
97 mDate = mServices.Context().focusDateAndTimeL(); |
|
98 |
|
99 // Check if the current day being shown is "Today" |
|
100 if (mGoToTodayAction) { |
|
101 if (mDate.date() == CalenDateUtils::today().date()) { |
|
102 // Hide the "Go to today" option |
|
103 mGoToTodayAction->setVisible(false); |
|
104 } else { |
|
105 mGoToTodayAction->setVisible(true); |
|
106 } |
|
107 } |
|
108 |
|
109 // Set self as the current view |
|
110 // mServices.MainWindow().setCurrentView(this); |
|
111 |
|
112 // Dont override the soft key behavior if day view is the first view |
|
113 if (ECalenDayView != mServices.getFirstView()) { |
|
114 mSoftKeyAction = new HbAction(Hb::BackAction); |
|
115 setNavigationAction(mSoftKeyAction); |
|
116 // Connect to the signal triggered by clicking on back button. |
|
117 connect(mSoftKeyAction, SIGNAL(triggered()), this, |
|
118 SLOT(launchMonthView())); |
|
119 } |
|
120 // Initialize the content widget |
|
121 mDayViewWidget->showWidget(); |
|
122 |
|
123 // Population is complete, issue a notification |
|
124 populationComplete(); |
|
125 } |
|
126 |
|
127 /*! |
|
128 Funtion to refresh the current view upon selecting a date |
|
129 from GoToDate popup |
|
130 */ |
|
131 void CalenDayView::refreshViewOnGoToDate() |
|
132 { |
|
133 // Get the day for which this view is being shown from the context |
|
134 mDate = mServices.Context().focusDateAndTimeL(); |
|
135 |
|
136 // Check if the current day being shown is "Today" |
|
137 if (mGoToTodayAction) { |
|
138 if (mDate.date() == CalenDateUtils::today().date()) { |
|
139 // Hide the "Go to today" option |
|
140 mGoToTodayAction->setVisible(false); |
|
141 } else { |
|
142 mGoToTodayAction->setVisible(true); |
|
143 } |
|
144 } |
|
145 |
|
146 // Initialize the content widget |
|
147 mDayViewWidget->showWidget(); |
|
148 } |
|
149 |
|
150 // ---------------------------------------------------------------------------- |
|
151 // CCalenDayView::HandleNotification |
|
152 // Rest of the details are commented in the header |
|
153 // ---------------------------------------------------------------------------- |
|
154 // |
|
155 void CalenDayView::HandleNotification(const TCalenNotification notification) |
|
156 { |
|
157 Q_UNUSED(notification) |
|
158 // No implementation yet |
|
159 } |
|
160 |
|
161 // ---------------------------------------------------------------------------- |
|
162 // CCalenDayView::docLoader |
|
163 // Rest of the details are commented in the header |
|
164 // ---------------------------------------------------------------------------- |
|
165 // |
|
166 CalenDocLoader* CalenDayView::docLoader() |
|
167 { |
|
168 return mDocLoader; |
|
169 } |
|
170 |
|
171 // ---------------------------------------------------------------------------- |
|
172 // CalenDayView::handleLocaleChange |
|
173 // Rest of the details are commented in the header |
|
174 // ---------------------------------------------------------------------------- |
|
175 // |
|
176 void CalenDayView::mousePressEvent(QGraphicsSceneMouseEvent *event) |
|
177 { |
|
178 // TODO: Remove these after gestures are available |
|
179 mTapPoint = event->pos(); |
|
180 event->accept(); |
|
181 } |
|
182 |
|
183 // ---------------------------------------------------------------------------- |
|
184 // CalenDayView::handleLocaleChange |
|
185 // Rest of the details are commented in the header |
|
186 // ---------------------------------------------------------------------------- |
|
187 // |
|
188 void CalenDayView::mouseMoveEvent(QGraphicsSceneMouseEvent *event) |
|
189 { |
|
190 // TODO: Remove these after gestures are available |
|
191 QPointF curPos = event->pos(); |
|
192 if (abs(curPos.y() - mTapPoint.y()) > 20) { |
|
193 event->accept(); |
|
194 return; |
|
195 } |
|
196 if (curPos.x() - mTapPoint.x() > 50) { |
|
197 mTapPoint = QPointF(0, 0); |
|
198 mServices.IssueCommandL(ECalenShowPrevDay); |
|
199 mActionTaken = true; |
|
200 } else if (curPos.x() - mTapPoint.x() < -50) { |
|
201 mTapPoint = QPointF(0, 0); |
|
202 mServices.IssueCommandL(ECalenShowNextDay); |
|
203 mActionTaken = true; |
|
204 } |
|
205 event->accept(); |
|
206 } |
|
207 |
|
208 // ---------------------------------------------------------------------------- |
|
209 // CCalenDayView::eventFilter |
|
210 // Rest of the details are commented in the header |
|
211 // ---------------------------------------------------------------------------- |
|
212 // |
|
213 bool CalenDayView::eventFilter(QObject *source, QEvent *event) |
|
214 { |
|
215 // TODO : remove this line after gestures are available |
|
216 mActionTaken = false; |
|
217 Q_UNUSED(source) |
|
218 if (event->type() == QEvent::GraphicsSceneMousePress) { |
|
219 QGraphicsSceneMouseEvent *mouseEvent = static_cast<QGraphicsSceneMouseEvent*>(event); |
|
220 mousePressEvent(mouseEvent); |
|
221 } else if (event->type() == QEvent::GraphicsSceneMouseMove) { |
|
222 QGraphicsSceneMouseEvent *mouseEvent = static_cast<QGraphicsSceneMouseEvent*>(event); |
|
223 mouseMoveEvent(mouseEvent); |
|
224 } |
|
225 if (mActionTaken) { |
|
226 // Swipe gesture has been enforced. |
|
227 // Do not pass the event to the source |
|
228 return true; |
|
229 } |
|
230 return false; |
|
231 } |
|
232 |
|
233 // ---------------------------------------------------------------------------- |
|
234 // CCalenDayView::createToolBar |
|
235 // Rest of the details are commented in the header |
|
236 // ---------------------------------------------------------------------------- |
|
237 // |
|
238 void CalenDayView::setupActions() |
|
239 { |
|
240 // Get the actions associated with this view |
|
241 HbAction *newEventAction = qobject_cast<HbAction *> |
|
242 (mDocLoader->findObject(CALEN_DAYVIEW_MENU_NEW_EVENT)); |
|
243 if (!newEventAction) { |
|
244 qFatal("calendayview.cpp : Unable to find new event action"); |
|
245 } |
|
246 // Connect to the signal triggered by new event action |
|
247 connect(newEventAction, SIGNAL(triggered()), mDayViewWidget, SLOT(createNewEvent())); |
|
248 |
|
249 mGoToTodayAction = qobject_cast<HbAction *> |
|
250 (mDocLoader->findObject(CALEN_DAYVIEW_MENU_GO_TO_TODAY)); |
|
251 if (!mGoToTodayAction) { |
|
252 qFatal("calendayview.cpp : Unable to find go to today action"); |
|
253 } |
|
254 // Connect to the signal triggered by new event action |
|
255 connect(mGoToTodayAction, SIGNAL(triggered()), mDayViewWidget, SLOT(goToToday())); |
|
256 |
|
257 HbAction *goToDateAction = qobject_cast<HbAction *> |
|
258 (mDocLoader->findObject(CALEN_DAYVIEW_MENU_GO_TO_DATE)); |
|
259 if (!goToDateAction) { |
|
260 qFatal("calendayview.cpp : Unable to find go to date action"); |
|
261 } |
|
262 // Connect to the signal triggered by new event action |
|
263 connect(goToDateAction, SIGNAL(triggered()), this, SLOT(goToDate())); |
|
264 |
|
265 HbAction *settingsAction = qobject_cast<HbAction *> |
|
266 (mDocLoader->findObject(CALEN_DAYVIEW_MENU_SETTINGS)); |
|
267 if (!settingsAction) { |
|
268 qFatal("calendayview.cpp : Unable to find settings action"); |
|
269 } |
|
270 // Connect to the signal triggered by new event action |
|
271 connect(settingsAction, SIGNAL(triggered()), this, SLOT(launchSettingsView())); |
|
272 } |
|
273 |
|
274 // ---------------------------------------------------------------------------- |
|
275 // CCalenDayView::onLocaleChanged |
|
276 // Rest of the details are commented in the header |
|
277 // ---------------------------------------------------------------------------- |
|
278 // |
|
279 void CalenDayView::onLocaleChanged(int reason) |
|
280 { |
|
281 Q_UNUSED(reason) |
|
282 // Notify the content widget about the change |
|
283 if(mDayViewWidget) { |
|
284 mDayViewWidget->handleLocaleChange(); |
|
285 } |
|
286 } |
|
287 |
|
288 // ---------------------------------------------------------------------------- |
|
289 // CCalenDayView::orientationChanged |
|
290 // Rest of the details are commented in the header |
|
291 // ---------------------------------------------------------------------------- |
|
292 // |
|
293 void CalenDayView::orientationChanged(Qt::Orientation orientation) |
|
294 { |
|
295 // Notify the content widget about the change |
|
296 if (mDayViewWidget) { |
|
297 mDayViewWidget->orientationChanged(orientation); |
|
298 } |
|
299 } |
|
300 |
|
301 // ---------------------------------------------------------------------------- |
|
302 // CCalenDayView::launchMonthView |
|
303 // ---------------------------------------------------------------------------- |
|
304 // |
|
305 void CalenDayView::launchMonthView() |
|
306 { |
|
307 // Issue the command to launch the month view |
|
308 mServices.IssueCommandL(ECalenMonthView); |
|
309 } |
|
310 |
|
311 // End of file --Don't remove this. |
|