src/hbplugins/inputmethods/touchinput/hbinputpredictionqwertyhandler.cpp
changeset 5 627c4a0fd0e7
parent 2 06ff229162e9
child 6 c3690ec91ef8
equal deleted inserted replaced
3:11d3954df52a 5:627c4a0fd0e7
    46     void init();
    46     void init();
    47 
    47 
    48 public:
    48 public:
    49     int mButton;    
    49     int mButton;    
    50     HbFnState mFnState;
    50     HbFnState mFnState;
    51     bool mExactPopupLaunched;
    51     bool mExactPopupLaunched;    
    52     bool mLongPressHappened;
       
    53 };
    52 };
    54 
    53 
    55 HbInputPredictionQwertyHandlerPrivate::HbInputPredictionQwertyHandlerPrivate()
    54 HbInputPredictionQwertyHandlerPrivate::HbInputPredictionQwertyHandlerPrivate()
    56 :mButton(0),    
    55 :mButton(0),    
    57     mFnState(HbFnOff),
    56     mFnState(HbFnOff),
    58     mExactPopupLaunched(false),
    57     mExactPopupLaunched(false)
    59     mLongPressHappened(false)
       
    60 {
    58 {
    61 }
    59 }
    62 
    60 
    63 HbInputPredictionQwertyHandlerPrivate::~HbInputPredictionQwertyHandlerPrivate()
    61 HbInputPredictionQwertyHandlerPrivate::~HbInputPredictionQwertyHandlerPrivate()
    64 {
    62 {
    76     if (!focusObject) {
    74     if (!focusObject) {
    77         qDebug("HbVirtualQwerty::virtualButtonClicked : no focused editor widget!");
    75         qDebug("HbVirtualQwerty::virtualButtonClicked : no focused editor widget!");
    78         return false;
    76         return false;
    79     }
    77     }
    80 
    78 
    81     if (mLongPressHappened) {
       
    82         mLongPressHappened = false;
       
    83         return false;
       
    84     }
       
    85 
    79 
    86     int key = event->key();
    80     int key = event->key();
    87     
    81     
    88     bool ret = true;
    82     bool ret = true;
    89     switch(key) {    
    83     switch(key) {    
    95             } else {
    89             } else {
    96                 mFnState = HbFnOff;
    90                 mFnState = HbFnOff;
    97             }
    91             }
    98         break;
    92         break;
    99     case HbInputButton::ButtonKeyCodeShift: {
    93     case HbInputButton::ButtonKeyCodeShift: {
   100 			HbTextCase currentTextCase = (HbTextCase)focusObject->editorInterface().textCase();
    94             HbTextCase currentTextCase = (HbTextCase)focusObject->editorInterface().textCase();
   101 			HbInputLanguage language = mInputMethod->inputState().language();
    95             HbInputLanguage language = mInputMethod->inputState().language();
   102 
    96 
   103 			// Update the Case Information in HbInputState, it internally updates in HbEditorInterface as well
    97             // Update the Case Information in HbInputState, it internally updates in HbEditorInterface as well
   104 			switch(currentTextCase) {
    98             switch(currentTextCase) {
   105 			case HbTextCaseLower:
    99             case HbTextCaseLower:
   106 				// For Case-insensitive languages, Shift Key is used to switch between character sets (i.e lower case characters and shifted characters)
   100                 // For Case-insensitive languages, Shift Key is used to switch between character sets (i.e lower case characters and shifted characters)
   107 				if(!language.isCaseSensitiveLanguage()){
   101                 if(!language.isCaseSensitiveLanguage()){
   108 					currentTextCase = HbTextCaseUpper; 
   102                     currentTextCase = HbTextCaseUpper; 
   109 				}
   103                 }
   110 				else {
   104                 else {
   111 					currentTextCase = HbTextCaseAutomatic;
   105                     currentTextCase = HbTextCaseAutomatic;
   112 				}
   106                 }
   113 				break;				
   107                 break;				
   114 			case HbTextCaseUpper:	
   108             case HbTextCaseUpper:	
   115 				currentTextCase = HbTextCaseLower;				
   109                 currentTextCase = HbTextCaseLower;				
   116 				break;
   110                 break;
   117             case HbTextCaseAutomatic:
   111             case HbTextCaseAutomatic:
   118 				currentTextCase = HbTextCaseUpper;				                
   112                 currentTextCase = HbTextCaseUpper;				                
   119                 break;
   113                 break;
   120             default:
   114             default:
   121                 break;
   115                 break;
   122             }
   116             }
   123 			HbInputState state = mInputMethod->inputState();
   117             HbInputState state = mInputMethod->inputState();
   124 			state.setTextCase(currentTextCase);			
   118             state.setTextCase(currentTextCase);			
   125 			mInputMethod->activateState(state);
   119             mInputMethod->activateState(state);
   126         }
   120         }
   127         break;
   121         break;
   128     case HbInputButton::ButtonKeyCodeSymbol: { // Ctrl/Chr
   122     case HbInputButton::ButtonKeyCodeSymbol: { // Ctrl/Chr
   129     case HbInputButton::ButtonKeyCodeAlphabet:
   123     case HbInputButton::ButtonKeyCodeAlphabet:
   130             mInputMethod->switchSpecialCharacterTable();
   124         mInputMethod->switchSpecialCharacterTable();
   131         }
   125         }		
   132         break;
   126         break;
       
   127     case HbInputButton::ButtonKeyCodeSettings:
       
   128         mInputMethod->closeExactWordPopup();
       
   129 		break;
   133     default: {
   130     default: {
   134             HbTextCase currentTextCase = focusObject->editorInterface().textCase();
   131             HbTextCase currentTextCase = focusObject->editorInterface().textCase();
   135             Qt::KeyboardModifiers modifiers = Qt::NoModifier;
   132             Qt::KeyboardModifiers modifiers = Qt::NoModifier;
   136             if (mFnState == HbFnNext) {
   133             if (mFnState == HbFnNext) {
   137                 modifiers |= Qt::AltModifier;
   134                 modifiers |= Qt::AltModifier;
   164 bool HbInputPredictionQwertyHandlerPrivate::buttonPressed(const QKeyEvent *event)
   161 bool HbInputPredictionQwertyHandlerPrivate::buttonPressed(const QKeyEvent *event)
   165 {
   162 {
   166     if (event->isAutoRepeat() && mButton == event->key()) {
   163     if (event->isAutoRepeat() && mButton == event->key()) {
   167         if (mButton == HbInputButton::ButtonKeyCodeSymbol) {
   164         if (mButton == HbInputButton::ButtonKeyCodeSymbol) {
   168             mInputMethod->selectSpecialCharacterTableMode();
   165             mInputMethod->selectSpecialCharacterTableMode();
   169             mLongPressHappened = true;
       
   170         }
       
   171         if (mLongPressHappened) {
       
   172             mButton = 0;        
   166             mButton = 0;        
   173             return true;
   167             return true;
   174         }
   168         }
   175     }
   169     }
   176         
   170         
   198 {
   192 {
   199     Q_D(HbInputPredictionQwertyHandler);
   193     Q_D(HbInputPredictionQwertyHandler);
   200     bool ret = true;
   194     bool ret = true;
   201     switch (action) {
   195     switch (action) {
   202         case HbInputModeActionCancelButtonPress:
   196         case HbInputModeActionCancelButtonPress:
   203         case HbInputModeActionReset:
       
   204             break;
   197             break;
   205         case HbInputModeActionFocusRecieved:
   198         case HbInputModeActionFocusRecieved:
   206             HbInputPredictionHandler::actionHandler(HbInputModeActionSetCandidateList);
   199             HbInputPredictionHandler::actionHandler(HbInputModeActionSetCandidateList);
   207             HbInputPredictionHandler::actionHandler(HbInputModeActionSetKeypad);
   200             HbInputPredictionHandler::actionHandler(HbInputModeActionSetKeypad);
   208             break;
   201             break;
   218             }
   211             }
   219             */
   212             */
   220             // close exactword popup.
   213             // close exactword popup.
   221             d->mInputMethod->closeExactWordPopup();
   214             d->mInputMethod->closeExactWordPopup();
   222             break;
   215             break;
   223         case HbInputModeActionCommit: {   
   216         default: 
   224 			d->commit();        
   217             ret = HbInputPredictionHandler::actionHandler(action);
   225 		}
       
   226         default: ret = HbInputPredictionHandler::actionHandler(action);
       
   227     }
   218     }
   228     return ret;
   219     return ret;
   229 }
   220 }
   230 
   221 
   231 /*!
   222 /*!
   249 {
   240 {
   250     Q_D(HbInputPredictionQwertyHandler);
   241     Q_D(HbInputPredictionQwertyHandler);
   251     HbInputModeHandler::commitAndUpdate(string, replaceFrom, replaceLength);
   242     HbInputModeHandler::commitAndUpdate(string, replaceFrom, replaceLength);
   252     d->mInputMethod->closeExactWordPopup();
   243     d->mInputMethod->closeExactWordPopup();
   253     d->mExactPopupLaunched = false;  
   244     d->mExactPopupLaunched = false;  
   254 	d->mTailShowing = false;
   245     d->mTailShowing = false;
   255 }
   246 }
   256 
   247 
   257 /*!
   248 /*!
   258     this function deletes one character and updates the engine and editor.
   249     this function deletes one character and updates the engine and editor.
   259 */
   250 */
   320         //can go on with prediction. This is because when we delete a key press
   311         //can go on with prediction. This is because when we delete a key press
   321         //we actually reduce ambiguity in the engine and hence we should have
   312         //we actually reduce ambiguity in the engine and hence we should have
   322         //some word getting predicted as a result to that.
   313         //some word getting predicted as a result to that.
   323         mCanContinuePrediction = true;
   314         mCanContinuePrediction = true;
   324  
   315  
   325 		if(false == mTailShowing && true == mExactPopupLaunched) {
   316         if(false == mTailShowing && true == mExactPopupLaunched) {
   326 				mEngine->deleteKeyPress();
   317                 mEngine->deleteKeyPress();
   327 				mEngine->updateCandidates(mBestGuessLocation);
   318                 mEngine->updateCandidates(mBestGuessLocation);
   328 		}
   319         }
   329 		if (true == mExactPopupLaunched) {			
   320         if (true == mExactPopupLaunched) {			
   330 			mBestGuessLocation = 0 ;
   321             mBestGuessLocation = 0 ;
   331 		}
   322         }
   332         //When there is a deletion of key press, no need to update the candidate list
   323         //When there is a deletion of key press, no need to update the candidate list
   333         //This is because deletion should not cause reprediction.
   324         //This is because deletion should not cause reprediction.
   334 		if(mCandidates->count() && (mCandidates->count()>mBestGuessLocation) && false == mTailShowing && false == mExactPopupLaunched) {
   325         if(mCandidates->count() && (mCandidates->count()>mBestGuessLocation) && false == mTailShowing && false == mExactPopupLaunched) {
   335 		    QString currentWord = mCandidates->at(mBestGuessLocation);
   326             QString currentWord = mCandidates->at(mBestGuessLocation);
   336 			if(currentWord.length() > mEngine->inputLength()) {
   327             if(currentWord.length() > mEngine->inputLength()) {
   337 				//chop off the autocompletion part
   328                 //chop off the autocompletion part
   338 				currentWord = currentWord.left(mEngine->inputLength());
   329                 currentWord = currentWord.left(mEngine->inputLength());
   339 			}
   330             }
   340 		    if(currentWord.length()) {
   331             if(currentWord.length()) {
   341                 currentWord.chop(1);
   332                 currentWord.chop(1);
   342 		        mEngine->deleteKeyPress();
   333                 mEngine->deleteKeyPress();
   343 				//We are not supposed to re-construct the candidate list as deletion
   334                 //We are not supposed to re-construct the candidate list as deletion
   344 				//does not cause reprediction. Also, candidate list construction is the
   335                 //does not cause reprediction. Also, candidate list construction is the
   345 				//heaviest operation out of all engine operations.
   336                 //heaviest operation out of all engine operations.
   346 				(*mCandidates)[mBestGuessLocation] = currentWord;
   337                 (*mCandidates)[mBestGuessLocation] = currentWord;
   347 		    } else {
   338             } else {
   348 		        commit(QString(""),false);
   339                 commit(QString(""),false);
   349 		    }
   340             }
   350 		        
   341                 
   351 		} else if(!mCandidates->count() && mEngine->inputLength() >= 1) {
   342         } else if(!mCandidates->count() && mEngine->inputLength() >= 1) {
   352             //If Input length greater or equal to one then Append the current word to candidate 
   343             //If Input length greater or equal to one then Append the current word to candidate 
   353 			mCandidates->append(mEngine->currentWord());
   344             mCandidates->append(mEngine->currentWord());
   354         }
   345         }
   355         // update the editor with the new preedit text.
   346         // update the editor with the new preedit text.
   356         updateEditor();
   347         updateEditor();
   357         return;
   348         return;
   358     } else {
   349     } else {