src/hbinput/inputwidgets/hbinputsctkeyboard.cpp
changeset 21 4633027730f5
parent 7 923ff622b8b9
child 23 e6ad4ef83b23
--- a/src/hbinput/inputwidgets/hbinputsctkeyboard.cpp	Tue Jul 06 14:36:53 2010 +0300
+++ b/src/hbinput/inputwidgets/hbinputsctkeyboard.cpp	Wed Aug 18 10:05:37 2010 +0300
@@ -158,6 +158,8 @@
 
     if (HbInputSettingProxy::instance()->activeKeyboard() & HbQwertyKeyboardMask) {
         mType = HbKeyboardSctLandscape;
+    } else {
+        mType = HbKeyboardSctPortrait;
     }
 
     HbInputButtonGroup *buttonGroup = static_cast<HbInputButtonGroup *>(q->contentItem());
@@ -185,13 +187,13 @@
                 item->setSize(QSize(2, 1));
                 ++key;
             } else if (keyCode(i) == HbInputButton::ButtonKeyCodeDelete &&
-                       mType == HbKeyboardSctPortrait) {
+                       (mType == HbKeyboardSctPortrait || mType == HbKeyboardSctEmail || mType == HbKeyboardSctUrl )) {
                 // Portrait SCT has different delete icon from the default one
                 item->setIcon(HbIcon(HbInputButtonIconDelete2), HbInputButton::ButtonIconIndexPrimary);
             } else if (keyCode(i) == HbInputButton::ButtonKeyCodeAlphabet) {
                 // Button that is used to return to normal keypad should be shown as latched
                 item->setState(HbInputButton::ButtonStateLatched);
-                if (mType == HbKeyboardSctPortrait) {
+				if (mType == HbKeyboardSctPortrait || mType == HbKeyboardSctEmail || mType == HbKeyboardSctUrl ) {
                     // Portrait SCT has different symbol icon from the default one
                     item->setIcon(HbIcon(HbInputButtonIconSymbol2), HbInputButton::ButtonIconIndexPrimary);
                 }
@@ -212,28 +214,31 @@
 
 int HbSctKeyboardPrivate::keyCode(int buttonId)
 {
-    if (mType == HbKeyboardSctPortrait) {
-        return HbPortraitButtonKeyCodeTable[buttonId];
+    if (mType == HbKeyboardSctLandscape) {
+        return HbLandscapeButtonKeyCodeTable[buttonId];
     } else {
-        return HbLandscapeButtonKeyCodeTable[buttonId];
+        return HbPortraitButtonKeyCodeTable[buttonId];        
     }
 }
 
+
 void HbSctKeyboardPrivate::applyEditorConstraints()
 {
     Q_Q(HbSctKeyboard);
+    HbInputFocusObject *focusedObject = mOwner->focusObject();
+    HbInputButtonGroup *buttonGroup = static_cast<HbInputButtonGroup *>(q->contentItem());
+    applyEditorConstraints(focusedObject, buttonGroup);
+}
 
-    HbInputFocusObject *focusedObject = mOwner->focusObject();
+void HbSctKeyboardPrivate::applyEditorConstraints(HbInputFocusObject *focusedObject, HbInputButtonGroup *buttonGroup)
+{
     if (!focusedObject) {
         return;
     }
-
-    HbInputButtonGroup *buttonGroup = static_cast<HbInputButtonGroup *>(q->contentItem());
     if (buttonGroup) {
-        QList<HbInputButton *> buttons = buttonGroup->buttons();
+        QList<HbInputButton*> buttons = buttonGroup->buttons();
         for (int i = 0; i < buttons.count(); ++i) {
             HbInputButton *item = buttons.at(i);
-
             HbInputButton::HbInputButtonState state = item->state();
             if (keyCode(i) == HbInputButton::ButtonKeyCodeCharacter) {
                 QString data = item->text(HbInputButton::ButtonTextIndexPrimary);
@@ -262,6 +267,7 @@
             }
             item->setState(state);
         }
+
         buttonGroup->setButtons(buttons);
     }
 }
@@ -269,20 +275,32 @@
 void HbSctKeyboardPrivate::updateKeyCodes()
 {
     Q_Q(HbSctKeyboard);
+    HbInputFocusObject *focusedObject = mOwner->focusObject();
+    if (!focusedObject) {
+        return;
+    }
 
+    if (HbInputSettingProxy::instance()->activeKeyboard() & HbQwertyKeyboardMask){
+        mType = HbKeyboardSctLandscape;
+    } else if (focusedObject && focusedObject->editorInterface().editorClass() == HbInputEditorClassEmail) {
+        mType = HbKeyboardSctEmail;
+    } else if (focusedObject && focusedObject->editorInterface().editorClass() == HbInputEditorClassUrl) {
+        mType = HbKeyboardSctUrl;
+    } else {
+        mType = HbKeyboardSctPortrait;
+    }
+    
     mPages = 0;
     const HbKeyboardMap *keyboardMap = mKeymap->keyboard(q->keyboardType());
     if (keyboardMap) {
-        mPages = (int)ceil((float)(keyboardMap->keys.count() / mCharacterButtons));
+        mPages = (int)ceil((float)countActiveKeys() / mCharacterButtons);
     }
-
-    if (mPages > 1) {
-        mFlickAnimation = true;
-    }
-
+    
+    mFlickAnimation = mPages > 1;
+    
     HbInputButtonGroup *buttonGroup = static_cast<HbInputButtonGroup *>(q->contentItem());
     if (buttonGroup) {
-        int key = mActivePage * mCharacterButtons;
+        int key = keyAtIndex(mActivePage * mCharacterButtons);
         QList<HbInputButton *> buttons = buttonGroup->buttons();
         for (int i = 0; i < buttons.count(); ++i) {
             if (keyCode(i) == HbInputButton::ButtonKeyCodeCharacter) {
@@ -290,12 +308,16 @@
 
                 if (keyboardMap && key < keyboardMap->keys.count()) {
                     // Replace space and enter markers with correct keycodes
-                    if (keyboardMap->keys.at(key)->keycode.unicode() == HbSctSpaceMarker) {
-                        item->setKeyCode(HbInputButton::ButtonKeyCodeSpace);
-                    } else if (keyboardMap->keys.at(key)->keycode.unicode() == HbSctEnterMarker) {
-                        item->setKeyCode(HbInputButton::ButtonKeyCodeEnter);
+                    if (focusedObject->characterAllowedInEditor(keyboardMap->keys.at(key)->characters(HbModifierNone).at(0)) || mType == HbKeyboardSctLandscape){
+	                    if (keyboardMap->keys.at(key)->keycode.unicode() == HbSctSpaceMarker) {
+    	                    item->setKeyCode(HbInputButton::ButtonKeyCodeSpace);
+        	            } else if (keyboardMap->keys.at(key)->keycode.unicode() == HbSctEnterMarker) {
+            	            item->setKeyCode(HbInputButton::ButtonKeyCodeEnter);
+                	    } else {
+                    	    item->setKeyCode(keyboardMap->keys.at(key)->keycode.unicode());
+                    	}
                     } else {
-                        item->setKeyCode(keyboardMap->keys.at(key)->keycode.unicode());
+                        i--;
                     }
                 } else {
                     item->setKeyCode(-1);
@@ -304,31 +326,40 @@
             }
         }
     }
+    applyEditorConstraints();           
 }
 
 void HbSctKeyboardPrivate::updateButtons()
 {
     Q_Q(HbSctKeyboard);
 
+    HbInputFocusObject *focusedObject = mOwner->focusObject();
+    if (!focusedObject) {
+        return;
+    }
+
     HbInputButtonGroup *buttonGroup = static_cast<HbInputButtonGroup *>(q->contentItem());
     if (buttonGroup) {
-        int key = mActivePage * mCharacterButtons;
+        int key = keyAtIndex(mActivePage * mCharacterButtons);
         QList<HbInputButton *> buttons = buttonGroup->buttons();
         for (int i = 0; i < buttons.count(); ++i) {
             if (keyCode(i) == HbInputButton::ButtonKeyCodeCharacter) {
                 HbInputButton *item = buttons.at(i);
-
                 const HbKeyboardMap *keyboardMap = mKeymap->keyboard(q->keyboardType());
                 if (keyboardMap && key < keyboardMap->keys.count() && keyboardMap->keys.at(key)->characters(HbModifierNone) != QString("")) {
-                    QString keydata = keyboardMap->keys.at(key)->characters(HbModifierNone);
-                    // Replace space and enter markers with correct glyphs.
-                    // These only exist in symbian fonts, so if we are not using symbian, use blank.
-                    if (keydata.at(0) == HbSctSpaceMarker) {
-                        item->setText(HbSctSpaceGlyph, HbInputButton::ButtonTextIndexPrimary);
-                    } else if (keydata.at(0) == HbSctEnterMarker) {
-                        item->setText(HbSctEnterGlyph, HbInputButton::ButtonTextIndexPrimary);
+                    if (focusedObject->characterAllowedInEditor(keyboardMap->keys.at(key)->characters(HbModifierNone).at(0)) || mType == HbKeyboardSctLandscape){
+                        QString keydata = keyboardMap->keys.at(key)->characters(HbModifierNone);
+                        // Replace space and enter markers with correct glyphs.
+                        // These only exist in symbian fonts, so if we are not using symbian, use blank.
+                        if (keydata.at(0) == HbSctSpaceMarker) {
+                            item->setText(HbSctSpaceGlyph, HbInputButton::ButtonTextIndexPrimary);
+                        } else if (keydata.at(0) == HbSctEnterMarker) {
+                            item->setText(HbSctEnterGlyph, HbInputButton::ButtonTextIndexPrimary);
+                        } else {
+                            item->setText(keydata.at(0), HbInputButton::ButtonTextIndexPrimary);
+                        }
                     } else {
-                        item->setText(keydata.at(0), HbInputButton::ButtonTextIndexPrimary);
+                        i--;
                     }
                 } else {
                     item->setText("", HbInputButton::ButtonTextIndexPrimary);
@@ -344,6 +375,54 @@
     }
 }
 
+int HbSctKeyboardPrivate::keyAtIndex(int index)
+{
+    Q_Q(HbSctKeyboard);
+    
+    const HbKeyboardMap *keyboardMap = mKeymap->keyboard(q->keyboardType());
+    if (mType == HbKeyboardSctLandscape){
+        return index;
+    }
+    int totalKeys=0;
+    HbInputFocusObject *focusedObject = mOwner->focusObject();
+    HbInputButtonGroup *buttonGroup = static_cast<HbInputButtonGroup*>(q->contentItem());    
+    if (buttonGroup) {
+        if (keyboardMap && totalKeys < keyboardMap->keys.count()) {
+            while (index){
+                if (focusedObject->characterAllowedInEditor(keyboardMap->keys.at(totalKeys)->characters(HbModifierNone).at(0))){
+                    index--;		            
+                }
+                totalKeys++;
+            }            
+        }
+    }
+    return totalKeys;
+}
+
+int HbSctKeyboardPrivate::countActiveKeys()
+{
+    Q_Q(HbSctKeyboard);
+
+    const HbKeyboardMap *keyboardMap = mKeymap->keyboard(q->keyboardType());
+    if (mType == HbKeyboardSctLandscape){
+        return keyboardMap->keys.count();
+    }
+
+    int totalKeys=0;
+    HbInputFocusObject *focusedObject = mOwner->focusObject();
+    HbInputButtonGroup *buttonGroup = static_cast<HbInputButtonGroup*>(q->contentItem());
+    if (buttonGroup) {
+        if (keyboardMap && totalKeys < keyboardMap->keys.count()) {
+            foreach(HbMappedKey *key, keyboardMap->keys){  
+                if (focusedObject->characterAllowedInEditor(key->characters(HbModifierNone).at(0))){
+                    totalKeys++;
+                }
+            }    
+        }
+    }
+    return totalKeys;
+}
+
 /*!
 Constructs the object. owner is the owning input method implementation. Keymap
 is key mapping data to be used to display button texts. Key mapping data can be
@@ -362,12 +441,10 @@
 
     const HbKeyboardMap *keyboardMap = keymap->keyboard(keyboardType());
     if (keyboardMap) {
-        d->mPages = (int)ceil((float)(keyboardMap->keys.count() / d->mCharacterButtons));
+        d->mPages = (int)ceil((float)d->countActiveKeys() / d->mCharacterButtons);
     }
 
-    if (d->mPages > 1) {
-        d->mFlickAnimation = true;
-    }
+    d->mFlickAnimation = d->mPages > 1;
 
     if (d->mType == HbKeyboardSctLandscape) {
         connect(HbInputSettingProxy::instance(), SIGNAL(characterPreviewStateForQwertyChanged(bool)), this, SLOT(updateButtonPreviewStatus(bool)));
@@ -394,12 +471,11 @@
 
     const HbKeyboardMap *keyboardMap = keymap->keyboard(keyboardType());
     if (keyboardMap) {
-        d->mPages = (int)ceil((float)(keyboardMap->keys.count() / d->mCharacterButtons));
+        d->mPages = (int)ceil((float)d->countActiveKeys() / d->mCharacterButtons);
     }
 
-    if (d->mPages > 1) {
-        d->mFlickAnimation = true;
-    }
+    d->mFlickAnimation = d->mPages > 1;
+    
 
     if (d->mType == HbKeyboardSctLandscape) {
         connect(HbInputSettingProxy::instance(), SIGNAL(characterPreviewStateForQwertyChanged(bool)), this, SLOT(updateButtonPreviewStatus(bool)));
@@ -420,7 +496,6 @@
 HbKeyboardType HbSctKeyboard::keyboardType() const
 {
     Q_D(const HbSctKeyboard);
-
     return d->mType;
 }
 
@@ -476,8 +551,7 @@
 {
     Q_D(HbSctKeyboard);
 
-    if (flickDirection == HbInputVkbWidget::HbFlickDirectionRight ||
-        flickDirection == HbInputVkbWidget::HbFlickDirectionLeft) {
+    if (d->mFlickAnimation) {
         int direction = 1;
         if (flickDirection == HbInputVkbWidget::HbFlickDirectionRight) {
             direction = -1;
@@ -487,9 +561,8 @@
         if (d->mActivePage < 0) {
             d->mActivePage = d->mPages - 1;
         }
+        d->updateButtons();
         d->updateKeyCodes();
-        d->updateButtons();
-        d->applyEditorConstraints();
     }
 }