src/gui/inputmethod/qcoefepinputcontext_s60.cpp
changeset 33 3e2da88830cd
parent 25 e24348a560a6
child 37 758a864f9613
--- a/src/gui/inputmethod/qcoefepinputcontext_s60.cpp	Tue Jul 06 15:10:48 2010 +0300
+++ b/src/gui/inputmethod/qcoefepinputcontext_s60.cpp	Wed Aug 18 10:37:55 2010 +0300
@@ -44,6 +44,9 @@
 #include "qcoefepinputcontext_p.h"
 #include <qapplication.h>
 #include <qtextformat.h>
+#include <qgraphicsview.h>
+#include <qgraphicsscene.h>
+#include <qgraphicswidget.h>
 #include <private/qcore_symbian_p.h>
 
 #include <fepitfr.h>
@@ -294,6 +297,10 @@
         return;
 
     commitCurrentString(false);
+
+    //update cursor position, now this pre-edit text has been committed.
+    //this prevents next keypress overwriting it (QTBUG-11673)
+    m_cursorPos = focusWidget()->inputMethodQuery(Qt::ImCursorPosition).toInt();
 }
 
 void QCoeFepInputContext::mouseHandler( int x, QMouseEvent *event)
@@ -320,12 +327,14 @@
     return TCoeInputCapabilities(m_textCapabilities, this, 0);
 }
 
-static QTextCharFormat qt_TCharFormat2QTextCharFormat(const TCharFormat &cFormat)
+static QTextCharFormat qt_TCharFormat2QTextCharFormat(const TCharFormat &cFormat, bool validStyleColor)
 {
     QTextCharFormat qFormat;
 
-    QBrush foreground(QColor(cFormat.iFontPresentation.iTextColor.Internal()));
-    qFormat.setForeground(foreground);
+    if (validStyleColor) {
+        QBrush foreground(QColor(cFormat.iFontPresentation.iTextColor.Internal()));
+        qFormat.setForeground(foreground);
+    }
 
     qFormat.setFontStrikeOut(cFormat.iFontPresentation.iStrikethrough == EStrikethroughOn);
     qFormat.setFontUnderline(cFormat.iFontPresentation.iUnderline == EUnderlineOn);
@@ -484,10 +493,30 @@
 void QCoeFepInputContext::applyFormat(QList<QInputMethodEvent::Attribute> *attributes)
 {
     TCharFormat cFormat;
-    const QColor styleTextColor = focusWidget() ? focusWidget()->palette().text().color() : 
-        QApplication::palette("QLineEdit").text().color();
-    const TLogicalRgb fontColor(TRgb(styleTextColor.red(), styleTextColor.green(), styleTextColor.blue(), styleTextColor.alpha()));
-    cFormat.iFontPresentation.iTextColor = fontColor;
+    QColor styleTextColor;
+    if (QWidget *focused = focusWidget()) {
+        QGraphicsView *gv = qobject_cast<QGraphicsView*>(focused);
+        if (!gv) // could be either the QGV or its viewport that has focus
+            gv = qobject_cast<QGraphicsView*>(focused->parentWidget());
+        if (gv) {
+            if (QGraphicsScene *scene = gv->scene()) {
+                if (QGraphicsItem *focusItem = scene->focusItem()) {
+                    if (focusItem->isWidget()) {
+                        styleTextColor = static_cast<QGraphicsWidget*>(focusItem)->palette().text().color();
+                    }
+                }
+            }
+        } else {
+            styleTextColor = focused->palette().text().color();
+        }
+    } else {
+        styleTextColor = QApplication::palette("QLineEdit").text().color();
+    }
+
+    if (styleTextColor.isValid()) {
+        const TLogicalRgb fontColor(TRgb(styleTextColor.red(), styleTextColor.green(), styleTextColor.blue(), styleTextColor.alpha()));
+        cFormat.iFontPresentation.iTextColor = fontColor;
+    }
 
     TInt numChars = 0;
     TInt charPos = 0;
@@ -501,7 +530,7 @@
         attributes->append(QInputMethodEvent::Attribute(QInputMethodEvent::TextFormat,
                                                         charPos,
                                                         numChars,
-                                                        QVariant(qt_TCharFormat2QTextCharFormat(cFormat))));
+                                                        QVariant(qt_TCharFormat2QTextCharFormat(cFormat, styleTextColor.isValid()))));
         charPos += numChars;
         if (charPos >= m_preeditString.size()) {
             break;