|
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: |
|
15 * |
|
16 */ |
|
17 |
|
18 #include <QStandardItemModel> |
|
19 #include <QDebug> |
|
20 |
|
21 #include <hbmainwindow.h> |
|
22 #include <hbapplication.h> |
|
23 #include <hbaction.h> |
|
24 #include <hbtoolbar.h> |
|
25 #include <hblabel.h> |
|
26 |
|
27 #include <hbtreeview.h> |
|
28 #include <hblistview.h> |
|
29 #include <hbsearchpanel.h> |
|
30 #include <hbscrollbar.h> |
|
31 #include <hblineedit.h> |
|
32 #include <hbmenu.h> |
|
33 #include <hbstaticvkbhost.h> |
|
34 #include <hbgroupbox.h> |
|
35 |
|
36 #include "HelpDataProvider.h" |
|
37 #include "HelpProxyModel.h" |
|
38 |
|
39 #include "HelpKeywordView.h" |
|
40 |
|
41 |
|
42 ////////////////////////////////////////////////////////////////////////////////////////////// |
|
43 |
|
44 HelpKeywordView::HelpKeywordView() : |
|
45 mListSearch(NULL), |
|
46 mSearchPanel(NULL) |
|
47 { |
|
48 } |
|
49 |
|
50 HelpKeywordView::~HelpKeywordView() |
|
51 { |
|
52 } |
|
53 |
|
54 |
|
55 //////////////////////////////////////////////////////////////////////////////////////////// |
|
56 |
|
57 void HelpKeywordView::init() |
|
58 { |
|
59 initDocMl(); |
|
60 initBackAction(); |
|
61 initSearchList(); |
|
62 initSearchPanel(); |
|
63 initVirtualKeyboard(); |
|
64 initEmptyLabel(); |
|
65 |
|
66 connect(mainWindow(), SIGNAL(viewReady()), this, SLOT(onViewReady())); |
|
67 } |
|
68 |
|
69 void HelpKeywordView::initDocMl() |
|
70 { |
|
71 initBaseDocMl(); |
|
72 mBuilder.load(QRC_DOCML_KEYWORD); |
|
73 } |
|
74 |
|
75 void HelpKeywordView::initBackAction() |
|
76 { |
|
77 mSoftKeyAction = new HbAction(Hb::BackNaviAction); |
|
78 connect(mSoftKeyAction, SIGNAL(triggered()), this, SLOT(onBackAction())); |
|
79 } |
|
80 |
|
81 void HelpKeywordView::initSearchList() |
|
82 { |
|
83 mListSearch = mBuilder.findWidget<HbListView*>(DOCML_LIST_SEARCH); |
|
84 mListSearch->setHorizontalScrollBarPolicy(HbScrollArea::ScrollBarAlwaysOff); |
|
85 mListSearch->setModel(HelpDataProvider::instance()->getSearchData()); |
|
86 connect(mListSearch, SIGNAL(activated(const QModelIndex&)), this, SLOT(onSearchListActivated(const QModelIndex&))); |
|
87 } |
|
88 void HelpKeywordView::initSearchPanel() |
|
89 { |
|
90 mSearchPanel = mBuilder.findWidget<HbSearchPanel*>(DOCML_SEARCH_PANEL); |
|
91 connect(mSearchPanel, SIGNAL(exitClicked()), this, SLOT(onSearchPanelExitClicked())); |
|
92 connect(mSearchPanel, SIGNAL(criteriaChanged(const QString&)), this, SLOT(onSearchPanelCriteriaChanged(const QString&))); |
|
93 } |
|
94 |
|
95 void HelpKeywordView::initVirtualKeyboard() |
|
96 { |
|
97 mVirtualKeyboard = new HbStaticVkbHost(this); |
|
98 connect(mVirtualKeyboard, SIGNAL(keypadOpened()), this, SLOT(onHandleKeypadOpen())); |
|
99 connect(mVirtualKeyboard, SIGNAL(keypadClosed()), this, SLOT(onHandleKeypadClose())); |
|
100 } |
|
101 |
|
102 void HelpKeywordView::initEmptyLabel() |
|
103 { |
|
104 HbLabel* label = mBuilder.findWidget<HbLabel*>(DOCML_NO_MATCH_LABEL); |
|
105 label->setFontSpec(HbFontSpec(HbFontSpec::Primary)); |
|
106 } |
|
107 |
|
108 void HelpKeywordView::loadAllContent() |
|
109 { |
|
110 mBuilder.load(QRC_DOCML_KEYWORD, DOCML_LAYOUT_SEARCH); |
|
111 ResetSearchPanel(); |
|
112 toolBar()->hide(); |
|
113 } |
|
114 |
|
115 HbGroupBox* HelpKeywordView::groupBox() |
|
116 { |
|
117 return mBuilder.findWidget<HbGroupBox*>(DOCML_GROUPBOX); |
|
118 } |
|
119 |
|
120 //////////////////////////////////////////////////////////////////////////////////////////// |
|
121 |
|
122 void HelpKeywordView::updateVisibleItems(bool visible) |
|
123 { |
|
124 static Hb::SceneItems items = Hb::TitleBarItem | Hb::StatusBarItem; |
|
125 if(visible) |
|
126 { |
|
127 showItems(items); |
|
128 } |
|
129 else |
|
130 { |
|
131 hideItems(items); |
|
132 } |
|
133 } |
|
134 |
|
135 void HelpKeywordView::ResetSearchPanel() |
|
136 { |
|
137 foreach(QGraphicsItem *obj, mSearchPanel->childItems()) |
|
138 { |
|
139 QGraphicsWidget *const widget = static_cast<QGraphicsWidget*>(obj); |
|
140 if(widget != NULL) |
|
141 { |
|
142 HbLineEdit *const lineEdit = qobject_cast<HbLineEdit*>(widget); |
|
143 if(lineEdit != NULL) |
|
144 { |
|
145 lineEdit->setText(""); |
|
146 lineEdit->setFocus(); |
|
147 break; |
|
148 } |
|
149 } |
|
150 } |
|
151 } |
|
152 |
|
153 //////////////////////////////////////////////////////////////////////////////////////////// |
|
154 // handle system event |
|
155 |
|
156 void HelpKeywordView::onViewReady() |
|
157 { |
|
158 if(isVisible()) |
|
159 { |
|
160 setNavigationAction(mSoftKeyAction); |
|
161 } |
|
162 } |
|
163 |
|
164 /////////////////////////////////////////////////////////////////////////////////////// |
|
165 // handle button back action |
|
166 |
|
167 void HelpKeywordView::onBackAction() |
|
168 { |
|
169 emit activateView(HelpViewCategory); |
|
170 } |
|
171 |
|
172 |
|
173 //////////////////////////////////////////////////////////////////////////////////////////// |
|
174 // handle list event |
|
175 |
|
176 void HelpKeywordView::onSearchListActivated(const QModelIndex& index) |
|
177 { |
|
178 if(!index.isValid() || // invalid |
|
179 index.child(0,0).isValid()) // this is a node |
|
180 { |
|
181 return; |
|
182 } |
|
183 |
|
184 QString uid = mListSearch->model()->data(index, UidRole).toString(); |
|
185 QString href = mListSearch->model()->data(index, HrefRole).toString(); |
|
186 HelpDataProvider::instance()->setHelpContentUrl(uid, href); |
|
187 emit activateView(HelpViewContents); |
|
188 } |
|
189 |
|
190 |
|
191 //////////////////////////////////////////////////////////////////////////////////////////// |
|
192 // handle search panel event |
|
193 |
|
194 void HelpKeywordView::onSearchPanelExitClicked() |
|
195 { |
|
196 if(mListSearch->model()->rowCount() == 0) |
|
197 { |
|
198 mBuilder.load(QRC_DOCML_KEYWORD, DOCML_LAYOUT_SEARCH_NO_SRHPAL_NO_MATCH); |
|
199 } |
|
200 else |
|
201 { |
|
202 mBuilder.load(QRC_DOCML_KEYWORD, DOCML_LAYOUT_SEARCH_NO_SRHPAL); |
|
203 } |
|
204 toolBar()->show(); |
|
205 } |
|
206 |
|
207 void HelpKeywordView::onSearchPanelCriteriaChanged(const QString &criteria) |
|
208 { |
|
209 HelpDataProvider::instance()->getSearchData(criteria); |
|
210 if(mListSearch->model()->rowCount() == 0) |
|
211 { |
|
212 mBuilder.load(QRC_DOCML_KEYWORD, DOCML_LAYOUT_SEARCH_NO_MATCH); |
|
213 } |
|
214 else |
|
215 { |
|
216 mBuilder.load(QRC_DOCML_KEYWORD, DOCML_LAYOUT_SEARCH); |
|
217 } |
|
218 |
|
219 toolBar()->hide(); |
|
220 |
|
221 if(criteria.isEmpty()) |
|
222 { |
|
223 groupBox()->setHeading(hbTrId(TXT_SETLABEL_SEARCH)); |
|
224 } |
|
225 else |
|
226 { |
|
227 QString heading = qtTrId(TXT_SETLABEL_SEARCH_RESULTS); |
|
228 heading.append(COLON); |
|
229 heading.append(criteria); |
|
230 groupBox()->setHeading(heading); |
|
231 } |
|
232 } |
|
233 |
|
234 //////////////////////////////////////////////////////////////////////////////////////////// |
|
235 // handle virtual keyboard event |
|
236 |
|
237 void HelpKeywordView::onHandleKeypadOpen() |
|
238 { |
|
239 updateVisibleItems(false); |
|
240 qreal heightToSet = mainWindow()->layoutRect().height() - mVirtualKeyboard->keyboardArea().height(); |
|
241 this->setMaximumHeight(heightToSet); |
|
242 } |
|
243 |
|
244 void HelpKeywordView::onHandleKeypadClose() |
|
245 { |
|
246 updateVisibleItems(true); |
|
247 qreal mainHeight = mainWindow()->layoutRect().height(); |
|
248 qreal toolbarHeight = toolBar()->size().height(); |
|
249 qreal height = mainHeight - (toolBar()->isVisible() ? toolbarHeight : 0); |
|
250 this->setMaximumHeight(height); |
|
251 } |
|
252 |
|
253 // end of file |