]> cloud.milkyroute.net Git - dolphin.git/blobdiff - src/treeviewsidebarpage.cpp
Use a QActionGroup and save 6 slots (and the duplication of the action names in the...
[dolphin.git] / src / treeviewsidebarpage.cpp
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;
     }