src/hbplugins/inputmethods/touchinput/hbinput12keytouchkeyboard.cpp
changeset 34 ed14f46c0e55
parent 7 923ff622b8b9
equal deleted inserted replaced
31:7516d6d86cf5 34:ed14f46c0e55
    27 
    27 
    28 #include <hbinputmethod.h>
    28 #include <hbinputmethod.h>
    29 #include <hbinputkeymap.h>
    29 #include <hbinputkeymap.h>
    30 #include <hbinpututils.h>
    30 #include <hbinpututils.h>
    31 #include <hbframedrawer.h>
    31 #include <hbframedrawer.h>
       
    32 #include <hbinputsettingproxy.h>
    32 
    33 
    33 #include "hbinput12keytouchkeyboard.h"
    34 #include "hbinput12keytouchkeyboard.h"
    34 #include "hbinput12keytouchkeyboard_p.h"
    35 #include "hbinput12keytouchkeyboard_p.h"
    35 #include "hbinputbuttongroup.h"
    36 #include "hbinputbuttongroup.h"
    36 #include "hbinputbutton.h"
    37 #include "hbinputbutton.h"
    39 const qreal HbKeyboardHeightInUnits = 36.9;
    40 const qreal HbKeyboardHeightInUnits = 36.9;
    40 const qreal HbKeyboardWidthInUnits = 53.8;
    41 const qreal HbKeyboardWidthInUnits = 53.8;
    41 
    42 
    42 const int HbFirstRowIndex = 0;
    43 const int HbFirstRowIndex = 0;
    43 const int HbSecondRowIndex = 2;
    44 const int HbSecondRowIndex = 2;
       
    45 const int HbNumberIndex = 4;
    44 const int HbVirtual12KeyNumberOfRows = 4;
    46 const int HbVirtual12KeyNumberOfRows = 4;
    45 const int HbVirtual12KeyNumberOfColumns = 4;
    47 const int HbVirtual12KeyNumberOfColumns = 4;
    46 const int HbButtonKeyCodeTable[HbVirtual12KeyNumberOfRows * HbVirtual12KeyNumberOfColumns] =
    48 const int HbButtonKeyCodeTable[HbVirtual12KeyNumberOfRows * HbVirtual12KeyNumberOfColumns] =
    47 {
    49 {
    48     HbInputButton::ButtonKeyCodeCharacter,
    50     HbInputButton::ButtonKeyCodeCharacter,
   194             if (keyCode(i) == HbInputButton::ButtonKeyCodeCharacter) {
   196             if (keyCode(i) == HbInputButton::ButtonKeyCodeCharacter) {
   195 
   197 
   196                 if (mMode == EModeNumeric) {
   198                 if (mMode == EModeNumeric) {
   197                     QChar numChr;
   199                     QChar numChr;
   198                     const HbKeyboardMap *labelMap = mKeymap->keyboard(HbKeyboardVirtual12KeyLabels);
   200                     const HbKeyboardMap *labelMap = mKeymap->keyboard(HbKeyboardVirtual12KeyLabels);
   199                     const HbKeyboardMap *keyMap = mKeymap->keyboard(HbKeyboardVirtual12Key);
   201                     const HbKeyboardMap *keyboardMap; 
   200                     if (labelMap && key < labelMap->keys.count()) {
   202                     if (mOwner->focusObject() && mOwner->focusObject()->editorInterface().editorClass() == HbInputEditorClassEmail) {
   201                         numChr = labelMap->keys.at(key)->keycode;
   203                         keyboardMap = mKeymap->keyboard(HbKeyboardVirtual12KeyEmail);
       
   204                         if (!keyboardMap) {
       
   205                             keyboardMap = mKeymap->keyboard(HbKeyboardVirtual12Key);
       
   206                         }
       
   207                     } else if (mOwner->focusObject() && mOwner->focusObject()->editorInterface().editorClass() == HbInputEditorClassUrl) {
       
   208                         keyboardMap = mKeymap->keyboard(HbKeyboardVirtual12KeyUrl);
       
   209                         if (!keyboardMap) {
       
   210                             keyboardMap = mKeymap->keyboard(HbKeyboardVirtual12Key);
       
   211                         }
       
   212                     } else {
       
   213                         keyboardMap = mKeymap->keyboard(HbKeyboardVirtual12Key);
       
   214                     }
       
   215 
       
   216                     if (labelMap && key < labelMap->keys.count() &&
       
   217                         !(mOwner->focusObject() && mOwner->focusObject()->editorInterface().isNumericEditor())) {
       
   218                         numChr = keyLabel(labelMap->keys.at(key)->chars, HbNumberIndex).at(0);
   202                     }
   219                     }
   203 
   220 
   204                     // Fallback to normal keymappings if key labels are not present
   221                     // Fallback to normal keymappings if key labels are not present
   205                     if (keyMap && key < keyMap->keys.count() && numChr.isNull()) {
   222                     if (keyboardMap && key < keyboardMap->keys.count() && numChr.isNull()) {
   206                         numChr = numberCharacterBoundToKey(key);
   223                         numChr = numberCharacterBoundToKey(key);
   207                     }
   224                     }
   208 
   225 
   209                     item->setText(numChr, HbInputButton::ButtonTextIndexPrimary);
   226                     item->setText(numChr, HbInputButton::ButtonTextIndexPrimary);
   210                     item->setText(QString(), HbInputButton::ButtonTextIndexSecondaryFirstRow);
   227                     item->setText(QString(), HbInputButton::ButtonTextIndexSecondaryFirstRow);
   215                 } else if (mMode == EModeAbc) {
   232                 } else if (mMode == EModeAbc) {
   216                     QString firstRow;
   233                     QString firstRow;
   217                     QString secondRow;
   234                     QString secondRow;
   218                     QChar numChr;
   235                     QChar numChr;
   219                     const HbKeyboardMap *labelMap = mKeymap->keyboard(HbKeyboardVirtual12KeyLabels);
   236                     const HbKeyboardMap *labelMap = mKeymap->keyboard(HbKeyboardVirtual12KeyLabels);
   220                     const HbKeyboardMap *keyMap = mKeymap->keyboard(HbKeyboardVirtual12Key);
   237                     const HbKeyboardMap *keyboardMap;
       
   238                     
       
   239                     if (mOwner->focusObject() && mOwner->focusObject()->editorInterface().editorClass() == HbInputEditorClassEmail) {
       
   240                         keyboardMap = mKeymap->keyboard(HbKeyboardVirtual12KeyEmail);
       
   241                         if (!keyboardMap) {
       
   242                             keyboardMap = mKeymap->keyboard(HbKeyboardVirtual12Key);
       
   243                         }
       
   244                     } else if (mOwner->focusObject() && mOwner->focusObject()->editorInterface().editorClass() == HbInputEditorClassUrl) {
       
   245                         keyboardMap = mKeymap->keyboard(HbKeyboardVirtual12KeyUrl);
       
   246                         if (!keyboardMap) {
       
   247                             keyboardMap = mKeymap->keyboard(HbKeyboardVirtual12Key);
       
   248                         }
       
   249                     } else {
       
   250                         keyboardMap = mKeymap->keyboard(HbKeyboardVirtual12Key);
       
   251                     }
       
   252 
   221                     if (labelMap && key < labelMap->keys.count()) {
   253                     if (labelMap && key < labelMap->keys.count()) {
   222                         firstRow = keyLabel(labelMap->keys.at(key)->chars, HbFirstRowIndex | mModifiers);
   254                         firstRow = keyLabel(labelMap->keys.at(key)->chars, HbFirstRowIndex | mModifiers);
   223                         secondRow = keyLabel(labelMap->keys.at(key)->chars, HbSecondRowIndex | mModifiers);
   255                         secondRow = keyLabel(labelMap->keys.at(key)->chars, HbSecondRowIndex | mModifiers);
   224                         numChr = labelMap->keys.at(key)->keycode;
   256                         if (!(mOwner->focusObject() && mOwner->focusObject()->editorInterface().isNumericEditor())) {
       
   257                             numChr = keyLabel(labelMap->keys.at(key)->chars, HbNumberIndex).at(0);
       
   258                         }
   225                     }
   259                     }
   226 
   260 
   227                     // Fallback to normal keymappings if key labels are not present
   261                     // Fallback to normal keymappings if key labels are not present
   228                     if (keyMap && key < keyMap->keys.count()) {
   262                     if (keyboardMap && key < keyboardMap->keys.count()) {
   229                         if (firstRow.isEmpty()) {
   263                         if (firstRow.isEmpty()) {
   230                             firstRow = keyMap->keys.at(key)->characters(mModifiers);
   264                             firstRow = keyboardMap->keys.at(key)->characters(mModifiers);
   231                             if (mOwner->focusObject()) {
   265                             if (mOwner->focusObject()) {
   232                                 QString allowedData;
   266                                 QString allowedData;
   233                                 mOwner->focusObject()->filterStringWithEditorFilter(firstRow, allowedData);
   267                                 mOwner->focusObject()->filterStringWithEditorFilter(firstRow, allowedData);
   234                                 firstRow = allowedData.left(3);
   268                                 firstRow = allowedData.left(3);
   235                             } else {
   269                             } else {
   261                     item->setIcon(HbIcon(HbInputButtonIconShift), HbInputButton::ButtonIconIndexPrimary);
   295                     item->setIcon(HbIcon(HbInputButtonIconShift), HbInputButton::ButtonIconIndexPrimary);
   262                     item->setText(QString(" "), HbInputButton::ButtonTextIndexSecondaryFirstRow);
   296                     item->setText(QString(" "), HbInputButton::ButtonTextIndexSecondaryFirstRow);
   263                 }
   297                 }
   264             } else if (keyCode(i) == HbInputButton::ButtonKeyCodeAsterisk) {
   298             } else if (keyCode(i) == HbInputButton::ButtonKeyCodeAsterisk) {
   265                 if (mMode == EModeNumeric) {
   299                 if (mMode == EModeNumeric) {
   266                     item->setText(QString("*"), HbInputButton::ButtonTextIndexPrimary);
   300                     item->setText(QString(""), HbInputButton::ButtonTextIndexPrimary);
   267                     item->setText(QString(""), HbInputButton::ButtonTextIndexSecondaryFirstRow);
   301                     item->setText(QString("+"), HbInputButton::ButtonTextIndexSecondaryFirstRow);
       
   302                     item->setText(QString("*"), HbInputButton::ButtonTextIndexSecondarySecondRow);
   268                 } else if (mMode == EModeAbc) {
   303                 } else if (mMode == EModeAbc) {
   269                     item->setText(QString("*"), HbInputButton::ButtonTextIndexPrimary);
   304                     if (HbInputSettingProxy::instance()->globalInputLanguage().language() == QLocale::Chinese) {
   270                     item->setText(QString("+"), HbInputButton::ButtonTextIndexSecondaryFirstRow);
   305                         QString str = QString(QChar(0x7B26));
   271                 }
   306                         str.append(QString(QChar(0x53F7)));
   272             }
   307                         item->setText(QString(), HbInputButton::ButtonTextIndexSecondaryFirstRow);
       
   308                         item->setText(str, HbInputButton::ButtonTextIndexPrimary);
       
   309                     } else {
       
   310                         item->setText(QString("*"), HbInputButton::ButtonTextIndexPrimary);
       
   311                         item->setText(QString("+"), HbInputButton::ButtonTextIndexSecondaryFirstRow);
       
   312                         item->setText(QString(""), HbInputButton::ButtonTextIndexSecondarySecondRow);
       
   313                     }
       
   314                 }
       
   315             } else if (keyCode(i) == HbInputButton::ButtonKeyCodeSymbol) {
       
   316                 if (HbInputSettingProxy::instance()->globalInputLanguage().language() == QLocale::Chinese) {
       
   317                     item->setText(QString(QChar(0x4E2D)), HbInputButton::ButtonTextIndexPrimary);
       
   318                     item->setIcon(HbIcon(), HbInputButton::ButtonIconIndexPrimary);
       
   319                 } else {
       
   320                     item->setIcon(HbIcon(HbInputButtonIconSymbol2), HbInputButton::ButtonIconIndexPrimary);
       
   321                 }
       
   322             } 
   273         }
   323         }
   274         buttonGroup->setButtons(buttons);
   324         buttonGroup->setButtons(buttons);
   275     }
   325     }
   276 }
   326 }
   277 
   327 
   278 QString Hb12KeyTouchKeyboardPrivate::keyLabel(const QStringList &labels, int index)
   328 QString Hb12KeyTouchKeyboardPrivate::keyLabel(const QStringList &labels, int index)
   279 {
   329 {
   280     if (index == HbFirstRowIndex && labels.count() >= 2) {
   330     if (index == HbNumberIndex && labels.count() >= 1) {
       
   331         return labels.at(0);
       
   332     } else if (index == HbFirstRowIndex && labels.count() >= 2) {
   281         return labels.at(1);
   333         return labels.at(1);
   282     } else if (index == (HbFirstRowIndex | HbModifierShiftPressed) && labels.count() >= 3) {
   334     } else if (index == (HbFirstRowIndex | HbModifierShiftPressed) && labels.count() >= 3) {
   283         return labels.at(2);
   335         return labels.at(2);
   284     } else if (index == HbSecondRowIndex && labels.count() >= 4) {
   336     } else if (index == HbSecondRowIndex && labels.count() >= 4) {
   285         return labels.at(3);
   337         return labels.at(3);
   334 /*!
   386 /*!
   335 Returns keyboard type.
   387 Returns keyboard type.
   336 */
   388 */
   337 HbKeyboardType Hb12KeyTouchKeyboard::keyboardType() const
   389 HbKeyboardType Hb12KeyTouchKeyboard::keyboardType() const
   338 {
   390 {
       
   391     Q_D(const Hb12KeyTouchKeyboard);
       
   392 
       
   393     if (d->mOwner->focusObject()) {
       
   394         if (d->mOwner->focusObject()->editorInterface().editorClass() == HbInputEditorClassEmail &&
       
   395             d->mKeymap && d->mKeymap->keyboard(HbKeyboardVirtual12KeyEmail)) {
       
   396             return HbKeyboardVirtual12KeyEmail;
       
   397         } else if (d->mOwner->focusObject()->editorInterface().editorClass() == HbInputEditorClassUrl &&
       
   398                    d->mKeymap && d->mKeymap->keyboard(HbKeyboardVirtual12KeyUrl)) {
       
   399             return HbKeyboardVirtual12KeyUrl;
       
   400         }
       
   401     }
   339     return HbKeyboardVirtual12Key;
   402     return HbKeyboardVirtual12Key;
   340 }
   403 }
   341 
   404 
   342 /*!
   405 /*!
   343 Returns preferred keyboard size. HbVkbHost uses this information when it opens the keyboard.
   406 Returns preferred keyboard size. HbVkbHost uses this information when it opens the keyboard.