src/gui/inputmethod/qcoefepinputcontext_s60.cpp
branchRCL_3
changeset 5 d3bac044e0f0
parent 4 3b1da2848fc7
child 8 3f74d0d4af4c
equal deleted inserted replaced
4:3b1da2848fc7 5:d3bac044e0f0
    70       m_cursorVisibility(1),
    70       m_cursorVisibility(1),
    71       m_inlinePosition(0),
    71       m_inlinePosition(0),
    72       m_formatRetriever(0),
    72       m_formatRetriever(0),
    73       m_pointerHandler(0),
    73       m_pointerHandler(0),
    74       m_longPress(0),
    74       m_longPress(0),
    75       m_cursorPos(0)
    75       m_cursorPos(0),
       
    76       m_hasTempPreeditString(false)
    76 {
    77 {
    77     m_fepState->SetObjectProvider(this);
    78     m_fepState->SetObjectProvider(this);
    78     m_fepState->SetFlags(EAknEditorFlagDefault);
    79     m_fepState->SetFlags(EAknEditorFlagDefault);
    79     m_fepState->SetDefaultInputMode( EAknEditorTextInputMode );
    80     m_fepState->SetDefaultInputMode( EAknEditorTextInputMode );
    80     m_fepState->SetPermittedInputModes( EAknEditorAllInputModes );
    81     m_fepState->SetPermittedInputModes( EAknEditorAllInputModes );
   197     // close when it discovers that the underlying widget does not have input capabilities.
   198     // close when it discovers that the underlying widget does not have input capabilities.
   198 
   199 
   199     if (!focusWidget())
   200     if (!focusWidget())
   200         return false;
   201         return false;
   201 
   202 
   202     if (event->type() == QEvent::KeyPress || event->type() == QEvent::KeyRelease) {
   203     switch (event->type()) {
       
   204     case QEvent::KeyPress:
       
   205         commitTemporaryPreeditString();
       
   206         // fall through intended
       
   207     case QEvent::KeyRelease:
   203         const QKeyEvent *keyEvent = static_cast<const QKeyEvent *>(event);
   208         const QKeyEvent *keyEvent = static_cast<const QKeyEvent *>(event);
   204         switch (keyEvent->key()) {
   209         switch (keyEvent->key()) {
   205         case Qt::Key_F20:
   210         case Qt::Key_F20:
   206             Q_ASSERT(m_lastImHints == focusWidget()->inputMethodHints());
   211             Q_ASSERT(m_lastImHints == focusWidget()->inputMethodHints());
   207             if (m_lastImHints & Qt::ImhHiddenText) {
   212             if (m_lastImHints & Qt::ImhHiddenText) {
   220             }
   225             }
   221             break;
   226             break;
   222         default:
   227         default:
   223             break;
   228             break;
   224         }
   229         }
       
   230 
       
   231         if (keyEvent->type() == QEvent::KeyPress
       
   232             && focusWidget()->inputMethodHints() & Qt::ImhHiddenText
       
   233             && !keyEvent->text().isEmpty()) {
       
   234             // Send some temporary preedit text in order to make text visible for a moment.
       
   235             m_preeditString = keyEvent->text();
       
   236             QList<QInputMethodEvent::Attribute> attributes;
       
   237             QInputMethodEvent imEvent(m_preeditString, attributes);
       
   238             QApplication::sendEvent(focusWidget(), &imEvent);
       
   239             m_tempPreeditStringTimeout.start(1000, this);
       
   240             m_hasTempPreeditString = true;
       
   241             update();
       
   242             return true;
       
   243         }
       
   244         break;
   225     }
   245     }
   226 
   246 
   227     if (!needsInputPanel())
   247     if (!needsInputPanel())
   228         return false;
   248         return false;
   229 
   249 
   248         }
   268         }
   249         return true;
   269         return true;
   250     }
   270     }
   251 
   271 
   252     return false;
   272     return false;
       
   273 }
       
   274 
       
   275 void QCoeFepInputContext::timerEvent(QTimerEvent *timerEvent)
       
   276 {
       
   277     if (timerEvent->timerId() == m_tempPreeditStringTimeout.timerId())
       
   278         commitTemporaryPreeditString();
       
   279 }
       
   280 
       
   281 void QCoeFepInputContext::commitTemporaryPreeditString()
       
   282 {
       
   283     if (m_tempPreeditStringTimeout.isActive())
       
   284         m_tempPreeditStringTimeout.stop();
       
   285 
       
   286     if (!m_hasTempPreeditString)
       
   287         return;
       
   288 
       
   289     commitCurrentString(false);
   253 }
   290 }
   254 
   291 
   255 void QCoeFepInputContext::mouseHandler( int x, QMouseEvent *event)
   292 void QCoeFepInputContext::mouseHandler( int x, QMouseEvent *event)
   256 {
   293 {
   257     Q_ASSERT(focusWidget());
   294     Q_ASSERT(focusWidget());
   306 }
   343 }
   307 
   344 
   308 void QCoeFepInputContext::applyHints(Qt::InputMethodHints hints)
   345 void QCoeFepInputContext::applyHints(Qt::InputMethodHints hints)
   309 {
   346 {
   310     using namespace Qt;
   347     using namespace Qt;
       
   348 
       
   349     commitTemporaryPreeditString();
   311 
   350 
   312     bool numbersOnly = hints & ImhDigitsOnly || hints & ImhFormattedNumbersOnly
   351     bool numbersOnly = hints & ImhDigitsOnly || hints & ImhFormattedNumbersOnly
   313             || hints & ImhDialableCharactersOnly;
   352             || hints & ImhDialableCharactersOnly;
   314     bool noOnlys = !(numbersOnly || hints & ImhUppercaseOnly
   353     bool noOnlys = !(numbersOnly || hints & ImhUppercaseOnly
   315             || hints & ImhLowercaseOnly);
   354             || hints & ImhLowercaseOnly);
   498 {
   537 {
   499     QWidget *w = focusWidget();
   538     QWidget *w = focusWidget();
   500     if (!w)
   539     if (!w)
   501         return;
   540         return;
   502 
   541 
       
   542     commitTemporaryPreeditString();
       
   543 
   503     m_cursorPos = w->inputMethodQuery(Qt::ImCursorPosition).toInt();
   544     m_cursorPos = w->inputMethodQuery(Qt::ImCursorPosition).toInt();
   504     
   545     
   505     QList<QInputMethodEvent::Attribute> attributes;
   546     QList<QInputMethodEvent::Attribute> attributes;
   506 
   547 
   507     m_cursorVisibility = aCursorVisibility ? 1 : 0;
   548     m_cursorVisibility = aCursorVisibility ? 1 : 0;
   596 void QCoeFepInputContext::SetCursorSelectionForFepL(const TCursorSelection& aCursorSelection)
   637 void QCoeFepInputContext::SetCursorSelectionForFepL(const TCursorSelection& aCursorSelection)
   597 {
   638 {
   598     QWidget *w = focusWidget();
   639     QWidget *w = focusWidget();
   599     if (!w)
   640     if (!w)
   600         return;
   641         return;
       
   642 
       
   643     commitTemporaryPreeditString();
   601 
   644 
   602     int pos = aCursorSelection.iAnchorPos;
   645     int pos = aCursorSelection.iAnchorPos;
   603     int length = aCursorSelection.iCursorPos - pos;
   646     int length = aCursorSelection.iCursorPos - pos;
   604 
   647 
   605     QList<QInputMethodEvent::Attribute> attributes;
   648     QList<QInputMethodEvent::Attribute> attributes;
   716     QInputMethodEvent event(QLatin1String(""), attributes);
   759     QInputMethodEvent event(QLatin1String(""), attributes);
   717     event.setCommitString(m_preeditString, 0-m_longPress, m_longPress);
   760     event.setCommitString(m_preeditString, 0-m_longPress, m_longPress);
   718     m_preeditString.clear();
   761     m_preeditString.clear();
   719     sendEvent(event);
   762     sendEvent(event);
   720 
   763 
       
   764     m_hasTempPreeditString = false;
   721     m_longPress = 0;
   765     m_longPress = 0;
   722 
   766 
   723     if (!triggeredBySymbian) {
   767     if (!triggeredBySymbian) {
   724         CCoeFep* fep = CCoeEnv::Static()->Fep();
   768         CCoeFep* fep = CCoeEnv::Static()->Fep();
   725         if (fep)
   769         if (fep)