QTextEdit to use tentative commit instead of QInputPanel::commit()
authorPekka Vuorela <pekka.ta.vuorela@nokia.com>
Tue, 8 Nov 2011 14:47:10 +0000 (16:47 +0200)
committerQt by Nokia <qt-info@nokia.com>
Thu, 10 Nov 2011 12:07:30 +0000 (13:07 +0100)
Latter to be deprecated.

Change-Id: I2c302c73a7ab2f4201af6a3c6fb4a64a4760263e
Reviewed-by: Lars Knoll <lars.knoll@nokia.com>
src/widgets/widgets/qwidgettextcontrol.cpp
src/widgets/widgets/qwidgettextcontrol_p_p.h

index b6432ee..258ab1b 100644 (file)
@@ -1537,8 +1537,7 @@ void QWidgetTextControlPrivate::mousePressEvent(QEvent *e, Qt::MouseButton butto
     const QTextCursor oldSelection = cursor;
     const int oldCursorPos = cursor.position();
 
-    if (isPreediting())
-        qApp->inputPanel()->commit();
+    commitPreedit();
 
     if (trippleClickTimer.isActive()
         && ((pos - trippleClickPoint).toPoint().manhattanLength() < QApplication::startDragDistance())) {
@@ -1648,7 +1647,7 @@ void QWidgetTextControlPrivate::mouseMoveEvent(QEvent *e, Qt::MouseButton button
             int selectionStartPos = q->hitTest(mousePressPos, Qt::FuzzyHit);
 
             if (newCursorPos != selectionStartPos) {
-                qApp->inputPanel()->commit();
+                commitPreedit();
                 // commit invalidates positions
                 newCursorPos = q->hitTest(mousePos, Qt::FuzzyHit);
                 selectionStartPos = q->hitTest(mousePressPos, Qt::FuzzyHit);
@@ -1774,8 +1773,7 @@ void QWidgetTextControlPrivate::mouseDoubleClickEvent(QEvent *e, Qt::MouseButton
 #ifndef QT_NO_DRAGANDDROP
         mightStartDrag = false;
 #endif
-        if (isPreediting())
-            qApp->inputPanel()->commit();
+        commitPreedit();
 
         const QTextCursor oldSelection = cursor;
         setCursorPosition(pos);
@@ -2752,6 +2750,27 @@ bool QWidgetTextControlPrivate::isPreediting() const
     return false;
 }
 
+void QWidgetTextControlPrivate::commitPreedit()
+{
+    if (!isPreediting())
+        return;
+
+    cursor.beginEditBlock();
+    qApp->inputPanel()->reset();
+
+    if (!tentativeCommit.isEmpty()) {
+        cursor.insertText(tentativeCommit);
+        tentativeCommit.clear();
+    }
+
+    preeditCursor = 0;
+    QTextBlock block = cursor.block();
+    QTextLayout *layout = block.layout();
+    layout->setPreeditArea(-1, QString());
+    layout->clearAdditionalFormats();
+    cursor.endEditBlock();
+}
+
 bool QWidgetTextControl::setFocusToNextOrPreviousAnchor(bool next)
 {
     Q_D(QWidgetTextControl);
index f53e080..cf493af 100644 (file)
@@ -170,6 +170,7 @@ public:
 #endif
 
     bool isPreediting() const;
+    void commitPreedit();
 
     void append(const QString &text, Qt::TextFormat format = Qt::AutoText);