ui/views/gridview/src/glxgridview.cpp
changeset 24 99ad1390cd33
parent 23 74c9f037fd5d
child 26 c499df2dbb33
--- a/ui/views/gridview/src/glxgridview.cpp	Fri Mar 19 09:28:59 2010 +0200
+++ b/ui/views/gridview/src/glxgridview.cpp	Fri Apr 16 14:58:46 2010 +0300
@@ -43,95 +43,84 @@
 #include "glxgridviewTraces.h"
 #endif
 
-GlxGridView::GlxGridView(HbMainWindow *window) : GlxView ( GLX_GRIDVIEW_ID ), 
-             mGridView(NULL), mView(NULL), mWindow(window), mModel ( NULL), mVisualIndex(0),
-             mItem(NULL)
-    {
+GlxGridView::GlxGridView(HbMainWindow *window) 
+    : GlxView ( GLX_GRIDVIEW_ID ), 
+      mGridView(NULL), 
+      mView(NULL), 
+      mWindow(window), 
+      mModel ( NULL), 
+      mVisualIndex(0),
+      mItem(NULL)
+{
     OstTraceFunctionEntry0( GLXGRIDVIEW_GLXGRIDVIEW_ENTRY );
     mDocLoader = new HbDocumentLoader();
     OstTraceFunctionExit0( GLXGRIDVIEW_GLXGRIDVIEW_EXIT );
 	setContentFullScreen( true );
-    }
+}
 
 void GlxGridView::activate()
-    {
+{
     OstTraceFunctionEntry0( GLXGRIDVIEW_ACTIVATE_ENTRY );
-
     loadGridView(mWindow->orientation());
-    addViewConnection();
-    //   mVisualIndex = 0; //To:Do remove later once we get visual index change notification from grid view
-
-
-
+    addViewConnection();           
     mGridView->resetTransform(); //to reset the transition effect (reset transform matrix)
     mGridView->setOpacity( 1);
-
-    if ( mItem ) {
-    mItem->resetTransform(); //to reset the transition effect (reset transform matrix)
-    mItem->setOpacity( 1);
-    mItem->setZValue( mItem->zValue() - 20);
-    disconnect( mItem, SIGNAL( destroyed() ), this, SLOT( itemDestroyed() ) );
-    mItem = NULL;
-    }
+    resetItemTransform();
     OstTraceFunctionExit0( GLXGRIDVIEW_ACTIVATE_EXIT );
-    }
+}
 
 void GlxGridView::deActivate()
-    {
+{
     OstTraceFunctionEntry0( GLXGRIDVIEW_DEACTIVATE_ENTRY );
     removeViewConnection();
-
+    OstTraceFunctionExit0( GLXGRIDVIEW_DEACTIVATE_EXIT );
+}
 
-    /*if ( mItem ) {
-        mItem->resetTransform(); //to reset the transition effect
-        mItem->setOpacity( 1);
-        disconnect( mItem, SIGNAL( destroyed() ), this, SLOT( itemDestroyed() ) );
-        mItem = NULL; 
-    }*/
-    takeToolBar(); //To:Do improved later
-    emit toolBarChanged();
-    OstTraceFunctionExit0( GLXGRIDVIEW_DEACTIVATE_EXIT );
+void GlxGridView::initializeView(QAbstractItemModel *model)
+{
+    resetItemTransform();
+    mGridView->setModel(model);
+    mModel = model;
+    loadGridView(mWindow->orientation());
+    QVariant variant = model->data( model->index(0,0), GlxFocusIndexRole );    
+    if ( variant.isValid() &&  variant.canConvert<int> () ) {
+        mGridView->scrollTo( model->index( variant.value<int>(),0), HbGridView::EnsureVisible );
     }
+}
 
 void GlxGridView::setModel(QAbstractItemModel *model) 
-    {
+{
     OstTraceFunctionEntry0( GLXGRIDVIEW_SETMODEL_ENTRY );
-
     mModel =  model ;
     mGridView->setModel(mModel);
     QVariant variant = mModel->data( mModel->index(0,0), GlxFocusIndexRole );    
     if ( variant.isValid() &&  variant.canConvert<int> () ) {
-    mGridView->scrollTo( mModel->index( variant.value<int>(),0), HbGridView::PositionAtCenter );
-    }  
-    
+        mGridView->scrollTo( mModel->index( variant.value<int>(),0), HbGridView::EnsureVisible );
+    }
     OstTraceFunctionExit0( GLXGRIDVIEW_SETMODEL_EXIT );
-    }
+}
 
 void GlxGridView::addToolBar( HbToolBar *toolBar ) 
-    {
-    OstTraceFunctionEntry0( GLXGRIDVIEW_ADDTOOLBAR_ENTRY );
-    //toolBar->setParent(this); 
-    if ( mGridView ) {
-        toolBar->setZValue(mGridView->zValue());
-    }
+{
+    OstTraceFunctionEntry0( GLXGRIDVIEW_ADDTOOLBAR_ENTRY );     
     setToolBar(toolBar) ;
     OstTraceFunctionExit0( GLXGRIDVIEW_ADDTOOLBAR_EXIT );
-    }
+}
 
 void GlxGridView::enableMarking()
-    {
+{
     OstTrace0( TRACE_NORMAL, GLXGRIDVIEW_ENABLEMARKING, "GlxGridView::enableMarking" );
     mGridView->setSelectionMode(HbGridView::MultiSelection);
-    }
+}
 
 void GlxGridView::disableMarking() 
-    {
+{
     OstTrace0( TRACE_NORMAL, GLXGRIDVIEW_DISABLEMARKING, "GlxGridView::disableMarking" );
     mGridView->setSelectionMode(HbGridView::NoSelection);
-    }
+}
 
 void GlxGridView::handleUserAction(qint32 commandId)
-    {
+{
     OstTrace0( TRACE_NORMAL, GLXGRIDVIEW_HANDLEUSERACTION, "GlxGridView::handleUserAction" );
     switch( commandId ){
         case EGlxCmdMarkAll :
@@ -142,102 +131,89 @@
             mGridView->clearSelection();
             break;
 
-        case EGlxCmdSend:
-            {
-            OstTrace0( TRACE_NORMAL, DUP1_GLXGRIDVIEW_HANDLEUSERACTION, "GlxGridView::handleUserAction-SendUI" );
-            
-            QString imagePath = (mModel->data(mModel->index(mModel->data(mModel->index(0,0),GlxFocusIndexRole).value<int>()
-                    ,0),GlxUriRole)).value<QString>();
-
-            if(imagePath.isNull())
-                {
-                OstTrace0( TRACE_NORMAL, DUP2_GLXGRIDVIEW_HANDLEUSERACTION, "GlxGridView::SendUi path is NULL" );
-                }
-            qDebug() << "GlxGridView::SendUi() imagePath= " << imagePath;
-
-            ShareUi dialog;
-            QList <QVariant> fileList;
-            fileList.append(QVariant(imagePath));
-            dialog.init(fileList,true);
-            }
-            break;
+        
 
         default :
             break;
     }    
-    }
+}
 
 QItemSelectionModel * GlxGridView::getSelectionModel()
-    {
+{
     OstTrace0( TRACE_NORMAL, GLXGRIDVIEW_GETSELECTIONMODEL, "GlxGridView::getSelectionModel" );
     return mGridView->selectionModel();    
-    }
+}
 
 QGraphicsItem * GlxGridView::getAnimationItem(GlxEffect transitionEffect)
-    {
+{
     OstTraceFunctionEntry0( GLXGRIDVIEW_GETANIMATIONITEM_ENTRY );
     int selIndex = -1;
 
     if ( transitionEffect == FULLSCREEN_TO_GRID ) {
-    return mGridView;
+        return mGridView;
     }
 
     if ( transitionEffect == GRID_TO_FULLSCREEN ) {
-    QVariant variant = mModel->data( mModel->index(0,0), GlxFocusIndexRole );    
-    if ( variant.isValid() &&  variant.canConvert<int> () ) {
-    selIndex = variant.value<int>();  
-    }  
-
-    mItem = mGridView->itemByIndex( mModel->index(selIndex,0) );
-    connect(mItem, SIGNAL(destroyed()), this, SLOT( itemDestroyed()));
-    mItem->setZValue( mItem->zValue() + 20); 
-    return mItem;
+        QVariant variant = mModel->data( mModel->index(0,0), GlxFocusIndexRole );    
+        if ( variant.isValid() &&  variant.canConvert<int> () ) {
+            selIndex = variant.value<int>();  
+        }  
+    
+        mItem = mGridView->itemByIndex( mModel->index(selIndex,0) );
+        connect(mItem, SIGNAL(destroyed()), this, SLOT( itemDestroyed()));
+        mItem->setZValue( mItem->zValue() + 20); 
+        return mItem;
     }
 
     if ( transitionEffect == GRID_TO_ALBUMLIST  || transitionEffect == ALBUMLIST_TO_GRID ){
-    return mGridView;
+        return mGridView;
     }
-    return NULL;
     OstTraceFunctionExit0( GLXGRIDVIEW_GETANIMATIONITEM_EXIT );
-    }
+    return NULL;    
+}
 
 void GlxGridView::loadGridView(Qt::Orientation orient)
-    {
+{
     OstTraceFunctionEntry0( GLXGRIDVIEW_LOADGRIDVIEW_ENTRY );
     bool loaded = true;
     QString section;
+    GlxContextMode mode ;
+    
     //Load the widgets accroding to the current Orientation
-    if(orient == Qt::Horizontal)
-        {
+    if(orient == Qt::Horizontal) {
         section = GLX_GRIDVIEW_LSSECTION ;
-        }
-    else
-        {
+        mode = GlxContextLsGrid ;
+    }
+    else {
         section = GLX_GRIDVIEW_PTSECTION ;
-        }
+        mode = GlxContextPtGrid ;
+    }
 
-    if (mGridView == NULL )
-        {       
+    if (mGridView == NULL ) {       
         mDocLoader->load(GLX_GRIDVIEW_DOCMLPATH,&loaded);
-        if(loaded)
-            {
+        if(loaded) {
             //retrieve the widgets            
             mView = static_cast<HbView*>(mDocLoader->findWidget(QString(GLX_GRIDVIEW_VIEW)));
             mGridView = static_cast<HbGridView*>(mDocLoader->findWidget(GLX_GRIDVIEW_GRID)); 
             setWidget( mView );
-            }
+            mGridView->setLayoutName( QString( "GridView" ) );
         }
+    }
     //Load the Sections
     mDocLoader->load(GLX_GRIDVIEW_DOCMLPATH,section,&loaded); 
+    
+    if ( mModel ) {        
+        mModel->setData(QModelIndex(), (int)mode, GlxContextRole );
+    }
     OstTraceFunctionExit0( GLXGRIDVIEW_LOADGRIDVIEW_EXIT );
-    }
+}
 
 void GlxGridView::itemDestroyed()
-    {
+{
     OstTrace0( TRACE_NORMAL, GLXGRIDVIEW_ITEMDESTROYED, "GlxGridView::itemDestroyed" );
     disconnect( mItem, SIGNAL( destroyed() ), this, SLOT( itemDestroyed() ) );
     mItem = NULL;    
-    }
+}
 
 QVariant  GlxGridView::itemChange (GraphicsItemChange change, const QVariant &value) 
     {
@@ -253,30 +229,40 @@
     }
 
 void GlxGridView::addViewConnection ()
-    {
+{
     OstTrace0( TRACE_NORMAL, GLXGRIDVIEW_ADDVIEWCONNECTION, "GlxGridView::addViewConnection" );
     connect(mWindow, SIGNAL(orientationChanged(Qt::Orientation)), this, SLOT(loadGridView(Qt::Orientation)));
     connect(mGridView, SIGNAL(activated(const QModelIndex &)), this, SLOT( itemSelected(const QModelIndex &)));
     connect( mGridView, SIGNAL( scrollingEnded() ), this, SLOT( setVisvalWindowIndex() ) );
     if(XQServiceUtil::isService()){
-    connect(mGridView, SIGNAL(activated(const QModelIndex &)), this, SIGNAL( gridItemSelected(const QModelIndex &)));
+        connect(mGridView, SIGNAL(activated(const QModelIndex &)), this, SIGNAL( gridItemSelected(const QModelIndex &)));
     }
-    //    connect(mGridView, SIGNAL(scrollPositionChange(QPointF , Qt::Orientations)), this, SLOT( scrollPositionChange(QPointF, Qt::Orientations)));
     connect(mGridView, SIGNAL(longPressed( HbAbstractViewItem*, QPointF )),this, SLOT( indicateLongPress( HbAbstractViewItem*, QPointF ) ) );
-    }
+}
 
 void GlxGridView::removeViewConnection ()
-    {
+{
     OstTrace0( TRACE_NORMAL, GLXGRIDVIEW_REMOVEVIEWCONNECTION, "GlxGridView::removeViewConnection" );
-    disconnect(mWindow, SIGNAL(orientationChanged(Qt::Orientation)), this, SLOT(orientationChanged(Qt::Orientation)));
+    disconnect(mWindow, SIGNAL(orientationChanged(Qt::Orientation)), this, SLOT(loadGridView(Qt::Orientation)));
     disconnect(mGridView, SIGNAL(activated(const QModelIndex &)), this, SLOT( itemSelected(const QModelIndex &)));
     disconnect(mGridView, SIGNAL(activated(const QModelIndex &)), this, SIGNAL( gridItemSelected(const QModelIndex &)));
     disconnect( mGridView, SIGNAL( scrollingEnded() ), this, SLOT( setVisvalWindowIndex() ) );
     disconnect(mGridView, SIGNAL(longPressed( HbAbstractViewItem*, QPointF )),this, SLOT( indicateLongPress( HbAbstractViewItem*, QPointF ) ) );
+}
+
+void GlxGridView::resetItemTransform()
+{
+    if ( mItem ) {
+        mItem->resetTransform(); //to reset the transition effect (reset transform matrix)
+        mItem->setOpacity( 1);
+        mItem->setZValue( mItem->zValue() - 20);
+        disconnect( mItem, SIGNAL( destroyed() ), this, SLOT( itemDestroyed() ) );
+        mItem = NULL;
     }
+}
 
 void GlxGridView::itemSelected(const QModelIndex &  index)
-    {
+{
     OstTrace1( TRACE_NORMAL, GLXGRIDVIEW_ITEMSELECTED, "GlxGridView::itemSelected;index=%d", index.row() );
 
     if ( mGridView->selectionMode() == HbGridView::MultiSelection ){ //in multi selection mode no need to open the full screen
@@ -290,10 +276,10 @@
         }
     emit actionTriggered( EGlxCmdFullScreenOpen );
     OstTraceEventStop( EVENT_DUP1_GLXGRIDVIEW_ITEMSELECTED_STOP, "Fullscreen Launch Time", EVENT_DUP1_GLXGRIDVIEW_ITEMSELECTED_START );
-    }
+}
 
 void GlxGridView::setVisvalWindowIndex()
-    {
+{
     OstTrace0( TRACE_IMPORTANT, GLXGRIDVIEW_SETVISVALWINDOWINDEX, "GlxGridView::setVisvalWindowIndex" );
     QList< HbAbstractViewItem * >  visibleItemList =  mGridView->visibleItems();
     qDebug("GlxGridView::setVisvalWindowIndex() %d", visibleItemList.count());    
@@ -315,42 +301,10 @@
         return ;
     
     mModel->setData( item->modelIndex (), item->modelIndex().row(), GlxVisualWindowIndex);
-    }
-
-//To:Do remove later once we get visual index change notification from grid view
-void GlxGridView::scrollPositionChange (QPointF newPosition, Qt::Orientations importantDimensions)
-    {
-    OstTrace0( TRACE_IMPORTANT, DUP1_GLXGRIDVIEW_SCROLLPOSITIONCHANGE, "GlxGridView::scrollPositionChange" );
-    Q_UNUSED(importantDimensions);
-    qreal x = newPosition.x();
-    qreal y = newPosition.y();  
-    int index = 0;
-    OstTraceExt2( TRACE_IMPORTANT, GLXGRIDVIEW_SCROLLPOSITIONCHANGE, "GlxGridView::scrollPositionChange;x=%f;y=%f", x, y );
-
-    if( mWindow->orientation() == Qt::Vertical ) {
-    index = y / 100;
-    index = index * NBR_COL;
-    }
-    else {
-    index = y / 98;
-    index = index * NBR_ROW;
-    }
-
-    OstTraceExt2( TRACE_IMPORTANT, DUP2_GLXGRIDVIEW_SCROLLPOSITIONCHANGE, 
-            "GlxGridView::scrollPositionChange;index=%d;visualindex=%d", index, mVisualIndex );
-
-    if ( qAbs (index - mVisualIndex) >= NBR_PAGE &&  index >=0 && index < mModel->rowCount() ) {
-    mVisualIndex = index;
-    OstTrace0( TRACE_IMPORTANT, DUP3_GLXGRIDVIEW_SCROLLPOSITIONCHANGE, 
-            "GlxGridView::scrollPositionChange visual index changed" );
-    //To:Do call back of model for visual index change
-    //mModel->setVisibleWindowIndex( mModel->index(mVisualIndex, 0 ));
-    }    
-    }
-
+}
 
 GlxGridView::~GlxGridView()
-    {
+{
     OstTraceFunctionEntry0( DUP1_GLXGRIDVIEW_GLXGRIDVIEW_ENTRY );
     removeViewConnection();
     delete mGridView;
@@ -360,20 +314,20 @@
     mDocLoader = NULL;
 
     OstTraceFunctionExit0( DUP1_GLXGRIDVIEW_GLXGRIDVIEW_EXIT );
-    }
+}
 
 void GlxGridView::indicateLongPress(HbAbstractViewItem *item, QPointF coords)
-    {
+{
     OstTrace0( TRACE_NORMAL, GLXGRIDVIEW_INDICATELONGPRESS, "GlxGridView::indicateLongPress" );
     qDebug() << "GlxGridView:indicateLongPress Item " << item->modelIndex() << "long pressed at "
     << coords;
 
     if ( mGridView->selectionMode() == HbGridView::MultiSelection ){ //in multi selection mode no need to open the context menu
-    return ;
+    	return ;
     }
 
     if ( mModel ) {
-    mModel->setData( item->modelIndex(), item->modelIndex().row(), GlxFocusIndexRole );
+    	mModel->setData( item->modelIndex(), item->modelIndex().row(), GlxFocusIndexRole );
     }
     emit itemSpecificMenuTriggered(viewId(),coords);
-    }
+}