]> cloud.milkyroute.net Git - dolphin.git/commitdiff
further selection model fixes
authorPeter Penz <peter.penz19@gmail.com>
Fri, 3 Aug 2007 18:46:49 +0000 (18:46 +0000)
committerPeter Penz <peter.penz19@gmail.com>
Fri, 3 Aug 2007 18:46:49 +0000 (18:46 +0000)
svn path=/trunk/KDE/kdebase/apps/; revision=696076

src/dolphincolumnview.cpp
src/dolphincolumnview.h

index 3389e15bf02e4151b8885e156c7062ca41b6dbd1..59a36d9f6070dd171dcba4ebd9a98b1b247416f8 100644 (file)
@@ -30,6 +30,7 @@
 #include <kdirmodel.h>
 
 #include <QAbstractProxyModel>
+#include <QApplication>
 #include <QPoint>
 
 /**
@@ -57,6 +58,9 @@ public:
 
     inline const KUrl& url() const;
 
+    void obtainSelectionModel();
+    void releaseSelectionModel();
+    
 protected:
     virtual QStyleOptionViewItem viewOptions() const;
     virtual void dragEnterEvent(QDragEnterEvent* event);
@@ -135,6 +139,12 @@ void ColumnWidget::setDecorationSize(const QSize& size)
 
 void ColumnWidget::setActive(bool active)
 {
+    if (active) {
+        obtainSelectionModel();
+    } else {
+        releaseSelectionModel();
+    }
+    
     if (m_active == active) {
         return;
     }
@@ -158,6 +168,22 @@ const KUrl& ColumnWidget::url() const
     return m_url;
 }
 
+void ColumnWidget::obtainSelectionModel()
+{
+    if (selectionModel() != m_view->selectionModel()) {
+        selectionModel()->deleteLater();
+        setSelectionModel(m_view->selectionModel());
+    }
+}
+
+void ColumnWidget::releaseSelectionModel()
+{
+    if (selectionModel() == m_view->selectionModel()) {
+        QItemSelectionModel* replacementModel = new QItemSelectionModel(model());
+        setSelectionModel(replacementModel);
+    }
+}
+
 QStyleOptionViewItem ColumnWidget::viewOptions() const
 {
     return m_viewOptions;
@@ -207,6 +233,9 @@ void ColumnWidget::dropEvent(QDropEvent* event)
 
 void ColumnWidget::mousePressEvent(QMouseEvent* event)
 {
+    m_view->requestSelectionModel(this);
+
+    bool swallowMousePressEvent = false;
     const QModelIndex index = indexAt(event->pos());
     if (index.isValid()) {
         // A click on an item has been done. Only request an activation
@@ -216,12 +245,31 @@ void ColumnWidget::mousePressEvent(QMouseEvent* event)
         const QModelIndex dirIndex = proxyModel->mapToSource(index);
         KFileItem* item = dirModel->itemForIndex(dirIndex);
         if (item != 0) {
-            if (item->isDir()) {
+            QItemSelectionModel* selModel = selectionModel();
+
+            const Qt::KeyboardModifiers modifier = QApplication::keyboardModifiers();
+            if (modifier & Qt::ControlModifier) {
+                m_view->requestActivation(this);
+                selModel->select(index, QItemSelectionModel::Select);
+                swallowMousePressEvent = true;
+            } else if (item->isDir()) {
                 m_childUrl = item->url();
                 viewport()->update();
-           } else {
+            } else {
                 m_view->requestActivation(this);
             }
+
+            // TODO: check behavior with ShiftModifier
+            //if (modifier & Qt::ShiftModifier)
+
+            // TODO: is the assumption OK that Qt::RightButton always represents the context menu button?
+            if (event->button() == Qt::RightButton) {
+                swallowMousePressEvent = true;
+                if (!selModel->isSelected(index)) {
+                    clearSelection();
+                }
+                selModel->select(index, QItemSelectionModel::Select);
+            }
         }
     } else {
         // a click on the viewport has been done
@@ -230,9 +278,12 @@ void ColumnWidget::mousePressEvent(QMouseEvent* event)
         // Swallow mouse move events if a click is done on the viewport. Otherwise the QColumnView
         // triggers an unwanted loading of directories on hovering folder items.
         m_swallowMouseMoveEvents = true;
+        clearSelection();
     }
 
-    QListView::mousePressEvent(event);
+    if (!swallowMousePressEvent) {
+        QListView::mousePressEvent(event);
+    }
 }
 
 void ColumnWidget::mouseMoveEvent(QMouseEvent* event)
@@ -342,6 +393,7 @@ DolphinColumnView::DolphinColumnView(QWidget* parent, DolphinController* control
     setAcceptDrops(true);
     setDragDropMode(QAbstractItemView::DragDrop);
     setDropIndicatorShown(false);
+    setSelectionMode(ExtendedSelection);
 
     if (KGlobalSettings::singleClick()) {
         connect(this, SIGNAL(clicked(const QModelIndex&)),
@@ -540,7 +592,21 @@ void DolphinColumnView::requestActivation(QWidget* column)
             if (isActive) {
                 m_controller->setUrl(widget->url());
             }
-       }
+        }
+    }
+}
+
+void DolphinColumnView::requestSelectionModel(QAbstractItemView* view)
+{
+    foreach (QObject* object, viewport()->children()) {
+        if (object->inherits("QListView")) {
+            ColumnWidget* widget = static_cast<ColumnWidget*>(object);
+            if (widget == view) {
+                widget->obtainSelectionModel();
+            } else {
+                widget->releaseSelectionModel();
+            }
+        }
     }
 }
 
index a3290cc2cb1fc50e1415ef36c719d4a032048f7c..03f210229fed4aceaf380841e79c08595bef0beb 100644 (file)
@@ -73,10 +73,19 @@ private:
 
     /**
      * Requests the activation for the column \a column. The URL
-     * navigator will be changed to represent the column.
+     * navigator will be changed to represent the column. It is
+     * assured that the selection model of \a column will be set
+     * to the selection model of the Column View.
      */
     void requestActivation(QWidget* column);
 
+    /**
+     * Requests the selection model from the Column View for \a view.
+     * If another column has already obtained the Column View selection
+     * model, it will be replaced by a default selection model.
+     */
+    void requestSelectionModel(QAbstractItemView* view);
+
 private:
     DolphinController* m_controller;