┌   ┐
54
└   ┘

summaryrefslogtreecommitdiff
path: root/src/tests/kitemlistcontrollertest.cpp
diff options
context:
space:
mode:
authorTomasz Kot <[email protected]>2025-11-28 16:11:00 +0100
committerMéven Car <[email protected]>2026-01-21 09:01:28 +0000
commit843d10ae2ab6a7f2c6f69b63fa278fdd6162254c (patch)
treeab8a57d633493ead07320e8113e268126b96c5b4 /src/tests/kitemlistcontrollertest.cpp
parentd04dc824270891b7e3d617b5bb7b5ed668388fd2 (diff)
Add keyboard anchor assignments to mouse events
The mouse events need to modify the keyboard anchor assignments as well, because selecting an item with a mouse and then navigating with keyboard wouldn't follow the same selection. BUG: 508609
Diffstat (limited to 'src/tests/kitemlistcontrollertest.cpp')
-rw-r--r--src/tests/kitemlistcontrollertest.cpp72
1 files changed, 72 insertions, 0 deletions
diff --git a/src/tests/kitemlistcontrollertest.cpp b/src/tests/kitemlistcontrollertest.cpp
index 8fd0f6158..a38e7803d 100644
--- a/src/tests/kitemlistcontrollertest.cpp
+++ b/src/tests/kitemlistcontrollertest.cpp
@@ -78,6 +78,7 @@ private Q_SLOTS:
void testKeyboardNavigationSingleSelectionNoSelection_data();
void testKeyboardNavigationSingleSelectionNoSelection();
void testMouseClickActivation();
+ void testKeyboardNavigationAfterMouseSelection();
private:
/**
@@ -85,6 +86,7 @@ private:
* by changing the geometry of the container.
*/
void adjustGeometryForColumnCount(int count);
+ void simulateMouseClickOnItem(int index);
private:
KFileItemListView *m_view;
@@ -1151,6 +1153,76 @@ void KItemListControllerTest::testMouseClickActivation()
m_testStyle->setActivateItemOnSingleClick(restoreSettingsSingleClick);
}
+/**
+ * This function simulates a mouse click on an item under a given index.
+ */
+void KItemListControllerTest::simulateMouseClickOnItem(int index)
+{
+ const QPointF pos = m_view->itemContextRect(index).center();
+ QGraphicsSceneMouseEvent mousePressEvent(QEvent::GraphicsSceneMousePress);
+ mousePressEvent.setPos(pos);
+ mousePressEvent.setButton(Qt::LeftButton);
+ mousePressEvent.setButtons(Qt::LeftButton);
+
+ QGraphicsSceneMouseEvent mouseReleaseEvent(QEvent::GraphicsSceneMouseRelease);
+ mouseReleaseEvent.setPos(pos);
+ mouseReleaseEvent.setButton(Qt::LeftButton);
+ mouseReleaseEvent.setButtons(Qt::NoButton);
+
+ m_view->event(&mousePressEvent);
+ m_view->event(&mouseReleaseEvent);
+}
+
+void KItemListControllerTest::testKeyboardNavigationAfterMouseSelection()
+{
+ QApplication::setLayoutDirection(Qt::LeftToRight);
+ m_view->setLayoutDirection(Qt::LeftToRight);
+ m_view->setItemLayout(KFileItemListView::IconsLayout);
+ m_model->setGroupedSorting(false);
+
+ adjustGeometryForColumnCount(3);
+ QCOMPARE(m_view->m_layouter->m_columnCount, 3);
+
+ m_view->setScrollOffset(0);
+ QCOMPARE(m_view->firstVisibleIndex(), 0);
+
+ simulateMouseClickOnItem(0);
+ QCOMPARE(m_selectionManager->currentItem(), 0);
+
+ QTest::keyClick(m_container, Qt::Key_Down);
+ QCOMPARE(m_selectionManager->currentItem(), 3);
+
+ QTest::keyClick(m_container, Qt::Key_Down);
+ QCOMPARE(m_selectionManager->currentItem(), 6);
+
+ simulateMouseClickOnItem(1);
+ QCOMPARE(m_selectionManager->currentItem(), 1);
+
+ QTest::keyClick(m_container, Qt::Key_Down);
+ QCOMPARE(m_selectionManager->currentItem(), 4);
+
+ QTest::keyClick(m_container, Qt::Key_Down);
+ QCOMPARE(m_selectionManager->currentItem(), 7);
+
+ simulateMouseClickOnItem(2);
+ QCOMPARE(m_selectionManager->currentItem(), 2);
+
+ QTest::keyClick(m_container, Qt::Key_Down);
+ QCOMPARE(m_selectionManager->currentItem(), 5);
+
+ QTest::keyClick(m_container, Qt::Key_Down);
+ QCOMPARE(m_selectionManager->currentItem(), 8);
+
+ simulateMouseClickOnItem(10);
+ QCOMPARE(m_selectionManager->currentItem(), 10);
+
+ QTest::keyClick(m_container, Qt::Key_Up);
+ QCOMPARE(m_selectionManager->currentItem(), 7);
+
+ QTest::keyClick(m_container, Qt::Key_Up);
+ QCOMPARE(m_selectionManager->currentItem(), 4);
+}
+
void KItemListControllerTest::adjustGeometryForColumnCount(int count)
{
const QSize size = m_view->itemSize().toSize();