ui/views/listview/src/glxlistview.cpp
changeset 72 0a8e959402e5
parent 71 27f2d7aec52a
equal deleted inserted replaced
71:27f2d7aec52a 72:0a8e959402e5
    36 #include "glxcommandhandlers.hrh"
    36 #include "glxcommandhandlers.hrh"
    37 #include "glxlocalisationstrings.h"
    37 #include "glxlocalisationstrings.h"
    38 
    38 
    39 GlxListView::GlxListView(HbMainWindow *window) 
    39 GlxListView::GlxListView(HbMainWindow *window) 
    40     : GlxView ( GLX_LISTVIEW_ID ), 
    40     : GlxView ( GLX_LISTVIEW_ID ), 
    41       mListView(NULL), 
    41       mListView( NULL ), 
    42       mView(NULL), 
    42       mView( NULL ), 
    43       mAlbumCount(NULL),
    43       mAlbumCount( NULL ),
    44       mWindow(window), 
    44       mWindow( window ), 
    45       mModel ( NULL),
    45       mModel ( NULL)
    46       mIsLongPress( false )
       
    47 {
    46 {
    48     qDebug("GlxListView::GlxListView()");
    47     qDebug("GlxListView::GlxListView()");
    49     mDocLoader = new HbDocumentLoader();
    48     mDocLoader = new HbDocumentLoader();
    50 }
    49 }
    51 
    50 
    52 void GlxListView::activate()
    51 void GlxListView::activate()
    53 {
    52 {
    54     qDebug("GlxListView::activate() %d", mWindow->orientation() );    
    53     qDebug("GlxListView::activate() %d", mWindow->orientation() );    
    55 
    54 
    56     if (mListView == NULL) {
    55     if ( !mListView ) {
    57         createListView();
    56         createListView();
    58     }
    57     }
    59  }
    58  }
    60 
    59 
    61 void GlxListView::deActivate()
    60 void GlxListView::deActivate()
    68     qDebug("GlxListView::setModel()");
    67     qDebug("GlxListView::setModel()");
    69     if ( mModel ) {
    68     if ( mModel ) {
    70         disconnect(mModel, SIGNAL(listPopulated()), this, SLOT( populated()));
    69         disconnect(mModel, SIGNAL(listPopulated()), this, SLOT( populated()));
    71         disconnect( mModel, SIGNAL( rowsInserted( QModelIndex, int, int ) ), this, SLOT( showAlbumCount() ) );
    70         disconnect( mModel, SIGNAL( rowsInserted( QModelIndex, int, int ) ), this, SLOT( showAlbumCount() ) );
    72         disconnect( mModel, SIGNAL( rowsRemoved( QModelIndex, int, int ) ), this, SLOT( showAlbumCount() ) );
    71         disconnect( mModel, SIGNAL( rowsRemoved( QModelIndex, int, int ) ), this, SLOT( showAlbumCount() ) );
       
    72 		disconnect( mModel, SIGNAL( destroyed() ), this, SLOT( modelDestroyed() ) );
    73     }
    73     }
    74     mModel =  model ;
    74     mModel =  model ;
    75     mListView->setModel(mModel);
    75     mListView->setModel(mModel);
    76     connect(mModel, SIGNAL(listPopulated()), this, SLOT( populated()));
    76     connect(mModel, SIGNAL(listPopulated()), this, SLOT( populated()));
    77     connect( mModel, SIGNAL( rowsInserted( QModelIndex, int, int ) ), this, SLOT( showAlbumCount() ) );
    77     connect( mModel, SIGNAL( rowsInserted( QModelIndex, int, int ) ), this, SLOT( showAlbumCount() ) );
    78     connect( mModel, SIGNAL( rowsRemoved( QModelIndex, int, int ) ), this, SLOT( showAlbumCount() ) );
    78     connect( mModel, SIGNAL( rowsRemoved( QModelIndex, int, int ) ), this, SLOT( showAlbumCount() ) );
       
    79     connect( mModel, SIGNAL( destroyed() ), this, SLOT( modelDestroyed() ) );
    79     showAlbumCount();
    80     showAlbumCount();
    80 }
    81 }
    81 
    82 
    82 void GlxListView::addToolBar( HbToolBar *toolBar ) 
    83 void GlxListView::addToolBar( HbToolBar *toolBar ) 
    83 {
    84 {
    86 
    87 
    87 void GlxListView::initializeView( QAbstractItemModel *model, GlxView *preView )
    88 void GlxListView::initializeView( QAbstractItemModel *model, GlxView *preView )
    88 {
    89 {
    89     Q_UNUSED( preView )
    90     Q_UNUSED( preView )
    90     qDebug("GlxListView::initializeView()");
    91     qDebug("GlxListView::initializeView()");
    91     if ( mListView == NULL ) {
    92     if ( !mListView ) {
    92         createListView();
    93         createListView();
    93     }
    94     }
    94     setModel( model );
    95     setModel( model );
    95 }
    96 }
    96 
    97 
    97 QGraphicsItem * GlxListView::getAnimationItem( GlxEffect transtionEffect )
    98 QGraphicsItem * GlxListView::getAnimationItem( GlxEffect transtionEffect )
    98 {
    99 {
    99     if ( transtionEffect == GRID_TO_ALBUMLIST  || transtionEffect == ALBUMLIST_TO_GRID ) {
   100     if ( transtionEffect == GRID_TO_ALBUMLIST  || transtionEffect == ALBUMLIST_TO_GRID ) {
   100         return mListView;
   101         return this;
   101     }
   102     }
   102     
   103     
   103     return NULL;
   104     return NULL;
   104 }
   105 }
   105 
   106 
   106 void GlxListView::addViewConnection ()
   107 void GlxListView::addViewConnection ()
   107 {
   108 {
   108     qDebug("GlxListView::addViewConnection()");
   109     qDebug("GlxListView::addViewConnection()");
   109     connect(mListView, SIGNAL(activated(const QModelIndex &)), this, SLOT( itemSelected(const QModelIndex &)));
   110     connect( mListView, SIGNAL( activated( const QModelIndex & ) ), this, SLOT( itemSelected( const QModelIndex & ) ) );
   110     connect(mListView, SIGNAL(longPressed( HbAbstractViewItem*, QPointF )),this, SLOT( indicateLongPress( HbAbstractViewItem*, QPointF ) ) );
   111     connect( mListView, SIGNAL( longPressed( HbAbstractViewItem*, QPointF ) ), this, SLOT( indicateLongPress( HbAbstractViewItem*, QPointF ) ) );
   111     connect( mListView, SIGNAL( scrollingEnded() ), this, SLOT( setVisvalWindowIndex() ) );
   112     connect( mListView, SIGNAL( scrollingEnded() ), this, SLOT( setVisvalWindowIndex() ) );
   112 }
   113 }
   113 
   114 
   114 void GlxListView::removeViewConnection()
   115 void GlxListView::removeViewConnection()
   115 {
   116 {
   116     qDebug("GlxListView::removeViewConnection()");
   117     qDebug("GlxListView::removeViewConnection()");
   117     disconnect(mListView, SIGNAL(activated(const QModelIndex &)), this, SLOT( itemSelected(const QModelIndex &)));
   118     disconnect( mListView, SIGNAL( activated( const QModelIndex & ) ), this, SLOT( itemSelected( const QModelIndex & ) ) );
   118     disconnect(mListView, SIGNAL(longPressed( HbAbstractViewItem*, QPointF )),this, SLOT( indicateLongPress( HbAbstractViewItem*, QPointF ) ) );
   119     disconnect( mListView, SIGNAL( longPressed( HbAbstractViewItem*, QPointF ) ), this, SLOT( indicateLongPress( HbAbstractViewItem*, QPointF ) ) );
   119     disconnect( mListView, SIGNAL( scrollingEnded() ), this, SLOT( setVisvalWindowIndex() ) );
   120     disconnect( mListView, SIGNAL( scrollingEnded() ), this, SLOT( setVisvalWindowIndex() ) );
   120 }
   121 }
   121 
   122 
   122 void GlxListView::setVisvalWindowIndex()
   123 void GlxListView::setVisvalWindowIndex()
   123 {
   124 {
   169 
   170 
   170 GlxListView::~GlxListView()
   171 GlxListView::~GlxListView()
   171 {
   172 {
   172     qDebug("GlxListView::~GlxListView()");
   173     qDebug("GlxListView::~GlxListView()");
   173 
   174 
   174     if(widget()) {
   175     if( widget() ) {
   175         qDebug("GlxListView::~GlxListView() takeWidget");
   176         qDebug("GlxListView::~GlxListView() takeWidget");
   176         takeWidget();    
   177         takeWidget();    
   177     }       
   178     }       
   178 
   179 
   179     removeViewConnection();
   180     removeViewConnection();
   180 
   181 
   181     if(mAlbumCount) {
   182     if( mAlbumCount ) {
   182         delete mAlbumCount ;
   183         delete mAlbumCount ;
   183         mAlbumCount = NULL;
   184         mAlbumCount = NULL;
   184     }
   185     }
   185 
   186 
   186     if(mListView) {
   187     if( mListView ) {
   187         delete mListView;
   188         delete mListView;
   188         mListView = NULL;
   189         mListView = NULL;
   189     }
   190     }
   190 
   191 
   191     if(mView) {
   192     if( mView ) {
   192         delete mView ;
   193         delete mView ;
   193         mView = NULL;
   194         mView = NULL;
   194     }
   195     }
   195     
   196     
   196     if(mDocLoader) {
   197     if( mDocLoader ) {
   197         delete mDocLoader;
   198         delete mDocLoader;
   198         mDocLoader = NULL;
   199         mDocLoader = NULL;
   199     }
   200     }
   200 }
   201 }
   201 
   202 
   208         visualIndex = variant.value<int>();
   209         visualIndex = variant.value<int>();
   209     }
   210     }
   210 	//Scroll To the Visible Index as mentioned in the AM.
   211 	//Scroll To the Visible Index as mentioned in the AM.
   211     mListView->scrollTo(mModel->index(visualIndex, 0),  HbAbstractItemView::PositionAtTop );
   212     mListView->scrollTo(mModel->index(visualIndex, 0),  HbAbstractItemView::PositionAtTop );
   212 }
   213 }
       
   214 
       
   215 void GlxListView::modelDestroyed()
       
   216 {
       
   217     mModel = NULL ;    
       
   218 }
       
   219 
   213 void GlxListView::itemSelected(const QModelIndex &  index)
   220 void GlxListView::itemSelected(const QModelIndex &  index)
   214 {
   221 {
   215     qDebug("GlxListView::itemSelected() index = %d", index.row() );
   222     qDebug("GlxListView::itemSelected() index = %d", index.row() );
   216     if ( mIsLongPress ) {
   223 
   217         mIsLongPress = false ;
       
   218         return ;
       
   219     }
       
   220     if ( mModel ) {
   224     if ( mModel ) {
   221         mModel->setData( index, index.row(), GlxFocusIndexRole );
   225         mModel->setData( index, index.row(), GlxFocusIndexRole );
   222     }
   226     }
   223     
   227     
   224     int curstate = NO_LIST_S; 
   228     int curstate = NO_LIST_S; 
   240 {
   244 {
   241     qDebug() << "GlxListView:indicateLongPress Item " << item->modelIndex() << "long pressed at " << coords;
   245     qDebug() << "GlxListView:indicateLongPress Item " << item->modelIndex() << "long pressed at " << coords;
   242     if ( mModel ) {
   246     if ( mModel ) {
   243         mModel->setData( item->modelIndex(), item->modelIndex().row(), GlxFocusIndexRole );
   247         mModel->setData( item->modelIndex(), item->modelIndex().row(), GlxFocusIndexRole );
   244     }
   248     }
   245     mIsLongPress = true;
       
   246     emit itemSpecificMenuTriggered(viewId(),coords);
   249     emit itemSpecificMenuTriggered(viewId(),coords);
   247 }
   250 }
   248 
   251 
   249 void GlxListView::showAlbumCount()
   252 void GlxListView::showAlbumCount()
   250 {
   253 {
   251     int albumCnt = mModel->rowCount();
   254     int albumCnt = mModel->rowCount();
   252     QString text = HbParameterLengthLimiter(GLX_ALBUM_LIST_COUNT_LABEL, albumCnt);
   255     QString text = HbParameterLengthLimiter(GLX_ALBUM_LIST_COUNT_LABEL).arg(albumCnt);
   253     mAlbumCount->setHeading(text);
   256     mAlbumCount->setHeading(text);
   254 }
   257 }