src/hbplugins/inputmethods/touchinput/virtual12key.cpp
changeset 1 f7ac710697a9
parent 0 16d8024aca5e
child 2 06ff229162e9
--- a/src/hbplugins/inputmethods/touchinput/virtual12key.cpp	Mon Apr 19 14:02:13 2010 +0300
+++ b/src/hbplugins/inputmethods/touchinput/virtual12key.cpp	Mon May 03 12:48:33 2010 +0300
@@ -42,11 +42,15 @@
 #include <hbview.h>
 #include <hbinputvkbhost.h>
 #include <hbinputcommondialogs.h>
+#include <hbdeviceprofile.h>
 
 //User includes
+#include "hbinputthaispecialpopup.h"
 #include "hbinputbasic12keyhandler.h"
 #include "hbinputprediction12keyhandler.h"
 #include "hbinputnumeric12keyhandler.h"
+#include "hbinputbasic12keythaihandler.h"
+#include "hbinputprediction12keythaihandler.h"
 
 const int HbSmileyNumberOfRows = 5;
 const int HbSmileyNumberOfColumns = 5;
@@ -65,6 +69,7 @@
               : mCurrentKeypad(0),
                 mItutKeypad(0),
                 mSctKeypad(0),
+				mThaiSpecialChar(0),
                 mKeymap(0),
                 mSctMode(HbInputVkbWidget::HbSctViewSpecialCharacter),
                 mOrientationAboutToChange(false),
@@ -81,16 +86,22 @@
     mBasicModeHandler = new HbInputBasic12KeyHandler(this);
     mPredictionModeHandler = new HbInputPrediction12KeyHandler(this);
     mNumericModeHandler = new HbInputNumeric12KeyHandler(this);
+	mBasic12keyThaiHandler = new HbInputBasic12KeyThaiHandler(this);
+	mPrediction12keyThaiHandler = new HbInputPrediction12KeyThaiHandler(this);
     mActiveModeHandler = mBasicModeHandler;
 
     mBasicModeHandler->actionHandler(HbInputModeHandler::HbInputModeActionInit);
     mPredictionModeHandler->actionHandler(HbInputModeHandler::HbInputModeActionInit);
     mNumericModeHandler->actionHandler(HbInputModeHandler::HbInputModeActionInit);
+	mPrediction12keyThaiHandler->actionHandler(HbInputModeHandler::HbInputModeActionInit);
 
     // let's connect prediction mode handler with latin basic mode handler. It is required incase we Qt::key_0 is pressed in prediction mode
     // key
     connect(mPredictionModeHandler, SIGNAL(passFilterEvent(const QKeyEvent *)), mBasicModeHandler, SLOT(filterEvent(const QKeyEvent *)));
     connect(mPredictionModeHandler, SIGNAL(passActionHandler(HbInputModeAction )), mBasicModeHandler, SLOT(actionHandler(HbInputModeAction )));
+	connect(mPrediction12keyThaiHandler, SIGNAL(passFilterEvent(const QKeyEvent *)), mBasicModeHandler, SLOT(filterEvent(const QKeyEvent *)));
+    connect(mPrediction12keyThaiHandler, SIGNAL(passActionHandler(HbInputModeAction )), mBasicModeHandler, SLOT(actionHandler(HbInputModeAction )));
+
 }
 
 bool HbVirtual12Key::isSctModeActive() const
@@ -111,6 +122,8 @@
     mSctKeypad = 0;
     delete mCandidatePopup;
     mCandidatePopup = 0;
+	delete mThaiSpecialChar;
+	mThaiSpecialChar = 0;
 
     // free mode handlers
     delete mBasicModeHandler;
@@ -119,6 +132,10 @@
     mPredictionModeHandler = 0;
     delete mNumericModeHandler;
     mNumericModeHandler = 0;
+	delete mBasic12keyThaiHandler;
+	mBasic12keyThaiHandler = 0;
+	delete mPrediction12keyThaiHandler;
+	mPrediction12keyThaiHandler = 0;
 }
 
 /*!
@@ -175,6 +192,7 @@
     //FLICKDISABLED connect(tempKeypad, SIGNAL(flickEvent(HbInputVkbWidget::FlickDirection)), this, SLOT(flickEvent(HbInputVkbWidget::FlickDirection)));
     connect(tempKeypad, SIGNAL(smileySelected(QString)), this, SLOT(smileySelected(QString)));
     connect(tempKeypad, SIGNAL(mouseMovedOutOfButton()), this, SLOT(mouseMovedOutOfButton()));
+	connect(tempKeypad, SIGNAL(chrSelected(QString)), this, SLOT(thaiSctCharacterSelected(QString)));
     tempKeypad->setRockerVisible(true);
     return tempKeypad;
 }
@@ -279,6 +297,9 @@
         mVkbHost->closeKeypad(!stateChangeInProgress());
         // set mCurrentKeypad to null.
         mCurrentKeypad = 0;
+		if(mThaiSpecialChar) {
+			mThaiSpecialChar->hide();
+		}
         if (mCandidatePopup) {
             mCandidatePopup->hide();
         }
@@ -298,6 +319,7 @@
     if(!keypadToOpen) {
         return;
     }
+    bool wasKeypadOpen = false;
     // see if we are trying to open a different keypad than what is already opened.
     if (mCurrentKeypad != keypadToOpen) {
         // close currently open keypad. We always close keypad without animation
@@ -305,6 +327,9 @@
         // in focusLost function call.
         if (mVkbHost && mVkbHost->keypadStatus() != HbVkbHost::HbVkbStatusClosed) {
             mVkbHost->closeKeypad(false);
+            // when their is a keypad that needs to be closed before opening the new keypad, we don't
+            // want to animate the opening of new keypad.
+            wasKeypadOpen = true;
         }
     }
     // Close candidate popup if open
@@ -321,7 +346,7 @@
         if (inMinimizedMode) {
             mVkbHost->openMinimizedKeypad(mCurrentKeypad, this);
         } else {
-            mVkbHost->openKeypad(mCurrentKeypad, this, !stateChangeInProgress());
+            mVkbHost->openKeypad(mCurrentKeypad, this, (!stateChangeInProgress() && !wasKeypadOpen));
         }
         connect(&(focusObject()->editorInterface()), SIGNAL(cursorPositionChanged(int, int)), mVkbHost, SLOT(ensureCursorVisibility()));
     }
@@ -336,15 +361,28 @@
     mActiveModeHandler->mouseHandler(cursorPosition, mouseEvent);
 }
 
+/*!
+\deprecated HbVirtual12Key::predictiveInputStatusChanged(int newStatus)
+    is deprecated. Use predictiveInputStateChanged instead.
+*/
 void HbVirtual12Key::predictiveInputStatusChanged(int newStatus)
 {
+    predictiveInputStateChanged(HbKeyboardSetting12key, newStatus);
+}
+
+/*!
+The framework calls this method when the predictive input status changes.
+*/
+void HbVirtual12Key::predictiveInputStateChanged(HbKeyboardSettingFlags keyboardType, bool newStatus)
+{
     Q_UNUSED(newStatus);
 
-    HbInputFocusObject *focusedObject = focusObject();
-    if (focusedObject) {
-        // Just refresh the situation.
-        inputStateActivated(inputState());
-        return;
+    if (keyboardType & HbKeyboardSetting12key) {
+        HbInputFocusObject *focusedObject = focusObject();
+        if (focusedObject) {
+            // Just refresh the situation.
+            inputStateActivated(inputState());
+        }
     }
 }
 
@@ -353,10 +391,6 @@
 */
 void HbVirtual12Key::keypadClosed()
 {
-
-    // commit any character/word which is in inline edit.
-    mActiveModeHandler->actionHandler(HbInputModeHandler::HbInputModeActionCommit);
-
     if (mOrientationAboutToChange) {
         mOrientationAboutToChange = false;
     }
@@ -378,10 +412,12 @@
     if (isActiveMethod()) {
         if (mVkbHost) {
             if (mVkbHost->keypadStatus() == HbVkbHost::HbVkbStatusOpened) {
-                mVkbHost->minimizeKeypad(!stateChangeInProgress());
+                // We need to commit the inline word when we minimize the keypad
+                mActiveModeHandler->actionHandler(HbInputModeHandler::HbInputModeActionCommit);
                 if (mCandidatePopup) {
                     mCandidatePopup->hide();
                 }
+                mVkbHost->minimizeKeypad(!stateChangeInProgress());
             }
         }
     }
@@ -483,10 +519,7 @@
     if (mItutKeypad) {
         if (newState.inputMode() == HbInputModeNumeric) {
             // Numeric mode is activated, set numeric mode to itu-t keypad
-            if(mItutKeypad->mode() != EModeNumeric) {
-                // Editor is in numeric mode.
                 mItutKeypad->setMode(EModeNumeric, HbModifierNone);
-            }
         } else if (newState.inputMode() != HbInputModeNumeric) {
             if (newState.textCase() == HbTextCaseUpper || newState.textCase() == HbTextCaseAutomatic) {
                 mItutKeypad->setMode(EModeAbc, HbModifierShiftPressed);
@@ -497,7 +530,16 @@
     }
 
     HbInputModeHandler *previousModeHandler = mActiveModeHandler;
-    if (newState.inputMode() == HbInputModeDefault && usePrediction()) {
+	if(HbInputSettingProxy::instance()->globalInputLanguage() == QLocale::Thai && usePrediction() && newState.inputMode() != HbInputModeNumeric ) {
+		mActiveModeHandler = mPrediction12keyThaiHandler;
+		// by passing HbInputModeActionFocusRecieved we will be setting the candidate list and keypad
+        mActiveModeHandler->actionHandler(HbInputModeHandler::HbInputModeActionFocusRecieved);
+	} else if (HbInputSettingProxy::instance()->globalInputLanguage() == QLocale::Thai && !usePrediction() && newState.inputMode() != HbInputModeNumeric 
+		&& ((HbEditorConstraintLatinAlphabetOnly | HbEditorConstraintAutoCompletingField)!=focusObject()->editorInterface().constraints())) {
+		mActiveModeHandler = mBasic12keyThaiHandler;
+		// by passing HbInputModeActionFocusRecieved we will be setting the candidate list and keypad
+        mActiveModeHandler->actionHandler(HbInputModeHandler::HbInputModeActionFocusRecieved);
+	} else if (newState.inputMode() == HbInputModeDefault && usePrediction()) {
         mActiveModeHandler = mPredictionModeHandler;
         // by passing HbInputModeActionFocusRecieved we will be setting the candidate list and keypad
         mActiveModeHandler->actionHandler(HbInputModeHandler::HbInputModeActionFocusRecieved);
@@ -522,7 +564,7 @@
         // Auto Completion part needs to be committed as well on mode change.
 
         previousModeHandler->actionHandler(HbInputModeHandler::HbInputModeActionCommit);
-        if (mActiveModeHandler == mPredictionModeHandler) {
+        if (mActiveModeHandler == mPredictionModeHandler || mActiveModeHandler == mPrediction12keyThaiHandler) {
             // lets set candidate list and keypad type to the engine.
             mActiveModeHandler->actionHandler(HbInputModeHandler::HbInputModeActionSetCandidateList);
             mActiveModeHandler->actionHandler(HbInputModeHandler::HbInputModeActionSetKeypad);
@@ -558,7 +600,13 @@
             }
             if(mNumericModeHandler) {
                 mNumericModeHandler->setKeymap(mKeymap);
-            }
+            } 
+			if(mBasic12keyThaiHandler) {
+				mBasic12keyThaiHandler->setKeymap(mKeymap);
+			}
+			if (mPrediction12keyThaiHandler) {
+				mPrediction12keyThaiHandler->setKeymap(mKeymap);
+			}
         }
     }
 }
@@ -600,18 +648,55 @@
             displaySpecialCharacterTable(this);
         }
     } else if ( keyCode == Qt::Key_Shift) {
-           HbInputState inputState = this->inputState();
-        if (inputState.inputMode() != HbInputModeNumeric ) {
-            inputState.setInputMode( HbInputModeNumeric );
-            this->activateState(inputState);
+        HbInputState nextState = inputState();
+        if (nextState.inputMode() != HbInputModeNumeric ) {
+            nextState.setInputMode( HbInputModeNumeric );
         } else {
-            HbInputState rootState;
-            editorRootState(rootState);
-            activateState(rootState);
+            editorRootState(nextState);
         }
+        activateState(nextState);
         switchToAlphaMode();
     }
 }
+/*!
+Returns previous character from editor
+*/
+uint HbVirtual12Key::previousChar()
+{
+	if(focusObject()) {
+		int cursorPosition = focusObject()->editorCursorPosition();
+		if(cursorPosition) {
+			QString editorText = focusObject()->editorSurroundingText();
+			return((editorText.at(cursorPosition-1)).unicode());
+		}
+	}
+	return 0;
+}
+/*!
+Shows the Thai specific special characters 
+*/
+void HbVirtual12Key::showThaiSpecialCharacters(uint buttonId)
+{
+	uint prevChar = previousChar();
+	int screenWidth = 0;
+	int screenHeight = 0;
+	//Get the sceen size from device profile
+	if(mCurrentKeypad) {
+		screenWidth = HbDeviceProfile::profile(mCurrentKeypad).logicalSize().width();
+		screenHeight = HbDeviceProfile::profile(mCurrentKeypad).logicalSize().height();
+	}
+	//Create Thai special popup if not created 
+	if(!mThaiSpecialChar) {
+		mThaiSpecialChar = new HbInputThaiSpecialPopup(buttonId,prevChar,0);
+		connect(mThaiSpecialChar, SIGNAL(chrSelected(QString)), this, SLOT(thaiSctCharacterSelected(QString)));
+	}
+	//Set Geometry and Layout for popup 
+	if (mThaiSpecialChar) {
+		mThaiSpecialChar->setGeometry(QRectF(0,screenHeight/2,screenWidth,screenHeight/2));
+		mThaiSpecialChar->setPopupLayout(mKeymap,prevChar,buttonId,screenWidth,screenHeight/2);
+		mThaiSpecialChar->show();
+	}
+}
 
 /*!
 Shows the special character table. Re-implements the same method from HbInputMethod.
@@ -653,8 +738,11 @@
     HbInputMethod::orientationAboutToChange();
     if (isActiveMethod()) {
         mOrientationAboutToChange = true;
+        mPredictionModeHandler->actionHandler(HbInputModeHandler::HbInputModeActionCloseSpellQuery);
+        // We need to commit the inline word before orientation change.
+        mActiveModeHandler->actionHandler(HbInputModeHandler::HbInputModeActionCommit);
+        closeKeypad();
     }
-    closeKeypad();
 }
 
 /*!
@@ -728,6 +816,12 @@
      mActiveModeHandler->smileySelected(smiley);
 }
 
+void HbVirtual12Key::thaiSctCharacterSelected(QString sctChar)
+{
+     mActiveModeHandler->sctCharacterSelected(sctChar);
+}
+
+
 void HbVirtual12Key::selectSpecialCharacterTableMode()
 {
     if (mItutKeypad) {
@@ -782,7 +876,7 @@
 bool HbVirtual12Key::usePrediction() const
 {
     HbInputFocusObject *fo = focusObject();
-    if (HbInputSettingProxy::instance()->predictiveInputStatus() &&
+    if (HbInputSettingProxy::instance()->predictiveInputStatus(HbKeyboardSetting12key) &&
         fo &&
         fo->editorInterface().isPredictionAllowed() &&
         mPredictionModeHandler->isActive() &&