|
|
|
|
@ -28,9 +28,9 @@ private slots:
|
|
|
|
|
model.appendRow(message); |
|
|
|
|
ChatView view; MessageDelegate delegate; |
|
|
|
|
view.setModel(&model); view.setItemDelegate(&delegate); view.resize(width, 300); |
|
|
|
|
view.setInviteHitTest([&](const QModelIndex& index, const QPoint& point) { |
|
|
|
|
view.setLinkHitTest([&](const QModelIndex& index, const QPoint& point) { |
|
|
|
|
QStyleOptionViewItem option; option.initFrom(&view); option.widget = &view; option.rect = view.visualRect(index); |
|
|
|
|
return delegate.inviteLinkAt(option, index, point); |
|
|
|
|
return delegate.linkAt(option, index, point); |
|
|
|
|
}); |
|
|
|
|
view.show(); QTest::qWait(30); |
|
|
|
|
const QModelIndex index = model.index(0, 0); |
|
|
|
|
@ -39,7 +39,7 @@ private slots:
|
|
|
|
|
QSet<int> rows; |
|
|
|
|
for (int y = 0; y < option.rect.height(); ++y) { |
|
|
|
|
for (int x = 0; x < view.viewport()->width(); x += 2) { |
|
|
|
|
const QString hit = delegate.inviteLinkAt(option, index, QPoint(x, y)); |
|
|
|
|
const QString hit = delegate.linkAt(option, index, QPoint(x, y)); |
|
|
|
|
if (hit.isEmpty()) continue; |
|
|
|
|
QCOMPARE(hit, link); |
|
|
|
|
rows.insert(y); |
|
|
|
|
@ -50,7 +50,7 @@ private slots:
|
|
|
|
|
QVERIFY(!firstPoint.isNull()); |
|
|
|
|
QVERIFY(rows.size() <= QFontMetrics(option.font).height() + 1); |
|
|
|
|
QVERIFY(option.rect.height() < 160); |
|
|
|
|
QSignalSpy clicked(&view, &ChatView::inviteLinkActivated); |
|
|
|
|
QSignalSpy clicked(&view, &ChatView::linkActivated); |
|
|
|
|
QTest::mouseClick(view.viewport(), Qt::LeftButton, Qt::NoModifier, lastPoint); |
|
|
|
|
QCOMPARE(clicked.count(), 1); QCOMPARE(clicked.last().first().toString(), link); |
|
|
|
|
QTest::mousePress(view.viewport(), Qt::LeftButton, Qt::NoModifier, firstPoint); |
|
|
|
|
@ -84,9 +84,9 @@ private slots:
|
|
|
|
|
model.appendRow(message); |
|
|
|
|
ChatView view; MessageDelegate delegate; |
|
|
|
|
view.setModel(&model); view.setItemDelegate(&delegate); view.resize(280, 900); |
|
|
|
|
view.setInviteHitTest([&](const QModelIndex& index, const QPoint& point) { |
|
|
|
|
view.setLinkHitTest([&](const QModelIndex& index, const QPoint& point) { |
|
|
|
|
QStyleOptionViewItem option; option.initFrom(&view); option.widget = &view; option.rect = view.visualRect(index); |
|
|
|
|
return delegate.inviteLinkAt(option, index, point); |
|
|
|
|
return delegate.linkAt(option, index, point); |
|
|
|
|
}); |
|
|
|
|
view.show(); QTest::qWait(30); |
|
|
|
|
const QModelIndex index = model.index(0, 0); |
|
|
|
|
@ -95,15 +95,15 @@ private slots:
|
|
|
|
|
QSet<int> firstRows; |
|
|
|
|
for (int y = 10; y < option.rect.height(); y += 8) { |
|
|
|
|
for (int x = 10; x < view.viewport()->width(); x += 16) { |
|
|
|
|
const QString link = delegate.inviteLinkAt(option, index, QPoint(x, y)); |
|
|
|
|
const QString link = delegate.linkAt(option, index, QPoint(x, y)); |
|
|
|
|
if (link == first) { if (firstPoint.isNull()) firstPoint = QPoint(x, y); firstRows.insert(y); } |
|
|
|
|
else if (link == second) secondPoint = QPoint(x, y); |
|
|
|
|
else QVERIFY(link.isEmpty()); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
QVERIFY(firstRows.size() > 4); QVERIFY(!firstPoint.isNull()); QVERIFY(!secondPoint.isNull()); |
|
|
|
|
QVERIFY(delegate.inviteLinkAt(option, index, QPoint(0, 0)).isEmpty()); |
|
|
|
|
QSignalSpy clicked(&view, &ChatView::inviteLinkActivated); |
|
|
|
|
QVERIFY(delegate.linkAt(option, index, QPoint(0, 0)).isEmpty()); |
|
|
|
|
QSignalSpy clicked(&view, &ChatView::linkActivated); |
|
|
|
|
QTest::mouseClick(view.viewport(), Qt::LeftButton, Qt::NoModifier, firstPoint); |
|
|
|
|
QCOMPARE(clicked.count(), 1); QCOMPARE(clicked.last().first().toString(), first); |
|
|
|
|
QTest::mouseClick(view.viewport(), Qt::LeftButton, Qt::NoModifier, secondPoint); |
|
|
|
|
|