]> cloud.milkyroute.net Git - dolphin.git/blobdiff - src/treeviewsidebarpage.cpp
* changed "Click to add comment..." to simply "Add comment..." for consistency with...
[dolphin.git] / src / treeviewsidebarpage.cpp
index 7fa56566af056a9add6cb2cba09b8a74fc7b4e9c..d84b72ae24a66ce3e69e126e041d0639199dec2f 100644 (file)
@@ -35,6 +35,7 @@
 #include <QBoxLayout>
 #include <QModelIndex>
 #include <QScrollBar>
+#include <QTimer>
 
 TreeViewSidebarPage::TreeViewSidebarPage(QWidget* parent) :
     SidebarPage(parent),
@@ -89,7 +90,7 @@ void TreeViewSidebarPage::showEvent(QShowEvent* event)
         m_dirLister = new KDirLister();
         m_dirLister->setDirOnlyMode(true);
         m_dirLister->setAutoUpdate(true);
-        m_dirLister->setMainWindow(this);
+        m_dirLister->setMainWindow(window());
         m_dirLister->setDelayedMimeTypes(true);
         m_dirLister->setAutoErrorHandlingEnabled(false, this);
 
@@ -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);
@@ -223,7 +233,7 @@ void TreeViewSidebarPage::loadTree(const KUrl& url)
     KUrl baseUrl = url;
     if (url.isLocalFile()) {
         // use the root directory as base for local URLs
-        baseUrl = KUrl("file:///");
+        baseUrl = QDir::rootPath();
     } else {
         // clear the path for non-local URLs and use it as base
         baseUrl = url;
@@ -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;
     }