]> cloud.milkyroute.net Git - dolphin.git/blobdiff - src/dolphincolumnview.cpp
Clarify some adjectives.
[dolphin.git] / src / dolphincolumnview.cpp
index 81337cb20c296bbecfba385e6b045aef1f09bc49..96ff728a2a1597627ed85fff083a3c6922bf61ea 100644 (file)
@@ -1,5 +1,5 @@
 /***************************************************************************
- *   Copyright (C) 2006 by Peter Penz (peter.penz@gmx.at)                  *
+ *   Copyright (C) 2007 by Peter Penz <peter.penz@gmx.at>                  *
  *                                                                         *
  *   This program is free software; you can redistribute it and/or modify  *
  *   it under the terms of the GNU General Public License as published by  *
@@ -26,9 +26,8 @@
 
 #include <kcolorutils.h>
 #include <kcolorscheme.h>
-#include <kdirmodel.h>
 #include <kdirlister.h>
-#include <kfileitem.h>
+#include <kdirmodel.h>
 
 #include <QAbstractProxyModel>
 #include <QPoint>
@@ -63,7 +62,7 @@ protected:
     virtual void dragLeaveEvent(QDragLeaveEvent* event);
     virtual void dragMoveEvent(QDragMoveEvent* event);
     virtual void dropEvent(QDropEvent* event);
-    virtual void mousePressEvent(QMouseEvent* event);
+    virtual void mouseReleaseEvent(QMouseEvent* event);
     virtual void paintEvent(QPaintEvent* event);
     virtual void contextMenuEvent(QContextMenuEvent* event);
 
@@ -76,8 +75,8 @@ private:
 
 private:
     bool m_active;
-    KUrl m_url;
     DolphinColumnView* m_view;
+    KUrl m_url;
     QStyleOptionViewItem m_viewOptions;
 
     bool m_dragging;   // TODO: remove this property when the issue #160611 is solved in Qt 4.4
@@ -89,8 +88,8 @@ ColumnWidget::ColumnWidget(QWidget* parent,
                            const KUrl& url) :
     QListView(parent),
     m_active(true),
-    m_url(url),
     m_view(columnView),
+    m_url(url),
     m_dragging(false),
     m_dropRect()
 {
@@ -195,15 +194,10 @@ void ColumnWidget::dropEvent(QDropEvent* event)
     m_dragging = false;
 }
 
-void ColumnWidget::mousePressEvent(QMouseEvent* event)
+void ColumnWidget::mouseReleaseEvent(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::mouseReleaseEvent(event);
 }
 
 void ColumnWidget::paintEvent(QPaintEvent* event)
@@ -219,22 +213,12 @@ void ColumnWidget::paintEvent(QPaintEvent* event)
 
 void ColumnWidget::contextMenuEvent(QContextMenuEvent* event)
 {
-    if (m_view->viewport()->children().first() == this) {
-        // This column widget represents the root column. DolphinColumnView::createColumn()
-        // cannot retrieve the correct URL at this stage, as the directory lister will be
-        // started after the model has been assigned. This will be fixed here, where it is
-        // assured that the directory lister has been started already.
-        const QAbstractProxyModel* proxyModel = static_cast<const QAbstractProxyModel*>(model());
-        const KDirModel* dirModel = static_cast<const KDirModel*>(proxyModel->sourceModel());
-        const KDirLister* dirLister = dirModel->dirLister();
-        m_url = dirLister->url();
-    }
+    m_view->requestActivation(this);
 
     QListView::contextMenuEvent(event);
 
     const QModelIndex index = indexAt(event->pos());
-    const KUrl& navigatorUrl = m_view->m_controller->url();
-    if (index.isValid() || (m_url == navigatorUrl)) {
+    if (index.isValid() || m_active) {
         // Only open a context menu above an item or if the mouse is above
         // the active column.
         const QPoint pos = m_view->viewport()->mapFromGlobal(event->globalPos());
@@ -250,6 +234,7 @@ void ColumnWidget::activate()
     viewport()->setPalette(palette);
 
     setSelectionMode(MultiSelection);
+    update();
 }
 
 void ColumnWidget::deactivate()
@@ -263,6 +248,7 @@ void ColumnWidget::deactivate()
     viewport()->setPalette(palette);
 
     setSelectionMode(SingleSelection);
+    update();
 }
 
 // ---
@@ -285,8 +271,6 @@ DolphinColumnView::DolphinColumnView(QWidget* parent, DolphinController* control
         connect(this, SIGNAL(doubleClicked(const QModelIndex&)),
                 this, SLOT(triggerItem(const QModelIndex&)));
     }
-    connect(this, SIGNAL(activated(const QModelIndex&)),
-            this, SLOT(triggerItem(const QModelIndex&)));
     connect(this, SIGNAL(entered(const QModelIndex&)),
             controller, SLOT(emitItemEntered(const QModelIndex&)));
     connect(this, SIGNAL(viewportEntered()),
@@ -295,6 +279,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();
 }
@@ -305,23 +291,24 @@ DolphinColumnView::~DolphinColumnView()
 
 QAbstractItemView* DolphinColumnView::createColumn(const QModelIndex& index)
 {
-    // To be able to visually indicate whether a column is active (which means
-    // that it represents the content of the URL navigator), the column
-    // must remember its URL.
-    const QAbstractProxyModel* proxyModel = static_cast<const QAbstractProxyModel*>(model());
-    const KDirModel* dirModel = static_cast<const KDirModel*>(proxyModel->sourceModel());
-
-    const QModelIndex dirModelIndex = proxyModel->mapToSource(index);
-    KFileItem* fileItem = dirModel->itemForIndex(dirModelIndex);
-
+    // let the column widget be aware about its URL...
     KUrl columnUrl;
-    if (fileItem != 0) {
-        columnUrl = fileItem->url();
+    if (viewport()->children().count() == 0) {
+        // For the first column widget the directory lister has not been started
+        // yet, hence use the URL from the controller instead.
+        columnUrl = m_controller->url();
+    } else {
+        const QAbstractProxyModel* proxyModel = static_cast<const QAbstractProxyModel*>(model());
+        const KDirModel* dirModel = static_cast<const KDirModel*>(proxyModel->sourceModel());
+
+        const QModelIndex dirModelIndex = proxyModel->mapToSource(index);
+        KFileItem* fileItem = dirModel->itemForIndex(dirModelIndex);
+        if (fileItem != 0) {
+            columnUrl = fileItem->url();
+        }
     }
 
-    ColumnWidget* view = new ColumnWidget(viewport(),
-                                          this,
-                                          columnUrl);
+    ColumnWidget* view = new ColumnWidget(viewport(), this, columnUrl);
 
     // The following code has been copied 1:1 from QColumnView::createColumn().
     // Copyright (C) 1992-2007 Trolltech ASA. In Qt 4.4 the new method
@@ -420,14 +407,15 @@ void DolphinColumnView::zoomOut()
 void DolphinColumnView::triggerItem(const QModelIndex& index)
 {
     m_controller->triggerItem(index);
+    updateColumnsState(m_controller->url());
+}
 
-    // Update the activation state of all columns. Only the column
-    // which represents the URL of the URL navigator is marked as active.
-    const KUrl& navigatorUrl = m_controller->url();
+void DolphinColumnView::updateColumnsState(const KUrl& url)
+{
     foreach (QObject* object, viewport()->children()) {
         if (object->inherits("QListView")) {
             ColumnWidget* widget = static_cast<ColumnWidget*>(object);
-            widget->setActive(navigatorUrl == widget->url());
+            widget->setActive(widget->url() == url);
         }
     }
 }
@@ -444,6 +432,20 @@ bool DolphinColumnView::isZoomOutPossible() const
     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);
+            const bool isActive = (widget == column);
+            widget->setActive(isActive);
+            if (isActive) {
+                m_controller->setUrl(widget->url());
+            }
+        }
+    }
+}
+
 void DolphinColumnView::updateDecorationSize()
 {
     ColumnModeSettings* settings = DolphinSettings::instance().columnModeSettings();