|
1 /**************************************************************************** |
|
2 ** |
|
3 ** Copyright (C) 2008-2010 Nokia Corporation and/or its subsidiary(-ies). |
|
4 ** All rights reserved. |
|
5 ** Contact: Nokia Corporation (developer.feedback@nokia.com) |
|
6 ** |
|
7 ** This file is part of the HbPlugins module of the UI Extensions for Mobile. |
|
8 ** |
|
9 ** GNU Lesser General Public License Usage |
|
10 ** This file may be used under the terms of the GNU Lesser General Public |
|
11 ** License version 2.1 as published by the Free Software Foundation and |
|
12 ** appearing in the file LICENSE.LGPL included in the packaging of this file. |
|
13 ** Please review the following information to ensure the GNU Lesser General |
|
14 ** Public License version 2.1 requirements will be met: |
|
15 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. |
|
16 ** |
|
17 ** In addition, as a special exception, Nokia gives you certain additional |
|
18 ** rights. These rights are described in the Nokia Qt LGPL Exception |
|
19 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. |
|
20 ** |
|
21 ** If you have questions regarding the use of this file, please contact |
|
22 ** Nokia at developer.feedback@nokia.com. |
|
23 ** |
|
24 ****************************************************************************/ |
|
25 |
|
26 #include <QTimer> |
|
27 #include <hbinputkeymapfactory.h> |
|
28 #include <hbinputpredictionengine.h> |
|
29 #include <HbInputSettingProxy.h> |
|
30 |
|
31 #include "hbhardwareinputbasic12keyhandler.h" |
|
32 #include "hbinputbasichandler_p.h" |
|
33 #include "hbinputabstractbase.h" |
|
34 #include "hbhardware12key.h" |
|
35 |
|
36 class HbHardwareInputBasic12KeyHandlerPrivate: public HbInputBasicHandlerPrivate |
|
37 { |
|
38 Q_DECLARE_PUBLIC(HbHardwareInputBasic12KeyHandler) |
|
39 |
|
40 public: |
|
41 HbHardwareInputBasic12KeyHandlerPrivate(); |
|
42 ~HbHardwareInputBasic12KeyHandlerPrivate(); |
|
43 |
|
44 void handleAlphaEvent(int buttonId); |
|
45 bool keyPressed(const QKeyEvent *keyEvent); |
|
46 bool keyReleased(const QKeyEvent *keyEvent); |
|
47 bool actionHandler(HbInputModeHandler::HbInputModeAction action); |
|
48 |
|
49 void _q_timeout(); |
|
50 public: |
|
51 int mLastKey; |
|
52 QChar mCurrentChar; |
|
53 int mNumChr; |
|
54 bool mButtonDown; |
|
55 HbInputFocusObject *mCurrentlyFocused; |
|
56 }; |
|
57 |
|
58 HbHardwareInputBasic12KeyHandlerPrivate::HbHardwareInputBasic12KeyHandlerPrivate() |
|
59 : mLastKey(0), |
|
60 mCurrentChar(0), |
|
61 mNumChr(0), |
|
62 mButtonDown(false), |
|
63 mCurrentlyFocused(0) |
|
64 { |
|
65 } |
|
66 |
|
67 HbHardwareInputBasic12KeyHandlerPrivate::~HbHardwareInputBasic12KeyHandlerPrivate() |
|
68 { |
|
69 } |
|
70 |
|
71 // handles the key press events. It starts a multitap timer as well. |
|
72 void HbHardwareInputBasic12KeyHandlerPrivate::handleAlphaEvent(int buttonId) |
|
73 { |
|
74 Q_Q(HbHardwareInputBasic12KeyHandler); |
|
75 HbInputFocusObject *focusObject = 0; |
|
76 focusObject = mInputMethod->focusObject(); |
|
77 if (!focusObject) { |
|
78 return; |
|
79 } |
|
80 |
|
81 mCurrentChar = q->getNthCharacterInKey(mNumChr, buttonId); |
|
82 |
|
83 if (mCurrentChar != 0) { |
|
84 QString str; |
|
85 str += mCurrentChar; |
|
86 |
|
87 QList<QInputMethodEvent::Attribute> list; |
|
88 QInputMethodEvent event(str, list); |
|
89 focusObject->sendEvent(event); |
|
90 mTimer->start(HbMultiTapTimerTimeout); |
|
91 } |
|
92 } |
|
93 |
|
94 bool HbHardwareInputBasic12KeyHandlerPrivate::keyPressed(const QKeyEvent *keyEvent) |
|
95 { |
|
96 Q_Q(HbHardwareInputBasic12KeyHandler); |
|
97 HbInputFocusObject *focusObject = 0; |
|
98 focusObject = mInputMethod->focusObject(); |
|
99 if (!focusObject) { |
|
100 return false; |
|
101 } |
|
102 |
|
103 int buttonId = keyEvent->key(); |
|
104 |
|
105 |
|
106 if( mLastKey != buttonId) { |
|
107 mLastKey = buttonId; |
|
108 if(mTimer->isActive()) { |
|
109 mTimer->stop(); |
|
110 mNumChr = 0; |
|
111 if (isEnterCharacter(mCurrentChar)) { |
|
112 focusObject->sendPreEditString(QString("")); // Make sure the enter character is cleared. |
|
113 mCurrentChar = QChar('\n'); // Convert enter character to line feed. |
|
114 } |
|
115 |
|
116 if(mCurrentChar != 0) { |
|
117 focusObject->filterAndCommitCharacter(mCurrentChar); |
|
118 } |
|
119 // For QLineEdit it works fine. For HbLineEdit, need to set the state |
|
120 // to lower by calling activateState(). |
|
121 // This is needed for the scenario - When automatic text case is true |
|
122 // click a button and before the multitap timer expires click on |
|
123 // another button. |
|
124 mInputMethod->updateState(); |
|
125 |
|
126 refreshAutoCompleter(); |
|
127 } |
|
128 } |
|
129 |
|
130 if (buttonId == Qt::Key_Return) { |
|
131 mLastKey = buttonId; |
|
132 return true; |
|
133 } else if (buttonId == Qt::Key_Shift) { |
|
134 // For single key press, change the text input case. If the second shift key press is |
|
135 // received within long key press time out interval, then activate the next state |
|
136 if (mTimer->isActive() && (mLastKey == buttonId)){ |
|
137 mTimer->stop(); |
|
138 HbInputState rootState; |
|
139 mInputMethod->editorRootState(rootState); |
|
140 mInputMethod->activateState(rootState); |
|
141 } else { |
|
142 updateTextCase(); |
|
143 mTimer->start(HbLongPressTimerTimeout); |
|
144 } |
|
145 mCurrentChar = 0; |
|
146 mButtonDown = true; |
|
147 mCurrentChar = 0; |
|
148 return true; |
|
149 } |
|
150 // Let's see if we can get the handler for this button in the base class. |
|
151 if (q->HbInputBasicHandler::filterEvent(keyEvent)) { |
|
152 return true; |
|
153 } |
|
154 |
|
155 mLastKey = buttonId; |
|
156 mButtonDown = true; |
|
157 |
|
158 handleAlphaEvent(buttonId); |
|
159 return true; |
|
160 } |
|
161 |
|
162 /*! |
|
163 Handles the key release events from the VKB. Launches the SCT with key release event of |
|
164 asterisk. |
|
165 */ |
|
166 bool HbHardwareInputBasic12KeyHandlerPrivate::keyReleased(const QKeyEvent *keyEvent) |
|
167 { |
|
168 Q_Q(HbHardwareInputBasic12KeyHandler); |
|
169 mButtonDown = false; |
|
170 int buttonId = keyEvent->key(); |
|
171 |
|
172 if (buttonId == Qt::Key_Asterisk) { |
|
173 //Same asterisk key is used for launching candidate list (long key press) |
|
174 //and also for SCT. So, do not launch SCT if candidate list is already launched. |
|
175 mInputMethod->switchMode(buttonId); |
|
176 return true; |
|
177 } else if (buttonId == Qt::Key_Delete) { |
|
178 QKeyEvent keyEvent(QEvent::KeyRelease, Qt::Key_Backspace, Qt::NoModifier); |
|
179 q->sendAndUpdate(keyEvent); |
|
180 return true; |
|
181 } |
|
182 |
|
183 return false; |
|
184 } |
|
185 |
|
186 |
|
187 void HbHardwareInputBasic12KeyHandlerPrivate::_q_timeout() |
|
188 { |
|
189 Q_Q(HbHardwareInputBasic12KeyHandler); |
|
190 mTimer->stop(); |
|
191 mNumChr = 0; |
|
192 |
|
193 HbInputFocusObject *focusedObject = 0; |
|
194 focusedObject = mInputMethod->focusObject(); |
|
195 if (!focusedObject) { |
|
196 qDebug("HbHardwareInputBasic12KeyHandler::timeout focusObject == 0"); |
|
197 return; |
|
198 } |
|
199 |
|
200 if (isEnterCharacter(mCurrentChar)) { |
|
201 focusedObject->sendPreEditString(QString("")); // Make sure the enter character is cleared. |
|
202 mCurrentChar = QChar('\n'); // Convert enter character to line feed. |
|
203 } |
|
204 |
|
205 //Long key press number key is applicable to all keys |
|
206 if (mButtonDown) { |
|
207 //switch to numeric mode for long key press of Hash key |
|
208 if (mLastKey == Qt::Key_Shift){ |
|
209 updateTextCase(); |
|
210 mInputMethod->switchMode(Qt::Key_Shift); |
|
211 }else { |
|
212 q->commitFirstMappedNumber(mLastKey); |
|
213 } |
|
214 } else if(mLastKey != Qt::Key_Shift){ |
|
215 if (!focusedObject->characterAllowedInEditor(mCurrentChar)) { |
|
216 focusedObject->sendCommitString(QString()); |
|
217 } else { |
|
218 if ( mCurrentChar != 0){ |
|
219 QString curString; |
|
220 curString.append(mCurrentChar); |
|
221 focusedObject->sendCommitString(curString); |
|
222 } |
|
223 mInputMethod->updateState(); |
|
224 // pass this character to autocompleter. |
|
225 refreshAutoCompleter(); |
|
226 } |
|
227 } |
|
228 return; |
|
229 } |
|
230 |
|
231 bool HbHardwareInputBasic12KeyHandlerPrivate::actionHandler(HbInputModeHandler::HbInputModeAction action) |
|
232 { |
|
233 HbInputFocusObject *focusObject = 0; |
|
234 focusObject = mInputMethod->focusObject(); |
|
235 if (!focusObject) { |
|
236 return false; |
|
237 } |
|
238 |
|
239 bool ret = true; |
|
240 switch (action) { |
|
241 case HbInputModeHandler::HbInputModeActionReset: |
|
242 mLastKey = 0; |
|
243 mNumChr = 0; |
|
244 if (mTimer->isActive()) { |
|
245 mTimer->stop(); |
|
246 } |
|
247 break; |
|
248 case HbInputModeHandler::HbInputModeActionDeleteAndCommit:{ |
|
249 mTimer->stop(); |
|
250 QString empty; |
|
251 if(mInputMethod) { |
|
252 //In case of the sct the character is already committed |
|
253 //We need to remove the committed character. |
|
254 QList<QInputMethodEvent::Attribute> list; |
|
255 QInputMethodEvent event(QString(), list); |
|
256 event.setCommitString(empty, -1, 1); |
|
257 focusObject->sendEvent(event); |
|
258 } else { |
|
259 // Close event was originated from a button press, remove the uncommitted character. |
|
260 focusObject->sendCommitString(empty); |
|
261 } |
|
262 } |
|
263 break; |
|
264 case HbInputModeHandler::HbInputModeActionFocusRecieved: |
|
265 mTimer->stop(); |
|
266 mNumChr = 0; |
|
267 if (mCurrentlyFocused != focusObject) { |
|
268 mCurrentlyFocused = focusObject; |
|
269 if (mAutoCompleter) { |
|
270 mAutoCompleter->commit(); |
|
271 } |
|
272 } |
|
273 // set up auto completer |
|
274 setUpAutoCompleter(); |
|
275 break; |
|
276 case HbInputModeHandler::HbInputModeActionCommit: |
|
277 case HbInputModeHandler::HbInputModeActionFocusLost: |
|
278 if (mTimer->isActive()) { |
|
279 mTimer->stop(); |
|
280 if (mCurrentChar != 0) { |
|
281 if (isEnterCharacter(mCurrentChar)) { |
|
282 focusObject->sendPreEditString(QString("")); // Make sure the enter character is cleared. |
|
283 mCurrentChar = QChar('\n'); // Convert enter character to line feed. |
|
284 } |
|
285 focusObject->filterAndCommitCharacter(mCurrentChar); |
|
286 mCurrentChar = 0; |
|
287 } |
|
288 mLastKey = 0; |
|
289 mNumChr = 0; |
|
290 mInputMethod->updateState(); |
|
291 } |
|
292 break; |
|
293 default: { |
|
294 ret = false; |
|
295 } |
|
296 break; |
|
297 }; |
|
298 |
|
299 return ret; |
|
300 } |
|
301 |
|
302 |
|
303 HbHardwareInputBasic12KeyHandler::HbHardwareInputBasic12KeyHandler(HbInputAbstractMethod* inputMethod) |
|
304 :HbInputBasicHandler( *new HbHardwareInputBasic12KeyHandlerPrivate, inputMethod) |
|
305 { |
|
306 Q_D(HbHardwareInputBasic12KeyHandler); |
|
307 d->q_ptr = this; |
|
308 } |
|
309 |
|
310 HbHardwareInputBasic12KeyHandler::~HbHardwareInputBasic12KeyHandler() |
|
311 { |
|
312 } |
|
313 |
|
314 /*! |
|
315 filterEvent function for handling different keyevents. |
|
316 */ |
|
317 bool HbHardwareInputBasic12KeyHandler::filterEvent(const QKeyEvent * event) |
|
318 { |
|
319 Q_D(HbHardwareInputBasic12KeyHandler); |
|
320 |
|
321 if (event->isAutoRepeat()) { |
|
322 // Ignore all repeat events after first repeat event |
|
323 return true; |
|
324 } else if (event->type() == QEvent::KeyRelease) { |
|
325 return d->keyReleased(event); |
|
326 } else { |
|
327 return d->keyPressed(event); |
|
328 } |
|
329 } |
|
330 |
|
331 /*! |
|
332 returns true if in inline edit. |
|
333 */ |
|
334 bool HbHardwareInputBasic12KeyHandler::isComposing() const |
|
335 { |
|
336 Q_D(const HbHardwareInputBasic12KeyHandler); |
|
337 return d->mTimer->isActive(); |
|
338 } |
|
339 |
|
340 /*! |
|
341 list different input modes. |
|
342 */ |
|
343 void HbHardwareInputBasic12KeyHandler::listInputModes(QVector<HbInputModeProperties>& modes) const |
|
344 { |
|
345 HbInputModeProperties binding; |
|
346 binding.iMode = HbInputModeDefault; |
|
347 binding.iKeyboard = HbKeyboard12Key; |
|
348 |
|
349 QVector<int> languages; |
|
350 HbKeyMapFactory::instance()->listLanguages(languages); |
|
351 for (int i = 0; i < languages.count(); i++) { |
|
352 binding.iLanguage = (QLocale::Language)languages.at(i); |
|
353 modes.push_back(binding); |
|
354 } |
|
355 } |
|
356 |
|
357 /*! |
|
358 Action Handler |
|
359 */ |
|
360 bool HbHardwareInputBasic12KeyHandler::actionHandler(HbInputModeAction action) |
|
361 { |
|
362 Q_D(HbHardwareInputBasic12KeyHandler); |
|
363 if (!d->actionHandler(action)) { |
|
364 // no action taken so let's pass it to the base class. |
|
365 return HbInputBasicHandler::actionHandler(action); |
|
366 } |
|
367 return false; |
|
368 } |
|
369 // EOF |