79 mEngine->deleteKeyPress( this ); |
79 mEngine->deleteKeyPress( this ); |
80 } |
80 } |
81 //To prevent showing autocompletion part while deleting the characters using backspace key |
81 //To prevent showing autocompletion part while deleting the characters using backspace key |
82 mShowTail = false; |
82 mShowTail = false; |
83 mShowTooltip = false; |
83 mShowTooltip = false; |
84 bool unused = false; |
84 bool unused = false; |
85 mEngine->updateCandidates(mBestGuessLocation, unused); |
85 mEngine->updateCandidates(mBestGuessLocation, unused); |
86 //If Input length greater or equal to one then Append the current word to candidate |
86 //If Input length greater or equal to one then Append the current word to candidate |
87 if (!mCandidates->count() && mEngine->inputLength() >= 1) { |
87 if (!mCandidates->count() && mEngine->inputLength() >= 1) { |
88 mCandidates->append(mEngine->currentWord()); |
88 mCandidates->append(mEngine->currentWord()); |
89 } |
89 } |
90 mCanContinuePrediction = true; |
90 mCanContinuePrediction = true; |
91 // update the editor with the new preedit text. |
91 // update the editor with the new preedit text. |
92 updateEditor(); |
92 updateEditor(); |
93 return; |
93 return; |
94 } else { |
94 } else { |
95 // we come here if their is no data in engine. |
95 // we come here if their is no data in engine. |
96 // once the word is committed, we can not bring it back to inline edit. |
96 // once the word is committed, we can not bring it back to inline edit. |
97 // so if the engine does not have any data, we just send backspace event to the editor. |
97 // so if the engine does not have any data, we just send backspace event to the editor. |
98 Q_Q(HbInputPredictionHandler); |
98 Q_Q(HbInputPredictionHandler); |
99 QKeyEvent event = QKeyEvent(QEvent::KeyPress, Qt::Key_Backspace, Qt::NoModifier); |
99 QKeyEvent event = QKeyEvent(QEvent::KeyPress, Qt::Key_Backspace, Qt::NoModifier); |
100 q->sendAndUpdate(event); |
100 q->sendAndUpdate(event); |
101 event = QKeyEvent(QEvent::KeyRelease, Qt::Key_Backspace, Qt::NoModifier); |
101 event = QKeyEvent(QEvent::KeyRelease, Qt::Key_Backspace, Qt::NoModifier); |
102 q->sendAndUpdate(event); |
102 q->sendAndUpdate(event); |
103 return; |
103 return; |
104 } |
104 } |
206 } else { |
206 } else { |
207 if (mCandidates->count() > mBestGuessLocation) { |
207 if (mCandidates->count() > mBestGuessLocation) { |
208 int taillength = mCandidates->at(mBestGuessLocation).length() - mEngine->inputLength(); |
208 int taillength = mCandidates->at(mBestGuessLocation).length() - mEngine->inputLength(); |
209 if (taillength > 0 && mShowTail) { |
209 if (taillength > 0 && mShowTail) { |
210 // TODO: Color from skin should be used |
210 // TODO: Color from skin should be used |
211 QColor col = HbColorScheme::color("qtc_input_hint_normal"); |
211 QColor col = HbColorScheme::color("qtc_input_hint_normal"); |
212 QBrush brush(col); |
212 QBrush brush(col); |
213 QTextCharFormat gray; |
213 QTextCharFormat gray; |
214 gray.setForeground(brush); |
214 gray.setForeground(brush); |
215 if((focusedObject->object())->inherits("QGraphicsWebView") || (focusedObject->object())->inherits("QWebView")) { |
215 if((focusedObject->object())->inherits("QGraphicsWebView") || (focusedObject->object())->inherits("QWebView")) { |
216 //QGraphicsWebView does not handle partial input length formatting well. Causes crash, a temporary fix provided, |
216 //QGraphicsWebView does not handle partial input length formatting well. Causes crash, a temporary fix provided, |
218 //This should be treated as a work around till QGraphicsWebView is fixed. |
218 //This should be treated as a work around till QGraphicsWebView is fixed. |
219 list.append(QInputMethodEvent::Attribute(QInputMethodEvent::TextFormat, 0, QInputMethodEvent::TextFormat, gray)); |
219 list.append(QInputMethodEvent::Attribute(QInputMethodEvent::TextFormat, 0, QInputMethodEvent::TextFormat, gray)); |
220 } else { |
220 } else { |
221 list.append(QInputMethodEvent::Attribute(QInputMethodEvent::TextFormat, mEngine->inputLength(), taillength, gray)); |
221 list.append(QInputMethodEvent::Attribute(QInputMethodEvent::TextFormat, mEngine->inputLength(), taillength, gray)); |
222 } |
222 } |
223 list.append(QInputMethodEvent::Attribute(QInputMethodEvent::Cursor, mEngine->inputLength(), 0, 0)); |
223 list.append(QInputMethodEvent::Attribute(QInputMethodEvent::Cursor, mEngine->inputLength(), 0, 0)); |
224 QInputMethodEvent event(mCandidates->at(mBestGuessLocation), list); |
224 QInputMethodEvent event(mCandidates->at(mBestGuessLocation), list); |
225 focusedObject->sendEvent(event); |
225 focusedObject->sendEvent(event); |
226 } else { |
226 } else { |
227 list.append(QInputMethodEvent::Attribute(QInputMethodEvent::Cursor, mCandidates->at(mBestGuessLocation).length(), 0, 0)); |
227 list.append(QInputMethodEvent::Attribute(QInputMethodEvent::Cursor, mCandidates->at(mBestGuessLocation).length(), 0, 0)); |
228 QInputMethodEvent event(mCandidates->at(mBestGuessLocation).left(mEngine->inputLength()), list); |
228 QInputMethodEvent event(mCandidates->at(mBestGuessLocation).left(mEngine->inputLength()), list); |
229 focusedObject->sendEvent(event); |
229 focusedObject->sendEvent(event); |
230 } |
230 } |
231 if (mShowTooltip && mBestGuessLocation > 0 && mCandidates->at(0).mid(0, mEngine->inputLength()) \ |
231 if (mShowTooltip && mBestGuessLocation > 0 && mCandidates->at(0).mid(0, mEngine->inputLength()) \ |
232 != mCandidates->at(mBestGuessLocation).mid(0, mEngine->inputLength())) { |
232 != mCandidates->at(mBestGuessLocation).mid(0, mEngine->inputLength())) { |
264 case Qt::Key_Backspace: |
264 case Qt::Key_Backspace: |
265 case HbInputButton::ButtonKeyCodeDelete: |
265 case HbInputButton::ButtonKeyCodeDelete: |
266 { |
266 { |
267 QString currentSelection = focusObject->inputMethodQuery(Qt::ImCurrentSelection).toString(); |
267 QString currentSelection = focusObject->inputMethodQuery(Qt::ImCurrentSelection).toString(); |
268 if(currentSelection.length()) { |
268 if(currentSelection.length()) { |
269 QKeyEvent event = QKeyEvent(QEvent::KeyPress, Qt::Key_Backspace, Qt::NoModifier); |
269 QKeyEvent event = QKeyEvent(QEvent::KeyPress, Qt::Key_Backspace, Qt::NoModifier); |
270 q->sendAndUpdate(event); |
270 q->sendAndUpdate(event); |
271 event = QKeyEvent(QEvent::KeyRelease, Qt::Key_Backspace, Qt::NoModifier); |
271 event = QKeyEvent(QEvent::KeyRelease, Qt::Key_Backspace, Qt::NoModifier); |
272 q->sendAndUpdate(event); |
272 q->sendAndUpdate(event); |
273 } else { |
273 } else { |
274 deleteOneCharacter(); |
274 deleteOneCharacter(); |
275 } |
275 } |
276 } |
276 } |
277 ret = true; |
277 ret = true; |
278 break; |
278 break; |
279 |
279 |
280 case HbInputButton::ButtonKeyCodeEnter: |
280 case HbInputButton::ButtonKeyCodeEnter: |
281 case HbInputButton::ButtonKeyCodeSpace: |
281 case HbInputButton::ButtonKeyCodeSpace: |
406 } |
406 } |
407 |
407 |
408 void HbInputPredictionHandlerPrivate::commit() |
408 void HbInputPredictionHandlerPrivate::commit() |
409 { |
409 { |
410 if (mEngine && mEngine->inputLength() > 0 && mCandidates->count() > 0) { |
410 if (mEngine && mEngine->inputLength() > 0 && mCandidates->count() > 0) { |
411 |
411 |
412 // Close exact word pop up in qwerty when the word is committed |
412 // Close exact word pop up in qwerty when the word is committed |
413 if(HbInputUtils::isQwertyKeyboard(mInputMethod->inputState().keyboard())) { |
413 if(HbInputUtils::isQwertyKeyboard(mInputMethod->inputState().keyboard())) { |
414 mInputMethod->closeExactWordPopup(); |
414 mInputMethod->closeExactWordPopup(); |
415 } |
415 } |
416 |
416 |
417 QString commitString = getCommitString(); |
417 QString commitString = getCommitString(); |
418 |
418 |
419 // need to update the freq information |
419 // need to update the freq information |
420 mEngine->commit(commitString); |
420 mEngine->commit(commitString); |
421 commit(commitString,false); |
421 commit(commitString,false); |
448 void HbInputPredictionHandlerPrivate::commit(const QString& string, bool addToUsedWordDict, bool isAsync) |
448 void HbInputPredictionHandlerPrivate::commit(const QString& string, bool addToUsedWordDict, bool isAsync) |
449 { |
449 { |
450 Q_Q(HbInputPredictionHandler); |
450 Q_Q(HbInputPredictionHandler); |
451 |
451 |
452 // Close exact word pop up in qwerty when the word is committed |
452 // Close exact word pop up in qwerty when the word is committed |
453 if(HbInputUtils::isQwertyKeyboard(mInputMethod->inputState().keyboard())) { |
453 if(HbInputUtils::isQwertyKeyboard(mInputMethod->inputState().keyboard())) { |
454 mInputMethod->closeExactWordPopup(); |
454 mInputMethod->closeExactWordPopup(); |
455 } |
455 } |
456 |
456 |
457 q->commitAndUpdate(string, 0, 0, isAsync); |
457 q->commitAndUpdate(string, 0, 0, isAsync); |
458 |
458 |
459 if(mEngine) { |
459 if(mEngine) { |
460 if(addToUsedWordDict && !string.isEmpty()) { |
460 if(addToUsedWordDict && !string.isEmpty()) { |
480 */ |
480 */ |
481 void HbInputPredictionHandlerPrivate::commit(QInputMethodEvent & event,bool addToUsedWordDict) |
481 void HbInputPredictionHandlerPrivate::commit(QInputMethodEvent & event,bool addToUsedWordDict) |
482 { |
482 { |
483 Q_Q(HbInputPredictionHandler); |
483 Q_Q(HbInputPredictionHandler); |
484 |
484 |
485 // Close exact word pop up in qwerty when the word is committed |
485 // Close exact word pop up in qwerty when the word is committed |
486 if(HbInputUtils::isQwertyKeyboard(mInputMethod->inputState().keyboard())) { |
486 if(HbInputUtils::isQwertyKeyboard(mInputMethod->inputState().keyboard())) { |
487 mInputMethod->closeExactWordPopup(); |
487 mInputMethod->closeExactWordPopup(); |
488 } |
488 } |
489 |
489 |
490 q->sendAndUpdate(event); |
490 q->sendAndUpdate(event); |
491 |
491 |
492 if(mEngine) { |
492 if(mEngine) { |
493 if(addToUsedWordDict && !event.commitString().isEmpty()) |
493 if(addToUsedWordDict && !event.commitString().isEmpty()) |
529 } |
529 } |
530 //Temporarily delete the key press |
530 //Temporarily delete the key press |
531 mEngine->deleteKeyPress(); |
531 mEngine->deleteKeyPress(); |
532 mEngine->updateCandidates(mBestGuessLocation, isCustomWord); |
532 mEngine->updateCandidates(mBestGuessLocation, isCustomWord); |
533 if (mCandidates->count()){ |
533 if (mCandidates->count()){ |
534 (*mCandidates)[mBestGuessLocation] = (*mCandidates)[mBestGuessLocation].left(mEngine->inputLength()); |
534 (*mCandidates)[mBestGuessLocation] = (*mCandidates)[mBestGuessLocation].left(mEngine->inputLength()); |
535 (*mCandidates)[mBestGuessLocation].append("?"); |
535 (*mCandidates)[mBestGuessLocation].append("?"); |
536 } else { |
536 } else { |
537 //Should the mBestGuessLocation not be zero. |
537 //Should the mBestGuessLocation not be zero. |
538 mBestGuessLocation = 0; |
538 mBestGuessLocation = 0; |
539 mCandidates->append(mEngine->currentWord()); |
539 mCandidates->append(mEngine->currentWord()); |
553 |
553 |
554 void HbInputPredictionHandlerPrivate::setPreEditTextToEditor(QString string, bool showAutocompletionPart) |
554 void HbInputPredictionHandlerPrivate::setPreEditTextToEditor(QString string, bool showAutocompletionPart) |
555 { |
555 { |
556 //update the editor with pre-edit text |
556 //update the editor with pre-edit text |
557 mEngine->setWord(string); |
557 mEngine->setWord(string); |
558 bool used = false; |
558 bool used = false; |
559 mEngine->updateCandidates(mBestGuessLocation, used); |
559 mEngine->updateCandidates(mBestGuessLocation, used); |
560 if(showAutocompletionPart && mShowTail) { |
560 if(showAutocompletionPart && mShowTail) { |
561 mShowTail = true; |
561 mShowTail = true; |
562 } else { |
562 } else { |
563 mShowTail = false; |
563 mShowTail = false; |
729 this SLOT is called when a character in sct is selected. |
729 this SLOT is called when a character in sct is selected. |
730 */ |
730 */ |
731 void HbInputPredictionHandler::sctCharacterSelected(QString character) |
731 void HbInputPredictionHandler::sctCharacterSelected(QString character) |
732 { |
732 { |
733 Q_D(HbInputPredictionHandler); |
733 Q_D(HbInputPredictionHandler); |
734 //d->mShowTail = false; |
734 //d->mShowTail = false; |
735 d->commit(); |
735 d->commit(); |
736 HbInputModeHandler::sctCharacterSelected(character); |
736 HbInputModeHandler::sctCharacterSelected(character); |
737 } |
737 } |
738 |
738 |
739 void HbInputPredictionHandler::smileySelected(QString smiley) |
739 void HbInputPredictionHandler::smileySelected(QString smiley) |
839 newFocusObject->setFocus(); |
839 newFocusObject->setFocus(); |
840 HbAbstractEdit *abstractEdit = qobject_cast<HbAbstractEdit*>(savedFocusObject); |
840 HbAbstractEdit *abstractEdit = qobject_cast<HbAbstractEdit*>(savedFocusObject); |
841 if(abstractEdit) { |
841 if(abstractEdit) { |
842 abstractEdit->setCursorPosition(abstractEdit->cursorPosition()); |
842 abstractEdit->setCursorPosition(abstractEdit->cursorPosition()); |
843 } |
843 } |
844 HbInputMethod::activeInputMethod()->setFocusObject(newFocusObject); |
844 HbInputMethod::activeInputMethod()->setFocusObject(newFocusObject); |
845 |
845 |
846 if (closeReason == HbInputSpellQuery::HbOkPressed) { |
846 if (closeReason == HbInputSpellQuery::HbOkPressed) { |
847 d->commit(string,true); |
847 d->commit(string,true); |
848 } else if(closeReason == HbInputSpellQuery::HbCancelPressed) { |
848 } else if(closeReason == HbInputSpellQuery::HbCancelPressed) { |
849 //update the editor with pre-edit text |
849 //update the editor with pre-edit text |