src/hbplugins/inputmethods/touchinput/hbinputnumeric12keyhandler.cpp
changeset 2 06ff229162e9
parent 1 f7ac710697a9
child 21 4633027730f5
child 34 ed14f46c0e55
equal deleted inserted replaced
1:f7ac710697a9 2:06ff229162e9
    24 ****************************************************************************/
    24 ****************************************************************************/
    25 
    25 
    26 #include <QTimer>
    26 #include <QTimer>
    27 #include <hbinputmethod.h>
    27 #include <hbinputmethod.h>
    28 #include <hbinputkeymapfactory.h>
    28 #include <hbinputkeymapfactory.h>
       
    29 #include <hbinputbutton.h>
    29 
    30 
    30 #include "hbinputnumeric12keyhandler.h"
    31 #include "hbinputnumeric12keyhandler.h"
    31 #include "hbinputnumerichandler_p.h"
    32 #include "hbinputnumerichandler_p.h"
    32 #include "virtual12key.h"
    33 #include "virtual12key.h"
    33 #include "hbinputabstractbase.h"
    34 #include "hbinputabstractbase.h"
    39 public:
    40 public:
    40     HbInputNumeric12KeyHandlerPrivate();
    41     HbInputNumeric12KeyHandlerPrivate();
    41     ~HbInputNumeric12KeyHandlerPrivate();
    42     ~HbInputNumeric12KeyHandlerPrivate();
    42 
    43 
    43 	void handleMultitapStarKey();
    44 	void handleMultitapStarKey();
       
    45     bool handleAlphaEvent(int buttonId, HbKeyboardType type);
    44     bool buttonPressed(const QKeyEvent *keyEvent);
    46     bool buttonPressed(const QKeyEvent *keyEvent);
    45     bool buttonReleased(const QKeyEvent *keyEvent);
    47     bool buttonReleased(const QKeyEvent *keyEvent);
    46     void _q_timeout();
    48     void _q_timeout();
    47 public:
    49 public:
    48     int mLastKey;
    50     int mLastKey;
       
    51     bool mLongPressHappened;
    49     int mButtonDown;
    52     int mButtonDown;
    50 	int mMultiTapNum;
    53 	int mMultiTapNum;
    51 	QChar mCurrentMultitapChar;
    54 	QChar mCurrentMultitapChar;
    52 };
    55 };
    53 
    56 
    54 HbInputNumeric12KeyHandlerPrivate::HbInputNumeric12KeyHandlerPrivate():
    57 HbInputNumeric12KeyHandlerPrivate::HbInputNumeric12KeyHandlerPrivate():
    55     mLastKey(0),
    58     mLastKey(0), mLongPressHappened(false),
    56     mButtonDown(0),
    59     mButtonDown(false),
    57 	mMultiTapNum(0),
    60 	mMultiTapNum(0),
    58 	mCurrentMultitapChar(0)
    61 	mCurrentMultitapChar(0)
    59 {
    62 {
    60 }
    63 }
    61 
    64 
    63 {
    66 {
    64 }
    67 }
    65 
    68 
    66 void HbInputNumeric12KeyHandlerPrivate::handleMultitapStarKey()
    69 void HbInputNumeric12KeyHandlerPrivate::handleMultitapStarKey()
    67 {
    70 {
    68 	HbInputFocusObject *focusObject = 0;
    71 	HbInputFocusObject *focusObject = mInputMethod->focusObject();
    69 	focusObject = mInputMethod->focusObject();
       
    70 	if (!focusObject) {
    72 	if (!focusObject) {
    71 		return;
    73 		return;
    72 	}
    74 	}
    73 	QChar MultitapStarKeyArray[] = {'+','*','p','w','\0'};
    75 	QChar MultitapStarKeyArray[] = {'*','+','p','w','\0'};
    74 	mCurrentMultitapChar = MultitapStarKeyArray[mMultiTapNum];
       
    75 	
    76 	
    76 	mMultiTapNum = (++mMultiTapNum)%4;
    77     int index = mMultiTapNum;
    77 	if (mCurrentMultitapChar != 0) {
    78     do {
    78 		QString str;
    79         mCurrentMultitapChar = MultitapStarKeyArray[mMultiTapNum];
    79 		str += mCurrentMultitapChar;
    80         mMultiTapNum = (++mMultiTapNum)%4;
    80 
    81 	    if (mCurrentMultitapChar != 0) {
    81 		QList<QInputMethodEvent::Attribute> list;
    82             if (focusObject->characterAllowedInEditor(mCurrentMultitapChar)) {
    82 		QInputMethodEvent event(str,list);
    83 		        QString str;
    83 		focusObject->sendEvent(event);
    84 		        str += mCurrentMultitapChar;
       
    85 
       
    86 		        QList<QInputMethodEvent::Attribute> list;
       
    87 		        QInputMethodEvent event(str,list);
       
    88 		        focusObject->sendEvent(event);
       
    89                 return;
       
    90             }
       
    91 	    }
       
    92     } while (index != mMultiTapNum);
       
    93 }
       
    94 
       
    95 bool HbInputNumeric12KeyHandlerPrivate::handleAlphaEvent(int buttonId, HbKeyboardType type)
       
    96 {
       
    97     Q_Q(HbInputNumeric12KeyHandler);
       
    98 
       
    99     HbInputFocusObject *focusObject = 0;
       
   100     focusObject = mInputMethod->focusObject();
       
   101     if (!focusObject) {
       
   102         return false;
       
   103     }
       
   104 
       
   105     QChar character = 0;
       
   106 	//This condition is to avoid get the characters mapped to Asterisk
       
   107 	//Especially for Thai language we have mapped character to Asterisk
       
   108     if (buttonId != HbInputButton::ButtonKeyCodeAsterisk ||
       
   109         mInputMethod->currentKeyboardType() == HbKeyboardSctPortrait) {
       
   110         int index = 0;
       
   111         character = q->getNthCharacterInKey(index, buttonId, type);
    84 	}
   112 	}
    85 }
   113 
       
   114     if (character != 0) {
       
   115         q->commitAndUpdate(character);
       
   116         return true;
       
   117     }
       
   118     return false;
       
   119 }
       
   120 
    86 bool HbInputNumeric12KeyHandlerPrivate::buttonPressed(const QKeyEvent *keyEvent)
   121 bool HbInputNumeric12KeyHandlerPrivate::buttonPressed(const QKeyEvent *keyEvent)
    87 {
   122 {
    88 	Q_Q(HbInputNumeric12KeyHandler);
   123     Q_Q(HbInputNumeric12KeyHandler);
    89 	HbInputFocusObject *focusObject = 0;
   124 	HbInputFocusObject *focusObject = 0;
    90     focusObject = mInputMethod->focusObject();
   125     focusObject = mInputMethod->focusObject();
    91     if (!focusObject) {
   126     if (!focusObject) {
    92         return false;
   127         return false;
    93     }
   128     }
    94 	int buttonId = keyEvent->key();
   129     int buttonId = keyEvent->key();
    95 	mButtonDown = buttonId;
   130 	mButtonDown = buttonId;
    96     
   131     if (keyEvent->isAutoRepeat() && mLastKey == buttonId) {
    97 	if (buttonId == Qt::Key_Shift) {
   132         if (buttonId == HbInputButton::ButtonKeyCodeShift) {
    98         mTimer->start(HbLongPressTimerTimeout);
   133             // If the editor is not a number only editor, then activate the alphanumeric keypad
    99 		mLastKey = buttonId;
   134             if (!focusObject->editorInterface().isNumericEditor()) {
   100 		return true;
   135                 mInputMethod->switchMode(buttonId);
       
   136                 mLongPressHappened = true;
       
   137             }
       
   138         } else if (buttonId == HbInputButton::ButtonKeyCodeSymbol) {
       
   139             mInputMethod->selectSpecialCharacterTableMode();
       
   140             mLongPressHappened = true;
       
   141         } else if (buttonId == HbInputButton::ButtonKeyCodeAsterisk &&
       
   142                    mInputMethod->currentKeyboardType() != HbKeyboardSctPortrait) {
       
   143             mLongPressHappened = true;
       
   144             mCurrentMultitapChar = QChar(HbInputButton::ButtonKeyCodeAsterisk);
       
   145             HbInputFocusObject *focusedObject = mInputMethod->focusObject();
       
   146             if (focusedObject) {
       
   147 			    focusedObject->filterAndCommitCharacter(mCurrentMultitapChar);
       
   148             }
       
   149         	mCurrentMultitapChar = 0;
       
   150         }
       
   151         if (mLongPressHappened) {
       
   152             mLastKey = 0;
       
   153             return true;
       
   154         }
   101 	}		   
   155 	}		   
       
   156    
   102 	if (mInputMethod) {
   157 	if (mInputMethod) {
   103 		if (mLastKey != buttonId) {
   158 		if (mLastKey != buttonId) {
   104 			if (mCurrentMultitapChar !=0) {
   159 			if (mCurrentMultitapChar !=0) {
   105 				if (!focusObject->characterAllowedInEditor(mCurrentMultitapChar))
   160                 if (!focusObject->characterAllowedInEditor(mCurrentMultitapChar)) {
   106 					focusObject->sendCommitString(QString());
   161 					focusObject->sendCommitString(QString());
   107 				else {
   162                 } else {
   108 					QChar commitChar(mCurrentMultitapChar);
   163 					QChar commitChar(mCurrentMultitapChar);
   109 					mCurrentMultitapChar = 0;
   164 					mCurrentMultitapChar = 0;
   110 					q->commitAndUpdate(commitChar);
   165 					q->commitAndUpdate(commitChar);
   111 				}
   166 				}
   112 			}
   167 			}
   113 		}
   168 		}
   114 		if (buttonId == Qt::Key_Asterisk) {
   169 		if (buttonId == HbInputButton::ButtonKeyCodeAsterisk) {
   115 			mTimer->stop();
   170 			mTimer->stop();
   116 			mTimer->start(HbMultiTapTimerTimeout);
   171 			mTimer->start(HbMultiTapTimerTimeout);
   117 		}
   172 		}
   118 		return false;
   173 	} 
   119 	}           
   174 
       
   175     mLastKey = buttonId;
   120     return false;
   176     return false;
   121 }
   177 }
   122 
   178 
   123 /*!
   179 /*!
   124 Handles the key release events from the VKB. Launches the SCT with key release event of
   180 Handles the key release events from the VKB. Launches the SCT with key release event of
   131     focusObject = mInputMethod->focusObject();
   187     focusObject = mInputMethod->focusObject();
   132     if (!focusObject || !mButtonDown) {
   188     if (!focusObject || !mButtonDown) {
   133         qDebug("HbInputModeHandler::buttonReleased no focusObject ... failed!!");
   189         qDebug("HbInputModeHandler::buttonReleased no focusObject ... failed!!");
   134         return false;
   190         return false;
   135     }
   191     }
   136 	int buttonId = keyEvent->key();
   192 	
   137 	if(mTimer->isActive() && buttonId == Qt::Key_Shift) {
   193     int buttonId = keyEvent->key();
   138 		mTimer->stop();
       
   139 	}
       
   140     
   194     
   141 	if (mLastKey != buttonId)
   195     if (mLongPressHappened) {
       
   196         mLongPressHappened = false;
       
   197         return false;
       
   198     }
       
   199 
       
   200     if (mTimer->isActive() && buttonId == Qt::Key_Shift) {
       
   201         mTimer->stop();
       
   202     }
       
   203     if (mLastKey != buttonId) {
   142 		mMultiTapNum = 0;
   204 		mMultiTapNum = 0;
       
   205     }
   143 
   206 
   144 	mButtonDown = 0;
   207 	mButtonDown = 0;
   145 
   208 
   146     if (buttonId == Qt::Key_Asterisk) {
   209     if (buttonId == HbInputButton::ButtonKeyCodeAsterisk &&
       
   210         mInputMethod->currentKeyboardType() != HbKeyboardSctPortrait) {
   147         //Asterisk Key will multitap bettween *,+,p,w
   211         //Asterisk Key will multitap bettween *,+,p,w
   148         //mInputMethod->switchMode(buttonId);
   212         //mInputMethod->switchMode(buttonId);
   149 		mLastKey = buttonId;
   213 		mLastKey = buttonId;
   150 		handleMultitapStarKey();
   214 		handleMultitapStarKey();
   151         return true;
   215         return true;
   152 	} else if (buttonId == Qt::Key_Control){
   216     } else if (buttonId == HbInputButton::ButtonKeyCodeSymbol) {
       
   217         mInputMethod->switchMode(buttonId);
       
   218     } else if (buttonId == HbInputButton::ButtonKeyCodeAlphabet) {
   153 		mInputMethod->switchMode(buttonId);
   219 		mInputMethod->switchMode(buttonId);
   154 		mLastKey = buttonId;
   220 		mLastKey = buttonId;
   155 		return true;
   221 		return true;
   156 	}
   222 	} else if (buttonId == Qt::Key_Return) {
   157 	else if (buttonId == Qt::Key_Return) {
       
   158         mInputMethod->closeKeypad();
   223         mInputMethod->closeKeypad();
   159         return true;
   224         return true;
   160 	} else if ( buttonId == Qt::Key_Shift ) {
   225 	} else if (buttonId == HbInputButton::ButtonKeyCodeShift) {
   161 		//Let's commit character "#" on single tap and double tap of shift Key
   226         //Let's commit character "#" on single tap and double tap of shift Key
   162 		mLastKey = buttonId;
   227 		mLastKey = buttonId;
   163 		QChar qc(keyEvent->key());
   228         QChar qc = QChar('#');
   164 		qc = QChar('#');
   229         q->commitAndUpdate(qc);
   165 		q->commitAndUpdate(qc);
   230         return true;            
   166 		return true;			
       
   167     } else if (buttonId >= 0) {
   231     } else if (buttonId >= 0) {
   168         // Let's see if we can get the handler for this button in the base class.
   232         // Let's see if we can get the handler for this button in the base class.
   169         if (q->HbInputNumericHandler::filterEvent(keyEvent)) {
   233         if (q->HbInputNumericHandler::filterEvent(keyEvent)) {
   170             return true;
   234             return true;
   171         }
   235         }
   172         mLastKey = buttonId;
   236         mLastKey = buttonId;
   173         q->commitFirstMappedNumber(buttonId);
   237         if (mInputMethod->currentKeyboardType() == HbKeyboardSctPortrait &&
       
   238             handleAlphaEvent(buttonId, mInputMethod->currentKeyboardType())) {
       
   239             return true;
       
   240         }
       
   241         q->commitFirstMappedNumber(buttonId, mInputMethod->currentKeyboardType());
   174         return true;
   242         return true;
   175     }
   243     }
   176     return false;
   244     return false;
   177 }
   245 }
   178 
   246 
   179 void HbInputNumeric12KeyHandlerPrivate::_q_timeout()
   247 void HbInputNumeric12KeyHandlerPrivate::_q_timeout()
   180 {
   248 {
   181 	Q_Q(HbInputNumeric12KeyHandler);
       
   182     mTimer->stop();
   249     mTimer->stop();
   183 	mMultiTapNum = 0;
   250 	mMultiTapNum = 0;
   184 
   251 
   185     HbInputFocusObject *focusedObject = 0;
   252     HbInputFocusObject *focusedObject = mInputMethod->focusObject();
   186     focusedObject = mInputMethod->focusObject();
       
   187     if (!focusedObject) {
   253     if (!focusedObject) {
   188         qDebug("HbInputNumeric12KeyHandler::timeout focusObject == 0");
   254         qDebug("HbInputNumeric12KeyHandler::timeout focusObject == 0");
   189         return;
   255         return;
   190     }
   256     }
   191     //switch to Alpha mode when Long key press of Shift key is received
   257 
   192     if (mButtonDown)
   258     if (!mButtonDown) {
   193     {
   259         if (mCurrentMultitapChar != 0) {
   194 		if (mButtonDown == Qt::Key_Shift) {
       
   195 			// If the editor is not a number only editor, then activate the alphanumeric keypad
       
   196             if( !focusedObject->editorInterface().isNumericEditor() ) {
       
   197 				mInputMethod->switchMode(mLastKey);
       
   198 				mLastKey = 0;
       
   199 			}
       
   200 			else
       
   201 			{
       
   202 				q->commitAndUpdate(QChar('#'));
       
   203 			}
       
   204         }
       
   205 		else if (mButtonDown == Qt::Key_Asterisk)
       
   206 		{
       
   207 			q->commitAndUpdate(QChar('*'));
       
   208 		}
       
   209 		mButtonDown = 0;
       
   210     }
       
   211 	else {
       
   212 		if (mCurrentMultitapChar != 0)
       
   213 			focusedObject->filterAndCommitCharacter(mCurrentMultitapChar);
   260 			focusedObject->filterAndCommitCharacter(mCurrentMultitapChar);
       
   261         }
   214 	}
   262 	}
   215 	mCurrentMultitapChar = 0;
   263 	mCurrentMultitapChar = 0;
   216 }
   264 }
   217 
   265 
   218 HbInputNumeric12KeyHandler::HbInputNumeric12KeyHandler(HbInputAbstractMethod* inputMethod)
   266 HbInputNumeric12KeyHandler::HbInputNumeric12KeyHandler(HbInputAbstractMethod* inputMethod)
   245 /*!
   293 /*!
   246  Action handler
   294  Action handler
   247 */
   295 */
   248 bool HbInputNumeric12KeyHandler::actionHandler(HbInputModeAction action)
   296 bool HbInputNumeric12KeyHandler::actionHandler(HbInputModeAction action)
   249 {
   297 {
   250 	Q_D(HbInputNumeric12KeyHandler);
   298     Q_D(HbInputNumeric12KeyHandler);
   251     bool ret = false;
   299     bool ret = false;
   252     switch (action) {
   300     switch (action) {
   253 		case HbInputModeHandler::HbInputModeActionCancelButtonPress:
   301         case HbInputModeHandler::HbInputModeActionCancelButtonPress:
   254         case HbInputModeHandler::HbInputModeActionReset:
   302         case HbInputModeHandler::HbInputModeActionReset:
   255 			d->mLastKey = 0;
   303             d->mLastKey = 0;
   256         	d->mButtonDown = 0;
   304         	d->mButtonDown = false;
   257 			d->mTimer->stop();
   305             break;
   258 			break;
       
   259         //In case of the numeric editor the character is already committed.
   306         //In case of the numeric editor the character is already committed.
   260         //Need to remove the committed character.
   307         //Need to remove the committed character.
   261         case HbInputModeHandler::HbInputModeActionDeleteAndCommit: {
   308         case HbInputModeHandler::HbInputModeActionDeleteAndCommit: {
   262             HbInputFocusObject *focusObject = 0;
   309             HbInputFocusObject *focusObject = 0;
   263             
   310             
   264             focusObject = d->mInputMethod->focusObject();
   311             focusObject = d->mInputMethod->focusObject();
   265             if (!focusObject) {
   312             if (!focusObject) {
   266                 return false;
   313                 return false;
   267             }
   314             }
   268             d->mTimer->stop();
       
   269             if (focusObject->editorCursorPosition()) {
   315             if (focusObject->editorCursorPosition()) {
   270                 QString empty;
   316                 QString empty;
   271                 QList<QInputMethodEvent::Attribute> list;
   317                 QList<QInputMethodEvent::Attribute> list;
   272                 QInputMethodEvent event(QString(), list);
   318                 QInputMethodEvent event(QString(), list);
   273                 event.setCommitString(empty, -1, 1);
   319                 event.setCommitString(empty, -1, 1);