|
1 /* |
|
2 * Copyright (c) 2010 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: LocationPickerLandscapeView implementation |
|
15 * |
|
16 */ |
|
17 |
|
18 #include "locationpickerlandscapeview.h" |
|
19 |
|
20 #include <qstandarditemmodel.h> |
|
21 #include <HbMainWindow> |
|
22 #include <HbGridViewItem> |
|
23 #include <HbGridView> |
|
24 #include <HbStyleLoader> |
|
25 #include <HbAction> |
|
26 |
|
27 #include "locationpickerproxymodel.h" |
|
28 #include "locationpickerdatamanager.h" |
|
29 #include "locationpickercontent.h" |
|
30 #include "locationpickercollectionlistcontent.h" |
|
31 #include "locationpickercollectioncontent.h" |
|
32 |
|
33 |
|
34 // ---------------------------------------------------- |
|
35 // LocationPickerLandscapeView::LocationPickerLandscapeView() |
|
36 // ---------------------------------------------------- |
|
37 LocationPickerLandscapeView::LocationPickerLandscapeView(HbDocumentLoader* aLoader) |
|
38 :mDocumentLoader(aLoader), |
|
39 mLocationPickerContent(NULL), |
|
40 mLocationPickerCollectionListContent(NULL), |
|
41 mAllAction(NULL), |
|
42 mCollectionAction(NULL), |
|
43 mSearchAction(NULL), |
|
44 mAscendingAction(NULL), |
|
45 mDescendingAction(NULL), |
|
46 mGridView(NULL), |
|
47 mCollectionContent(NULL), |
|
48 mGridViewItem(NULL), |
|
49 mViewType(ELocationPickerContent) |
|
50 { |
|
51 HbStyleLoader::registerFilePath(":/locationgrid.css"); |
|
52 HbStyleLoader::registerFilePath(":/locationgrid.hbgridviewitem.widgetml"); |
|
53 //create grid view item |
|
54 mGridViewItem = new HbGridViewItem(); |
|
55 mGridViewItem->setObjectName("locationgrid"); |
|
56 |
|
57 // create back action |
|
58 mLandscapeBackAction = new HbAction(Hb::BackAction); |
|
59 setNavigationAction(mLandscapeBackAction); |
|
60 connect(mLandscapeBackAction, SIGNAL(triggered()), this, |
|
61 SLOT(backButtonTriggered())); |
|
62 } |
|
63 // ---------------------------------------------------- |
|
64 // LocationPickerPotraitView::~LocationPickerLandscapeView() |
|
65 // ---------------------------------------------------- |
|
66 LocationPickerLandscapeView::~LocationPickerLandscapeView() |
|
67 { |
|
68 delete mCollectionContent; |
|
69 delete mLocationPickerContent; |
|
70 delete mLocationPickerCollectionListContent; |
|
71 delete mAllAction; |
|
72 delete mCollectionAction; |
|
73 delete mAscendingAction; |
|
74 delete mDescendingAction; |
|
75 } |
|
76 |
|
77 // ---------------------------------------------------------------------------- |
|
78 // LocationPickerPotraitView::backButtonTriggered() |
|
79 // ---------------------------------------------------------------------------- |
|
80 void LocationPickerLandscapeView::backButtonTriggered() |
|
81 { |
|
82 //if current model is collection content, go back to collectionlist content |
|
83 if(mViewType == ELocationPickerCollectionContent) |
|
84 { |
|
85 colectionTabTriggered(); |
|
86 delete mCollectionContent; |
|
87 mCollectionContent=NULL; |
|
88 } |
|
89 else |
|
90 { |
|
91 //complete the service |
|
92 emit completeService(); |
|
93 } |
|
94 } |
|
95 |
|
96 |
|
97 // ---------------------------------------------------- |
|
98 // LocationPickerPotraitView::~init() |
|
99 // ---------------------------------------------------- |
|
100 void LocationPickerLandscapeView::init(Qt::Orientation aOrientation ) |
|
101 { |
|
102 // Create Collection List Content |
|
103 mLocationPickerCollectionListContent = new LocationPickerCollectionListContent(aOrientation); |
|
104 |
|
105 mLocationPickerContent = new LocationPickerContent(aOrientation); |
|
106 |
|
107 //Get HbAction items |
|
108 mGridView = qobject_cast<HbGridView*> (mDocumentLoader->findObject(QString( |
|
109 "gridView"))); |
|
110 //get the action items from docml |
|
111 mAllAction = qobject_cast<HbAction*> (mDocumentLoader->findObject(QString( |
|
112 "allAction"))); |
|
113 mCollectionAction = qobject_cast<HbAction*> (mDocumentLoader->findObject( |
|
114 QString("collectionAction"))); |
|
115 mSearchAction = qobject_cast<HbAction*> (mDocumentLoader->findObject(QString( |
|
116 "searchAction"))); |
|
117 mAscendingAction = qobject_cast<HbAction*> (mDocumentLoader->findObject( |
|
118 QString("ascendingAction"))); |
|
119 mDescendingAction = qobject_cast<HbAction*> (mDocumentLoader->findObject( |
|
120 QString("descendingAction"))); |
|
121 if( !mAllAction || !mCollectionAction || !mSearchAction || !mGridView || !mAscendingAction || !mDescendingAction) |
|
122 { |
|
123 qFatal("Error Reading Docml"); |
|
124 } |
|
125 |
|
126 //connect to slots |
|
127 connect(mAscendingAction, SIGNAL(triggered()), this, SLOT(sortAscending())); |
|
128 connect(mDescendingAction, SIGNAL(triggered()), this, |
|
129 SLOT(sortDescending())); |
|
130 //connect all action Items to respective slots |
|
131 connect(mAllAction, SIGNAL(triggered()), this, SLOT(allTabTriggered())); |
|
132 connect(mCollectionAction, SIGNAL(triggered()), this,SLOT(colectionTabTriggered())); |
|
133 connect(mSearchAction, SIGNAL(triggered()), this, |
|
134 SLOT(searchTabTriggered())); |
|
135 |
|
136 connect(mGridView, SIGNAL(activated(const QModelIndex &)), this, SLOT(handleActivated(const QModelIndex &))); |
|
137 } |
|
138 |
|
139 |
|
140 void LocationPickerLandscapeView::manageGridView() |
|
141 { |
|
142 // Create Locationpicker Content |
|
143 if (!mLocationPickerContent->locationsFound()) |
|
144 { |
|
145 //if no location entries present |
|
146 mGridView->setModel(mLocationPickerContent->getStandardModel(),mGridViewItem); |
|
147 disableTabs(); |
|
148 mViewType = ELocationPickerContent; |
|
149 } |
|
150 else |
|
151 { |
|
152 //set the appropriate model |
|
153 switch(mViewType) |
|
154 { |
|
155 case ELocationPickerContent: |
|
156 { |
|
157 mGridView->setModel(mLocationPickerContent->getGridProxyModel(),mGridViewItem); |
|
158 mAllAction->setChecked(true); |
|
159 mCollectionAction->setChecked(false); |
|
160 } |
|
161 break; |
|
162 case ELocationPickerCollectionContent: |
|
163 { |
|
164 setCollectionData(mCategoryId); |
|
165 mCollectionAction->setChecked(true); |
|
166 mAllAction->setChecked(false); |
|
167 } |
|
168 break; |
|
169 } |
|
170 } |
|
171 } |
|
172 |
|
173 void LocationPickerLandscapeView::disableTabs() |
|
174 { |
|
175 mAllAction->setDisabled(true); |
|
176 mCollectionAction->setDisabled(true); |
|
177 mSearchAction->setDisabled(true); |
|
178 mAscendingAction->setDisabled(true); |
|
179 mDescendingAction->setDisabled(true); |
|
180 } |
|
181 |
|
182 |
|
183 // ----------------------------------------------------------------------------- |
|
184 // LocationPickerLandscapeView::handleActivated() |
|
185 // ----------------------------------------------------------------------------- |
|
186 void LocationPickerLandscapeView::handleActivated(const QModelIndex &aIndex) |
|
187 { |
|
188 //handle the activated signal according to model set |
|
189 |
|
190 switch(mViewType) |
|
191 { |
|
192 case ELocationPickerContent: |
|
193 { |
|
194 QModelIndex index = mLocationPickerContent->getGridProxyModel()->mapToSource( |
|
195 aIndex); |
|
196 quint32 lm = 0; |
|
197 mLocationPickerContent->getDataManager()->getData(index.row(), lm); |
|
198 emit selectItem( lm ); |
|
199 } |
|
200 break; |
|
201 case ELocationPickerCollectionListContent: |
|
202 { |
|
203 mLocationPickerCollectionListContent->getDataManager()->getData( |
|
204 aIndex.row(), mCategoryId); |
|
205 setCollectionData(mCategoryId); |
|
206 emit sendCategoryID(mCategoryId); |
|
207 } |
|
208 break; |
|
209 //default |
|
210 case ELocationPickerCollectionContent: |
|
211 { |
|
212 QModelIndex index = mCollectionContent->getProxyModel()->mapToSource( |
|
213 aIndex); |
|
214 quint32 lm = 0; |
|
215 mCollectionContent->getDataManager()->getData(index.row(), lm); |
|
216 emit selectItem(lm); |
|
217 } |
|
218 break; |
|
219 default: |
|
220 break; |
|
221 } |
|
222 } |
|
223 |
|
224 |
|
225 |
|
226 // ----------------------------------------------------------------------------- |
|
227 // LocationPickerLandscapeView::sortAscending() |
|
228 // ----------------------------------------------------------------------------- |
|
229 void LocationPickerLandscapeView::sortAscending() |
|
230 { |
|
231 //check the model set and do sorting accordingly |
|
232 if (mViewType == ELocationPickerContent) |
|
233 { |
|
234 mLocationPickerContent->getGridProxyModel()->sort(0, Qt::AscendingOrder); |
|
235 } |
|
236 else |
|
237 { |
|
238 mCollectionContent->getProxyModel()->sort(0, Qt::AscendingOrder); |
|
239 } |
|
240 } |
|
241 |
|
242 // ----------------------------------------------------------------------------- |
|
243 // LocationPickerLandscapeView::sortDescending() |
|
244 // ----------------------------------------------------------------------------- |
|
245 void LocationPickerLandscapeView::sortDescending() |
|
246 { |
|
247 //check the model set and do sorting accordingly |
|
248 if (mViewType == ELocationPickerContent) |
|
249 { |
|
250 mLocationPickerContent->getGridProxyModel()->sort(0, Qt::DescendingOrder); |
|
251 } |
|
252 else |
|
253 { |
|
254 mCollectionContent->getProxyModel()->sort(0, Qt::DescendingOrder); |
|
255 } |
|
256 } |
|
257 |
|
258 // ----------------------------------------------------------------------------- |
|
259 // LocationPickerLandscapeView::handleAllTab() |
|
260 // ----------------------------------------------------------------------------- |
|
261 void LocationPickerLandscapeView::allTabTriggered() |
|
262 { |
|
263 //execute only if tab is not pressed |
|
264 if (mAllAction->isChecked()) |
|
265 { |
|
266 mGridView->setModel(mLocationPickerContent->getGridProxyModel(),mGridViewItem); |
|
267 mAscendingAction->setEnabled(true); |
|
268 mDescendingAction->setEnabled(true); |
|
269 mCollectionAction->setChecked(false); |
|
270 mViewType = ELocationPickerContent; |
|
271 //delete mCollectionContent if coming back from collectioncontent |
|
272 if (mCollectionContent) |
|
273 { |
|
274 delete mCollectionContent; |
|
275 mCollectionContent = NULL; |
|
276 } |
|
277 } |
|
278 else |
|
279 { |
|
280 //Keep the tab pressed |
|
281 mAllAction->setChecked(true); |
|
282 } |
|
283 |
|
284 } |
|
285 |
|
286 // ----------------------------------------------------------------------------- |
|
287 // LocationPickerLandscapeView::handleCollectionTab() |
|
288 // ----------------------------------------------------------------------------- |
|
289 void LocationPickerLandscapeView::colectionTabTriggered() |
|
290 { |
|
291 //execute only if tab is not pressed |
|
292 if (mCollectionAction->isChecked()) |
|
293 { |
|
294 mViewType = ELocationPickerCollectionListContent; |
|
295 emit handleCollectionList(); |
|
296 } |
|
297 else |
|
298 { |
|
299 //Keep the tab pressed |
|
300 mCollectionAction->setChecked(true); |
|
301 } |
|
302 } |
|
303 |
|
304 // ----------------------------------------------------------------------------- |
|
305 // LocationPickerLandscapeView::searchTabTriggered() |
|
306 // ----------------------------------------------------------------------------- |
|
307 void LocationPickerLandscapeView::searchTabTriggered() |
|
308 { |
|
309 emit switchToSearchView(); |
|
310 } |
|
311 |
|
312 void LocationPickerLandscapeView::setCollectionData( quint32 aCategoryId ) |
|
313 { |
|
314 mCollectionContent |
|
315 = new LocationPickerCollectionContent(this->mainWindow()->orientation() , aCategoryId); |
|
316 mGridView->setModel(mCollectionContent->getProxyModel(),mGridViewItem); |
|
317 mViewType = ELocationPickerCollectionContent; |
|
318 //Enable the options |
|
319 mAscendingAction->setEnabled(true); |
|
320 mDescendingAction->setEnabled(true); |
|
321 mCollectionAction->setChecked(true); |
|
322 } |
|
323 |
|
324 // ----------------------------------------------------------------------------- |
|
325 // LocationPickerLandscapeView::setCategoryID() |
|
326 // ----------------------------------------------------------------------------- |
|
327 void LocationPickerLandscapeView::setCategoryID( quint32 aCategoryId ) |
|
328 { |
|
329 mCategoryId = aCategoryId; |
|
330 } |
|
331 |
|
332 // ----------------------------------------------------------------------------- |
|
333 // LocationPickerLandscapeView::getViewType() |
|
334 // ----------------------------------------------------------------------------- |
|
335 TViewType LocationPickerLandscapeView::getViewType() |
|
336 { |
|
337 return mViewType; |
|
338 } |
|
339 |
|
340 // ----------------------------------------------------------------------------- |
|
341 // LocationPickerLandscapeView::setViewType() |
|
342 // ----------------------------------------------------------------------------- |
|
343 void LocationPickerLandscapeView::setViewType(TViewType aViewType) |
|
344 { |
|
345 mViewType = aViewType; |
|
346 } |