|
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: ?Description |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 //Includes |
|
20 #include <QDebug> |
|
21 #include <hbmenu.h> |
|
22 #include <hbtoolbar.h> |
|
23 #include <hblistview.h> |
|
24 #include <hbmainwindow.h> |
|
25 #include <hbdocumentloader.h> |
|
26 #include <hbabstractviewitem.h> |
|
27 |
|
28 //User Includes |
|
29 #include "glxviewids.h" |
|
30 #include "glxlistview.h" |
|
31 #include "glxmodelparm.h" |
|
32 #include "glxdocloaderdefs.h" |
|
33 #include "glxcommandhandlers.hrh" |
|
34 |
|
35 |
|
36 GlxListView::GlxListView(HbMainWindow *window) : GlxView ( GLX_LISTVIEW_ID ), |
|
37 mListView(NULL), mView(NULL), mWindow(window), mModel ( NULL) |
|
38 { |
|
39 qDebug("GlxListView::GlxListView()"); |
|
40 mDocLoader = new HbDocumentLoader(); |
|
41 setContentFullScreen( true ); |
|
42 } |
|
43 |
|
44 void GlxListView::activate() |
|
45 { |
|
46 qDebug("GlxListView::activate() %d", mWindow->orientation() ); |
|
47 |
|
48 if (mListView == NULL) { |
|
49 createListView(); |
|
50 } |
|
51 } |
|
52 |
|
53 void GlxListView::deActivate() |
|
54 { |
|
55 qDebug("GlxListView::deActivate()"); |
|
56 disconnect(mWindow, SIGNAL(orientationChanged(Qt::Orientation)), this, SLOT(orientationChanged(Qt::Orientation))); |
|
57 takeToolBar(); //To:Do improved later |
|
58 emit toolBarChanged(); |
|
59 } |
|
60 |
|
61 void GlxListView::setModel(QAbstractItemModel *model) |
|
62 { |
|
63 qDebug("GlxListView::setModel()"); |
|
64 mModel = model ; |
|
65 mListView->setModel(mModel); |
|
66 } |
|
67 |
|
68 void GlxListView::addToolBar( HbToolBar *toolBar ) |
|
69 { |
|
70 //toolBar->setParent(this); |
|
71 if ( mListView ) { |
|
72 toolBar->setZValue(mListView->zValue()); |
|
73 } |
|
74 setToolBar(toolBar) ; |
|
75 } |
|
76 |
|
77 void GlxListView::initializeView(QAbstractItemModel *model) |
|
78 { |
|
79 qDebug("GlxListView::initializeView()"); |
|
80 if (mListView == NULL) { |
|
81 createListView(); |
|
82 } |
|
83 setModel(model); |
|
84 } |
|
85 |
|
86 QGraphicsItem * GlxListView::getAnimationItem( GlxEffect transtionEffect ) |
|
87 { |
|
88 if ( transtionEffect == GRID_TO_ALBUMLIST || transtionEffect == ALBUMLIST_TO_GRID ) { |
|
89 return mListView; |
|
90 } |
|
91 |
|
92 return NULL; |
|
93 } |
|
94 |
|
95 void GlxListView::addViewConnection () |
|
96 { |
|
97 qDebug("GlxListView::addViewConnection()"); |
|
98 connect(mListView, SIGNAL(activated(const QModelIndex &)), this, SLOT( itemSelected(const QModelIndex &))); |
|
99 connect(mListView, SIGNAL(longPressed( HbAbstractViewItem*, QPointF )),this, SLOT( indicateLongPress( HbAbstractViewItem*, QPointF ) ) ); |
|
100 } |
|
101 |
|
102 void GlxListView::removeViewConnection() |
|
103 { |
|
104 qDebug("GlxListView::removeViewConnection()"); |
|
105 disconnect(mListView, SIGNAL(activated(const QModelIndex &)), this, SLOT( itemSelected(const QModelIndex &))); |
|
106 disconnect(mListView, SIGNAL(longPressed( HbAbstractViewItem*, QPointF )),this, SLOT( indicateLongPress( HbAbstractViewItem*, QPointF ) ) ); |
|
107 } |
|
108 |
|
109 void GlxListView::loadListView() |
|
110 { |
|
111 qDebug("GlxListView::loadListView()"); |
|
112 bool loaded = true; |
|
113 //Load the widgets accroding to the current Orientation |
|
114 if (mListView == NULL ) |
|
115 { |
|
116 mDocLoader->load(GLX_LISTVIEW_DOCMLPATH,&loaded); |
|
117 if(loaded) |
|
118 { |
|
119 //retrieve the widgets |
|
120 mView = static_cast<HbView*>(mDocLoader->findWidget(QString(GLX_LISTVIEW_VIEW))); |
|
121 mListView = static_cast<HbListView*>(mDocLoader->findWidget(QString(GLX_LISTVIEW_LIST))); |
|
122 |
|
123 if(mListView) |
|
124 { |
|
125 //sets the widget |
|
126 setWidget((QGraphicsWidget*) mView); |
|
127 } |
|
128 } |
|
129 } |
|
130 } |
|
131 |
|
132 void GlxListView::createListView() |
|
133 { |
|
134 qDebug("GlxListView::createListView()"); |
|
135 loadListView(); |
|
136 addViewConnection(); //only one time add the connection and remove in side the destructor |
|
137 } |
|
138 |
|
139 GlxListView::~GlxListView() |
|
140 { |
|
141 qDebug("GlxListView::~GlxListView()"); |
|
142 |
|
143 if(widget()) |
|
144 { |
|
145 qDebug("GlxListView::~GlxListView() takeWidget"); |
|
146 takeWidget(); |
|
147 } |
|
148 |
|
149 removeViewConnection(); |
|
150 |
|
151 if(mListView) |
|
152 { |
|
153 delete mListView; |
|
154 mListView = NULL; |
|
155 } |
|
156 |
|
157 if(mView) |
|
158 { |
|
159 delete mView ; |
|
160 mView = NULL; |
|
161 } |
|
162 if(mDocLoader) |
|
163 { |
|
164 delete mDocLoader; |
|
165 mDocLoader = NULL; |
|
166 } |
|
167 } |
|
168 |
|
169 void GlxListView::itemSelected(const QModelIndex & index) |
|
170 { |
|
171 qDebug("GlxListView::itemSelected() index = %d", index.row() ); |
|
172 if ( mModel ) { |
|
173 mModel->setData( index, index.row(), GlxFocusIndexRole ); |
|
174 } |
|
175 emit actionTriggered( EGlxCmdAlbumGridOpen ); |
|
176 } |
|
177 |
|
178 |
|
179 void GlxListView::indicateLongPress(HbAbstractViewItem *item, QPointF coords) |
|
180 { |
|
181 qDebug() << "GlxListView:indicateLongPress Item " << item->modelIndex() << "long pressed at " << coords; |
|
182 if ( mModel ) { |
|
183 mModel->setData( item->modelIndex(), item->modelIndex().row(), GlxFocusIndexRole ); |
|
184 } |
|
185 emit itemSpecificMenuTriggered(viewId(),coords); |
|
186 } |
|
187 |