src/hbinput/inputwidgets/hbinputvkbwidget.cpp
changeset 5 627c4a0fd0e7
parent 3 11d3954df52a
child 6 c3690ec91ef8
equal deleted inserted replaced
3:11d3954df52a 5:627c4a0fd0e7
    41 #include <hbdialog.h>
    41 #include <hbdialog.h>
    42 #include <hbeffect.h>
    42 #include <hbeffect.h>
    43 #include <hbframedrawer.h>
    43 #include <hbframedrawer.h>
    44 #include <hbevent.h>
    44 #include <hbevent.h>
    45 #include <hbdataform.h>
    45 #include <hbdataform.h>
       
    46 #include <hbinputregioncollector_p.h>
    46 
    47 
    47 #include <hbinputmethod.h>
    48 #include <hbinputmethod.h>
    48 #include <hbinputsettingproxy.h>
    49 #include <hbinputsettingproxy.h>
    49 #include <hbinpututils.h>
    50 #include <hbinpututils.h>
    50 #include <hbinputdef.h>
    51 #include <hbinputdef.h>
    51 #include <hbinputvkbhost.h>
    52 #include <hbinputvkbhost.h>
       
    53 #include <hbinputvkbhostbridge.h>
    52 #include <hbinputsettingwidget.h>
    54 #include <hbinputsettingwidget.h>
    53 #include <hbinputcommondialogs.h>
    55 #include <hbinputcommondialogs.h>
    54 #include <hbinputkeymap.h>
    56 #include <hbinputkeymap.h>
    55 #include <hbinputkeymapfactory.h>
    57 #include <hbinputkeymapfactory.h>
    56 #include <hbwidgetfeedback.h>
    58 #include <hbwidgetfeedback.h>
    57 #include <hbinputpredictionfactory.h>
    59 #include <hbinputpredictionfactory.h>
    58 #include <hbinputbuttongroup.h>
    60 #include <hbinputbuttongroup.h>
    59 #include <hbinputbutton.h>
    61 #include <hbinputbutton.h>
    60 #include <HbSwipeGesture>
    62 #include <HbSwipeGesture>
    61 #include <HbTapGesture>
    63 #include <HbTapGesture>
       
    64 #include <HbSelectionDialog>
       
    65 #include <HbListWidgetItem>
    62 #include "hbinputvirtualrocker.h"
    66 #include "hbinputvirtualrocker.h"
    63 #include "hbinputvkbwidget.h"
    67 #include "hbinputvkbwidget.h"
    64 #include "hbinputvkbwidget_p.h"
    68 #include "hbinputvkbwidget_p.h"
    65 #include "hbinputsettinglist.h"
    69 #include "hbinputsettinglist.h"
    66 #include "hbinputmodeindicator.h"
    70 #include "hbinputmodeindicator.h"
    67 #include <hbfeedbackmanager.h>
    71 #include <hbfeedbackmanager.h>
    68 #include "hbinputsmileypicker.h"
    72 #include "hbinputsmileypicker.h"
    69 #include "hbinputscreenshotwidget.h"
    73 #include "hbinputscreenshotwidget.h"
       
    74 
       
    75 #define HB_DIGIT_LATIN_START_VALUE          0x0030
       
    76 #define HB_DIGIT_ARABIC_INDIC_START_VALUE   0x0660
       
    77 #define HB_DIGIT_EASTERN_ARABIC_START_VALUE 0x06F0
       
    78 #define HB_DIGIT_DEVANAGARI_START_VALUE     0x0966
    70 
    79 
    71 const qreal HbRockerWidth = 50.0;
    80 const qreal HbRockerWidth = 50.0;
    72 
    81 
    73 
    82 
    74 /*!
    83 /*!
   124 mKeyboardSize(HbQwerty4x10),
   133 mKeyboardSize(HbQwerty4x10),
   125 mCloseHandleHeight(0),
   134 mCloseHandleHeight(0),
   126 mCloseHandle(0),
   135 mCloseHandle(0),
   127 mSettingView(0),
   136 mSettingView(0),
   128 mCurrentView(0),
   137 mCurrentView(0),
   129 mKeyboardDimmed(false)
   138 mKeyboardDimmed(false),
       
   139 mImSelectionDialog(0)
   130 {
   140 {
   131     mScreenshotTimeLine.setUpdateInterval(16);
   141     mScreenshotTimeLine.setUpdateInterval(16);
   132 }
   142 }
   133 
   143 
   134 
   144 
   136 {
   146 {
   137     delete mSettingList;
   147     delete mSettingList;
   138     delete mBackgroundDrawer;
   148     delete mBackgroundDrawer;
   139     delete mIconDrawer;
   149     delete mIconDrawer;
   140     delete mSmileyPicker;
   150     delete mSmileyPicker;
   141     delete mScreenshotWidget;
   151     delete mScreenshotWidget; 
       
   152     delete mImSelectionDialog;
   142 }
   153 }
   143 
   154 
   144 void HbInputVkbWidgetPrivate::initLayout()
   155 void HbInputVkbWidgetPrivate::initLayout()
   145 {
   156 {
   146     Q_Q(HbInputVkbWidget);
   157     Q_Q(HbInputVkbWidget);
   164 }
   175 }
   165 
   176 
   166 void HbInputVkbWidgetPrivate::init()
   177 void HbInputVkbWidgetPrivate::init()
   167 {
   178 {
   168     Q_Q(HbInputVkbWidget);
   179     Q_Q(HbInputVkbWidget);
       
   180 
       
   181     HbInputButtonGroup *buttonGroup = static_cast<HbInputButtonGroup*>(q->contentItem());
       
   182     QObject::connect(buttonGroup,SIGNAL(aboutToActivateCustomAction(HbAction*)),
       
   183                                 q,SIGNAL(aboutToActivateCustomAction(HbAction*)));
   169 
   184 
   170     mRocker = new HbInputVirtualRocker(q);
   185     mRocker = new HbInputVirtualRocker(q);
   171     mRocker->setObjectName("VirtualRocker");
   186     mRocker->setObjectName("VirtualRocker");
   172     QSizeF rockerSize(HbRockerWidth, HbRockerWidth);
   187     QSizeF rockerSize(HbRockerWidth, HbRockerWidth);
   173     mRocker->resize(rockerSize);
   188     mRocker->resize(rockerSize);
   196     q->grabGesture(Qt::SwipeGesture);
   211     q->grabGesture(Qt::SwipeGesture);
   197 
   212 
   198     // eating gestures below the panel (remove when panel starts to do this)
   213     // eating gestures below the panel (remove when panel starts to do this)
   199     q->grabGesture(Qt::TapGesture);
   214     q->grabGesture(Qt::TapGesture);
   200     q->grabGesture(Qt::PanGesture);
   215     q->grabGesture(Qt::PanGesture);
       
   216 
       
   217     HbInputRegionCollector::instance()->attach(q);
   201 }
   218 }
   202 
   219 
   203 // re-implemented by inherited keyboards
   220 // re-implemented by inherited keyboards
   204 int HbInputVkbWidgetPrivate::keyCode(int buttonId)
   221 int HbInputVkbWidgetPrivate::keyCode(int buttonId)
   205 {
   222 {
   297         for (int i = 0; i < buttons.count(); ++i) {
   314         for (int i = 0; i < buttons.count(); ++i) {
   298             if (keyCode(i) == HbInputButton::ButtonKeyCodeCharacter) {
   315             if (keyCode(i) == HbInputButton::ButtonKeyCodeCharacter) {
   299                 HbInputButton *item = buttons.at(i);
   316                 HbInputButton *item = buttons.at(i);
   300 
   317 
   301                 const HbKeyboardMap *keyboardMap = mKeymap->keyboard(q->keyboardType());
   318                 const HbKeyboardMap *keyboardMap = mKeymap->keyboard(q->keyboardType());
   302                 if (keyboardMap && key < keyboardMap->keys.count()) {
   319                 if (keyboardMap && key < keyboardMap->keys.count() && keyboardMap->keys.at(key)->characters(mModifiers)!= QString("")) {
   303                     QString keydata = keyboardMap->keys.at(key)->characters(mModifiers);
   320                     QString keydata = keyboardMap->keys.at(key)->characters(mModifiers);
   304                     item->setText(keydata.at(0), HbInputButton::ButtonTextIndexPrimary);
   321                     item->setText(keydata.at(0), HbInputButton::ButtonTextIndexPrimary);
   305 
   322 
   306                     QString mappedCharacters;
   323                     QString mappedCharacters;
   307                     keydata.append(keyboardMap->keys.at(key)->characters(mModifiers | HbModifierFnPressed));
   324                     keydata.append(keyboardMap->keys.at(key)->characters(mModifiers | HbModifierFnPressed));
   409         }
   426         }
   410     }
   427     }
   411 
   428 
   412     return ret;
   429     return ret;
   413 }
   430 }
       
   431 
       
   432 QChar HbInputVkbWidgetPrivate::numberCharacterBoundToKey(int key)
       
   433 {
       
   434     QChar numChr;
       
   435     if (!mKeymap || !mOwner) {
       
   436         return numChr;
       
   437     }
       
   438 
       
   439     HbInputFocusObject *focusObject = mOwner->focusObject();
       
   440     if (!focusObject) {
       
   441         return numChr;
       
   442     }	
       
   443     HbInputLanguage language = mKeymap->language();
       
   444     if (language.language()  != (QLocale::Language)0) {
       
   445         HbInputDigitType digitType = HbInputUtils::inputDigitType(language);
       
   446         	
       
   447         // In number editors, show the native digits only when both device and writing languages are same,
       
   448         // else show latin digits
       
   449         if (focusObject->editorInterface().isNumericEditor()) {
       
   450             QLocale::Language systemLanguage = QLocale::system().language();
       
   451             if (language.language() != systemLanguage) {
       
   452                 digitType = HbDigitTypeLatin;
       
   453             }	
       
   454         }
       
   455 			
       
   456         HbKeyboardType keyboardType = mOwner->inputState().keyboard();
       
   457         
       
   458         if (keyboardType == HbKeyboardVirtual12Key) {
       
   459             numChr = HbInputUtils::findFirstNumberCharacterBoundToKey(
       
   460             mKeymap->keyboard(keyboardType)->keys.at(key),
       
   461             language, digitType);
       
   462         } else if (keyboardType == HbKeyboardVirtualQwerty) {
       
   463             switch (digitType) {
       
   464             case HbDigitTypeLatin:
       
   465                 numChr = HB_DIGIT_LATIN_START_VALUE + key;
       
   466                 break;
       
   467             case HbDigitTypeArabicIndic:
       
   468                 numChr = HB_DIGIT_ARABIC_INDIC_START_VALUE + key;
       
   469                 break;
       
   470             case HbDigitTypeEasternArabic:
       
   471                 numChr = HB_DIGIT_EASTERN_ARABIC_START_VALUE + key;
       
   472                 break;
       
   473             case HbDigitTypeDevanagari:
       
   474                 numChr = HB_DIGIT_DEVANAGARI_START_VALUE + key;
       
   475                 break;
       
   476             default:
       
   477                 break;
       
   478             }
       
   479         }
       
   480     }
       
   481     return numChr;
       
   482 }
       
   483 
       
   484 void HbInputVkbWidgetPrivate::showInputMethodSelectionDialog()
       
   485 {
       
   486     Q_Q(HbInputVkbWidget);
       
   487 
       
   488     delete mImSelectionDialog;
       
   489     mImSelectionDialog = new HbSelectionDialog();
       
   490 
       
   491     mImSelectionDialog->setObjectName("Input method dialog");
       
   492 
       
   493     // Make sure the language dialog never steals focus.
       
   494     mImSelectionDialog->setFlag(QGraphicsItem::ItemIsPanel, true);
       
   495     mImSelectionDialog->setActive(false);
       
   496 
       
   497     QList<HbInputMethodDescriptor> customList = HbInputMethod::listCustomInputMethods();
       
   498 
       
   499     QList<HbListWidgetItem*> listItems;
       
   500     HbListWidgetItem* item = new HbListWidgetItem();
       
   501     QString methodName("Default");
       
   502     item->setText(methodName);
       
   503     listItems.append(item);
       
   504 
       
   505     foreach (HbInputMethodDescriptor descriptor, customList) {
       
   506     QString displayName = descriptor.displayName();
       
   507         if (displayName.length() == 0) {
       
   508             displayName = QString("Unknown");
       
   509         }
       
   510         item = new HbListWidgetItem();
       
   511         item->setText(displayName);
       
   512         listItems.append(item);
       
   513     }
       
   514     mImSelectionDialog->setWidgetItems(listItems, true);
       
   515     mImSelectionDialog->setSelectionMode(HbAbstractItemView::SingleSelection);
       
   516     mImSelectionDialog->setDismissPolicy(HbPopup::NoDismiss);
       
   517     mImSelectionDialog->setModal(true);
       
   518 
       
   519     q->connect(mImSelectionDialog, SIGNAL(finished(HbAction*)), q, SLOT(_q_inputMethodSelectionDialogFinished(HbAction*)));
       
   520 
       
   521     mImSelectionDialog->open();
       
   522 }
       
   523 
       
   524 void HbInputVkbWidgetPrivate::_q_inputMethodSelectionDialogFinished(HbAction *action)
       
   525 {
       
   526     Q_UNUSED(action);
       
   527 
       
   528     QList<QVariant> selectedItems = mImSelectionDialog->selectedItems();
       
   529     if (selectedItems.count()) {
       
   530         HbInputMethodDescriptor result;
       
   531         int selection = selectedItems.first().toInt();
       
   532         if (selection == 0) {
       
   533            result.setDefault();
       
   534         } else {
       
   535            QList<HbInputMethodDescriptor> customList = HbInputMethod::listCustomInputMethods();
       
   536            if (customList.count() <= selection) {
       
   537                result = customList[selection-1];
       
   538            }
       
   539         }
       
   540 
       
   541         if (!result.isEmpty() && mOwner) {
       
   542             mOwner->activateInputMethod(result);
       
   543         }
       
   544     }
       
   545 }
       
   546 
   414 /// @endcond
   547 /// @endcond
   415 
   548 
   416 /*!
   549 /*!
   417 Costructs the object.
   550 Costructs the object.
   418 */
   551 */
   615     Q_D(HbInputVkbWidget);
   748     Q_D(HbInputVkbWidget);
   616     d->mMode = mode;
   749     d->mMode = mode;
   617     d->mModifiers = modifiers;
   750     d->mModifiers = modifiers;
   618 
   751 
   619     d->updateButtons();
   752     d->updateButtons();
       
   753 	d->updateKeyCodes();
   620     d->applyEditorConstraints();
   754     d->applyEditorConstraints();
   621 
   755 
   622     HbInputButtonGroup *buttonGroup = static_cast<HbInputButtonGroup*>(contentItem());
   756     HbInputButtonGroup *buttonGroup = static_cast<HbInputButtonGroup*>(contentItem());
   623     if (buttonGroup && d->mOwner->focusObject()) {
   757     if (buttonGroup && d->mOwner->focusObject()) {
   624         buttonGroup->setCustomButtonActions(d->mOwner->focusObject()->editorInterface().actions());
   758         buttonGroup->setCustomButtonActions(d->mOwner->focusObject()->editorInterface().actions());
   674 {
   808 {
   675     Q_D(HbInputVkbWidget);
   809     Q_D(HbInputVkbWidget);
   676 
   810 
   677     d->mCurrentHost = host;
   811     d->mCurrentHost = host;
   678 
   812 
       
   813     if (d->mSmileyPicker && d->mSmileyPicker->isVisible()) {
       
   814         d->mSmileyPicker->hide();
       
   815     }	
   679     d->mRocker->setVisible(false);
   816     d->mRocker->setVisible(false);
   680     if (d->mSettingList) {
   817     if (d->mSettingList) {
   681         d->mSettingList->close();
   818         d->mSettingList->close();
   682     }
   819     }
   683 }
   820 }
   781 Shows settings view
   918 Shows settings view
   782 */
   919 */
   783 void HbInputVkbWidget::showSettingsView()
   920 void HbInputVkbWidget::showSettingsView()
   784 {
   921 {
   785     Q_D(HbInputVkbWidget);
   922     Q_D(HbInputVkbWidget);
       
   923     
       
   924     //HbVkbHostBridge::instance()->minimizeKeypad(true);
       
   925     /*
       
   926     Added for vanilla input
       
   927     When settings dialog is launched, keypad is not closed.
       
   928     */
       
   929     HbInputFocusObject *focusObject = 0;
       
   930     if (!d->mOwner || !(focusObject = d->mOwner->focusObject())) {
       
   931         return;
       
   932     }
       
   933     HbVkbHost *vkbHost = focusObject->editorInterface().vkbHost();
       
   934     if (vkbHost && vkbHost->keypadStatus() != HbVkbHost::HbVkbStatusClosed) {
       
   935         vkbHost->closeKeypad();
       
   936     }
   786 
   937 
   787     closeSettingList();
   938     closeSettingList();
   788     hide();
   939     hide();
   789 
   940 
   790     d->mSettingView = new HbView(this);
   941     d->mSettingView = new HbView(this);
       
   942     HbInputRegionCollector::instance()->attach(d->mSettingView);
   791     d->mSettingView->setTitle(tr("Input Settings"));
   943     d->mSettingView->setTitle(tr("Input Settings"));
   792     mainWindow()->addView(d->mSettingView);
   944     mainWindow()->addView(d->mSettingView);
   793 
   945 
   794     HbAction *backAction = new HbAction(Hb::BackNaviAction, d->mSettingView);
   946     HbAction *backAction = new HbAction(Hb::BackNaviAction, d->mSettingView);
   795     backAction->setText(tr("Back"));
   947     backAction->setText(tr("Back"));
   813 {
   965 {
   814     Q_D(HbInputVkbWidget);
   966     Q_D(HbInputVkbWidget);
   815 
   967 
   816     mainWindow()->setCurrentView(d->mCurrentView);
   968     mainWindow()->setCurrentView(d->mCurrentView);
   817     mainWindow()->removeView(d->mSettingView);
   969     mainWindow()->removeView(d->mSettingView);
       
   970     HbInputRegionCollector::instance()->detach(d->mSettingView);
   818     delete d->mSettingView;
   971     delete d->mSettingView;
   819     d->mSettingView = 0;
   972     d->mSettingView = 0;
       
   973     
       
   974     /***** To be removed, Added for vanilla input.
       
   975     HbInputFocusObject *focusObject = 0;
       
   976     if (!d->mOwner || !(focusObject = d->mOwner->focusObject())) {
       
   977         return;
       
   978     }
       
   979     HbVkbHost *vkbHost = focusObject->editorInterface().vkbHost();
       
   980     if (vkbHost && vkbHost->keypadStatus() != HbVkbHost::HbVkbStatusOpened) {
       
   981         vkbHost->openKeypad();
       
   982     }
       
   983     *****/
   820 }
   984 }
   821 
   985 
   822 /*!
   986 /*!
   823 Executes input method selection dialog
   987 Executes input method selection dialog
   824 */
   988 */
   825 void HbInputVkbWidget::executeMethodDialog()
   989 void HbInputVkbWidget::executeMethodDialog()
   826 {
   990 {
   827     Q_D(HbInputVkbWidget);
   991     Q_D(HbInputVkbWidget);
   828 
   992 
   829     closeSettingList();
   993     closeSettingList();
   830     HbInputMethodDescriptor method
   994     d->showInputMethodSelectionDialog();
   831         = HbInputCommonDialogs::showCustomInputMethodSelectionDialog(HbInputSettingProxy::instance()->globalInputLanguage());
       
   832     if (!method.isEmpty() && d->mOwner) {
       
   833         d->mOwner->activateInputMethod(method);
       
   834     }
       
   835 }
   995 }
   836 
   996 
   837 /*!
   997 /*!
   838 \reimp
   998 \reimp
   839 */
   999 */
  1017 */
  1177 */
  1018 void HbInputVkbWidget::sendKeyReleaseEvent(const QKeyEvent &event)
  1178 void HbInputVkbWidget::sendKeyReleaseEvent(const QKeyEvent &event)
  1019 {
  1179 {
  1020     Q_D(HbInputVkbWidget);
  1180     Q_D(HbInputVkbWidget);
  1021 
  1181 
       
  1182 	if (d->mOwner && event.key() > 0) {
       
  1183 		d->mOwner->filterEvent(&event);
       
  1184 	}
       
  1185 
  1022     if (event.key() == HbInputButton::ButtonKeyCodeSettings) {
  1186     if (event.key() == HbInputButton::ButtonKeyCodeSettings) {
  1023         showSettingList();
  1187         showSettingList();
  1024     } else {
  1188     } 
  1025         if (d->mOwner) {
       
  1026             d->mOwner->filterEvent(&event);
       
  1027         }
       
  1028     }
       
  1029 }
  1189 }
  1030 
  1190 
  1031 /*!
  1191 /*!
  1032 Sends key event to owning input method.
  1192 Sends key event to owning input method.
  1033 */
  1193 */
  1167             }
  1327             }
  1168         }
  1328         }
  1169     } else if(HbTapGesture *gesture = qobject_cast<HbTapGesture *>(event->gesture(Qt::TapGesture))) {
  1329     } else if(HbTapGesture *gesture = qobject_cast<HbTapGesture *>(event->gesture(Qt::TapGesture))) {
  1170         if (gesture->state() == Qt::GestureFinished) {        
  1330         if (gesture->state() == Qt::GestureFinished) {        
  1171             // if keypad is minimized, open it 
  1331             // if keypad is minimized, open it 
  1172             if ( d->mCurrentHost->keypadStatus() == HbVkbHost::HbVkbStatusMinimized ) {
  1332             if (d->mCurrentHost && d->mCurrentHost->keypadStatus() == HbVkbHost::HbVkbStatusMinimized ) {
  1173                 d->mCurrentHost->openKeypad(this, d->mOwner);
  1333                 d->mCurrentHost->openKeypad(this, d->mOwner);
  1174             }
  1334             }
  1175         }
  1335         }
  1176     }
  1336     }
  1177 }
  1337 }
  1178 
  1338 
       
  1339 #include "moc_hbinputvkbwidget.cpp"
  1179 // End of file
  1340 // End of file