From b5c37d9e137dee2754335e83b8437dfd0e6cc7e7 Mon Sep 17 00:00:00 2001 From: Pekka Vuorela Date: Tue, 8 Nov 2011 16:47:10 +0200 Subject: QTextEdit to use tentative commit instead of QInputPanel::commit() Latter to be deprecated. Change-Id: I2c302c73a7ab2f4201af6a3c6fb4a64a4760263e Reviewed-by: Lars Knoll --- src/widgets/widgets/qwidgettextcontrol.cpp | 29 +++++++++++++++++++++++----- src/widgets/widgets/qwidgettextcontrol_p_p.h | 1 + 2 files changed, 25 insertions(+), 5 deletions(-) diff --git a/src/widgets/widgets/qwidgettextcontrol.cpp b/src/widgets/widgets/qwidgettextcontrol.cpp index b6432ee53f..258ab1bb11 100644 --- a/src/widgets/widgets/qwidgettextcontrol.cpp +++ b/src/widgets/widgets/qwidgettextcontrol.cpp @@ -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); diff --git a/src/widgets/widgets/qwidgettextcontrol_p_p.h b/src/widgets/widgets/qwidgettextcontrol_p_p.h index f53e0808b8..cf493aff71 100644 --- a/src/widgets/widgets/qwidgettextcontrol_p_p.h +++ b/src/widgets/widgets/qwidgettextcontrol_p_p.h @@ -170,6 +170,7 @@ public: #endif bool isPreediting() const; + void commitPreedit(); void append(const QString &text, Qt::TextFormat format = Qt::AutoText); -- cgit v1.2.3