]> cloud.milkyroute.net Git - dolphin.git/commitdiff
Backport:
authorPeter Penz <peter.penz19@gmail.com>
Sat, 19 Jan 2008 18:20:24 +0000 (18:20 +0000)
committerPeter Penz <peter.penz19@gmail.com>
Sat, 19 Jan 2008 18:20:24 +0000 (18:20 +0000)
treeview: prevent that when expanding a subtree that the selected item gets hidden by the (maybe) appearing horizontal scrollbar

svn path=/branches/KDE/4.0/kdebase/apps/; revision=763550

src/treeviewsidebarpage.cpp
src/treeviewsidebarpage.h

index 7fa56566af056a9add6cb2cba09b8a74fc7b4e9c..14c8777280d15d775b97ce2dd8291a7642e7e88a 100644 (file)
@@ -35,6 +35,7 @@
 #include <QBoxLayout>
 #include <QModelIndex>
 #include <QScrollBar>
+#include <QTimer>
 
 TreeViewSidebarPage::TreeViewSidebarPage(QWidget* parent) :
     SidebarPage(parent),
@@ -213,6 +214,15 @@ void TreeViewSidebarPage::loadSubTree()
     }
 }
 
+void TreeViewSidebarPage::scrollToLeaf()
+{
+    const QModelIndex dirIndex = m_dolphinModel->indexForUrl(m_leafDir);
+    const QModelIndex proxyIndex = m_proxyModel->mapFromSource(dirIndex);
+    if (proxyIndex.isValid()) {
+        m_treeView->scrollTo(proxyIndex);
+    }
+}
+
 void TreeViewSidebarPage::loadTree(const KUrl& url)
 {
     Q_ASSERT(m_dirLister != 0);
@@ -247,7 +257,11 @@ void TreeViewSidebarPage::selectLeafDirectory()
     }
 
     if (m_setLeafVisible) {
-        m_treeView->scrollTo(proxyIndex);
+        // Invoke m_treeView->scrollTo(proxyIndex) asynchronously by
+        // scrollToLeaf(). This assures that the scrolling is done after
+        // the horizontal scrollbar gets visible (otherwise the scrollbar
+        // might hide the leaf).
+        QTimer::singleShot(100, this, SLOT(scrollToLeaf()));
         m_setLeafVisible = false;
     }
 
index 9ff37ed062e6953b300e64df0c2a5a7dd8e5df1c..a389077a94e7da64ca8aeaf40321abe72201f128 100644 (file)
@@ -99,6 +99,11 @@ private slots:
      */
     void loadSubTree();
 
+    /**
+     * Assures that the leaf folder gets visible.
+     */
+    void scrollToLeaf();
+
 private:
     /**
      * Initializes the base URL of the tree and expands all