path: root/src/gui/text/qtextdocument_p.cpp
diff options
authorJiang Jiang <>2010-12-15 15:11:45 +0100
committerJiang Jiang <>2011-04-29 11:02:23 +0200
commit0f7cba14f612885151a95c590b23c5fe25efdd05 (patch)
tree5dd6063357b8f554cc729d4bffe9ced2c7b988f9 /src/gui/text/qtextdocument_p.cpp
parent028aa80d700ad8d6799202f1fa1beb919e6ee531 (diff)
Support visual cursor movement for BIDI text
Bidi input can in some contexts be more intuitive if the cursor works in visual way: pressing left arrow key always make cursor move one character to the left regardless the language of text, pressing right arrow key always make cursor move to the right. It is also the behavior of Mac OS X. Based on the above reason and requests from Symbian we implemented this support for visual movement in BIDI text. 3 public properties are added to QTextDocument, QTextLayout and QLineEdit respectively: - QTextDocument::defaultCursorMoveStyle can be used to control the cursor behavior in all widgets based on QTextDocument, like QTextEdit, QPlainTextEdit, etc. When set to QTextCursor:: Visual, it will enable visual movement for all the cursors in the corresponding text edit. Default is QTextCursor::Logical. - QTextLayout::cursorMoveStyle is used for low-level cursor manipulation. When set to Visual, it will enable visual movement behavior for all the cursor related methods, including cursorToX, xToCursor and drawCursor. Default is Logical. - QLineEdit::cursorMoveStyle is used to control cursor movement behavior in QLineEdit. Default is Logical.: Task-number: QTBUG-13859 Reviewed-by: Eskil (cherry picked from commit c480dd641f5d22d1ee72cb27bf39e24c6df65658)
Diffstat (limited to 'src/gui/text/qtextdocument_p.cpp')
1 files changed, 15 insertions, 0 deletions
diff --git a/src/gui/text/qtextdocument_p.cpp b/src/gui/text/qtextdocument_p.cpp
index a997720c12..779b1fff35 100644
--- a/src/gui/text/qtextdocument_p.cpp
+++ b/src/gui/text/qtextdocument_p.cpp
@@ -209,6 +209,7 @@ QTextDocumentPrivate::QTextDocumentPrivate()
defaultTextOption.setTabStop(80); // same as in qtextengine.cpp
+ defaultCursorMoveStyle = QTextCursor::Logical;
indentWidth = 40;
documentMargin = 4;
@@ -1382,6 +1383,20 @@ int QTextDocumentPrivate::previousCursorPosition(int position, QTextLayout::Curs
return it.layout()->previousCursorPosition(position-start, mode) + start;
+int QTextDocumentPrivate::leftCursorPosition(int position) const
+ QTextBlock it = blocksFind(position);
+ int start = it.position();
+ return it.layout()->leftCursorPosition(position-start) + start;
+int QTextDocumentPrivate::rightCursorPosition(int position) const
+ QTextBlock it = blocksFind(position);
+ int start = it.position();
+ return it.layout()->rightCursorPosition(position-start) + start;
void QTextDocumentPrivate::changeObjectFormat(QTextObject *obj, int format)