]> cloud.milkyroute.net Git - dolphin.git/commitdiff
Fixed issue that the scroll position is reset if the focus of the itemview changes.
authorPeter Penz <peter.penz19@gmail.com>
Mon, 29 Jun 2009 19:32:39 +0000 (19:32 +0000)
committerPeter Penz <peter.penz19@gmail.com>
Mon, 29 Jun 2009 19:32:39 +0000 (19:32 +0000)
BUG: 197951

svn path=/trunk/KDE/kdebase/apps/; revision=989236

src/dolphincolumnwidget.cpp
src/dolphindetailsview.cpp
src/dolphiniconsview.cpp
src/dolphinviewautoscroller.cpp
src/dolphinviewautoscroller.h

index e85c9491bed721545f8ce3711ce6b3488c29e498..c8bff02908972b0183bf607d02a1cccb3102206e 100644 (file)
@@ -491,9 +491,7 @@ void DolphinColumnWidget::selectionChanged(const QItemSelection& selected, const
 void DolphinColumnWidget::currentChanged(const QModelIndex& current, const QModelIndex& previous)
 {
     QListView::currentChanged(current, previous);
-    if (current.isValid() && !m_autoScroller->isActive()) {
-        scrollTo(current);
-    }
+    m_autoScroller->handleCurrentIndexChange(current, previous);
 }
 
 void DolphinColumnWidget::slotEntered(const QModelIndex& index)
index ad362914aec896948bdd6e2bf00a2aeb9a1600ce..aa65ff6bc7fc22e19c072fa07dfbf6d549712be0 100644 (file)
@@ -429,9 +429,7 @@ void DolphinDetailsView::wheelEvent(QWheelEvent* event)
 void DolphinDetailsView::currentChanged(const QModelIndex& current, const QModelIndex& previous)
 {
     QTreeView::currentChanged(current, previous);
-    if (current.isValid() && !m_autoScroller->isActive()) {
-        scrollTo(current);
-    }
+    m_autoScroller->handleCurrentIndexChange(current, previous);
 
     // Stay consistent with QListView: When changing the current index by key presses,
     // also change the selection.
index 4c7e9180f8aaf8a80baaea0ba4aa3542167da5a4..183197ffb3101795bf3b843e01a52a3f23b78362 100644 (file)
@@ -302,9 +302,7 @@ void DolphinIconsView::leaveEvent(QEvent* event)
 void DolphinIconsView::currentChanged(const QModelIndex& current, const QModelIndex& previous)
 {
     KCategorizedView::currentChanged(current, previous);
-    if (current.isValid() && !m_autoScroller->isActive()) {
-        scrollTo(current);
-    }
+    m_autoScroller->handleCurrentIndexChange(current, previous);
 }
 
 void DolphinIconsView::resizeEvent(QResizeEvent* event)
index 75dab3214cb6f28a52dd20bd2f0f019e58b2a74a..ea9b1a2d6bb2103007baa3bf0c558d17164304b2 100644 (file)
@@ -54,6 +54,17 @@ bool DolphinViewAutoScroller::isActive() const
     return m_timer->isActive();
 }
 
+void DolphinViewAutoScroller::handleCurrentIndexChange(const QModelIndex& current,
+                                                       const QModelIndex& previous)
+{
+    // When the autoscroller is inactive and a key has been pressed, it must be
+    // assured that the current item stays visible. The check whether the previous
+    // item is valid is important because of #197951.
+    if (current.isValid() && previous.isValid() && !isActive()) {
+        m_itemView->scrollTo(current);
+    }
+}
+
 bool DolphinViewAutoScroller::eventFilter(QObject* watched, QEvent* event)
 {
     if (watched == m_itemView->viewport()) {
index 3827b2326114284f0f957d52ee12569c9c44079d..c95155f58bb9109521e085d370f853f1edc893ed 100644 (file)
@@ -23,6 +23,7 @@
 #include <QObject>
 
 class QAbstractItemView;
+class QModelIndex;
 class QTimer;
 
 /**
@@ -40,6 +41,13 @@ public:
     virtual ~DolphinViewAutoScroller();
     bool isActive() const;
 
+    /**
+     * Must be invoked by the parent item view, when QAbstractItemView::currentChanged()
+     * has been called. Assures that the current item stays visible when it has been
+     * changed by the keyboard.
+     */
+    void handleCurrentIndexChange(const QModelIndex& current, const QModelIndex& previous);
+
 protected:
     virtual bool eventFilter(QObject* watched, QEvent* event);