src/hbplugins/inputmethods/common/hbinputpredictionhandler.cpp
changeset 2 06ff229162e9
parent 1 f7ac710697a9
child 5 627c4a0fd0e7
equal deleted inserted replaced
1:f7ac710697a9 2:06ff229162e9
    31 #include <hbinputdialog.h>
    31 #include <hbinputdialog.h>
    32 #include <hbaction.h>
    32 #include <hbaction.h>
    33 #include <hbinputvkbhost.h>
    33 #include <hbinputvkbhost.h>
    34 #include <hbcolorscheme.h>
    34 #include <hbcolorscheme.h>
    35 #include <hbinpututils.h>
    35 #include <hbinpututils.h>
       
    36 #include <hbinputbutton.h>
    36 #include "../touchinput/virtualqwerty.h"
    37 #include "../touchinput/virtualqwerty.h"
    37 
    38 
    38 #include "hbinputpredictionhandler_p.h"
    39 #include "hbinputpredictionhandler_p.h"
    39 #include "hbinputabstractbase.h"
    40 #include "hbinputabstractbase.h"
    40 
    41 
   148     if (!focusedObject) {
   149     if (!focusedObject) {
   149         return;
   150         return;
   150     }
   151     }
   151 
   152 
   152     QString commitString  = activatedText;
   153     QString commitString  = activatedText;
   153     if (closingKey == Qt::Key_0 || closingKey == Qt::Key_Space) {
   154     if (closingKey == Qt::Key_0 || closingKey == HbInputButton::ButtonKeyCodeSpace) {
   154         commitString = activatedText+' ';
   155         commitString = activatedText+' ';
   155     } else if (closingKey == Qt::Key_Enter || closingKey == Qt::Key_Return) {
   156     } else if (closingKey == HbInputButton::ButtonKeyCodeEnter) {
   156         commitString = activatedText;
   157         commitString = activatedText;
   157         commit(commitString);
   158         commit(commitString);
   158         commitString = '\n';
   159         commitString = '\n';
   159     }
   160     }
   160 
   161 
   263     bool ret = false;
   264     bool ret = false;
   264     mModifiers = Qt::NoModifier;   
   265     mModifiers = Qt::NoModifier;   
   265     mCanContinuePrediction = true;
   266     mCanContinuePrediction = true;
   266     switch (event->key()) {
   267     switch (event->key()) {
   267     case Qt::Key_Backspace:
   268     case Qt::Key_Backspace:
   268     case Qt::Key_Delete:
   269     case HbInputButton::ButtonKeyCodeDelete:
   269         {
   270         {
   270             QString currentSelection = focusObject->inputMethodQuery(Qt::ImCurrentSelection).toString();
   271             QString currentSelection = focusObject->inputMethodQuery(Qt::ImCurrentSelection).toString();
   271             if(currentSelection.length()) {
   272             if(currentSelection.length()) {
   272                 QKeyEvent event = QKeyEvent(QEvent::KeyPress, Qt::Key_Backspace, Qt::NoModifier);		
   273                 QKeyEvent event = QKeyEvent(QEvent::KeyPress, Qt::Key_Backspace, Qt::NoModifier);		
   273                 q->sendAndUpdate(event);
   274                 q->sendAndUpdate(event);
   320                 q->processExactWord(empty);
   321                 q->processExactWord(empty);
   321             }
   322             }
   322             ret = true;
   323             ret = true;
   323         }
   324         }
   324         break;
   325         break;
   325     case Qt::Key_Return:
   326     case HbInputButton::ButtonKeyCodeEnter:
   326     case Qt::Key_Enter:
   327     case HbInputButton::ButtonKeyCodeSpace:
   327     case Qt::Key_Space:
       
   328     case Qt::Key_0: {//Space
   328     case Qt::Key_0: {//Space
   329             // A space means we have to commit the candidates when we are in predictive mode.
   329             // A space means we have to commit the candidates when we are in predictive mode.
   330             QChar qc(event->key());
   330             QChar qc(event->key());
   331             if (qc == Qt::Key_Enter) {
   331             if (qc == Qt::Key_Enter) {
   332                 qc = QChar('\n');  // Editor expects normal line feed.
   332                 qc = QChar('\n');  // Editor expects normal line feed.
   351             if (mEngine) {
   351             if (mEngine) {
   352                 int currentTextCase = focusObject->editorInterface().textCase();
   352                 int currentTextCase = focusObject->editorInterface().textCase();
   353                 if ( HbTextCaseUpper == currentTextCase || HbTextCaseAutomatic == currentTextCase ) {
   353                 if ( HbTextCaseUpper == currentTextCase || HbTextCaseAutomatic == currentTextCase ) {
   354                     mModifiers |= Qt::ShiftModifier;
   354                     mModifiers |= Qt::ShiftModifier;
   355                 }
   355                 }
   356                 mEngine->appendKeyPress(event->key(), mModifiers, mInputMethod->inputState().textCase(), this);
   356                 if (event->text().isEmpty()) {
       
   357                     mEngine->appendKeyPress(event->key(), mModifiers, mInputMethod->inputState().textCase(), this);
       
   358                 } else {
       
   359                     mEngine->appendCharacter(event->text().at(0), mInputMethod->inputState().textCase(), this);
       
   360                 }
   357                 bool isCustomWord = false;
   361                 bool isCustomWord = false;
   358                 mEngine->updateCandidates(mBestGuessLocation, isCustomWord);
   362                 mEngine->updateCandidates(mBestGuessLocation, isCustomWord);
   359                 //The engine can not predict the word, it is a custom word. Now engine returns a
   363                 //The engine can not predict the word, it is a custom word. Now engine returns a
   360                 //single candidate entry which is actually the previous properly predicted character.
   364                 //single candidate entry which is actually the previous properly predicted character.
   361                 //TODO: In such a scenario, the prediction should stop and there needs to be some way for
   365                 //TODO: In such a scenario, the prediction should stop and there needs to be some way for