From 34ff90696f8a9d8a5d2c02be1b11b4d092b888c1 Mon Sep 17 00:00:00 2001 From: Peter Penz Date: Thu, 28 Jun 2007 18:52:54 +0000 Subject: [PATCH] Improve handling of column view: * 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 | 52 ++++++++++++++++++++++++++++++--------- src/dolphincolumnview.h | 18 ++++++++++++++ src/dolphincontroller.cpp | 8 ++++++ src/dolphincontroller.h | 14 ++++++----- src/dolphinview.cpp | 2 ++ 5 files changed, 77 insertions(+), 17 deletions(-) diff --git a/src/dolphincolumnview.cpp b/src/dolphincolumnview.cpp index c132cc1642..1ab49d05ba 100644 --- a/src/dolphincolumnview.cpp +++ b/src/dolphincolumnview.cpp @@ -26,7 +26,10 @@ #include #include +#include +#include +#include #include /** @@ -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()); +} - // assure that the last column gets marked as active and all - // other columns as inactive - QObject* lastWidget = viewport()->children().last(); +void DolphinColumnView::updateColumnsState(const KUrl& url) +{ + const KUrl baseUrl = dirLister()->url(); + const int activeIndex = url.path().count('/') - baseUrl.path().count('/'); + + int index = 0; foreach (QObject* object, viewport()->children()) { if (object->inherits("QListView")) { ColumnWidget* widget = static_cast(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(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(model()); + const KDirModel* dirModel = static_cast(proxyModel->sourceModel()); + return dirModel->dirLister(); +} + #include "dolphincolumnview.moc" diff --git a/src/dolphincolumnview.h b/src/dolphincolumnview.h index 978847ab6b..eb5d33342c 100644 --- a/src/dolphincolumnview.h +++ b/src/dolphincolumnview.h @@ -24,6 +24,8 @@ #include 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; diff --git a/src/dolphincontroller.cpp b/src/dolphincontroller.cpp index 1831c15c33..0f308481fb 100644 --- a/src/dolphincontroller.cpp +++ b/src/dolphincontroller.cpp @@ -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(); diff --git a/src/dolphincontroller.h b/src/dolphincontroller.h index aa0eab22fa..356daead5e 100644 --- a/src/dolphincontroller.h +++ b/src/dolphincontroller.h @@ -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; diff --git a/src/dolphinview.cpp b/src/dolphinview.cpp index 4964010c52..5a1de5217e 100644 --- a/src/dolphinview.cpp +++ b/src/dolphinview.cpp @@ -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*)),