]> cloud.milkyroute.net Git - dolphin.git/blobdiff - src/dolphinview.cpp
selection model fixes
[dolphin.git] / src / dolphinview.cpp
index 3a8d6a8eaff2ed79d53f2c06eaf597b03fcaa8de..0041ab35d55b89645a312a4f9a7ddb93c7a0b5b8 100644 (file)
@@ -262,22 +262,15 @@ void DolphinView::selectAll()
 
 void DolphinView::invertSelection()
 {
-    if (isColumnViewActive()) {
-        // In opposite to QAbstractItemView::selectAll() there is no virtual method
-        // for adjusting the invertion of a selection. As the generic approach by using
-        // the selection model does not work for the column view, we delegate this task:
-        m_columnView->invertSelection();
-    } else {
-        QItemSelectionModel* selectionModel = itemView()->selectionModel();
-        const QAbstractItemModel* itemModel = selectionModel->model();
+    QItemSelectionModel* selectionModel = itemView()->selectionModel();
+    const QAbstractItemModel* itemModel = selectionModel->model();
 
-        const QModelIndex topLeft = itemModel->index(0, 0);
-        const QModelIndex bottomRight = itemModel->index(itemModel->rowCount() - 1,
-                                                         itemModel->columnCount() - 1);
+    const QModelIndex topLeft = itemModel->index(0, 0);
+    const QModelIndex bottomRight = itemModel->index(itemModel->rowCount() - 1,
+                                                     itemModel->columnCount() - 1);
 
-        QItemSelection selection(topLeft, bottomRight);
-        selectionModel->select(selection, QItemSelectionModel::Toggle);
-    }
+    QItemSelection selection(topLeft, bottomRight);
+    selectionModel->select(selection, QItemSelectionModel::Toggle);
 }
 
 bool DolphinView::hasSelection() const
@@ -302,11 +295,8 @@ QList<KFileItem> DolphinView::selectedItems() const
     QList<KFileItem> itemList;
 
     const QModelIndexList indexList = selection.indexes();
-    QModelIndexList::const_iterator end = indexList.end();
-    for (QModelIndexList::const_iterator it = indexList.begin(); it != end; ++it) {
-        Q_ASSERT((*it).isValid());
-
-        KFileItem item = m_dirModel->itemForIndex(*it);
+    foreach (QModelIndex index, indexList) {
+        KFileItem item = m_dirModel->itemForIndex(index);
         if (!item.isNull()) {
             itemList.append(item);
         }
@@ -335,7 +325,11 @@ KFileItem DolphinView::fileItem(const QModelIndex& index) const
 void DolphinView::setContentsPosition(int x, int y)
 {
     QAbstractItemView* view = itemView();
-    view->horizontalScrollBar()->setValue(x);
+
+    // the ColumnView takes care itself for the horizontal scrolling
+    if (!isColumnViewActive()) {
+        view->horizontalScrollBar()->setValue(x);
+    }
     view->verticalScrollBar()->setValue(y);
 
     m_loadingDirectory = false;
@@ -435,6 +429,7 @@ void DolphinView::setUrl(const KUrl& url)
     applyViewProperties(url);
 
     startDirLister(url);
+    itemView()->setFocus();
 }
 
 void DolphinView::mouseReleaseEvent(QMouseEvent* event)
@@ -838,6 +833,7 @@ void DolphinView::createView()
             this, SLOT(emitContentsMoved()));
     connect(view->horizontalScrollBar(), SIGNAL(valueChanged(int)),
             this, SLOT(emitContentsMoved()));
+    view->setFocus();
 }
 
 QAbstractItemView* DolphinView::itemView() const
@@ -914,7 +910,7 @@ void DolphinView::applyCutItemEffect()
 
 void DolphinView::updateViewportColor()
 {
-    QColor color = KColorScheme(KColorScheme::View).background();
+    QColor color = KColorScheme(QPalette::Active, KColorScheme::View).background().color();
     if (m_active) {
         emit urlChanged(url()); // Hmm, this is a hack; the url hasn't really changed.
         emit selectionChanged(selectedItems());