1 /* |
1 /* |
2 * Copyright (c) 2002 Nokia Corporation and/or its subsidiary(-ies). |
2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). |
3 * All rights reserved. |
3 * All rights reserved. |
4 * This component and the accompanying materials are made available |
4 * This component and the accompanying materials are made available |
5 * under the terms of "Eclipse Public License v1.0" |
5 * under the terms of "Eclipse Public License v1.0" |
6 * which accompanies this distribution, and is available |
6 * which accompanies this distribution, and is available |
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
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: Grid of the MonthView. |
|
15 * |
8 * |
16 */ |
9 * Initial Contributors: |
17 |
10 * Nokia Corporation - initial contribution. |
18 |
11 * |
19 |
12 * Contributors: |
20 //debug |
13 * |
21 #include "calendarui_debug.h" |
14 * Description: Definition file for class CalenMonthGrid. |
22 |
15 * |
23 // INCLUDE FILES |
16 */ |
|
17 |
|
18 // System includes |
|
19 #include <qtimer.h> |
|
20 #include <hbmenu.h> |
|
21 #include <hbaction.h> |
|
22 #include <hbmainwindow.h> |
|
23 #include <hbgridview.h> |
|
24 #include <hbabstractviewitem.h> |
|
25 #include <hbcolorscheme.h> |
|
26 |
|
27 // User includes |
24 #include "calenmonthgrid.h" |
28 #include "calenmonthgrid.h" |
25 #include "calenmonthcontainer.h" |
29 #include "calengriditemprototype.h" |
26 #include "calenmonthcelllistboxdata.h" |
30 #include "calenmonthdata.h" |
27 #include "calenmonthcelllistboxitemdrawer.h" |
31 #include "calenmonthview.h" |
28 |
32 #include "calendateutils.h" |
29 #include <aknlayoutscalable_apps.cdl.h> |
33 #include "calencommon.h" |
30 |
34 |
31 // New line color groups in enhanced skinning |
35 // Constants |
32 static void DrawLAFLine(CWindowGc& aGc, const TAknLayoutRect& aArea, |
36 #define SCROLL_SPEEED 1000 |
33 const TAknsItemID& aSkinComponent, TInt aColorGroup) |
37 |
34 { |
38 /*! |
35 TRACE_ENTRY_POINT; |
39 \class CalenMonthGrid |
36 |
40 |
37 TRgb lineColor = aArea.Color(); |
41 Implements the month grid |
38 AknsUtils::GetCachedColor(AknsUtils::SkinInstance(), lineColor, |
42 */ |
39 aSkinComponent, aColorGroup); |
43 |
40 aGc.SetBrushColor( lineColor ); |
44 /*! |
41 aGc.SetBrushStyle( CGraphicsContext::ESolidBrush ); |
45 Default constructor. |
42 aGc.Clear( aArea.Rect() ); |
46 */ |
43 |
47 CalenMonthGrid::CalenMonthGrid(QGraphicsItem *parent): |
44 TRACE_EXIT_POINT; |
48 HbGridView(parent), |
45 } |
49 mModel(0), |
46 |
50 mDirection(invalid), |
47 static void DrawSecondaryLine(CWindowGc& aGc, const TAknLayoutRect& aArea) |
51 mIsPanGesture(false), |
48 { |
52 mIsAtomicScroll(true), |
49 TRACE_ENTRY_POINT; |
53 mView(NULL), |
50 |
54 mCurrentRow(0), |
51 DrawLAFLine(aGc, aArea, KAknsIIDQsnLineColors, EAknsCIQsnLineColorsCG2); |
55 mIsNonActiveDayFocused(false), |
52 |
56 mIgnoreItemActivated(false) |
53 TRACE_EXIT_POINT; |
57 { |
54 } |
58 setScrollDirections(Qt::Vertical); |
55 |
59 setRowCount(KNumOfVisibleRows); |
56 // ================= MEMBER FUNCTIONS ======================= |
60 setColumnCount(KCalenDaysInWeek); |
57 |
61 setLongPressEnabled(false); |
58 // C++ default constructor can NOT contain any code, that |
62 setItemRecycling(false); |
59 // might leave. |
63 setSelectionMode(HbGridView::NoSelection); |
60 // |
64 setUniformItemSizes(true); |
61 CCalenMonthGrid::CCalenMonthGrid |
65 setVerticalScrollBarPolicy(HbScrollArea::ScrollBarAlwaysOff); |
62 (TTime aFirstDayOfGrid, CCalenMonthContainer* aMonthCont) |
66 setClampingStyle(HbScrollArea::StrictClamping ); |
63 : iFirstDayOfGrid(aFirstDayOfGrid),iMonthContainer(aMonthCont) |
67 CalenGridItemPrototype *gridItemPrototype = new CalenGridItemPrototype(this); |
64 { |
68 setItemPrototype(gridItemPrototype); |
65 TRACE_ENTRY_POINT; |
69 mModel = new QStandardItemModel(14*KCalenDaysInWeek, 1, this); |
66 |
70 setModel(mModel); |
67 SetVerticalMargin(0); |
71 connect(this, SIGNAL(scrollingEnded()), this, |
68 SetHorizontalMargin(0); |
72 SLOT(scrollingFinished())); |
69 |
73 |
70 TRACE_EXIT_POINT; |
74 // Connect to item activated signal |
71 } |
75 connect(this, SIGNAL(activated(const QModelIndex &)), this, |
72 |
76 SLOT(itemActivated(const QModelIndex &))); |
73 // Destructor |
77 } |
74 CCalenMonthGrid::~CCalenMonthGrid() |
78 |
75 { |
79 /*! |
76 TRACE_ENTRY_POINT; |
80 Destructor |
77 TRACE_EXIT_POINT; |
81 */ |
78 } |
82 CalenMonthGrid::~CalenMonthGrid() |
79 |
83 { |
80 // --------------------------------------------------------- |
84 } |
81 // CCalenMonthGrid::Draw |
85 |
82 // Drawing month gird |
86 /*! |
83 // (other items were commented in a header). |
87 Stores the view pointer |
84 // --------------------------------------------------------- |
88 */ |
85 // |
89 void CalenMonthGrid::setView(CalenMonthView *view) |
86 void CCalenMonthGrid::Draw(const TRect& aRect)const |
90 { |
87 { |
91 mView = view; |
88 TRACE_ENTRY_POINT; |
92 } |
89 //const TBool useWeeks( UseWeeks() ); |
93 |
90 CAknGrid::Draw( aRect ); |
94 /*! |
91 |
95 Updates the model with the proper dates and sets the required user roles |
92 // For drawing Secondary grid lines |
96 */ |
93 DrawGridLines(); |
97 void CalenMonthGrid::updateMonthGridModel(QList<CalenMonthData> &monthDataArray, |
94 |
98 int indexToBeScrolled) |
95 TRACE_EXIT_POINT; |
99 { |
96 |
100 // Check the counts |
97 } |
101 int dataCount = monthDataArray.count(); |
98 |
102 int rowCount = mModel->rowCount(); |
99 // --------------------------------------------------------- |
103 int countDiff = dataCount - rowCount; |
100 // CCalenMonthGrid::DrawGridLines |
104 if (countDiff < 0) { |
101 // Draws secondary lines of the grid |
105 // Delete extra rows in the model |
102 // (other items were commented in a header). |
106 mModel->removeRows(dataCount,abs(countDiff)); |
103 // --------------------------------------------------------- |
107 } else if (countDiff > 0) { |
104 // |
108 // Add the necessary number of rows |
105 void CCalenMonthGrid::DrawGridLines()const |
109 mModel->insertRows(rowCount,countDiff); |
106 { |
110 } |
107 TRACE_ENTRY_POINT; |
111 QDateTime currDate = mView->getCurrentDay(); |
108 |
112 QDateTime activeDay = mView->getActiveDay(); |
109 CWindowGc& gc = SystemGc(); |
113 QModelIndex currentIndex; |
110 TRect parentRect = iMonthContainer->Rect(); |
114 for (int i = 0; i < dataCount; i++) { |
111 TRect main_pane(iMonthContainer->ReducePreview( parentRect ) ); |
115 QDateTime dateTime = monthDataArray[i].Day(); |
112 |
116 currentIndex = mModel->index(i, 0); |
113 |
117 HbExtendedLocale locale = HbExtendedLocale::system(); |
114 TAknLayoutRect main_cale_month_pane; |
118 // Get the localised string for the day |
115 TInt layoutVariant = iMonthContainer->LayoutVariantIndex(CCalenMonthContainer::EMainCaleMonthPane); |
119 QString date = locale.toString(dateTime.date().day()); |
116 main_cale_month_pane.LayoutRect( main_pane, AknLayoutScalable_Apps::main_cale_month_pane(layoutVariant).LayoutLine() ); |
120 mModel->itemFromIndex(currentIndex)->setData(date, |
117 |
121 CalendarNamespace::CalendarMonthDayRole); |
118 TAknLayoutRect cale_month_pane_g; |
122 |
119 |
123 // Check for active day |
120 // Get indexes for grid lines (cale_month_pane_g) |
124 if (CalenDateUtils::beginningOfDay(activeDay) |
121 TAknLayoutScalableTableLimits cale_month_pane_g_Limits = AknLayoutScalable_Apps::cale_month_pane_g_Limits(); |
125 == CalenDateUtils::beginningOfDay(dateTime)) { |
122 TInt index( cale_month_pane_g_Limits.FirstIndex() ); |
126 mCurrentRow = currentIndex.row(); |
123 TInt end( cale_month_pane_g_Limits.LastIndex() ); |
127 // Set the focus icon |
124 // First two are primary lines to separate heading and week number panes from grid |
128 mModel->itemFromIndex(currentIndex)->setData( |
125 // We draw them elsewhere |
129 QString("qtg_fr_cal_focused_day_ind"), |
126 const TInt firstGridLineIndex = 2; |
130 CalendarNamespace::CalendarMonthFocusRole); |
127 layoutVariant = iMonthContainer->LayoutVariantIndex(CCalenMonthContainer::ECaleMonthPaneG ); |
131 } else { |
128 for ( index+=firstGridLineIndex; index<=end; ++index ) |
132 // reset the highlight |
129 { |
133 mModel->itemFromIndex(currentIndex)->setData( |
130 cale_month_pane_g.LayoutRect( main_cale_month_pane.Rect(), |
134 QString(""), |
131 AknLayoutScalable_Apps::cale_month_pane_g( index, layoutVariant ).LayoutLine() ); |
135 CalendarNamespace::CalendarMonthFocusRole); |
132 DrawSecondaryLine( gc, cale_month_pane_g ); |
136 } |
133 } |
137 |
134 |
138 // Check for current day |
135 TRACE_EXIT_POINT; |
139 if (CalenDateUtils::beginningOfDay(currDate) |
136 |
140 == CalenDateUtils::beginningOfDay(dateTime)) { |
137 } |
141 // Set the underline icon |
138 |
142 mModel->itemFromIndex(currentIndex)->setData(true, |
139 |
143 CalendarNamespace::CalendarMonthUnderlineRole); |
140 // --------------------------------------------------------- |
144 } else { |
141 // CCalenMonthGrid::FirstDayOfGrid |
145 mModel->itemFromIndex(currentIndex)->setData(false, |
142 // Return first day of grid |
146 CalendarNamespace::CalendarMonthUnderlineRole); |
143 // (other items were commented in a header). |
147 } |
144 // --------------------------------------------------------- |
148 |
145 // |
149 // Reset the event indicator attribute |
146 TTime CCalenMonthGrid::FirstDayOfGrid() |
150 mModel->itemFromIndex(currentIndex)->setData(QString(""), |
147 { |
151 CalendarNamespace::CalendarMonthEventRole); |
148 TRACE_ENTRY_POINT; |
152 |
149 |
153 // Check for events |
150 TRACE_EXIT_POINT; |
154 if (monthDataArray[i].HasEvents()) { |
151 return iFirstDayOfGrid; |
155 // Set the underline icon |
152 } |
156 mModel->itemFromIndex(currentIndex)->setData(QString( |
153 |
157 "qtg_graf_cal_event_ind"), |
154 // --------------------------------------------------------- |
158 CalendarNamespace::CalendarMonthEventRole); |
155 // CCalenMonthGrid::SetFirstDayOfGrid |
159 } |
156 // Set argument aDay to first day of Grid |
160 // Check if this item falls on seventh column |
157 // (other items were commented in a header). |
161 if ((i % KCalenDaysInWeek) == 6) { |
158 // --------------------------------------------------------- |
162 // Set the seventh column role |
159 // |
163 mModel->itemFromIndex(currentIndex)->setData(true, |
160 void CCalenMonthGrid::SetFirstDayOfGrid(TTime aDay) |
164 CalendarNamespace::CalendarMonthSeventhColumn); |
161 { |
165 } |
162 TRACE_ENTRY_POINT; |
166 } |
163 |
167 mMonthDataArray = monthDataArray; |
164 iFirstDayOfGrid = aDay; |
168 |
165 |
169 // Get the active month |
166 TRACE_EXIT_POINT; |
170 QDateTime activeDate = mView->getActiveDay(); |
167 } |
171 // Set the text color properly |
168 |
172 setActiveDates(activeDate); |
169 // --------------------------------------------------------- |
173 |
170 // CCalenMonthGrid::CreateItemDrawerL |
174 // Reset the view and update it again |
171 // Creates CFormattedCellListBoxItemDrawer, |
175 reset(); |
172 // actually CCalenMonthCellListBoxItemDrawer. |
176 update(); |
173 // (other items were commented in a header). |
177 |
174 // --------------------------------------------------------- |
178 // Calculate the last visible item in the grid |
175 // |
179 QModelIndex index = mModel->index(indexToBeScrolled, 0); |
176 void CCalenMonthGrid::CreateItemDrawerL() |
180 scrollTo(index); |
177 { |
181 } |
178 TRACE_ENTRY_POINT; |
182 |
179 |
183 /*! |
180 CCalenMonthCellListBoxData* columnData = CCalenMonthCellListBoxData::NewL(); |
184 Listens for down gesture |
181 CleanupStack::PushL( columnData ); |
185 */ |
182 |
186 void CalenMonthGrid::downGesture (int value) |
183 iItemDrawer = new(ELeave) |
187 { |
184 CCalenMonthCellListBoxItemDrawer(Model(), this, iEikonEnv->NormalFont(), columnData); |
188 Q_UNUSED(value) |
185 |
189 mDirection = down; |
186 CleanupStack::Pop(); // columnData |
190 HbScrollArea::downGesture(SCROLL_SPEEED); |
187 |
191 } |
188 TRACE_EXIT_POINT; |
192 |
189 } |
193 /*! |
190 |
194 Listens for Up gesture |
191 // --------------------------------------------------------- |
195 */ |
192 // |
196 void CalenMonthGrid::upGesture (int value) |
193 // --------------------------------------------------------- |
197 { |
194 // |
198 Q_UNUSED(value) |
195 void CCalenMonthGrid::UpdateScrollBarsL() |
199 mDirection = up; |
196 { |
200 HbScrollArea::upGesture(SCROLL_SPEEED); |
197 TRACE_ENTRY_POINT; |
201 } |
198 |
202 |
199 // Override default implementation and just turn scrollbars off |
203 /*! |
200 // This is needed, because CAknGrid doesn't respect scrollbar |
204 Function to listen mouse press events |
201 // visibility settings, but turns them on e.g. in HandleResourceChange |
205 */ |
202 CEikScrollBarFrame* sbf = ScrollBarFrame(); |
206 void CalenMonthGrid::mousePressEvent(QGraphicsSceneMouseEvent* event) |
203 if ( sbf ) |
207 { |
204 { |
208 mPressedPos = event->pos(); |
205 sbf->SetScrollBarVisibilityL(CEikScrollBarFrame::EOff, |
209 // Pass it to parent |
206 CEikScrollBarFrame::EOff); |
210 HbGridView::mousePressEvent(event); |
207 } |
211 } |
208 |
212 |
209 TRACE_EXIT_POINT; |
213 /*! |
210 } |
214 Function to listen mouse release events |
|
215 */ |
|
216 void CalenMonthGrid::mouseReleaseEvent(QGraphicsSceneMouseEvent* event) |
|
217 { |
|
218 int posDiff = mPressedPos.y() - event->pos().y(); |
|
219 if (posDiff < -50) { |
|
220 mDirection = down; |
|
221 } else if (posDiff > 50){ |
|
222 mDirection = up; |
|
223 } |
|
224 // Pass it to parent |
|
225 HbGridView::mouseReleaseEvent(event); |
|
226 } |
|
227 |
|
228 /*! |
|
229 Listens for pan gesture |
|
230 */ |
|
231 void CalenMonthGrid::panGesture(const QPointF & delta) |
|
232 { |
|
233 if (!mIsPanGesture) { |
|
234 mIsPanGesture = true; |
|
235 mIgnoreItemActivated = true; |
|
236 |
|
237 // Get to know the direction of the gesture |
|
238 if (delta.y() > 0) { |
|
239 mDirection = down; |
|
240 } else { |
|
241 mDirection = up; |
|
242 } |
|
243 } else { // This case is when user changes the direction while panning |
|
244 // without lifting the finger |
|
245 // Check if direction has changed |
|
246 if (((delta.y() > 0) && (mDirection == up)) |
|
247 || ((delta.y() < 0) && (mDirection == down))) { |
|
248 // Direction has changed, ignore this pan |
|
249 return; |
|
250 } |
|
251 } |
|
252 // Call the parent class to perform the pan gesture |
|
253 // When scrolling finished, month grid will adjust to show the proper month |
|
254 HbScrollArea::panGesture(delta); |
|
255 } |
|
256 |
|
257 /*! |
|
258 Gets called when scrolling finishes to update the model |
|
259 */ |
|
260 void CalenMonthGrid::scrollingFinished() |
|
261 { |
|
262 |
|
263 if (mIsPanGesture) { |
|
264 mIsPanGesture = false; |
|
265 if (mDirection == up) { |
|
266 // Make a request for upgesture |
|
267 upGesture(SCROLL_SPEEED); |
|
268 return; // return immediately |
|
269 } else if (mDirection == down) { |
|
270 // Make a request for upgesture |
|
271 downGesture(SCROLL_SPEEED); |
|
272 return; // return immediately |
|
273 } |
|
274 } else if(!mIsAtomicScroll) { |
|
275 if (mDirection == down) { |
|
276 // Before we start scrolling, setthe active text color to previous month |
|
277 QDateTime activeDate = mView->getActiveDay(); |
|
278 if (!mIsNonActiveDayFocused) { |
|
279 activeDate = activeDate.addMonths(-1); |
|
280 } |
|
281 setActiveDates(activeDate); |
|
282 } else if (mDirection == up) { |
|
283 // Before we start scrolling, setthe active text color to previous month |
|
284 QDateTime activeDate = mView->getActiveDay(); |
|
285 if (!mIsNonActiveDayFocused) { |
|
286 activeDate = activeDate.addMonths(1); |
|
287 } |
|
288 setActiveDates(activeDate); |
|
289 } |
|
290 // Before we do anything, set the focus to proper date |
|
291 // Set it only when non active day was focussed. When inactive day |
|
292 // was focussed, we need to focus the same day |
|
293 if (!mIsNonActiveDayFocused) { |
|
294 setFocusToProperDay(); |
|
295 } |
|
296 // To improve the performance, lets start the timer for 10 ms, |
|
297 // return immediately and do the other things after that |
|
298 QTimer::singleShot(10, this, SLOT(timerExpired())); |
|
299 } else { |
|
300 mIsAtomicScroll = false; |
|
301 } |
|
302 mIgnoreItemActivated = false; |
|
303 } |
|
304 |
|
305 void CalenMonthGrid::timerExpired() |
|
306 { |
|
307 if(mDirection == down) { // down gesture |
|
308 prependRows(); |
|
309 } else if (mDirection == up) { //up gesture |
|
310 appendRows(); |
|
311 } |
|
312 mDirection = invalid; |
|
313 } |
|
314 |
|
315 /*! |
|
316 Called when down gesture is performed. Adds the new previous month details |
|
317 to the model |
|
318 */ |
|
319 void CalenMonthGrid::prependRows() |
|
320 { |
|
321 mIsNonActiveDayFocused = false; |
|
322 QDateTime currDate = mView->getCurrentDay(); |
|
323 int rowsInFutMonthEarlier = mView->rowsInFutMonth(); |
|
324 int rowsInPrevMonthEarlier = mView->rowsInPrevMonth(); |
|
325 |
|
326 // Get the updated dates from the view |
|
327 mView->updateModelWithPrevMonth(); |
|
328 QList<CalenMonthData > monthDataList = mView->monthDataList(); |
|
329 mMonthDataArray = monthDataList; |
|
330 int listCount = monthDataList.count(); |
|
331 // Get the updated rows to be inserted |
|
332 int rowsInPrevMonth = mView->rowsInPrevMonth(); |
|
333 int rowsInFutMonth = mView->rowsInFutMonth(); |
|
334 |
|
335 // remove the cells in the future month |
|
336 int deleteFromIndex = (rowsInPrevMonthEarlier + KNumOfVisibleRows) * KCalenDaysInWeek; |
|
337 int numOfIndices = rowsInFutMonthEarlier * KCalenDaysInWeek; |
|
338 int count = mModel->rowCount(); |
|
339 |
|
340 count = mModel->rowCount(); |
|
341 |
|
342 // Add the new days |
|
343 int countToBeAdded = rowsInPrevMonth * KCalenDaysInWeek; |
|
344 mModel->insertRows(0, countToBeAdded); |
|
345 count = mModel->rowCount(); |
|
346 for (int i = 0; i < countToBeAdded; i++) { |
|
347 QDateTime dateTime = monthDataList[i].Day(); |
|
348 int date = dateTime.date().day(); |
|
349 QModelIndex currentIndex = mModel->index(i, 0); |
|
350 mModel->itemFromIndex(currentIndex)->setData(date, |
|
351 CalendarNamespace::CalendarMonthDayRole); |
|
352 // Check for current date |
|
353 if (CalenDateUtils::beginningOfDay( currDate ) == |
|
354 CalenDateUtils::beginningOfDay( dateTime )) { |
|
355 // Set the underline icon |
|
356 mModel->setData(mModel->index(i, 0), true, |
|
357 CalendarNamespace::CalendarMonthUnderlineRole); |
|
358 } |
|
359 if (monthDataList[i].HasEvents()) { |
|
360 // Set the underline icon |
|
361 mModel->setData(mModel->index(i, 0), |
|
362 QString("qtg_graf_cal_event_ind"), |
|
363 CalendarNamespace::CalendarMonthEventRole); |
|
364 } |
|
365 |
|
366 // Check if this item falls on seventh column |
|
367 if ((i%KCalenDaysInWeek) == 6) { |
|
368 // Set the seventh column role |
|
369 mModel->setData(mModel->index(i, 0), true, |
|
370 CalendarNamespace::CalendarMonthSeventhColumn); |
|
371 } |
|
372 } |
|
373 |
|
374 // Update the mCurrentRow |
|
375 mCurrentRow += countToBeAdded; |
|
376 // Scroll to proper index |
|
377 int itemToBeScrolled = ((rowsInPrevMonth + KNumOfVisibleRows) * |
|
378 KCalenDaysInWeek) - 1; |
|
379 QModelIndex indexToBeScrolled = mModel->index(itemToBeScrolled, 0); |
|
380 QMap<int, QVariant> data; |
|
381 data = mModel->itemData(indexToBeScrolled); |
|
382 QVariant value = data.value(Qt::DisplayRole); |
|
383 int date = value.toInt(); |
|
384 mIsAtomicScroll = true; |
|
385 scrollTo(indexToBeScrolled); |
|
386 |
|
387 // Now remove the necessary items frm the model |
|
388 mModel->removeRows(deleteFromIndex+countToBeAdded, numOfIndices); |
|
389 mIsAtomicScroll = true; |
|
390 itemToBeScrolled = rowsInPrevMonth * KCalenDaysInWeek; |
|
391 indexToBeScrolled = mModel->index(itemToBeScrolled, 0); |
|
392 scrollTo(indexToBeScrolled); |
|
393 } |
|
394 |
|
395 /*! |
|
396 Called when Up gwsture is performed. Adds the new future month details |
|
397 to the model |
|
398 */ |
|
399 void CalenMonthGrid::appendRows() |
|
400 { |
|
401 mIsNonActiveDayFocused = false; |
|
402 QDateTime currDate = mView->getCurrentDay(); |
|
403 int rowsInFutMonth = mView->rowsInFutMonth(); |
|
404 int rowsInPrevMonth = mView->rowsInPrevMonth(); |
|
405 // remove the cells in the previous month |
|
406 int countToBeDeleted = rowsInPrevMonth * KCalenDaysInWeek; |
|
407 |
|
408 // Get the updated dates from the view |
|
409 mView->updateModelWithFutureMonth(); |
|
410 QList<CalenMonthData > monthDataList = mView->monthDataList(); |
|
411 mMonthDataArray = monthDataList; |
|
412 // Get the updated rows to be inserted |
|
413 rowsInPrevMonth = mView->rowsInPrevMonth(); |
|
414 rowsInFutMonth = mView->rowsInFutMonth(); |
|
415 int countToBeAdded = rowsInFutMonth * KCalenDaysInWeek; |
|
416 int lastVisibleIndex = monthDataList.count() - countToBeAdded; |
|
417 int rowCount = mModel->rowCount(); |
|
418 mModel->insertRows(rowCount, countToBeAdded); |
|
419 for (int i = 0; i < countToBeAdded; i++) { |
|
420 QMap<int, QVariant> data; |
|
421 QModelIndex currentIndex = mModel->index(i, 0); |
|
422 |
|
423 QDateTime dateTime = monthDataList[lastVisibleIndex + i].Day(); |
|
424 int date = dateTime.date().day(); |
|
425 data.insert(CalendarNamespace::CalendarMonthDayRole, date); |
|
426 mModel->setItemData(mModel->index(rowCount + i, 0), data); |
|
427 // Check for active day |
|
428 if (CalenDateUtils::beginningOfDay( currDate ) == |
|
429 CalenDateUtils::beginningOfDay( dateTime )) { |
|
430 // Set the underline icon |
|
431 mModel->setData(mModel->index(rowCount + i, 0),true, |
|
432 CalendarNamespace::CalendarMonthUnderlineRole); |
|
433 } |
|
434 |
|
435 // Update the event indicators |
|
436 if (monthDataList[lastVisibleIndex + i].HasEvents()) { |
|
437 // Set the underline icon |
|
438 mModel->setData(mModel->index(rowCount + i, 0), |
|
439 QString("qtg_graf_cal_event_ind"), |
|
440 CalendarNamespace::CalendarMonthEventRole); |
|
441 } |
|
442 |
|
443 if ((i%KCalenDaysInWeek) == 6) { |
|
444 // Set the seventh column role |
|
445 mModel->setData(mModel->index(rowCount + i, 0), true, |
|
446 CalendarNamespace::CalendarMonthSeventhColumn); |
|
447 } |
|
448 } |
|
449 |
|
450 // Update the mCurrentRow |
|
451 mCurrentRow -= (countToBeDeleted); |
|
452 |
|
453 mIsAtomicScroll = true; |
|
454 for (int i = 0; i < countToBeDeleted; i++) { |
|
455 mModel->removeRow(0); |
|
456 } |
|
457 // Calculate the proper index to be scrolled to |
|
458 int itemToBeScrolled = rowsInPrevMonth * KCalenDaysInWeek; |
|
459 QModelIndex indexToBeScrolled = mModel->index(itemToBeScrolled, 0); |
|
460 scrollTo(indexToBeScrolled); |
|
461 } |
|
462 |
|
463 /*! |
|
464 Slot to handle when a particular grid item is tapped |
|
465 */ |
|
466 void CalenMonthGrid::itemActivated(const QModelIndex &index) |
|
467 { |
|
468 if (mIgnoreItemActivated) { |
|
469 mIgnoreItemActivated = false; |
|
470 return; |
|
471 } |
|
472 mIsNonActiveDayFocused = false; |
|
473 // Check if the same item has been tapped twice |
|
474 if (mCurrentRow == index.row()) { |
|
475 // Launch the agenda view |
|
476 mView->launchDayView(); |
|
477 } else { |
|
478 // Reset the focus attribute to this item |
|
479 mModel->setData(mModel->index(mCurrentRow,0), QString(""), |
|
480 CalendarNamespace::CalendarMonthFocusRole); |
|
481 |
|
482 // Inform view to update the context and preview panes |
|
483 mCurrentRow = index.row(); |
|
484 mModel->setData(mModel->index(mCurrentRow,0), |
|
485 QString("qtg_fr_cal_focused_day_ind"), |
|
486 CalendarNamespace::CalendarMonthFocusRole); |
|
487 // Check if inactive date is tapped |
|
488 QList<CalenMonthData> list = mView->monthDataList(); |
|
489 if(!list[mCurrentRow].isActive()){ |
|
490 // Set the flag |
|
491 mIsNonActiveDayFocused = true; |
|
492 mNonActiveFocusedDay = list[mCurrentRow].Day(); |
|
493 |
|
494 // Get the current active month |
|
495 QDateTime activeMonth = mView->getActiveDay(); |
|
496 // Add one month to it |
|
497 activeMonth = activeMonth.addMonths(1); |
|
498 if (activeMonth.date().month() == |
|
499 mNonActiveFocusedDay.date().month()) { |
|
500 // up gesture |
|
501 upGesture(SCROLL_SPEEED); |
|
502 } else { |
|
503 // down gesture |
|
504 downGesture(SCROLL_SPEEED); |
|
505 } |
|
506 } |
|
507 mView->setContextForActiveDay(index.row()); |
|
508 } |
|
509 } |
|
510 |
|
511 /*! |
|
512 Sets the focus to proper day after the flick scrollng |
|
513 */ |
|
514 void CalenMonthGrid::setFocusToProperDay() |
|
515 { |
|
516 // Calculate the new item to be focussed |
|
517 QDateTime oldFocussedDate = mView->getActiveDay(); |
|
518 QList<CalenMonthData> monthDataList = mView->monthDataList(); |
|
519 int listCount = monthDataList.count(); |
|
520 int rowsInPrevMonth = mView->rowsInPrevMonth(); |
|
521 QDateTime dateToBeFocussed; |
|
522 int indexStart = 0; |
|
523 int indexEnd = listCount - 1; |
|
524 if (mDirection == up) { |
|
525 dateToBeFocussed = oldFocussedDate.addMonths(1); // add the month |
|
526 indexStart = (rowsInPrevMonth + 4) * KCalenDaysInWeek; |
|
527 } else if (mDirection == down) { |
|
528 dateToBeFocussed = oldFocussedDate.addMonths(-1); // substract the month |
|
529 indexEnd = (rowsInPrevMonth + 1) * KCalenDaysInWeek; |
|
530 } |
|
531 // Reset the focus attribute to earlier current item |
|
532 mModel->setData(mModel->index(mCurrentRow,0), QString(""), |
|
533 CalendarNamespace::CalendarMonthFocusRole); |
|
534 // Search for this date in the model |
|
535 for (int i = indexStart; i <= indexEnd; i++) { |
|
536 if (monthDataList[i].Day().date() == dateToBeFocussed.date()) { |
|
537 mModel->setData(mModel->index(i,0), |
|
538 QString("qtg_fr_cal_focused_day_ind"), |
|
539 CalendarNamespace::CalendarMonthFocusRole); |
|
540 mCurrentRow = i; |
|
541 mView->setContextForActiveDay(i); |
|
542 break; |
|
543 } |
|
544 } |
|
545 } |
|
546 |
|
547 /*! |
|
548 Sets the appropriate text colot depending upon the active dates |
|
549 */ |
|
550 void CalenMonthGrid::setActiveDates(QDateTime activeDate) |
|
551 { |
|
552 int month = activeDate.date().month(); |
|
553 for (int i = 0; i < mMonthDataArray.count(); i++) { |
|
554 QColor textColor; |
|
555 if (month == mMonthDataArray[i].Day().date().month()) { |
|
556 // Set the active text color |
|
557 textColor = HbColorScheme::color("qtc_cal_month_active_dates"); |
|
558 } else { |
|
559 // Set the inactive text color |
|
560 textColor = HbColorScheme::color("qtc_cal_month_notactive_dates"); |
|
561 } |
|
562 if (textColor.isValid()) { |
|
563 mModel->setData(mModel->index(i,0), textColor, |
|
564 CalendarNamespace::CalendarMonthTextColorRole); |
|
565 } |
|
566 } |
|
567 } |
|
568 |
|
569 /*! |
|
570 To get current foucsed index of monthGrid |
|
571 */ |
|
572 int CalenMonthGrid::getCurrentIndex() |
|
573 { |
|
574 return mCurrentRow; |
|
575 } |
|
576 |
|
577 /*! |
|
578 To set the focus to Index |
|
579 */ |
|
580 void CalenMonthGrid::setCurrentIdex(int index) |
|
581 { |
|
582 itemActivated(mModel->index(index, 0)); |
|
583 } |
|
584 |
|
585 /*! |
|
586 Function to override the default behavior of hbgridview on orientation change |
|
587 */ |
|
588 void CalenMonthGrid::orientationChanged(Qt::Orientation newOrientation) |
|
589 { |
|
590 Q_UNUSED(newOrientation) |
|
591 // We are overriding this function to avoid the default behavior of |
|
592 // hbgridview on orientation change as it swaps the row and column counts |
|
593 } |
211 // End of File |
594 // End of File |