|
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: CalenPreviewPane implementation. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // System includes |
|
20 #include <QtGui> |
|
21 #include <qfont.h> |
|
22 #include <qicon.h> |
|
23 #include <qpainter.h> |
|
24 #include <hblabel.h> |
|
25 #include <hbmainwindow.h> |
|
26 #include <hbframeitem.h> |
|
27 #include <hbframedrawer.h> |
|
28 #include <hbfontspec.h> |
|
29 #include <hbcolorscheme.h> |
|
30 #include <agendautil.h> |
|
31 #include <agendaentry.h> |
|
32 |
|
33 //user includes |
|
34 #include "calenagendautils.h" |
|
35 #include "calendateutils.h" |
|
36 #include "calencontext.h" |
|
37 #include "calenservices.h" |
|
38 #include "calenservices.h" |
|
39 #include "calencommon.h" |
|
40 #include "calenpreviewpane.h" |
|
41 #include "calenmonthview.h" |
|
42 |
|
43 // Macros |
|
44 #define TWO_SECONDS_TIMER 2000 // millseconds |
|
45 #define SCROLLING_SPEED 50 |
|
46 |
|
47 static const QString EMPTYSTRING(" "); |
|
48 |
|
49 /*! |
|
50 Constructor |
|
51 */ |
|
52 CalenPreviewPane::CalenPreviewPane(MCalenServices& services, |
|
53 QGraphicsItem* parent) |
|
54 : HbScrollArea(parent),mServices(services) |
|
55 { |
|
56 // Create the timer |
|
57 mTwoSecTimer = new QTimer(this); |
|
58 mScrollDirection = invalid; |
|
59 mIsNoEntriesAdded = true; |
|
60 mNoEntriesLabel = 0; |
|
61 setAcceptDrops(true); |
|
62 setScrollDirections(Qt::Vertical); |
|
63 setVerticalScrollBarPolicy(HbScrollArea::ScrollBarAlwaysOff); |
|
64 // Set the frame to the preview pane |
|
65 HbFrameItem* frame = new HbFrameItem(this); |
|
66 frame->frameDrawer().setFrameType(HbFrameDrawer::NinePieces); |
|
67 |
|
68 frame->frameDrawer().setFrameGraphicsName("qtg_fr_cal_preview_bg"); |
|
69 setBackgroundItem(frame->graphicsItem(), -5); |
|
70 |
|
71 // Connect the scrollig finished signal |
|
72 connect(this, SIGNAL(scrollingEnded()), this, |
|
73 SLOT(scrollingFinished())); |
|
74 } |
|
75 |
|
76 /*! |
|
77 Destructor |
|
78 */ |
|
79 CalenPreviewPane::~CalenPreviewPane() |
|
80 { |
|
81 } |
|
82 |
|
83 /*! |
|
84 Stores the "No Entries for today" label |
|
85 */ |
|
86 void CalenPreviewPane::setNoEntriesLabel(HbLabel* label) |
|
87 { |
|
88 mNoEntriesLabel = label; |
|
89 } |
|
90 |
|
91 /*! |
|
92 Populates the preview with proper data |
|
93 */ |
|
94 void CalenPreviewPane::populateLabel(QDateTime date) |
|
95 { |
|
96 mScrollDirection = up; |
|
97 |
|
98 // Scroll contents to zero position before we display to the user |
|
99 // if it was scrolling already or timer was running |
|
100 mNumOfScrolls = 0; |
|
101 stopScrolling(); |
|
102 |
|
103 mDate = date; |
|
104 |
|
105 // Get Instances for the day |
|
106 GetInstanceListL(); |
|
107 |
|
108 // Get the content of the scroll area |
|
109 QGraphicsWidget* content = this->contentWidget(); |
|
110 // Adjust the layout |
|
111 QGraphicsLinearLayout* layout = static_cast<QGraphicsLinearLayout *> |
|
112 (content->layout()); |
|
113 |
|
114 layout->setPreferredWidth(preferredWidth()); |
|
115 layout->setMinimumWidth(minimumWidth()); |
|
116 layout->setMaximumWidth(maximumWidth()); |
|
117 |
|
118 int instanceCount = mInstanceArray.count(); |
|
119 HbFontSpec font(HbFontSpec::Secondary); |
|
120 if (mIsNoEntriesAdded) { |
|
121 if (!instanceCount) { |
|
122 return; |
|
123 } else { |
|
124 // Remove the no entries label |
|
125 layout->removeAt(0); |
|
126 mNoEntriesLabel->setVisible(false); |
|
127 } |
|
128 } |
|
129 int count = layout->count(); |
|
130 int labelCount = mLabelList.count(); |
|
131 for (int i = 0; i < labelCount; i++) { |
|
132 mLabelList.at(i)->clear(); |
|
133 } |
|
134 if (instanceCount) { |
|
135 mIsNoEntriesAdded = false; |
|
136 // Parse the instances and add them to the layout |
|
137 for (int i = 0; i <instanceCount; i++) { |
|
138 HbLabel* label; |
|
139 if(!count) { |
|
140 label = new HbLabel(this); |
|
141 |
|
142 // Set the required font |
|
143 label->setFontSpec(font); |
|
144 |
|
145 // Set the text color from the theme |
|
146 QColor previewPaneColor = HbColorScheme::color( |
|
147 "qtc_cal_day_preview_text"); |
|
148 if (previewPaneColor.isValid()) { |
|
149 label->setTextColor(previewPaneColor); |
|
150 } |
|
151 |
|
152 // Set the elide mode to right |
|
153 label->setElideMode(Qt::ElideRight); |
|
154 // Add the label to the list |
|
155 mLabelList.append(label); |
|
156 layout->addItem(label); |
|
157 } else { |
|
158 // Reuse the same label |
|
159 label = mLabelList.at(i); |
|
160 count--; |
|
161 } |
|
162 QString summary = mInstanceArray[i].summary(); |
|
163 if(!summary.length()) { |
|
164 // No summary display "No subject" |
|
165 summary.append(hbTrId("txt_calendar_dblist_unnamed")); |
|
166 } |
|
167 QDateTime startTime = mInstanceArray[i].startTime(); |
|
168 HbExtendedLocale systemLocale =HbExtendedLocale::system(); |
|
169 QString start = systemLocale.format(startTime.time(), |
|
170 r_qtn_time_usual_with_zero); |
|
171 start.append(EMPTYSTRING); |
|
172 // Append summary to start time |
|
173 QString text = start.append(summary); |
|
174 label->setPlainText(text); |
|
175 layout->setStretchFactor(label,0); |
|
176 } |
|
177 |
|
178 // Cleanup the remaining labels |
|
179 if (count) { |
|
180 int layoutCount = layout->count(); |
|
181 int offset = layoutCount - count; |
|
182 int labelCount = mLabelList.count(); |
|
183 for (int i = 0; i < count; i++) { |
|
184 QGraphicsLayoutItem* item = layout->itemAt(offset); |
|
185 layout->removeAt(offset); |
|
186 int index = --labelCount; |
|
187 mLabelList.removeAt(index); |
|
188 if (item) { |
|
189 delete item; |
|
190 } |
|
191 } |
|
192 } |
|
193 } else { // Delete all the items in the layout |
|
194 // TODO: Need to see if we can clear all the items at one shot |
|
195 // remove the items if any |
|
196 for (int i = 0; i < count; i++) { |
|
197 QGraphicsLayoutItem* item = layout->itemAt(0); |
|
198 layout->removeAt(0); |
|
199 // Clear the label text |
|
200 mLabelList.at(i)->clear(); |
|
201 if (item) { |
|
202 delete item; |
|
203 } |
|
204 } |
|
205 // Clear the list |
|
206 mLabelList.clear(); |
|
207 |
|
208 // Add the no entries text to the preview pane |
|
209 mNoEntriesLabel->setVisible(true); |
|
210 layout->addItem(mNoEntriesLabel); |
|
211 layout->setStretchFactor(mNoEntriesLabel,1); |
|
212 mIsNoEntriesAdded = true; |
|
213 } |
|
214 layout->activate(); |
|
215 } |
|
216 |
|
217 /*! |
|
218 Fetches the instance for a given day |
|
219 */ |
|
220 void CalenPreviewPane::GetInstanceListL() |
|
221 { |
|
222 mInstanceArray.clear(); |
|
223 |
|
224 // Find Meetings, Remainders, Anniversaries and Day Notes |
|
225 QDateTime dayStart( CalenDateUtils::beginningOfDay( mDate ) ); |
|
226 |
|
227 // Make a request to get all the entries for the mDate |
|
228 AgendaUtil::FilterFlags filter = AgendaUtil::FilterFlags( |
|
229 AgendaUtil::IncludeAnniversaries | |
|
230 AgendaUtil::IncludeAppointments | |
|
231 AgendaUtil::IncludeEvents | |
|
232 AgendaUtil::IncludeIncompletedTodos | |
|
233 AgendaUtil::IncludeReminders); |
|
234 mInstanceArray = mServices.agendaInterface()-> |
|
235 createEntryIdListForDay(dayStart, filter); |
|
236 } |
|
237 |
|
238 /*! |
|
239 Returns the date which this preview pane is representing |
|
240 */ |
|
241 QDateTime CalenPreviewPane::Date() |
|
242 { |
|
243 return mDate; |
|
244 } |
|
245 |
|
246 /*! |
|
247 Starts the auto scroll on the preview pane |
|
248 */ |
|
249 void CalenPreviewPane::startAutoScroll() |
|
250 { |
|
251 if (mIsNoEntriesAdded) { |
|
252 scrollContentsTo(QPointF(0.0,0.0)); |
|
253 |
|
254 // Call pan gesture with zero delta just to stop the scfrolling |
|
255 HbScrollArea::panGesture(QPointF(0.0,0.0)); |
|
256 return; |
|
257 } |
|
258 |
|
259 // Start the 2 seconds timer |
|
260 mTwoSecTimer->setSingleShot(true); |
|
261 connect(mTwoSecTimer, SIGNAL(timeout()), this, SLOT(onTwoSecondsTimeout())); |
|
262 mTwoSecTimer->start(TWO_SECONDS_TIMER); |
|
263 } |
|
264 |
|
265 /*! |
|
266 Slot to handle two seconds timer time out |
|
267 Starts the scrolling animation in required direction |
|
268 */ |
|
269 void CalenPreviewPane::onTwoSecondsTimeout() |
|
270 { |
|
271 mTwoSecTimer->stop(); |
|
272 disconnect(mTwoSecTimer, SIGNAL(timeout()), |
|
273 this, SLOT(onTwoSecondsTimeout())); |
|
274 // Start the scrolling in the proper direction |
|
275 if (mScrollDirection == up) { |
|
276 // Start scrolling upwards |
|
277 mScrollDirection = down; |
|
278 mNumOfScrolls++; |
|
279 upGesture(SCROLLING_SPEED); |
|
280 } else if (mScrollDirection == down) { |
|
281 mScrollDirection = up; |
|
282 mNumOfScrolls++; |
|
283 // Start scrolling downwards |
|
284 downGesture(SCROLLING_SPEED); |
|
285 } |
|
286 } |
|
287 |
|
288 /*! |
|
289 Slot to handle scrolling finished |
|
290 Restarts the two seconds timer |
|
291 */ |
|
292 void CalenPreviewPane::scrollingFinished() |
|
293 { |
|
294 // If we are here because of calling scrollContentsTo() |
|
295 if (!mNumOfScrolls) { |
|
296 return; |
|
297 } |
|
298 // Now start the two seconds timer again |
|
299 mTwoSecTimer->setSingleShot(true); |
|
300 connect(mTwoSecTimer, SIGNAL(timeout()), this, SLOT(onTwoSecondsTimeout())); |
|
301 mTwoSecTimer->start(TWO_SECONDS_TIMER); |
|
302 } |
|
303 |
|
304 /*! |
|
305 Function to listen mouse press events |
|
306 */ |
|
307 void CalenPreviewPane::mousePressEvent(QGraphicsSceneMouseEvent* event) |
|
308 { |
|
309 mPressedPos = event->pos(); |
|
310 } |
|
311 |
|
312 /*! |
|
313 Function to listen mouse release events |
|
314 */ |
|
315 void CalenPreviewPane::mouseReleaseEvent(QGraphicsSceneMouseEvent* event) |
|
316 { |
|
317 qreal posDiff = mPressedPos.x()-event->pos().x(); |
|
318 if (abs(posDiff) < 50) { |
|
319 // Preview pane tapped |
|
320 mServices.IssueCommandL(ECalenDayView); |
|
321 } else if (posDiff < -50) { |
|
322 // right gesture |
|
323 mView->handlePreviewPaneGesture(true); |
|
324 } else if (posDiff > 50) { |
|
325 // left gesture |
|
326 mView->handlePreviewPaneGesture(false); |
|
327 } |
|
328 } |
|
329 |
|
330 /*! |
|
331 Set monthview pointer |
|
332 */ |
|
333 void CalenPreviewPane::setView(CalenMonthView* view) |
|
334 { |
|
335 mView = view; |
|
336 } |
|
337 |
|
338 /*! |
|
339 Stops the auto scrolling |
|
340 */ |
|
341 void CalenPreviewPane::stopScrolling() |
|
342 { |
|
343 if (isScrolling() || mTwoSecTimer->isActive()) { |
|
344 scrollContentsTo(QPointF(0.0,0.0)); |
|
345 |
|
346 // Call pan gesture with zero delta just to stop the scfrolling |
|
347 HbScrollArea::panGesture(QPointF(0.0,0.0)); |
|
348 mTwoSecTimer->stop(); |
|
349 } |
|
350 } |
|
351 |
|
352 // End of file --Don't remove this. |