src/hbplugins/inputmethods/touchinput/virtualqwerty.cpp
changeset 0 16d8024aca5e
child 1 f7ac710697a9
equal deleted inserted replaced
-1:000000000000 0:16d8024aca5e
       
     1 /****************************************************************************
       
     2 **
       
     3 ** Copyright (C) 2008-2010 Nokia Corporation and/or its subsidiary(-ies).
       
     4 ** All rights reserved.
       
     5 ** Contact: Nokia Corporation (developer.feedback@nokia.com)
       
     6 **
       
     7 ** This file is part of the HbPlugins module of the UI Extensions for Mobile.
       
     8 **
       
     9 ** GNU Lesser General Public License Usage
       
    10 ** This file may be used under the terms of the GNU Lesser General Public
       
    11 ** License version 2.1 as published by the Free Software Foundation and
       
    12 ** appearing in the file LICENSE.LGPL included in the packaging of this file.
       
    13 ** Please review the following information to ensure the GNU Lesser General
       
    14 ** Public License version 2.1 requirements will be met:
       
    15 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
       
    16 **
       
    17 ** In addition, as a special exception, Nokia gives you certain additional
       
    18 ** rights.  These rights are described in the Nokia Qt LGPL Exception
       
    19 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
       
    20 **
       
    21 ** If you have questions regarding the use of this file, please contact
       
    22 ** Nokia at developer.feedback@nokia.com.
       
    23 **
       
    24 ****************************************************************************/
       
    25 #include "virtualqwerty.h"
       
    26 #include <hbapplication.h>
       
    27 #include <QLocale>
       
    28 
       
    29 #include <hbinputexactwordpopup.h>
       
    30 #include <hbinputkeymapfactory.h>
       
    31 #include <hbinputkeymap.h>
       
    32 #include <hbinputcandidatelist.h>
       
    33 #include <hbinputsettingproxy.h>
       
    34 #include <hbinpututils.h>
       
    35 #include <hbinputvirtualrocker.h>
       
    36 #include <hbinputsctlandscape.h>
       
    37 #include <hbinputqwertytouchkeyboard.h>
       
    38 #include <hbinputeditorinterface.h>
       
    39 #include <hbinputdef.h>
       
    40 #include <hbinputvkbhost.h>
       
    41 #include <hbinputcommondialogs.h>
       
    42 
       
    43 #include <hbmainwindow.h>
       
    44 
       
    45 #include "hbinputbasicqwertyhandler.h"
       
    46 #include "hbinputpredictionqwertyhandler.h"
       
    47 #include "hbinputnumericqwertyhandler.h"
       
    48 #include <hbaction.h>
       
    49 #include <hbview.h>
       
    50 #include <hbinputpredictionfactory.h>
       
    51 
       
    52 HbVirtualQwerty::HbVirtualQwerty() : mCurrentKeypad(0),
       
    53                                      mQwertyAlphaKeypad(0),
       
    54                                      mQwertyNumericKeypad(0),
       
    55                                      mSctKeypad(0),
       
    56                                      mKeymap(0),
       
    57                                      mExactWordPopup(0),
       
    58                                      mCandidatePopup(0),
       
    59                                      mOrientationAboutToChange(false),
       
    60                                      mSctMode(HbInputVkbWidget::HbSctViewSpecialCharacter),
       
    61                                      mShiftKeyState(0),
       
    62                                      mVkbHost(0)
       
    63 {
       
    64     initializeModeHandlers();
       
    65 }
       
    66 
       
    67 void HbVirtualQwerty::initializeModeHandlers()
       
    68 {
       
    69     // lets construct all the three supported mode handlers.
       
    70     mBasicModeHandler = new HbInputBasicQwertyHandler(this);
       
    71     mPredictionModeHandler = new HbInputPredictionQwertyHandler(this);
       
    72     mNumericModeHandler = new HbInputNumericQwertyHandler(this);
       
    73     // bydefault latin basic mode handler is activated.
       
    74     mActiveModeHandler = mBasicModeHandler;
       
    75 
       
    76     // init will initialize the individual mode handlers.
       
    77     mBasicModeHandler->actionHandler(HbInputModeHandler::HbInputModeActionInit);
       
    78     mPredictionModeHandler->actionHandler(HbInputModeHandler::HbInputModeActionInit);
       
    79     mNumericModeHandler->actionHandler(HbInputModeHandler::HbInputModeActionInit);
       
    80 
       
    81     // autocompleter connection
       
    82     connect(this, SIGNAL(autoCompletionPopupClosed(QString, int)), mBasicModeHandler, SLOT(autoCompletionPopupClosed(QString, int)));
       
    83 }
       
    84 
       
    85 // ---------------------------------------------------------------------------
       
    86 // HbVirtualQwerty::~HbVirtualQwerty
       
    87 //
       
    88 // ---------------------------------------------------------------------------
       
    89 //
       
    90 HbVirtualQwerty::~HbVirtualQwerty()
       
    91 {
       
    92     delete mCandidatePopup;
       
    93     mCandidatePopup = 0;
       
    94 
       
    95     delete mQwertyAlphaKeypad;
       
    96     mQwertyAlphaKeypad = 0;
       
    97 
       
    98     delete mQwertyNumericKeypad;
       
    99     mQwertyNumericKeypad = 0;
       
   100 
       
   101     delete mSctKeypad;
       
   102     mSctKeypad = 0;
       
   103 
       
   104     delete mExactWordPopup;
       
   105     mExactWordPopup = 0;
       
   106 
       
   107     // free mode handlers
       
   108     delete mBasicModeHandler;
       
   109     mBasicModeHandler = 0;
       
   110     delete mPredictionModeHandler;
       
   111     mPredictionModeHandler = 0;
       
   112     delete mNumericModeHandler;
       
   113     mNumericModeHandler = 0;
       
   114 }
       
   115 
       
   116 QString HbVirtualQwerty::identifierName()
       
   117 {
       
   118     return QString("HbVirtualQwerty");
       
   119 }
       
   120 
       
   121 bool HbVirtualQwerty::isComposing() const
       
   122 {
       
   123     return mActiveModeHandler->isComposing();
       
   124 }
       
   125 
       
   126 QString HbVirtualQwerty::language()
       
   127 {
       
   128     return QString();
       
   129 }
       
   130 
       
   131 void HbVirtualQwerty::reset()
       
   132 {
       
   133     mActiveModeHandler->actionHandler(HbInputModeHandler::HbInputModeActionReset);
       
   134 }
       
   135 
       
   136 void HbVirtualQwerty::focusReceived()
       
   137 {
       
   138     // set input mode to default ABC
       
   139     HbInputLanguage language = inputState().language();
       
   140     if ((!focusObject()->editorInterface().isNumericEditor() && inputState().inputMode() == HbInputModeNumeric) || !language.isCaseSensitiveLanguage()) {
       
   141         HbInputState state = inputState();
       
   142         // For Case insensitive languages, the default case should be lowercase.
       
   143         if (!language.isCaseSensitiveLanguage())
       
   144         {
       
   145             state.setTextCase(HbTextCaseLower);
       
   146         }
       
   147         else if (automaticTextCaseNeeded()) {
       
   148             state.setTextCase(HbTextCaseAutomatic);
       
   149         }
       
   150         state.inputMode() = HbInputModeDefault;
       
   151         activateState(state);
       
   152         inputStateToEditor(state);
       
   153     }
       
   154 
       
   155     // load the new keymappings to all keypads and all mode handlers
       
   156     loadKeymap(inputState().language());
       
   157     // After loadKeyMapData call, mKeyData should have keymappings data of the current language
       
   158     if(!mKeymap) {
       
   159         return; // could not get keymappings. Just return.
       
   160     }
       
   161 
       
   162     //Get vkbhost
       
   163     mVkbHost = focusObject()->editorInterface().vkbHost();
       
   164 
       
   165     HbKeypadMode currentInputType = EModeAbc;
       
   166     if (focusObject()->editorInterface().isNumericEditor()) {
       
   167         currentInputType = EModeNumeric;
       
   168     }
       
   169 
       
   170     HbInputVkbWidget * keypadToOpen = 0;
       
   171     if (currentInputType == EModeAbc) {
       
   172         if(!mQwertyAlphaKeypad) {
       
   173             mQwertyAlphaKeypad = constructKeypad(EModeAbc);
       
   174             connect(mQwertyAlphaKeypad, SIGNAL(smileySelected(QString)), this, SLOT(smileySelected(QString)));
       
   175             //FLICKDISABLED connect(mQwertyAlphaKeypad, SIGNAL(flickEvent(HbInputVkbWidget::FlickDirection)), this, SLOT(flickEvent(HbInputVkbWidget::FlickDirection)));
       
   176         }
       
   177         keypadToOpen = mQwertyAlphaKeypad;
       
   178     } else if(currentInputType == EModeNumeric) {
       
   179         if(!mQwertyNumericKeypad) {
       
   180             mQwertyNumericKeypad = constructKeypad(EModeNumeric);
       
   181             mQwertyNumericKeypad->setBackgroundDrawing(true);
       
   182         }
       
   183         keypadToOpen = mQwertyNumericKeypad;
       
   184     }
       
   185 
       
   186     if(!keypadToOpen) {
       
   187         return; // just return if keypad can not be created
       
   188     }
       
   189 
       
   190     // inform active mode handler about the focusrecieve event.
       
   191     mActiveModeHandler->actionHandler(HbInputModeHandler::HbInputModeActionFocusRecieved);
       
   192 
       
   193     // We need to check if this focusRecieved call is due to a orientation
       
   194     // switch. If yes we should get the keypad status prior to the orientation
       
   195     // switch and open the keypad in that state only.
       
   196     // For example we have minimized the keypad in Qwerty mode and change the
       
   197     // orientation to portrait then in Itu-T mode also keypad should be in minimized state.
       
   198     HbVkbHost *host = focusObject()->editorInterface().vkbHost();
       
   199     if (orientationContextSwitchInProgress()) {
       
   200         if (host) {
       
   201             // We can get the keypad status prior to the orientation switch from vkbHost it self.
       
   202             HbVkbHost::HbVkbStatus vkbStatus = host->keypadStatusBeforeOrientationChange();
       
   203             if (vkbStatus != HbVkbHost::HbVkbStatusClosed) {
       
   204                 openKeypad(keypadToOpen,vkbStatus == HbVkbHost::HbVkbStatusMinimized);
       
   205             }
       
   206         }
       
   207     } else {
       
   208         openKeypad(keypadToOpen);
       
   209     }
       
   210 
       
   211     if (mVkbHost) {
       
   212         connect(&(focusObject()->editorInterface()), SIGNAL(cursorPositionChanged(int, int)), mVkbHost, SLOT(ensureCursorVisibility()));
       
   213     }
       
   214 
       
   215     if (focusObject()) {
       
   216         disconnect(&(focusObject()->editorInterface()), SIGNAL(cursorPositionChanged(int, int)), mActiveModeHandler, SLOT(cursorPositionChanged(int, int)));
       
   217         connect(&(focusObject()->editorInterface()), SIGNAL(cursorPositionChanged(int, int)), mActiveModeHandler, SLOT(cursorPositionChanged(int, int)));
       
   218     }
       
   219 }
       
   220 
       
   221 void HbVirtualQwerty::focusLost(bool focusSwitch)
       
   222 {
       
   223     mActiveModeHandler->actionHandler(HbInputModeHandler::HbInputModeActionFocusLost);
       
   224 
       
   225     if (focusObject()) {
       
   226         disconnect(&(focusObject()->editorInterface()), SIGNAL(cursorPositionChanged(int, int)), mActiveModeHandler, SLOT(cursorPositionChanged(int, int)));
       
   227     }
       
   228 
       
   229     if (!focusSwitch) {
       
   230         if (mVkbHost && mVkbHost->keypadStatus() != HbVkbHost::HbVkbStatusClosed) {
       
   231             // Context switch has happened but the keypad is still open.
       
   232             // Close it.
       
   233             closeKeypad();
       
   234         }
       
   235     }
       
   236 }
       
   237 
       
   238 void HbVirtualQwerty::closeKeypad()
       
   239 {
       
   240     if (mVkbHost && mVkbHost->keypadStatus() != HbVkbHost::HbVkbStatusClosed) {
       
   241         mVkbHost->closeKeypad();
       
   242         // set mCurrentKeypad to null.
       
   243         mCurrentKeypad = 0;
       
   244         if (mCandidatePopup && mCandidatePopup->isVisible()) {
       
   245             mCandidatePopup->hide();
       
   246         }
       
   247     }
       
   248 }
       
   249 
       
   250 void HbVirtualQwerty::openKeypad(HbInputVkbWidget * keypadToOpen,bool inMinimizedMode )
       
   251 {
       
   252     // if null is sent, just return.
       
   253     if(!keypadToOpen) {
       
   254         return;
       
   255     }
       
   256     // see if we are trying to open a different keypad than what is already opened.
       
   257     if (mCurrentKeypad != keypadToOpen) {
       
   258         // close currently open keypad. We always close keypad without animation
       
   259         // keypad should be closed with animation only when we loses focus and this is handled
       
   260         // in focusLost function call.
       
   261         if (mVkbHost && mVkbHost->keypadStatus() != HbVkbHost::HbVkbStatusClosed) {
       
   262             mVkbHost->closeKeypad(false);
       
   263         }
       
   264     }
       
   265     // Close candidate popup if open
       
   266     if (mCandidatePopup) {
       
   267         mCandidatePopup->hide();
       
   268     }
       
   269     // assign new keypad to be opened to varable mCurrentKeypad
       
   270     mCurrentKeypad =  keypadToOpen;
       
   271 
       
   272     if (mVkbHost && mVkbHost->keypadStatus() != HbVkbHost::HbVkbStatusOpened) {
       
   273         connect(mVkbHost, SIGNAL(keypadClosed()), this, SLOT(keypadClosed()));
       
   274         if (inMinimizedMode) {
       
   275             mVkbHost->openMinimizedKeypad(mCurrentKeypad, this);
       
   276         } else {
       
   277             mVkbHost->openKeypad(mCurrentKeypad, this);
       
   278         }
       
   279 
       
   280         // If previous focused editor was numeric, prediction is disabled.
       
   281         // Enable prediction if prediction was set in alpha editor prior
       
   282         // to focusing numeric editor.
       
   283 /*        if (mPrevKeypadMode == EModeAbc && HbInputModeLatinPredictive == mPreviousInputMode) {
       
   284             mMode = HbInputModeLatinPredictive;
       
   285         } else if (mPrevKeypadMode == EModeNumeric && HbInputModeLatinPredictive == mMode) {
       
   286             // If the previous focused editor was alpha and if prediction is
       
   287             // on, disable prediction. Store the previous state because if
       
   288             // any alpha editor is focused next, the previous prediction state
       
   289             // should be enabled.
       
   290             mMode = HbInputModeDefault;
       
   291             mPreviousInputMode = HbInputModeLatinPredictive;
       
   292         }  */
       
   293         connect(&(focusObject()->editorInterface()), SIGNAL(cursorPositionChanged(int, int)), mVkbHost, SLOT(ensureCursorVisibility()));
       
   294     }
       
   295 }
       
   296 
       
   297 HbQwertyKeyboard* HbVirtualQwerty::constructKeypad(HbKeypadMode currentInputType)
       
   298 {
       
   299     HbQwertyKeyboard* keypad =  new HbQwertyKeyboard(this, mKeymap, 0, currentInputType);
       
   300     connect(keypad, SIGNAL(keypadCloseEventDetected(HbInputVkbWidget::HbVkbCloseMethod)),
       
   301         this, SLOT(keypadCloseEventDetected(HbInputVkbWidget::HbVkbCloseMethod)));
       
   302     connect(keypad, SIGNAL(rockerDirection(int, HbInputVirtualRocker::RockerSelectionMode)),
       
   303         this, SLOT(rockerDirection(int, HbInputVirtualRocker::RockerSelectionMode)));
       
   304     connect(keypad, SIGNAL(mouseMovedOutOfButton()), this, SLOT(mouseMovedOutOfButton()));
       
   305     keypad->setRockerVisible(true);
       
   306 
       
   307     return keypad;
       
   308 }
       
   309 
       
   310 void HbVirtualQwerty::mouseHandler(int x, QMouseEvent* event)
       
   311 {
       
   312     mActiveModeHandler->mouseHandler(x, event);
       
   313 }
       
   314 
       
   315 void HbVirtualQwerty::keypadClosed()
       
   316 {
       
   317     // by calling focuslost we will be committing the inline text.
       
   318     mActiveModeHandler->actionHandler(HbInputModeHandler::HbInputModeActionFocusLost);
       
   319 
       
   320     if (mOrientationAboutToChange) {
       
   321         mOrientationAboutToChange = false;
       
   322     }
       
   323 }
       
   324 
       
   325 void HbVirtualQwerty::keypadCloseEventDetected(HbInputVkbWidget::HbVkbCloseMethod vkbCloseMethod)
       
   326 {
       
   327     Q_UNUSED(vkbCloseMethod);
       
   328     if (isActiveMethod()) {
       
   329         if (mVkbHost && mVkbHost->keypadStatus() != HbVkbHost::HbVkbStatusMinimized) {
       
   330             mVkbHost->minimizeKeypad(!stateChangeInProgress());
       
   331             if (mCandidatePopup) {
       
   332                 mCandidatePopup->hide();
       
   333             }
       
   334         }
       
   335     }
       
   336 }
       
   337 
       
   338 void HbVirtualQwerty::inputLanguageChanged(const HbInputLanguage &aNewLanguage)
       
   339 {
       
   340     mPredictionModeHandler->actionHandler(HbInputModeHandler::HbInputModeActionCommit);
       
   341 	if (mExactWordPopup && mExactWordPopup->isVisible())
       
   342         closeExactWordPopup();
       
   343     // move keypad off screen
       
   344     if (mCurrentKeypad){
       
   345         mCurrentKeypad->keypadLanguageChangeAnimationUpdate(0);
       
   346     }
       
   347     // load the new key keymappings for newLanguage to all keypads and all mode handlers
       
   348     loadKeymap(aNewLanguage);
       
   349     mPredictionModeHandler->actionHandler(HbInputModeHandler::HbInputModeActionPrimaryLanguageChanged);
       
   350     if (mCurrentKeypad){
       
   351         mCurrentKeypad->animKeyboardChange();
       
   352     }
       
   353 
       
   354 }
       
   355 
       
   356 void HbVirtualQwerty::inputStateActivated(const HbInputState& newState)
       
   357 {
       
   358 
       
   359     if (!isActiveMethod()) {
       
   360         return;  // Just to be sure...
       
   361     }
       
   362 
       
   363     if (newState.inputMode() == HbInputModeNumeric && mQwertyNumericKeypad) {
       
   364         mQwertyNumericKeypad->setMode(EModeNumeric, HbModifierNone);
       
   365     } else if(mQwertyAlphaKeypad) {
       
   366         if (newState.textCase() == HbTextCaseUpper || newState.textCase() == HbTextCaseAutomatic) {
       
   367             mQwertyAlphaKeypad->setMode(EModeAbc, HbModifierShiftPressed);
       
   368         } else {
       
   369             mQwertyAlphaKeypad->setMode(EModeAbc, HbModifierNone);
       
   370         }
       
   371     }
       
   372 
       
   373     HbInputModeHandler *previousModeHandler = mActiveModeHandler;
       
   374     if (newState.inputMode() == HbInputModeNumeric) {
       
   375         mActiveModeHandler = mNumericModeHandler;
       
   376     }  else if (newState.inputMode() == HbInputModeDefault && usePrediction()) {
       
   377         mActiveModeHandler = mPredictionModeHandler;
       
   378         if (mQwertyAlphaKeypad) {
       
   379             mQwertyAlphaKeypad->disconnect(SIGNAL(charFromPreviewSelected(QString)));
       
   380             connect(mQwertyAlphaKeypad, SIGNAL(charFromPreviewSelected(QString)), mActiveModeHandler, SLOT(charFromPreviewSelected(QString)));
       
   381         }
       
   382     } else if (newState.inputMode() == HbInputModeDefault) {
       
   383         mActiveModeHandler = mBasicModeHandler;
       
   384         // Auto completer setup needs following line.
       
   385         mActiveModeHandler->actionHandler(HbInputModeHandler::HbInputModeActionFocusRecieved);
       
   386         if (mQwertyAlphaKeypad) {
       
   387             mQwertyAlphaKeypad->disconnect(SIGNAL(charFromPreviewSelected(QString)));
       
   388             connect(mQwertyAlphaKeypad, SIGNAL(charFromPreviewSelected(QString)), mActiveModeHandler, SLOT(charFromPreviewSelected(QString)));
       
   389         }
       
   390     }
       
   391 
       
   392     if (focusObject()) {
       
   393         disconnect(&(focusObject()->editorInterface()), SIGNAL(cursorPositionChanged(int, int)), previousModeHandler, SLOT(cursorPositionChanged(int, int)));
       
   394         connect(&(focusObject()->editorInterface()), SIGNAL(cursorPositionChanged(int, int)), mActiveModeHandler, SLOT(cursorPositionChanged(int, int)));
       
   395     }
       
   396 
       
   397     // load the new keymappings to all keypads and all mode handlers
       
   398     loadKeymap(newState.language());
       
   399 
       
   400     // if there is a change in the modehandler we need send a commit in previous mode handler.
       
   401     if (previousModeHandler != mActiveModeHandler) {
       
   402         //Auto Completion part also to be committed on mode change and hide exact word popup.
       
   403         previousModeHandler->actionHandler(HbInputModeHandler::HbInputModeActionCommit);
       
   404         if (previousModeHandler == mPredictionModeHandler) {
       
   405             closeExactWordPopup();
       
   406         }
       
   407         // lets set candidate list and keypad type to the engine.
       
   408         mActiveModeHandler->actionHandler(HbInputModeHandler::HbInputModeActionSetCandidateList);
       
   409         mActiveModeHandler->actionHandler(HbInputModeHandler::HbInputModeActionSetKeypad);
       
   410     }
       
   411 }
       
   412 
       
   413 /*!
       
   414 This function loads the keymappings data of the given language to all the keypads and to all mode handlers.
       
   415 It first checks if we already have keymappings data of given language in mKeyData, if not then gets the
       
   416 keymappings,loads them to all avaialble keyboards and to all mode handlers
       
   417 */
       
   418 void HbVirtualQwerty::loadKeymap(const HbInputLanguage &newLanguage)
       
   419 {
       
   420     // inform all the mode handler about the language change.
       
   421     //dont try to get the keymappings if we ( mKeyData) already have keymappings for newLanguage
       
   422     if (!mKeymap || mKeymap->language() != newLanguage) {
       
   423 
       
   424         const HbKeymap* keymap = HbKeymapFactory::instance()->keymap(newLanguage);
       
   425         if (keymap) {
       
   426             mKeymap =  keymap;
       
   427             if (mQwertyNumericKeypad) {
       
   428                 mQwertyNumericKeypad->setKeymap(mKeymap);
       
   429             }
       
   430 
       
   431             if (mQwertyAlphaKeypad) {
       
   432                 mQwertyAlphaKeypad->setKeymap(mKeymap);
       
   433             }
       
   434 
       
   435             if (mSctKeypad) {
       
   436                 mSctKeypad->setKeymap(mKeymap);
       
   437             }
       
   438 
       
   439             // inform mode handlers about the language change.
       
   440             if(mBasicModeHandler) {
       
   441                 mBasicModeHandler->setKeymap(mKeymap);
       
   442             }
       
   443             if(mPredictionModeHandler) {
       
   444                 mPredictionModeHandler->setKeymap(mKeymap);
       
   445             }
       
   446             if(mNumericModeHandler) {
       
   447                 mNumericModeHandler->setKeymap(mKeymap);
       
   448             }
       
   449         }
       
   450     }
       
   451 }
       
   452 
       
   453 void HbVirtualQwerty::switchSpecialCharacterTable()
       
   454 {
       
   455     if (mCurrentKeypad != mSctKeypad) {
       
   456         mSctMode = HbInputVkbWidget::HbSctViewSpecialCharacter;
       
   457         displaySpecialCharacterTable(this);
       
   458     } else {
       
   459         // we always go back to alpha qwerty mode after coming back from sct
       
   460         openKeypad(mQwertyAlphaKeypad);
       
   461     }
       
   462 }
       
   463 
       
   464 void HbVirtualQwerty::secondaryInputLanguageChanged(const HbInputLanguage &newLanguage)
       
   465 {
       
   466     Q_UNUSED(newLanguage);
       
   467     mPredictionModeHandler->actionHandler(HbInputModeHandler::HbInputModeActionSecondaryLanguageChanged);
       
   468 }
       
   469 
       
   470 int HbVirtualQwerty::displaySpecialCharacterTable(QObject* aReceiver)
       
   471 {
       
   472     Q_UNUSED(aReceiver);
       
   473 
       
   474     if (!mSctKeypad) {
       
   475         mSctKeypad = new HbInputSctLandscape(this, mKeymap);
       
   476         connect(mSctKeypad, SIGNAL(sctCharacterSelected(QString)), this, SLOT(sctCharacterSelected(QString)));
       
   477         connect(mSctKeypad, SIGNAL(smileySelected(QString)), this, SLOT(smileySelected(QString)));
       
   478         connect(mSctKeypad, SIGNAL(keypadCloseEventDetected(HbInputVkbWidget::HbVkbCloseMethod)), this, SLOT(keypadCloseEventDetected(HbInputVkbWidget::HbVkbCloseMethod)));
       
   479         connect(mSctKeypad, SIGNAL(rockerDirection(int, HbInputVirtualRocker::RockerSelectionMode)),
       
   480             this, SLOT(rockerDirection(int, HbInputVirtualRocker::RockerSelectionMode)));
       
   481         mSctKeypad->setRockerVisible(true);
       
   482     }
       
   483 
       
   484     // set up sct!
       
   485     mSctKeypad->setSct(mSctMode);
       
   486     //open the keypad
       
   487     openKeypad(mSctKeypad);
       
   488 
       
   489     return 0;
       
   490 }
       
   491 
       
   492 /*!
       
   493 Call-back implementation to indicate that a character was selected from the SCT. With this, the character is committed to the
       
   494 editor and editor is again made to focus.
       
   495 */
       
   496 void HbVirtualQwerty::sctCharacterSelected(QString character)
       
   497 {
       
   498     mActiveModeHandler->sctCharacterSelected(character);
       
   499     /* Update the text case */
       
   500     updateState();
       
   501 }
       
   502 void HbVirtualQwerty::smileySelected(QString smiley)
       
   503 {
       
   504      mActiveModeHandler->smileySelected(smiley);
       
   505 }
       
   506 
       
   507 void HbVirtualQwerty::selectSpecialCharacterTableMode()
       
   508 {
       
   509     if (mQwertyAlphaKeypad) {
       
   510         mQwertyAlphaKeypad->showSmileyPicker(4, 10);
       
   511     }
       
   512 }
       
   513 
       
   514 /*!
       
   515 Slot used by mode handlers to close the autocompletion popup.
       
   516 */
       
   517 void HbVirtualQwerty::closeAutoCompletionPopup()
       
   518 {
       
   519     if (mCandidatePopup && mCandidatePopup->isVisible()) {
       
   520         mCandidatePopup->hide();
       
   521     }
       
   522 }
       
   523 
       
   524 /*!
       
   525 Launches auto-completion popup if there are candidates available.
       
   526 */
       
   527 void HbVirtualQwerty::launchAutoCompletionPopup(const QStringList& candidates)
       
   528 {
       
   529     if (!mCandidatePopup) {
       
   530         mCandidatePopup = new HbCandidateList(this);
       
   531         connect(mCandidatePopup, SIGNAL(candidatePopupCancelled()), this, SLOT(candidatePopupCancelled()));
       
   532     }
       
   533 
       
   534     if (candidates.count() > 0) {
       
   535         mCandidatePopup->populateList(candidates);
       
   536         mCandidatePopup->setModal(false);
       
   537 
       
   538         if (mCandidatePopup->setSizeAndPositionForAutoCompletion(mVkbHost)) {
       
   539             mCandidatePopup->setDismissPolicy(HbPopup::TapInside);
       
   540             mCandidatePopup->setBackgroundFaded(false);
       
   541             mCandidatePopup->show();
       
   542         }
       
   543     } else if (mCandidatePopup->isVisible()) {
       
   544         mCandidatePopup->hide();
       
   545     }
       
   546 }
       
   547 
       
   548 /*!
       
   549 Launches the candidate list.
       
   550 */
       
   551 void HbVirtualQwerty::launchCandidatePopup()
       
   552 {
       
   553 
       
   554 }
       
   555 /*!
       
   556 Launches the candidate list with the passed candidates.
       
   557 */
       
   558 void HbVirtualQwerty::launchCandidatePopup(const QStringList &candidates)
       
   559 {
       
   560     //before launching candidate popup, close exact word popup if visible.
       
   561     closeExactWordPopup();
       
   562     if (!mCandidatePopup) {
       
   563         mCandidatePopup = new HbCandidateList(this);
       
   564         connect(mCandidatePopup, SIGNAL(candidatePopupCancelled()), this, SLOT(candidatePopupCancelled()));
       
   565     }
       
   566     mCandidatePopup->populateList(candidates);
       
   567     mCandidatePopup->setModal(true);
       
   568 
       
   569     QSizeF candListSize = mCandidatePopup->size();
       
   570     QPointF candListPos = mCandidatePopup->pos();
       
   571     getCandidatePositionAndSize(mCandidatePopup, mCurrentKeypad,candListPos,candListSize);
       
   572 
       
   573     QRectF geom = mCandidatePopup->geometry();
       
   574     geom.setHeight(candListSize.height());
       
   575     geom.setWidth(candListSize.width());
       
   576     mCandidatePopup->setGeometry(geom);
       
   577 
       
   578     mCandidatePopup->setPos(candListPos);
       
   579 
       
   580     mCandidatePopup->show();
       
   581 }
       
   582 
       
   583 /*!
       
   584 Commits the candidate upon closing of the candidate list.
       
   585 */
       
   586 void HbVirtualQwerty::candidatePopupClosed(int closingKey)
       
   587 {
       
   588     if (mCandidatePopup) {
       
   589         QString currentCandidate = mCandidatePopup->currentCandidate();
       
   590         if (currentCandidate.size() > 0) {
       
   591             if ((focusObject()->editorInterface().constraints() & HbEditorConstraintAutoCompletingField)) {
       
   592                 emit autoCompletionPopupClosed(currentCandidate, closingKey);
       
   593             } else {
       
   594             mPredictionModeHandler->candidatePopupClosed(currentCandidate, closingKey);
       
   595             }
       
   596         }
       
   597     }
       
   598 }
       
   599 
       
   600 /*!
       
   601 The call back from framework to indicate that the orientation is about to change. This closes the keypad
       
   602 if it is already open.
       
   603 */
       
   604 void HbVirtualQwerty::orientationAboutToChange()
       
   605 {
       
   606     HbInputMethod::orientationAboutToChange();
       
   607 
       
   608     if (isActiveMethod()) {
       
   609         mOrientationAboutToChange = true;
       
   610     }
       
   611     closeKeypad();
       
   612 }
       
   613 
       
   614 /*!
       
   615 This function is called during a long key press
       
   616 for a long time.
       
   617 */
       
   618 void HbVirtualQwerty::launchCharacterPreviewPane(int key)
       
   619 {
       
   620     // In alpha keyboard, when the keypad is closed by
       
   621     // dragging it, long key press event is generated.
       
   622     // Character preview must not be shown in this case.
       
   623     if (mVkbHost && mVkbHost->keypadStatus() != HbVkbHost::HbVkbStatusOpened) {
       
   624         return;
       
   625     }
       
   626 
       
   627     // get the characters bound to the key.
       
   628     QStringList spellList;
       
   629     mActiveModeHandler->getAndFilterCharactersBoundToKey(spellList, static_cast<Qt::Key>(key));
       
   630 
       
   631     bool previewAvailable = false;
       
   632     if (spellList.size()) {
       
   633         // preview pane should show the correct case.
       
   634         int currentTextCase = focusObject()->editorInterface().textCase();
       
   635         for(int i = 0; i < spellList.size(); i++) {
       
   636             if (currentTextCase == HbTextCaseLower) {
       
   637                 spellList[i] = spellList.at(i).toLower();
       
   638             } else {
       
   639                 spellList[i] = spellList.at(i).toUpper();
       
   640             }
       
   641         }
       
   642         previewAvailable = mQwertyAlphaKeypad->previewCharacters(spellList);
       
   643     }
       
   644     mActiveModeHandler->characterPreviewAvailable(previewAvailable);
       
   645 }
       
   646 
       
   647 /*!
       
   648 Slot used by virtual rocker to move cursor.
       
   649 */
       
   650 void HbVirtualQwerty::rockerDirection(int aDirection, HbInputVirtualRocker::RockerSelectionMode aSelectionMode)
       
   651 {
       
   652     Qt::KeyboardModifiers modifiers = 0;
       
   653     if (aSelectionMode == HbInputVirtualRocker::RockerSelectionModeOn) {
       
   654         modifiers = Qt::ShiftModifier;
       
   655     }
       
   656     // commit any character/word which is in inline edit.
       
   657     mActiveModeHandler->actionHandler(HbInputModeHandler::HbInputModeActionCommit);
       
   658     HbInputLanguage inputlang = HbInputSettingProxy::instance()->globalInputLanguage();
       
   659 
       
   660     switch (aDirection) {
       
   661     case HbInputVirtualRocker::HbRockerDirectionLeft:
       
   662         if(inputlang.isRightToLeftLanguage()) {
       
   663             focusObject()->cursorRight(modifiers);
       
   664         } else {
       
   665             focusObject()->cursorLeft(modifiers);
       
   666         }
       
   667         break;
       
   668     case HbInputVirtualRocker::HbRockerDirectionRight:
       
   669         if(inputlang.isRightToLeftLanguage()) {
       
   670             focusObject()->cursorLeft(modifiers);
       
   671         } else {
       
   672             focusObject()->cursorRight(modifiers);
       
   673         }
       
   674         break;
       
   675     case HbInputVirtualRocker::HbRockerDirectionUp: {
       
   676         QKeyEvent keyEvent(QEvent::KeyPress, Qt::Key_Up, modifiers);
       
   677         focusObject()->sendEvent(keyEvent);
       
   678         }
       
   679         break;
       
   680     case HbInputVirtualRocker::HbRockerDirectionDown: {
       
   681         QKeyEvent keyEvent(QEvent::KeyPress, Qt::Key_Down, modifiers);
       
   682         focusObject()->sendEvent(keyEvent);
       
   683         }
       
   684         break;
       
   685     default:
       
   686         break;
       
   687     }
       
   688 }
       
   689 
       
   690 void HbVirtualQwerty::predictiveInputStatusChanged(int newStatus)
       
   691 {
       
   692     Q_UNUSED(newStatus);
       
   693 
       
   694     HbInputFocusObject *focusedObject = focusObject();
       
   695     if (focusedObject) {
       
   696         // Just refresh the situation.
       
   697         inputStateActivated(inputState());
       
   698         return;
       
   699     }
       
   700 }
       
   701 
       
   702 /*!
       
   703 this function is called whenever there is a hardware keypress Or virtual keypad button is pressed.
       
   704 */
       
   705 bool HbVirtualQwerty::filterEvent(const QEvent* event)
       
   706 {
       
   707     return mActiveModeHandler->filterEvent(event);
       
   708 }
       
   709 
       
   710 void HbVirtualQwerty::flickEvent(HbInputVkbWidget::HbFlickDirection direction)
       
   711 {
       
   712     Q_UNUSED(direction);
       
   713 }
       
   714 
       
   715 /*!
       
   716 Slot used by mode handlers to set the keypad modifiers
       
   717 */
       
   718 void HbVirtualQwerty::launchExactWordPopup(QString exactWord)
       
   719 {
       
   720     if (!mExactWordPopup) {
       
   721         mExactWordPopup = HbExactWordPopup::instance();
       
   722         connect(mExactWordPopup, SIGNAL(exactWordSelected()), mPredictionModeHandler, SLOT(exactWordPopupClosed()));
       
   723     }
       
   724     mExactWordPopup->setText(exactWord);
       
   725     mExactWordPopup->showText(getCursorCoordinatePosition());
       
   726 }
       
   727 
       
   728 /*!
       
   729 Slot for hiding the exact word popup.
       
   730 */
       
   731 void HbVirtualQwerty::closeExactWordPopup()
       
   732 {
       
   733     if (mExactWordPopup && mExactWordPopup->isVisible()) {
       
   734         mExactWordPopup->hide();
       
   735     }
       
   736 }
       
   737 
       
   738 QPointF HbVirtualQwerty::getCursorCoordinatePosition()
       
   739 {
       
   740     QRectF microRect = focusObject()->microFocus();
       
   741     return microRect.topLeft();
       
   742 }
       
   743 
       
   744 /*!
       
   745 Returns true if prediction is on, prediction engine is available and predictions is allowed in current editor.
       
   746 */
       
   747 bool HbVirtualQwerty::usePrediction() const
       
   748 {
       
   749     HbInputFocusObject *fo = focusObject();
       
   750     if (HbInputSettingProxy::instance()->predictiveInputStatus() &&
       
   751         fo &&
       
   752         fo->editorInterface().isPredictionAllowed() &&
       
   753         mPredictionModeHandler->isActive() &&
       
   754         HbPredictionFactory::instance()->predictionEngineForLanguage(inputState().language())) {
       
   755          return true;           
       
   756     }
       
   757 
       
   758     return false;
       
   759 }
       
   760 
       
   761 void HbVirtualQwerty::mouseMovedOutOfButton()
       
   762 {
       
   763     mActiveModeHandler->actionHandler(HbInputModeHandler::HbInputModeActionCancelButtonPress);
       
   764 }
       
   765 
       
   766 QList<HbKeyPressProbability> HbVirtualQwerty::probableKeypresses()
       
   767 {
       
   768     return mCurrentKeypad->probableKeypresses();
       
   769 }
       
   770 
       
   771 void HbVirtualQwerty::candidatePopupCancelled()
       
   772 {
       
   773     if(mPredictionModeHandler) {
       
   774         mPredictionModeHandler->showExactWordPopupIfNeeded();
       
   775     }
       
   776 }
       
   777 // End of file