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
#include <QBoxLayout>
#include <QModelIndex>
#include <QScrollBar>
#include <QBoxLayout>
#include <QModelIndex>
#include <QScrollBar>
TreeViewSidebarPage::TreeViewSidebarPage(QWidget* parent) :
SidebarPage(parent),
TreeViewSidebarPage::TreeViewSidebarPage(QWidget* parent) :
SidebarPage(parent),
+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);
void TreeViewSidebarPage::loadTree(const KUrl& url)
{
Q_ASSERT(m_dirLister != 0);
}
if (m_setLeafVisible) {
}
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;
}
m_setLeafVisible = false;
}
+ /**
+ * Assures that the leaf folder gets visible.
+ */
+ void scrollToLeaf();
+
private:
/**
* Initializes the base URL of the tree and expands all
private:
/**
* Initializes the base URL of the tree and expands all