diff -r f7ac710697a9 -r 06ff229162e9 src/hbplugins/inputmethods/touchinput/hbinputnumeric12keyhandler.cpp --- a/src/hbplugins/inputmethods/touchinput/hbinputnumeric12keyhandler.cpp Mon May 03 12:48:33 2010 +0300 +++ b/src/hbplugins/inputmethods/touchinput/hbinputnumeric12keyhandler.cpp Fri May 14 16:09:54 2010 +0300 @@ -26,6 +26,7 @@ #include #include #include +#include #include "hbinputnumeric12keyhandler.h" #include "hbinputnumerichandler_p.h" @@ -41,19 +42,21 @@ ~HbInputNumeric12KeyHandlerPrivate(); void handleMultitapStarKey(); + bool handleAlphaEvent(int buttonId, HbKeyboardType type); bool buttonPressed(const QKeyEvent *keyEvent); bool buttonReleased(const QKeyEvent *keyEvent); void _q_timeout(); public: int mLastKey; + bool mLongPressHappened; int mButtonDown; int mMultiTapNum; QChar mCurrentMultitapChar; }; HbInputNumeric12KeyHandlerPrivate::HbInputNumeric12KeyHandlerPrivate(): - mLastKey(0), - mButtonDown(0), + mLastKey(0), mLongPressHappened(false), + mButtonDown(false), mMultiTapNum(0), mCurrentMultitapChar(0) { @@ -65,58 +68,111 @@ void HbInputNumeric12KeyHandlerPrivate::handleMultitapStarKey() { - HbInputFocusObject *focusObject = 0; - focusObject = mInputMethod->focusObject(); + HbInputFocusObject *focusObject = mInputMethod->focusObject(); if (!focusObject) { return; } - QChar MultitapStarKeyArray[] = {'+','*','p','w','\0'}; - mCurrentMultitapChar = MultitapStarKeyArray[mMultiTapNum]; + QChar MultitapStarKeyArray[] = {'*','+','p','w','\0'}; - mMultiTapNum = (++mMultiTapNum)%4; - if (mCurrentMultitapChar != 0) { - QString str; - str += mCurrentMultitapChar; + int index = mMultiTapNum; + do { + mCurrentMultitapChar = MultitapStarKeyArray[mMultiTapNum]; + mMultiTapNum = (++mMultiTapNum)%4; + if (mCurrentMultitapChar != 0) { + if (focusObject->characterAllowedInEditor(mCurrentMultitapChar)) { + QString str; + str += mCurrentMultitapChar; + + QList list; + QInputMethodEvent event(str,list); + focusObject->sendEvent(event); + return; + } + } + } while (index != mMultiTapNum); +} + +bool HbInputNumeric12KeyHandlerPrivate::handleAlphaEvent(int buttonId, HbKeyboardType type) +{ + Q_Q(HbInputNumeric12KeyHandler); - QList list; - QInputMethodEvent event(str,list); - focusObject->sendEvent(event); + HbInputFocusObject *focusObject = 0; + focusObject = mInputMethod->focusObject(); + if (!focusObject) { + return false; + } + + QChar character = 0; + //This condition is to avoid get the characters mapped to Asterisk + //Especially for Thai language we have mapped character to Asterisk + if (buttonId != HbInputButton::ButtonKeyCodeAsterisk || + mInputMethod->currentKeyboardType() == HbKeyboardSctPortrait) { + int index = 0; + character = q->getNthCharacterInKey(index, buttonId, type); } + + if (character != 0) { + q->commitAndUpdate(character); + return true; + } + return false; } + bool HbInputNumeric12KeyHandlerPrivate::buttonPressed(const QKeyEvent *keyEvent) { - Q_Q(HbInputNumeric12KeyHandler); + Q_Q(HbInputNumeric12KeyHandler); HbInputFocusObject *focusObject = 0; focusObject = mInputMethod->focusObject(); if (!focusObject) { return false; } - int buttonId = keyEvent->key(); + int buttonId = keyEvent->key(); mButtonDown = buttonId; - - if (buttonId == Qt::Key_Shift) { - mTimer->start(HbLongPressTimerTimeout); - mLastKey = buttonId; - return true; + if (keyEvent->isAutoRepeat() && mLastKey == buttonId) { + if (buttonId == HbInputButton::ButtonKeyCodeShift) { + // If the editor is not a number only editor, then activate the alphanumeric keypad + if (!focusObject->editorInterface().isNumericEditor()) { + mInputMethod->switchMode(buttonId); + mLongPressHappened = true; + } + } else if (buttonId == HbInputButton::ButtonKeyCodeSymbol) { + mInputMethod->selectSpecialCharacterTableMode(); + mLongPressHappened = true; + } else if (buttonId == HbInputButton::ButtonKeyCodeAsterisk && + mInputMethod->currentKeyboardType() != HbKeyboardSctPortrait) { + mLongPressHappened = true; + mCurrentMultitapChar = QChar(HbInputButton::ButtonKeyCodeAsterisk); + HbInputFocusObject *focusedObject = mInputMethod->focusObject(); + if (focusedObject) { + focusedObject->filterAndCommitCharacter(mCurrentMultitapChar); + } + mCurrentMultitapChar = 0; + } + if (mLongPressHappened) { + mLastKey = 0; + return true; + } } + if (mInputMethod) { if (mLastKey != buttonId) { if (mCurrentMultitapChar !=0) { - if (!focusObject->characterAllowedInEditor(mCurrentMultitapChar)) + if (!focusObject->characterAllowedInEditor(mCurrentMultitapChar)) { focusObject->sendCommitString(QString()); - else { + } else { QChar commitChar(mCurrentMultitapChar); mCurrentMultitapChar = 0; q->commitAndUpdate(commitChar); } } } - if (buttonId == Qt::Key_Asterisk) { + if (buttonId == HbInputButton::ButtonKeyCodeAsterisk) { mTimer->stop(); mTimer->start(HbMultiTapTimerTimeout); } - return false; - } + } + + mLastKey = buttonId; return false; } @@ -133,44 +189,56 @@ qDebug("HbInputModeHandler::buttonReleased no focusObject ... failed!!"); return false; } - int buttonId = keyEvent->key(); - if(mTimer->isActive() && buttonId == Qt::Key_Shift) { - mTimer->stop(); - } + + int buttonId = keyEvent->key(); - if (mLastKey != buttonId) + if (mLongPressHappened) { + mLongPressHappened = false; + return false; + } + + if (mTimer->isActive() && buttonId == Qt::Key_Shift) { + mTimer->stop(); + } + if (mLastKey != buttonId) { mMultiTapNum = 0; + } mButtonDown = 0; - if (buttonId == Qt::Key_Asterisk) { + if (buttonId == HbInputButton::ButtonKeyCodeAsterisk && + mInputMethod->currentKeyboardType() != HbKeyboardSctPortrait) { //Asterisk Key will multitap bettween *,+,p,w //mInputMethod->switchMode(buttonId); mLastKey = buttonId; handleMultitapStarKey(); return true; - } else if (buttonId == Qt::Key_Control){ + } else if (buttonId == HbInputButton::ButtonKeyCodeSymbol) { + mInputMethod->switchMode(buttonId); + } else if (buttonId == HbInputButton::ButtonKeyCodeAlphabet) { mInputMethod->switchMode(buttonId); mLastKey = buttonId; return true; - } - else if (buttonId == Qt::Key_Return) { + } else if (buttonId == Qt::Key_Return) { mInputMethod->closeKeypad(); return true; - } else if ( buttonId == Qt::Key_Shift ) { - //Let's commit character "#" on single tap and double tap of shift Key + } else if (buttonId == HbInputButton::ButtonKeyCodeShift) { + //Let's commit character "#" on single tap and double tap of shift Key mLastKey = buttonId; - QChar qc(keyEvent->key()); - qc = QChar('#'); - q->commitAndUpdate(qc); - return true; + QChar qc = QChar('#'); + q->commitAndUpdate(qc); + return true; } else if (buttonId >= 0) { // Let's see if we can get the handler for this button in the base class. if (q->HbInputNumericHandler::filterEvent(keyEvent)) { return true; } mLastKey = buttonId; - q->commitFirstMappedNumber(buttonId); + if (mInputMethod->currentKeyboardType() == HbKeyboardSctPortrait && + handleAlphaEvent(buttonId, mInputMethod->currentKeyboardType())) { + return true; + } + q->commitFirstMappedNumber(buttonId, mInputMethod->currentKeyboardType()); return true; } return false; @@ -178,39 +246,19 @@ void HbInputNumeric12KeyHandlerPrivate::_q_timeout() { - Q_Q(HbInputNumeric12KeyHandler); mTimer->stop(); mMultiTapNum = 0; - HbInputFocusObject *focusedObject = 0; - focusedObject = mInputMethod->focusObject(); + HbInputFocusObject *focusedObject = mInputMethod->focusObject(); if (!focusedObject) { qDebug("HbInputNumeric12KeyHandler::timeout focusObject == 0"); return; } - //switch to Alpha mode when Long key press of Shift key is received - if (mButtonDown) - { - if (mButtonDown == Qt::Key_Shift) { - // If the editor is not a number only editor, then activate the alphanumeric keypad - if( !focusedObject->editorInterface().isNumericEditor() ) { - mInputMethod->switchMode(mLastKey); - mLastKey = 0; - } - else - { - q->commitAndUpdate(QChar('#')); - } + + if (!mButtonDown) { + if (mCurrentMultitapChar != 0) { + focusedObject->filterAndCommitCharacter(mCurrentMultitapChar); } - else if (mButtonDown == Qt::Key_Asterisk) - { - q->commitAndUpdate(QChar('*')); - } - mButtonDown = 0; - } - else { - if (mCurrentMultitapChar != 0) - focusedObject->filterAndCommitCharacter(mCurrentMultitapChar); } mCurrentMultitapChar = 0; } @@ -247,15 +295,14 @@ */ bool HbInputNumeric12KeyHandler::actionHandler(HbInputModeAction action) { - Q_D(HbInputNumeric12KeyHandler); + Q_D(HbInputNumeric12KeyHandler); bool ret = false; switch (action) { - case HbInputModeHandler::HbInputModeActionCancelButtonPress: + case HbInputModeHandler::HbInputModeActionCancelButtonPress: case HbInputModeHandler::HbInputModeActionReset: - d->mLastKey = 0; - d->mButtonDown = 0; - d->mTimer->stop(); - break; + d->mLastKey = 0; + d->mButtonDown = false; + break; //In case of the numeric editor the character is already committed. //Need to remove the committed character. case HbInputModeHandler::HbInputModeActionDeleteAndCommit: { @@ -265,7 +312,6 @@ if (!focusObject) { return false; } - d->mTimer->stop(); if (focusObject->editorCursorPosition()) { QString empty; QList list;