62 } |
61 } |
63 } |
62 } |
64 |
63 |
65 void HbInputPredictionHandlerPrivate::deleteOneCharacter() |
64 void HbInputPredictionHandlerPrivate::deleteOneCharacter() |
66 { |
65 { |
|
66 if (!mEngine && !mInputMethod->focusObject()) { |
|
67 return; |
|
68 } |
67 mShowTail = true; |
69 mShowTail = true; |
68 mShowTooltip = true; |
70 mShowTooltip = true; |
69 // A backspace in predictive means updating the engine for the delete key press |
71 // A backspace in predictive means updating the engine for the delete key press |
70 // and get the new candidate list from the engine. |
72 // and get the new candidate list from the engine. |
71 if ( mEngine->inputLength() >= 1 ) { |
73 if ( mEngine->inputLength() >= 1 ) { |
72 //Only autocomplition part should be deleted when autocompliton part is enable and user pressed a delete key |
74 int tailLength = mInputMethod->focusObject()->preEditString().length() - mEngine->inputLength(); |
73 if(false == mTailShowing) { |
75 //Only autocomplition part should be deleted when autocompliton part is shown and user pressed a delete key |
|
76 if(tailLength <= 0) { // no autocompletion part displayed |
74 mEngine->deleteKeyPress( this ); |
77 mEngine->deleteKeyPress( this ); |
75 } |
78 } |
76 //To prevent showing autocompletion part while deleting the characters using backspace key |
79 //To prevent showing autocompletion part while deleting the characters using backspace key |
77 mShowTail = false; |
80 mShowTail = false; |
78 mShowTooltip = false; |
81 mShowTooltip = false; |
216 list.append(QInputMethodEvent::Attribute(QInputMethodEvent::TextFormat, mEngine->inputLength(), taillength, gray)); |
219 list.append(QInputMethodEvent::Attribute(QInputMethodEvent::TextFormat, mEngine->inputLength(), taillength, gray)); |
217 } |
220 } |
218 list.append(QInputMethodEvent::Attribute(QInputMethodEvent::Cursor, mEngine->inputLength(), 0, 0)); |
221 list.append(QInputMethodEvent::Attribute(QInputMethodEvent::Cursor, mEngine->inputLength(), 0, 0)); |
219 QInputMethodEvent event(mCandidates->at(mBestGuessLocation), list); |
222 QInputMethodEvent event(mCandidates->at(mBestGuessLocation), list); |
220 focusedObject->sendEvent(event); |
223 focusedObject->sendEvent(event); |
221 mTailShowing = true; |
|
222 } else { |
224 } else { |
223 list.append(QInputMethodEvent::Attribute(QInputMethodEvent::Cursor, mCandidates->at(mBestGuessLocation).length(), 0, 0)); |
225 list.append(QInputMethodEvent::Attribute(QInputMethodEvent::Cursor, mCandidates->at(mBestGuessLocation).length(), 0, 0)); |
224 QInputMethodEvent event(mCandidates->at(mBestGuessLocation).left(mEngine->inputLength()), list); |
226 QInputMethodEvent event(mCandidates->at(mBestGuessLocation).left(mEngine->inputLength()), list); |
225 focusedObject->sendEvent(event); |
227 focusedObject->sendEvent(event); |
226 mTailShowing = false; |
|
227 } |
228 } |
228 if (mShowTooltip && mBestGuessLocation > 0 && mCandidates->at(0).mid(0, mEngine->inputLength()) \ |
229 if (mShowTooltip && mBestGuessLocation > 0 && mCandidates->at(0).mid(0, mEngine->inputLength()) \ |
229 != mCandidates->at(mBestGuessLocation).mid(0, mEngine->inputLength())) { |
230 != mCandidates->at(mBestGuessLocation).mid(0, mEngine->inputLength())) { |
230 q->processExactWord(mCandidates->at(0)); |
231 q->processExactWord(mCandidates->at(0)); |
231 } else { |
232 } else { |
271 deleteOneCharacter(); |
272 deleteOneCharacter(); |
272 } |
273 } |
273 } |
274 } |
274 ret = true; |
275 ret = true; |
275 break; |
276 break; |
276 case Qt::Key_Period: // TODO: better handling for punctuation |
277 |
277 case Qt::Key_Comma: { // Need to take fn, shift etc. in account |
|
278 HbModifier modifier = HbModifierNone; |
|
279 int currentTextCase = focusObject->editorInterface().textCase(); |
|
280 if ( HbTextCaseUpper == currentTextCase || HbTextCaseAutomatic == currentTextCase ) { |
|
281 modifier = HbModifierShiftPressed; |
|
282 } |
|
283 QString qc; |
|
284 const HbMappedKey* mappedKey = mKeymap->keyForKeycode(mInputMethod->inputState().keyboard(), event->key()); |
|
285 |
|
286 if (mappedKey) { |
|
287 if (modifier == HbModifierNone) { |
|
288 qc = mappedKey->characters(HbModifierNone).left(1); |
|
289 } else if (modifier == HbModifierShiftPressed) { |
|
290 qc = mappedKey->characters(HbModifierShiftPressed).left(1); |
|
291 } |
|
292 } |
|
293 |
|
294 if (mEngine->inputLength() == 0) { |
|
295 QList<QInputMethodEvent::Attribute> list; |
|
296 QInputMethodEvent event(QString(), list); |
|
297 if (mAutoAddedSpace) { |
|
298 int cursorPos = mInputMethod->focusObject()->inputMethodQuery(Qt::ImCursorPosition).toInt(); |
|
299 QString text = mInputMethod->focusObject()->inputMethodQuery(Qt::ImSurroundingText).toString(); |
|
300 if (cursorPos > 0 && text.at(cursorPos-1).isSpace()) { |
|
301 event.setCommitString(qc, -1, 1); |
|
302 } else { |
|
303 event.setCommitString(qc); |
|
304 } |
|
305 } else { |
|
306 event.setCommitString(qc); |
|
307 } |
|
308 mAutoAddedSpace = false; |
|
309 q->sendAndUpdate(event); |
|
310 } else { |
|
311 // Fix for input stopping after ,. keys in qwerty predictive |
|
312 commitAndAppendCharacter(qc.at(0)); |
|
313 QString empty; |
|
314 q->processExactWord(empty); |
|
315 } |
|
316 ret = true; |
|
317 } |
|
318 break; |
|
319 case HbInputButton::ButtonKeyCodeEnter: |
278 case HbInputButton::ButtonKeyCodeEnter: |
320 case HbInputButton::ButtonKeyCodeSpace: |
279 case HbInputButton::ButtonKeyCodeSpace: |
321 case Qt::Key_0: {//Space |
280 |
|
281 { |
322 // A space means we have to commit the candidates when we are in predictive mode. |
282 // A space means we have to commit the candidates when we are in predictive mode. |
323 QChar qc(event->key()); |
283 QChar qc(event->key()); |
324 if (qc == Qt::Key_Enter) { |
284 if (qc == Qt::Key_Enter) { |
325 qc = QChar('\n'); // Editor expects normal line feed. |
285 qc = QChar('\n'); // Editor expects normal line feed. |
326 } else if (qc == Qt::Key_0) { |
286 } |
327 qc = QChar(' '); |
|
328 } |
|
329 commitAndAppendCharacter(qc); |
287 commitAndAppendCharacter(qc); |
330 // if exact word popup functionality is on then we should inform exact word popup |
288 // if exact word popup functionality is on then we should inform exact word popup |
331 // about the space.//++TODO |
289 // about the space.//++TODO |
332 QString empty; |
290 QString empty; |
333 q->processExactWord(empty); |
291 q->processExactWord(empty); |