Activate links in a read only TextEdit.
authorAndrew den Exter <andrew.den-exter@nokia.com>
Tue, 13 Dec 2011 05:42:49 +0000 (15:42 +1000)
committerQt by Nokia <qt-info@nokia.com>
Thu, 15 Dec 2011 08:08:35 +0000 (09:08 +0100)
Don't ignore mouse press events if  the LinksAccessibleByMouse
interaction flag is set.

Task-number: QTBUG-23065
Change-Id: I25b3e3b0cf194b71fc863ed239196a567f42c19c
Reviewed-by: Martin Jones <martin.jones@nokia.com>
src/quick/items/qquicktextcontrol.cpp
tests/auto/qtquick2/qquicktextedit/data/linkActivated.qml [new file with mode: 0644]
tests/auto/qtquick2/qquicktextedit/tst_qquicktextedit.cpp

index f50e70a..90483e5 100644 (file)
@@ -1187,10 +1187,13 @@ void QQuickTextControlPrivate::mousePressEvent(QMouseEvent *e, const QPointF &po
             cursor.clearSelection();
         }
     }
-    if (!(e->button() & Qt::LeftButton) ||
-        !((interactionFlags & Qt::TextSelectableByMouse) || (interactionFlags & Qt::TextEditable))) {
+    if (!(e->button() & Qt::LeftButton)) {
+        e->ignore();
+        return;
+    } else if (!(interactionFlags & (Qt::TextSelectableByMouse | Qt::TextEditable))) {
+        if (!(interactionFlags & Qt::LinksAccessibleByMouse))
             e->ignore();
-            return;
+        return;
     }
 
     cursorIsFocusIndicator = false;
diff --git a/tests/auto/qtquick2/qquicktextedit/data/linkActivated.qml b/tests/auto/qtquick2/qquicktextedit/data/linkActivated.qml
new file mode 100644 (file)
index 0000000..d3bba82
--- /dev/null
@@ -0,0 +1,6 @@
+import QtQuick 2.0
+
+TextEdit {
+    textFormat: TextEdit.RichText
+    text: "Test <a href='http://example.com/'>link</a>"
+}
index 4ad8bf0..9cc904e 100644 (file)
@@ -132,6 +132,8 @@ private slots:
 
     void positionAt();
 
+    void linkActivated();
+
     void cursorDelegate();
     void cursorVisible();
     void delegateLoading_data();
@@ -1642,6 +1644,43 @@ void tst_qquicktextedit::positionAt()
     QVERIFY(texteditObject->positionAt(x0 / 2, y1) > 0);
 }
 
+void tst_qquicktextedit::linkActivated()
+{
+    QQuickView canvas(QUrl::fromLocalFile(TESTDATA("linkActivated.qml")));
+    QVERIFY(canvas.rootObject() != 0);
+    canvas.show();
+    canvas.requestActivateWindow();
+    QTest::qWaitForWindowShown(&canvas);
+
+    QQuickTextEdit *texteditObject = qobject_cast<QQuickTextEdit *>(canvas.rootObject());
+    QVERIFY(texteditObject != 0);
+
+    QSignalSpy spy(texteditObject, SIGNAL(linkActivated(QString)));
+
+    const QString link("http://example.com/");
+
+    const QPointF linkPos = texteditObject->positionToRectangle(7).center();
+    const QPointF textPos = texteditObject->positionToRectangle(2).center();
+
+    QTest::mouseClick(&canvas, Qt::LeftButton, 0, linkPos.toPoint());
+    QTRY_COMPARE(spy.count(), 1);
+    QCOMPARE(spy.last()[0].toString(), link);
+
+    QTest::mouseClick(&canvas, Qt::LeftButton, 0, textPos.toPoint());
+    QTest::qWait(50);
+    QCOMPARE(spy.count(), 1);
+
+    texteditObject->setReadOnly(true);
+
+    QTest::mouseClick(&canvas, Qt::LeftButton, 0, linkPos.toPoint());
+    QTRY_COMPARE(spy.count(), 2);
+    QCOMPARE(spy.last()[0].toString(), link);
+
+    QTest::mouseClick(&canvas, Qt::LeftButton, 0, textPos.toPoint());
+    QTest::qWait(50);
+    QCOMPARE(spy.count(), 2);
+}
+
 void tst_qquicktextedit::cursorDelegate()
 {
     QQuickView view(QUrl::fromLocalFile(TESTDATA("cursorTest.qml")));