132 } |
135 } |
133 |
136 |
134 void GlxGridView::clearCurrentModel() |
137 void GlxGridView::clearCurrentModel() |
135 { |
138 { |
136 if ( mModel ) { |
139 if ( mModel ) { |
137 disconnect(mModel, SIGNAL(rowsInserted(QModelIndex,int,int)), this, SLOT(showItemCount())); |
140 disconnect( mModel, SIGNAL( rowsInserted( QModelIndex, int, int ) ), this, SLOT( rowsInserted() ) ); |
138 disconnect(mModel, SIGNAL(rowsRemoved(QModelIndex,int,int)), this, SLOT(showItemCount())); |
141 disconnect( mModel, SIGNAL( rowsRemoved( QModelIndex, int, int ) ), this, SLOT( rowsRemoved() ) ); |
139 disconnect(mModel, SIGNAL(destroyed()), this, SLOT( clearCurrentModel())); |
142 disconnect( mModel, SIGNAL(destroyed()), this, SLOT( clearCurrentModel() ) ); |
140 disconnect(mModel, SIGNAL(albumTitleAvailable(QString)), this, SLOT(showAlbumTitle(QString))); |
143 disconnect( mModel, SIGNAL( albumTitleAvailable( QString ) ), this, SLOT( showAlbumTitle( QString ) ) ); |
141 disconnect(mModel, SIGNAL(populated()), this, SLOT( populated())); |
144 disconnect( mModel, SIGNAL( populated() ), this, SLOT( populated() ) ); |
142 mModel = NULL ; |
145 mModel = NULL; |
143 } |
146 } |
144 } |
147 } |
145 |
148 |
146 void GlxGridView::initializeNewModel() |
149 void GlxGridView::initializeNewModel() |
147 { |
150 { |
148 if ( mModel ) { |
151 if ( mModel ) { |
149 connect(mModel, SIGNAL(rowsInserted(QModelIndex,int,int)), this, SLOT(showItemCount())); |
152 connect( mModel, SIGNAL( rowsInserted( QModelIndex, int, int ) ), this, SLOT( rowsInserted() ) ); |
150 connect(mModel, SIGNAL(rowsRemoved(QModelIndex,int,int)), this, SLOT(showItemCount())); |
153 connect( mModel, SIGNAL( rowsRemoved( QModelIndex, int, int ) ), this, SLOT( rowsRemoved() ) ); |
151 connect(mModel, SIGNAL(destroyed()), this, SLOT( clearCurrentModel())); |
154 connect( mModel, SIGNAL(destroyed()), this, SLOT( clearCurrentModel() ) ); |
152 if(getSubState() == ALBUM_ITEM_S){ |
155 if ( getSubState() == ALBUM_ITEM_S ) { |
153 connect(mModel, SIGNAL(albumTitleAvailable(QString)), this, SLOT(showAlbumTitle(QString))); |
156 connect( mModel, SIGNAL( albumTitleAvailable( QString ) ), this, SLOT( showAlbumTitle( QString ) ) ); |
154 } |
157 } |
155 connect(mModel, SIGNAL(populated()), this, SLOT( populated())); |
158 connect( mModel, SIGNAL( populated() ), this, SLOT( populated() ) ); |
156 } |
159 } |
157 } |
160 } |
158 |
161 |
159 void GlxGridView::setModel(QAbstractItemModel *model) |
162 void GlxGridView::setModel( QAbstractItemModel *model ) |
160 { |
163 { |
161 OstTraceFunctionEntry0( GLXGRIDVIEW_SETMODEL_ENTRY ); |
164 OstTraceFunctionEntry0( GLXGRIDVIEW_SETMODEL_ENTRY ); |
162 if(model) |
165 if( model ) { |
163 { |
|
164 clearCurrentModel(); |
166 clearCurrentModel(); |
165 mModel = model; |
167 mModel = model; |
166 initializeNewModel(); |
168 initializeNewModel(); |
|
169 |
167 QVariant variantimage = mModel->data(mModel->index(0,0),GlxDefaultImage); |
170 QVariant variantimage = mModel->data(mModel->index(0,0),GlxDefaultImage); |
168 if (mWidget && variantimage.isValid() && variantimage.canConvert<QImage> () ) |
171 if ( variantimage.isValid() && variantimage.canConvert<QImage> () ) { |
169 { |
172 mWidget->setDefaultImage( variantimage.value<QImage>() ); |
170 mWidget->setDefaultImage(variantimage.value<QImage>()); |
173 } |
171 } |
174 |
172 mModelWrapper->setModel(mModel); |
175 mModelWrapper->setModel( mModel ); |
173 mWidget->setModel(mModelWrapper); |
176 mWidget->setModel( mModelWrapper ); |
174 if(!mSelectionModel) |
177 |
175 { |
178 if( !mSelectionModel ) { |
176 mSelectionModel = new QItemSelectionModel(mModelWrapper, this); |
179 mSelectionModel = new QItemSelectionModel( mModelWrapper, this ); |
177 connect(mSelectionModel, SIGNAL(currentChanged(const QModelIndex &, const QModelIndex &)), this, SLOT(visibleIndexChanged(const QModelIndex &, const QModelIndex &))); |
180 connect( mSelectionModel, SIGNAL( currentChanged( const QModelIndex &, const QModelIndex & ) ), this, SLOT( visibleIndexChanged( const QModelIndex &, const QModelIndex & ) ) ); |
178 mWidget->setSelectionModel(mSelectionModel); |
181 mWidget->setSelectionModel( mSelectionModel ); |
179 } |
182 } |
180 scrolltofocus(); // Need to do it here ? |
183 |
|
184 scrolltofocus(); // Need to do it here ? |
181 showItemCount(); |
185 showItemCount(); |
182 } |
186 } |
183 OstTraceFunctionExit0( GLXGRIDVIEW_SETMODEL_EXIT ); |
187 OstTraceFunctionExit0( GLXGRIDVIEW_SETMODEL_EXIT ); |
184 } |
188 } |
185 |
189 |
186 void GlxGridView::visibleIndexChanged(const QModelIndex& current, const QModelIndex& previous) |
190 void GlxGridView::visibleIndexChanged(const QModelIndex& current, const QModelIndex& previous) |
187 { |
191 { |
196 } |
200 } |
197 |
201 |
198 void GlxGridView::addToolBar( HbToolBar *toolBar ) |
202 void GlxGridView::addToolBar( HbToolBar *toolBar ) |
199 { |
203 { |
200 OstTraceFunctionEntry0( GLXGRIDVIEW_ADDTOOLBAR_ENTRY ); |
204 OstTraceFunctionEntry0( GLXGRIDVIEW_ADDTOOLBAR_ENTRY ); |
201 setToolBar(toolBar); |
205 |
|
206 //For album grid view, add and remove from album tool bar will be shown |
|
207 int subState = getSubState(); |
|
208 if ( subState == ALBUM_ITEM_S && mWidget->selectionMode() == HgWidget::NoSelection ) { |
|
209 if ( !mToolBar ) { |
|
210 createAlbumGridToolBar(); |
|
211 } |
|
212 if ( mToolBar ) { |
|
213 //remove from action will be disable if number of images in the album grid is zero. |
|
214 if ( mModel->rowCount() ) { |
|
215 mToolBar->actions().at(0)->setEnabled( true ); //To:Do remove once selection dialog is implemented |
|
216 mToolBar->actions().at(1)->setEnabled( true ); |
|
217 } |
|
218 else { |
|
219 mToolBar->actions().at(0)->setEnabled( false ); |
|
220 mToolBar->actions().at(1)->setEnabled( false ); |
|
221 } |
|
222 if ( mToolBar != mCurrentToolBar ) { |
|
223 takeToolBar(); |
|
224 setToolBar( mToolBar ); |
|
225 mCurrentToolBar = mToolBar; |
|
226 } |
|
227 } |
|
228 } |
|
229 else { |
|
230 if ( toolBar != mCurrentToolBar ) { |
|
231 takeToolBar(); |
|
232 setToolBar( toolBar ); |
|
233 mCurrentToolBar = toolBar; |
|
234 } |
|
235 } |
|
236 |
202 showHbItems(); |
237 showHbItems(); |
203 OstTraceFunctionExit0( GLXGRIDVIEW_ADDTOOLBAR_EXIT ); |
238 OstTraceFunctionExit0( GLXGRIDVIEW_ADDTOOLBAR_EXIT ); |
204 } |
239 } |
205 |
240 |
206 void GlxGridView::enableMarking() |
241 void GlxGridView::enableMarking() |
268 |
303 |
269 void GlxGridView::showMarkedItemCount() |
304 void GlxGridView::showMarkedItemCount() |
270 { |
305 { |
271 int count = mModel->rowCount(); |
306 int count = mModel->rowCount(); |
272 QModelIndexList indexList = mWidget->selectionModel()->selectedIndexes(); |
307 QModelIndexList indexList = mWidget->selectionModel()->selectedIndexes(); |
273 int markItemCount = indexList.count(); |
308 int markItemCount = indexList.count(); |
274 |
309 QString text= HbParameterLengthLimiter(GLX_LABEL_MARK_COUNT).arg(markItemCount).arg(count); |
275 QString text= HbParameterLengthLimiter(GLX_LABEL_MARK_COUNT).arg(markItemCount).arg(count); |
|
276 |
|
277 mMarkCountLabel->setPlainText( text ); |
310 mMarkCountLabel->setPlainText( text ); |
278 } |
311 } |
279 |
312 |
280 void GlxGridView::showItemCount() |
313 void GlxGridView::showItemCount() |
281 { |
314 { |
282 int count = 0; |
315 int count = 0; |
283 if(mModel) { |
316 if( mModel ) { |
284 count = mModel->rowCount(); |
317 count = mModel->rowCount(); |
285 QSize deviceSize = HbDeviceProfile::current().logicalSize(); |
318 QSize deviceSize = HbDeviceProfile::current().logicalSize(); |
286 QSize screenSize = ( mWindow->orientation() == Qt::Vertical ) ? QSize( deviceSize.width(), deviceSize.height() ) |
319 QSize screenSize = ( mWindow->orientation() == Qt::Vertical ) ? QSize( deviceSize.width(), deviceSize.height() ) |
287 : QSize( deviceSize.height(), deviceSize.width() ) ; |
320 : QSize( deviceSize.height(), deviceSize.width() ) ; |
288 if(count) { |
321 if( count ) { |
289 if(mZeroItemLabel) { |
322 if(mZeroItemLabel) { |
290 mZeroItemLabel->hide(); |
323 mZeroItemLabel->hide(); |
291 } |
324 } |
292 |
325 |
293 if(isItemVisible(Hb::TitleBarItem)) { |
326 if( isItemVisible( Hb::TitleBarItem ) ) { |
294 QString text; |
327 QString text; |
295 if(XQServiceUtil::isService()) |
328 if(XQServiceUtil::isService()) { |
296 { |
|
297 showAlbumTitle(GLX_SELECT_IMAGE); |
329 showAlbumTitle(GLX_SELECT_IMAGE); |
298 } |
330 } |
299 else if (getSubState() == ALL_ITEM_S) { |
331 else if ( getSubState() == ALL_ITEM_S ) { |
300 if (mAlbumNameHeading) { |
332 if (mAlbumNameHeading) { |
301 mAlbumNameHeading->hide(); |
333 mAlbumNameHeading->hide(); |
302 } |
334 } |
303 mTotalImagesCount->setGeometry(QRectF(0,0,screenSize.width(),deviceSize.height()/24)); |
335 mTotalImagesCount->setGeometry(QRectF(0,0,screenSize.width(),deviceSize.height()/24)); |
304 text = HbParameterLengthLimiter(GLX_GRID_VIEW_COUNT_LABEL, count); |
336 text = HbParameterLengthLimiter(GLX_GRID_VIEW_COUNT_LABEL, count); |
305 mTotalImagesCount->setHeading ( text ); |
337 mTotalImagesCount->setHeading ( text ); |
306 mTotalImagesCount->show(); |
338 mTotalImagesCount->show(); |
307 } |
339 } |
308 else if (getSubState() == ALBUM_ITEM_S) { |
340 else if ( getSubState() == ALBUM_ITEM_S ) { |
309 mTotalImagesCount->hide(); |
341 mTotalImagesCount->hide(); |
310 QVariant variant = mModel->data(mModel->index(0,0),GlxViewTitle); |
342 QVariant variant = mModel->data(mModel->index(0,0),GlxViewTitle); |
311 if (variant.toString() != NULL) { |
343 if (variant.toString() != NULL) { |
312 showAlbumTitle(variant.toString()); |
344 showAlbumTitle(variant.toString()); |
313 } |
345 } |
404 |
436 |
405 } |
437 } |
406 |
438 |
407 void GlxGridView::populated() |
439 void GlxGridView::populated() |
408 { |
440 { |
409 QVariant variant = mModelWrapper->data(mModelWrapper->index(0,0), GlxVisualWindowIndex ); |
441 QVariant variant = mModelWrapper->data(mModelWrapper->index(0,0), GlxVisualWindowIndex ); |
410 int visualIndex = 0; |
442 int visualIndex = 0; |
411 if ( variant.isValid() && variant.canConvert<int> () ) { |
443 if ( variant.isValid() && variant.canConvert<int> () ) { |
412 visualIndex = variant.value<int>(); |
444 visualIndex = variant.value<int>(); |
413 } |
445 } |
414 mWidget->scrollTo(mModelWrapper->index(visualIndex,0)); |
446 mWidget->scrollTo(mModelWrapper->index(visualIndex,0)); |
415 showItemCount(); |
447 showItemCount(); |
|
448 } |
|
449 |
|
450 void GlxGridView::rowsInserted() |
|
451 { |
|
452 showItemCount(); |
|
453 if( getSubState() == ALBUM_ITEM_S && mToolBar ) { |
|
454 mToolBar->actions().at(0)->setEnabled( true ); //To:Do remove once selection dialog is implemented |
|
455 mToolBar->actions().at(1)->setEnabled( true ); |
|
456 } |
|
457 } |
|
458 |
|
459 void GlxGridView::rowsRemoved() |
|
460 { |
|
461 showItemCount(); |
|
462 if( getSubState() == ALBUM_ITEM_S && mModel->rowCount() == 0 && mToolBar ) { |
|
463 mToolBar->actions().at(0)->setEnabled( false ); //To:Do remove once selection dialog is implemented |
|
464 mToolBar->actions().at(1)->setEnabled( false ); |
|
465 } |
|
466 } |
|
467 |
|
468 void GlxGridView::handleToolBarAction() |
|
469 { |
|
470 HbAction *action = qobject_cast<HbAction*>( sender() ); |
|
471 qint32 commandId = action->data().toInt(); |
|
472 emit actionTriggered( commandId ); |
416 } |
473 } |
417 |
474 |
418 void GlxGridView::handleUserAction(qint32 commandId) |
475 void GlxGridView::handleUserAction(qint32 commandId) |
419 { |
476 { |
420 OstTrace0( TRACE_NORMAL, GLXGRIDVIEW_HANDLEUSERACTION, "GlxGridView::handleUserAction" ); |
477 OstTrace0( TRACE_NORMAL, GLXGRIDVIEW_HANDLEUSERACTION, "GlxGridView::handleUserAction" ); |
669 } |
726 } |
670 |
727 |
671 void GlxGridView::scrollingEnded() |
728 void GlxGridView::scrollingEnded() |
672 { |
729 { |
673 mScrolling = FALSE; |
730 mScrolling = FALSE; |
674 if (mUiOnButton && (mWindow->orientation() == Qt::Horizontal)) |
731 if ( mUiOnButton && ( mWindow->orientation() == Qt::Horizontal ) ) { |
675 { |
|
676 mUiOnButton->show(); |
732 mUiOnButton->show(); |
677 } |
733 } |
|
734 |
678 QList<QModelIndex> visibleIndex = mWidget->getVisibleItemIndices(); |
735 QList<QModelIndex> visibleIndex = mWidget->getVisibleItemIndices(); |
679 if (visibleIndex.count() <= 0) |
736 if ( visibleIndex.count() <= 0 ) { |
680 { |
|
681 return; |
737 return; |
682 } |
738 } |
683 QModelIndex index = visibleIndex.at(0); |
739 QModelIndex index = visibleIndex.at(0); |
684 if ( index.row() < 0 || index.row() >= mModel->rowCount() ) |
740 |
685 { |
741 if(mModel) { |
686 return; |
742 if ( index.row() < 0 || index.row() >= mModel->rowCount() ) { |
687 } |
743 return; |
688 if(mModel) |
744 } |
689 { |
745 mModel->setData( index, index.row(), GlxVisualWindowIndex ); |
690 mModel->setData( index, index.row(), GlxVisualWindowIndex); |
|
691 mModel->setData( index, index.row(), GlxFocusIndexRole ); |
746 mModel->setData( index, index.row(), GlxFocusIndexRole ); |
692 } |
747 } |
693 } |
748 } |
694 |
749 |
695 GlxGridView::~GlxGridView() |
750 GlxGridView::~GlxGridView() |
696 { |
751 { |
697 OstTraceFunctionEntry0( DUP1_GLXGRIDVIEW_GLXGRIDVIEW_ENTRY ); |
752 OstTraceFunctionEntry0( DUP1_GLXGRIDVIEW_GLXGRIDVIEW_ENTRY ); |
777 if ( mWidget && mWidget->selectionMode() == HgWidget::MultiSelection ) { |
833 if ( mWidget && mWidget->selectionMode() == HgWidget::MultiSelection ) { |
778 setItemVisible( Hb::ToolBarItem, TRUE ) ; |
834 setItemVisible( Hb::ToolBarItem, TRUE ) ; |
779 return ; |
835 return ; |
780 } |
836 } |
781 |
837 |
782 //In Album grid it is not required to show tool bar |
838 //In the case of fetcher, there is no tool bar for album grid view |
783 int subState = getSubState(); |
839 int subState = getSubState(); |
784 if ( subState == ALBUM_ITEM_S || subState == FETCHER_ALBUM_ITEM_S ) { |
840 if ( subState == FETCHER_ALBUM_ITEM_S ) { |
785 setItemVisible( Hb::ToolBarItem, FALSE ) ; |
841 setItemVisible( Hb::ToolBarItem, FALSE ) ; |
786 } |
842 } |
787 else { |
843 else { |
788 setItemVisible( Hb::ToolBarItem, TRUE ); |
844 setItemVisible( Hb::ToolBarItem, TRUE ); |
789 } |
845 } |
790 } |
846 } |
791 |
847 |
|
848 void GlxGridView::createAlbumGridToolBar() |
|
849 { |
|
850 mToolBar = new HbToolBar(); |
|
851 mToolBar->setOrientation( Qt::Horizontal ); |
|
852 mToolBar->setVisible(true); |
|
853 mToolBar->clearActions(); |
|
854 |
|
855 HbAction *action = new HbAction(); |
|
856 action->setData( EGlxCmdAddToAlbum ); |
|
857 action->setIcon( HbIcon( GLXICON_ADD ) ); |
|
858 action->setObjectName( "Add Action" ); |
|
859 mToolBar->addAction( action ); |
|
860 connect( action, SIGNAL( triggered( ) ), this, SLOT( handleToolBarAction( ) ) ); |
|
861 |
|
862 action = new HbAction(); |
|
863 action->setData( EGlxCmdRemoveFrom ); |
|
864 action->setIcon( HbIcon( GLXICON_REMOVE ) ); |
|
865 action->setObjectName( "Remove Action" ); |
|
866 mToolBar->addAction( action ); |
|
867 connect( action, SIGNAL( triggered( ) ), this, SLOT( handleToolBarAction( ) ) ); |
|
868 } |
|
869 |