src/gui/widgets/qplaintextedit.cpp
changeset 30 5dc02b23752f
parent 18 2f34d5167611
child 33 3e2da88830cd
--- a/src/gui/widgets/qplaintextedit.cpp	Wed Jun 23 19:07:03 2010 +0300
+++ b/src/gui/widgets/qplaintextedit.cpp	Tue Jul 06 15:10:48 2010 +0300
@@ -911,6 +911,7 @@
         setTopBlock(block.blockNumber(), line);
 
         if (moveCursor) {
+            cursor.setVisualNavigation(true);
             // move using movePosition to keep the cursor's x
             lastY += verticalOffset();
             bool moved = false;
@@ -943,8 +944,8 @@
     int vSliderLength = 0;
     if (!centerOnScroll && q->isVisible()) {
         QTextBlock block = doc->lastBlock();
-        const int visible = static_cast<int>(viewport->rect().height() - margin - 1);
-        int y = 0;
+        const qreal visible = viewport->rect().height() - margin - 1;
+        qreal y = 0;
         int visibleFromBottom = 0;
 
         while (block.isValid()) {
@@ -952,7 +953,7 @@
                 block = block.previous();
                 continue;
             }
-            y += int(documentLayout->blockBoundingRect(block).height());
+            y += documentLayout->blockBoundingRect(block).height();
 
             QTextLayout *layout = block.layout();
             int layoutLineCount = layout->lineCount();
@@ -961,7 +962,7 @@
                 while (lineNumber < layoutLineCount) {
                     QTextLine line = layout->lineAt(lineNumber);
                     const QRectF lr = line.naturalTextRect();
-                    if (int(lr.top()) >= y - visible)
+                    if (lr.top() >= y - visible)
                         break;
                     ++lineNumber;
                 }
@@ -1319,6 +1320,26 @@
     return d->control->textCursor();
 }
 
+/*!
+    Returns the reference of the anchor at position \a pos, or an
+    empty string if no anchor exists at that point.
+
+    \since 4.7
+ */
+QString QPlainTextEdit::anchorAt(const QPoint &pos) const
+{
+    Q_D(const QPlainTextEdit);
+    int cursorPos = d->control->hitTest(pos + QPoint(d->horizontalOffset(),
+                                                     d->verticalOffset()),
+                                        Qt::ExactHit);
+    if (cursorPos < 0)
+        return QString();
+
+    QTextDocumentPrivate *pieceTable = document()->docHandle();
+    QTextDocumentPrivate::FragmentIterator it = pieceTable->find(cursorPos);
+    QTextCharFormat fmt = pieceTable->formatCollection()->charFormat(it->format);
+    return fmt.anchorHref();
+}
 
 /*!
     Undoes the last operation.
@@ -2393,7 +2414,7 @@
     then the focus policy is also automatically set to Qt::ClickFocus.
 
     The default value depends on whether the QPlainTextEdit is read-only
-    or editable, and whether it is a QTextBrowser or not.
+    or editable.
 */
 
 void QPlainTextEdit::setTextInteractionFlags(Qt::TextInteractionFlags flags)