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
This commit is contained in:
Peter Penz 2007-06-28 18:52:54 +00:00
parent ba6c853219
commit 34ff90696f
5 changed files with 77 additions and 17 deletions

View file

@ -26,7 +26,10 @@
#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());
}
// 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<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"

View 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;

View 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();

View 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;

View 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*)),