src/hbinput/inputwidgets/hbinputsctkeyboard.cpp
changeset 34 ed14f46c0e55
parent 7 923ff622b8b9
equal deleted inserted replaced
31:7516d6d86cf5 34:ed14f46c0e55
    32 #include <hbinputmethod.h>
    32 #include <hbinputmethod.h>
    33 #include <hbinputkeymap.h>
    33 #include <hbinputkeymap.h>
    34 #include <hbinpututils.h>
    34 #include <hbinpututils.h>
    35 #include <hbframedrawer.h>
    35 #include <hbframedrawer.h>
    36 #include <hbinputsettingproxy.h>
    36 #include <hbinputsettingproxy.h>
       
    37 #include <hbmainwindow.h>
       
    38 #include <hbwidgetfeedback.h>
    37 
    39 
    38 #include "hbinputbuttongroup.h"
    40 #include "hbinputbuttongroup.h"
    39 #include "hbinputbutton.h"
    41 #include "hbinputbutton.h"
    40 
    42 
    41 const qreal HbPortraitKeyboardHeightInUnits = 45.9;
    43 const qreal HbPortraitKeyboardHeightInUnits = 45.9;
    42 const qreal HbPortraitKeyboardWidthInUnits = 53.8;
    44 const qreal HbPortraitKeyboardWidthInUnits = 53.8;
    43 const qreal HbLandscapeKeyboardHeightInUnits = 33.7;
    45 const qreal HbLandscapeKeyboardHeightInUnits = 27.0;
    44 const qreal HbLandscapeKeyboardWidthInUnits = 95.5;
    46 const qreal HbLandscapeKeyboardWidthInUnits = 95.5;
    45 
    47 
    46 const int HbSctPortraitNumberOfRows = 5;
    48 const int HbSctPortraitNumberOfRows = 5;
    47 const int HbSctPortraitNumberOfColumns = 5;
    49 const int HbSctPortraitNumberOfColumns = 5;
    48 const int HbPortraitButtonKeyCodeTable[HbSctPortraitNumberOfRows *HbSctPortraitNumberOfColumns] = {
    50 const int HbPortraitButtonCount = HbSctPortraitNumberOfRows * HbSctPortraitNumberOfColumns;
       
    51 const int HbPortraitButtonKeyCodeTable[HbPortraitButtonCount] = {
    49     HbInputButton::ButtonKeyCodeCharacter,
    52     HbInputButton::ButtonKeyCodeCharacter,
    50     HbInputButton::ButtonKeyCodeCharacter,
    53     HbInputButton::ButtonKeyCodeCharacter,
    51     HbInputButton::ButtonKeyCodeCharacter,
    54     HbInputButton::ButtonKeyCodeCharacter,
    52     HbInputButton::ButtonKeyCodeCharacter,
    55     HbInputButton::ButtonKeyCodeCharacter,
    53     HbInputButton::ButtonKeyCodeDelete,
    56     HbInputButton::ButtonKeyCodeDelete,
    73     HbInputButton::ButtonKeyCodeCustom
    76     HbInputButton::ButtonKeyCodeCustom
    74 };
    77 };
    75 
    78 
    76 const int HbSctLandscapeNumberOfRows = 4;
    79 const int HbSctLandscapeNumberOfRows = 4;
    77 const int HbSctLandscapeNumberOfColumns = 10;
    80 const int HbSctLandscapeNumberOfColumns = 10;
    78 const int HbLandscapeButtonKeyCodeTable[HbSctLandscapeNumberOfRows *HbSctLandscapeNumberOfColumns] = {
    81 const int HbLandscapeButtonCount = HbSctLandscapeNumberOfRows * HbSctLandscapeNumberOfColumns - 1;
       
    82 const int HbLandscapeButtonKeyCodeTable[HbLandscapeButtonCount] = {
    79     HbInputButton::ButtonKeyCodeCharacter,
    83     HbInputButton::ButtonKeyCodeCharacter,
    80     HbInputButton::ButtonKeyCodeCharacter,
    84     HbInputButton::ButtonKeyCodeCharacter,
    81     HbInputButton::ButtonKeyCodeCharacter,
    85     HbInputButton::ButtonKeyCodeCharacter,
    82     HbInputButton::ButtonKeyCodeCharacter,
    86     HbInputButton::ButtonKeyCodeCharacter,
    83     HbInputButton::ButtonKeyCodeCharacter,
    87     HbInputButton::ButtonKeyCodeCharacter,
   127 const QChar HbSctSpaceGlyph = ' ';
   131 const QChar HbSctSpaceGlyph = ' ';
   128 const QChar HbSctEnterGlyph = ' ';
   132 const QChar HbSctEnterGlyph = ' ';
   129 #endif
   133 #endif
   130 
   134 
   131 /*!
   135 /*!
   132 @proto
   136 @stable
   133 @hbinput
   137 @hbinput
   134 \class HbSctKeyboard
   138 \class HbSctKeyboard
   135 \brief Touch keyboard for special characters
   139 \brief The HbSctKeyboard class provides a touch keyboard for special characters.
   136 
   140 
   137 Implements special character keyboard. The keyboard knows how to set up button titles according to
   141 The class implements a special character keyboard. The keyboard supports setting up
   138 given key map data object and it also supports editor specific custom buttons.
   142 button titles according to a given keymap data object, and it also supports
       
   143 editor-specific custom buttons.
   139 
   144 
   140 \sa HbInputVkbWidget
   145 \sa HbInputVkbWidget
   141 */
   146 */
   142 
   147 
   143 HbSctKeyboardPrivate::HbSctKeyboardPrivate()
   148 HbSctKeyboardPrivate::HbSctKeyboardPrivate()
   154 {
   159 {
   155     Q_Q(HbSctKeyboard);
   160     Q_Q(HbSctKeyboard);
   156 
   161 
   157     HbInputVkbWidgetPrivate::init();
   162     HbInputVkbWidgetPrivate::init();
   158 
   163 
   159     if (HbInputSettingProxy::instance()->activeKeyboard() & HbQwertyKeyboardMask) {
   164     Qt::Orientation orientation = Qt::Horizontal;
       
   165     if (q->mainWindow()) {
       
   166         orientation = q->mainWindow()->orientation();
       
   167     }
       
   168 
       
   169     if (HbInputSettingProxy::instance()->activeKeyboard(orientation) & HbQwertyKeyboardMask) {
   160         mType = HbKeyboardSctLandscape;
   170         mType = HbKeyboardSctLandscape;
       
   171     } else {
       
   172         mType = HbKeyboardSctPortrait;
   161     }
   173     }
   162 
   174 
   163     HbInputButtonGroup *buttonGroup = static_cast<HbInputButtonGroup *>(q->contentItem());
   175     HbInputButtonGroup *buttonGroup = static_cast<HbInputButtonGroup *>(q->contentItem());
   164     if (buttonGroup) {
   176     if (buttonGroup) {
   165         mColumns = HbSctPortraitNumberOfColumns;
   177         mColumns = HbSctPortraitNumberOfColumns;
   166         mRows = HbSctPortraitNumberOfRows;
   178         mRows = HbSctPortraitNumberOfRows;
       
   179         int count = HbPortraitButtonCount;
   167         if (mType == HbKeyboardSctLandscape) {
   180         if (mType == HbKeyboardSctLandscape) {
   168             mColumns = HbSctLandscapeNumberOfColumns;
   181             mColumns = HbSctLandscapeNumberOfColumns;
   169             mRows = HbSctLandscapeNumberOfRows;
   182             mRows = HbSctLandscapeNumberOfRows;
       
   183             count = HbLandscapeButtonCount;
   170 
   184 
   171             buttonGroup->setButtonPreviewEnabled(HbInputSettingProxy::instance()->isCharacterPreviewForQwertyEnabled());
   185             buttonGroup->setButtonPreviewEnabled(HbInputSettingProxy::instance()->isCharacterPreviewForQwertyEnabled());
   172         }
   186         }
   173 
   187 
   174         buttonGroup->setGridSize(QSize(mColumns, mRows));
   188         buttonGroup->setGridSize(QSize(mColumns, mRows));
   175 
   189 
   176         int key = 0;
   190         int key = 0;
   177         QList<HbInputButton *> buttons;
   191         QList<HbInputButton *> buttons;
   178         for (int i = 0; i < mColumns * mRows; ++i) {
   192         for (int i = 0; i < count; ++i) {
   179             HbInputButton *item = new HbInputButton(keyCode(i), QPoint(key % mColumns, key / mColumns));
   193             HbInputButton *item = new HbInputButton(keyCode(i), QPoint(key % mColumns, key / mColumns));
   180             buttons.append(item);
   194             buttons.append(item);
   181 
   195 
   182             if (keyCode(i) == HbInputButton::ButtonKeyCodeCharacter) {
   196             if (keyCode(i) == HbInputButton::ButtonKeyCodeCharacter) {
   183                 ++mCharacterButtons;
   197                 ++mCharacterButtons;
   184             } else if (keyCode(i) == HbInputButton::ButtonKeyCodeSpace) {
   198             } else if (keyCode(i) == HbInputButton::ButtonKeyCodeSpace) {
   185                 item->setSize(QSize(2, 1));
   199                 item->setSize(QSize(2, 1));
   186                 ++key;
   200                 ++key;
   187             } else if (keyCode(i) == HbInputButton::ButtonKeyCodeDelete &&
   201             } else if (keyCode(i) == HbInputButton::ButtonKeyCodeDelete &&
   188                        mType == HbKeyboardSctPortrait) {
   202                        (mType == HbKeyboardSctPortrait || mType == HbKeyboardSctEmail || mType == HbKeyboardSctUrl )) {
   189                 // Portrait SCT has different delete icon from the default one
   203                 // Portrait SCT has different delete icon from the default one
   190                 item->setIcon(HbIcon(HbInputButtonIconDelete2), HbInputButton::ButtonIconIndexPrimary);
   204                 item->setIcon(HbIcon(HbInputButtonIconDelete2), HbInputButton::ButtonIconIndexPrimary);
   191             } else if (keyCode(i) == HbInputButton::ButtonKeyCodeAlphabet) {
   205             } else if (keyCode(i) == HbInputButton::ButtonKeyCodeAlphabet) {
   192                 // Button that is used to return to normal keypad should be shown as latched
   206                 // Button that is used to return to normal keypad should be shown as latched
   193                 item->setState(HbInputButton::ButtonStateLatched);
   207                 item->setState(HbInputButton::ButtonStateLatched);
   194                 if (mType == HbKeyboardSctPortrait) {
   208                 if (mType == HbKeyboardSctPortrait || mType == HbKeyboardSctEmail || mType == HbKeyboardSctUrl ) {
   195                     // Portrait SCT has different symbol icon from the default one
   209                     // Portrait SCT has different symbol icon from the default one
   196                     item->setIcon(HbIcon(HbInputButtonIconSymbol2), HbInputButton::ButtonIconIndexPrimary);
   210                     item->setIcon(HbIcon(HbInputButtonIconSymbol2), HbInputButton::ButtonIconIndexPrimary);
   197                 }
   211                 }
   198             }
   212             }
   199             ++key;
   213             ++key;
   210     QObject::connect(q, SIGNAL(flickEvent(HbInputVkbWidget::HbFlickDirection)), buttonGroup, SLOT(cancelButtonPress()));
   224     QObject::connect(q, SIGNAL(flickEvent(HbInputVkbWidget::HbFlickDirection)), buttonGroup, SLOT(cancelButtonPress()));
   211 }
   225 }
   212 
   226 
   213 int HbSctKeyboardPrivate::keyCode(int buttonId)
   227 int HbSctKeyboardPrivate::keyCode(int buttonId)
   214 {
   228 {
   215     if (mType == HbKeyboardSctPortrait) {
   229     if (mType == HbKeyboardSctLandscape) {
       
   230         return HbLandscapeButtonKeyCodeTable[buttonId];
       
   231     } else {
   216         return HbPortraitButtonKeyCodeTable[buttonId];
   232         return HbPortraitButtonKeyCodeTable[buttonId];
   217     } else {
   233     }
   218         return HbLandscapeButtonKeyCodeTable[buttonId];
   234 }
   219     }
   235 
   220 }
       
   221 
   236 
   222 void HbSctKeyboardPrivate::applyEditorConstraints()
   237 void HbSctKeyboardPrivate::applyEditorConstraints()
   223 {
   238 {
   224     Q_Q(HbSctKeyboard);
   239     Q_Q(HbSctKeyboard);
   225 
       
   226     HbInputFocusObject *focusedObject = mOwner->focusObject();
   240     HbInputFocusObject *focusedObject = mOwner->focusObject();
       
   241     HbInputButtonGroup *buttonGroup = static_cast<HbInputButtonGroup *>(q->contentItem());
       
   242     applyEditorConstraints(focusedObject, buttonGroup);
       
   243 }
       
   244 
       
   245 void HbSctKeyboardPrivate::applyEditorConstraints(HbInputFocusObject *focusedObject, HbInputButtonGroup *buttonGroup)
       
   246 {
   227     if (!focusedObject) {
   247     if (!focusedObject) {
   228         return;
   248         return;
   229     }
   249     }
   230 
       
   231     HbInputButtonGroup *buttonGroup = static_cast<HbInputButtonGroup *>(q->contentItem());
       
   232     if (buttonGroup) {
   250     if (buttonGroup) {
   233         QList<HbInputButton *> buttons = buttonGroup->buttons();
   251         QList<HbInputButton*> buttons = buttonGroup->buttons();
   234         for (int i = 0; i < buttons.count(); ++i) {
   252         for (int i = 0; i < buttons.count(); ++i) {
   235             HbInputButton *item = buttons.at(i);
   253             HbInputButton *item = buttons.at(i);
   236 
       
   237             HbInputButton::HbInputButtonState state = item->state();
   254             HbInputButton::HbInputButtonState state = item->state();
   238             if (keyCode(i) == HbInputButton::ButtonKeyCodeCharacter) {
   255             if (keyCode(i) == HbInputButton::ButtonKeyCodeCharacter) {
   239                 QString data = item->text(HbInputButton::ButtonTextIndexPrimary);
   256                 QString data = item->text(HbInputButton::ButtonTextIndexPrimary);
   240                 if (data.isEmpty() || !focusedObject->characterAllowedInEditor(data.at(0))) {
   257                 if (data.isEmpty() || !focusedObject->characterAllowedInEditor(data.at(0))) {
   241                     state = HbInputButton::ButtonStateDisabled;
   258                     state = HbInputButton::ButtonStateDisabled;
   242                 } else if (item->state() == HbInputButton::ButtonStateDisabled) {
   259                 } else if (item->state() == HbInputButton::ButtonStateDisabled) {
   243                     state = HbInputButton::ButtonStateReleased;
   260                     state = HbInputButton::ButtonStateReleased;
   244                 }
   261                 }
   245             } else if (keyCode(i) == HbInputButton::ButtonKeyCodeSmiley) {
   262             } else if (keyCode(i) == HbInputButton::ButtonKeyCodeSmiley) {
   246                 if (focusedObject->editorInterface().isNumericEditor() ||
   263                 if (focusedObject->editorInterface().isNumericEditor() ||
   247                     !focusedObject->editorInterface().editorClass() == HbInputEditorClassUnknown ||
       
   248                     !isSmileysEnabled()) {
   264                     !isSmileysEnabled()) {
   249                     state = HbInputButton::ButtonStateDisabled;
   265                     state = HbInputButton::ButtonStateDisabled;
   250                 } else if (item->state() == HbInputButton::ButtonStateDisabled) {
   266                 } else if (item->state() == HbInputButton::ButtonStateDisabled) {
   251                     state = HbInputButton::ButtonStateReleased;
   267                     state = HbInputButton::ButtonStateReleased;
   252                 }
   268                 }
   260                     state = HbInputButton::ButtonStateReleased; 
   276                     state = HbInputButton::ButtonStateReleased; 
   261                 }
   277                 }
   262             }
   278             }
   263             item->setState(state);
   279             item->setState(state);
   264         }
   280         }
       
   281 
   265         buttonGroup->setButtons(buttons);
   282         buttonGroup->setButtons(buttons);
   266     }
   283     }
   267 }
   284 }
   268 
   285 
   269 void HbSctKeyboardPrivate::updateKeyCodes()
   286 void HbSctKeyboardPrivate::updateKeyCodes()
   270 {
   287 {
   271     Q_Q(HbSctKeyboard);
   288     Q_Q(HbSctKeyboard);
   272 
   289 
       
   290     HbInputFocusObject *focusedObject = mOwner->focusObject();
       
   291     if (!focusedObject) {
       
   292         return;
       
   293     }
       
   294 
       
   295     Qt::Orientation orientation = Qt::Horizontal;
       
   296     if (q->mainWindow()) {
       
   297         orientation = q->mainWindow()->orientation();
       
   298     }
       
   299 
       
   300     if (HbInputSettingProxy::instance()->activeKeyboard(orientation) & HbQwertyKeyboardMask){
       
   301         mType = HbKeyboardSctLandscape;
       
   302     } else if (focusedObject && focusedObject->editorInterface().editorClass() == HbInputEditorClassEmail &&
       
   303                mKeymap->keyboard(HbKeyboardSctEmail)) {
       
   304         mType = HbKeyboardSctEmail;
       
   305     } else if (focusedObject && focusedObject->editorInterface().editorClass() == HbInputEditorClassUrl &&
       
   306                mKeymap->keyboard(HbKeyboardSctUrl)) {
       
   307         mType = HbKeyboardSctUrl;
       
   308     } else {
       
   309         mType = HbKeyboardSctPortrait;
       
   310     }
       
   311     
   273     mPages = 0;
   312     mPages = 0;
   274     const HbKeyboardMap *keyboardMap = mKeymap->keyboard(q->keyboardType());
   313     const HbKeyboardMap *keyboardMap = mKeymap->keyboard(q->keyboardType());
   275     if (keyboardMap) {
   314     if (keyboardMap) {
   276         mPages = (int)ceil((float)(keyboardMap->keys.count() / mCharacterButtons));
   315         mPages = (int)ceil((float)countActiveKeys() / mCharacterButtons);
   277     }
   316     }
   278 
   317     
   279     if (mPages > 1) {
   318     mFlickAnimation = mPages > 1;
   280         mFlickAnimation = true;
   319     
   281     }
       
   282 
       
   283     HbInputButtonGroup *buttonGroup = static_cast<HbInputButtonGroup *>(q->contentItem());
   320     HbInputButtonGroup *buttonGroup = static_cast<HbInputButtonGroup *>(q->contentItem());
   284     if (buttonGroup) {
   321     if (buttonGroup) {
   285         int key = mActivePage * mCharacterButtons;
   322         int key = keyAtIndex(mActivePage * mCharacterButtons);
   286         QList<HbInputButton *> buttons = buttonGroup->buttons();
   323         QList<HbInputButton *> buttons = buttonGroup->buttons();
   287         for (int i = 0; i < buttons.count(); ++i) {
   324         for (int i = 0; i < buttons.count(); ++i) {
   288             if (keyCode(i) == HbInputButton::ButtonKeyCodeCharacter) {
   325             if (keyCode(i) == HbInputButton::ButtonKeyCodeCharacter) {
   289                 HbInputButton *item = buttons.at(i);
   326                 HbInputButton *item = buttons.at(i);
   290 
   327 
   291                 if (keyboardMap && key < keyboardMap->keys.count()) {
   328                 if (keyboardMap && key < keyboardMap->keys.count()) {
   292                     // Replace space and enter markers with correct keycodes
   329                     // Replace space and enter markers with correct keycodes
   293                     if (keyboardMap->keys.at(key)->keycode.unicode() == HbSctSpaceMarker) {
   330                     if (focusedObject->characterAllowedInEditor(keyboardMap->keys.at(key)->characters(HbModifierNone).at(0)) || mType == HbKeyboardSctLandscape){
   294                         item->setKeyCode(HbInputButton::ButtonKeyCodeSpace);
   331                         if (keyboardMap->keys.at(key)->keycode.unicode() == HbSctSpaceMarker) {
   295                     } else if (keyboardMap->keys.at(key)->keycode.unicode() == HbSctEnterMarker) {
   332                             item->setKeyCode(HbInputButton::ButtonKeyCodeSpace);
   296                         item->setKeyCode(HbInputButton::ButtonKeyCodeEnter);
   333                         } else if (keyboardMap->keys.at(key)->keycode.unicode() == HbSctEnterMarker) {
       
   334                             item->setKeyCode(HbInputButton::ButtonKeyCodeEnter);
       
   335                         } else {
       
   336                             item->setKeyCode(keyboardMap->keys.at(key)->keycode.unicode());
       
   337                         }
   297                     } else {
   338                     } else {
   298                         item->setKeyCode(keyboardMap->keys.at(key)->keycode.unicode());
   339                         i--;
   299                     }
   340                     }
   300                 } else {
   341                 } else {
   301                     item->setKeyCode(-1);
   342                     item->setKeyCode(-1);
   302                 }
   343                 }
   303                 ++key;
   344                 ++key;
   304             }
   345             }
   305         }
   346         }
   306     }
   347     }
       
   348     applyEditorConstraints();           
   307 }
   349 }
   308 
   350 
   309 void HbSctKeyboardPrivate::updateButtons()
   351 void HbSctKeyboardPrivate::updateButtons()
   310 {
   352 {
   311     Q_Q(HbSctKeyboard);
   353     Q_Q(HbSctKeyboard);
       
   354 
       
   355     HbInputFocusObject *focusedObject = mOwner->focusObject();
       
   356     if (!focusedObject) {
       
   357         return;
       
   358     }
   312 
   359 
   313     HbInputButtonGroup *buttonGroup = static_cast<HbInputButtonGroup *>(q->contentItem());
   360     HbInputButtonGroup *buttonGroup = static_cast<HbInputButtonGroup *>(q->contentItem());
   314     if (buttonGroup) {
   361     if (buttonGroup) {
   315         int key = mActivePage * mCharacterButtons;
   362         int key = keyAtIndex(mActivePage * mCharacterButtons);
   316         QList<HbInputButton *> buttons = buttonGroup->buttons();
   363         QList<HbInputButton *> buttons = buttonGroup->buttons();
   317         for (int i = 0; i < buttons.count(); ++i) {
   364         for (int i = 0; i < buttons.count(); ++i) {
   318             if (keyCode(i) == HbInputButton::ButtonKeyCodeCharacter) {
   365             if (keyCode(i) == HbInputButton::ButtonKeyCodeCharacter) {
   319                 HbInputButton *item = buttons.at(i);
   366                 HbInputButton *item = buttons.at(i);
   320 
       
   321                 const HbKeyboardMap *keyboardMap = mKeymap->keyboard(q->keyboardType());
   367                 const HbKeyboardMap *keyboardMap = mKeymap->keyboard(q->keyboardType());
   322                 if (keyboardMap && key < keyboardMap->keys.count() && keyboardMap->keys.at(key)->characters(HbModifierNone) != QString("")) {
   368                 if (keyboardMap && key < keyboardMap->keys.count() && keyboardMap->keys.at(key)->characters(HbModifierNone) != QString("")) {
   323                     QString keydata = keyboardMap->keys.at(key)->characters(HbModifierNone);
   369                     if (focusedObject->characterAllowedInEditor(keyboardMap->keys.at(key)->characters(HbModifierNone).at(0)) || mType == HbKeyboardSctLandscape){
   324                     // Replace space and enter markers with correct glyphs.
   370                         QString keydata = keyboardMap->keys.at(key)->characters(HbModifierNone);
   325                     // These only exist in symbian fonts, so if we are not using symbian, use blank.
   371                         // Replace space and enter markers with correct glyphs.
   326                     if (keydata.at(0) == HbSctSpaceMarker) {
   372                         // These only exist in symbian fonts, so if we are not using symbian, use blank.
   327                         item->setText(HbSctSpaceGlyph, HbInputButton::ButtonTextIndexPrimary);
   373                         if (keydata.at(0) == HbSctSpaceMarker) {
   328                     } else if (keydata.at(0) == HbSctEnterMarker) {
   374                             item->setText(HbSctSpaceGlyph, HbInputButton::ButtonTextIndexPrimary);
   329                         item->setText(HbSctEnterGlyph, HbInputButton::ButtonTextIndexPrimary);
   375                         } else if (keydata.at(0) == HbSctEnterMarker) {
       
   376                             item->setText(HbSctEnterGlyph, HbInputButton::ButtonTextIndexPrimary);
       
   377                         } else {
       
   378                             item->setText(keydata.at(0), HbInputButton::ButtonTextIndexPrimary);
       
   379                         }
   330                     } else {
   380                     } else {
   331                         item->setText(keydata.at(0), HbInputButton::ButtonTextIndexPrimary);
   381                         i--;
   332                     }
   382                     }
   333                 } else {
   383                 } else {
   334                     item->setText("", HbInputButton::ButtonTextIndexPrimary);
   384                     item->setText("", HbInputButton::ButtonTextIndexPrimary);
   335                 }
   385                 }
   336 
   386 
   342         }
   392         }
   343         buttonGroup->setButtons(buttons);
   393         buttonGroup->setButtons(buttons);
   344     }
   394     }
   345 }
   395 }
   346 
   396 
   347 /*!
   397 int HbSctKeyboardPrivate::keyAtIndex(int index)
   348 Constructs the object. owner is the owning input method implementation. Keymap
   398 {
   349 is key mapping data to be used to display button texts. Key mapping data can be
   399     Q_Q(HbSctKeyboard);
   350 changed later (for example when the input language changes) by calling
   400     
   351 setKeymap.
   401     const HbKeyboardMap *keyboardMap = mKeymap->keyboard(q->keyboardType());
       
   402     if (mType == HbKeyboardSctLandscape){
       
   403         return index;
       
   404     }
       
   405     int totalKeys=0;
       
   406     HbInputFocusObject *focusedObject = mOwner->focusObject();
       
   407     HbInputButtonGroup *buttonGroup = static_cast<HbInputButtonGroup*>(q->contentItem());    
       
   408     if (buttonGroup) {
       
   409         if (keyboardMap && totalKeys < keyboardMap->keys.count()) {
       
   410             while (index){
       
   411                 if (focusedObject->characterAllowedInEditor(keyboardMap->keys.at(totalKeys)->characters(HbModifierNone).at(0))){
       
   412                     index--;                    
       
   413                 }
       
   414                 totalKeys++;
       
   415             }            
       
   416         }
       
   417     }
       
   418     return totalKeys;
       
   419 }
       
   420 
       
   421 int HbSctKeyboardPrivate::countActiveKeys()
       
   422 {
       
   423     Q_Q(HbSctKeyboard);
       
   424 
       
   425     const HbKeyboardMap *keyboardMap = mKeymap->keyboard(q->keyboardType());
       
   426     if (mType == HbKeyboardSctLandscape){
       
   427         return keyboardMap->keys.count();
       
   428     }
       
   429 
       
   430     int totalKeys=0;
       
   431     HbInputFocusObject *focusedObject = mOwner->focusObject();
       
   432     HbInputButtonGroup *buttonGroup = static_cast<HbInputButtonGroup*>(q->contentItem());
       
   433     if (buttonGroup) {
       
   434         if (keyboardMap && totalKeys < keyboardMap->keys.count()) {
       
   435             foreach(HbMappedKey *key, keyboardMap->keys){  
       
   436                 if (focusedObject->characterAllowedInEditor(key->characters(HbModifierNone).at(0))){
       
   437                     totalKeys++;
       
   438                 }
       
   439             }    
       
   440         }
       
   441     }
       
   442     return totalKeys;
       
   443 }
       
   444 
       
   445 void HbSctKeyboardPrivate::changePage(HbInputVkbWidget::HbFlickDirection flickDirection)
       
   446 {
       
   447     if (mFlickAnimation) {
       
   448         int direction = 1;
       
   449         if (flickDirection == HbInputVkbWidget::HbFlickDirectionRight) {
       
   450             direction = -1;
       
   451         }
       
   452 
       
   453         mActivePage = (mActivePage + direction) % mPages;
       
   454         if (mActivePage < 0) {
       
   455             mActivePage = mPages - 1;
       
   456         }
       
   457         updateButtons();
       
   458         updateKeyCodes();
       
   459     }
       
   460 }
       
   461 
       
   462 /*!
       
   463 Constructor. \a owner is the owning input method implementation, and
       
   464 \a keymap is the key mapping data that is used to display the button texts. Key mapping
       
   465 data can be changed later (for example when the input language changes) by calling
       
   466 the base class function HbInputVkbWidget::setKeymap.
   352 */
   467 */
   353 HbSctKeyboard::HbSctKeyboard(HbInputMethod *owner, const HbKeymap *keymap, QGraphicsItem *parent)
   468 HbSctKeyboard::HbSctKeyboard(HbInputMethod *owner, const HbKeymap *keymap, QGraphicsItem *parent)
   354     : HbInputVkbWidget(*new HbSctKeyboardPrivate, parent)
   469     : HbInputVkbWidget(*new HbSctKeyboardPrivate, parent)
   355 {
   470 {
   356     if (!owner) {
   471     if (!owner) {
   360     d->mOwner = owner;
   475     d->mOwner = owner;
   361     setKeymap(keymap);
   476     setKeymap(keymap);
   362 
   477 
   363     const HbKeyboardMap *keyboardMap = keymap->keyboard(keyboardType());
   478     const HbKeyboardMap *keyboardMap = keymap->keyboard(keyboardType());
   364     if (keyboardMap) {
   479     if (keyboardMap) {
   365         d->mPages = (int)ceil((float)(keyboardMap->keys.count() / d->mCharacterButtons));
   480         d->mPages = (int)ceil((float)d->countActiveKeys() / d->mCharacterButtons);
   366     }
   481     }
   367 
   482 
   368     if (d->mPages > 1) {
   483     d->mFlickAnimation = d->mPages > 1;
   369         d->mFlickAnimation = true;
       
   370     }
       
   371 
   484 
   372     if (d->mType == HbKeyboardSctLandscape) {
   485     if (d->mType == HbKeyboardSctLandscape) {
   373         connect(HbInputSettingProxy::instance(), SIGNAL(characterPreviewStateForQwertyChanged(bool)), this, SLOT(updateButtonPreviewStatus(bool)));
   486         connect(HbInputSettingProxy::instance(), SIGNAL(characterPreviewStateForQwertyChanged(bool)), this, SLOT(updateButtonPreviewStatus(bool)));
   374     }
   487     }
   375     connect(this, SIGNAL(flickEvent(HbInputVkbWidget::HbFlickDirection)), this, SLOT(changePage(HbInputVkbWidget::HbFlickDirection)));
   488     connect(this, SIGNAL(flickEvent(HbInputVkbWidget::HbFlickDirection)), this, SLOT(changePage(HbInputVkbWidget::HbFlickDirection)));
   376 }
   489 }
   377 
   490 
   378 /*!
   491 /*!
   379 Constructs the object. owner is the owning input method implementation. Keymap
   492 Constructor. \a owner is the owning input method implementation, and
   380 is key mapping data to be used to display button texts. Key mapping data can be
   493 \a keymap is the key mapping data that is used to display the button texts. Key mapping
   381 changed later (for example when the input language changes) by calling
   494 data can be changed later (for example when the input language changes) by calling
   382 setKeymap.
   495 the base class function HbInputVkbWidget::setKeymap.
   383 */
   496 */
   384 HbSctKeyboard::HbSctKeyboard(HbSctKeyboardPrivate &dd, HbInputMethod *owner,
   497 HbSctKeyboard::HbSctKeyboard(HbSctKeyboardPrivate &dd, HbInputMethod *owner,
   385                              const HbKeymap *keymap, QGraphicsItem *parent)
   498                              const HbKeymap *keymap, QGraphicsItem *parent)
   386     : HbInputVkbWidget(dd, parent)
   499     : HbInputVkbWidget(dd, parent)
   387 {
   500 {
   392     d->mOwner = owner;
   505     d->mOwner = owner;
   393     setKeymap(keymap);
   506     setKeymap(keymap);
   394 
   507 
   395     const HbKeyboardMap *keyboardMap = keymap->keyboard(keyboardType());
   508     const HbKeyboardMap *keyboardMap = keymap->keyboard(keyboardType());
   396     if (keyboardMap) {
   509     if (keyboardMap) {
   397         d->mPages = (int)ceil((float)(keyboardMap->keys.count() / d->mCharacterButtons));
   510         d->mPages = (int)ceil((float)d->countActiveKeys() / d->mCharacterButtons);
   398     }
   511     }
   399 
   512 
   400     if (d->mPages > 1) {
   513     d->mFlickAnimation = d->mPages > 1;
   401         d->mFlickAnimation = true;
   514     
   402     }
       
   403 
   515 
   404     if (d->mType == HbKeyboardSctLandscape) {
   516     if (d->mType == HbKeyboardSctLandscape) {
   405         connect(HbInputSettingProxy::instance(), SIGNAL(characterPreviewStateForQwertyChanged(bool)), this, SLOT(updateButtonPreviewStatus(bool)));
   517         connect(HbInputSettingProxy::instance(), SIGNAL(characterPreviewStateForQwertyChanged(bool)), this, SLOT(updateButtonPreviewStatus(bool)));
   406     }
   518     }
   407     connect(this, SIGNAL(flickEvent(HbInputVkbWidget::HbFlickDirection)), this, SLOT(changePage(HbInputVkbWidget::HbFlickDirection)));
   519     connect(this, SIGNAL(flickEvent(HbInputVkbWidget::HbFlickDirection)), this, SLOT(changePage(HbInputVkbWidget::HbFlickDirection)));
   408 }
   520 }
   409 
   521 
   410 /*!
   522 /*!
   411 Destructs the object.
   523 Destructor.
   412 */
   524 */
   413 HbSctKeyboard::~HbSctKeyboard()
   525 HbSctKeyboard::~HbSctKeyboard()
   414 {
   526 {
   415 }
   527 }
   416 
   528 
   417 /*!
   529 /*!
   418 Returns keyboard type.
   530 Returns the keyboard type.
   419 */
   531 */
   420 HbKeyboardType HbSctKeyboard::keyboardType() const
   532 HbKeyboardType HbSctKeyboard::keyboardType() const
   421 {
   533 {
   422     Q_D(const HbSctKeyboard);
   534     Q_D(const HbSctKeyboard);
   423 
       
   424     return d->mType;
   535     return d->mType;
   425 }
   536 }
   426 
   537 
   427 /*!
   538 /*!
   428 Returns preferred keyboard size. HbVkbHost uses this information when it opens the keyboard.
   539 Returns the preferred keyboard size. HbVkbHost uses this information when it opens the keyboard.
   429 */
   540 */
   430 QSizeF HbSctKeyboard::preferredKeyboardSize()
   541 QSizeF HbSctKeyboard::preferredKeyboardSize()
   431 {
   542 {
   432     Q_D(HbSctKeyboard);
   543     Q_D(HbSctKeyboard);
   433 
   544 
   444 
   555 
   445     return QSizeF(result);
   556     return QSizeF(result);
   446 }
   557 }
   447 
   558 
   448 /*!
   559 /*!
   449 Sets the keypad to given mode. Possible values are EModeAbc, EModeNumeric and EModeSct.
   560 Sets the keypad to given \a mode. Possible values are EModeAbc and EModeNumeric.
       
   561 \a modifiers is a set of flags for shift, chr, and fn keys (see details in file
       
   562 <tt>hbinputdef.h</tt>).
   450 */
   563 */
   451 void HbSctKeyboard::setMode(HbKeypadMode mode, HbModifiers modifiers)
   564 void HbSctKeyboard::setMode(HbKeypadMode mode, HbModifiers modifiers)
   452 {
   565 {
   453     Q_D(HbSctKeyboard);
   566     Q_D(HbSctKeyboard);
   454 
   567 
   457 
   570 
   458     HbInputVkbWidget::setMode(mode, modifiers);
   571     HbInputVkbWidget::setMode(mode, modifiers);
   459 }
   572 }
   460 
   573 
   461 /*!
   574 /*!
   462 Updates button preview status.
   575 Updates the button preview status.
   463 */
   576 */
   464 void HbSctKeyboard::updateButtonPreviewStatus(bool status)
   577 void HbSctKeyboard::updateButtonPreviewStatus(bool status)
   465 {
   578 {
   466     HbInputButtonGroup *buttonGroup = static_cast<HbInputButtonGroup *>(contentItem());
   579     HbInputButtonGroup *buttonGroup = static_cast<HbInputButtonGroup *>(contentItem());
   467     if (buttonGroup) {
   580     if (buttonGroup) {
   468         buttonGroup->setButtonPreviewEnabled(status);
   581         buttonGroup->setButtonPreviewEnabled(status);
   469     }
   582     }
   470 }
   583 }
   471 
   584 
   472 /*!
   585 /*!
   473 Handles flick gesture
   586 Handles the flick gesture.
   474 */
   587 */
   475 void HbSctKeyboard::changePage(HbInputVkbWidget::HbFlickDirection flickDirection)
   588 void HbSctKeyboard::changePage(HbInputVkbWidget::HbFlickDirection flickDirection)
   476 {
   589 {
   477     Q_D(HbSctKeyboard);
   590     Q_D(HbSctKeyboard);
   478 
   591 
   479     if (flickDirection == HbInputVkbWidget::HbFlickDirectionRight ||
   592     if (d->mFlickAnimation &&
   480         flickDirection == HbInputVkbWidget::HbFlickDirectionLeft) {
   593         (flickDirection == HbInputVkbWidget::HbFlickDirectionRight ||
   481         int direction = 1;
   594         flickDirection == HbInputVkbWidget::HbFlickDirectionLeft)) {
   482         if (flickDirection == HbInputVkbWidget::HbFlickDirectionRight) {
   595         
   483             direction = -1;
   596         HbWidgetFeedback::triggered(this, Hb::InstantFlicked);
   484         }
   597         d->changePage(flickDirection);
   485 
   598     }
   486         d->mActivePage = (d->mActivePage + direction) % d->mPages;
   599 }
   487         if (d->mActivePage < 0) {
   600 
   488             d->mActivePage = d->mPages - 1;
   601 /*!
   489         }
   602 Sends the key press event to the owning input method.
   490         d->updateKeyCodes();
       
   491         d->updateButtons();
       
   492         d->applyEditorConstraints();
       
   493     }
       
   494 }
       
   495 
       
   496 /*!
       
   497 Sends key event to owning input method.
       
   498 */
   603 */
   499 void HbSctKeyboard::sendKeyPressEvent(const QKeyEvent &event)
   604 void HbSctKeyboard::sendKeyPressEvent(const QKeyEvent &event)
   500 {
   605 {
   501     if (event.key() != HbInputButton::ButtonKeyCodePageChange &&
   606     if (event.key() != HbInputButton::ButtonKeyCodePageChange &&
   502         event.key() != HbInputButton::ButtonKeyCodeSmiley) {
   607         event.key() != HbInputButton::ButtonKeyCodeSmiley) {
   503         HbInputVkbWidget::sendKeyPressEvent(event);
   608         HbInputVkbWidget::sendKeyPressEvent(event);
   504     }
   609     }
   505 }
   610 }
   506 
   611 
   507 /*!
   612 /*!
   508 Sends key event to owning input method.
   613 Sends the key release event to the owning input method.
   509 */
   614 */
   510 void HbSctKeyboard::sendKeyReleaseEvent(const QKeyEvent &event)
   615 void HbSctKeyboard::sendKeyReleaseEvent(const QKeyEvent &event)
   511 {
   616 {
       
   617     Q_D(HbSctKeyboard);
       
   618 
   512     if (event.key() == HbInputButton::ButtonKeyCodePageChange) {
   619     if (event.key() == HbInputButton::ButtonKeyCodePageChange) {
   513         changePage(HbInputVkbWidget::HbFlickDirectionLeft);
   620         d->changePage(HbInputVkbWidget::HbFlickDirectionLeft);
   514     } else if (event.key() == HbInputButton::ButtonKeyCodeSmiley) {
   621     } else if (event.key() == HbInputButton::ButtonKeyCodeSmiley) {
   515         showSmileyPicker();
   622         showSmileyPicker();
   516     } else {
   623     } else {
   517         HbInputVkbWidget::sendKeyReleaseEvent(event);
   624         HbInputVkbWidget::sendKeyReleaseEvent(event);
   518     }
   625     }
   519 }
   626 }
   520 
   627 
   521 /*!
   628 /*!
   522 Sends key event to owning input method.
   629 Sends the key change event to the owning input method.
   523 Release event is ignored.
   630 The release event is ignored, and the press event is handled further.
   524 */
   631 */
   525 void HbSctKeyboard::sendKeyChangeEvent(const QKeyEvent &releaseEvent, const QKeyEvent &pressEvent)
   632 void HbSctKeyboard::sendKeyChangeEvent(const QKeyEvent &releaseEvent, const QKeyEvent &pressEvent)
   526 {
   633 {
   527     if (pressEvent.key() != HbInputButton::ButtonKeyCodePageChange &&
   634     if (pressEvent.key() != HbInputButton::ButtonKeyCodePageChange &&
   528         pressEvent.key() != HbInputButton::ButtonKeyCodeSmiley) {
   635         pressEvent.key() != HbInputButton::ButtonKeyCodeSmiley) {