24 #include <QtCore/QDir>
25 #include <QtGui/QContextMenuEvent>
26 #include <QtGui/QMenu>
36 class KFileTreeView::Private
44 KUrl urlForProxyIndex(
const QModelIndex &index)
const;
46 void _k_activated(
const QModelIndex&);
47 void _k_currentChanged(
const QModelIndex&,
const QModelIndex&);
48 void _k_expanded(
const QModelIndex&);
55 KUrl KFileTreeView::Private::urlForProxyIndex(
const QModelIndex &index)
const
57 const KFileItem item = mSourceModel->itemForIndex(mProxyModel->mapToSource(index));
62 void KFileTreeView::Private::_k_activated(
const QModelIndex &index)
64 const KUrl url = urlForProxyIndex(index);
66 emit q->activated(url);
69 void KFileTreeView::Private::_k_currentChanged(
const QModelIndex ¤tIndex,
const QModelIndex&)
71 const KUrl url = urlForProxyIndex(currentIndex);
73 emit q->currentChanged(url);
76 void KFileTreeView::Private::_k_expanded(
const QModelIndex &baseIndex)
78 QModelIndex index = mProxyModel->mapFromSource(baseIndex);
80 q->selectionModel()->clearSelection();
81 q->selectionModel()->setCurrentIndex(index, QItemSelectionModel::SelectCurrent);
90 d->mProxyModel->setSourceModel(d->mSourceModel);
92 setModel(d->mProxyModel);
94 setLayoutDirection(Qt::LeftToRight);
98 connect(
this, SIGNAL(
activated(QModelIndex)),
99 this, SLOT(_k_activated(QModelIndex)));
100 connect(selectionModel(), SIGNAL(
currentChanged(QModelIndex,QModelIndex)),
101 this, SLOT(_k_currentChanged(QModelIndex,QModelIndex)));
103 connect(d->mSourceModel, SIGNAL(expand(QModelIndex)),
104 this, SLOT(_k_expanded(QModelIndex)));
114 return d->urlForProxyIndex(currentIndex());
119 if (!selectionModel()->hasSelection())
122 const QItemSelection selection = selectionModel()->selection();
123 const QModelIndex firstIndex = selection.indexes().first();
125 return d->urlForProxyIndex(firstIndex);
132 if (!selectionModel()->hasSelection())
135 const QModelIndexList indexes = selectionModel()->selection().indexes();
136 foreach (
const QModelIndex &index, indexes) {
137 const KUrl url = d->urlForProxyIndex(index);
147 return d->mSourceModel->dirLister()->url();
152 d->mSourceModel->dirLister()->setDirOnlyMode(enabled);
153 d->mSourceModel->dirLister()->openUrl(d->mSourceModel->dirLister()->url());
159 d->mSourceModel->dirLister()->setShowingDotFiles(enabled);
160 d->mSourceModel->dirLister()->openUrl(d->mSourceModel->dirLister()->url());
166 QModelIndex baseIndex = d->mSourceModel->indexForUrl(url);
168 if (!baseIndex.isValid()) {
169 d->mSourceModel->expandToUrl(url);
173 QModelIndex proxyIndex = d->mProxyModel->mapFromSource(baseIndex);
174 selectionModel()->clearSelection();
175 selectionModel()->setCurrentIndex(proxyIndex, QItemSelectionModel::SelectCurrent);
176 scrollTo(proxyIndex);
181 d->mSourceModel->dirLister()->openUrl(url);
188 showHiddenAction->setChecked(d->mSourceModel->dirLister()->showingDotFiles());
189 connect(showHiddenAction, SIGNAL(toggled(
bool)),
this, SLOT(
setShowHiddenFiles(
bool)));
191 menu.addAction(showHiddenAction);
192 menu.exec(event->globalPos());
197 return d->mSourceModel->dirLister()->showingDotFiles();
203 return QSize(680, 500);
206 #include "kfiletreeview.moc"