src/hbplugins/inputmethods/common/hbinputbasichandler.cpp
changeset 2 06ff229162e9
parent 0 16d8024aca5e
child 6 c3690ec91ef8
equal deleted inserted replaced
1:f7ac710697a9 2:06ff229162e9
    23 **
    23 **
    24 ****************************************************************************/
    24 ****************************************************************************/
    25 
    25 
    26 #include <hbinputkeymap.h>
    26 #include <hbinputkeymap.h>
    27 #include <hbinputpredictionfactory.h>
    27 #include <hbinputpredictionfactory.h>
       
    28 #include <hbinputbutton.h>
    28 
    29 
    29 #include "hbinputbasichandler_p.h"
    30 #include "hbinputbasichandler_p.h"
    30 #include "hbinputpredictionengine.h"
    31 #include "hbinputpredictionengine.h"
    31 #include "hbinputabstractbase.h"
    32 #include "hbinputabstractbase.h"
    32 
    33 
    49     focusObject = mInputMethod->focusObject();
    50     focusObject = mInputMethod->focusObject();
    50     if (!focusObject) {
    51     if (!focusObject) {
    51         return;
    52         return;
    52     }
    53     }
    53     // Check if this is auto completion field and set it up if it is.
    54     // Check if this is auto completion field and set it up if it is.
    54     if (focusObject->editorInterface().constraints() & HbEditorConstraintAutoCompletingField) {
    55     if (focusObject->editorInterface().inputConstraints() & HbEditorConstraintAutoCompletingField) {
    55         if (!mAutoCompleter) {
    56         if (!mAutoCompleter) {
    56             mAutoCompleter = HbPredictionFactory::instance()->createEngine(HbAutoCompleteVendorIdString);
    57             mAutoCompleter = HbPredictionFactory::instance()->createEngine(HbAutoCompleteVendorIdString);
    57         }
    58         }
    58 
    59 
    59         mInputMethod->closeAutoCompletionPopup();
    60         mInputMethod->closeAutoCompletionPopup();
    71 
    72 
    72     if (!focusObject) {
    73     if (!focusObject) {
    73         return;
    74         return;
    74     }
    75     }
    75 
    76 
    76     if (focusObject->editorInterface().constraints() & HbEditorConstraintAutoCompletingField &&
    77     if (focusObject->editorInterface().inputConstraints() & HbEditorConstraintAutoCompletingField &&
    77         mAutoCompleter) {
    78         mAutoCompleter) {
    78         mAutoCompleter->setWord(focusObject->editorSurroundingText());
    79         mAutoCompleter->setWord(focusObject->editorSurroundingText());
    79         mInputMethod->launchAutoCompletionPopup(mAutoCompleter->candidateList());
    80         mInputMethod->launchAutoCompletionPopup(mAutoCompleter->candidateList());
    80     }
    81     }
    81 }
    82 }
   101     focusObject = mInputMethod->focusObject();
   102     focusObject = mInputMethod->focusObject();
   102     if (!focusObject) {
   103     if (!focusObject) {
   103         return;
   104         return;
   104     }
   105     }
   105 
   106 
   106     if (focusObject->editorInterface().constraints() & HbEditorConstraintAutoCompletingField) {
   107     if (focusObject->editorInterface().inputConstraints() & HbEditorConstraintAutoCompletingField) {
   107         if (mAutoCompleter) {
   108         if (mAutoCompleter) {
   108             int inputLength = mAutoCompleter->inputLength();
   109             int inputLength = mAutoCompleter->inputLength();
   109 
   110 
   110             mAutoCompleter->clear();
   111             mAutoCompleter->clear();
   111             QString current = currentCandidate;
   112             QString current = currentCandidate;
   151     }
   152     }
   152 
   153 
   153     bool ret = true;
   154     bool ret = true;
   154     switch (event->key()) {
   155     switch (event->key()) {
   155     case Qt::Key_Backspace:
   156     case Qt::Key_Backspace:
   156     case Qt::Key_Delete: {
   157     case HbInputButton::ButtonKeyCodeDelete: {
   157         QKeyEvent keyEvent(QEvent::KeyPress, Qt::Key_Backspace, Qt::NoModifier);
   158         QKeyEvent keyEvent(QEvent::KeyPress, Qt::Key_Backspace, Qt::NoModifier);
   158         sendAndUpdate(keyEvent);
   159         sendAndUpdate(keyEvent);
   159         // pass event to auto completer.
   160         // pass event to auto completer.
   160         deleteCharacterInAutoCompleter();
   161         deleteCharacterInAutoCompleter();
   161         // return false since the event is sent forward
   162         // return false since the event is sent forward
   162         ret = false;
   163         ret = false;
   163         break;
   164         break;
   164     }
   165     }
   165     case Qt::Key_Return:
   166     case HbInputButton::ButtonKeyCodeEnter:
   166     case Qt::Key_Enter:
   167     case HbInputButton::ButtonKeyCodeSpace: {
   167     case Qt::Key_Space: {
       
   168         QChar qc(event->key());
   168         QChar qc(event->key());
   169         if (qc == Qt::Key_Enter || qc == Qt::Key_Return) {
   169         if (qc == Qt::Key_Enter || qc == Qt::Key_Return) {
   170             qc = QChar('\n');  // Editor expects normal line feed.
   170             qc = QChar('\n');  // Editor expects normal line feed.
   171         }
   171         }
   172         commitAndUpdate(qc);
   172         commitAndUpdate(qc);
   173         }
   173         }
   174         break;
   174         break;
   175     case Qt::Key_Period:
       
   176     case Qt::Key_Comma: {
       
   177         QString qc(event->key());
       
   178         HbModifier modifier = HbModifierNone;
       
   179         int currentTextCase = focusObject->editorInterface().textCase();
       
   180         if ( HbTextCaseUpper == currentTextCase || HbTextCaseAutomatic == currentTextCase ) {
       
   181             modifier = HbModifierShiftPressed;
       
   182         }
       
   183         // If shift is pressed, the shifted characters should
       
   184         // be input.
       
   185         const HbMappedKey* mappedKey = d->mKeymap->keyForKeycode(d->mInputMethod->inputState().keyboard(), event->key());
       
   186         if (mappedKey) {
       
   187             qc = mappedKey->characters(modifier).left(1);
       
   188         }
       
   189         commitAndUpdate(qc);
       
   190         break;
       
   191     }
       
   192     default:
   175     default:
   193         ret = HbInputModeHandler::filterEvent(event);
   176         ret = HbInputModeHandler::filterEvent(event);
   194         break;
   177         break;
   195     }
   178     }
   196     return ret;
   179     return ret;