mpviewplugins/mpcollectionviewplugin/src/mpcollectionlistcontainer.cpp
branchRCL_3
changeset 25 14979e23cb5e
equal deleted inserted replaced
24:26a1709b9fec 25:14979e23cb5e
       
     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: Music Player collection view base list container definition.
       
    15 *
       
    16 */
       
    17 
       
    18 // INCLUDE FILES
       
    19 #include <QtCore>
       
    20 #include <QGraphicsGridLayout>
       
    21 
       
    22 #include <hblistview.h>
       
    23 #include <hbabstractviewitem.h>
       
    24 #include <hblistviewitem.h>
       
    25 #include <hbscrollbar.h>
       
    26 #include <hbdocumentloader.h>
       
    27 #include <hblabel.h>
       
    28 #include <hbindexfeedback.h>
       
    29 
       
    30 #include "mpcollectionlistcontainer.h"
       
    31 #include "mpcollectiondatamodel.h"
       
    32 #include "mpmpxcollectiondata.h"
       
    33 #include "mptrace.h"
       
    34 
       
    35 /*!
       
    36     \class MpCollectionListContainer
       
    37     \brief Music Player collection view base list container definition.
       
    38 
       
    39     Collection container is a base container that provides interface to
       
    40     be implemented by the specific collection context containers, e.g.
       
    41     All Songs, Artists, etc. Collection container owns UI elements such
       
    42     as the layout and the widgets.
       
    43 */
       
    44 
       
    45 /*!
       
    46  Constructs the collection container.
       
    47  */
       
    48 MpCollectionListContainer::MpCollectionListContainer( HbDocumentLoader *loader, QGraphicsItem *parent )
       
    49     : MpCollectionContainer(loader, parent),
       
    50       mList(0),
       
    51       mNoMusic(0),
       
    52       mIndexFeedback(0),
       
    53       mLongPressedIndex(0),
       
    54       mLongPressEnabled(true)
       
    55 {
       
    56     TX_ENTRY
       
    57     mIndexFeedback = new HbIndexFeedback();
       
    58     mIndexFeedback->setIndexFeedbackPolicy(HbIndexFeedback::IndexFeedbackSingleCharacter);
       
    59     TX_EXIT
       
    60 }
       
    61 
       
    62 /*!
       
    63  Destructs the collection container.
       
    64  */
       
    65 MpCollectionListContainer::~MpCollectionListContainer()
       
    66 {
       
    67     TX_ENTRY
       
    68     delete mNoMusic;
       
    69     delete mIndexFeedback;
       
    70     TX_EXIT
       
    71 }
       
    72 
       
    73 /*!
       
    74  Initializes the collection container. Allocates all resources needed by the
       
    75  container.
       
    76  */
       
    77 void MpCollectionListContainer::initialize()
       
    78 {
       
    79     TX_LOG
       
    80 }
       
    81 
       
    82 /*!
       
    83  Sets the data model for the container.
       
    84  */
       
    85 void MpCollectionListContainer::setDataModel( MpCollectionDataModel *dataModel )
       
    86 {
       
    87     TX_ENTRY
       
    88     MpCollectionContainer::setDataModel(dataModel);
       
    89     if ( mList ) {
       
    90         mList->setModel(dataModel);
       
    91     }
       
    92     TX_EXIT
       
    93 }
       
    94 
       
    95 /*!
       
    96  Slot to be called when an item is selected by the user.
       
    97  */
       
    98 void MpCollectionListContainer::itemActivated( const QModelIndex &index )
       
    99 {
       
   100     TX_ENTRY_ARGS("index=" << index.row());
       
   101     emit MpCollectionContainer::itemActivated( index.row() );
       
   102     TX_EXIT
       
   103 }
       
   104 
       
   105 /*!
       
   106  Slot to be called when an item is long pressed by the user.
       
   107  Remember the index so that we can scroll to this vicinity if the data is reloaded, for example,
       
   108  after a delete operation is selected from the context menu.
       
   109  */
       
   110 void MpCollectionListContainer::onLongPressed( HbAbstractViewItem *listViewItem, const QPointF &coords )
       
   111 {
       
   112     TX_ENTRY
       
   113     if ( mLongPressEnabled ) {
       
   114         mLongPressedIndex = listViewItem->modelIndex().row();
       
   115         emit MpCollectionContainer::itemLongPressed(mLongPressedIndex, coords);
       
   116     }
       
   117     TX_EXIT
       
   118 }
       
   119 
       
   120 /*!
       
   121  Slot to be called data model has new data. 
       
   122  If the data is reloaded as a result of operation like delete, we want to scroll to the 
       
   123  nearby area where user has performed the action.
       
   124  
       
   125  \sa onLongPressed
       
   126  */
       
   127 void MpCollectionListContainer::dataReloaded()
       
   128 {
       
   129     TX_ENTRY
       
   130     if ( mLongPressedIndex > 0 ) {
       
   131         --mLongPressedIndex;
       
   132     }
       
   133     if ( mList ) {
       
   134         mList->scrollTo( mDataModel->index(mLongPressedIndex, 0) );
       
   135     }
       
   136     TX_EXIT
       
   137 }
       
   138 
       
   139 /*!
       
   140  \internal
       
   141  */
       
   142 void MpCollectionListContainer::initializeList()
       
   143 {
       
   144     TX_ENTRY
       
   145     mList->setItemRecycling(true);
       
   146     mList->setLongPressEnabled(true);
       
   147 
       
   148     connect(mList, SIGNAL(activated(QModelIndex)), this, SLOT(itemActivated(QModelIndex)));
       
   149     connect(mList, SIGNAL(longPressed(HbAbstractViewItem*, QPointF)), this, SLOT(onLongPressed(HbAbstractViewItem*, QPointF)));
       
   150 
       
   151     HbScrollBar *scrollbar = mList->verticalScrollBar();
       
   152     scrollbar->show();
       
   153     scrollbar->setInteractive(true);
       
   154     mList->setVerticalScrollBarPolicy(HbScrollArea::ScrollBarAsNeeded);
       
   155 
       
   156     mList->listItemPrototype()->setGraphicsSize(HbListViewItem::Thumbnail);
       
   157     TX_EXIT
       
   158 }
       
   159 
       
   160 /*!
       
   161  \internal
       
   162  */
       
   163 void MpCollectionListContainer::setupEmptyListContainer()
       
   164 {
       
   165     TX_ENTRY
       
   166     bool ok = false;
       
   167     mDocumentLoader->load(QString(":/docml/musiccollection.docml"), "emptyList", &ok);
       
   168     if ( !ok ) {
       
   169         TX_LOG_ARGS("Error: invalid xml file.");
       
   170         Q_ASSERT_X(ok, "MpCollectionListContainer::setupContainer", "invalid xml file");
       
   171     }
       
   172 
       
   173     QGraphicsWidget *widget;
       
   174     widget = mDocumentLoader->findWidget(QString("noMusic"));
       
   175     mNoMusic = qobject_cast<HbLabel*>(widget);
       
   176     TX_EXIT
       
   177 }
       
   178