┌   ┐
54
└   ┘

summaryrefslogtreecommitdiff
path: root/src/dolphincolumnview.cpp
diff options
context:
space:
mode:
authorPeter Penz <[email protected]>2007-09-19 13:00:22 +0000
committerPeter Penz <[email protected]>2007-09-19 13:00:22 +0000
commit539531e1df468a4e0f138ba087498f83c0c44225 (patch)
tree73023923af2c59c7481f330518f7b7f39726ba11 /src/dolphincolumnview.cpp
parent81dd225e69064445716cc05d5b7c6b06da34f7a3 (diff)
implemented keyboard navigation for the column view
svn path=/trunk/KDE/kdebase/apps/; revision=714392
Diffstat (limited to 'src/dolphincolumnview.cpp')
-rw-r--r--src/dolphincolumnview.cpp66
1 files changed, 65 insertions, 1 deletions
diff --git a/src/dolphincolumnview.cpp b/src/dolphincolumnview.cpp
index b820e6b0e..7a1bc4a25 100644
--- a/src/dolphincolumnview.cpp
+++ b/src/dolphincolumnview.cpp
@@ -79,6 +79,7 @@ protected:
virtual void dropEvent(QDropEvent* 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);
@@ -280,6 +281,20 @@ void ColumnWidget::mousePressEvent(QMouseEvent* event)
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)
{
if (!m_active) {
@@ -308,6 +323,11 @@ void ColumnWidget::selectionChanged(const QItemSelection& selected, const QItemS
void ColumnWidget::activate()
{
+ 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'.
@@ -324,6 +344,16 @@ void ColumnWidget::activate()
palette.setColor(viewport()->backgroundRole(), bgColor);
viewport()->setPalette(palette);
+ 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();
}
@@ -435,7 +465,41 @@ bool DolphinColumnView::isIndexHidden(const QModelIndex& index) const
QModelIndex DolphinColumnView::moveCursor(CursorAction cursorAction, Qt::KeyboardModifiers modifiers)
{
- return QModelIndex(); //activeColumn()->moveCursor(cursorAction, modifiers);
+ // Parts of this code have been taken from QColumnView::moveCursor().
+ // Copyright (C) 1992-2007 Trolltech ASA.
+
+ Q_UNUSED(modifiers);
+ if (model() == 0) {
+ return QModelIndex();
+ }
+
+ const QModelIndex current = currentIndex();
+ if (isRightToLeft()) {
+ if (cursorAction == MoveLeft) {
+ cursorAction = MoveRight;
+ } else if (cursorAction == MoveRight) {
+ cursorAction = MoveLeft;
+ }
+ }
+
+ switch (cursorAction) {
+ case MoveLeft:
+ if (m_index > 0) {
+ setActiveColumnIndex(m_index - 1);
+ }
+ break;
+
+ case MoveRight:
+ if (m_index < m_columns.count() - 1) {
+ setActiveColumnIndex(m_index + 1);
+ }
+ break;
+
+ default:
+ break;
+ }
+
+ return QModelIndex();
}
void DolphinColumnView::setSelection(const QRect& rect, QItemSelectionModel::SelectionFlags flags)