src/hbplugins/inputmethods/common/hbinputmodehandler.cpp
changeset 1 f7ac710697a9
parent 0 16d8024aca5e
child 2 06ff229162e9
equal deleted inserted replaced
0:16d8024aca5e 1:f7ac710697a9
   174 */
   174 */
   175 bool HbInputModeHandler::filterEvent(const QEvent * event)
   175 bool HbInputModeHandler::filterEvent(const QEvent * event)
   176 {
   176 {
   177     if (event) {
   177     if (event) {
   178         if (event->type() == QEvent::KeyPress || event->type() == QEvent::KeyRelease) {
   178         if (event->type() == QEvent::KeyPress || event->type() == QEvent::KeyRelease) {
   179             const QKeyEvent *keyEvent = 0;
   179             const QKeyEvent *keyEvent = static_cast<const QKeyEvent *>(event);
   180             keyEvent = static_cast<const QKeyEvent *>(event);
   180             return filterEvent(keyEvent);
   181             if (keyEvent) {
   181 		}
   182                 return filterEvent(keyEvent);
   182 	}
   183             }
       
   184         }
       
   185     }
       
   186 
       
   187     return false;
   183     return false;
   188 }
   184 }
   189 
   185 
   190 /*!
   186 /*!
   191  This function handles the most common key events.
   187  This function handles the most common key events.
   278  this function commits the first number found in the key.
   274  this function commits the first number found in the key.
   279 */
   275 */
   280 void HbInputModeHandler::commitFirstMappedNumber(int key)
   276 void HbInputModeHandler::commitFirstMappedNumber(int key)
   281 {
   277 {
   282     Q_D(HbInputModeHandler);
   278     Q_D(HbInputModeHandler);
       
   279 
       
   280     HbInputLanguage language = d->mInputMethod->inputState().language();
   283     // This is long key press number shortcut functionality.
   281     // This is long key press number shortcut functionality.
   284     if (!d->mKeymap) {
   282     if (!d->mKeymap) {
   285         d->mKeymap = HbKeymapFactory::instance()->keymap(d->mInputMethod->inputState().language());
   283         d->mKeymap = HbKeymapFactory::instance()->keymap(language);
   286     }
   284     }
   287     QChar numChr = HbInputUtils::findFirstNumberCharacterBoundToKey(d->mKeymap->keyForKeycode(d->mInputMethod->inputState().keyboard(), key),
   285 	bool isNumericEditor = d->mInputMethod->focusObject()->editorInterface().isNumericEditor();
   288                                                                     d->mKeymap->language());
   286 	HbInputDigitType digitType = HbInputUtils::inputDigitType(language);
       
   287 	if (isNumericEditor) {
       
   288         QLocale::Language systemLanguage = QLocale::system().language();		 
       
   289 		if (language.language() != systemLanguage) {
       
   290             digitType = HbDigitTypeLatin;
       
   291 	 	}
       
   292 	}	
       
   293     QChar numChr = HbInputUtils::findFirstNumberCharacterBoundToKey(
       
   294 		d->mKeymap->keyForKeycode(d->mInputMethod->inputState().keyboard(), key),language, digitType);
   289 	// when a number is to be entered, it should commit 
   295 	// when a number is to be entered, it should commit 
   290     // the previous string and then append the number to the string
   296     // the previous string and then append the number to the string
   291     if (numChr != 0) {
   297     if (numChr != 0) {
   292         commitAndAppendString(numChr);
   298         commitAndAppendString(numChr);
   293     }
   299     }
   303     HbModifiers modifiers = 0;
   309     HbModifiers modifiers = 0;
   304     int textCase = d->mInputMethod->inputState().textCase();
   310     int textCase = d->mInputMethod->inputState().textCase();
   305     if (textCase == HbTextCaseUpper || textCase == HbTextCaseAutomatic) {
   311     if (textCase == HbTextCaseUpper || textCase == HbTextCaseAutomatic) {
   306         modifiers |= HbModifierShiftPressed;
   312         modifiers |= HbModifierShiftPressed;
   307     }
   313     }
       
   314     HbInputLanguage language = d->mInputMethod->inputState().language();
       
   315 	
   308     if (!d->mKeymap) {
   316     if (!d->mKeymap) {
   309         d->mKeymap = HbKeymapFactory::instance()->keymap(d->mInputMethod->inputState().language());
   317         d->mKeymap = HbKeymapFactory::instance()->keymap(language);
   310     }
   318     }
   311     const HbMappedKey* mappedKey = d->mKeymap->keyForKeycode(d->mInputMethod->inputState().keyboard(), key);
   319     const HbMappedKey* mappedKey = d->mKeymap->keyForKeycode(d->mInputMethod->inputState().keyboard(), key);
   312     if (!mappedKey) {
   320     if (!mappedKey) {
   313         return 0;
   321         return 0;
   314     }
   322     }
       
   323     QString chars = mappedKey->characters(modifiers);
       
   324 	// check whether current input language supports native digits. if yes, replace latin digits with native digits    
       
   325     for (int i = 0; i < chars.length(); i++) {
       
   326         if (chars.at(i) >= '0' && chars.at(i) <= '9') {
       
   327             chars = chars.replace(chars.at(i), HbInputUtils::findFirstNumberCharacterBoundToKey(mappedKey,
       
   328 				language, HbInputUtils::inputDigitType(language)));
       
   329         }		
       
   330     }		
   315     // We need to see which of the characters in keyData are allowed to the editor.
   331     // We need to see which of the characters in keyData are allowed to the editor.
   316     // this looks like expensive operation, need to find out a better way/place to do it.
   332     // this looks like expensive operation, need to find out a better way/place to do it.
   317     QString allowedChars;
   333     QString allowedChars = chars;
   318     HbInputFocusObject *focusedObject = d->mInputMethod->focusObject();
   334     HbInputFocusObject *focusedObject = d->mInputMethod->focusObject();
   319     if(focusedObject) {
   335     if(focusedObject) {
   320         focusedObject->filterStringWithEditorFilter(mappedKey->characters(modifiers),allowedChars);
   336         focusedObject->filterStringWithEditorFilter(chars,allowedChars);
   321     } else {
   337     } 
   322         // we should not come here. Just for saftey.
       
   323          allowedChars =  mappedKey->characters(modifiers);
       
   324     }
       
   325     QChar character = 0;
   338     QChar character = 0;
   326     if (!allowedChars.isNull()) {
   339     if (!allowedChars.isNull()) {
   327         if (index >= allowedChars.length() || index < 0) {
   340         if (index >= allowedChars.length() || index < 0) {
   328             index = 0;
   341             index = 0;
   329         }
   342         }
   423 void HbInputModeHandler::characterPreviewAvailable(bool available)
   436 void HbInputModeHandler::characterPreviewAvailable(bool available)
   424 {
   437 {
   425     Q_UNUSED(available);
   438     Q_UNUSED(available);
   426 }
   439 }
   427 
   440 
       
   441 /*!
       
   442 Toggles prediction after doing a check if the editor allows it.
       
   443 */
       
   444 void HbInputModeHandler::togglePrediction()
       
   445 {
       
   446     Q_D(HbInputModeHandler);
       
   447     int currentStatus = HbInputSettingProxy::instance()->predictiveInputStatus();
       
   448     HbInputFocusObject* focusedObject = 0;
       
   449     focusedObject = d->mInputMethod->focusObject();
       
   450     bool isPredictionAllowed = focusedObject->editorInterface().isPredictionAllowed();
       
   451     if (currentStatus) {
       
   452         HbInputSettingProxy::instance()->setPredictiveInputStatus(0);
       
   453     } else if (isPredictionAllowed) {
       
   454         HbInputSettingProxy::instance()->setPredictiveInputStatus(1);
       
   455     }
       
   456 }
       
   457 
   428 #include "moc_hbinputmodehandler.cpp"
   458 #include "moc_hbinputmodehandler.cpp"
   429 // EOF
   459 // EOF