mirror of
https://invent.kde.org/system/dolphin
synced 2024-10-02 14:45:04 +00:00
Some basic fixes to stay synchronized between the tree view and the currently active view.
svn path=/trunk/KDE/kdebase/apps/; revision=639008
This commit is contained in:
parent
9470a816eb
commit
862c090bf3
|
@ -26,6 +26,8 @@
|
|||
#include "kdirlister.h"
|
||||
#include "kdirmodel.h"
|
||||
|
||||
#include <QHeaderView>
|
||||
#include <QItemSelectionModel>
|
||||
#include <QTreeView>
|
||||
#include <QVBoxLayout>
|
||||
|
||||
|
@ -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"
|
||||
|
|
|
@ -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:
|
||||
/**
|
||||
|
|
Loading…
Reference in a new issue