909 } |
909 } |
910 } |
910 } |
911 setTopBlock(block.blockNumber(), line); |
911 setTopBlock(block.blockNumber(), line); |
912 |
912 |
913 if (moveCursor) { |
913 if (moveCursor) { |
|
914 cursor.setVisualNavigation(true); |
914 // move using movePosition to keep the cursor's x |
915 // move using movePosition to keep the cursor's x |
915 lastY += verticalOffset(); |
916 lastY += verticalOffset(); |
916 bool moved = false; |
917 bool moved = false; |
917 do { |
918 do { |
918 moved = cursor.movePosition(op, moveMode); |
919 moved = cursor.movePosition(op, moveMode); |
941 int vmax = 0; |
942 int vmax = 0; |
942 |
943 |
943 int vSliderLength = 0; |
944 int vSliderLength = 0; |
944 if (!centerOnScroll && q->isVisible()) { |
945 if (!centerOnScroll && q->isVisible()) { |
945 QTextBlock block = doc->lastBlock(); |
946 QTextBlock block = doc->lastBlock(); |
946 const int visible = static_cast<int>(viewport->rect().height() - margin - 1); |
947 const qreal visible = viewport->rect().height() - margin - 1; |
947 int y = 0; |
948 qreal y = 0; |
948 int visibleFromBottom = 0; |
949 int visibleFromBottom = 0; |
949 |
950 |
950 while (block.isValid()) { |
951 while (block.isValid()) { |
951 if (!block.isVisible()) { |
952 if (!block.isVisible()) { |
952 block = block.previous(); |
953 block = block.previous(); |
953 continue; |
954 continue; |
954 } |
955 } |
955 y += int(documentLayout->blockBoundingRect(block).height()); |
956 y += documentLayout->blockBoundingRect(block).height(); |
956 |
957 |
957 QTextLayout *layout = block.layout(); |
958 QTextLayout *layout = block.layout(); |
958 int layoutLineCount = layout->lineCount(); |
959 int layoutLineCount = layout->lineCount(); |
959 if (y > visible) { |
960 if (y > visible) { |
960 int lineNumber = 0; |
961 int lineNumber = 0; |
961 while (lineNumber < layoutLineCount) { |
962 while (lineNumber < layoutLineCount) { |
962 QTextLine line = layout->lineAt(lineNumber); |
963 QTextLine line = layout->lineAt(lineNumber); |
963 const QRectF lr = line.naturalTextRect(); |
964 const QRectF lr = line.naturalTextRect(); |
964 if (int(lr.top()) >= y - visible) |
965 if (lr.top() >= y - visible) |
965 break; |
966 break; |
966 ++lineNumber; |
967 ++lineNumber; |
967 } |
968 } |
968 if (lineNumber < layoutLineCount) |
969 if (lineNumber < layoutLineCount) |
969 visibleFromBottom += (layoutLineCount - lineNumber - 1); |
970 visibleFromBottom += (layoutLineCount - lineNumber - 1); |
1317 { |
1318 { |
1318 Q_D(const QPlainTextEdit); |
1319 Q_D(const QPlainTextEdit); |
1319 return d->control->textCursor(); |
1320 return d->control->textCursor(); |
1320 } |
1321 } |
1321 |
1322 |
|
1323 /*! |
|
1324 Returns the reference of the anchor at position \a pos, or an |
|
1325 empty string if no anchor exists at that point. |
|
1326 |
|
1327 \since 4.7 |
|
1328 */ |
|
1329 QString QPlainTextEdit::anchorAt(const QPoint &pos) const |
|
1330 { |
|
1331 Q_D(const QPlainTextEdit); |
|
1332 int cursorPos = d->control->hitTest(pos + QPoint(d->horizontalOffset(), |
|
1333 d->verticalOffset()), |
|
1334 Qt::ExactHit); |
|
1335 if (cursorPos < 0) |
|
1336 return QString(); |
|
1337 |
|
1338 QTextDocumentPrivate *pieceTable = document()->docHandle(); |
|
1339 QTextDocumentPrivate::FragmentIterator it = pieceTable->find(cursorPos); |
|
1340 QTextCharFormat fmt = pieceTable->formatCollection()->charFormat(it->format); |
|
1341 return fmt.anchorHref(); |
|
1342 } |
1322 |
1343 |
1323 /*! |
1344 /*! |
1324 Undoes the last operation. |
1345 Undoes the last operation. |
1325 |
1346 |
1326 If there is no operation to undo, i.e. there is no undo step in |
1347 If there is no operation to undo, i.e. there is no undo step in |
2391 |
2412 |
2392 If the flags contain either Qt::LinksAccessibleByKeyboard or Qt::TextSelectableByKeyboard |
2413 If the flags contain either Qt::LinksAccessibleByKeyboard or Qt::TextSelectableByKeyboard |
2393 then the focus policy is also automatically set to Qt::ClickFocus. |
2414 then the focus policy is also automatically set to Qt::ClickFocus. |
2394 |
2415 |
2395 The default value depends on whether the QPlainTextEdit is read-only |
2416 The default value depends on whether the QPlainTextEdit is read-only |
2396 or editable, and whether it is a QTextBrowser or not. |
2417 or editable. |
2397 */ |
2418 */ |
2398 |
2419 |
2399 void QPlainTextEdit::setTextInteractionFlags(Qt::TextInteractionFlags flags) |
2420 void QPlainTextEdit::setTextInteractionFlags(Qt::TextInteractionFlags flags) |
2400 { |
2421 { |
2401 Q_D(QPlainTextEdit); |
2422 Q_D(QPlainTextEdit); |