]> cloud.milkyroute.net Git - dolphin.git/blobdiff - src/klistview.cpp
Add needed method for keyboard navigation
[dolphin.git] / src / klistview.cpp
index 1971d7f98def069deb65026bb72f6d58bd962201..e484c3fb31174e7281561a417e0480e454add4a7 100644 (file)
@@ -547,7 +547,6 @@ void KListView::reset()
     d->elementDictionary.clear();
     d->categoriesIndexes.clear();
     d->categoriesPosition.clear();
-    d->isIndexSelected.clear();       // selection cache
     d->categories.clear();
     d->intersectedIndexes.clear();
     d->sourceModelIndexList.clear();
@@ -816,46 +815,33 @@ void KListView::mouseReleaseEvent(QMouseEvent *event)
     event->accept();
 
     d->mouseButtonPressed = false;
-    d->lastSelection = selectionModel()->selection();
 
     QPoint initialPressPosition = viewport()->mapFromGlobal(QCursor::pos());
     initialPressPosition.setY(initialPressPosition.y() + verticalOffset());
     initialPressPosition.setX(initialPressPosition.x() + horizontalOffset());
 
+    QItemSelection selection;
+
     if (initialPressPosition == d->initialPressPosition)
     {
-        QItemSelection selection;
         foreach(const QString &category, d->categories)
         {
             if (d->categoryVisualRect(category).contains(event->pos()))
             {
-                QModelIndex index;
-                foreach (const QModelIndex &mappedIndex,
-                         d->categoriesIndexes[category])
-                {
-                    index = d->proxyModel->mapFromSource(mappedIndex);
-
-                    if (d->isIndexSelected.contains(index))
-                    {
-                        if (!d->isIndexSelected[index])
-                            selection.select(index, index);
-
-                        d->isIndexSelected[index] = true;
-                    }
-                    else
-                    {
-                        d->isIndexSelected.insert(index, true);
-                        selection.select(index, index);
-                    }
-                }
-
-                selectionModel()->select(selection, QItemSelectionModel::Toggle);
+                QItemSelectionRange selectionRange(d->proxyModel->mapFromSource(d->categoriesIndexes[category][0]),
+                                                   d->proxyModel->mapFromSource(d->categoriesIndexes[category][d->categoriesIndexes[category].count() - 1]));
+
+                selection << selectionRange;
+
+                selectionModel()->select(selection, QItemSelectionModel::Select);
 
                 break;
             }
         }
     }
 
+    d->lastSelection = selectionModel()->selection();
+
     viewport()->update();
 }
 
@@ -929,6 +915,18 @@ void KListView::dragLeaveEvent(QDragLeaveEvent *event)
     viewport()->update();
 }
 
+QModelIndex KListView::moveCursor(CursorAction cursorAction,
+                                  Qt::KeyboardModifiers modifiers)
+{
+    if ((viewMode() != KListView::IconMode) || !d->proxyModel ||
+        !d->itemCategorizer)
+    {
+        return QListView::moveCursor(cursorAction, modifiers);
+    }
+
+    return QListView::moveCursor(cursorAction, modifiers);
+}
+
 void KListView::rowsInserted(const QModelIndex &parent,
                              int start,
                              int end)
@@ -948,12 +946,12 @@ void KListView::rowsInsertedArtifficial(const QModelIndex &parent,
                                         int start,
                                         int end)
 {
+    d->lastSelection = QItemSelection();
     d->elementsInfo.clear();
     d->elementsPosition.clear();
     d->elementDictionary.clear();
     d->categoriesIndexes.clear();
     d->categoriesPosition.clear();
-    d->isIndexSelected.clear();       // selection cache
     d->categories.clear();
     d->intersectedIndexes.clear();
     d->sourceModelIndexList.clear();
@@ -1052,7 +1050,8 @@ void KListView::rowsRemoved(const QModelIndex &parent,
                             int start,
                             int end)
 {
-    if (d->proxyModel)
+    if ((viewMode() == KListView::IconMode) && d->proxyModel &&
+        d->itemCategorizer)
     {
         // Force the view to update all elements
         rowsInsertedArtifficial(parent, start, end);