32 #include <hbaction.h> |
32 #include <hbaction.h> |
33 #include <hbinputvkbhost.h> |
33 #include <hbinputvkbhost.h> |
34 #include <hbcolorscheme.h> |
34 #include <hbcolorscheme.h> |
35 #include <hbinpututils.h> |
35 #include <hbinpututils.h> |
36 #include <hbinputbutton.h> |
36 #include <hbinputbutton.h> |
|
37 #include "hbinputspellquerydialog.h" |
37 #include "../touchinput/virtualqwerty.h" |
38 #include "../touchinput/virtualqwerty.h" |
38 |
39 |
39 #include "hbinputpredictionhandler_p.h" |
40 #include "hbinputpredictionhandler_p.h" |
40 #include "hbinputabstractbase.h" |
41 #include "hbinputabstractbase.h" |
41 |
42 |
166 This function shows the exact popup if needed. |
168 This function shows the exact popup if needed. |
167 */ |
169 */ |
168 void HbInputPredictionHandlerPrivate::showExactWordPopupIfNeeded() |
170 void HbInputPredictionHandlerPrivate::showExactWordPopupIfNeeded() |
169 { |
171 { |
170 Q_Q(HbInputPredictionHandler); |
172 Q_Q(HbInputPredictionHandler); |
171 if (mShowTooltip && mBestGuessLocation > 0 && mCandidates->at(0).mid(0, mEngine->inputLength()) \ |
173 if (mShowTooltip && mBestGuessLocation > 0 && mCandidates->count() > 0 |
|
174 && mCandidates->at(0).mid(0, mEngine->inputLength()) \ |
172 != mCandidates->at(mBestGuessLocation).mid(0, mEngine->inputLength())) { |
175 != mCandidates->at(mBestGuessLocation).mid(0, mEngine->inputLength())) { |
173 q->processExactWord(mCandidates->at(0)); |
176 q->processExactWord(mCandidates->at(0)); |
174 } else { |
177 } else { |
175 QString empty; |
178 QString empty; |
176 q->processExactWord(empty); |
179 q->processExactWord(empty); |
220 // TODO: Color from skin should be used |
223 // TODO: Color from skin should be used |
221 QColor col = HbColorScheme::color("qtc_input_hint_normal"); |
224 QColor col = HbColorScheme::color("qtc_input_hint_normal"); |
222 QBrush brush(col); |
225 QBrush brush(col); |
223 QTextCharFormat gray; |
226 QTextCharFormat gray; |
224 gray.setForeground(brush); |
227 gray.setForeground(brush); |
225 list.append(QInputMethodEvent::Attribute(QInputMethodEvent::TextFormat, mEngine->inputLength(), taillength, gray)); |
228 if((focusedObject->object())->inherits("QGraphicsWebView") || (focusedObject->object())->inherits("QWebView")) { |
|
229 //QGraphicsWebView does not handle partial input length formatting well. Causes crash, a temporary fix provided, |
|
230 //This makes the whole text field grey insted of just the auto-completion part. Anyways, it does not cause crash. |
|
231 //This should be treated as a work around till QGraphicsWebView is fixed. |
|
232 list.append(QInputMethodEvent::Attribute(QInputMethodEvent::TextFormat, 0, QInputMethodEvent::TextFormat, gray)); |
|
233 } else { |
|
234 list.append(QInputMethodEvent::Attribute(QInputMethodEvent::TextFormat, mEngine->inputLength(), taillength, gray)); |
|
235 } |
226 list.append(QInputMethodEvent::Attribute(QInputMethodEvent::Cursor, mEngine->inputLength(), 0, 0)); |
236 list.append(QInputMethodEvent::Attribute(QInputMethodEvent::Cursor, mEngine->inputLength(), 0, 0)); |
227 QInputMethodEvent event(mCandidates->at(mBestGuessLocation), list); |
237 QInputMethodEvent event(mCandidates->at(mBestGuessLocation), list); |
228 focusedObject->sendEvent(event); |
238 focusedObject->sendEvent(event); |
229 mTailShowing = true; |
239 mTailShowing = true; |
230 } else { |
240 } else { |
250 bool HbInputPredictionHandlerPrivate::filterEvent(const QKeyEvent * event) |
260 bool HbInputPredictionHandlerPrivate::filterEvent(const QKeyEvent * event) |
251 { |
261 { |
252 HbInputFocusObject* focusObject = 0; |
262 HbInputFocusObject* focusObject = 0; |
253 focusObject = mInputMethod->focusObject(); |
263 focusObject = mInputMethod->focusObject(); |
254 //If the focused object is NULL or the key event is improper, can not continue |
264 //If the focused object is NULL or the key event is improper, can not continue |
255 if(!focusObject || (event->key()<0)) { |
265 if(!focusObject || event->key() < 0 || |
|
266 event->key() == HbInputButton::ButtonKeyCodeCustom) { |
256 return false; |
267 return false; |
257 } |
268 } |
258 |
269 |
259 Q_Q(HbInputPredictionHandler); |
270 Q_Q(HbInputPredictionHandler); |
260 if (!mEngine) { |
271 if (!mEngine) { |
423 if(!mCanContinuePrediction && (*mCandidates)[mBestGuessLocation].endsWith('?')) { |
434 if(!mCanContinuePrediction && (*mCandidates)[mBestGuessLocation].endsWith('?')) { |
424 // mouse has been clicked on the pre-editing string ends with "?" |
435 // mouse has been clicked on the pre-editing string ends with "?" |
425 //Remove the "?" mark |
436 //Remove the "?" mark |
426 (*mCandidates)[mBestGuessLocation].chop(1); |
437 (*mCandidates)[mBestGuessLocation].chop(1); |
427 updateEditor(); |
438 updateEditor(); |
428 q->processCustomWord((*mCandidates)[mBestGuessLocation]); |
439 q->launchSpellQueryDialog(); |
429 mCanContinuePrediction = true; |
440 mCanContinuePrediction = true; |
430 } else { |
441 } else { |
431 |
442 |
432 //The mouse has been clicked on the pre-editing word, launch candidate list |
443 //The mouse has been clicked on the pre-editing word, launch candidate list |
433 mInputMethod->launchCandidatePopup(*mCandidates); |
444 mInputMethod->launchCandidatePopup(*mCandidates); |
599 } else { |
610 } else { |
600 mCanContinuePrediction = true; |
611 mCanContinuePrediction = true; |
601 } |
612 } |
602 } |
613 } |
603 |
614 |
|
615 void HbInputPredictionHandlerPrivate::setPreEditTextToEditor(QString string) |
|
616 { |
|
617 //update the editor with pre-edit text |
|
618 mEngine->setWord(string); |
|
619 bool used = false; |
|
620 mEngine->updateCandidates(mBestGuessLocation, used); |
|
621 mTailShowing = true; |
|
622 updateEditor(); |
|
623 |
|
624 } |
|
625 |
604 HbInputPredictionHandler::HbInputPredictionHandler(HbInputPredictionHandlerPrivate &dd, HbInputAbstractMethod* inputMethod) |
626 HbInputPredictionHandler::HbInputPredictionHandler(HbInputPredictionHandlerPrivate &dd, HbInputAbstractMethod* inputMethod) |
605 :HbInputModeHandler(dd, inputMethod) |
627 :HbInputModeHandler(dd, inputMethod) |
606 { |
628 { |
607 Q_D(HbInputPredictionHandler); |
629 Q_D(HbInputPredictionHandler); |
608 d->q_ptr = this; |
630 d->q_ptr = this; |
629 bool HbInputPredictionHandler::actionHandler(HbInputModeAction action) |
651 bool HbInputPredictionHandler::actionHandler(HbInputModeAction action) |
630 { |
652 { |
631 Q_D(HbInputPredictionHandler); |
653 Q_D(HbInputPredictionHandler); |
632 bool ret = true; |
654 bool ret = true; |
633 switch (action) { |
655 switch (action) { |
634 case HbInputModeActionReset: { |
656 case HbInputModeActionReset: |
|
657 case HbInputModeActionCommit: |
|
658 case HbInputModeActionFocusLost: { |
635 //At the moment we are commiting the text with the autocompletion part as it needs to be committed on clicking outside the editor. |
659 //At the moment we are commiting the text with the autocompletion part as it needs to be committed on clicking outside the editor. |
636 //TO DO : When We back to the application by pressing Application key the inline word should not commit and remain in the inline editing |
660 //TO DO : When We back to the application by pressing Application key the inline word should not commit and remain in the inline editing |
637 //d->mShowTail = false; |
661 //d->mShowTail = false; |
638 d->commit(); |
662 d->commit(); |
639 d->reset(); |
663 d->reset(); |
640 } |
|
641 break; |
|
642 case HbInputModeActionFocusLost: { |
|
643 // if focus lost happens and before that if toolitip is available then typing line word should be committed in the editor |
|
644 // if tooltip and autocompletion part is available then typing line word should be committed in the editor along with the autocompletion part |
|
645 // Focus change should commit the auto-completed part as well. |
|
646 d->commit(); |
|
647 } |
|
648 break; |
|
649 case HbInputModeActionCommit: { |
|
650 d->commit(); |
|
651 } |
664 } |
652 break; |
665 break; |
653 case HbInputModeActionDeleteAndCommit: { |
666 case HbInputModeActionDeleteAndCommit: { |
654 deleteOneCharacter(); |
667 deleteOneCharacter(); |
655 d->commit(); |
668 d->commit(); |
811 void HbInputPredictionHandler::processExactWord(QString exactWord) |
827 void HbInputPredictionHandler::processExactWord(QString exactWord) |
812 { |
828 { |
813 Q_UNUSED(exactWord); |
829 Q_UNUSED(exactWord); |
814 } |
830 } |
815 |
831 |
816 void HbInputPredictionHandler::processCustomWord(QString customWord) |
|
817 { |
|
818 Q_UNUSED(customWord); |
|
819 } |
|
820 |
|
821 void HbInputPredictionHandler::showExactWordPopupIfNeeded() |
832 void HbInputPredictionHandler::showExactWordPopupIfNeeded() |
822 { |
833 { |
823 Q_D(HbInputPredictionHandler); |
834 Q_D(HbInputPredictionHandler); |
824 d->showExactWordPopupIfNeeded(); |
835 d->showExactWordPopupIfNeeded(); |
825 } |
836 } |
|
837 |
|
838 // Launch spell query dialog in responce to launchSpellQueryDialog signal |
|
839 void HbInputPredictionHandler::launchSpellQueryDialog() |
|
840 { |
|
841 Q_D(HbInputPredictionHandler); |
|
842 HbInputFocusObject *focusedObject = d->mInputMethod->focusObject(); |
|
843 if(!focusedObject) { |
|
844 return; |
|
845 } |
|
846 |
|
847 // As of now we need to delete and create mSpellQueryDialog every time |
|
848 // we launch it. If we launch the same dialog, keypad does not open sometimes. |
|
849 // Will take sometime to find out the root cause of this, and will fix this. |
|
850 if(d->mSpellQueryDialog) { |
|
851 delete d->mSpellQueryDialog; |
|
852 d->mSpellQueryDialog =0; |
|
853 } |
|
854 if(!d->mSpellQueryDialog) { |
|
855 d->mSpellQueryDialog = new HbInputSpellQuery(d->mInputMethod,this); |
|
856 d->mSpellQueryDialog->setParent(this); |
|
857 } |
|
858 |
|
859 QString string; |
|
860 if(d->mCandidates && (*(d->mCandidates)).size() >= d->mBestGuessLocation + 1) { |
|
861 string = (*(d->mCandidates))[d->mBestGuessLocation].left(d->mEngine->inputLength()); |
|
862 } |
|
863 d->reset(); |
|
864 d->mSpellQueryDialog->launch(string); |
|
865 |
|
866 } |
|
867 |
|
868 // To force the spell query dialog to close. |
|
869 void HbInputPredictionHandler::closeSpellQueryDialog() |
|
870 { |
|
871 Q_D(HbInputPredictionHandler); |
|
872 if (d->mSpellQueryDialog && d->mSpellQueryDialog->isVisible()) { |
|
873 d->mSpellQueryDialog->close(); |
|
874 } |
|
875 } |
|
876 |
|
877 // |
|
878 void HbInputPredictionHandler::spellQueryDialogClosed(QObject *savedFocusObject,bool isOk,QString string) |
|
879 { |
|
880 Q_D(HbInputPredictionHandler); |
|
881 |
|
882 // set the focus back to the editor which caused the launch of spell dialog. |
|
883 if(savedFocusObject) { |
|
884 HbInputFocusObject *newFocusObject = new HbInputFocusObject(savedFocusObject); |
|
885 newFocusObject->releaseFocus(); |
|
886 newFocusObject->setFocus(); |
|
887 HbAbstractEdit *abstractEdit = qobject_cast<HbAbstractEdit*>(savedFocusObject); |
|
888 if(abstractEdit) { |
|
889 abstractEdit->setCursorPosition(abstractEdit->cursorPosition()); |
|
890 } |
|
891 d->mInputMethod->setFocusObject(newFocusObject); |
|
892 } |
|
893 |
|
894 if (isOk) { |
|
895 d->commit(string,true); |
|
896 } else { |
|
897 //update the editor with pre-edit text |
|
898 d->setPreEditTextToEditor(string); |
|
899 // This update is need for below usecase |
|
900 // Editor is empty => enter some data till their is no match => click on word |
|
901 // to lauch spell query => now press cancel => testcase of keypad is uppercase, |
|
902 // but it should be lower case |
|
903 d->mInputMethod->updateState(); |
|
904 } |
|
905 } |
826 // EOF |
906 // EOF |