Changeset 846 for trunk/src/gui/inputmethod/qcoefepinputcontext_s60.cpp
- Timestamp:
- May 5, 2011, 5:36:53 AM (14 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk
- Property svn:mergeinfo changed
/branches/vendor/nokia/qt/4.7.2 (added) merged: 845 /branches/vendor/nokia/qt/current merged: 844 /branches/vendor/nokia/qt/4.6.3 removed
- Property svn:mergeinfo changed
-
trunk/src/gui/inputmethod/qcoefepinputcontext_s60.cpp
r769 r846 1 1 /**************************************************************************** 2 2 ** 3 ** Copyright (C) 201 0Nokia Corporation and/or its subsidiary(-ies).3 ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). 4 4 ** All rights reserved. 5 5 ** Contact: Nokia Corporation (qt-info@nokia.com) … … 45 45 #include <qapplication.h> 46 46 #include <qtextformat.h> 47 #include <qgraphicsview.h> 48 #include <qgraphicsscene.h> 49 #include <qgraphicswidget.h> 50 #include <qsymbianevent.h> 47 51 #include <private/qcore_symbian_p.h> 48 52 … … 77 81 m_formatRetriever(0), 78 82 m_pointerHandler(0), 79 m_cursorPos(0),80 83 m_hasTempPreeditString(false) 81 84 { … … 87 90 m_fepState->SetDefaultInputMode( EAknEditorTextInputMode ); 88 91 m_fepState->SetPermittedInputModes( EAknEditorAllInputModes ); 89 m_fepState->SetDefaultCase( EAknEditor LowerCase );92 m_fepState->SetDefaultCase( EAknEditorTextCase ); 90 93 m_fepState->SetPermittedCases( EAknEditorAllCaseModes ); 91 94 m_fepState->SetSpecialCharacterTableResourceId(R_AVKON_SPECIAL_CHARACTER_TABLE_DIALOG); … … 235 238 } 236 239 240 QString widgetText = focusWidget()->inputMethodQuery(Qt::ImSurroundingText).toString(); 241 bool validLength; 242 int maxLength = focusWidget()->inputMethodQuery(Qt::ImMaximumTextLength).toInt(&validLength); 243 if (!keyEvent->text().isEmpty() && validLength 244 && widgetText.size() + m_preeditString.size() >= maxLength) { 245 // Don't send key events with string content if the widget is "full". 246 return true; 247 } 248 237 249 if (keyEvent->type() == QEvent::KeyPress 238 250 && focusWidget()->inputMethodHints() & Qt::ImhHiddenText 239 251 && !keyEvent->text().isEmpty()) { 240 252 // Send some temporary preedit text in order to make text visible for a moment. 241 m_cursorPos = focusWidget()->inputMethodQuery(Qt::ImCursorPosition).toInt();242 253 m_preeditString = keyEvent->text(); 243 254 QList<QInputMethodEvent::Attribute> attributes; … … 280 291 } 281 292 293 bool QCoeFepInputContext::symbianFilterEvent(QWidget *keyWidget, const QSymbianEvent *event) 294 { 295 Q_UNUSED(keyWidget); 296 if (event->type() == QSymbianEvent::CommandEvent) 297 // A command basically means the same as a button being pushed. With Qt buttons 298 // that would normally result in a reset of the input method due to the focus change. 299 // This should also happen for commands. 300 reset(); 301 302 return false; 303 } 304 282 305 void QCoeFepInputContext::timerEvent(QTimerEvent *timerEvent) 283 306 { … … 321 344 } 322 345 323 static QTextCharFormat qt_TCharFormat2QTextCharFormat(const TCharFormat &cFormat )346 static QTextCharFormat qt_TCharFormat2QTextCharFormat(const TCharFormat &cFormat, bool validStyleColor) 324 347 { 325 348 QTextCharFormat qFormat; 326 349 327 QBrush foreground(QColor(cFormat.iFontPresentation.iTextColor.Internal())); 328 qFormat.setForeground(foreground); 350 if (validStyleColor) { 351 QBrush foreground(QColor(cFormat.iFontPresentation.iTextColor.Internal())); 352 qFormat.setForeground(foreground); 353 } 329 354 330 355 qFormat.setFontStrikeOut(cFormat.iFontPresentation.iStrikethrough == EStrikethroughOn); … … 356 381 commitTemporaryPreeditString(); 357 382 358 bool numbersOnly = hints & ImhDigitsOnly || hints & ImhFormattedNumbersOnly 359 || hints & ImhDialableCharactersOnly; 360 bool noOnlys = !(numbersOnly || hints & ImhUppercaseOnly 361 || hints & ImhLowercaseOnly); 383 const bool anynumbermodes = hints & (ImhDigitsOnly | ImhFormattedNumbersOnly | ImhDialableCharactersOnly); 384 const bool anytextmodes = hints & (ImhUppercaseOnly | ImhLowercaseOnly | ImhEmailCharactersOnly | ImhUrlCharactersOnly); 385 const bool numbersOnly = anynumbermodes && !anytextmodes; 386 const bool noOnlys = !(hints & ImhExclusiveInputMask); 387 // if alphanumeric input, or if multiple incompatible number modes are selected; 388 // then make all symbols available in numeric mode too. 389 const bool needsCharMap= !numbersOnly || ((hints & ImhFormattedNumbersOnly) && (hints & ImhDialableCharactersOnly)); 362 390 TInt flags; 363 391 Qt::InputMethodHints oldHints = hints; … … 371 399 if (!noOnlys) { 372 400 // Make sure that the preference is within the permitted set. 373 if (hints & ImhPreferNumbers && !(hints & ImhDigitsOnly || hints & ImhFormattedNumbersOnly 374 || hints & ImhDialableCharactersOnly)) { 401 if (hints & ImhPreferNumbers && !anynumbermodes) { 375 402 hints &= ~ImhPreferNumbers; 376 403 } else if (hints & ImhPreferUppercase && !(hints & ImhUppercaseOnly)) { … … 385 412 } else if (hints & ImhUppercaseOnly) { 386 413 hints |= ImhPreferUppercase; 387 } else if (hints & ImhDigitsOnly || hints & ImhFormattedNumbersOnly 388 || hints & ImhDialableCharactersOnly) { 414 } else if (numbersOnly) { 389 415 hints |= ImhPreferNumbers; 390 416 } … … 400 426 } 401 427 flags = 0; 402 if (numbersOnly) { 428 if (noOnlys || (anynumbermodes && anytextmodes)) { 429 flags = EAknEditorAllInputModes; 430 } 431 else if (anynumbermodes) { 403 432 flags |= EAknEditorNumericInputMode; 404 } 405 if (hints & ImhUppercaseOnly || hints & ImhLowercaseOnly) { 433 if (QSysInfo::s60Version() > QSysInfo::SV_S60_5_0 434 && ((hints & ImhFormattedNumbersOnly) || (hints & ImhDialableCharactersOnly))) { 435 //workaround - the * key does not launch the symbols menu, making it impossible to use these modes unless text mode is enabled. 436 flags |= EAknEditorTextInputMode; 437 } 438 } 439 else if (anytextmodes) { 406 440 flags |= EAknEditorTextInputMode; 407 441 } 408 if (flags == 0){442 else { 409 443 flags = EAknEditorAllInputModes; 410 444 } … … 453 487 flags |= EAknEditorFlagNoT9; 454 488 } 489 if (needsCharMap) 490 flags |= EAknEditorFlagUseSCTNumericCharmap; 455 491 m_fepState->SetFlags(flags); 456 492 ReportAknEdStateEvent(MAknEdStateObserver::EAknEdwinStateFlagsUpdate); 457 493 458 if (hints & ImhFormattedNumbersOnly) { 494 if (hints & ImhDialableCharactersOnly) { 495 // This is first, because if (ImhDialableCharactersOnly | ImhFormattedNumbersOnly) 496 // is specified, this one is more natural (# key enters a #) 497 flags = EAknEditorStandardNumberModeKeymap; 498 } else if (hints & ImhFormattedNumbersOnly) { 499 // # key enters decimal point 459 500 flags = EAknEditorCalculatorNumberModeKeymap; 460 501 } else if (hints & ImhDigitsOnly) { 502 // This is last, because it is most restrictive (# key is inactive) 461 503 flags = EAknEditorPlainNumberModeKeymap; 462 504 } else { 463 // ImhDialableCharactersOnly is the fallback as well, so we don't need to check for464 // that flag.465 505 flags = EAknEditorStandardNumberModeKeymap; 466 506 } 467 507 m_fepState->SetNumericKeymap(static_cast<TAknEditorNumericKeymap>(flags)); 468 508 469 if (hints & ImhEmailCharactersOnly) { 509 if (hints & ImhUrlCharactersOnly) { 510 // URL characters is everything except space, so a superset of the other restrictions 511 m_fepState->SetSpecialCharacterTableResourceId(R_AVKON_URL_SPECIAL_CHARACTER_TABLE_DIALOG); 512 } else if (hints & ImhEmailCharactersOnly) { 470 513 m_fepState->SetSpecialCharacterTableResourceId(R_AVKON_EMAIL_ADDR_SPECIAL_CHARACTER_TABLE_DIALOG); 471 } else if ( hints & ImhUrlCharactersOnly) {472 m_fepState->SetSpecialCharacterTableResourceId(R_AVKON_ URL_SPECIAL_CHARACTER_TABLE_DIALOG);514 } else if (needsCharMap) { 515 m_fepState->SetSpecialCharacterTableResourceId(R_AVKON_SPECIAL_CHARACTER_TABLE_DIALOG); 473 516 } else { 474 m_fepState->SetSpecialCharacterTableResourceId( R_AVKON_SPECIAL_CHARACTER_TABLE_DIALOG);517 m_fepState->SetSpecialCharacterTableResourceId(0); 475 518 } 476 519 … … 485 528 { 486 529 TCharFormat cFormat; 487 const QColor styleTextColor = focusWidget() ? focusWidget()->palette().text().color() : 488 QApplication::palette("QLineEdit").text().color(); 489 const TLogicalRgb fontColor(TRgb(styleTextColor.red(), styleTextColor.green(), styleTextColor.blue(), styleTextColor.alpha())); 490 cFormat.iFontPresentation.iTextColor = fontColor; 530 QColor styleTextColor; 531 if (QWidget *focused = focusWidget()) { 532 QGraphicsView *gv = qobject_cast<QGraphicsView*>(focused); 533 if (!gv) // could be either the QGV or its viewport that has focus 534 gv = qobject_cast<QGraphicsView*>(focused->parentWidget()); 535 if (gv) { 536 if (QGraphicsScene *scene = gv->scene()) { 537 if (QGraphicsItem *focusItem = scene->focusItem()) { 538 if (focusItem->isWidget()) { 539 styleTextColor = static_cast<QGraphicsWidget*>(focusItem)->palette().text().color(); 540 } 541 } 542 } 543 } else { 544 styleTextColor = focused->palette().text().color(); 545 } 546 } else { 547 styleTextColor = QApplication::palette("QLineEdit").text().color(); 548 } 549 550 if (styleTextColor.isValid()) { 551 const TLogicalRgb fontColor(TRgb(styleTextColor.red(), styleTextColor.green(), styleTextColor.blue(), styleTextColor.alpha())); 552 cFormat.iFontPresentation.iTextColor = fontColor; 553 } 491 554 492 555 TInt numChars = 0; … … 502 565 charPos, 503 566 numChars, 504 QVariant(qt_TCharFormat2QTextCharFormat(cFormat ))));567 QVariant(qt_TCharFormat2QTextCharFormat(cFormat, styleTextColor.isValid())))); 505 568 charPos += numChars; 506 569 if (charPos >= m_preeditString.size()) { … … 553 616 commitTemporaryPreeditString(); 554 617 555 m_cursorPos = w->inputMethodQuery(Qt::ImCursorPosition).toInt();556 557 618 QList<QInputMethodEvent::Attribute> attributes; 558 619 … … 569 630 if (m_preeditString.isEmpty()) { 570 631 int anchor = w->inputMethodQuery(Qt::ImAnchorPosition).toInt(); 571 int replacementLength = qAbs(m_cursorPos-anchor); 632 int cursorPos = w->inputMethodQuery(Qt::ImCursorPosition).toInt(); 633 int replacementLength = qAbs(cursorPos-anchor); 572 634 if (replacementLength > 0) { 573 int replacementStart = m_cursorPos < anchor ? 0 : -replacementLength;635 int replacementStart = cursorPos < anchor ? 0 : -replacementLength; 574 636 QList<QInputMethodEvent::Attribute> clearSelectionAttributes; 575 637 QInputMethodEvent clearSelectionEvent(QLatin1String(""), clearSelectionAttributes); … … 596 658 return; 597 659 660 commitTemporaryPreeditString(); 661 598 662 m_inlinePosition = aPositionOfInsertionPointInInlineText; 599 663 … … 604 668 m_cursorVisibility, 605 669 QVariant())); 606 m_preeditString = qt_TDesC2QString(aNewInlineText); 607 QInputMethodEvent event(m_preeditString, attributes); 670 QString newPreeditString = qt_TDesC2QString(aNewInlineText); 671 QInputMethodEvent event(newPreeditString, attributes); 672 if (newPreeditString.isEmpty() && m_preeditString.isEmpty()) { 673 // In Symbian world this means "erase last character". 674 event.setCommitString(QLatin1String(""), -1, 1); 675 } 676 m_preeditString = newPreeditString; 608 677 sendEvent(event); 609 678 } … … 628 697 void QCoeFepInputContext::CancelFepInlineEdit() 629 698 { 699 // We are not supposed to ever have a tempPreeditString and a real preedit string 700 // from S60 at the same time, so it should be safe to rely on this test to determine 701 // whether we should honor S60's request to clear the text or not. 702 if (m_hasTempPreeditString) 703 return; 704 630 705 QList<QInputMethodEvent::Attribute> attributes; 631 706 QInputMethodEvent event(QLatin1String(""), attributes); 632 707 event.setCommitString(QLatin1String(""), 0, 0); 633 708 m_preeditString.clear(); 709 m_inlinePosition = 0; 634 710 sendEvent(event); 635 711 } … … 775 851 void QCoeFepInputContext::commitCurrentString(bool cancelFepTransaction) 776 852 { 777 int longPress = 0;778 779 if (m_preeditString.size() == 0) {780 QWidget *w = focusWidget();781 if (!cancelFepTransaction && w) {782 // We must replace the last character only if the input box has already accepted one783 if (w->inputMethodQuery(Qt::ImCursorPosition).toInt() != m_cursorPos)784 longPress = 1;785 }786 }787 788 853 QList<QInputMethodEvent::Attribute> attributes; 789 854 QInputMethodEvent event(QLatin1String(""), attributes); 790 event.setCommitString(m_preeditString, 0 -longPress, longPress);855 event.setCommitString(m_preeditString, 0, 0); 791 856 m_preeditString.clear(); 857 m_inlinePosition = 0; 792 858 sendEvent(event); 793 859 794 860 m_hasTempPreeditString = false; 795 longPress = 0;796 861 797 862 if (cancelFepTransaction) {
Note:
See TracChangeset
for help on using the changeset viewer.