diff --git a/src/quick/items/qquickitemsmodule.cpp b/src/quick/items/qquickitemsmodule.cpp index 4652bdf98e1dcede734e8748121564477da92f8c..a52ccf48328a8fabf4de6d46a3c77ce34622ea3a 100644 --- a/src/quick/items/qquickitemsmodule.cpp +++ b/src/quick/items/qquickitemsmodule.cpp @@ -271,6 +271,7 @@ static void qt_quickitems_defineModule(const char *uri, int major, int minor) qmlRegisterType<QQuickTextEdit, 2>(uri, 2, 2, "TextEdit"); qmlRegisterType<QQuickText, 3>(uri, 2, 3, "Text"); + qmlRegisterType<QQuickTextEdit, 3>(uri, 2, 3, "TextEdit"); } static void initResources() diff --git a/src/quick/items/qquicktextedit.cpp b/src/quick/items/qquicktextedit.cpp index 38a40a9e81b0814f11769a32f661c154b963da99..810a47cfa8fed335b9323c7c8119a8e07d45bf26 100644 --- a/src/quick/items/qquicktextedit.cpp +++ b/src/quick/items/qquicktextedit.cpp @@ -2515,7 +2515,7 @@ bool QQuickTextEditPrivate::isLinkHoveredConnected() The link must be in rich text or HTML format and the \a link string provides access to the particular link. - \sa hoveredLink + \sa hoveredLink, linkAt() */ /*! @@ -2526,7 +2526,7 @@ bool QQuickTextEditPrivate::isLinkHoveredConnected() embedded in the text. The link must be in rich text or HTML format and the link string provides access to the particular link. - \sa onLinkHovered + \sa onLinkHovered, linkAt() */ QString QQuickTextEdit::hoveredLink() const @@ -2599,4 +2599,19 @@ void QQuickTextEdit::append(const QString &text) d->control->updateCursorRectangle(false); } +/*! + \qmlmethod QtQuick::TextEdit::linkAt(real x, real y) + \since 5.3 + + Returns the link string at point \a x, \a y in content coordinates, + or an empty string if no link exists at that point. + + \sa hoveredLink +*/ +QString QQuickTextEdit::linkAt(qreal x, qreal y) const +{ + Q_D(const QQuickTextEdit); + return d->control->anchorAt(QPointF(x, y)); +} + QT_END_NAMESPACE diff --git a/src/quick/items/qquicktextedit_p.h b/src/quick/items/qquicktextedit_p.h index 8057f76be554f0e61eb06486eadcc8d1cdb51a84..b84552d2552428333a2e235a686d7195783b1c7d 100644 --- a/src/quick/items/qquicktextedit_p.h +++ b/src/quick/items/qquicktextedit_p.h @@ -258,6 +258,8 @@ public: QString hoveredLink() const; + Q_REVISION(3) Q_INVOKABLE QString linkAt(qreal x, qreal y) const; + Q_SIGNALS: void textChanged(); void contentSizeChanged(); diff --git a/tests/auto/quick/qquicktextedit/tst_qquicktextedit.cpp b/tests/auto/quick/qquicktextedit/tst_qquicktextedit.cpp index 8bf9d14a560c5229f63bb75623e781e82bfcca6f..e6a83b33380acd050728f5bedc02f72ea1f97e81 100644 --- a/tests/auto/quick/qquicktextedit/tst_qquicktextedit.cpp +++ b/tests/auto/quick/qquicktextedit/tst_qquicktextedit.cpp @@ -2393,12 +2393,14 @@ void tst_qquicktextedit::linkInteraction() QCOMPARE(spy.last()[0].toString(), link); QCOMPARE(hover.last()[0].toString(), link); QCOMPARE(texteditObject->hoveredLink(), link); + QCOMPARE(texteditObject->linkAt(linkPos.x(), linkPos.y()), link); QTest::mouseClick(&window, Qt::LeftButton, 0, textPos.toPoint()); QTRY_COMPARE(spy.count(), 1); QTRY_COMPARE(hover.count(), 2); QCOMPARE(hover.last()[0].toString(), QString()); QCOMPARE(texteditObject->hoveredLink(), QString()); + QCOMPARE(texteditObject->linkAt(textPos.x(), textPos.y()), QString()); texteditObject->setReadOnly(true); @@ -2408,12 +2410,14 @@ void tst_qquicktextedit::linkInteraction() QCOMPARE(spy.last()[0].toString(), link); QCOMPARE(hover.last()[0].toString(), link); QCOMPARE(texteditObject->hoveredLink(), link); + QCOMPARE(texteditObject->linkAt(linkPos.x(), linkPos.y()), link); QTest::mouseClick(&window, Qt::LeftButton, 0, textPos.toPoint()); QTRY_COMPARE(spy.count(), 2); QTRY_COMPARE(hover.count(), 4); QCOMPARE(hover.last()[0].toString(), QString()); QCOMPARE(texteditObject->hoveredLink(), QString()); + QCOMPARE(texteditObject->linkAt(textPos.x(), textPos.y()), QString()); } void tst_qquicktextedit::cursorDelegate_data()