27 #include <HbToolBar> |
27 #include <HbToolBar> |
28 #include <HbView> |
28 #include <HbView> |
29 #include <HbToolBarExtension> |
29 #include <HbToolBarExtension> |
30 #include <HbShrinkingVkbHost> |
30 #include <HbShrinkingVkbHost> |
31 #include <HbScrollBar> |
31 #include <HbScrollBar> |
|
32 #include <HbFrameBackground> |
32 |
33 |
33 #include "hsallappsstate.h" |
34 #include "hsallappsstate.h" |
34 #include "hsallcollectionsstate.h" |
35 #include "hsallcollectionsstate.h" |
35 #include "hscollectionstate.h" |
36 #include "hscollectionstate.h" |
36 #include "hsmainwindow.h" |
37 #include "hsmainwindow.h" |
72 |
73 |
73 \param builder Menu View builder. |
74 \param builder Menu View builder. |
74 \param stateContext Variable representing view context the view is to be prepared for. |
75 \param stateContext Variable representing view context the view is to be prepared for. |
75 \param mainWindow Object responsible for making a given view |
76 \param mainWindow Object responsible for making a given view |
76 a currently displayed view. |
77 a currently displayed view. |
|
78 \param operationalContext representing operational context. |
77 */ |
79 */ |
78 HsMenuView::HsMenuView(HsMenuViewBuilder &builder, |
80 HsMenuView::HsMenuView(HsMenuViewBuilder &builder, |
79 HsStateContext stateContext, |
81 HsStateContext stateContext, |
80 HsMainWindow &mainWindow): |
82 HsMainWindow &mainWindow, |
|
83 HsOperationalContext operationalContext): |
81 mBuilder(builder), |
84 mBuilder(builder), |
82 mStateContext(stateContext), |
85 mStateContext(stateContext), |
83 mOperationalContext(HsItemViewContext), |
86 mOperationalContext(operationalContext), |
84 mMainWindow(mainWindow), |
87 mMainWindow(mainWindow), |
85 mHsSearchView(new HsSearchView(mBuilder, mStateContext, mMainWindow)) |
88 mHsSearchView(new HsSearchView(mBuilder, mStateContext, |
|
89 mMainWindow, mOperationalContext)) |
|
90 |
86 { |
91 { |
87 synchronizeCache(); |
92 synchronizeCache(); |
88 |
93 |
89 connect(mListView, |
94 connect(mAbstractItemView, |
90 SIGNAL(activated(QModelIndex)), |
95 SIGNAL(activated(QModelIndex)), |
91 this, SIGNAL(activated(QModelIndex))); |
96 this, SIGNAL(activated(QModelIndex))); |
92 connect(mListView, |
97 connect(mAbstractItemView, |
93 SIGNAL(longPressed(HbAbstractViewItem *, QPointF)), |
98 SIGNAL(longPressed(HbAbstractViewItem *, QPointF)), |
94 this, SIGNAL(longPressed(HbAbstractViewItem *, QPointF))); |
99 this, SIGNAL(longPressed(HbAbstractViewItem *, QPointF))); |
95 |
100 |
96 connect(mHsSearchView.data(), SIGNAL(activated(QModelIndex)), |
101 connect(mHsSearchView.data(), SIGNAL(activated(QModelIndex)), |
97 this, SIGNAL(activated(QModelIndex))); |
102 this, SIGNAL(activated(QModelIndex))); |
118 */ |
123 */ |
119 void HsMenuView::setModel(QAbstractItemModel *model) |
124 void HsMenuView::setModel(QAbstractItemModel *model) |
120 { |
125 { |
121 HSMENUTEST_FUNC_ENTRY("HsMenuView::setModel"); |
126 HSMENUTEST_FUNC_ENTRY("HsMenuView::setModel"); |
122 |
127 |
123 if (mListView != NULL) { |
128 if (mAbstractItemView != NULL) { |
124 if (mListView->model()) { |
129 if (mAbstractItemView->model()) { |
125 disconnect(mListView->model(), |
130 disconnect(mAbstractItemView->model(), |
126 SIGNAL(scrollTo(int, QAbstractItemView::ScrollHint)), |
131 SIGNAL(scrollTo(int, QAbstractItemView::ScrollHint)), |
127 this, |
132 this, |
128 SLOT(scrollToRow(int, QAbstractItemView::ScrollHint))); |
133 SLOT(scrollToRow(int, QAbstractItemView::ScrollHint))); |
129 disconnect(mListView->model(), SIGNAL(countChange()), |
134 disconnect(mAbstractItemView->model(), SIGNAL(countChange()), |
130 this, |
135 this, |
131 SIGNAL(listViewChange())); |
136 SIGNAL(listViewChange())); |
132 } |
137 } |
133 |
138 mAbstractItemView->setItemPixmapCacheEnabled(true);// TODO: remove when enabled from default |
134 mListView->setItemPixmapCacheEnabled(true); // TODO: remove when enabled from default |
139 if (mOperationalContext == HsGridPortraitContext || |
135 mListView->setModel(model, new HsListViewItem()); |
140 mOperationalContext == HsGridLandscapeContext) { |
136 mListView->verticalScrollBar()->setInteractive(true); |
141 HbFrameBackground frame; |
137 if (mListView->model()) { |
142 frame.setFrameGraphicsName(QString("")); |
138 connect(mListView->model(), |
143 mAbstractItemView->itemPrototypes()[0]->setDefaultFrame(frame); |
|
144 mAbstractItemView->setModel(model); |
|
145 } else { |
|
146 mAbstractItemView->setModel(model, new HsListViewItem()); |
|
147 } |
|
148 if(mOperationalContext == HsGridLandscapeContext) |
|
149 { |
|
150 mAbstractItemView->horizontalScrollBar()->setInteractive(true); |
|
151 } |
|
152 else |
|
153 { |
|
154 mAbstractItemView->verticalScrollBar()->setInteractive(true); |
|
155 } |
|
156 |
|
157 if (mAbstractItemView->model()) { |
|
158 connect(mAbstractItemView->model(), |
139 SIGNAL(scrollTo(int, QAbstractItemView::ScrollHint)), |
159 SIGNAL(scrollTo(int, QAbstractItemView::ScrollHint)), |
140 this, |
160 this, |
141 SLOT(scrollToRow(int, QAbstractItemView::ScrollHint))); |
161 SLOT(scrollToRow(int, QAbstractItemView::ScrollHint))); |
142 connect(mListView->model(), SIGNAL(countChange()), |
162 connect(mAbstractItemView->model(), SIGNAL(countChange()), |
143 this, |
163 this, |
144 SIGNAL(listViewChange())); |
164 SIGNAL(listViewChange())); |
145 } |
165 } |
146 } |
166 } |
147 |
167 |
186 { |
206 { |
187 return mViewLabel; |
207 return mViewLabel; |
188 } |
208 } |
189 |
209 |
190 /*! |
210 /*! |
|
211 Return current scroll position for the list from the view. |
|
212 \return first visible row from model displayed in list |
|
213 */ |
|
214 QPersistentModelIndex HsMenuView::currentScrollPosition() const |
|
215 { |
|
216 const QList<HbAbstractViewItem *> items = mAbstractItemView->visibleItems(); |
|
217 if (!items.empty()) { |
|
218 return QPersistentModelIndex(items.at(0)->modelIndex()); |
|
219 } |
|
220 return QModelIndex(); |
|
221 } |
|
222 |
|
223 /*! |
191 Makes search panel visible. |
224 Makes search panel visible. |
192 Equivalent to \a setSearchPanelVisible(true) |
225 Equivalent to \a setSearchPanelVisible(true) |
193 */ |
226 */ |
194 void HsMenuView::showSearchPanel() |
227 void HsMenuView::showSearchPanel() |
195 { |
228 { |
196 HSMENUTEST_FUNC_ENTRY("HsMenuView::showSearchPanel"); |
229 HSMENUTEST_FUNC_ENTRY("HsMenuView::showSearchPanel"); |
197 |
|
198 mHsSearchView->setSearchPanelVisible(true); |
230 mHsSearchView->setSearchPanelVisible(true); |
199 |
231 |
200 HSMENUTEST_FUNC_EXIT("HsMenuView::showSearchPanel"); |
232 HSMENUTEST_FUNC_EXIT("HsMenuView::showSearchPanel"); |
201 } |
233 } |
202 |
234 |
205 Equivalent to \a setSearchPanelVisible(false). |
237 Equivalent to \a setSearchPanelVisible(false). |
206 */ |
238 */ |
207 void HsMenuView::hideSearchPanel() |
239 void HsMenuView::hideSearchPanel() |
208 { |
240 { |
209 HSMENUTEST_FUNC_ENTRY("HsMenuView::hideSearchPanel"); |
241 HSMENUTEST_FUNC_ENTRY("HsMenuView::hideSearchPanel"); |
210 |
|
211 mHsSearchView->setSearchPanelVisible(false); |
242 mHsSearchView->setSearchPanelVisible(false); |
212 |
|
213 HSMENUTEST_FUNC_EXIT("HsMenuView::hideSearchPanel"); |
243 HSMENUTEST_FUNC_EXIT("HsMenuView::hideSearchPanel"); |
214 } |
244 } |
215 |
245 |
216 /*! |
246 /*! |
217 Disable or enable search action button. |
247 Disable or enable search action button. |
246 */ |
276 */ |
247 void HsMenuView::scrollToRow(int row, QAbstractItemView::ScrollHint hint) |
277 void HsMenuView::scrollToRow(int row, QAbstractItemView::ScrollHint hint) |
248 { |
278 { |
249 HSMENUTEST_FUNC_ENTRY("HsMenuView::scrollToRow"); |
279 HSMENUTEST_FUNC_ENTRY("HsMenuView::scrollToRow"); |
250 |
280 |
251 if (mListView != NULL) { |
281 if (mAbstractItemView != NULL) { |
252 mListView->scrollTo( |
282 mAbstractItemView->scrollTo( |
253 mListView->model()->index(row, 0), convertScrollHint(hint)); |
283 mAbstractItemView->model()->index(row, 0), convertScrollHint(hint)); |
254 } |
284 } |
255 |
285 |
256 HSMENUTEST_FUNC_EXIT("HsMenuView::scrollToRow"); |
286 HSMENUTEST_FUNC_EXIT("HsMenuView::scrollToRow"); |
257 } |
287 } |
258 |
288 |
307 heading are preserved after reset. |
337 heading are preserved after reset. |
308 \param operationalContext Context indicating which view to activate. |
338 \param operationalContext Context indicating which view to activate. |
309 */ |
339 */ |
310 void HsMenuView::reset(HsOperationalContext operationalContext) |
340 void HsMenuView::reset(HsOperationalContext operationalContext) |
311 { |
341 { |
|
342 if (mAbstractItemView) { |
|
343 disconnect(mAbstractItemView, |
|
344 SIGNAL(activated(QModelIndex)), |
|
345 this, SIGNAL(activated(QModelIndex))); |
|
346 disconnect(mAbstractItemView, |
|
347 SIGNAL(longPressed(HbAbstractViewItem *, QPointF)), |
|
348 this, SIGNAL(longPressed(HbAbstractViewItem *, QPointF))); |
|
349 } |
|
350 |
312 QString viewLabelHeading; |
351 QString viewLabelHeading; |
313 |
352 |
314 // before changing context read current view label heading ... |
353 // before changing context read current view label heading ... |
315 synchronizeCache(); |
354 synchronizeCache(); |
316 |
355 |
326 |
365 |
327 if (mBuilder.currentViewLabel() != 0) { |
366 if (mBuilder.currentViewLabel() != 0) { |
328 mBuilder.currentViewLabel()->setHeading(viewLabelHeading); |
367 mBuilder.currentViewLabel()->setHeading(viewLabelHeading); |
329 } |
368 } |
330 mView->setNavigationAction(backKeyAction); |
369 mView->setNavigationAction(backKeyAction); |
|
370 |
|
371 connect(mAbstractItemView, |
|
372 SIGNAL(activated(QModelIndex)), |
|
373 this, SIGNAL(activated(QModelIndex))); |
|
374 connect(mAbstractItemView, |
|
375 SIGNAL(longPressed(HbAbstractViewItem *, QPointF)), |
|
376 this, SIGNAL(longPressed(HbAbstractViewItem *, QPointF))); |
|
377 |
|
378 mHsSearchView->setOperationalContext(operationalContext); |
331 } |
379 } |
332 |
380 |
333 /*! |
381 /*! |
334 Builder can be shared between many instances of HsMenuView |
382 Builder can be shared between many instances of HsMenuView |
335 being in different contexts. Before using builder make sure |
383 being in different contexts. Before using builder make sure |
361 If menu view is about to show it scrolls the list to \a firstMatching. |
409 If menu view is about to show it scrolls the list to \a firstMatching. |
362 Makes view represented by the object main view of the application. |
410 Makes view represented by the object main view of the application. |
363 */ |
411 */ |
364 void HsMenuView::handleSearchComplete(const QModelIndex& firstMatching) |
412 void HsMenuView::handleSearchComplete(const QModelIndex& firstMatching) |
365 { |
413 { |
366 if (mListView != NULL) { |
414 if (mAbstractItemView != NULL) { |
367 mListView->scrollTo(firstMatching, HbAbstractItemView::PositionAtTop); |
415 mAbstractItemView->scrollTo(firstMatching, |
368 } |
416 HbAbstractItemView::PositionAtTop); |
369 |
417 } |
370 activate(); |
418 activate(); |
371 } |
419 } |