Ignore:
Timestamp:
May 5, 2011, 5:36:53 AM (14 years ago)
Author:
Dmitry A. Kuminov
Message:

trunk: Merged in qt 4.7.2 sources from branches/vendor/nokia/qt.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk

  • trunk/src/gui/text/qtextcursor.cpp

    r651 r846  
    11/****************************************************************************
    22**
    3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     3** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
    44** All rights reserved.
    55** Contact: Nokia Corporation (qt-info@nokia.com)
     
    6565QTextCursorPrivate::QTextCursorPrivate(QTextDocumentPrivate *p)
    6666    : priv(p), x(0), position(0), anchor(0), adjusted_anchor(0),
    67       currentCharFormat(-1), visualNavigation(false)
     67      currentCharFormat(-1), visualNavigation(false), keepPositionOnInsert(false),
     68      changed(false)
    6869{
    6970    priv->addCursor(this);
     
    8081    currentCharFormat = rhs.currentCharFormat;
    8182    visualNavigation = rhs.visualNavigation;
     83    keepPositionOnInsert = rhs.keepPositionOnInsert;
     84    changed = rhs.changed;
    8285    priv->addCursor(this);
    8386}
     
    9699        || (position == positionOfChange
    97100            && (op == QTextUndoCommand::KeepCursor
    98                 || anchor < position)
     101                || keepPositionOnInsert)
    99102            )
    100103         ) {
     
    361364    QTextBlock blockIt = block();
    362365
     366    if (!blockIt.isValid())
     367        return false;
     368
    363369    if (op >= QTextCursor::Left && op <= QTextCursor::WordRight
    364         && blockIt.blockFormat().layoutDirection() == Qt::RightToLeft) {
     370        && blockIt.textDirection() == Qt::RightToLeft) {
    365371        if (op == QTextCursor::Left)
    366372            op = QTextCursor::NextCharacter;
     
    11461152    The cursor is positioned between characters.
    11471153
    1148     \sa setPosition() movePosition() anchor()
     1154    \sa setPosition() movePosition() anchor() positionInBlock()
    11491155*/
    11501156int QTextCursor::position() const
     
    11531159        return -1;
    11541160    return d->position;
     1161}
     1162
     1163/*!
     1164    \since 4.7
     1165    Returns the relative position of the cursor within the block.
     1166    The cursor is positioned between characters.
     1167
     1168    This is equivalent to \c{ position() - block().position()}.
     1169
     1170    \sa position()
     1171*/
     1172int QTextCursor::positionInBlock() const
     1173{
     1174    if (!d || !d->priv)
     1175        return 0;
     1176    return d->position - d->block().position();
    11551177}
    11561178
     
    12611283}
    12621284
     1285
     1286/*!
     1287  \since 4.7
     1288
     1289  Sets the visual x position for vertical cursor movements to \a x.
     1290
     1291  The vertical movement x position is cleared automatically when the cursor moves horizontally, and kept
     1292  unchanged when the cursor moves vertically. The mechanism allows the cursor to move up and down on a
     1293  visually straight line with proportional fonts, and to gently "jump" over short lines.
     1294
     1295  A value of -1 indicates no predefined x position. It will then be set automatically the next time the
     1296  cursor moves up or down.
     1297
     1298  \sa verticalMovementX()
     1299  */
     1300void QTextCursor::setVerticalMovementX(int x)
     1301{
     1302    if (d)
     1303        d->x = x;
     1304}
     1305
     1306/*! \since 4.7
     1307
     1308  Returns the visual x position for vertical cursor movements.
     1309
     1310  A value of -1 indicates no predefined x position. It will then be set automatically the next time the
     1311  cursor moves up or down.
     1312
     1313  \sa setVerticalMovementX()
     1314  */
     1315int QTextCursor::verticalMovementX() const
     1316{
     1317    return d ? d->x : -1;
     1318}
     1319
     1320/*!
     1321  \since 4.7
     1322
     1323  Returns whether the cursor should keep its current position when text gets inserted at the position of the
     1324  cursor.
     1325
     1326  The default is false;
     1327
     1328  \sa setKeepPositionOnInsert()
     1329 */
     1330bool QTextCursor::keepPositionOnInsert() const
     1331{
     1332    return d ? d->keepPositionOnInsert : false;
     1333}
     1334
     1335/*!
     1336  \since 4.7
     1337
     1338  Defines whether the cursor should keep its current position when text gets inserted at the current position of the
     1339  cursor.
     1340
     1341  If \a b is true, the cursor keeps its current position when text gets inserted at the positing of the cursor.
     1342  If \a b is false, the cursor moves along with the inserted text.
     1343
     1344  The default is false.
     1345
     1346  Note that a cursor always moves when text is inserted before the current position of the cursor, and it
     1347  always keeps its position when text is inserted after the current position of the cursor.
     1348
     1349  \sa keepPositionOnInsert()
     1350 */
     1351void QTextCursor::setKeepPositionOnInsert(bool b)
     1352{
     1353    if (d)
     1354        d->keepPositionOnInsert = b;
     1355}
     1356
     1357
     1358
    12631359/*!
    12641360    Inserts \a text at the current position, using the current
     
    13931489    if (!d || !d->priv)
    13941490        return;
    1395    
     1491
    13961492    if (d->position != d->anchor) {
    13971493        removeSelectedText();
    13981494        return;
    13991495    }
    1400    
     1496
    14011497    if (d->anchor < 1 || !d->canDelete(d->anchor-1))
    14021498        return;
    14031499    d->anchor--;
    1404    
     1500
    14051501    QTextDocumentPrivate::FragmentIterator fragIt = d->priv->find(d->anchor);
    14061502    const QTextFragmentData * const frag = fragIt.value();
     
    14141510            --d->anchor;
    14151511    }
    1416    
     1512
    14171513    d->adjusted_anchor = d->anchor;
    14181514    d->remove();
     
    23472443        return;
    23482444
     2445    if (d->priv->editBlock == 0) // we are the initial edit block, store current cursor position for undo
     2446        d->priv->editBlockCursorPosition = d->position;
     2447
    23492448    d->priv->beginEditBlock();
    23502449}
     
    24152514}
    24162515
     2516
    24172517/*!
    24182518    \since 4.2
    24192519    Returns the position of the cursor within its containing line.
     2520
     2521    Note that this is the column number relative to a wrapped line,
     2522    not relative to the block (i.e. the paragraph).
     2523
     2524    You probably want to call positionInBlock() instead.
     2525
     2526    \sa positionInBlock()
    24202527*/
    24212528int QTextCursor::columnNumber() const
Note: See TracChangeset for help on using the changeset viewer.