summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorShawn Rutledge <shawn.rutledge@qt.io>2019-03-01 22:40:54 +0100
committerShawn Rutledge <shawn.rutledge@qt.io>2019-05-15 11:25:45 +0000
commit23f78b6b76fb9350a472485e34857e1a4842e5d3 (patch)
tree0cb54f7ebe3dcc50a51f1238f7bc9369b859c505 /tests
parent24b286773ae5d47ad43f5e1810ebe6c5093a49da (diff)
TextEdit: use I-beam cursor by default, pointing cursor for links
But do not interfere with any custom cursor that user code sets: remember and restore it when the mouse is no longer hovering a link. Task-number: QTBUG-14769 Fixes: QTBUG-50482 Change-Id: Ia4633c22d0ad42d07203d4dc3e330b90a5f94a7c Reviewed-by: Mitch Curtis <mitch.curtis@qt.io>
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/quick/qquicktextedit/qquicktextedit.pro1
-rw-r--r--tests/auto/quick/qquicktextedit/tst_qquicktextedit.cpp56
2 files changed, 57 insertions, 0 deletions
diff --git a/tests/auto/quick/qquicktextedit/qquicktextedit.pro b/tests/auto/quick/qquicktextedit/qquicktextedit.pro
index ea6e8bc60d..576e25d092 100644
--- a/tests/auto/quick/qquicktextedit/qquicktextedit.pro
+++ b/tests/auto/quick/qquicktextedit/qquicktextedit.pro
@@ -8,6 +8,7 @@ SOURCES += tst_qquicktextedit.cpp \
HEADERS += ../../shared/testhttpserver.h
include (../../shared/util.pri)
+include (../shared/util.pri)
TESTDATA = data/*
diff --git a/tests/auto/quick/qquicktextedit/tst_qquicktextedit.cpp b/tests/auto/quick/qquicktextedit/tst_qquicktextedit.cpp
index da15ca6b48..80ba05b634 100644
--- a/tests/auto/quick/qquicktextedit/tst_qquicktextedit.cpp
+++ b/tests/auto/quick/qquicktextedit/tst_qquicktextedit.cpp
@@ -48,6 +48,7 @@
#include <QMimeData>
#include <private/qquicktextcontrol_p.h>
#include "../../shared/util.h"
+#include "../shared/viewtestutil.h"
#include "../../shared/platformquirks.h"
#include "../../shared/platforminputcontext.h"
#include <private/qinputmethod_p.h>
@@ -62,6 +63,11 @@ Q_DECLARE_METATYPE(QQuickTextEdit::SelectionMode)
Q_DECLARE_METATYPE(Qt::Key)
DEFINE_BOOL_CONFIG_OPTION(qmlDisableDistanceField, QML_DISABLE_DISTANCEFIELD)
+static bool isPlatformWayland()
+{
+ return !QGuiApplication::platformName().compare(QLatin1String("wayland"), Qt::CaseInsensitive);
+}
+
QString createExpectedFileIfNotFound(const QString& filebasename, const QImage& actual)
{
// XXX This will be replaced by some clever persistent platform image store.
@@ -132,6 +138,7 @@ private slots:
void positionAt_data();
void positionAt();
+ void linkHover();
void linkInteraction();
void cursorDelegate_data();
@@ -2506,10 +2513,59 @@ void tst_qquicktextedit::positionAt()
QVERIFY(texteditObject->positionAt(x0 / 2, y1) > 0);
}
+#if QT_CONFIG(cursor)
+void tst_qquicktextedit::linkHover()
+{
+ if (isPlatformWayland())
+ QSKIP("Wayland: QCursor::setPos() doesn't work.");
+
+ QQuickView window(testFileUrl("linkInteraction.qml"));
+ window.setFlag(Qt::FramelessWindowHint);
+ QVERIFY(window.rootObject() != nullptr);
+ QQuickViewTestUtil::centerOnScreen(&window);
+ QQuickViewTestUtil::moveMouseAway(&window);
+ window.show();
+ window.requestActivate();
+ QVERIFY(QTest::qWaitForWindowActive(&window));
+ QQuickTextEdit *texteditObject = qobject_cast<QQuickTextEdit *>(window.rootObject());
+ QVERIFY(texteditObject != nullptr);
+
+ QSignalSpy hover(texteditObject, SIGNAL(linkHovered(QString)));
+
+ const QString link("http://example.com/");
+ const QPoint linkPos = window.mapToGlobal(texteditObject->positionToRectangle(7).center().toPoint());
+ const QPoint textPos = window.mapToGlobal(texteditObject->positionToRectangle(2).center().toPoint());
+
+ QCursor::setPos(linkPos);
+ QTRY_COMPARE(hover.count(), 1);
+ QCOMPARE(window.cursor().shape(), Qt::PointingHandCursor);
+ QCOMPARE(hover.last()[0].toString(), link);
+
+ QCursor::setPos(textPos);
+ QTRY_COMPARE(hover.count(), 2);
+ QCOMPARE(window.cursor().shape(), Qt::IBeamCursor);
+ QCOMPARE(hover.last()[0].toString(), QString());
+
+ texteditObject->setCursor(Qt::OpenHandCursor);
+
+ QCursor::setPos(linkPos);
+ QTRY_COMPARE(hover.count(), 3);
+ QCOMPARE(window.cursor().shape(), Qt::PointingHandCursor);
+ QCOMPARE(hover.last()[0].toString(), link);
+
+ QCursor::setPos(textPos);
+ QTRY_COMPARE(hover.count(), 4);
+ QCOMPARE(window.cursor().shape(), Qt::OpenHandCursor);
+ QCOMPARE(hover.last()[0].toString(), QString());
+}
+#endif
+
void tst_qquicktextedit::linkInteraction()
{
QQuickView window(testFileUrl("linkInteraction.qml"));
QVERIFY(window.rootObject() != nullptr);
+ QQuickViewTestUtil::centerOnScreen(&window);
+ QQuickViewTestUtil::moveMouseAway(&window);
window.show();
window.requestActivate();
QVERIFY(QTest::qWaitForWindowActive(&window));