]> cloud.milkyroute.net Git - dolphin.git/commitdiff
Improve handling of column view:
authorPeter Penz <peter.penz19@gmail.com>
Thu, 28 Jun 2007 18:52:54 +0000 (18:52 +0000)
committerPeter Penz <peter.penz19@gmail.com>
Thu, 28 Jun 2007 18:52:54 +0000 (18:52 +0000)
* Activate column on a mouse press event
* Always synchronize the active column with the URL navigator and vice versa

svn path=/trunk/KDE/kdebase/apps/; revision=681369

src/dolphincolumnview.cpp
src/dolphincolumnview.h
src/dolphincontroller.cpp
src/dolphincontroller.h
src/dolphinview.cpp

index c132cc1642f3527a850fcdefcf3ec4151d332638..1ab49d05ba3efc88acaa46352364f274dc24fca9 100644 (file)
 
 #include <kcolorutils.h>
 #include <kcolorscheme.h>
+#include <kdirlister.h>
+#include <kdirmodel.h>
 
+#include <QAbstractProxyModel>
 #include <QPoint>
 
 /**
@@ -181,13 +184,8 @@ void ColumnWidget::dropEvent(QDropEvent* event)
 
 void ColumnWidget::mousePressEvent(QMouseEvent* event)
 {
-    if (m_active || indexAt(event->pos()).isValid()) {
-        // Only accept the mouse press event in inactive views,
-        // if a click is done on an item. This assures that
-        // the current selection, which usually shows the
-        // the directory for next column, won't get deleted.
-        QListView::mousePressEvent(event);
-    }
+    m_view->requestActivation(this);
+    QListView::mousePressEvent(event);
 }
 
 void ColumnWidget::paintEvent(QPaintEvent* event)
@@ -265,6 +263,8 @@ DolphinColumnView::DolphinColumnView(QWidget* parent, DolphinController* control
             this, SLOT(zoomIn()));
     connect(controller, SIGNAL(zoomOut()),
             this, SLOT(zoomOut()));
+    connect(controller, SIGNAL(urlChanged(const KUrl&)),
+            this, SLOT(updateColumnsState(const KUrl&)));
 
     updateDecorationSize();
 }
@@ -374,14 +374,20 @@ void DolphinColumnView::zoomOut()
 void DolphinColumnView::triggerItem(const QModelIndex& index)
 {
     m_controller->triggerItem(index);
+    updateColumnsState(m_controller->url());
+}
+
+void DolphinColumnView::updateColumnsState(const KUrl& url)
+{
+    const KUrl baseUrl = dirLister()->url();
+    const int activeIndex = url.path().count('/') - baseUrl.path().count('/');
 
-    // assure that the last column gets marked as active and all
-    // other columns as inactive
-    QObject* lastWidget = viewport()->children().last();
+    int index = 0;
     foreach (QObject* object, viewport()->children()) {
         if (object->inherits("QListView")) {
             ColumnWidget* widget = static_cast<ColumnWidget*>(object);
-            widget->setActive(widget == lastWidget);
+            widget->setActive(index == activeIndex);
+            ++index;
         }
     }
 }
@@ -398,6 +404,23 @@ bool DolphinColumnView::isZoomOutPossible() const
     return settings->iconSize() > K3Icon::SizeSmall;
 }
 
+void DolphinColumnView::requestActivation(QWidget* column)
+{
+    KUrl::List dirs = dirLister()->directories();
+    KUrl::List::const_iterator it = dirs.constBegin();
+    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(*it);
+            }
+            ++it;
+        }
+    }
+}
+
 void DolphinColumnView::updateDecorationSize()
 {
     ColumnModeSettings* settings = DolphinSettings::instance().columnModeSettings();
@@ -416,4 +439,11 @@ void DolphinColumnView::updateDecorationSize()
     doItemsLayout();
 }
 
+KDirLister* DolphinColumnView::dirLister() const
+{
+    const QAbstractProxyModel* proxyModel = static_cast<const QAbstractProxyModel*>(model());
+    const KDirModel* dirModel = static_cast<const KDirModel*>(proxyModel->sourceModel());
+    return dirModel->dirLister();
+}
+
 #include "dolphincolumnview.moc"
index 978847ab6b9fee1fac1a14b74019958179ba09f6..eb5d33342c84ed2fb022cf78cc77c39ac1a932c8 100644 (file)
@@ -24,6 +24,8 @@
 #include <QtGui/QStyleOption>
 
 class DolphinController;
+class KDirLister;
+class KUrl;
 
 /**
  * @brief Represents the view, where each directory is show as separate column.
@@ -50,10 +52,23 @@ private slots:
     void zoomOut();
     void triggerItem(const QModelIndex& index);
 
+    /**
+     * Updates the activation state of all columns, where \a url
+     * represents the URL of the active column. All operations
+     * are applied only to the column which is marked as active.
+     */
+    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.
+     */
+    void requestActivation(QWidget* column);
+
     /**
      * Updates the size of the decoration dependent on the
      * icon size of the ColumnModeSettings. The controller
@@ -62,6 +77,9 @@ private:
      */
     void updateDecorationSize();
 
+    /** Returns the directory lister used by the view. */
+    KDirLister* dirLister() const;
+
 private:
     DolphinController* m_controller;
 
index 1831c15c33670dca59475ee9341d427d229d122c..0f308481fba40691ef1a2de818c019fd7ed3e1ea 100644 (file)
@@ -34,6 +34,14 @@ DolphinController::~DolphinController()
 {
 }
 
+void DolphinController::setUrl(const KUrl& url)
+{
+    if (m_url != url) {
+        m_url = url;
+        emit urlChanged(url);
+    }
+}
+
 void DolphinController::triggerContextMenuRequest(const QPoint& pos)
 {
     emit activated();
index aa0eab22fabbcc4d7fd5cafa0317dcc401a53af5..356daead5e49a3b209bfc6cf75e28fffe41a7665 100644 (file)
@@ -57,7 +57,8 @@ public:
     explicit DolphinController(QObject* parent);
     virtual ~DolphinController();
 
-    inline void setUrl(const KUrl& url);
+    /** Sets the URL to \a url and emits the signal urlChanged(). */
+    void setUrl(const KUrl& url);
     inline const KUrl& url() const;
 
     void triggerContextMenuRequest(const QPoint& pos);
@@ -110,6 +111,12 @@ public slots:
     void emitViewportEntered();
 
 signals:
+    /**
+     * Is emitted if the URL for the Dolphin controller has been changed
+     * to \a url.
+     */
+    void urlChanged(const KUrl& url);
+
     /**
      * Is emitted if a context menu should be opened.
      * @param pos       Position relative to the view widget where the
@@ -183,11 +190,6 @@ private:
     KUrl m_url;
 };
 
-void DolphinController::setUrl(const KUrl& url)
-{
-    m_url = url;
-}
-
 const KUrl& DolphinController::url() const
 {
     return m_url;
index 4964010c52357f1664b24c5939524ddaf41d602c..5a1de5217e1c0702e42d4ce281c3b18a3dee7f66 100644 (file)
@@ -89,6 +89,8 @@ DolphinView::DolphinView(QWidget* parent,
 
     m_controller = new DolphinController(this);
     m_controller->setUrl(url);
+    connect(m_controller, SIGNAL(urlChanged(const KUrl&)),
+            this, SIGNAL(urlChanged(const KUrl&)));
     connect(m_controller, SIGNAL(requestContextMenu(const QPoint&)),
             this, SLOT(openContextMenu(const QPoint&)));
     connect(m_controller, SIGNAL(urlsDropped(const KUrl::List&, const QModelIndex&, QWidget*)),