|
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: ?Description |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 //Includes |
|
21 #include <QDebug> |
|
22 #include <hbmenu.h> |
|
23 #include <hbaction.h> |
|
24 #include <hbtoolbar.h> |
|
25 #include <hbgridview.h> |
|
26 #include <hbmainwindow.h> |
|
27 #include <shareuidialog.h> |
|
28 #include <hbdocumentloader.h> |
|
29 #include <QAbstractItemModel> |
|
30 #include <hbabstractviewitem.h> |
|
31 #include <xqserviceutil.h> |
|
32 |
|
33 //User Includes |
|
34 #include "glxuistd.h" |
|
35 #include "glxviewids.h" |
|
36 #include "glxgridview.h" |
|
37 #include "glxmodelparm.h" |
|
38 #include "glxloggerenabler.h" |
|
39 #include "glxdocloaderdefs.h" |
|
40 #include "glxcommandhandlers.hrh" |
|
41 #include "OstTraceDefinitions.h" |
|
42 #ifdef OST_TRACE_COMPILER_IN_USE |
|
43 #include "glxgridviewTraces.h" |
|
44 #endif |
|
45 |
|
46 GlxGridView::GlxGridView(HbMainWindow *window) : GlxView ( GLX_GRIDVIEW_ID ), |
|
47 mGridView(NULL), mView(NULL), mWindow(window), mModel ( NULL), mVisualIndex(0), |
|
48 mItem(NULL) |
|
49 { |
|
50 OstTraceFunctionEntry0( GLXGRIDVIEW_GLXGRIDVIEW_ENTRY ); |
|
51 mDocLoader = new HbDocumentLoader(); |
|
52 OstTraceFunctionExit0( GLXGRIDVIEW_GLXGRIDVIEW_EXIT ); |
|
53 setContentFullScreen( true ); |
|
54 } |
|
55 |
|
56 void GlxGridView::activate() |
|
57 { |
|
58 OstTraceFunctionEntry0( GLXGRIDVIEW_ACTIVATE_ENTRY ); |
|
59 |
|
60 loadGridView(mWindow->orientation()); |
|
61 addViewConnection(); |
|
62 // mVisualIndex = 0; //To:Do remove later once we get visual index change notification from grid view |
|
63 |
|
64 |
|
65 |
|
66 mGridView->resetTransform(); //to reset the transition effect (reset transform matrix) |
|
67 mGridView->setOpacity( 1); |
|
68 |
|
69 if ( mItem ) { |
|
70 mItem->resetTransform(); //to reset the transition effect (reset transform matrix) |
|
71 mItem->setOpacity( 1); |
|
72 mItem->setZValue( mItem->zValue() - 20); |
|
73 disconnect( mItem, SIGNAL( destroyed() ), this, SLOT( itemDestroyed() ) ); |
|
74 mItem = NULL; |
|
75 } |
|
76 OstTraceFunctionExit0( GLXGRIDVIEW_ACTIVATE_EXIT ); |
|
77 } |
|
78 |
|
79 void GlxGridView::deActivate() |
|
80 { |
|
81 OstTraceFunctionEntry0( GLXGRIDVIEW_DEACTIVATE_ENTRY ); |
|
82 removeViewConnection(); |
|
83 |
|
84 |
|
85 /*if ( mItem ) { |
|
86 mItem->resetTransform(); //to reset the transition effect |
|
87 mItem->setOpacity( 1); |
|
88 disconnect( mItem, SIGNAL( destroyed() ), this, SLOT( itemDestroyed() ) ); |
|
89 mItem = NULL; |
|
90 }*/ |
|
91 takeToolBar(); //To:Do improved later |
|
92 emit toolBarChanged(); |
|
93 OstTraceFunctionExit0( GLXGRIDVIEW_DEACTIVATE_EXIT ); |
|
94 } |
|
95 |
|
96 void GlxGridView::setModel(QAbstractItemModel *model) |
|
97 { |
|
98 OstTraceFunctionEntry0( GLXGRIDVIEW_SETMODEL_ENTRY ); |
|
99 |
|
100 mModel = model ; |
|
101 mGridView->setModel(mModel); |
|
102 QVariant variant = mModel->data( mModel->index(0,0), GlxFocusIndexRole ); |
|
103 if ( variant.isValid() && variant.canConvert<int> () ) { |
|
104 mGridView->scrollTo( mModel->index( variant.value<int>(),0), HbGridView::PositionAtCenter ); |
|
105 } |
|
106 |
|
107 OstTraceFunctionExit0( GLXGRIDVIEW_SETMODEL_EXIT ); |
|
108 } |
|
109 |
|
110 void GlxGridView::addToolBar( HbToolBar *toolBar ) |
|
111 { |
|
112 OstTraceFunctionEntry0( GLXGRIDVIEW_ADDTOOLBAR_ENTRY ); |
|
113 //toolBar->setParent(this); |
|
114 if ( mGridView ) { |
|
115 toolBar->setZValue(mGridView->zValue()); |
|
116 } |
|
117 setToolBar(toolBar) ; |
|
118 OstTraceFunctionExit0( GLXGRIDVIEW_ADDTOOLBAR_EXIT ); |
|
119 } |
|
120 |
|
121 void GlxGridView::enableMarking() |
|
122 { |
|
123 OstTrace0( TRACE_NORMAL, GLXGRIDVIEW_ENABLEMARKING, "GlxGridView::enableMarking" ); |
|
124 mGridView->setSelectionMode(HbGridView::MultiSelection); |
|
125 } |
|
126 |
|
127 void GlxGridView::disableMarking() |
|
128 { |
|
129 OstTrace0( TRACE_NORMAL, GLXGRIDVIEW_DISABLEMARKING, "GlxGridView::disableMarking" ); |
|
130 mGridView->setSelectionMode(HbGridView::NoSelection); |
|
131 } |
|
132 |
|
133 void GlxGridView::handleUserAction(qint32 commandId) |
|
134 { |
|
135 OstTrace0( TRACE_NORMAL, GLXGRIDVIEW_HANDLEUSERACTION, "GlxGridView::handleUserAction" ); |
|
136 switch( commandId ){ |
|
137 case EGlxCmdMarkAll : |
|
138 mGridView->selectAll(); |
|
139 break; |
|
140 |
|
141 case EGlxCmdUnMarkAll : |
|
142 mGridView->clearSelection(); |
|
143 break; |
|
144 |
|
145 case EGlxCmdSend: |
|
146 { |
|
147 OstTrace0( TRACE_NORMAL, DUP1_GLXGRIDVIEW_HANDLEUSERACTION, "GlxGridView::handleUserAction-SendUI" ); |
|
148 |
|
149 QString imagePath = (mModel->data(mModel->index(mModel->data(mModel->index(0,0),GlxFocusIndexRole).value<int>() |
|
150 ,0),GlxUriRole)).value<QString>(); |
|
151 |
|
152 if(imagePath.isNull()) |
|
153 { |
|
154 OstTrace0( TRACE_NORMAL, DUP2_GLXGRIDVIEW_HANDLEUSERACTION, "GlxGridView::SendUi path is NULL" ); |
|
155 } |
|
156 qDebug() << "GlxGridView::SendUi() imagePath= " << imagePath; |
|
157 |
|
158 ShareUi dialog; |
|
159 QList <QVariant> fileList; |
|
160 fileList.append(QVariant(imagePath)); |
|
161 dialog.init(fileList,true); |
|
162 } |
|
163 break; |
|
164 |
|
165 default : |
|
166 break; |
|
167 } |
|
168 } |
|
169 |
|
170 QItemSelectionModel * GlxGridView::getSelectionModel() |
|
171 { |
|
172 OstTrace0( TRACE_NORMAL, GLXGRIDVIEW_GETSELECTIONMODEL, "GlxGridView::getSelectionModel" ); |
|
173 return mGridView->selectionModel(); |
|
174 } |
|
175 |
|
176 QGraphicsItem * GlxGridView::getAnimationItem(GlxEffect transitionEffect) |
|
177 { |
|
178 OstTraceFunctionEntry0( GLXGRIDVIEW_GETANIMATIONITEM_ENTRY ); |
|
179 int selIndex = -1; |
|
180 |
|
181 if ( transitionEffect == FULLSCREEN_TO_GRID ) { |
|
182 return mGridView; |
|
183 } |
|
184 |
|
185 if ( transitionEffect == GRID_TO_FULLSCREEN ) { |
|
186 QVariant variant = mModel->data( mModel->index(0,0), GlxFocusIndexRole ); |
|
187 if ( variant.isValid() && variant.canConvert<int> () ) { |
|
188 selIndex = variant.value<int>(); |
|
189 } |
|
190 |
|
191 mItem = mGridView->itemByIndex( mModel->index(selIndex,0) ); |
|
192 connect(mItem, SIGNAL(destroyed()), this, SLOT( itemDestroyed())); |
|
193 mItem->setZValue( mItem->zValue() + 20); |
|
194 return mItem; |
|
195 } |
|
196 |
|
197 if ( transitionEffect == GRID_TO_ALBUMLIST || transitionEffect == ALBUMLIST_TO_GRID ){ |
|
198 return mGridView; |
|
199 } |
|
200 return NULL; |
|
201 OstTraceFunctionExit0( GLXGRIDVIEW_GETANIMATIONITEM_EXIT ); |
|
202 } |
|
203 |
|
204 void GlxGridView::loadGridView(Qt::Orientation orient) |
|
205 { |
|
206 OstTraceFunctionEntry0( GLXGRIDVIEW_LOADGRIDVIEW_ENTRY ); |
|
207 bool loaded = true; |
|
208 QString section; |
|
209 //Load the widgets accroding to the current Orientation |
|
210 if(orient == Qt::Horizontal) |
|
211 { |
|
212 section = GLX_GRIDVIEW_LSSECTION ; |
|
213 } |
|
214 else |
|
215 { |
|
216 section = GLX_GRIDVIEW_PTSECTION ; |
|
217 } |
|
218 |
|
219 if (mGridView == NULL ) |
|
220 { |
|
221 mDocLoader->load(GLX_GRIDVIEW_DOCMLPATH,&loaded); |
|
222 if(loaded) |
|
223 { |
|
224 //retrieve the widgets |
|
225 mView = static_cast<HbView*>(mDocLoader->findWidget(QString(GLX_GRIDVIEW_VIEW))); |
|
226 mGridView = static_cast<HbGridView*>(mDocLoader->findWidget(GLX_GRIDVIEW_GRID)); |
|
227 setWidget( mView ); |
|
228 } |
|
229 } |
|
230 //Load the Sections |
|
231 mDocLoader->load(GLX_GRIDVIEW_DOCMLPATH,section,&loaded); |
|
232 OstTraceFunctionExit0( GLXGRIDVIEW_LOADGRIDVIEW_EXIT ); |
|
233 } |
|
234 |
|
235 void GlxGridView::itemDestroyed() |
|
236 { |
|
237 OstTrace0( TRACE_NORMAL, GLXGRIDVIEW_ITEMDESTROYED, "GlxGridView::itemDestroyed" ); |
|
238 disconnect( mItem, SIGNAL( destroyed() ), this, SLOT( itemDestroyed() ) ); |
|
239 mItem = NULL; |
|
240 } |
|
241 |
|
242 QVariant GlxGridView::itemChange (GraphicsItemChange change, const QVariant &value) |
|
243 { |
|
244 OstTrace0( TRACE_NORMAL, GLXGRIDVIEW_ITEMCHANGE, "GlxGridView::itemChange" ); |
|
245 |
|
246 static bool isEmit = true; |
|
247 |
|
248 if ( isEmit && change == QGraphicsItem::ItemVisibleHasChanged && value.toBool() ) { |
|
249 emit actionTriggered( EGlxCmdSetupItem ); |
|
250 isEmit = false; |
|
251 } |
|
252 return HbWidget::itemChange(change, value); |
|
253 } |
|
254 |
|
255 void GlxGridView::addViewConnection () |
|
256 { |
|
257 OstTrace0( TRACE_NORMAL, GLXGRIDVIEW_ADDVIEWCONNECTION, "GlxGridView::addViewConnection" ); |
|
258 connect(mWindow, SIGNAL(orientationChanged(Qt::Orientation)), this, SLOT(loadGridView(Qt::Orientation))); |
|
259 connect(mGridView, SIGNAL(activated(const QModelIndex &)), this, SLOT( itemSelected(const QModelIndex &))); |
|
260 connect( mGridView, SIGNAL( scrollingEnded() ), this, SLOT( setVisvalWindowIndex() ) ); |
|
261 if(XQServiceUtil::isService()){ |
|
262 connect(mGridView, SIGNAL(activated(const QModelIndex &)), this, SIGNAL( gridItemSelected(const QModelIndex &))); |
|
263 } |
|
264 // connect(mGridView, SIGNAL(scrollPositionChange(QPointF , Qt::Orientations)), this, SLOT( scrollPositionChange(QPointF, Qt::Orientations))); |
|
265 connect(mGridView, SIGNAL(longPressed( HbAbstractViewItem*, QPointF )),this, SLOT( indicateLongPress( HbAbstractViewItem*, QPointF ) ) ); |
|
266 } |
|
267 |
|
268 void GlxGridView::removeViewConnection () |
|
269 { |
|
270 OstTrace0( TRACE_NORMAL, GLXGRIDVIEW_REMOVEVIEWCONNECTION, "GlxGridView::removeViewConnection" ); |
|
271 disconnect(mWindow, SIGNAL(orientationChanged(Qt::Orientation)), this, SLOT(orientationChanged(Qt::Orientation))); |
|
272 disconnect(mGridView, SIGNAL(activated(const QModelIndex &)), this, SLOT( itemSelected(const QModelIndex &))); |
|
273 disconnect(mGridView, SIGNAL(activated(const QModelIndex &)), this, SIGNAL( gridItemSelected(const QModelIndex &))); |
|
274 disconnect( mGridView, SIGNAL( scrollingEnded() ), this, SLOT( setVisvalWindowIndex() ) ); |
|
275 disconnect(mGridView, SIGNAL(longPressed( HbAbstractViewItem*, QPointF )),this, SLOT( indicateLongPress( HbAbstractViewItem*, QPointF ) ) ); |
|
276 } |
|
277 |
|
278 void GlxGridView::itemSelected(const QModelIndex & index) |
|
279 { |
|
280 OstTrace1( TRACE_NORMAL, GLXGRIDVIEW_ITEMSELECTED, "GlxGridView::itemSelected;index=%d", index.row() ); |
|
281 |
|
282 if ( mGridView->selectionMode() == HbGridView::MultiSelection ){ //in multi selection mode no need to open the full screen |
|
283 return ; |
|
284 } |
|
285 OstTraceEventStart0( EVENT_DUP1_GLXGRIDVIEW_ITEMSELECTED_START, "Fullscreen Launch Time" ); |
|
286 |
|
287 if ( mModel ) |
|
288 { |
|
289 mModel->setData( index, index.row(), GlxFocusIndexRole ); |
|
290 } |
|
291 emit actionTriggered( EGlxCmdFullScreenOpen ); |
|
292 OstTraceEventStop( EVENT_DUP1_GLXGRIDVIEW_ITEMSELECTED_STOP, "Fullscreen Launch Time", EVENT_DUP1_GLXGRIDVIEW_ITEMSELECTED_START ); |
|
293 } |
|
294 |
|
295 void GlxGridView::setVisvalWindowIndex() |
|
296 { |
|
297 OstTrace0( TRACE_IMPORTANT, GLXGRIDVIEW_SETVISVALWINDOWINDEX, "GlxGridView::setVisvalWindowIndex" ); |
|
298 QList< HbAbstractViewItem * > visibleItemList = mGridView->visibleItems(); |
|
299 qDebug("GlxGridView::setVisvalWindowIndex() %d", visibleItemList.count()); |
|
300 OstTrace1( TRACE_IMPORTANT, DUP1_GLXGRIDVIEW_SETVISVALWINDOWINDEX, "GlxGridView::setVisvalWindowIndex;visibleitemindex=%d", |
|
301 visibleItemList.count() ); |
|
302 |
|
303 if ( visibleItemList.count() <= 0 ) |
|
304 return ; |
|
305 |
|
306 HbAbstractViewItem *item = visibleItemList.at(0); |
|
307 if ( item == NULL ) |
|
308 return ; |
|
309 |
|
310 OstTrace1( TRACE_IMPORTANT, DUP2_GLXGRIDVIEW_SETVISVALWINDOWINDEX, "GlxGridView::setVisvalWindowIndex item=%d", item ); |
|
311 OstTrace1( TRACE_IMPORTANT, DUP3_GLXGRIDVIEW_SETVISVALWINDOWINDEX, "GlxGridView::setVisvalWindowIndex;visual index=%d", |
|
312 item->modelIndex().row() ); |
|
313 |
|
314 if ( item->modelIndex().row() < 0 || item->modelIndex().row() >= mModel->rowCount() ) |
|
315 return ; |
|
316 |
|
317 mModel->setData( item->modelIndex (), item->modelIndex().row(), GlxVisualWindowIndex); |
|
318 } |
|
319 |
|
320 //To:Do remove later once we get visual index change notification from grid view |
|
321 void GlxGridView::scrollPositionChange (QPointF newPosition, Qt::Orientations importantDimensions) |
|
322 { |
|
323 OstTrace0( TRACE_IMPORTANT, DUP1_GLXGRIDVIEW_SCROLLPOSITIONCHANGE, "GlxGridView::scrollPositionChange" ); |
|
324 Q_UNUSED(importantDimensions); |
|
325 qreal x = newPosition.x(); |
|
326 qreal y = newPosition.y(); |
|
327 int index = 0; |
|
328 OstTraceExt2( TRACE_IMPORTANT, GLXGRIDVIEW_SCROLLPOSITIONCHANGE, "GlxGridView::scrollPositionChange;x=%f;y=%f", x, y ); |
|
329 |
|
330 if( mWindow->orientation() == Qt::Vertical ) { |
|
331 index = y / 100; |
|
332 index = index * NBR_COL; |
|
333 } |
|
334 else { |
|
335 index = y / 98; |
|
336 index = index * NBR_ROW; |
|
337 } |
|
338 |
|
339 OstTraceExt2( TRACE_IMPORTANT, DUP2_GLXGRIDVIEW_SCROLLPOSITIONCHANGE, |
|
340 "GlxGridView::scrollPositionChange;index=%d;visualindex=%d", index, mVisualIndex ); |
|
341 |
|
342 if ( qAbs (index - mVisualIndex) >= NBR_PAGE && index >=0 && index < mModel->rowCount() ) { |
|
343 mVisualIndex = index; |
|
344 OstTrace0( TRACE_IMPORTANT, DUP3_GLXGRIDVIEW_SCROLLPOSITIONCHANGE, |
|
345 "GlxGridView::scrollPositionChange visual index changed" ); |
|
346 //To:Do call back of model for visual index change |
|
347 //mModel->setVisibleWindowIndex( mModel->index(mVisualIndex, 0 )); |
|
348 } |
|
349 } |
|
350 |
|
351 |
|
352 GlxGridView::~GlxGridView() |
|
353 { |
|
354 OstTraceFunctionEntry0( DUP1_GLXGRIDVIEW_GLXGRIDVIEW_ENTRY ); |
|
355 removeViewConnection(); |
|
356 delete mGridView; |
|
357 mGridView = NULL; |
|
358 |
|
359 delete mDocLoader; |
|
360 mDocLoader = NULL; |
|
361 |
|
362 OstTraceFunctionExit0( DUP1_GLXGRIDVIEW_GLXGRIDVIEW_EXIT ); |
|
363 } |
|
364 |
|
365 void GlxGridView::indicateLongPress(HbAbstractViewItem *item, QPointF coords) |
|
366 { |
|
367 OstTrace0( TRACE_NORMAL, GLXGRIDVIEW_INDICATELONGPRESS, "GlxGridView::indicateLongPress" ); |
|
368 qDebug() << "GlxGridView:indicateLongPress Item " << item->modelIndex() << "long pressed at " |
|
369 << coords; |
|
370 |
|
371 if ( mGridView->selectionMode() == HbGridView::MultiSelection ){ //in multi selection mode no need to open the context menu |
|
372 return ; |
|
373 } |
|
374 |
|
375 if ( mModel ) { |
|
376 mModel->setData( item->modelIndex(), item->modelIndex().row(), GlxFocusIndexRole ); |
|
377 } |
|
378 emit itemSpecificMenuTriggered(viewId(),coords); |
|
379 } |