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: LocationPickerSearchView implementation |
|
15 * |
|
16 */ |
|
17 |
|
18 #include <HbListViewItem> |
|
19 #include <QStandardItemModel> |
|
20 #include <HbSearchPanel> |
|
21 #include <HbListView> |
|
22 #include <HbTextItem> |
|
23 #include <HbDocumentLoader> |
|
24 #include <QGraphicsLinearLayout> |
|
25 #include <HbMenu> |
|
26 #include <HbAction> |
|
27 |
|
28 #include "locationpickerproxymodel.h" |
|
29 #include "locationpickersearchview.h" |
|
30 #include "locationpickerdatamanager.h" |
|
31 |
|
32 // ======== MEMBER FUNCTIONS ======== |
|
33 |
|
34 // ---------------------------------------------------- |
|
35 // LocationPickerSearchView::LocationPickerSearchView() |
|
36 // ---------------------------------------------------- |
|
37 LocationPickerSearchView::LocationPickerSearchView( HbDocumentLoader &aLoader ) |
|
38 :mProxyModel(NULL), |
|
39 mModel(NULL), |
|
40 mListView(NULL), |
|
41 mSearchPanel(NULL), |
|
42 mEmptyLabel(NULL), |
|
43 mVerticalLayout(NULL), |
|
44 mDocumentLoader(aLoader), |
|
45 mLongPressMenu(NULL), |
|
46 mSelectAction(NULL) |
|
47 { |
|
48 |
|
49 } |
|
50 // ---------------------------------------------------- |
|
51 // LocationPickerSearchView::~LocationPickerSearchView() |
|
52 // ---------------------------------------------------- |
|
53 LocationPickerSearchView::~LocationPickerSearchView() |
|
54 { |
|
55 delete mProxyModel; |
|
56 delete mEmptyLabel; |
|
57 } |
|
58 |
|
59 // ---------------------------------------------------- |
|
60 // LocationPickerSearchView::init() |
|
61 // ---------------------------------------------------- |
|
62 void LocationPickerSearchView::init( QStandardItemModel *aModel ) |
|
63 { |
|
64 mModel = aModel; |
|
65 //get listview from docml |
|
66 mListView = qobject_cast<HbListView*>( |
|
67 mDocumentLoader.findObject(QString("SearchListView"))); |
|
68 if(!mListView) |
|
69 { |
|
70 qFatal("Error Reading Docml"); |
|
71 } |
|
72 //get search panel from docml |
|
73 mSearchPanel = qobject_cast<HbSearchPanel*>( |
|
74 mDocumentLoader.findObject(QString("searchPanel"))); |
|
75 //conect to respective slots |
|
76 connect(mListView, SIGNAL(activated(const QModelIndex &)), this, SLOT(handleActivated |
|
77 (const QModelIndex &))); |
|
78 connect(mListView,SIGNAL(longPressed(HbAbstractViewItem*, const QPointF &)),this, |
|
79 SLOT(launchPopUpMenu(HbAbstractViewItem*, const QPointF &))); |
|
80 connect(mSearchPanel, SIGNAL(exitClicked()),this, SLOT(handleExit())); |
|
81 connect(mSearchPanel,SIGNAL(criteriaChanged(QString)),this,SLOT(doSearch(QString))); |
|
82 |
|
83 //Set graphics size for the list items. |
|
84 HbListViewItem *hbListItem = new HbListViewItem(); |
|
85 hbListItem->setGraphicsSize(HbListViewItem::Thumbnail); |
|
86 mListView->setItemPrototype( hbListItem ); |
|
87 |
|
88 // Create the proxy model. |
|
89 mProxyModel = new LocationPickerProxyModel(); |
|
90 mProxyModel->setSourceModel(mModel); |
|
91 mListView->setModel(mProxyModel); |
|
92 |
|
93 // set filter properties |
|
94 mProxyModel->setDynamicSortFilter(TRUE); |
|
95 mProxyModel->setSortRole(Qt::DisplayRole); |
|
96 mProxyModel->setSortCaseSensitivity(Qt::CaseInsensitive); |
|
97 // sort |
|
98 mProxyModel->sort(0, Qt::AscendingOrder); |
|
99 } |
|
100 |
|
101 // ---------------------------------------------------- |
|
102 // LocationPickerSearchView::handleExit() |
|
103 // ---------------------------------------------------- |
|
104 void LocationPickerSearchView::handleExit() |
|
105 { |
|
106 //emit signal to switch the current view |
|
107 emit switchView(); |
|
108 } |
|
109 |
|
110 // ---------------------------------------------------- |
|
111 // LocationPickerSearchView::doSearch() |
|
112 // ---------------------------------------------------- |
|
113 void LocationPickerSearchView::doSearch( QString aCriteria ) |
|
114 { |
|
115 // use the string to search |
|
116 mProxyModel->filterParameterChanged(aCriteria); |
|
117 mProxyModel->setFilterFixedString(aCriteria); |
|
118 //if no entries presentdisplay empty text item |
|
119 if (!mProxyModel->rowCount() ) |
|
120 { |
|
121 if(!mEmptyLabel) |
|
122 { |
|
123 QGraphicsWidget *widget = NULL; |
|
124 widget = mDocumentLoader.findWidget(QString("container")); |
|
125 mVerticalLayout = static_cast<QGraphicsLinearLayout*>(widget->layout()); |
|
126 if(!widget || !mVerticalLayout) |
|
127 { |
|
128 qFatal("Error Reading Docml"); |
|
129 } |
|
130 mVerticalLayout->removeItem(mListView); |
|
131 mListView->setVisible(false); |
|
132 mEmptyLabel = new HbTextItem(hbTrId("txt_lint_list_no_results")); |
|
133 mEmptyLabel->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding); |
|
134 mEmptyLabel->setFontSpec(HbFontSpec(HbFontSpec::Primary)); |
|
135 mEmptyLabel->setAlignment(Qt::AlignCenter); |
|
136 mVerticalLayout->insertItem(0, mEmptyLabel); |
|
137 mEmptyLabel->setVisible(true); |
|
138 } |
|
139 } |
|
140 //else display the result |
|
141 else if (mEmptyLabel) |
|
142 { |
|
143 mVerticalLayout->removeItem(mEmptyLabel); |
|
144 mEmptyLabel->setVisible(false); |
|
145 delete mEmptyLabel; |
|
146 mEmptyLabel=NULL; |
|
147 mVerticalLayout->insertItem(0, mListView); |
|
148 mListView->setVisible(true); |
|
149 } |
|
150 } |
|
151 |
|
152 // ---------------------------------------------------- |
|
153 // LocationPickerSearchView::handleActivated() |
|
154 // ---------------------------------------------------- |
|
155 void LocationPickerSearchView::handleActivated( const QModelIndex &aIndex ) |
|
156 { |
|
157 QModelIndex index = mProxyModel->mapToSource(aIndex); |
|
158 quint32 lm = 0; |
|
159 getData( index, lm ); |
|
160 //emit item is selectedsignal |
|
161 emit selectItem( lm ); |
|
162 } |
|
163 |
|
164 // ---------------------------------------------------------------------------- |
|
165 // LocationPickerSearchView::getData() |
|
166 // ---------------------------------------------------------------------------- |
|
167 |
|
168 void LocationPickerSearchView::getData( QModelIndex aIndex, quint32& aValue ) |
|
169 { |
|
170 QStandardItem* item = mModel->item( aIndex.row(), aIndex.column() ); |
|
171 QVariant var = item->data( Qt::UserRole ); |
|
172 aValue = var.toUInt(); |
|
173 } |
|
174 |
|
175 // ----------------------------------------------------------------------------- |
|
176 // LocationPickerSearchView::launchPopUpMenu() |
|
177 // ----------------------------------------------------------------------------- |
|
178 void LocationPickerSearchView::launchPopUpMenu(HbAbstractViewItem *aItem, const QPointF &aPoint) |
|
179 { |
|
180 mLongPressMenu = new HbMenu(); |
|
181 mLongPressMenu->setTimeout(HbMenu::NoTimeout); |
|
182 mSelectAction = mLongPressMenu->addAction(hbTrId("txt_lint_list_select")); |
|
183 mIndex = aItem->modelIndex(); |
|
184 connect(mSelectAction, SIGNAL(triggered()),this, SLOT(handleLongPress())); |
|
185 mLongPressMenu->setPreferredPos(aPoint); |
|
186 connect(mLongPressMenu,SIGNAL(aboutToClose ()),this,SLOT(deleteMenu())); |
|
187 mLongPressMenu->open(); |
|
188 } |
|
189 |
|
190 // ----------------------------------------------------------------------------- |
|
191 // LocationPickerSearchView::handleLongPress() |
|
192 // ----------------------------------------------------------------------------- |
|
193 void LocationPickerSearchView::handleLongPress() |
|
194 { |
|
195 handleActivated(mIndex); |
|
196 } |
|
197 |
|
198 // ----------------------------------------------------------------------------- |
|
199 // LocationPickerSearchView::deleteMenu() |
|
200 // ----------------------------------------------------------------------------- |
|
201 void LocationPickerSearchView::deleteMenu() |
|
202 { |
|
203 mLongPressMenu->deleteLater(); |
|
204 mLongPressMenu = NULL; |
|
205 mSelectAction->deleteLater(); |
|
206 mSelectAction = NULL; |
|
207 } |
|