src/gui/inputmethod/qcoefepinputcontext_s60.cpp
changeset 33 3e2da88830cd
parent 25 e24348a560a6
child 37 758a864f9613
equal deleted inserted replaced
30:5dc02b23752f 33:3e2da88830cd
    42 #ifndef QT_NO_IM
    42 #ifndef QT_NO_IM
    43 
    43 
    44 #include "qcoefepinputcontext_p.h"
    44 #include "qcoefepinputcontext_p.h"
    45 #include <qapplication.h>
    45 #include <qapplication.h>
    46 #include <qtextformat.h>
    46 #include <qtextformat.h>
       
    47 #include <qgraphicsview.h>
       
    48 #include <qgraphicsscene.h>
       
    49 #include <qgraphicswidget.h>
    47 #include <private/qcore_symbian_p.h>
    50 #include <private/qcore_symbian_p.h>
    48 
    51 
    49 #include <fepitfr.h>
    52 #include <fepitfr.h>
    50 #include <hal.h>
    53 #include <hal.h>
    51 
    54 
   292 
   295 
   293     if (!m_hasTempPreeditString)
   296     if (!m_hasTempPreeditString)
   294         return;
   297         return;
   295 
   298 
   296     commitCurrentString(false);
   299     commitCurrentString(false);
       
   300 
       
   301     //update cursor position, now this pre-edit text has been committed.
       
   302     //this prevents next keypress overwriting it (QTBUG-11673)
       
   303     m_cursorPos = focusWidget()->inputMethodQuery(Qt::ImCursorPosition).toInt();
   297 }
   304 }
   298 
   305 
   299 void QCoeFepInputContext::mouseHandler( int x, QMouseEvent *event)
   306 void QCoeFepInputContext::mouseHandler( int x, QMouseEvent *event)
   300 {
   307 {
   301     Q_ASSERT(focusWidget());
   308     Q_ASSERT(focusWidget());
   318     }
   325     }
   319 
   326 
   320     return TCoeInputCapabilities(m_textCapabilities, this, 0);
   327     return TCoeInputCapabilities(m_textCapabilities, this, 0);
   321 }
   328 }
   322 
   329 
   323 static QTextCharFormat qt_TCharFormat2QTextCharFormat(const TCharFormat &cFormat)
   330 static QTextCharFormat qt_TCharFormat2QTextCharFormat(const TCharFormat &cFormat, bool validStyleColor)
   324 {
   331 {
   325     QTextCharFormat qFormat;
   332     QTextCharFormat qFormat;
   326 
   333 
   327     QBrush foreground(QColor(cFormat.iFontPresentation.iTextColor.Internal()));
   334     if (validStyleColor) {
   328     qFormat.setForeground(foreground);
   335         QBrush foreground(QColor(cFormat.iFontPresentation.iTextColor.Internal()));
       
   336         qFormat.setForeground(foreground);
       
   337     }
   329 
   338 
   330     qFormat.setFontStrikeOut(cFormat.iFontPresentation.iStrikethrough == EStrikethroughOn);
   339     qFormat.setFontStrikeOut(cFormat.iFontPresentation.iStrikethrough == EStrikethroughOn);
   331     qFormat.setFontUnderline(cFormat.iFontPresentation.iUnderline == EUnderlineOn);
   340     qFormat.setFontUnderline(cFormat.iFontPresentation.iUnderline == EUnderlineOn);
   332 
   341 
   333     return qFormat;
   342     return qFormat;
   482 }
   491 }
   483 
   492 
   484 void QCoeFepInputContext::applyFormat(QList<QInputMethodEvent::Attribute> *attributes)
   493 void QCoeFepInputContext::applyFormat(QList<QInputMethodEvent::Attribute> *attributes)
   485 {
   494 {
   486     TCharFormat cFormat;
   495     TCharFormat cFormat;
   487     const QColor styleTextColor = focusWidget() ? focusWidget()->palette().text().color() : 
   496     QColor styleTextColor;
   488         QApplication::palette("QLineEdit").text().color();
   497     if (QWidget *focused = focusWidget()) {
   489     const TLogicalRgb fontColor(TRgb(styleTextColor.red(), styleTextColor.green(), styleTextColor.blue(), styleTextColor.alpha()));
   498         QGraphicsView *gv = qobject_cast<QGraphicsView*>(focused);
   490     cFormat.iFontPresentation.iTextColor = fontColor;
   499         if (!gv) // could be either the QGV or its viewport that has focus
       
   500             gv = qobject_cast<QGraphicsView*>(focused->parentWidget());
       
   501         if (gv) {
       
   502             if (QGraphicsScene *scene = gv->scene()) {
       
   503                 if (QGraphicsItem *focusItem = scene->focusItem()) {
       
   504                     if (focusItem->isWidget()) {
       
   505                         styleTextColor = static_cast<QGraphicsWidget*>(focusItem)->palette().text().color();
       
   506                     }
       
   507                 }
       
   508             }
       
   509         } else {
       
   510             styleTextColor = focused->palette().text().color();
       
   511         }
       
   512     } else {
       
   513         styleTextColor = QApplication::palette("QLineEdit").text().color();
       
   514     }
       
   515 
       
   516     if (styleTextColor.isValid()) {
       
   517         const TLogicalRgb fontColor(TRgb(styleTextColor.red(), styleTextColor.green(), styleTextColor.blue(), styleTextColor.alpha()));
       
   518         cFormat.iFontPresentation.iTextColor = fontColor;
       
   519     }
   491 
   520 
   492     TInt numChars = 0;
   521     TInt numChars = 0;
   493     TInt charPos = 0;
   522     TInt charPos = 0;
   494     int oldSize = attributes->size();
   523     int oldSize = attributes->size();
   495     while (m_formatRetriever) {
   524     while (m_formatRetriever) {
   499             break;
   528             break;
   500         }
   529         }
   501         attributes->append(QInputMethodEvent::Attribute(QInputMethodEvent::TextFormat,
   530         attributes->append(QInputMethodEvent::Attribute(QInputMethodEvent::TextFormat,
   502                                                         charPos,
   531                                                         charPos,
   503                                                         numChars,
   532                                                         numChars,
   504                                                         QVariant(qt_TCharFormat2QTextCharFormat(cFormat))));
   533                                                         QVariant(qt_TCharFormat2QTextCharFormat(cFormat, styleTextColor.isValid()))));
   505         charPos += numChars;
   534         charPos += numChars;
   506         if (charPos >= m_preeditString.size()) {
   535         if (charPos >= m_preeditString.size()) {
   507             break;
   536             break;
   508         }
   537         }
   509     }
   538     }