From: Frank Reininghaus Date: Sat, 20 Nov 2010 17:53:38 +0000 (+0000) Subject: Make sure that an item's visualRect in the Details View is not wider X-Git-Url: https://cloud.milkyroute.net/gitweb/dolphin.git/commitdiff_plain/5e7da43c2ddeb9cf99e5a2d2521b4274557b921a?ds=inline Make sure that an item's visualRect in the Details View is not wider than the "Name" column. Fixes keyboard navigation problems if files with very wide names are present in the current folder. Unit test included. CCBUG: 257401 svn path=/trunk/KDE/kdebase/apps/; revision=1199123 --- 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(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;