src/hbplugins/inputmethods/touchinput/hbinputbasicqwertyhandler.cpp
changeset 2 06ff229162e9
parent 1 f7ac710697a9
child 5 627c4a0fd0e7
equal deleted inserted replaced
1:f7ac710697a9 2:06ff229162e9
    21 ** If you have questions regarding the use of this file, please contact
    21 ** If you have questions regarding the use of this file, please contact
    22 ** Nokia at developer.feedback@nokia.com.
    22 ** Nokia at developer.feedback@nokia.com.
    23 **
    23 **
    24 ****************************************************************************/
    24 ****************************************************************************/
    25 
    25 
    26 #include <QTimer>
       
    27 #include <hbinputpredictionengine.h>
    26 #include <hbinputpredictionengine.h>
    28 #include <hbinputmethod.h>
    27 #include <hbinputmethod.h>
    29 #include <hbinputkeymap.h>
    28 #include <hbinputkeymap.h>
    30 #include <hbinputkeymapfactory.h>
    29 #include <hbinputkeymapfactory.h>
       
    30 #include <hbinputbutton.h>
    31 
    31 
    32 #include "hbinputabstractbase.h"
    32 #include "hbinputabstractbase.h"
    33 #include "hbinputbasicqwertyhandler.h"
    33 #include "hbinputbasicqwertyhandler.h"
    34 #include "hbinputbasichandler_p.h"
    34 #include "hbinputbasichandler_p.h"
    35 
    35 
    43     void init();
    43     void init();
    44 
    44 
    45     // button related operations.
    45     // button related operations.
    46     bool buttonPressed(const QKeyEvent *event);
    46     bool buttonPressed(const QKeyEvent *event);
    47     bool buttonReleased(const QKeyEvent *event);
    47     bool buttonReleased(const QKeyEvent *event);
    48     void _q_timeout();
       
    49 
    48 
    50 public:
    49 public:
    51     HbFnState mFnState;
    50     HbFnState mFnState;
    52     int mButton;
    51     int mButton;
    53     bool mPreviewAvailable;
    52     bool mLongPressHappened;
    54     QChar mPrevDeadKey;
    53     QChar mPrevDeadKey;
    55     HbInputFocusObject *mCurrentlyFocused;
    54     HbInputFocusObject *mCurrentlyFocused;
    56 };
    55 };
    57 
    56 
    58 HbInputBasicQwertyHandlerPrivate::HbInputBasicQwertyHandlerPrivate()
    57 HbInputBasicQwertyHandlerPrivate::HbInputBasicQwertyHandlerPrivate()
    59 :mFnState(HbFnOff),
    58 :mFnState(HbFnOff),
    60 mButton(0),
    59 mButton(0),
    61 mPreviewAvailable(false),
    60 mLongPressHappened(0),
    62 mPrevDeadKey(0),
    61 mPrevDeadKey(0),
    63 mCurrentlyFocused(0)
    62 mCurrentlyFocused(0)
    64 {
    63 {
    65 }
    64 }
    66 
    65 
    73 }
    72 }
    74 
    73 
    75 bool HbInputBasicQwertyHandlerPrivate::buttonPressed(const QKeyEvent * event)
    74 bool HbInputBasicQwertyHandlerPrivate::buttonPressed(const QKeyEvent * event)
    76 {
    75 {
    77     if (!mKeymap->isDeadKey(event->key())) {
    76     if (!mKeymap->isDeadKey(event->key())) {
       
    77         if (event->isAutoRepeat() && mButton == event->key()) {
       
    78             if (mButton == HbInputButton::ButtonKeyCodeSymbol) {
       
    79                 mInputMethod->selectSpecialCharacterTableMode();
       
    80                 mLongPressHappened = true;
       
    81             }
       
    82             if (mLongPressHappened) {
       
    83                 mButton = 0;
       
    84                 return true;
       
    85             }
       
    86         }
    78         mButton = event->key();
    87         mButton = event->key();
    79         mTimer->start(HbLongPressTimerTimeout);
       
    80         mPreviewAvailable = false;
       
    81     } 
    88     } 
    82     return false;
    89     return false;
    83 }
    90 }
    84 
    91 
    85 bool HbInputBasicQwertyHandlerPrivate::buttonReleased(const QKeyEvent *event)
    92 bool HbInputBasicQwertyHandlerPrivate::buttonReleased(const QKeyEvent *event)
    86 {
    93 {
    87     Q_Q(HbInputBasicQwertyHandler);
    94     Q_Q(HbInputBasicQwertyHandler);
       
    95     mButton = 0;
       
    96 
    88     int buttonId = event->key();
    97     int buttonId = event->key();
       
    98     if (!event->text().isEmpty()) {
       
    99         buttonId = event->text().at(0).unicode();
       
   100     }
       
   101 
    89     QChar firstChar = 0;
   102     QChar firstChar = 0;
    90     QChar secondChar = 0;
   103     QChar secondChar = 0;
    91 
   104 
    92     // If the timer is not active and it is alpha mode, it is a long press
   105     if (mLongPressHappened) {
    93     // and handled in another function. So just return.
   106         mLongPressHappened = false;
    94     if (mTimer->isActive()) {
       
    95         mTimer->stop();
       
    96     } else if (buttonId == Qt::Key_Control) {
       
    97         return false;
       
    98     } else if (!(buttonId & 0xffff0000) && mPreviewAvailable) {
       
    99         return false;
   107         return false;
   100     }
   108     }
   101 
   109 
   102     HbInputFocusObject *focusObject = 0;
   110     HbInputFocusObject *focusObject = 0;
   103     focusObject = mInputMethod->focusObject();
   111     focusObject = mInputMethod->focusObject();
   104     if (!focusObject) {
   112     if (!focusObject) {
   105         qDebug("HbInputBasicQwertyHandler::virtualButtonClicked : no focused editor widget!");
   113         qDebug("HbInputBasicQwertyHandler::virtualButtonClicked : no focused editor widget!");
   106         return false;
   114         return false;
   107     }
   115     }
   108     int currentTextCase = focusObject->editorInterface().textCase();
   116     int currentTextCase = focusObject->editorInterface().textCase();
   109     const HbMappedKey *mappedKey = mKeymap->keyForKeycode(HbKeyboardVirtualQwerty, event->key());
   117     const HbMappedKey *mappedKey = mKeymap->keyForKeycode(mInputMethod->currentKeyboardType(), buttonId);
   110     QChar newChar;
   118     QChar newChar;
   111     if (mFnState == HbFnNext) {
   119     if (mFnState == HbFnNext) {
   112         newChar = (mappedKey->characters(HbModifierFnPressed)).at(0);
   120         newChar = (mappedKey->characters(HbModifierFnPressed)).at(0);
   113         mFnState = HbFnOff;
   121         mFnState = HbFnOff;
   114     } else {
   122     } else {
   125                 newChar = buttonId;
   133                 newChar = buttonId;
   126             }
   134             }
   127         }
   135         }
   128     }
   136     }
   129 
   137 
   130     if (!mPrevDeadKey.isNull()) {
   138     if (mInputMethod->currentKeyboardType() != HbKeyboardSctLandscape) {
   131         if (event->key() != Qt::Key_Shift && event->key() != Qt::Key_Alt) {
   139         if (!mPrevDeadKey.isNull()) {
   132             mKeymap->combineCharacter(mPrevDeadKey, newChar, firstChar, secondChar );
   140             if (buttonId != HbInputButton::ButtonKeyCodeShift && buttonId != Qt::Key_Alt) {
   133             mPrevDeadKey = 0;
   141                 mKeymap->combineCharacter(mPrevDeadKey, newChar, firstChar, secondChar );
   134             if (firstChar.isNull() && secondChar.isNull()) {
   142                 mPrevDeadKey = 0;
       
   143                 if (firstChar.isNull() && secondChar.isNull()) {
       
   144                     return true;
       
   145                 }
       
   146             }
       
   147         } else {
       
   148             if (mKeymap->isDeadKey(newChar.unicode())) {
       
   149                 mPrevDeadKey = newChar.unicode();
   135                 return true;
   150                 return true;
       
   151             } else {
       
   152                 firstChar = newChar;
   136             }
   153             }
   137         }
   154         }
   138     } else {
   155     } else {
   139         if (mKeymap->isDeadKey(newChar.unicode())) {
   156         firstChar = newChar;
   140             mPrevDeadKey = newChar.unicode();
       
   141             return true;
       
   142         } else {
       
   143             firstChar = newChar;
       
   144         }
       
   145     }
   157     }
   146 
   158 
   147     bool ret = false;
   159     bool ret = false;
   148     switch(buttonId) {
   160     switch(buttonId) {
   149     case Qt::Key_Alt:
   161     case Qt::Key_Alt:
   154         } else {
   166         } else {
   155             mFnState = HbFnOff;
   167             mFnState = HbFnOff;
   156         }
   168         }
   157         ret = true;
   169         ret = true;
   158         break;
   170         break;
   159     case Qt::Key_Shift: {
   171     case HbInputButton::ButtonKeyCodeShift: {
   160             HbTextCase currentTextCase = focusObject->editorInterface().textCase();
   172             HbTextCase currentTextCase = focusObject->editorInterface().textCase();
   161             HbInputLanguage language = mInputMethod->inputState().language();
   173             HbInputLanguage language = mInputMethod->inputState().language();
   162             
   174             
   163             // Update the Case Information in HbInputState, it internally updates in HbEditorInterface as well
   175             // Update the Case Information in HbInputState, it internally updates in HbEditorInterface as well
   164             switch(currentTextCase) {
   176             switch(currentTextCase) {
   184             state.setTextCase(currentTextCase);            
   196             state.setTextCase(currentTextCase);            
   185             mInputMethod->activateState(state);
   197             mInputMethod->activateState(state);
   186             ret = true;
   198             ret = true;
   187         }
   199         }
   188         break;
   200         break;
   189     case Qt::Key_Control:   // Ctrl/Chr
   201     case HbInputButton::ButtonKeyCodeSymbol:   // Ctrl/Chr
       
   202     case HbInputButton::ButtonKeyCodeAlphabet:
   190         mInputMethod->switchSpecialCharacterTable();
   203         mInputMethod->switchSpecialCharacterTable();
   191         ret = true;
   204         ret = true;
   192         break;
   205         break;
   193     default:
   206     default:
   194 
   207 
   195         // let's pass non deadkey event to the base class.
   208         // let's pass non deadkey event to the base class.
   196         if (!mKeymap->isDeadKey(firstChar.unicode()) && secondChar.isNull() && q->HbInputBasicHandler::filterEvent(event)) {
   209         if (!mKeymap->isDeadKey(firstChar.unicode()) && secondChar.isNull() && q->HbInputBasicHandler::filterEvent(event)) {
   197             return true;
   210             return true;
   198         }
   211         }
   199 
   212 
   200         if (event->key() == Qt::Key_Delete || event->key() == Qt::Key_Backspace) {
   213         if (event->key() == HbInputButton::ButtonKeyCodeDelete || event->key() == Qt::Key_Backspace) {
   201             return false;
   214             return false;
   202         }
   215         }
   203 
   216 
   204         QList<QInputMethodEvent::Attribute> list;
   217         QList<QInputMethodEvent::Attribute> list;
   205         QString newText;
   218         QString newText;
   232         break;
   245         break;
   233     }
   246     }
   234     return ret;
   247     return ret;
   235 }
   248 }
   236 
   249 
   237 void HbInputBasicQwertyHandlerPrivate::_q_timeout()
       
   238 {
       
   239     mTimer->stop();
       
   240 
       
   241     //If long key press of shift key is received, just return
       
   242     if (mButton == Qt::Key_Shift) {
       
   243         return;
       
   244     } else if (mButton == Qt::Key_Control) {
       
   245         mInputMethod->selectSpecialCharacterTableMode();
       
   246     }
       
   247     QStringList spellList;
       
   248     //If long key press of shift key, space key and enter key is received, don't
       
   249     if (mButton) {
       
   250         mInputMethod->launchCharacterPreviewPane(mButton);
       
   251     }
       
   252 
       
   253     return;
       
   254 }
       
   255 
       
   256 HbInputBasicQwertyHandler::HbInputBasicQwertyHandler(HbInputAbstractMethod* inputMethod)
   250 HbInputBasicQwertyHandler::HbInputBasicQwertyHandler(HbInputAbstractMethod* inputMethod)
   257 :HbInputBasicHandler(* new HbInputBasicQwertyHandlerPrivate, inputMethod)
   251 :HbInputBasicHandler(* new HbInputBasicQwertyHandlerPrivate, inputMethod)
   258 {
   252 {
   259     Q_D(HbInputBasicQwertyHandler);
   253     Q_D(HbInputBasicQwertyHandler);
   260     d->q_ptr = this;
   254     d->q_ptr = this;
   283 /*!
   277 /*!
   284 returns true if in inline edit.
   278 returns true if in inline edit.
   285 */
   279 */
   286 bool HbInputBasicQwertyHandler::isComposing() const
   280 bool HbInputBasicQwertyHandler::isComposing() const
   287 {   
   281 {   
   288     Q_D(const HbInputBasicQwertyHandler);
   282     return false;
   289     return d->mTimer->isActive();
       
   290 }
   283 }
   291 
   284 
   292 /*!
   285 /*!
   293 Action handler
   286 Action handler
   294 */
   287 */
   299     focusObject = d->mInputMethod->focusObject();
   292     focusObject = d->mInputMethod->focusObject();
   300     bool ret = true;
   293     bool ret = true;
   301     switch (action) {
   294     switch (action) {
   302     case HbInputModeActionCancelButtonPress:
   295     case HbInputModeActionCancelButtonPress:
   303     case HbInputModeActionReset:
   296     case HbInputModeActionReset:
   304         if (d->mTimer->isActive()) {
   297         d->mButton = 0;
   305             d->mTimer->stop();
       
   306         }
       
   307         break;
   298         break;
   308     case HbInputModeActionFocusRecieved:
   299     case HbInputModeActionFocusRecieved:
   309         if (d->mTimer->isActive()) {
   300         d->mButton = 0;
   310             d->mTimer->stop(); 
       
   311         }
       
   312         // set up auto completer
   301         // set up auto completer
   313         setUpAutoCompleter();
   302         setUpAutoCompleter();
   314     break;
   303     break;
   315     case HbInputModeActionFocusLost:
   304     case HbInputModeActionFocusLost:
   316         // We should add the commit autocompleting text when focus lost happens
   305         d->mButton = 0;
   317          if (d->mTimer->isActive()) {
       
   318             d->mTimer->stop(); 
       
   319         }
       
   320         if (d->mCurrentlyFocused != focusObject) {
   306         if (d->mCurrentlyFocused != focusObject) {
   321             d->mCurrentlyFocused = focusObject;
   307             d->mCurrentlyFocused = focusObject;
   322             addWordInAutoCompleter();
   308             addWordInAutoCompleter();
   323         } 
   309         } 
   324     break;
   310     break;
   327         }
   313         }
   328     }
   314     }
   329     return ret;
   315     return ret;
   330 }
   316 }
   331 
   317 
   332 /*!
       
   333 this SLOT is called by input plugin when there is a character selected from character preview pane.
       
   334 */
       
   335 void HbInputBasicQwertyHandler::charFromPreviewSelected(QString characters)
       
   336 {
       
   337     Q_D(HbInputBasicQwertyHandler);
       
   338     if(characters.size() > 0) {
       
   339         sctCharacterSelected(characters.at(0));
       
   340         d->mInputMethod->updateState();
       
   341     }
       
   342 }
       
   343 
       
   344 void HbInputBasicQwertyHandler::sctCharacterSelected(QString character)
   318 void HbInputBasicQwertyHandler::sctCharacterSelected(QString character)
   345 {
   319 {
   346     HbInputModeHandler::sctCharacterSelected(character);
   320     HbInputModeHandler::sctCharacterSelected(character);
   347 }
   321 }
   348 
   322 
   349 void HbInputBasicQwertyHandler::characterPreviewAvailable(bool available)
       
   350 {
       
   351     Q_D(HbInputBasicQwertyHandler);
       
   352     d->mPreviewAvailable = available;
       
   353 }