Support better committing preedit in QLineController
authorPekka Vuorela <pekka.ta.vuorela@nokia.com>
Tue, 15 Nov 2011 16:05:27 +0000 (18:05 +0200)
committerQt by Nokia <qt-info@nokia.com>
Mon, 21 Nov 2011 21:45:41 +0000 (22:45 +0100)
Similar as 7851568c65e0560056c6fa541039543d43a63e20 for
QWidgetLineController

Change-Id: I7c1a1dc22e9b73515a5a72093866ac747a80896f
Reviewed-by: Lars Knoll <lars.knoll@nokia.com>
src/gui/text/qlinecontrol.cpp
src/gui/text/qlinecontrol_p.h

index 91a07d9..62f4515 100644 (file)
@@ -151,6 +151,30 @@ void QLineControl::paste(QClipboard::Mode clipboardMode)
 /*!
     \internal
 
+    Exits preedit mode and commits parts marked as tentative commit
+*/
+void QLineControl::commitPreedit()
+{
+    if (!composeMode())
+        return;
+
+    qApp->inputPanel()->reset();
+
+    if (!m_tentativeCommit.isEmpty()) {
+        internalInsert(m_tentativeCommit);
+        m_tentativeCommit.clear();
+        finishChange(-1, true/*not used, not documented*/, false);
+    }
+
+    m_preeditCursor = 0;
+    setPreeditArea(-1, QString());
+    m_textLayout.clearAdditionalFormats();
+    updateDisplayText(/*force*/ true);
+}
+
+/*!
+    \internal
+
     Handles the behavior for the backspace key or function.
     Removes the current selection if there is a selection, otherwise
     removes the character prior to the cursor position.
@@ -243,6 +267,8 @@ void QLineControl::clear()
 */
 void QLineControl::setSelection(int start, int length)
 {
+    commitPreedit();
+
     if(start < 0 || start > (int)m_text.length()){
         qWarning("QLineControl::setSelection: Invalid start position");
         return;
@@ -403,6 +429,8 @@ bool QLineControl::fixup() // this function assumes that validate currently retu
 */
 void QLineControl::moveCursor(int pos, bool mark)
 {
+    commitPreedit();
+
     if (pos != m_cursor) {
         separate();
         if (m_maskData)
index 7f5244e..4970a8c 100644 (file)
@@ -209,6 +209,7 @@ public:
     QString text() const;
     QString realText() const;
     void setText(const QString &txt);
+    void commitPreedit();
 
     QString displayText() const { return m_textLayout.text(); }