#include <kcolorutils.h>
#include <kcolorscheme.h>
+#include <kdirlister.h>
+#include <kdirmodel.h>
+#include <QAbstractProxyModel>
#include <QPoint>
/**
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)
this, SLOT(zoomIn()));
connect(controller, SIGNAL(zoomOut()),
this, SLOT(zoomOut()));
+ connect(controller, SIGNAL(urlChanged(const KUrl&)),
+ this, SLOT(updateColumnsState(const KUrl&)));
updateDecorationSize();
}
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;
}
}
}
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();
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"
#include <QtGui/QStyleOption>
class DolphinController;
+class KDirLister;
+class KUrl;
/**
* @brief Represents the view, where each directory is show as separate column.
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
*/
void updateDecorationSize();
+ /** Returns the directory lister used by the view. */
+ KDirLister* dirLister() const;
+
private:
DolphinController* m_controller;
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);
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
KUrl m_url;
};
-void DolphinController::setUrl(const KUrl& url)
-{
- m_url = url;
-}
-
const KUrl& DolphinController::url() const
{
return m_url;
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*)),