diff options
| -rw-r--r-- | src/tests/dolphindetailsviewtest.cpp | 53 | ||||
| -rw-r--r-- | src/views/dolphindetailsview.cpp | 5 |
2 files changed, 57 insertions, 1 deletions
diff --git a/src/tests/dolphindetailsviewtest.cpp b/src/tests/dolphindetailsviewtest.cpp index 0ca19bddd..6f10c0f55 100644 --- a/src/tests/dolphindetailsviewtest.cpp +++ b/src/tests/dolphindetailsviewtest.cpp @@ -44,6 +44,7 @@ private slots: void bug217447_shiftArrowSelection(); void bug234600_overlappingIconsWhenZooming(); + void bug257401_longFilenamesKeyboardNavigation(); private: @@ -256,6 +257,58 @@ void DolphinDetailsViewTest::bug234600_overlappingIconsWhenZooming() cleanupTestDir(); } +/** + * The width of the visualRect of an item is usually replaced by the width of the file name. + * However, if the file name is wider then the view's name column, this leads to problems with + * keyboard navigation if files with very long names are present in the current folder, see + * + * https://bugs.kde.org/show_bug.cgi?id=257401 + * + * This test checks that the visualRect of an item is never wider than the "Name" column. + */ + +void DolphinDetailsViewTest::bug257401_longFilenamesKeyboardNavigation() { + QString name; + for (int i = 0; i < 20; i++) { + name += "mmmmmmmmmm"; + createFile(name); + } + + m_view->setMode(DolphinView::DetailsView); + DolphinDetailsView* detailsView = qobject_cast<DolphinDetailsView*>(itemView()); + QVERIFY(detailsView); + m_view->resize(400, 400); + m_view->show(); + QTest::qWaitForWindowShown(m_view); + reloadViewAndWait(); + + // Select the first item + QModelIndex index0 = detailsView->model()->index(0, 0); + detailsView->setCurrentIndex(index0); + QCOMPARE(detailsView->currentIndex(), index0); + QVERIFY(detailsView->visualRect(index0).width() < detailsView->columnWidth(DolphinModel::Name)); + + QItemSelectionModel* selectionModel = detailsView->selectionModel(); + QModelIndexList selectedIndexes = selectionModel->selectedIndexes(); + QCOMPARE(selectedIndexes.count(), 1); + QVERIFY(selectedIndexes.contains(index0)); + + // Move down successively using the "Down" key and check that current item + // and selection are as expected. + for (int i = 0; i < 19; i++) { + QTest::keyClick(detailsView->viewport(), Qt::Key_Down, Qt::NoModifier); + QModelIndex currentIndex = detailsView->model()->index(i + 1, 0); + QCOMPARE(detailsView->currentIndex(), currentIndex); + QVERIFY(detailsView->visualRect(currentIndex).width() <= detailsView->columnWidth(DolphinModel::Name)); + selectedIndexes = selectionModel->selectedIndexes(); + QCOMPARE(selectedIndexes.count(), 1); + QVERIFY(selectedIndexes.contains(currentIndex)); + } + + m_view->hide(); + cleanupTestDir(); +} + QTEST_KDEMAIN(DolphinDetailsViewTest, GUI) #include "dolphindetailsviewtest.moc"
\ No newline at end of file diff --git a/src/views/dolphindetailsview.cpp b/src/views/dolphindetailsview.cpp index 2d0d522ac..83460163c 100644 --- a/src/views/dolphindetailsview.cpp +++ b/src/views/dolphindetailsview.cpp @@ -299,7 +299,10 @@ QRect DolphinDetailsView::visualRect(const QModelIndex& index) const const KFileItem item = m_dolphinViewController->itemForIndex(index); if (!item.isNull()) { const int width = DolphinFileItemDelegate::nameColumnWidth(item.text(), viewOptions()); - rect.setWidth(width); + + if (width < rect.width()) { + rect.setWidth(width); + } } return rect; |
