]> cloud.milkyroute.net Git - dolphin.git/commitdiff
temporary fixes until MultiSelection will be implemented
authorPeter Penz <peter.penz19@gmail.com>
Sat, 28 Jul 2007 22:27:58 +0000 (22:27 +0000)
committerPeter Penz <peter.penz19@gmail.com>
Sat, 28 Jul 2007 22:27:58 +0000 (22:27 +0000)
svn path=/trunk/KDE/kdebase/apps/; revision=693752

src/dolphincolumnview.cpp
src/dolphincolumnview.h

index c702b8a62d9918d533360d4021ce505cbbe57beb..e3e084718cd58ba7917a840abd7b60289ffcdee5 100644 (file)
@@ -26,6 +26,7 @@
 
 #include <kcolorutils.h>
 #include <kcolorscheme.h>
+#include <kdirlister.h>
 #include <kdirmodel.h>
 
 #include <QAbstractProxyModel>
@@ -56,6 +57,13 @@ public:
 
     inline const KUrl& url() const;
 
+    /**
+     * Updates the selection that the folder gets selected which represents
+     * the URL \a url. If \a url is empty, the selection of the column widget
+     * gets cleared.
+     */
+    void updateSelection(const KUrl& url);
+
 protected:
     virtual QStyleOptionViewItem viewOptions() const;
     virtual void dragEnterEvent(QDragEnterEvent* event);
@@ -93,10 +101,6 @@ ColumnWidget::ColumnWidget(QWidget* parent,
     m_dragging(false),
     m_dropRect()
 {
-    setAcceptDrops(true);
-    setDragDropMode(QAbstractItemView::DragDrop);
-    setDropIndicatorShown(false);
-
     setMouseTracking(true);
     viewport()->setAttribute(Qt::WA_Hover);
 
@@ -152,6 +156,31 @@ const KUrl& ColumnWidget::url() const
     return m_url;
 }
 
+void ColumnWidget::updateSelection(const KUrl& url)
+{
+    setSelectionMode(SingleSelection);
+    QItemSelectionModel* selModel = selectionModel();
+    if (url.isEmpty()) {
+        selModel->clear();
+        return;
+    }
+
+    const QAbstractProxyModel* proxyModel = static_cast<const QAbstractProxyModel*>(m_view->model());
+    const KDirModel* dirModel = static_cast<const KDirModel*>(proxyModel->sourceModel());
+    const QModelIndex dirIndex = dirModel->indexForUrl(url);
+    const QModelIndex proxyIndex = proxyModel->mapFromSource(dirIndex);
+
+    const QItemSelection selection = selModel->selection();
+    const bool isIndexSelected = selModel->isSelected(proxyIndex);
+
+    if (!m_active && ((selection.count() > 1) || !isIndexSelected)) {
+        selModel->clear();
+    }
+    if (!isIndexSelected) {
+        selModel->select(proxyIndex, QItemSelectionModel::Select);
+    }
+}
+
 QStyleOptionViewItem ColumnWidget::viewOptions() const
 {
     return m_viewOptions;
@@ -201,7 +230,14 @@ void ColumnWidget::dropEvent(QDropEvent* event)
 
 void ColumnWidget::mousePressEvent(QMouseEvent* event)
 {
+    if (m_active) {
+        selectionModel()->clear();
+        QListView::mousePressEvent(event);
+        return;
+    }
+
     QListView::mousePressEvent(event);
+
     const QModelIndex index = indexAt(event->pos());
 
     bool requestActivation = false;
@@ -238,7 +274,9 @@ void ColumnWidget::paintEvent(QPaintEvent* event)
 
 void ColumnWidget::contextMenuEvent(QContextMenuEvent* event)
 {
-    m_view->requestActivation(this);
+    if (!m_active) {
+        m_view->requestActivation(this);
+    }
 
     QListView::contextMenuEvent(event);
 
@@ -258,7 +296,6 @@ void ColumnWidget::activate()
     palette.setColor(viewport()->backgroundRole(), bgColor);
     viewport()->setPalette(palette);
 
-    setSelectionMode(MultiSelection);
     update();
 }
 
@@ -272,7 +309,6 @@ void ColumnWidget::deactivate()
     palette.setColor(viewport()->backgroundRole(), bgColor);
     viewport()->setPalette(palette);
 
-    setSelectionMode(SingleSelection);
     update();
 }
 
@@ -287,7 +323,7 @@ DolphinColumnView::DolphinColumnView(QWidget* parent, DolphinController* control
     setAcceptDrops(true);
     setDragDropMode(QAbstractItemView::DragDrop);
     setDropIndicatorShown(false);
-    setSelectionMode(MultiSelection);
+    setSelectionMode(SingleSelection);
 
     if (KGlobalSettings::singleClick()) {
         connect(this, SIGNAL(clicked(const QModelIndex&)),
@@ -401,6 +437,20 @@ void DolphinColumnView::dropEvent(QDropEvent* event)
     QColumnView::dropEvent(event);
 }
 
+void DolphinColumnView::showEvent(QShowEvent* event)
+{
+    QColumnView::showEvent(event);
+    if (!event->spontaneous()) {
+        // QColumnView might clear the selection for folders that are shown in the next column.
+        // As this is not wanted the selection is updated if the directory lister has been completed.
+        const QAbstractProxyModel* proxyModel = static_cast<const QAbstractProxyModel*>(model());
+        const KDirModel* dirModel = static_cast<const KDirModel*>(proxyModel->sourceModel());
+        KDirLister* dirLister = dirModel->dirLister();
+        connect(dirLister, SIGNAL(completed()),
+                this, SLOT(updateSelections()));
+    }
+}
+
 void DolphinColumnView::zoomIn()
 {
     if (isZoomInPossible()) {
@@ -445,31 +495,23 @@ void DolphinColumnView::updateColumnsState(const KUrl& url)
     }
 }
 
-bool DolphinColumnView::isZoomInPossible() const
-{
-    ColumnModeSettings* settings = DolphinSettings::instance().columnModeSettings();
-    return settings->iconSize() < K3Icon::SizeLarge;
-}
 
-bool DolphinColumnView::isZoomOutPossible() const
+void DolphinColumnView::updateDecorationSize()
 {
     ColumnModeSettings* settings = DolphinSettings::instance().columnModeSettings();
-    return settings->iconSize() > K3Icon::SizeSmall;
-}
+    const int iconSize = settings->iconSize();
 
-void DolphinColumnView::requestActivation(QWidget* column)
-{
     foreach (QObject* object, viewport()->children()) {
         if (object->inherits("QListView")) {
             ColumnWidget* widget = static_cast<ColumnWidget*>(object);
-            const bool isActive = (widget == column);
-            widget->setActive(isActive);
-            if (isActive) {
-                m_controller->setUrl(widget->url());
-            }
-       }
+            widget->setDecorationSize(QSize(iconSize, iconSize));
+        }
     }
-    updateSelections();
+
+    m_controller->setZoomInPossible(isZoomInPossible());
+    m_controller->setZoomOutPossible(isZoomOutPossible());
+
+    doItemsLayout();
 }
 
 void DolphinColumnView::updateSelections()
@@ -479,46 +521,41 @@ void DolphinColumnView::updateSelections()
         if (object->inherits("QListView")) {
             ColumnWidget* widget = static_cast<ColumnWidget*>(object);
             if (previousWidget != 0) {
-                const QAbstractProxyModel* proxyModel = static_cast<const QAbstractProxyModel*>(model());
-                const KDirModel* dirModel = static_cast<const KDirModel*>(proxyModel->sourceModel());
-                const QModelIndex dirIndex = dirModel->indexForUrl(widget->url());
-                const QModelIndex proxyIndex = proxyModel->mapFromSource(dirIndex);
-
-                QItemSelectionModel* selModel = previousWidget->selectionModel();
-                const QItemSelection selection = selModel->selection();
-                const bool isIndexSelected = selModel->isSelected(proxyIndex);
-
-                const bool clearSelection = !previousWidget->isActive() &&
-                                            ((selection.count() > 1) || !isIndexSelected);
-                if (clearSelection) {
-                    selModel->clear();
-                }
-                if (!isIndexSelected) {
-                    selModel->select(proxyIndex, QItemSelectionModel::Select);
-                }
+                previousWidget->updateSelection(widget->url());
             }
-
             previousWidget = widget;
        }
     }
+    if (previousWidget != 0) {
+        previousWidget->updateSelection(KUrl());
+    }
 }
 
-void DolphinColumnView::updateDecorationSize()
+bool DolphinColumnView::isZoomInPossible() const
 {
     ColumnModeSettings* settings = DolphinSettings::instance().columnModeSettings();
-    const int iconSize = settings->iconSize();
+    return settings->iconSize() < K3Icon::SizeLarge;
+}
 
+bool DolphinColumnView::isZoomOutPossible() const
+{
+    ColumnModeSettings* settings = DolphinSettings::instance().columnModeSettings();
+    return settings->iconSize() > K3Icon::SizeSmall;
+}
+
+void DolphinColumnView::requestActivation(QWidget* column)
+{
     foreach (QObject* object, viewport()->children()) {
         if (object->inherits("QListView")) {
             ColumnWidget* widget = static_cast<ColumnWidget*>(object);
-            widget->setDecorationSize(QSize(iconSize, iconSize));
-        }
+            const bool isActive = (widget == column);
+            widget->setActive(isActive);
+            if (isActive) {
+                m_controller->setUrl(widget->url());
+            }
+       }
     }
-
-    m_controller->setZoomInPossible(isZoomInPossible());
-    m_controller->setZoomOutPossible(isZoomOutPossible());
-
-    doItemsLayout();
+    updateSelections();
 }
 
 #include "dolphincolumnview.moc"
index 274b71195bfe93a45f304929d5e93f77415d2081..59bb805fe13f74e16b44c83b6f25e9d6c68a7174 100644 (file)
@@ -46,6 +46,7 @@ protected:
     virtual void mousePressEvent(QMouseEvent* event);
     virtual void dragEnterEvent(QDragEnterEvent* event);
     virtual void dropEvent(QDropEvent* event);
+    virtual void showEvent(QShowEvent* event);
 
 private slots:
     void zoomIn();
@@ -59,15 +60,13 @@ private slots:
      */
     void updateColumnsState(const KUrl& url);
 
-private:
-    bool isZoomInPossible() const;
-    bool isZoomOutPossible() const;
-
     /**
-     * Requests the activation for the column \a column. The URL
-     * navigator will be changed to represent the column.
+     * Updates the size of the decoration dependent on the
+     * icon size of the ColumnModeSettings. The controller
+     * will get informed about possible zoom in/zoom out
+     * operations.
      */
-    void requestActivation(QWidget* column);
+    void updateDecorationSize();
 
     /**
      * Updates the selections of all columns to assure that
@@ -76,13 +75,15 @@ private:
      */
     void updateSelections();
 
+private:
+    bool isZoomInPossible() const;
+    bool isZoomOutPossible() const;
+
     /**
-     * Updates the size of the decoration dependent on the
-     * icon size of the ColumnModeSettings. The controller
-     * will get informed about possible zoom in/zoom out
-     * operations.
+     * Requests the activation for the column \a column. The URL
+     * navigator will be changed to represent the column.
      */
-    void updateDecorationSize();
+    void requestActivation(QWidget* column);
 
 private:
     DolphinController* m_controller;