]> cloud.milkyroute.net Git - dolphin.git/blobdiff - src/dolphincolumnview.cpp
implemented keyboard navigation for the column view
[dolphin.git] / src / dolphincolumnview.cpp
index c702b8a62d9918d533360d4021ce505cbbe57beb..7a1bc4a25969e525434d77639b42930a61e5a923 100644 (file)
@@ -19,6 +19,7 @@
 
 #include "dolphincolumnview.h"
 
+#include "dolphinmodel.h"
 #include "dolphincontroller.h"
 #include "dolphinsettings.h"
 
 
 #include <kcolorutils.h>
 #include <kcolorscheme.h>
-#include <kdirmodel.h>
+#include <kdirlister.h>
 
 #include <QAbstractProxyModel>
+#include <QApplication>
 #include <QPoint>
+#include <QScrollBar>
+#include <QTimeLine>
 
 /**
  * Represents one column inside the DolphinColumnView and has been
@@ -54,6 +58,17 @@ public:
     void setActive(bool active);
     inline bool isActive() const;
 
+    /**
+     * Sets the directory URL of the child column that is shown next to
+     * this column. This property is only used for a visual indication
+     * of the shown directory, it does not trigger a loading of the model.
+     */
+    inline void setChildUrl(const KUrl& url);
+    inline const KUrl& childUrl() const;
+
+    /**
+     * Returns the directory URL that is shown inside the column widget.
+     */
     inline const KUrl& url() const;
 
 protected:
@@ -62,9 +77,11 @@ protected:
     virtual void dragLeaveEvent(QDragLeaveEvent* event);
     virtual void dragMoveEvent(QDragMoveEvent* event);
     virtual void dropEvent(QDropEvent* event);
-    virtual void mousePressEvent(QMouseEvent* event);
     virtual void paintEvent(QPaintEvent* event);
+    virtual void mousePressEvent(QMouseEvent* event);
+    virtual void keyPressEvent(QKeyEvent* event);
     virtual void contextMenuEvent(QContextMenuEvent* event);
+    virtual void selectionChanged(const QItemSelection& selected, const QItemSelection& deselected);
 
 private:
     /** Used by ColumnWidget::setActive(). */
@@ -76,7 +93,8 @@ private:
 private:
     bool m_active;
     DolphinColumnView* m_view;
-    KUrl m_url;
+    KUrl m_url;      // URL of the directory that is shown
+    KUrl m_childUrl; // URL of the next column that is shown
     QStyleOptionViewItem m_viewOptions;
 
     bool m_dragging;   // TODO: remove this property when the issue #160611 is solved in Qt 4.4
@@ -86,19 +104,23 @@ private:
 ColumnWidget::ColumnWidget(QWidget* parent,
                            DolphinColumnView* columnView,
                            const KUrl& url) :
-    QListView(parent),
+    QListView(columnView),
     m_active(true),
     m_view(columnView),
     m_url(url),
+    m_childUrl(),
     m_dragging(false),
     m_dropRect()
 {
-    setAcceptDrops(true);
-    setDragDropMode(QAbstractItemView::DragDrop);
-    setDropIndicatorShown(false);
-
     setMouseTracking(true);
     viewport()->setAttribute(Qt::WA_Hover);
+    setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
+    setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn);
+    setSelectionBehavior(SelectItems);
+    setSelectionMode(QAbstractItemView::ExtendedSelection);
+    setDragDropMode(QAbstractItemView::DragDrop);
+    setDropIndicatorShown(false);
+    setFocusPolicy(Qt::NoFocus);
 
     // apply the column mode settings to the widget
     const ColumnModeSettings* settings = DolphinSettings::instance().columnModeSettings();
@@ -114,7 +136,15 @@ ColumnWidget::ColumnWidget(QWidget* parent,
     const int iconSize = settings->iconSize();
     m_viewOptions.decorationSize = QSize(iconSize, iconSize);
 
+    KFileItemDelegate* delegate = new KFileItemDelegate(this);
+    setItemDelegate(delegate);
+
     activate();
+
+    connect(this, SIGNAL(entered(const QModelIndex&)),
+            m_view->m_controller, SLOT(emitItemEntered(const QModelIndex&)));
+    connect(this, SIGNAL(viewportEntered()),
+            m_view->m_controller, SLOT(emitViewportEntered()));
 }
 
 ColumnWidget::~ColumnWidget()
@@ -147,6 +177,16 @@ inline bool ColumnWidget::isActive() const
     return m_active;
 }
 
+inline void ColumnWidget::setChildUrl(const KUrl& url)
+{
+    m_childUrl = url;
+}
+
+inline const KUrl& ColumnWidget::childUrl() const
+{
+    return m_childUrl;
+}
+
 const KUrl& ColumnWidget::url() const
 {
     return m_url;
@@ -179,7 +219,7 @@ void ColumnWidget::dragMoveEvent(QDragMoveEvent* event)
 {
     QListView::dragMoveEvent(event);
 
-   // TODO: remove this code when the issue #160611 is solved in Qt 4.4
+    // TODO: remove this code when the issue #160611 is solved in Qt 4.4
     const QModelIndex index = indexAt(event->pos());
     setDirtyRegion(m_dropRect);
     m_dropRect = visualRect(index);
@@ -192,6 +232,7 @@ void ColumnWidget::dropEvent(QDropEvent* event)
     if (!urls.isEmpty()) {
         event->acceptProposedAction();
         m_view->m_controller->indicateDroppedUrls(urls,
+                                                  url(),
                                                   indexAt(event->pos()),
                                                   event->source());
     }
@@ -199,34 +240,29 @@ void ColumnWidget::dropEvent(QDropEvent* event)
     m_dragging = false;
 }
 
-void ColumnWidget::mousePressEvent(QMouseEvent* event)
+void ColumnWidget::paintEvent(QPaintEvent* event)
 {
-    QListView::mousePressEvent(event);
-    const QModelIndex index = indexAt(event->pos());
-
-    bool requestActivation = false;
-    if (index.isValid()) {
-        // A click on an item has been done. Only request an activation
-        // if the item is not a directory.
+    if (!m_childUrl.isEmpty()) {
+        // indicate the shown URL of the next column by highlighting the shown folder item
         const QAbstractProxyModel* proxyModel = static_cast<const QAbstractProxyModel*>(m_view->model());
-        const KDirModel* dirModel = static_cast<const KDirModel*>(proxyModel->sourceModel());
-        const QModelIndex dirIndex = proxyModel->mapToSource(index);
-        KFileItem* item = dirModel->itemForIndex(dirIndex);
-        requestActivation = (item != 0) && !item->isDir();
-    } else {
-        // a click on the viewport has been done
-        requestActivation = true;
-    }
-
-    if (requestActivation) {
-        m_view->requestActivation(this);
-    } else {
-        m_view->updateSelections();
+        const DolphinModel* dolphinModel = static_cast<const DolphinModel*>(proxyModel->sourceModel());
+        const QModelIndex dirIndex = dolphinModel->indexForUrl(m_childUrl);
+        const QModelIndex proxyIndex = proxyModel->mapFromSource(dirIndex);
+        if (proxyIndex.isValid() && !selectionModel()->isSelected(proxyIndex)) {
+            const QRect itemRect = visualRect(proxyIndex);
+            QPainter painter(viewport());
+            painter.save();
+
+            QColor color = KColorScheme(QPalette::Active, KColorScheme::View).foreground().color();
+            color.setAlpha(32);
+            painter.setPen(Qt::NoPen);
+            painter.setBrush(color);
+            painter.drawRect(itemRect);
+
+            painter.restore();
+        }
     }
-}
 
-void ColumnWidget::paintEvent(QPaintEvent* event)
-{
     QListView::paintEvent(event);
 
     // TODO: remove this code when the issue #160611 is solved in Qt 4.4
@@ -236,9 +272,34 @@ void ColumnWidget::paintEvent(QPaintEvent* event)
     }
 }
 
+void ColumnWidget::mousePressEvent(QMouseEvent* event)
+{
+    if (!m_active) {
+        m_view->requestActivation(this);
+    }
+
+    QListView::mousePressEvent(event);
+}
+
+void ColumnWidget::keyPressEvent(QKeyEvent* event)
+{
+    QListView::keyPressEvent(event);
+
+    const QItemSelectionModel* selModel = selectionModel();
+    const QModelIndex currentIndex = selModel->currentIndex();
+    const bool triggerItem = currentIndex.isValid()
+                             && (event->key() == Qt::Key_Return)
+                             && (selModel->selectedIndexes().count() <= 1);
+    if (triggerItem) {
+        m_view->triggerItem(currentIndex);
+    }
+}
+
 void ColumnWidget::contextMenuEvent(QContextMenuEvent* event)
 {
-    m_view->requestActivation(this);
+    if (!m_active) {
+        m_view->requestActivation(this);
+    }
 
     QListView::contextMenuEvent(event);
 
@@ -251,51 +312,94 @@ void ColumnWidget::contextMenuEvent(QContextMenuEvent* event)
     }
 }
 
+void ColumnWidget::selectionChanged(const QItemSelection& selected, const QItemSelection& deselected)
+{
+    QListView::selectionChanged(selected, deselected);
+
+    QItemSelectionModel* selModel = m_view->selectionModel();
+    selModel->select(selected, QItemSelectionModel::Select);
+    selModel->select(deselected, QItemSelectionModel::Deselect);
+}
+
 void ColumnWidget::activate()
 {
-    const QColor bgColor = KColorScheme(KColorScheme::View).background();
+    if (m_view->hasFocus()) {
+        setFocus(Qt::OtherFocusReason);
+    }
+    m_view->setFocusProxy(this);
+
+    // TODO: Connecting to the signal 'activated()' is not possible, as kstyle
+    // does not forward the single vs. doubleclick to it yet (KDE 4.1?). Hence it is
+    // necessary connecting the signal 'singleClick()' or 'doubleClick'.
+    if (KGlobalSettings::singleClick()) {
+        connect(this, SIGNAL(clicked(const QModelIndex&)),
+                m_view, SLOT(triggerItem(const QModelIndex&)));
+    } else {
+        connect(this, SIGNAL(doubleClicked(const QModelIndex&)),
+                m_view, SLOT(triggerItem(const QModelIndex&)));
+    }
+
+    const QColor bgColor = KColorScheme(QPalette::Active, KColorScheme::View).background().color();
     QPalette palette = viewport()->palette();
     palette.setColor(viewport()->backgroundRole(), bgColor);
     viewport()->setPalette(palette);
 
-    setSelectionMode(MultiSelection);
+    if (!m_childUrl.isEmpty()) {
+        // assure that the current index is set on the index that represents
+        // the child URL
+        const QAbstractProxyModel* proxyModel = static_cast<const QAbstractProxyModel*>(model());
+        const KDirModel* dirModel = static_cast<const KDirModel*>(proxyModel->sourceModel());
+        const QModelIndex dirIndex = dirModel->indexForUrl(m_childUrl);
+        const QModelIndex proxyIndex = proxyModel->mapFromSource(dirIndex);
+        selectionModel()->setCurrentIndex(proxyIndex, QItemSelectionModel::Current);
+    }
+
     update();
 }
 
 void ColumnWidget::deactivate()
 {
-    QColor bgColor = KColorScheme(KColorScheme::View).background();
-    const QColor fgColor = KColorScheme(KColorScheme::View).foreground();
+    // TODO: Connecting to the signal 'activated()' is not possible, as kstyle
+    // does not forward the single vs. doubleclick to it yet (KDE 4.1?). Hence it is
+    // necessary connecting the signal 'singleClick()' or 'doubleClick'.
+    if (KGlobalSettings::singleClick()) {
+        disconnect(this, SIGNAL(clicked(const QModelIndex&)),
+                   m_view, SLOT(triggerItem(const QModelIndex&)));
+    } else {
+        disconnect(this, SIGNAL(doubleClicked(const QModelIndex&)),
+                   m_view, SLOT(triggerItem(const QModelIndex&)));
+    }
+
+    QColor bgColor = KColorScheme(QPalette::Active, KColorScheme::View).background().color();
+    const QColor fgColor = KColorScheme(QPalette::Active, KColorScheme::View).foreground().color();
     bgColor = KColorUtils::mix(bgColor, fgColor, 0.04);
 
     QPalette palette = viewport()->palette();
     palette.setColor(viewport()->backgroundRole(), bgColor);
     viewport()->setPalette(palette);
 
-    setSelectionMode(SingleSelection);
+    selectionModel()->clear();
+
     update();
 }
 
 // ---
 
 DolphinColumnView::DolphinColumnView(QWidget* parent, DolphinController* controller) :
-    QColumnView(parent),
-    m_controller(controller)
+    QAbstractItemView(parent),
+    m_controller(controller),
+    m_index(-1),
+    m_contentX(0),
+    m_columns(),
+    m_animation(0)
 {
     Q_ASSERT(controller != 0);
 
     setAcceptDrops(true);
     setDragDropMode(QAbstractItemView::DragDrop);
     setDropIndicatorShown(false);
-    setSelectionMode(MultiSelection);
+    setSelectionMode(ExtendedSelection);
 
-    if (KGlobalSettings::singleClick()) {
-        connect(this, SIGNAL(clicked(const QModelIndex&)),
-                this, SLOT(triggerItem(const QModelIndex&)));
-    } else {
-        connect(this, SIGNAL(doubleClicked(const QModelIndex&)),
-                this, SLOT(triggerItem(const QModelIndex&)));
-    }
     connect(this, SIGNAL(entered(const QModelIndex&)),
             controller, SLOT(emitItemEntered(const QModelIndex&)));
     connect(this, SIGNAL(viewportEntered()),
@@ -305,100 +409,130 @@ DolphinColumnView::DolphinColumnView(QWidget* parent, DolphinController* control
     connect(controller, SIGNAL(zoomOut()),
             this, SLOT(zoomOut()));
     connect(controller, SIGNAL(urlChanged(const KUrl&)),
-            this, SLOT(updateColumnsState(const KUrl&)));
+            this, SLOT(showColumn(const KUrl&)));
+
+    connect(horizontalScrollBar(), SIGNAL(valueChanged(int)),
+            this, SLOT(moveContentHorizontally(int)));
+
+    ColumnWidget* column = new ColumnWidget(viewport(), this, m_controller->url());
+    m_columns.append(column);
+    setActiveColumnIndex(0);
 
     updateDecorationSize();
+
+    m_animation = new QTimeLine(500, this);
+    connect(m_animation, SIGNAL(frameChanged(int)), horizontalScrollBar(), SLOT(setValue(int)));
 }
 
 DolphinColumnView::~DolphinColumnView()
 {
 }
 
-QAbstractItemView* DolphinColumnView::createColumn(const QModelIndex& index)
+QModelIndex DolphinColumnView::indexAt(const QPoint& point) const
 {
-    // let the column widget be aware about its URL...
-    KUrl columnUrl;
-    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();
+    foreach (ColumnWidget* column, m_columns) {
+        const QPoint topLeft = column->frameGeometry().topLeft();
+        const QPoint adjustedPoint(point.x() - topLeft.x(), point.y() - topLeft.y());
+        const QModelIndex index = column->indexAt(adjustedPoint);
+        if (index.isValid()) {
+            return index;
         }
     }
 
-    ColumnWidget* view = new ColumnWidget(viewport(), this, columnUrl);
+    return QModelIndex();
+}
+
+void DolphinColumnView::scrollTo(const QModelIndex& index, ScrollHint hint)
+{
+    activeColumn()->scrollTo(index, hint);
+}
+
+QRect DolphinColumnView::visualRect(const QModelIndex& index) const
+{
+    return activeColumn()->visualRect(index);
+}
+
+void DolphinColumnView::setModel(QAbstractItemModel* model)
+{
+    activeColumn()->setModel(model);
+    QAbstractItemView::setModel(model);
+}
 
-    // The following code has been copied 1:1 from QColumnView::createColumn().
-    // Copyright (C) 1992-2007 Trolltech ASA. In Qt 4.4 the new method
-    // QColumnView::initializeColumn() will be available for this.
+bool DolphinColumnView::isIndexHidden(const QModelIndex& index) const
+{
+    return false;//activeColumn()->isIndexHidden(index);
+}
 
-    view->setFrameShape(QFrame::NoFrame);
-    view->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
-    view->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn);
-    view->setMinimumWidth(100);
-    view->setAttribute(Qt::WA_MacShowFocusRect, false);
+QModelIndex DolphinColumnView::moveCursor(CursorAction cursorAction, Qt::KeyboardModifiers modifiers)
+{
+    // Parts of this code have been taken from QColumnView::moveCursor().
+    // Copyright (C) 1992-2007 Trolltech ASA.
 
-    // copy the 'view' behavior
-    view->setDragDropMode(dragDropMode());
-    view->setDragDropOverwriteMode(dragDropOverwriteMode());
-    view->setDropIndicatorShown(showDropIndicator());
-    view->setAlternatingRowColors(alternatingRowColors());
-    view->setAutoScroll(hasAutoScroll());
-    view->setEditTriggers(editTriggers());
-    view->setHorizontalScrollMode(horizontalScrollMode());
-    view->setIconSize(iconSize());
-    view->setSelectionBehavior(selectionBehavior());
-    view->setSelectionMode(selectionMode());
-    view->setTabKeyNavigation(tabKeyNavigation());
-    view->setTextElideMode(textElideMode());
-    view->setVerticalScrollMode(verticalScrollMode());
+    Q_UNUSED(modifiers);
+    if (model() == 0) {
+        return QModelIndex();
+    }
 
-    view->setModel(model());
+    const QModelIndex current = currentIndex();
+    if (isRightToLeft()) {
+        if (cursorAction == MoveLeft) {
+            cursorAction = MoveRight;
+        } else if (cursorAction == MoveRight) {
+            cursorAction = MoveLeft;
+        }
+    }
 
-    // set the delegate to be the columnview delegate
-    QAbstractItemDelegate* delegate = view->itemDelegate();
-    view->setItemDelegate(itemDelegate());
-    delete delegate;
+    switch (cursorAction) {
+    case MoveLeft:
+        if (m_index > 0) {
+            setActiveColumnIndex(m_index - 1);
+        }
+        break;
 
-    view->setRootIndex(index);
+    case MoveRight:
+        if (m_index < m_columns.count() - 1) {
+            setActiveColumnIndex(m_index + 1);
+        }
+        break;
 
-    if (model()->canFetchMore(index)) {
-        model()->fetchMore(index);
+    default:
+        break;
     }
 
-    return view;
+    return QModelIndex();
 }
 
-void DolphinColumnView::mousePressEvent(QMouseEvent* event)
+void DolphinColumnView::setSelection(const QRect& rect, QItemSelectionModel::SelectionFlags flags)
 {
-    m_controller->triggerActivation();
-    QColumnView::mousePressEvent(event);
+    //activeColumn()->setSelection(rect, flags);
 }
 
-void DolphinColumnView::dragEnterEvent(QDragEnterEvent* event)
+QRegion DolphinColumnView::visualRegionForSelection(const QItemSelection& selection) const
 {
-    if (event->mimeData()->hasUrls()) {
-        event->acceptProposedAction();
-    }
+    return QRegion(); //activeColumn()->visualRegionForSelection(selection);
 }
 
-void DolphinColumnView::dropEvent(QDropEvent* event)
+int DolphinColumnView::horizontalOffset() const
 {
-    const KUrl::List urls = KUrl::List::fromMimeData(event->mimeData());
-    if (!urls.isEmpty()) {
-        m_controller->indicateDroppedUrls(urls,
-                                          indexAt(event->pos()),
-                                          event->source());
-        event->acceptProposedAction();
-    }
-    QColumnView::dropEvent(event);
+    return -m_contentX;
+}
+
+int DolphinColumnView::verticalOffset() const
+{
+    return 0;
+}
+
+void DolphinColumnView::mousePressEvent(QMouseEvent* event)
+{
+    m_controller->triggerActivation();
+    QAbstractItemView::mousePressEvent(event);
+}
+
+void DolphinColumnView::resizeEvent(QResizeEvent* event)
+{
+    QAbstractItemView::resizeEvent(event);
+    layoutColumns();
+    updateScrollBar();
 }
 
 void DolphinColumnView::zoomIn()
@@ -432,17 +566,95 @@ void DolphinColumnView::zoomOut()
 void DolphinColumnView::triggerItem(const QModelIndex& index)
 {
     m_controller->triggerItem(index);
-    updateColumnsState(m_controller->url());
+
+    const Qt::KeyboardModifiers modifiers = QApplication::keyboardModifiers();
+    if ((modifiers & Qt::ControlModifier) || (modifiers & Qt::ShiftModifier)) {
+        return;
+    }
+
+    const QAbstractProxyModel* proxyModel = static_cast<const QAbstractProxyModel*>(model());
+    const KDirModel* dirModel = static_cast<const KDirModel*>(proxyModel->sourceModel());
+    const KFileItem item = dirModel->itemForIndex(proxyModel->mapToSource(index));
+    if ((item.url() != activeColumn()->url()) && item.isDir()) {
+        deleteInactiveChildColumns();
+
+        const KUrl& childUrl = m_controller->url();
+        activeColumn()->setChildUrl(childUrl);
+
+        ColumnWidget* column = new ColumnWidget(viewport(), this, childUrl);
+        column->setModel(model());
+        column->setRootIndex(index);
+
+        m_columns.append(column);
+
+        setActiveColumnIndex(m_index + 1);
+
+        // Before invoking layoutColumns() the column must be shown. To prevent
+        // a flickering the initial geometry is set to be invisible.
+        column->setGeometry(QRect(-1, -1, 1, 1));
+        column->show();
+
+        layoutColumns();
+        updateScrollBar();
+        assureVisibleActiveColumn();
+    }
 }
 
-void DolphinColumnView::updateColumnsState(const KUrl& url)
+void DolphinColumnView::moveContentHorizontally(int x)
 {
+    m_contentX = -x;
+    layoutColumns();
+}
+
+void DolphinColumnView::showColumn(const KUrl& url)
+{
+    if (!m_columns[0]->url().isParentOf(url)) {
+        // the URL is no child URL of the column view, hence do nothing
+        return;
+    }
+
+    int columnIndex = 0;
+    foreach (ColumnWidget* column, m_columns) {
+        if (column->url() == url) {
+            // the column represents already the requested URL, hence activate it
+            requestActivation(column);
+            return;
+        } else if (!column->url().isParentOf(url)) {
+            // the column is no parent of the requested URL, hence it must
+            // be deleted and a new column must be loaded
+            if (columnIndex > 0) {
+                setActiveColumnIndex(columnIndex - 1);
+                deleteInactiveChildColumns();
+            }
+
+            const QAbstractProxyModel* proxyModel = static_cast<const QAbstractProxyModel*>(model());
+            const KDirModel* dirModel = static_cast<const KDirModel*>(proxyModel->sourceModel());
+            const QModelIndex dirIndex = dirModel->indexForUrl(url);
+            if (dirIndex.isValid()) {
+                triggerItem(proxyModel->mapFromSource(dirIndex));
+            }
+            return;
+        }
+        ++columnIndex;
+    }
+}
+
+void DolphinColumnView::updateDecorationSize()
+{
+    ColumnModeSettings* settings = DolphinSettings::instance().columnModeSettings();
+    const int iconSize = settings->iconSize();
+
     foreach (QObject* object, viewport()->children()) {
         if (object->inherits("QListView")) {
             ColumnWidget* widget = static_cast<ColumnWidget*>(object);
-            widget->setActive(widget->url() == url);
+            widget->setDecorationSize(QSize(iconSize, iconSize));
         }
     }
+
+    m_controller->setZoomInPossible(isZoomInPossible());
+    m_controller->setZoomOutPossible(isZoomOutPossible());
+
+    doItemsLayout();
 }
 
 bool DolphinColumnView::isZoomInPossible() const
@@ -457,68 +669,89 @@ bool DolphinColumnView::isZoomOutPossible() const
     return settings->iconSize() > K3Icon::SizeSmall;
 }
 
-void DolphinColumnView::requestActivation(QWidget* column)
+void DolphinColumnView::setActiveColumnIndex(int index)
 {
-    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());
-            }
-       }
+    if (m_index == index) {
+        return;
     }
-    updateSelections();
+
+    const bool hasActiveColumn = (m_index >= 0);
+    if (hasActiveColumn) {
+        m_columns[m_index]->setActive(false);
+    }
+
+    m_index = index;
+    m_columns[m_index]->setActive(true);
+
+    m_controller->setUrl(m_columns[m_index]->url());
 }
 
-void DolphinColumnView::updateSelections()
+void DolphinColumnView::layoutColumns()
 {
-    ColumnWidget* previousWidget = 0;
-    foreach (QObject* object, viewport()->children()) {
-        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 = widget;
-       }
+    int x = m_contentX;
+    ColumnModeSettings* settings = DolphinSettings::instance().columnModeSettings();
+    const int columnWidth = settings->columnWidth();
+    foreach (ColumnWidget* column, m_columns) {
+        column->setGeometry(QRect(x, 0, columnWidth, viewport()->height()));
+        x += columnWidth;
     }
 }
 
-void DolphinColumnView::updateDecorationSize()
+void DolphinColumnView::updateScrollBar()
 {
-    ColumnModeSettings* settings = DolphinSettings::instance().columnModeSettings();
-    const int iconSize = settings->iconSize();
+    int contentWidth = 0;
+    foreach (ColumnWidget* column, m_columns) {
+        contentWidth += column->width();
+    }
 
-    foreach (QObject* object, viewport()->children()) {
-        if (object->inherits("QListView")) {
-            ColumnWidget* widget = static_cast<ColumnWidget*>(object);
-            widget->setDecorationSize(QSize(iconSize, iconSize));
+    horizontalScrollBar()->setPageStep(contentWidth);
+    horizontalScrollBar()->setRange(0, contentWidth - viewport()->width());
+}
+
+void DolphinColumnView::assureVisibleActiveColumn()
+{
+    const int viewportWidth = viewport()->width();
+    const int x = activeColumn()->x();
+    const int width = activeColumn()->width();
+    if (x + width > viewportWidth) {
+        int newContentX = m_contentX - x - width + viewportWidth;
+        if (newContentX > 0) {
+            newContentX = 0;
         }
+        m_animation->setFrameRange(-m_contentX, -newContentX);
+        m_animation->start();
+    } else if (x < 0) {
+        const int newContentX = m_contentX - x;
+        m_animation->setFrameRange(-m_contentX, -newContentX);
+        m_animation->start();
     }
+}
 
-    m_controller->setZoomInPossible(isZoomInPossible());
-    m_controller->setZoomOutPossible(isZoomOutPossible());
+void DolphinColumnView::requestActivation(ColumnWidget* column)
+{
+    if (column->isActive()) {
+        assureVisibleActiveColumn();
+    } else {
+        int index = 0;
+        foreach (ColumnWidget* currColumn, m_columns) {
+            if (currColumn == column) {
+                setActiveColumnIndex(index);
+                assureVisibleActiveColumn();
+                return;
+            }
+            ++index;
+        }
+    }
+}
 
-    doItemsLayout();
+void DolphinColumnView::deleteInactiveChildColumns()
+{
+    QList<ColumnWidget*>::iterator start = m_columns.begin() + m_index + 1;
+    QList<ColumnWidget*>::iterator end = m_columns.end();
+    for (QList<ColumnWidget*>::iterator it = start; it != end; ++it) {
+        (*it)->deleteLater();
+    }
+    m_columns.erase(start, end);
 }
 
 #include "dolphincolumnview.moc"