diff options
author | Qt Continuous Integration System <qt-info@nokia.com> | 2010-06-01 23:34:54 (GMT) |
---|---|---|
committer | Qt Continuous Integration System <qt-info@nokia.com> | 2010-06-01 23:34:54 (GMT) |
commit | 0fd09af3a05ac88c55fed73c85dc1c5aba68f057 (patch) | |
tree | 593ea0c942dfddef8d31b0088dd984fcdcb5756d | |
parent | 6982c5e7f9d93d26ab5f241af0a5c6e80cd0e1ff (diff) | |
parent | 3f329793dbc8ffdf65d4ac2c46894ad46c3dfe07 (diff) | |
download | Qt-0fd09af3a05ac88c55fed73c85dc1c5aba68f057.zip Qt-0fd09af3a05ac88c55fed73c85dc1c5aba68f057.tar.gz Qt-0fd09af3a05ac88c55fed73c85dc1c5aba68f057.tar.bz2 |
Merge branch '4.7' of scm.dev.nokia.troll.no:qt/qt-qml into 4.7-integration
* '4.7' of scm.dev.nokia.troll.no:qt/qt-qml:
Introduced getter and setter for the visual X cursor position.
Defines whether the cursor should keep its current position.
-rw-r--r-- | src/gui/text/qtextcursor.cpp | 87 | ||||
-rw-r--r-- | src/gui/text/qtextcursor.h | 6 | ||||
-rw-r--r-- | src/gui/text/qtextcursor_p.h | 3 | ||||
-rw-r--r-- | tests/auto/qtextcursor/tst_qtextcursor.cpp | 8 |
4 files changed, 94 insertions, 10 deletions
diff --git a/src/gui/text/qtextcursor.cpp b/src/gui/text/qtextcursor.cpp index c91df3c..d6ac3aa 100644 --- a/src/gui/text/qtextcursor.cpp +++ b/src/gui/text/qtextcursor.cpp @@ -64,7 +64,7 @@ enum { QTextCursorPrivate::QTextCursorPrivate(QTextDocumentPrivate *p) : priv(p), x(0), position(0), anchor(0), adjusted_anchor(0), - currentCharFormat(-1), visualNavigation(false) + currentCharFormat(-1), visualNavigation(false), keepPositionOnInsert(false) { priv->addCursor(this); } @@ -79,6 +79,7 @@ QTextCursorPrivate::QTextCursorPrivate(const QTextCursorPrivate &rhs) x = rhs.x; currentCharFormat = rhs.currentCharFormat; visualNavigation = rhs.visualNavigation; + keepPositionOnInsert = rhs.keepPositionOnInsert; priv->addCursor(this); } @@ -95,7 +96,7 @@ QTextCursorPrivate::AdjustResult QTextCursorPrivate::adjustPosition(int position if (position < positionOfChange || (position == positionOfChange && (op == QTextUndoCommand::KeepCursor - || anchor < position) + || keepPositionOnInsert) ) ) { result = CursorUnchanged; @@ -1276,6 +1277,80 @@ void QTextCursor::setVisualNavigation(bool b) d->visualNavigation = b; } + +/*! + \since 4.7 + + Sets the visual x position for vertical cursor movements. + + The vertical movement x position is cleared automatically when the cursor moves horizontally, and kept + unchanged when the cursor moves vertically. The mechanism allows the cursor to move up and down on a + visually straight line with proportional fonts, and to gently "jump" over short lines. + + A value of -1 indicates no predefined x position. It will then be set automatically the next time the + cursor moves up or down. + + \sa verticalMovementX() + */ +void QTextCursor::setVerticalMovementX(int x) +{ + if (d) + d->x = x; +} + +/*! \since 4.7 + + Returns the visual x position for vertical cursor movements. + + A value of -1 indicates no predefined x position. It will then be set automatically the next time the + cursor moves up or down. + + \sa setVerticalMovementX() + */ +int QTextCursor::verticalMovementX() const +{ + return d ? d->x : -1; +} + +/*! + \since 4.7 + + Returns whether the cursor should keep its current position when text gets inserted at the position of the + cursor. + + The default is false; + + \sa setKeepPositionOnInsert() + */ +bool QTextCursor::keepPositionOnInsert() const +{ + return d ? d->keepPositionOnInsert : false; +} + +/*! + \since 4.7 + + Defines whether the cursor should keep its current position when text gets inserted at the current position of the + cursor. + + If \b is true, the cursor keeps its current position when text gets inserted at the positing of the cursor. + If \b is false, the cursor moves along with the inserted text. + + The default is false. + + Note that a cursor always moves when text is inserted before the current position of the cursor, and it + always keeps its position when text is inserted after the current position of the cursor. + + \sa keepPositionOnInsert() + */ +void QTextCursor::setKeepPositionOnInsert(bool b) +{ + if (d) + d->keepPositionOnInsert = b; +} + + + /*! Inserts \a text at the current position, using the current character format. @@ -1408,16 +1483,16 @@ void QTextCursor::deletePreviousChar() { if (!d || !d->priv) return; - + if (d->position != d->anchor) { removeSelectedText(); return; } - + if (d->anchor < 1 || !d->canDelete(d->anchor-1)) return; d->anchor--; - + QTextDocumentPrivate::FragmentIterator fragIt = d->priv->find(d->anchor); const QTextFragmentData * const frag = fragIt.value(); int fpos = fragIt.position(); @@ -1429,7 +1504,7 @@ void QTextCursor::deletePreviousChar() if (uc.unicode() >= 0xd800 && uc.unicode() < 0xdc00) --d->anchor; } - + d->adjusted_anchor = d->anchor; d->remove(); d->setX(); diff --git a/src/gui/text/qtextcursor.h b/src/gui/text/qtextcursor.h index 3e968a3..251cb33 100644 --- a/src/gui/text/qtextcursor.h +++ b/src/gui/text/qtextcursor.h @@ -132,6 +132,12 @@ public: bool visualNavigation() const; void setVisualNavigation(bool b); + void setVerticalMovementX(int x); + int verticalMovementX() const; + + void setKeepPositionOnInsert(bool b); + bool keepPositionOnInsert() const; + void deleteChar(); void deletePreviousChar(); diff --git a/src/gui/text/qtextcursor_p.h b/src/gui/text/qtextcursor_p.h index 1bdfa78..4e36b95 100644 --- a/src/gui/text/qtextcursor_p.h +++ b/src/gui/text/qtextcursor_p.h @@ -112,7 +112,8 @@ public: int anchor; int adjusted_anchor; int currentCharFormat; - bool visualNavigation; + uint visualNavigation : 1; + uint keepPositionOnInsert : 1; }; QT_END_NAMESPACE diff --git a/tests/auto/qtextcursor/tst_qtextcursor.cpp b/tests/auto/qtextcursor/tst_qtextcursor.cpp index d44ce72..99babac 100644 --- a/tests/auto/qtextcursor/tst_qtextcursor.cpp +++ b/tests/auto/qtextcursor/tst_qtextcursor.cpp @@ -226,9 +226,9 @@ void tst_QTextCursor::navigation1() cursor.movePosition(QTextCursor::End); cursor.insertBlock(); { - int oldPos = cursor.position(); - cursor.movePosition(QTextCursor::End); - QVERIFY(cursor.position() == oldPos); + int oldPos = cursor.position(); + cursor.movePosition(QTextCursor::End); + QVERIFY(cursor.position() == oldPos); } QVERIFY(cursor.atBlockStart()); QVERIFY(cursor.position() == 9); @@ -1699,8 +1699,10 @@ void tst_QTextCursor::adjustCursorsOnInsert() QCOMPARE(selection.position(), posAfter+1); doc->undo(); + selection.setKeepPositionOnInsert(true); cursor.setPosition(posAfter); cursor.insertText(QLatin1String("x")); + selection.setKeepPositionOnInsert(false); QCOMPARE(selection.anchor(), posBefore); QCOMPARE(selection.position(), posAfter); doc->undo(); |