]> cloud.milkyroute.net Git - dolphin.git/commitdiff
Make sure that an item's visualRect in the Details View is not wider
authorFrank Reininghaus <frank78ac@googlemail.com>
Sat, 20 Nov 2010 17:53:38 +0000 (17:53 +0000)
committerFrank Reininghaus <frank78ac@googlemail.com>
Sat, 20 Nov 2010 17:53:38 +0000 (17:53 +0000)
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

src/tests/dolphindetailsviewtest.cpp
src/views/dolphindetailsview.cpp

index 0ca19bdddce76b67e42af92973936ec4b40acf87..6f10c0f55228c62f458fb831b3202869a2d1294d 100644 (file)
@@ -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
index 2d0d522acd3cdd38eb070b9a813c2a634cc0883b..83460163caa37fb4a0f3f47b76fb0beb9bf82ed6 100644 (file)
@@ -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;