src/hbplugins/inputmethods/touchinput/hbinputprediction12keyhandler.cpp
changeset 2 06ff229162e9
parent 1 f7ac710697a9
child 3 11d3954df52a
equal deleted inserted replaced
1:f7ac710697a9 2:06ff229162e9
    33 #include <hbinputdialog.h>
    33 #include <hbinputdialog.h>
    34 #include <hbaction.h>
    34 #include <hbaction.h>
    35 #include <hbmainwindow.h>
    35 #include <hbmainwindow.h>
    36 #include <hbinstance.h>
    36 #include <hbinstance.h>
    37 #include <hbeffect.h>
    37 #include <hbeffect.h>
       
    38 #include <hbinputbutton.h>
    38 
    39 
    39 #include "virtual12key.h"
    40 #include "virtual12key.h"
    40 
    41 
    41 #include "hbinputprediction12keyhandler.h"
    42 #include "hbinputprediction12keyhandler.h"
    42 #include "hbinputpredictionhandler_p.h"
    43 #include "hbinputpredictionhandler_p.h"
   112 	bool isCancel = false;
   113 	bool isCancel = false;
   113 	bool isExternalClose = false;
   114 	bool isExternalClose = false;
   114 	// action is null when input query is closed externally , for example by calling
   115 	// action is null when input query is closed externally , for example by calling
   115 	// HbDialog::close() function.
   116 	// HbDialog::close() function.
   116 	if (action) {
   117 	if (action) {
   117 		isOk = (action->text() == primaryAction()->text())? true : false;
   118 		isOk = (action->text() == actions().at(0)->text())? true : false;
   118 		isCancel = (action->text() == secondaryAction()->text())? true:false;
   119 		isCancel = (action->text() == actions().at(1)->text())? true:false;
   119 	} else {
   120 	} else {
   120 		isExternalClose = true;
   121 		isExternalClose = true;
   121 	}
   122 	}
   122     
   123     
   123 	//Need to disable effects as asynchronous hide will commit the word otherwise.
   124 	//Need to disable effects as asynchronous hide will commit the word otherwise.
   212         updateEditor();
   213         updateEditor();
   213         mCanContinuePrediction = true;
   214         mCanContinuePrediction = true;
   214     }
   215     }
   215 }
   216 }
   216 
   217 
   217 void HbInputPrediction12KeyHandlerPrivate::_q_timeout()
   218 bool HbInputPrediction12KeyHandlerPrivate::buttonPressed(const QKeyEvent *keyEvent)
   218 {
   219 {
   219     qDebug("HbInputPrediction12KeyHandlerPrivate::_q_timeout()");
       
   220     Q_Q(HbInputPrediction12KeyHandler);
   220     Q_Q(HbInputPrediction12KeyHandler);
   221 
   221     mLongPressHappened = false;
   222     // let's stop the timer first.
   222     HbInputFocusObject *focusObject = 0;
   223     mTimer->stop();
   223     focusObject = mInputMethod->focusObject();
   224 
   224     if (!focusObject) {
   225     //Long key press number key is applicable to all keys
   225         return false;
   226     if (mButtonDown) {	
   226     }
   227         if (mLastKey == Qt::Key_Asterisk) {
   227 
   228 			//Remove the "?" mark if present
   228     int buttonId = keyEvent->key();
   229             chopQMarkAndUpdateEditor();
   229 
   230             mInputMethod->switchMode(mLastKey);
   230     if (keyEvent->isAutoRepeat() && mLastKey == buttonId) {
   231         } else if (mLastKey == Qt::Key_Shift) {
   231         if (buttonId == HbInputButton::ButtonKeyCodeAsterisk) {
   232             mInputMethod->switchMode(Qt::Key_Shift);
   232             if (!mCanContinuePrediction) {
       
   233                 mInputMethod->switchMode(buttonId);
       
   234             } else {
       
   235                 //Remove the "?" mark if present
       
   236                 chopQMarkAndUpdateEditor();
       
   237                 mInputMethod->selectSpecialCharacterTableMode();
       
   238             }
   233             mLongPressHappened = true;
   239             mLongPressHappened = true;
   234         } else if (mLastKey == Qt::Key_Control) {
   240         } else if (buttonId == HbInputButton::ButtonKeyCodeShift) {
       
   241             mInputMethod->switchMode(HbInputButton::ButtonKeyCodeShift);
       
   242             mLongPressHappened = true;
       
   243         } else if (buttonId == HbInputButton::ButtonKeyCodeSymbol) {
   235             //Remove the "?" mark if present
   244             //Remove the "?" mark if present
   236             chopQMarkAndUpdateEditor();
   245             chopQMarkAndUpdateEditor();
   237             mInputMethod->selectSpecialCharacterTableMode();
   246             mInputMethod->selectSpecialCharacterTableMode();
       
   247             mLongPressHappened = true;
   238         } else {
   248         } else {
   239             //With a long key press of a key, numbers are supposed to be entered.
   249             //With a long key press of a key, numbers are supposed to be entered.
   240             //When the existing input (along with the short key press input of the
   250             //When the existing input (along with the short key press input of the
   241             //existing key) results in tail (i.e. autocompletion), we need to accept
   251             //existing key) results in tail (i.e. autocompletion), we need to accept
   242             //the short key press as well as the tail. In case of ? delete the questionmark and add the number value.          
   252             //the short key press as well as the tail. In case of ? delete the questionmark and add the number value.          
   243             //mTailShowing = false;            
   253             //mTailShowing = false;            
   244             // Delete "?" entered
   254             // Delete "?" entered
   245             if (!mCanContinuePrediction) {
   255             if (!mCanContinuePrediction) {
   246                 deleteOneCharacter();
   256                 deleteOneCharacter();
   247             }
   257                 mLongPressHappened = true;
   248 			if (mLastKey != Qt::Key_Delete) {
   258             }
   249 				q->commitFirstMappedNumber(mLastKey);
   259 			if (buttonId != HbInputButton::ButtonKeyCodeDelete) {
       
   260 				q->commitFirstMappedNumber(buttonId, mInputMethod->currentKeyboardType());
       
   261                 mLongPressHappened = true;
   250 			}
   262 			}
   251             mLongPressHappened = true;
   263         }
   252         }
   264 
   253     }
   265         if (mLongPressHappened) {
   254 }
   266             mLastKey = 0;
   255 
   267             return true;
   256 bool HbInputPrediction12KeyHandlerPrivate::buttonPressed(const QKeyEvent *keyEvent)
   268         }
   257 {
   269     }
   258     mLongPressHappened = false;
   270 
   259     HbInputFocusObject *focusObject = 0;
   271     if (buttonId == HbInputButton::ButtonKeyCodeShift) {		
   260     focusObject = mInputMethod->focusObject();
   272         // if we get a second consequtive shift key press, 
   261     if (!focusObject) {
   273         // we want to handle it in buttonRelease
   262         return false;
       
   263     }
       
   264 
       
   265     int buttonId = keyEvent->key();
       
   266 
       
   267     
       
   268     if (buttonId == Qt::Key_Control) {
       
   269         mLastKey = buttonId;
       
   270         mButtonDown = true;
       
   271         mTimer->start(HbLongPressTimerTimeout);
       
   272         return true;
       
   273     } else if (buttonId == Qt::Key_Shift) {		
       
   274     // if we get a second consequtive shift key press, 
       
   275     // we want to handle it in buttonRelease
       
   276         if (mTimer->isActive() && (mLastKey == buttonId)){
   274         if (mTimer->isActive() && (mLastKey == buttonId)){
   277             mShiftKeyDoubleTap = true;
   275             mShiftKeyDoubleTap = true;
   278         }
   276         }
   279         if (!mTimer->isActive()) {            		
       
   280             mTimer->start(HbLongPressTimerTimeout);
       
   281         }
       
   282         mLastKey = buttonId;
       
   283         mButtonDown = true;
       
   284         return true;
       
   285     }
   277     }
   286 
   278 
   287     mLastKey = buttonId;
   279     mLastKey = buttonId;
   288     mButtonDown = true;
   280     mButtonDown = true;
   289     
   281     
   290     // custom button should not start timer.
       
   291     if ((buttonId & CUSTOM_INPUT_MASK) != CUSTOM_INPUT_MASK) {
       
   292         mTimer->start(HbLongPressTimerTimeout);
       
   293     }
       
   294     return false;
   282     return false;
   295 }
   283 }
   296 
   284 
   297 /*!
   285 /*!
   298 Handles the key release events from the VKB. Launches the SCT with key release event of
   286 Handles the key release events from the VKB. Launches the SCT with key release event of
   307     }
   295     }
   308 
   296 
   309     // since button is released we can set buttonDown back to false.
   297     // since button is released we can set buttonDown back to false.
   310     mButtonDown = false;
   298     mButtonDown = false;
   311     int buttonId = keyEvent->key(); 
   299     int buttonId = keyEvent->key(); 
   312     // it was a long press on sct swith button. so just return form here.
       
   313     if (!mTimer->isActive() && buttonId == Qt::Key_Control) {
       
   314         return true;
       
   315     }
       
   316 
   300 
   317     // Sym key is handled in this class it self, so not passing it to 
   301     // Sym key is handled in this class it self, so not passing it to 
   318     // the base mode handlers.	
   302     // the base mode handlers.	
   319     if ( buttonId == Qt::Key_Control) {
   303     if (buttonId == HbInputButton::ButtonKeyCodeSymbol ||
       
   304         buttonId == HbInputButton::ButtonKeyCodeAlphabet) {
   320         //Remove the "?" mark if present
   305         //Remove the "?" mark if present
   321         chopQMarkAndUpdateEditor();
   306         chopQMarkAndUpdateEditor();
   322         mInputMethod->switchMode(buttonId);
   307         mInputMethod->switchMode(buttonId);
   323         return true;
   308         return true;
   324     } 
   309     } 
   326 		- Should launch Candidate List if we can continue with prediction i.e. "?" is not displayed
   311 		- Should launch Candidate List if we can continue with prediction i.e. "?" is not displayed
   327 		- Should launch Spell Query Dialog if we cannot continue with prediction 
   312 		- Should launch Spell Query Dialog if we cannot continue with prediction 
   328 	- Behavior of Short Press of Asterisk Key when not in inline editing state 
   313 	- Behavior of Short Press of Asterisk Key when not in inline editing state 
   329 		- Should launch SCT
   314 		- Should launch SCT
   330 	*/
   315 	*/
   331     else if (buttonId == Qt::Key_Asterisk ) {
   316     else if (buttonId == HbInputButton::ButtonKeyCodeAsterisk ) {
   332 		if(!mCanContinuePrediction && (*mCandidates)[mBestGuessLocation].endsWith('?')) {			
   317 		if(!mCanContinuePrediction && (*mCandidates)[mBestGuessLocation].endsWith('?')) {			
   333             //Remove the "?" mark
   318             //Remove the "?" mark
   334             (*mCandidates)[mBestGuessLocation].chop(1);
   319             (*mCandidates)[mBestGuessLocation].chop(1);
   335             updateEditor();
   320             updateEditor();
   336             q->processCustomWord((*mCandidates)[mBestGuessLocation]);
   321             q->processCustomWord((*mCandidates)[mBestGuessLocation]);
   338 		}
   323 		}
   339 		else
   324 		else
   340 			mInputMethod->starKeySelected();
   325 			mInputMethod->starKeySelected();
   341         return true;
   326         return true;
   342     }	
   327     }	
   343     else if (buttonId == Qt::Key_Return) {
   328     else if (buttonId == HbInputButton::ButtonKeyCodeEnter) {
   344         mInputMethod->closeKeypad();
   329         mInputMethod->closeKeypad();
   345         return true;
   330         return true;
   346     }
   331     }
   347     if (buttonId == Qt::Key_Shift) {
   332     if (buttonId == HbInputButton::ButtonKeyCodeShift) {
   348         // single tap of shift key toggles prediction status in case insensitive languages
   333         // single tap of shift key toggles prediction status in case insensitive languages
   349         if (!HbInputSettingProxy::instance()->globalInputLanguage().isCaseSensitiveLanguage()) {
   334         if (!HbInputSettingProxy::instance()->globalInputLanguage().isCaseSensitiveLanguage()) {
   350             HbInputSettingProxy::instance()->togglePrediction();
   335             HbInputSettingProxy::instance()->togglePrediction();
   351         } else {
   336         } else {
   352             if (mShiftKeyDoubleTap) {
   337             if (mShiftKeyDoubleTap) {
   369                     mInputMethod->activateState(rootState); 		
   354                     mInputMethod->activateState(rootState); 		
   370                 }
   355                 }
   371             } else {
   356             } else {
   372                 updateTextCase();
   357                 updateTextCase();
   373                 if( !mTimer->isActive()){
   358                 if( !mTimer->isActive()){
   374                     mTimer->start();
   359                     mTimer->start(HbMultiTapTimerTimeout);
   375                 }
   360                 }
   376             }
   361             }
   377         }
   362         }
       
   363         return true;
       
   364     }
       
   365 
       
   366     if (buttonId != HbInputButton::ButtonKeyCodeDelete &&
       
   367         mInputMethod->currentKeyboardType() == HbKeyboardSctPortrait) {
       
   368         q->sctCharacterSelected(QChar(buttonId));
   378         return true;
   369         return true;
   379     }
   370     }
   380 
   371 
   381     // text input happens on button release		
   372     // text input happens on button release		
   382     if (q->HbInputPredictionHandler::filterEvent(keyEvent)) {
   373     if (q->HbInputPredictionHandler::filterEvent(keyEvent)) {
   426     //any meaningful word for the input sequence.
   417     //any meaningful word for the input sequence.
   427     if(!d->mCanContinuePrediction) {
   418     if(!d->mCanContinuePrediction) {
   428         int eventKey = event->key();
   419         int eventKey = event->key();
   429         switch(eventKey) {
   420         switch(eventKey) {
   430         case Qt::Key_0:        
   421         case Qt::Key_0:        
   431         case Qt::Key_Space: {
   422         case HbInputButton::ButtonKeyCodeSpace: {
   432             if(d->mCandidates->size() && focusObject) {
   423             if(d->mCandidates->size() && focusObject) {
   433                 //Remove the "?" mark
   424                 //Remove the "?" mark
   434                 (*d->mCandidates)[d->mBestGuessLocation].chop(1);
   425                 (*d->mCandidates)[d->mBestGuessLocation].chop(1);
   435                 d->updateEditor();
   426                 d->updateEditor();
   436                 d->mCanContinuePrediction = true;
   427                 d->mCanContinuePrediction = true;
   437                 }
   428                 }
   438             }
   429             }
   439             break;
   430             break;
   440         case Qt::Key_Shift: {
   431         case HbInputButton::ButtonKeyCodeShift: {
   441             if(event->type() == QEvent::KeyRelease && d->mShiftKeyDoubleTap) {
   432             if(event->type() == QEvent::KeyRelease && d->mShiftKeyDoubleTap) {
   442                 //Remove the "?" mark
   433                 //Remove the "?" mark
   443                 deleteOneCharacter();
   434                 deleteOneCharacter();
   444                 }
   435                 }
   445             }
   436             }
   446         //For the following set of keys, it does not matter.
   437         //For the following set of keys, it does not matter.
   447         case Qt::Key_Backspace:
   438         case Qt::Key_Backspace:
   448         case Qt::Key_Delete:
   439         case HbInputButton::ButtonKeyCodeDelete:
   449         case Qt::Key_Return:
   440         case HbInputButton::ButtonKeyCodeEnter:
   450         case Qt::Key_Enter:
   441 		case HbInputButton::ButtonKeyCodeAsterisk:
   451 		case Qt::Key_Asterisk:
   442         case HbInputButton::ButtonKeyCodeControl:
   452         case Qt::Key_Control:
       
   453             break;
   443             break;
   454         /* Behavior for other keys i.e. from key1 to key9 - 
   444         /* Behavior for other keys i.e. from key1 to key9 - 
   455         To start the long press timer as we need to handle long press functionality i.e Enter corresponding number mapped to a key */
   445         To start the long press timer as we need to handle long press functionality i.e Enter corresponding number mapped to a key */
   456         case Qt::Key_1:
   446         case Qt::Key_1:
   457         case Qt::Key_2:
   447         case Qt::Key_2:
   465             if (event->type() == QEvent::KeyRelease) {
   455             if (event->type() == QEvent::KeyRelease) {
   466                 d->mButtonDown = false;
   456                 d->mButtonDown = false;
   467             } else {
   457             } else {
   468                 d->mButtonDown = true;			
   458                 d->mButtonDown = true;			
   469                 d->mLastKey = event->key();		
   459                 d->mLastKey = event->key();		
   470                 // start Long Press timer as corresponding number mapped to a key should be allowed to enter
       
   471                 d->mTimer->start(HbLongPressTimerTimeout);					
       
   472             }
   460             }
   473             return true;
   461             return true;
   474         }
   462         }
   475         //The default behavior for any other key press is just to consume the key event and
   463         //The default behavior for any other key press is just to consume the key event and
   476         //not to do anything.
   464         //not to do anything.