|
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 |
|
27 #include "mpcollectionlistcontainer.h" |
|
28 #include "mpcollectiondatamodel.h" |
|
29 #include "mpmpxcollectiondata.h" |
|
30 #include "mptrace.h" |
|
31 |
|
32 /*! |
|
33 \class MpCollectionListContainer |
|
34 \brief Music Player collection view base list container definition. |
|
35 |
|
36 Collection container is a base container that provides interface to |
|
37 be implemented by the specific collection context containers, e.g. |
|
38 All Songs, Artists, etc. Collection container owns UI elements such |
|
39 as the layout and the widgets. |
|
40 */ |
|
41 |
|
42 /*! |
|
43 Constructs the collection container. |
|
44 */ |
|
45 MpCollectionListContainer::MpCollectionListContainer( HbDocumentLoader *loader, QGraphicsItem *parent ) |
|
46 : MpCollectionContainer(loader, parent), |
|
47 mList(0), |
|
48 mEffectOnGoing(false) |
|
49 { |
|
50 TX_LOG |
|
51 } |
|
52 |
|
53 /*! |
|
54 Destructs the collection container. |
|
55 */ |
|
56 MpCollectionListContainer::~MpCollectionListContainer() |
|
57 { |
|
58 TX_LOG |
|
59 } |
|
60 |
|
61 /*! |
|
62 Initializes the collection container. Allocates all resources needed by the |
|
63 container. |
|
64 */ |
|
65 void MpCollectionListContainer::initialize() |
|
66 { |
|
67 TX_ENTRY |
|
68 HbEffect::add(QString("viewItem"), QString(":/effects/select.fxml"), |
|
69 QString("chosen") ); |
|
70 HbEffect::add(QString("viewItem"), QString(":/effects/select_end.fxml"), |
|
71 QString("chosenEnd") ); |
|
72 TX_EXIT |
|
73 } |
|
74 |
|
75 /*! |
|
76 Sets the data model for the container. |
|
77 */ |
|
78 void MpCollectionListContainer::setDataModel( MpCollectionDataModel *dataModel ) |
|
79 { |
|
80 TX_ENTRY |
|
81 MpCollectionContainer::setDataModel(dataModel); |
|
82 mList->setModel(0); |
|
83 mList->setModel(dataModel); |
|
84 TX_EXIT |
|
85 } |
|
86 |
|
87 /*! |
|
88 Slot to be called when an item is selected by the user. |
|
89 Start animation. |
|
90 */ |
|
91 void MpCollectionListContainer::itemActivated( const QModelIndex &index ) |
|
92 { |
|
93 TX_ENTRY_ARGS("index=" << index.row()); |
|
94 if ( !mEffectOnGoing ) { |
|
95 HbAbstractViewItem *listViewItem = mList->itemByIndex(index); |
|
96 mEffectOnGoing = true; |
|
97 mChosenIndex = index; |
|
98 HbEffect::start(listViewItem, QString("viewItem"), QString("chosen"), |
|
99 this, "itemChosenFxComplete1"); |
|
100 } |
|
101 TX_EXIT |
|
102 } |
|
103 |
|
104 /*! |
|
105 Slot to be called when an item is long pressed by the user. |
|
106 */ |
|
107 void MpCollectionListContainer::onLongPressed( HbAbstractViewItem *listViewItem, const QPointF &coords ) |
|
108 { |
|
109 TX_ENTRY |
|
110 emit MpCollectionContainer::itemLongPressed(listViewItem->modelIndex().row(), coords); |
|
111 TX_EXIT |
|
112 } |
|
113 |
|
114 /*! |
|
115 Slot for item selected effects part 1. |
|
116 */ |
|
117 void MpCollectionListContainer::itemChosenFxComplete1( |
|
118 const HbEffect::EffectStatus &status ) |
|
119 { |
|
120 Q_UNUSED(status); |
|
121 HbAbstractViewItem *listViewItem = mList->itemByIndex(mChosenIndex); |
|
122 HbEffect::start(listViewItem, QString("viewItem"), QString("chosenEnd"), |
|
123 this, "itemChosenFxComplete2"); |
|
124 } |
|
125 |
|
126 /*! |
|
127 Slot for item selected effects part 2. The end. |
|
128 */ |
|
129 void MpCollectionListContainer::itemChosenFxComplete2( |
|
130 const HbEffect::EffectStatus &status ) |
|
131 { |
|
132 Q_UNUSED(status); |
|
133 mEffectOnGoing = false; |
|
134 emit MpCollectionContainer::itemActivated( mChosenIndex.row() ); |
|
135 } |
|
136 |
|
137 |
|
138 /*! |
|
139 \internal |
|
140 */ |
|
141 void MpCollectionListContainer::initializeList() |
|
142 { |
|
143 mList->setItemRecycling(true); |
|
144 mList->setScrollingStyle( HbListView::PanOrFlick ); |
|
145 mList->setClampingStyle( HbListView::BounceBackClamping ); |
|
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 } |
|
158 |