69 } |
69 } |
70 |
70 |
71 // handles the key press events. It starts a multitap timer as well. |
71 // handles the key press events. It starts a multitap timer as well. |
72 void HbHardwareInputBasic12KeyHandlerPrivate::handleAlphaEvent(int buttonId) |
72 void HbHardwareInputBasic12KeyHandlerPrivate::handleAlphaEvent(int buttonId) |
73 { |
73 { |
74 Q_Q(HbHardwareInputBasic12KeyHandler); |
74 Q_Q(HbHardwareInputBasic12KeyHandler); |
75 HbInputFocusObject *focusObject = 0; |
75 HbInputFocusObject *focusObject = 0; |
76 focusObject = mInputMethod->focusObject(); |
76 focusObject = mInputMethod->focusObject(); |
77 if (!focusObject) { |
77 if (!focusObject) { |
78 return; |
78 return; |
79 } |
79 } |
80 |
80 |
81 mCurrentChar = q->getNthCharacterInKey(mNumChr, buttonId); |
81 mCurrentChar = q->getNthCharacterInKey(mNumChr, buttonId); |
82 |
82 |
83 if (mCurrentChar != 0) { |
83 if (mCurrentChar != 0) { |
84 QString str; |
84 QString str; |
85 str += mCurrentChar; |
85 str += mCurrentChar; |
86 |
86 |
87 QList<QInputMethodEvent::Attribute> list; |
87 QList<QInputMethodEvent::Attribute> list; |
88 QInputMethodEvent event(str, list); |
88 QInputMethodEvent event(str, list); |
89 focusObject->sendEvent(event); |
89 focusObject->sendEvent(event); |
90 mTimer->start(HbMultiTapTimerTimeout); |
90 mTimer->start(HbMultiTapTimerTimeout); |
91 } |
91 } |
92 } |
92 } |
93 |
93 |
94 bool HbHardwareInputBasic12KeyHandlerPrivate::keyPressed(const QKeyEvent *keyEvent) |
94 bool HbHardwareInputBasic12KeyHandlerPrivate::keyPressed(const QKeyEvent *keyEvent) |
95 { |
95 { |
96 Q_Q(HbHardwareInputBasic12KeyHandler); |
96 Q_Q(HbHardwareInputBasic12KeyHandler); |
97 HbInputFocusObject *focusObject = 0; |
97 HbInputFocusObject *focusObject = 0; |
98 focusObject = mInputMethod->focusObject(); |
98 focusObject = mInputMethod->focusObject(); |
99 if (!focusObject) { |
99 if (!focusObject) { |
100 return false; |
100 return false; |
101 } |
101 } |
102 |
102 |
103 int buttonId = keyEvent->key(); |
103 int buttonId = keyEvent->key(); |
104 |
104 |
105 |
105 |
106 if( mLastKey != buttonId) { |
106 if( mLastKey != buttonId) { |
107 mLastKey = buttonId; |
107 mLastKey = buttonId; |
108 if(mTimer->isActive()) { |
108 if(mTimer->isActive()) { |
109 mTimer->stop(); |
109 mTimer->stop(); |
110 mNumChr = 0; |
110 mNumChr = 0; |
111 if (isEnterCharacter(mCurrentChar)) { |
111 if (isEnterCharacter(mCurrentChar)) { |
112 focusObject->sendPreEditString(QString("")); // Make sure the enter character is cleared. |
112 focusObject->sendPreEditString(QString("")); // Make sure the enter character is cleared. |
113 mCurrentChar = QChar('\n'); // Convert enter character to line feed. |
113 mCurrentChar = QChar('\n'); // Convert enter character to line feed. |
114 } |
114 } |
115 |
115 |
116 if(mCurrentChar != 0) { |
116 if(mCurrentChar != 0) { |
117 focusObject->filterAndCommitCharacter(mCurrentChar); |
117 focusObject->filterAndCommitCharacter(mCurrentChar); |
118 } |
118 } |
119 // For QLineEdit it works fine. For HbLineEdit, need to set the state |
119 // For QLineEdit it works fine. For HbLineEdit, need to set the state |
120 // to lower by calling activateState(). |
120 // to lower by calling activateState(). |
121 // This is needed for the scenario - When automatic text case is true |
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 |
122 // click a button and before the multitap timer expires click on |
123 // another button. |
123 // another button. |
124 mInputMethod->updateState(); |
124 mInputMethod->updateState(); |
125 |
125 |
126 refreshAutoCompleter(); |
126 refreshAutoCompleter(); |
127 } |
127 } |
128 } |
128 } |
129 |
129 |
130 if (buttonId == Qt::Key_Return) { |
130 if (buttonId == Qt::Key_Return) { |
131 mLastKey = buttonId; |
131 mLastKey = buttonId; |
132 return true; |
132 return true; |
133 } else if (buttonId == Qt::Key_Shift) { |
133 } else if (buttonId == Qt::Key_Shift) { |
134 // For single key press, change the text input case. If the second shift key press is |
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 |
135 // received within long key press time out interval, then activate the next state |
136 if (mTimer->isActive() && (mLastKey == buttonId)){ |
136 if (mTimer->isActive() && (mLastKey == buttonId)){ |
137 mTimer->stop(); |
137 mTimer->stop(); |
138 HbInputState rootState; |
138 HbInputState rootState; |
139 mInputMethod->editorRootState(rootState); |
139 mInputMethod->editorRootState(rootState); |
140 mInputMethod->activateState(rootState); |
140 mInputMethod->activateState(rootState); |
141 } else { |
141 } else { |
142 updateTextCase(); |
142 updateTextCase(); |
143 mTimer->start(HbLongPressTimerTimeout); |
143 mTimer->start(HbLongPressTimerTimeout); |
144 } |
144 } |
145 mCurrentChar = 0; |
145 mCurrentChar = 0; |
146 mButtonDown = true; |
146 mButtonDown = true; |
147 mCurrentChar = 0; |
147 mCurrentChar = 0; |
148 return true; |
148 return true; |
149 } |
149 } |
150 // Let's see if we can get the handler for this button in the base class. |
150 // Let's see if we can get the handler for this button in the base class. |
151 if (q->HbInputBasicHandler::filterEvent(keyEvent)) { |
151 if (q->HbInputBasicHandler::filterEvent(keyEvent)) { |
152 return true; |
152 return true; |
153 } |
153 } |
154 |
154 |
155 mLastKey = buttonId; |
155 mLastKey = buttonId; |
156 mButtonDown = true; |
156 mButtonDown = true; |
157 |
157 |
158 handleAlphaEvent(buttonId); |
158 handleAlphaEvent(buttonId); |
159 return true; |
159 return true; |
160 } |
160 } |
161 |
161 |
162 /*! |
162 /*! |
163 Handles the key release events from the VKB. Launches the SCT with key release event of |
163 Handles the key release events from the VKB. Launches the SCT with key release event of |
164 asterisk. |
164 asterisk. |
165 */ |
165 */ |
166 bool HbHardwareInputBasic12KeyHandlerPrivate::keyReleased(const QKeyEvent *keyEvent) |
166 bool HbHardwareInputBasic12KeyHandlerPrivate::keyReleased(const QKeyEvent *keyEvent) |
167 { |
167 { |
168 Q_Q(HbHardwareInputBasic12KeyHandler); |
168 Q_Q(HbHardwareInputBasic12KeyHandler); |
169 mButtonDown = false; |
169 mButtonDown = false; |
170 int buttonId = keyEvent->key(); |
170 int buttonId = keyEvent->key(); |
171 |
171 |
172 if (buttonId == Qt::Key_Asterisk) { |
172 if (buttonId == Qt::Key_Asterisk) { |
173 //Same asterisk key is used for launching candidate list (long key press) |
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. |
174 //and also for SCT. So, do not launch SCT if candidate list is already launched. |
175 mInputMethod->switchMode(buttonId); |
175 mInputMethod->switchMode(buttonId); |
176 return true; |
176 return true; |
177 } else if (buttonId == Qt::Key_Delete) { |
177 } else if (buttonId == Qt::Key_Delete) { |
178 QKeyEvent keyEvent(QEvent::KeyRelease, Qt::Key_Backspace, Qt::NoModifier); |
178 QKeyEvent keyEvent(QEvent::KeyRelease, Qt::Key_Backspace, Qt::NoModifier); |
179 q->sendAndUpdate(keyEvent); |
179 q->sendAndUpdate(keyEvent); |
180 return true; |
180 return true; |
181 } |
181 } |
182 |
182 |
183 return false; |
183 return false; |
184 } |
184 } |
185 |
185 |
186 |
186 |
187 void HbHardwareInputBasic12KeyHandlerPrivate::_q_timeout() |
187 void HbHardwareInputBasic12KeyHandlerPrivate::_q_timeout() |
188 { |
188 { |
189 Q_Q(HbHardwareInputBasic12KeyHandler); |
189 Q_Q(HbHardwareInputBasic12KeyHandler); |
190 mTimer->stop(); |
190 mTimer->stop(); |
191 mNumChr = 0; |
191 mNumChr = 0; |
192 |
192 |
193 HbInputFocusObject *focusedObject = 0; |
193 HbInputFocusObject *focusedObject = 0; |
194 focusedObject = mInputMethod->focusObject(); |
194 focusedObject = mInputMethod->focusObject(); |
195 if (!focusedObject) { |
195 if (!focusedObject) { |
196 qDebug("HbHardwareInputBasic12KeyHandler::timeout focusObject == 0"); |
196 qDebug("HbHardwareInputBasic12KeyHandler::timeout focusObject == 0"); |
197 return; |
197 return; |
198 } |
198 } |
199 |
199 |
200 if (isEnterCharacter(mCurrentChar)) { |
200 if (isEnterCharacter(mCurrentChar)) { |
201 focusedObject->sendPreEditString(QString("")); // Make sure the enter character is cleared. |
201 focusedObject->sendPreEditString(QString("")); // Make sure the enter character is cleared. |
202 mCurrentChar = QChar('\n'); // Convert enter character to line feed. |
202 mCurrentChar = QChar('\n'); // Convert enter character to line feed. |
203 } |
203 } |
204 |
204 |
205 //Long key press number key is applicable to all keys |
205 //Long key press number key is applicable to all keys |
206 if (mButtonDown) { |
206 if (mButtonDown) { |
207 //switch to numeric mode for long key press of Hash key |
207 //switch to numeric mode for long key press of Hash key |
208 if (mLastKey == Qt::Key_Shift){ |
208 if (mLastKey == Qt::Key_Shift){ |
209 updateTextCase(); |
209 updateTextCase(); |
210 mInputMethod->switchMode(Qt::Key_Shift); |
210 mInputMethod->switchMode(Qt::Key_Shift); |
211 }else { |
211 }else { |
212 q->commitFirstMappedNumber(mLastKey); |
212 q->commitFirstMappedNumber(mLastKey); |
213 } |
213 } |
214 } else if(mLastKey != Qt::Key_Shift){ |
214 } else if(mLastKey != Qt::Key_Shift){ |
215 if (!focusedObject->characterAllowedInEditor(mCurrentChar)) { |
215 if (!focusedObject->characterAllowedInEditor(mCurrentChar)) { |
216 focusedObject->sendCommitString(QString()); |
216 focusedObject->sendCommitString(QString()); |
217 } else { |
217 } else { |
218 if ( mCurrentChar != 0){ |
218 if ( mCurrentChar != 0){ |
219 QString curString; |
219 QString curString; |
220 curString.append(mCurrentChar); |
220 curString.append(mCurrentChar); |
221 focusedObject->sendCommitString(curString); |
221 focusedObject->sendCommitString(curString); |
222 } |
222 } |
223 mInputMethod->updateState(); |
223 mInputMethod->updateState(); |
224 // pass this character to autocompleter. |
224 // pass this character to autocompleter. |
225 refreshAutoCompleter(); |
225 refreshAutoCompleter(); |
226 } |
226 } |
227 } |
227 } |
228 return; |
228 return; |
229 } |
229 } |
230 |
230 |
231 bool HbHardwareInputBasic12KeyHandlerPrivate::actionHandler(HbInputModeHandler::HbInputModeAction action) |
231 bool HbHardwareInputBasic12KeyHandlerPrivate::actionHandler(HbInputModeHandler::HbInputModeAction action) |
232 { |
232 { |
233 HbInputFocusObject *focusObject = 0; |
233 HbInputFocusObject *focusObject = 0; |
234 focusObject = mInputMethod->focusObject(); |
234 focusObject = mInputMethod->focusObject(); |
235 if (!focusObject) { |
235 if (!focusObject) { |
236 return false; |
236 return false; |
237 } |
237 } |
238 |
238 |
239 bool ret = true; |
239 bool ret = true; |
240 switch (action) { |
240 switch (action) { |
241 case HbInputModeHandler::HbInputModeActionReset: |
241 case HbInputModeHandler::HbInputModeActionReset: |
242 mLastKey = 0; |
242 mLastKey = 0; |
243 mNumChr = 0; |
243 mNumChr = 0; |
244 if (mTimer->isActive()) { |
244 if (mTimer->isActive()) { |
245 mTimer->stop(); |
245 mTimer->stop(); |
246 } |
246 } |
247 break; |
247 break; |
248 case HbInputModeHandler::HbInputModeActionDeleteAndCommit:{ |
248 case HbInputModeHandler::HbInputModeActionDeleteAndCommit:{ |
249 mTimer->stop(); |
249 mTimer->stop(); |
250 QString empty; |
250 QString empty; |
251 if(mInputMethod) { |
251 if(mInputMethod) { |
252 //In case of the sct the character is already committed |
252 //In case of the sct the character is already committed |
253 //We need to remove the committed character. |
253 //We need to remove the committed character. |
254 QList<QInputMethodEvent::Attribute> list; |
254 QList<QInputMethodEvent::Attribute> list; |
255 QInputMethodEvent event(QString(), list); |
255 QInputMethodEvent event(QString(), list); |
256 event.setCommitString(empty, -1, 1); |
256 event.setCommitString(empty, -1, 1); |
257 focusObject->sendEvent(event); |
257 focusObject->sendEvent(event); |
258 } else { |
258 } else { |
259 // Close event was originated from a button press, remove the uncommitted character. |
259 // Close event was originated from a button press, remove the uncommitted character. |
260 focusObject->sendCommitString(empty); |
260 focusObject->sendCommitString(empty); |
261 } |
261 } |
262 } |
262 } |
263 break; |
263 break; |
264 case HbInputModeHandler::HbInputModeActionFocusRecieved: |
264 case HbInputModeHandler::HbInputModeActionFocusRecieved: |
265 mTimer->stop(); |
265 mTimer->stop(); |
266 mNumChr = 0; |
266 mNumChr = 0; |
267 if (mCurrentlyFocused != focusObject) { |
267 if (mCurrentlyFocused != focusObject) { |
268 mCurrentlyFocused = focusObject; |
268 mCurrentlyFocused = focusObject; |
269 if (mAutoCompleter) { |
269 if (mAutoCompleter) { |
270 mAutoCompleter->commit(); |
270 mAutoCompleter->commit(); |
271 } |
271 } |
272 } |
272 } |
273 // set up auto completer |
273 // set up auto completer |
274 setUpAutoCompleter(); |
274 setUpAutoCompleter(); |
275 break; |
275 break; |
276 case HbInputModeHandler::HbInputModeActionCommit: |
276 case HbInputModeHandler::HbInputModeActionCommit: |
277 case HbInputModeHandler::HbInputModeActionFocusLost: |
277 case HbInputModeHandler::HbInputModeActionFocusLost: |
278 if (mTimer->isActive()) { |
278 if (mTimer->isActive()) { |
279 mTimer->stop(); |
279 mTimer->stop(); |
280 if (mCurrentChar != 0) { |
280 if (mCurrentChar != 0) { |
281 if (isEnterCharacter(mCurrentChar)) { |
281 if (isEnterCharacter(mCurrentChar)) { |
282 focusObject->sendPreEditString(QString("")); // Make sure the enter character is cleared. |
282 focusObject->sendPreEditString(QString("")); // Make sure the enter character is cleared. |
283 mCurrentChar = QChar('\n'); // Convert enter character to line feed. |
283 mCurrentChar = QChar('\n'); // Convert enter character to line feed. |
284 } |
284 } |
285 focusObject->filterAndCommitCharacter(mCurrentChar); |
285 focusObject->filterAndCommitCharacter(mCurrentChar); |
286 mCurrentChar = 0; |
286 mCurrentChar = 0; |
287 } |
287 } |
288 mLastKey = 0; |
288 mLastKey = 0; |
289 mNumChr = 0; |
289 mNumChr = 0; |
290 mInputMethod->updateState(); |
290 mInputMethod->updateState(); |
291 } |
291 } |
292 break; |
292 break; |
293 default: { |
293 default: { |
294 ret = false; |
294 ret = false; |
295 } |
295 } |
296 break; |
296 break; |
297 }; |
297 }; |
298 |
298 |
299 return ret; |
299 return ret; |
300 } |
300 } |
301 |
301 |
302 |
302 |
303 HbHardwareInputBasic12KeyHandler::HbHardwareInputBasic12KeyHandler(HbInputAbstractMethod* inputMethod) |
303 HbHardwareInputBasic12KeyHandler::HbHardwareInputBasic12KeyHandler(HbInputAbstractMethod* inputMethod) |
304 :HbInputBasicHandler( *new HbHardwareInputBasic12KeyHandlerPrivate, inputMethod) |
304 :HbInputBasicHandler( *new HbHardwareInputBasic12KeyHandlerPrivate, inputMethod) |
305 { |
305 { |
306 Q_D(HbHardwareInputBasic12KeyHandler); |
306 Q_D(HbHardwareInputBasic12KeyHandler); |
307 d->q_ptr = this; |
307 d->q_ptr = this; |
308 } |
308 } |
309 |
309 |
310 HbHardwareInputBasic12KeyHandler::~HbHardwareInputBasic12KeyHandler() |
310 HbHardwareInputBasic12KeyHandler::~HbHardwareInputBasic12KeyHandler() |
311 { |
311 { |
312 } |
312 } |