From: Peter Penz Date: Sun, 4 Mar 2007 00:40:14 +0000 (+0000) Subject: Some basic fixes to stay synchronized between the tree view and the currently active... X-Git-Url: https://cloud.milkyroute.net/gitweb/dolphin.git/commitdiff_plain/862c090bf3be00b3016adfa5c7c0bd40ba409ca3 Some basic fixes to stay synchronized between the tree view and the currently active view. svn path=/trunk/KDE/kdebase/apps/; revision=639008 --- diff --git a/src/treeviewsidebarpage.cpp b/src/treeviewsidebarpage.cpp index 32edef05e..29213ebcd 100644 --- a/src/treeviewsidebarpage.cpp +++ b/src/treeviewsidebarpage.cpp @@ -26,6 +26,8 @@ #include "kdirlister.h" #include "kdirmodel.h" +#include +#include #include #include @@ -50,6 +52,7 @@ TreeViewSidebarPage::TreeViewSidebarPage(DolphinMainWindow* mainWindow, m_treeView = new QTreeView(this); m_treeView->setModel(m_dirModel); + m_treeView->setSelectionMode(QAbstractItemView::SingleSelection); // hide all columns except of the 'Name' column m_treeView->hideColumn(KDirModel::Size); @@ -57,11 +60,13 @@ TreeViewSidebarPage::TreeViewSidebarPage(DolphinMainWindow* mainWindow, m_treeView->hideColumn(KDirModel::Permissions); m_treeView->hideColumn(KDirModel::Owner); m_treeView->hideColumn(KDirModel::Group); + m_treeView->header()->hide(); + + connect(m_treeView, SIGNAL(clicked(const QModelIndex&)), + this, SLOT(updateViewUrl(const QModelIndex&))); QVBoxLayout* layout = new QVBoxLayout(this); layout->addWidget(m_treeView); - - connectToActiveView(); } TreeViewSidebarPage::~TreeViewSidebarPage() @@ -75,24 +80,64 @@ void TreeViewSidebarPage::activeViewChanged() connectToActiveView(); } -void TreeViewSidebarPage::updatePosition(const KUrl& url) +void TreeViewSidebarPage::showEvent(QShowEvent* event) +{ + SidebarPage::showEvent(event); + connectToActiveView(); +} + +void TreeViewSidebarPage::updateSelection(const KUrl& url) { + // adjust the root of the tree to the base bookmark KUrl baseUrl = BookmarkSelector::baseBookmark(url).url(); if (m_dirLister->url() != baseUrl) { m_dirLister->stop(); m_dirLister->openUrl(baseUrl); } - // TODO: open sub folders to be synchronous to 'url' + // select the folder which contains the given url + + // TODO: check how Konqi does it before reinventing the wheel. The directory + // must already be loaded _before_ the index can be retrieved by + // KDirModel::indexForItem(). + QItemSelectionModel* selModel = m_treeView->selectionModel(); + selModel->clearSelection(); + + KFileItem item(S_IFDIR, KFileItem::Unknown, url); + const QModelIndex index = m_dirModel->indexForItem(item); + if (index.isValid()) { + m_treeView->scrollTo(index); + m_treeView->setExpanded(index, true); + + selModel->setCurrentIndex(index, QItemSelectionModel::Select); + } +} + +void TreeViewSidebarPage::updateViewUrl(const QModelIndex& index) +{ + KFileItem* item = m_dirModel->itemForIndex(index); + if (item != 0) { + const KUrl& url = item->url(); + mainWindow()->activeView()->setUrl(url); + } } void TreeViewSidebarPage::connectToActiveView() { + const QWidget* parent = parentWidget(); + if ((parent == 0) || parent->isHidden()) { + return; + } + DolphinView* view = mainWindow()->activeView(); + const KUrl& url = view->url(); + m_dirLister->stop(); - m_dirLister->openUrl(view->url()); + m_dirLister->openUrl(url); connect(view, SIGNAL(urlChanged(const KUrl&)), - this, SLOT(updatePosition(const KUrl&))); + this, SLOT(updateSelection(const KUrl&))); + + updateSelection(url); } #include "treeviewsidebarpage.moc" diff --git a/src/treeviewsidebarpage.h b/src/treeviewsidebarpage.h index 1761d8c2b..045586bcc 100644 --- a/src/treeviewsidebarpage.h +++ b/src/treeviewsidebarpage.h @@ -25,6 +25,8 @@ class KDirLister; class KDirModel; class KUrl; + +class QModelIndex; class QTreeView; /** @@ -42,12 +44,21 @@ protected: /** @see SidebarPage::activeViewChanged() */ virtual void activeViewChanged(); + /** @see QWidget::showEvent() */ + virtual void showEvent(QShowEvent* event); + private slots: /** - * Updates the current position inside the tree to + * Updates the current selection inside the tree to * \a url. */ - void updatePosition(const KUrl& url); + void updateSelection(const KUrl& url); + + /** + * Updates the URL of the active view to the URL + * which is given by the item with the index \a index. + */ + void updateViewUrl(const QModelIndex& index); private: /**