|
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: LocationPickerView implementation |
|
15 * |
|
16 */ |
|
17 |
|
18 #include "locationpickerview.h" |
|
19 |
|
20 #include <HbMainWindow> |
|
21 #include <qstandarditemmodel.h> |
|
22 #include <HbListView> |
|
23 #include <HbListViewItem> |
|
24 #include <HbAction> |
|
25 #include <HbMenu> |
|
26 #include <HbToolBar> |
|
27 #include <HbStyleLoader> |
|
28 #include <QGraphicsLinearLayout> |
|
29 #include <HbDialog> |
|
30 |
|
31 #include "hgwidgetdatamodel.h" |
|
32 #include "locationpickerproxymodel.h" |
|
33 #include "locationpickerdatamanager.h" |
|
34 #include "locationpickercontent.h" |
|
35 #include "locationpickercollectionlistcontent.h" |
|
36 #include "locationpickercollectioncontent.h" |
|
37 |
|
38 // ======== MEMBER FUNCTIONS ======== |
|
39 |
|
40 // ---------------------------------------------------- |
|
41 // LocationPickerView::LocationPickerView() |
|
42 // ---------------------------------------------------- |
|
43 LocationPickerView::LocationPickerView( HbDocumentLoader* aLoader ) |
|
44 :mDocumentLoader(aLoader), |
|
45 mLocationPickerCollectionListContent(NULL), |
|
46 mProxyModel(NULL), |
|
47 mAllAction(NULL), |
|
48 mCollectionAction(NULL), |
|
49 mSearchAction(NULL), |
|
50 mAscendingAction(NULL), |
|
51 mDescendingAction(NULL), |
|
52 mListView(NULL), |
|
53 mCollectionContent(NULL), |
|
54 mViewType(ELocationPickerContent), |
|
55 mLinerLayout(NULL), |
|
56 mColllabel(NULL), |
|
57 mEmptyLabel(NULL), |
|
58 mDialog(NULL), |
|
59 mMapIconLabel(NULL), |
|
60 mTitleLabel(NULL), |
|
61 mAddressMiddle(NULL), |
|
62 mAddressBottom(NULL), |
|
63 mLongPressMenu(NULL), |
|
64 mSelectAction(NULL), |
|
65 mDetailsAction(NULL), |
|
66 mPopulated(false) |
|
67 { |
|
68 //Create Action Items |
|
69 mAllAction = qobject_cast<HbAction*> (mDocumentLoader->findObject( |
|
70 QString("allAction"))); |
|
71 mCollectionAction = qobject_cast<HbAction*> (mDocumentLoader->findObject( |
|
72 QString("collectionAction"))); |
|
73 mSearchAction = qobject_cast<HbAction*> (mDocumentLoader->findObject( |
|
74 QString("searchAction"))); |
|
75 mAscendingAction = qobject_cast<HbAction*> (mDocumentLoader->findObject( |
|
76 QString("ascendingAction"))); |
|
77 mDescendingAction = qobject_cast<HbAction*> (mDocumentLoader->findObject( |
|
78 QString("descendingAction"))); |
|
79 if( !mAllAction || !mCollectionAction || !mSearchAction || !mAscendingAction || !mDescendingAction ) |
|
80 { |
|
81 qFatal("Error Reading Docml"); |
|
82 } |
|
83 // create back action |
|
84 mBackAction = new HbAction(Hb::BackNaviAction); |
|
85 // add back key action |
|
86 setNavigationAction(mBackAction); |
|
87 //connect to slots |
|
88 connect(mBackAction, SIGNAL(triggered()), this, |
|
89 SLOT(backTriggered())); |
|
90 //create list item |
|
91 mListItem = new HbListViewItem(); |
|
92 //set the graphics size |
|
93 mListItem->setGraphicsSize(HbListViewItem::Thumbnail); |
|
94 } |
|
95 // ---------------------------------------------------- |
|
96 // LocationPickerView::~LocationPickerView() |
|
97 // ---------------------------------------------------- |
|
98 LocationPickerView::~LocationPickerView() |
|
99 { |
|
100 delete mListItem; |
|
101 delete mBackAction; |
|
102 if(mPopulated) |
|
103 { |
|
104 mLinerLayout->removeItem(mListView); |
|
105 mLinerLayout->removeItem(mWidget); |
|
106 delete mCollectionContent; |
|
107 delete mLocationPickerCollectionListContent; |
|
108 delete mListView; |
|
109 delete mWidget; |
|
110 delete mHgModel; |
|
111 delete mProxyModel; |
|
112 delete mColllabel; |
|
113 } |
|
114 } |
|
115 |
|
116 // ---------------------------------------------------------------------------- |
|
117 // LocationPickerView::backButtonTriggered() |
|
118 // ---------------------------------------------------------------------------- |
|
119 void LocationPickerView::backTriggered() |
|
120 { |
|
121 //if current model is collection content, go back to collectionlist content |
|
122 if(mViewType == ELocationPickerCollectionContent) |
|
123 { |
|
124 removeDetailsLabel(); |
|
125 colectionTabTriggered(); |
|
126 clearContentModel(); |
|
127 } |
|
128 else |
|
129 { |
|
130 //complete the service |
|
131 emit completeService(); |
|
132 } |
|
133 |
|
134 } |
|
135 |
|
136 |
|
137 // ---------------------------------------------------- |
|
138 // LocationPickerView::init() |
|
139 // ---------------------------------------------------- |
|
140 void LocationPickerView::init( Qt::Orientation aOrientation, QStandardItemModel *aModel ) |
|
141 { |
|
142 mPopulated = true; |
|
143 // Create Collection List Content |
|
144 mLocationPickerCollectionListContent = new LocationPickerCollectionListContent(); |
|
145 mModel = aModel; |
|
146 // Create Collection List Content |
|
147 mLocationPickerCollectionListContent = new LocationPickerCollectionListContent(); |
|
148 //create proxy model |
|
149 mProxyModel = new LocationPickerProxyModel( this ); |
|
150 mProxyModel->setSourceModel(aModel); |
|
151 // set sort properties |
|
152 mProxyModel->setDynamicSortFilter(TRUE); |
|
153 mProxyModel->setSortRole(Qt::DisplayRole); |
|
154 mProxyModel->setSortCaseSensitivity(Qt::CaseInsensitive); |
|
155 // sort in ascending order |
|
156 mProxyModel->sort(0, Qt::AscendingOrder); |
|
157 mLinerLayout = static_cast<QGraphicsLinearLayout*>(widget()->layout()); |
|
158 //Get HbAction items |
|
159 mListView = new HbListView(); |
|
160 mColllabel = new HbLabel(); |
|
161 createHurriganesWidget(); |
|
162 mWidget->setModel(mHgModel); |
|
163 //connect to slots |
|
164 connect(mAscendingAction, SIGNAL(triggered()), this, SLOT(sortAscending())); |
|
165 connect(mDescendingAction, SIGNAL(triggered()), this, |
|
166 SLOT(sortDescending())); |
|
167 //connect all action Items to respective slots |
|
168 connect(mAllAction, SIGNAL(triggered()), this, SLOT(allTabTriggered())); |
|
169 connect(mCollectionAction, SIGNAL(triggered()), this,SLOT(colectionTabTriggered())); |
|
170 connect(mSearchAction, SIGNAL(triggered()), this, |
|
171 SLOT(searchTabTriggered())); |
|
172 // connect the signal of the list activated to a slot. |
|
173 connect(mListView, SIGNAL(activated(const QModelIndex &)), this, SLOT(handleActivated(const QModelIndex &))); |
|
174 connect(mListView,SIGNAL(longPressed(HbAbstractViewItem*, const QPointF &)),this, |
|
175 SLOT(launchPopUpMenu(HbAbstractViewItem*, const QPointF &))); |
|
176 //set widget according to orientation |
|
177 if(aOrientation == Qt::Horizontal) |
|
178 { |
|
179 manageHgWidget(); |
|
180 } |
|
181 else |
|
182 { |
|
183 manageListView(); |
|
184 } |
|
185 } |
|
186 |
|
187 |
|
188 void LocationPickerView::createHurriganesWidget() |
|
189 { |
|
190 //hurrriganes widget |
|
191 mHgModel = new HgWidgetDataModel( mProxyModel, this ); |
|
192 mHgModel->setImageDataType(HgWidgetDataModel::ETypeQImage); |
|
193 //create MediaWall Object |
|
194 mWidget = new HgMediawall(); |
|
195 HbIcon defaultIcon(KDummyImage); |
|
196 QImage defaultImage = defaultIcon.pixmap().toImage().convertToFormat(QImage::Format_ARGB32_Premultiplied); |
|
197 mWidget->setDefaultImage(defaultImage); |
|
198 HgMediawall* mediawall = qobject_cast<HgMediawall*>( mWidget ); |
|
199 mediawall->setObjectName("location"); |
|
200 HbStyleLoader::registerFilePath(":/location.hgmediawall.widgetml"); |
|
201 HbStyleLoader::registerFilePath(":/location.hgmediawall.css"); |
|
202 mediawall->enableReflections(false); |
|
203 mediawall->setFontSpec(HbFontSpec(HbFontSpec::Primary)); |
|
204 mediawall->setItemSize(QSize(4,3)); |
|
205 connect(this->mainWindow(), SIGNAL(orientationChanged(Qt::Orientation)),mWidget, |
|
206 SLOT(orientationChanged(Qt::Orientation))); |
|
207 |
|
208 mWidget->setAcceptTouchEvents(true); |
|
209 connect(mWidget, SIGNAL(activated(const QModelIndex &)),this, SLOT(handleActivated(const QModelIndex &))); |
|
210 connect(mWidget, SIGNAL(longPressed(const QModelIndex &, const QPointF &)),this, |
|
211 SLOT(launchPopUpMenu(const QModelIndex &, const QPointF &))); |
|
212 mWidget->setLongPressEnabled(true); |
|
213 mWidget->scrollTo(mWidget->currentIndex()); |
|
214 } |
|
215 |
|
216 // ----------------------------------------------------------------------------- |
|
217 // LocationPickerView::manageHgWidget() |
|
218 // ----------------------------------------------------------------------------- |
|
219 void LocationPickerView::manageHgWidget() |
|
220 { |
|
221 removeDetailsLabel(); |
|
222 mLinerLayout->removeItem(mListView); |
|
223 mListView->hide(); |
|
224 mWidget->show(); |
|
225 mLinerLayout->updateGeometry(); |
|
226 //set the appropriate model |
|
227 switch(mViewType) |
|
228 { |
|
229 case ELocationPickerContent: |
|
230 { |
|
231 mHgModel->resetModel(mProxyModel); |
|
232 mAllAction->setChecked(true); |
|
233 mCollectionAction->setChecked(false); |
|
234 mLinerLayout->insertItem(1,mWidget); |
|
235 } |
|
236 break; |
|
237 case ELocationPickerCollectionContent: |
|
238 { |
|
239 setCollectionData(mCategoryId); |
|
240 mCollectionAction->setChecked(true); |
|
241 mAllAction->setChecked(false); |
|
242 } |
|
243 break; |
|
244 } |
|
245 } |
|
246 |
|
247 // ---------------------------------------------------- |
|
248 // LocationPickerView::manageListView() |
|
249 // ---------------------------------------------------- |
|
250 void LocationPickerView::manageListView() |
|
251 { |
|
252 if(mEmptyLabel) |
|
253 { |
|
254 removeDetailsLabel(); |
|
255 } |
|
256 else |
|
257 { |
|
258 mLinerLayout->removeItem(mWidget); |
|
259 mWidget->hide(); |
|
260 } |
|
261 mLinerLayout->insertItem(1,mListView); |
|
262 mListView->show(); |
|
263 //set the appropriate model |
|
264 switch(mViewType) |
|
265 { |
|
266 case ELocationPickerContent: |
|
267 { |
|
268 mListItem->setGraphicsSize(HbListViewItem::Thumbnail); |
|
269 mListView->setModel(mProxyModel,mListItem); |
|
270 mAllAction->setChecked(true); |
|
271 mCollectionAction->setChecked(false); |
|
272 mViewType = ELocationPickerContent; |
|
273 } |
|
274 break; |
|
275 case ELocationPickerCollectionListContent: |
|
276 { |
|
277 mListView->setModel(mLocationPickerCollectionListContent->getStandardModel(),mListItem); |
|
278 mCollectionAction->setChecked(true); |
|
279 mAllAction->setChecked(false); |
|
280 if(mAscendingAction->isEnabled()) |
|
281 { |
|
282 mAscendingAction->setDisabled(true); |
|
283 mDescendingAction->setDisabled(true); |
|
284 } |
|
285 mViewType = ELocationPickerCollectionListContent; |
|
286 } |
|
287 break; |
|
288 case ELocationPickerCollectionContent: |
|
289 { |
|
290 mCollectionAction->setChecked(true); |
|
291 mAllAction->setChecked(false); |
|
292 mViewType = ELocationPickerCollectionContent; |
|
293 setCollectionData(mCategoryId); |
|
294 } |
|
295 break; |
|
296 default: |
|
297 break; |
|
298 } |
|
299 } |
|
300 |
|
301 // ----------------------------------------------------------------------------- |
|
302 // LocationPickerView::disableTabs() |
|
303 // ----------------------------------------------------------------------------- |
|
304 void LocationPickerView::disableTabs() |
|
305 { |
|
306 //if no location entries present |
|
307 mLinerLayout = static_cast<QGraphicsLinearLayout*>(widget()->layout()); |
|
308 mEmptyLabel = new HbTextItem( hbTrId( "txt_lint_list_no_location_entries_present" ) ); |
|
309 mEmptyLabel->setSizePolicy( QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding ); |
|
310 mEmptyLabel->setFontSpec( HbFontSpec( HbFontSpec::Primary ) ); |
|
311 mEmptyLabel->setAlignment( Qt::AlignCenter ); |
|
312 mLinerLayout->insertItem( 1, mEmptyLabel ); |
|
313 mAllAction->setDisabled( true ); |
|
314 mCollectionAction->setDisabled( true ); |
|
315 mSearchAction->setDisabled( true ); |
|
316 mAscendingAction->setDisabled( true ); |
|
317 mDescendingAction->setDisabled( true ); |
|
318 } |
|
319 |
|
320 // ----------------------------------------------------------------------------- |
|
321 // LocationPickerView::handleActivated() |
|
322 // ----------------------------------------------------------------------------- |
|
323 void LocationPickerView::handleActivated( const QModelIndex &aIndex ) |
|
324 { |
|
325 QModelIndex index; |
|
326 QStandardItem* item; |
|
327 int row= aIndex.row(); |
|
328 int col = aIndex.column(); |
|
329 //handle the activated signal according to model set |
|
330 switch(mViewType) |
|
331 { |
|
332 case ELocationPickerContent: |
|
333 { |
|
334 if(mainWindow()->orientation() == Qt::Vertical) |
|
335 { |
|
336 index = mProxyModel->mapToSource( |
|
337 aIndex); |
|
338 item = mModel->item( index.row(), index.column() ); |
|
339 } |
|
340 else |
|
341 { |
|
342 QModelIndex proxyModelIndex = mProxyModel->index(row,col); |
|
343 index = mProxyModel->mapToSource( |
|
344 proxyModelIndex); |
|
345 item = mModel->item( index.row(), index.column() ); |
|
346 } |
|
347 QVariant var = item->data( Qt::UserRole ); |
|
348 quint32 lm = var.toUInt(); |
|
349 //item selected, complete request |
|
350 emit selectItem( lm ); |
|
351 } |
|
352 break; |
|
353 case ELocationPickerCollectionListContent: |
|
354 { |
|
355 mLocationPickerCollectionListContent->getData( |
|
356 aIndex, mCategoryId ); |
|
357 setCollectionData(mCategoryId); |
|
358 mViewType = ELocationPickerCollectionContent; |
|
359 } |
|
360 break; |
|
361 case ELocationPickerCollectionContent: |
|
362 { |
|
363 if(mainWindow()->orientation() == Qt::Vertical) |
|
364 { |
|
365 index = mCollectionContent->getProxyModel()->mapToSource( |
|
366 aIndex); |
|
367 } |
|
368 else |
|
369 { |
|
370 QModelIndex proxyModelIndex = mCollectionContent->getProxyModel()->index(row,col); |
|
371 index = mCollectionContent->getProxyModel()->mapToSource( |
|
372 proxyModelIndex); |
|
373 } |
|
374 quint32 lm = 0; |
|
375 mCollectionContent->getData(index, lm); |
|
376 //item selected, complete request |
|
377 emit selectItem(lm); |
|
378 } |
|
379 break; |
|
380 default: |
|
381 break; |
|
382 } |
|
383 } |
|
384 |
|
385 // ----------------------------------------------------------------------------- |
|
386 // LocationPickerView::sortAscending() |
|
387 // ----------------------------------------------------------------------------- |
|
388 void LocationPickerView::sortAscending() |
|
389 { |
|
390 //check the model set and do sorting accordingly |
|
391 if (mViewType == ELocationPickerContent) |
|
392 { |
|
393 mProxyModel->sort( 0, Qt::AscendingOrder ); |
|
394 if(mainWindow()->orientation()==Qt::Horizontal) |
|
395 mHgModel->resetModel(mProxyModel); |
|
396 } |
|
397 else |
|
398 { |
|
399 mCollectionContent->getProxyModel()->sort( 0, Qt::AscendingOrder ); |
|
400 if(mainWindow()->orientation()==Qt::Horizontal) |
|
401 mHgModel->resetModel(mCollectionContent->getProxyModel()); |
|
402 } |
|
403 } |
|
404 |
|
405 // ----------------------------------------------------------------------------- |
|
406 // LocationPickerView::sortDescending() |
|
407 // ----------------------------------------------------------------------------- |
|
408 void LocationPickerView::sortDescending() |
|
409 { |
|
410 //check the model set and do sorting accordingly |
|
411 if (mViewType == ELocationPickerContent) |
|
412 { |
|
413 mProxyModel->sort(0, Qt::DescendingOrder); |
|
414 if(mainWindow()->orientation()==Qt::Horizontal) |
|
415 mHgModel->resetModel(mProxyModel); |
|
416 } |
|
417 else |
|
418 { |
|
419 mCollectionContent->getProxyModel()->sort( 0, Qt::DescendingOrder ); |
|
420 if(mainWindow()->orientation()==Qt::Horizontal) |
|
421 mHgModel->resetModel(mCollectionContent->getProxyModel()); |
|
422 } |
|
423 } |
|
424 |
|
425 // ----------------------------------------------------------------------------- |
|
426 // LocationPickerView::allTabTriggered() |
|
427 // ----------------------------------------------------------------------------- |
|
428 void LocationPickerView::allTabTriggered() |
|
429 { |
|
430 removeDetailsLabel(); |
|
431 //execute only if tab is not pressed |
|
432 if (mAllAction->isChecked()) |
|
433 { |
|
434 mViewType = ELocationPickerContent; |
|
435 mCollectionAction->setChecked(false); |
|
436 mAscendingAction->setEnabled(true); |
|
437 mDescendingAction->setEnabled(true); |
|
438 //delete mCollectionContent if coming back from collectioncontent |
|
439 if (mCollectionContent) |
|
440 { |
|
441 delete mCollectionContent; |
|
442 mCollectionContent = NULL; |
|
443 } |
|
444 if(mainWindow()->orientation() == Qt::Vertical) |
|
445 { |
|
446 manageListView(); |
|
447 } |
|
448 else |
|
449 { |
|
450 manageHgWidget(); |
|
451 } |
|
452 } |
|
453 else |
|
454 { |
|
455 //Keep the tab pressed |
|
456 mAllAction->setChecked(true); |
|
457 } |
|
458 |
|
459 } |
|
460 |
|
461 // ----------------------------------------------------------------------------- |
|
462 // LocationPickerView::colectionTabTriggered() |
|
463 // ----------------------------------------------------------------------------- |
|
464 void LocationPickerView::colectionTabTriggered() |
|
465 { |
|
466 mListItem->setGraphicsSize(HbListViewItem::MediumIcon); |
|
467 removeDetailsLabel(); |
|
468 //execute only if tab is not pressed |
|
469 if (mCollectionAction->isChecked()) |
|
470 { |
|
471 mAscendingAction->setDisabled(true); |
|
472 mDescendingAction->setDisabled(true); |
|
473 mAllAction->setChecked(false); |
|
474 mViewType = ELocationPickerCollectionListContent; |
|
475 manageListView(); |
|
476 } |
|
477 else |
|
478 { |
|
479 //Keep the tab pressed |
|
480 mCollectionAction->setChecked(true); |
|
481 } |
|
482 } |
|
483 |
|
484 // ----------------------------------------------------------------------------- |
|
485 // LocationPickerView::searchTabTriggered() |
|
486 // ----------------------------------------------------------------------------- |
|
487 void LocationPickerView::searchTabTriggered() |
|
488 { |
|
489 emit switchToSearchView(); |
|
490 } |
|
491 |
|
492 // ----------------------------------------------------------------------------- |
|
493 // LocationPickerView::setCollectionData() |
|
494 // ----------------------------------------------------------------------------- |
|
495 void LocationPickerView::setCollectionData( quint32 acategoryId ) |
|
496 { |
|
497 if(!mCollectionContent) |
|
498 { |
|
499 mCollectionContent |
|
500 = new LocationPickerCollectionContent( acategoryId ); |
|
501 } |
|
502 |
|
503 if(mainWindow()->orientation() == Qt::Vertical) |
|
504 { |
|
505 QString categoryname; |
|
506 removeDetailsLabel(); |
|
507 switch(acategoryId) |
|
508 { |
|
509 |
|
510 case 1: categoryname = "Landmarks"; |
|
511 break; |
|
512 case 8: categoryname = "Contacts"; |
|
513 break; |
|
514 case 9: categoryname = "Calender"; |
|
515 break; |
|
516 } |
|
517 if(mCollectionContent->locationFound()) |
|
518 { |
|
519 mListView->setModel( mCollectionContent->getProxyModel(),mListItem ); |
|
520 //Enable the options |
|
521 mAscendingAction->setEnabled(true); |
|
522 mDescendingAction->setEnabled(true); |
|
523 mListItem->setGraphicsSize(HbListViewItem::Thumbnail); |
|
524 } |
|
525 else |
|
526 { |
|
527 displayNoEntries(); |
|
528 } |
|
529 mCollectionAction->setChecked(true); |
|
530 |
|
531 if(mColllabel) |
|
532 { |
|
533 mLinerLayout->insertItem(0,mColllabel); |
|
534 mColllabel->setPlainText(categoryname); |
|
535 mColllabel->show(); |
|
536 } |
|
537 } |
|
538 else |
|
539 { |
|
540 if(mCollectionContent->locationFound()) |
|
541 { |
|
542 mHgModel->resetModel( mCollectionContent->getProxyModel() ); |
|
543 //Enable the options |
|
544 mAscendingAction->setEnabled(true); |
|
545 mDescendingAction->setEnabled(true); |
|
546 mLinerLayout->removeItem(mListView); |
|
547 mListView->hide(); |
|
548 mLinerLayout->insertItem(1,mWidget); |
|
549 mWidget->show(); |
|
550 mLinerLayout->updateGeometry(); |
|
551 } |
|
552 else |
|
553 { |
|
554 displayNoEntries(); |
|
555 } |
|
556 } |
|
557 mViewType = ELocationPickerCollectionContent; |
|
558 } |
|
559 |
|
560 // ----------------------------------------------------------------------------- |
|
561 // LocationPickerView::getViewType() |
|
562 // ----------------------------------------------------------------------------- |
|
563 TViewType LocationPickerView::getViewType() |
|
564 { |
|
565 return mViewType; |
|
566 } |
|
567 |
|
568 // ----------------------------------------------------------------------------- |
|
569 // LocationPickerView::setViewType() |
|
570 // ----------------------------------------------------------------------------- |
|
571 void LocationPickerView::setViewType( TViewType aViewType ) |
|
572 { |
|
573 mViewType = aViewType; |
|
574 } |
|
575 |
|
576 |
|
577 // ----------------------------------------------------------------------------- |
|
578 // LocationPickerView::clearContentModel() |
|
579 // ----------------------------------------------------------------------------- |
|
580 void LocationPickerView::clearContentModel() |
|
581 { |
|
582 if(mCollectionContent) |
|
583 { |
|
584 delete mCollectionContent; |
|
585 mCollectionContent = NULL; |
|
586 } |
|
587 } |
|
588 |
|
589 // ----------------------------------------------------------------------------- |
|
590 // LocationPickerView::launchPopUpMenu() |
|
591 // ----------------------------------------------------------------------------- |
|
592 void LocationPickerView::launchPopUpMenu( HbAbstractViewItem *aItem, const QPointF &aPoint ) |
|
593 { |
|
594 mLongPressMenu = new HbMenu(); |
|
595 mLongPressMenu->setTimeout(HbMenu::NoTimeout); |
|
596 connect(mLongPressMenu,SIGNAL(aboutToClose ()),this,SLOT(deleteMenu())); |
|
597 mSelectAction = mLongPressMenu->addAction(hbTrId("Select")); |
|
598 if( mViewType == ELocationPickerCollectionContent || mViewType == ELocationPickerContent ) |
|
599 { |
|
600 mDetailsAction = mLongPressMenu->addAction(hbTrId("txt_lint_list_details")); |
|
601 connect(mDetailsAction, SIGNAL(triggered()), this, SLOT(handleDetails())); |
|
602 } |
|
603 mIndex = aItem->modelIndex(); |
|
604 connect(mSelectAction, SIGNAL(triggered()), this, SLOT(handleSelect())); |
|
605 mLongPressMenu->setPreferredPos(aPoint); |
|
606 mLongPressMenu->open(); |
|
607 } |
|
608 |
|
609 // ----------------------------------------------------------------------------- |
|
610 // LocationPickerView::launchPopUpMenu() |
|
611 // ----------------------------------------------------------------------------- |
|
612 void LocationPickerView::launchPopUpMenu( const QModelIndex &aIndex, const QPointF &aPoint ) |
|
613 { |
|
614 mLongPressMenu = new HbMenu(); |
|
615 mLongPressMenu->setTimeout(HbMenu::NoTimeout); |
|
616 connect(mLongPressMenu,SIGNAL(aboutToClose ()),this,SLOT(deleteMenu())); |
|
617 mSelectAction = mLongPressMenu->addAction(hbTrId("Select")); |
|
618 mIndex = aIndex; |
|
619 connect(mSelectAction, SIGNAL(triggered()), this, SLOT(handleSelect())); |
|
620 mLongPressMenu->setPreferredPos(aPoint); |
|
621 mLongPressMenu->open(); |
|
622 } |
|
623 // ----------------------------------------------------------------------------- |
|
624 // LocationPickerView::handleSelect() |
|
625 // ----------------------------------------------------------------------------- |
|
626 void LocationPickerView::handleSelect() |
|
627 { |
|
628 handleActivated(mIndex); |
|
629 } |
|
630 |
|
631 // ----------------------------------------------------------------------------- |
|
632 // LocationPickerView::deleteMenu() |
|
633 // ----------------------------------------------------------------------------- |
|
634 void LocationPickerView::deleteMenu() |
|
635 { |
|
636 mLongPressMenu->deleteLater(); |
|
637 mLongPressMenu = NULL; |
|
638 mSelectAction->deleteLater(); |
|
639 mSelectAction = NULL; |
|
640 mDetailsAction->deleteLater(); |
|
641 mDetailsAction = NULL; |
|
642 |
|
643 } |
|
644 |
|
645 // ----------------------------------------------------------------------------- |
|
646 // LocationPickerView::handleSelect() |
|
647 // ----------------------------------------------------------------------------- |
|
648 void LocationPickerView::handleDetails() |
|
649 { |
|
650 HbDocumentLoader* loader = new HbDocumentLoader(); |
|
651 |
|
652 bool ok = false; |
|
653 //load the popup dialog |
|
654 loader->load(":/popupdialog.docml", &ok); |
|
655 Q_ASSERT_X(ok,"locationpickerservice","invalid DocML file"); |
|
656 //find graphics popup dialog |
|
657 QGraphicsWidget *popUpDialog = loader->findWidget("dialog"); |
|
658 Q_ASSERT_X((popUpDialog != 0), "locationpickerservice", "invalid DocML file"); |
|
659 mDialog = qobject_cast<HbDialog*>(popUpDialog); |
|
660 mMapIconLabel = qobject_cast<HbLabel*>(loader->findWidget("mapLabel")); |
|
661 mTitleLabel = qobject_cast<HbLabel*>(loader->findWidget("titleLabel")); |
|
662 mAddressMiddle = qobject_cast<HbLabel*>(loader->findWidget("addressMiddle")); |
|
663 mAddressBottom = qobject_cast<HbLabel*>(loader->findWidget("addressBottom")); |
|
664 mDone = qobject_cast<HbAction*>(loader->findObject(QString("action"))); |
|
665 mTitleLabel->setFontSpec(HbFontSpec(HbFontSpec::Primary)); |
|
666 mDialog->setDismissPolicy(HbDialog::NoDismiss); |
|
667 mDialog->setTimeout(HbDialog::NoTimeout); |
|
668 connect(mDone, SIGNAL(triggered()), this, SLOT(closeDetailsDialog())); |
|
669 QStringList adressDetail; |
|
670 QString iconName; |
|
671 mMapIconLabel->setAlignment(Qt::AlignCenter); |
|
672 if(mViewType == ELocationPickerContent) |
|
673 { |
|
674 adressDetail = mProxyModel->data(mIndex,Qt::UserRole+3).toStringList(); |
|
675 iconName = mProxyModel->data(mIndex,Qt::UserRole+1).toString(); |
|
676 } |
|
677 else |
|
678 { |
|
679 adressDetail = mCollectionContent->getProxyModel()->data(mIndex,Qt::UserRole+3).toStringList(); |
|
680 iconName = mCollectionContent->getProxyModel()->data(mIndex,Qt::UserRole+1).toString(); |
|
681 } |
|
682 if(iconName.isEmpty()) |
|
683 { |
|
684 mMapIconLabel->setIcon(KDummyImage); |
|
685 } |
|
686 else |
|
687 { |
|
688 mMapIconLabel->setIcon(HbIcon(iconName)); |
|
689 } |
|
690 |
|
691 if(adressDetail[0].isEmpty() && adressDetail[1].isEmpty()) |
|
692 { |
|
693 mTitleLabel->setPlainText(adressDetail[2]); |
|
694 mAddressMiddle->setPlainText(QString("")); |
|
695 mAddressBottom->setPlainText(QString("")); |
|
696 } |
|
697 else if(adressDetail[0].isEmpty()) |
|
698 { |
|
699 mTitleLabel->setPlainText(adressDetail[1]); |
|
700 mAddressMiddle->setPlainText(adressDetail[2]); |
|
701 mAddressBottom->setPlainText(QString("")); |
|
702 } |
|
703 else if (adressDetail[1].isEmpty()) |
|
704 { |
|
705 mTitleLabel->setPlainText(adressDetail[0]); |
|
706 mAddressMiddle->setPlainText(adressDetail[2]); |
|
707 mAddressBottom->setPlainText(QString("")); |
|
708 } |
|
709 else |
|
710 { |
|
711 mTitleLabel->setPlainText(adressDetail[0]); |
|
712 mAddressMiddle->setPlainText(adressDetail[1]); |
|
713 mAddressBottom->setPlainText(adressDetail[2]); |
|
714 } |
|
715 |
|
716 mDialog->open(); |
|
717 delete loader; |
|
718 } |
|
719 |
|
720 // ----------------------------------------------------------------------------- |
|
721 // LocationPickerView::closeDetailsDialog() |
|
722 // ----------------------------------------------------------------------------- |
|
723 void LocationPickerView::closeDetailsDialog() |
|
724 { |
|
725 if(mDialog) |
|
726 { |
|
727 mDialog->close(); |
|
728 delete mDialog; |
|
729 mDialog = NULL; |
|
730 } |
|
731 } |
|
732 // ----------------------------------------------------------------------------- |
|
733 // LocationPickerView::displayNoEntries() |
|
734 // ----------------------------------------------------------------------------- |
|
735 void LocationPickerView::displayNoEntries() |
|
736 { |
|
737 if(!mEmptyLabel) |
|
738 { |
|
739 mEmptyLabel = new HbTextItem(hbTrId("txt_lint_list_no_location_entries_present")); |
|
740 mEmptyLabel->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding); |
|
741 mEmptyLabel->setFontSpec(HbFontSpec(HbFontSpec::Primary)); |
|
742 mEmptyLabel->setAlignment(Qt::AlignCenter); |
|
743 mLinerLayout->removeItem(mListView); |
|
744 mListView->hide(); |
|
745 mWidget->setVisible(false); |
|
746 mLinerLayout->insertItem(0, mEmptyLabel); |
|
747 } |
|
748 |
|
749 } |
|
750 |
|
751 // ----------------------------------------------------------------------------- |
|
752 // LocationPickerView::removeDetailsLabel() |
|
753 // ----------------------------------------------------------------------------- |
|
754 void LocationPickerView::removeDetailsLabel() |
|
755 { |
|
756 if (mLinerLayout && mColllabel) |
|
757 { |
|
758 mColllabel->setPlainText(""); |
|
759 mLinerLayout->removeItem(mColllabel); |
|
760 mColllabel->hide(); |
|
761 } |
|
762 if(mEmptyLabel) |
|
763 { |
|
764 mLinerLayout->removeItem(mEmptyLabel); |
|
765 mEmptyLabel->hide(); |
|
766 delete mEmptyLabel; |
|
767 mEmptyLabel = NULL; |
|
768 } |
|
769 } |
|
770 |