From: Peter Penz Date: Sun, 5 Jul 2009 16:24:46 +0000 (+0000) Subject: Wrap the cursor on the right/left side to have a similar keyboard behavior like in... X-Git-Url: https://cloud.milkyroute.net/gitweb/dolphin.git/commitdiff_plain/40cd135f4dc7ae5ffacf8095fcf6e9fca9c04d45?ds=inline Wrap the cursor on the right/left side to have a similar keyboard behavior like in Konqueror for KDE 3. Thanks to Tahseen Mohammad for the patch! No backport to KDE 4.3.x is done until the patch has proven to work well under all circumstances. BUG: 152985 CCMAIL: tahseen.mohammad@gmail.com CCMAIL: frank78ac@googlemail.com svn path=/trunk/KDE/kdebase/apps/; revision=991780 --- diff --git a/src/dolphiniconsview.cpp b/src/dolphiniconsview.cpp index 183197ffb..55d70a0a2 100644 --- a/src/dolphiniconsview.cpp +++ b/src/dolphiniconsview.cpp @@ -245,6 +245,85 @@ void DolphinIconsView::dropEvent(QDropEvent* event) KCategorizedView::dropEvent(event); } +QModelIndex DolphinIconsView::moveCursor(CursorAction cursorAction, Qt::KeyboardModifiers modifiers) +{ + QModelIndex current = currentIndex(); + + QModelIndex newCurrent = QListView::moveCursor(cursorAction, modifiers); + if (newCurrent != current) { + return newCurrent; + } + + // The cursor has not been moved by the base implementation. Provide a + // wrap behavior, so that the cursor will go to the next item when reaching + // the border. + const IconsModeSettings* settings = DolphinSettings::instance().iconsModeSettings(); + if (settings->arrangement() == QListView::LeftToRight) { + switch (cursorAction) { + case MoveUp: + if (newCurrent.row() == 0) { + return newCurrent; + } + newCurrent = QListView::moveCursor(MoveLeft, modifiers); + selectionModel()->setCurrentIndex(newCurrent, QItemSelectionModel::NoUpdate); + newCurrent = QListView::moveCursor(MovePageDown, modifiers); + break; + + case MoveDown: + if (newCurrent.row() == (model()->rowCount() - 1)) { + return newCurrent; + } + newCurrent = QListView::moveCursor(MovePageUp, modifiers); + selectionModel()->setCurrentIndex(newCurrent, QItemSelectionModel::Clear); + newCurrent = QListView::moveCursor(MoveRight, modifiers); + break; + + default: + break; + } + } else { + switch (cursorAction) { + case MoveLeft: + if (newCurrent.row() == 0) { + return newCurrent; + } + newCurrent = QListView::moveCursor(MoveUp, modifiers); + do { + selectionModel()->setCurrentIndex(newCurrent, QItemSelectionModel::NoUpdate); + current = newCurrent; + newCurrent = QListView::moveCursor(MoveRight, modifiers); + } while (newCurrent != current); + + if (!(modifiers & Qt::ControlModifier)) { + // Ctrl is not pressed -> selection is updated + if (!(modifiers & Qt::ShiftModifier)) { + // Shift is not pressed -> previous selection is lost + selectionModel()->clearSelection(); + } + selectionModel()->setCurrentIndex(newCurrent, QItemSelectionModel::Select); + } + break; + + case MoveRight: + if (newCurrent.row() == (model()->rowCount() - 1)) { + return newCurrent; + } + do { + selectionModel()->setCurrentIndex(newCurrent, QItemSelectionModel::NoUpdate); + current = newCurrent; + newCurrent = QListView::moveCursor(MoveLeft, modifiers); + } while (newCurrent != current); + newCurrent = QListView::moveCursor(MoveDown, modifiers); + break; + + default: + break; + } + } + + return newCurrent; +} + void DolphinIconsView::keyPressEvent(QKeyEvent* event) { KCategorizedView::keyPressEvent(event); diff --git a/src/dolphiniconsview.h b/src/dolphiniconsview.h index 8cb2fd3af..70552a413 100644 --- a/src/dolphiniconsview.h +++ b/src/dolphiniconsview.h @@ -62,6 +62,7 @@ protected: virtual void dragLeaveEvent(QDragLeaveEvent* event); virtual void dragMoveEvent(QDragMoveEvent* event); virtual void dropEvent(QDropEvent* event); + virtual QModelIndex moveCursor(CursorAction cursorAction, Qt::KeyboardModifiers modifiers); virtual void keyPressEvent(QKeyEvent* event); virtual void wheelEvent(QWheelEvent* event); virtual void showEvent(QShowEvent* event);