m_index(-1),
m_contentX(0),
m_columns(),
- m_animation(0),
- m_dolphinModel(0),
- m_proxyModel(0)
+ m_animation(0)
{
Q_ASSERT(controller != 0);
this, SLOT(zoomIn()));
connect(controller, SIGNAL(zoomOut()),
this, SLOT(zoomOut()));
- connect(controller, SIGNAL(urlChanged(const KUrl&)),
- this, SLOT(showColumn(const KUrl&)));
connect(controller, SIGNAL(showHiddenFilesChanged(bool)),
this, SLOT(slotShowHiddenFilesChanged(bool)));
connect(controller, SIGNAL(showPreviewChanged(bool)),
return activeColumn()->visualRect(index);
}
-void DolphinColumnView::setModel(QAbstractItemModel* model)
-{
- m_proxyModel = static_cast<QAbstractProxyModel*>(model);
- m_dolphinModel = static_cast<DolphinModel*>(m_proxyModel->sourceModel());
- QAbstractItemView::setModel(model);
-}
-
void DolphinColumnView::invertSelection()
{
QItemSelectionModel* selectionModel = activeColumn()->selectionModel();
}
}
+void DolphinColumnView::setRootUrl(const KUrl& url)
+{
+ removeAllColumns();
+ m_columns[0]->setUrl(url);
+}
+
+KUrl DolphinColumnView::rootUrl() const
+{
+ return m_columns[0]->url();
+}
+
void DolphinColumnView::showColumn(const KUrl& url)
{
const KUrl& rootUrl = m_columns[0]->url();
if (!rootUrl.isParentOf(url)) {
- // the URL is no child URL of the column view, hence clear all columns
- // and reset the root column
- QList<DolphinColumnWidget*>::iterator start = m_columns.begin() + 1;
- QList<DolphinColumnWidget*>::iterator end = m_columns.end();
- for (QList<DolphinColumnWidget*>::iterator it = start; it != end; ++it) {
- (*it)->deleteLater();
- }
- m_columns.erase(start, end);
- m_index = 0;
- m_columns[0]->setActive(true);
- m_columns[0]->setUrl(url);
- assureVisibleActiveColumn();
+ setRootUrl(url);
return;
}
- KDirLister* dirLister = m_dolphinModel->dirLister();
- const KUrl dirListerUrl = dirLister->url();
- if (dirListerUrl != rootUrl) {
- // It is possible that root URL of the directory lister is adjusted
- // after creating the column widget (e. g. when restoring the history
- // having a different root URL than the controller indicates).
- m_columns[0]->setUrl(dirListerUrl);
- }
-
int columnIndex = 0;
foreach (DolphinColumnWidget* column, m_columns) {
if (column->url() == url) {
++slashIndex;
const KUrl childUrl = KUrl(path);
- const QModelIndex dirIndex = m_dolphinModel->indexForUrl(KUrl(path));
- const QModelIndex proxyIndex = m_proxyModel->mapFromSource(dirIndex);
-
m_columns[columnIndex]->setChildUrl(childUrl);
columnIndex++;
column->show();
layoutColumns();
updateScrollBar();
-
- // the layout is finished, now let the column be invisible until it
- // gets a valid root index due to expandToActiveUrl()
- //column->hide();
}
}
}
}
+void DolphinColumnView::removeAllColumns()
+{
+ QList<DolphinColumnWidget*>::iterator start = m_columns.begin() + 1;
+ QList<DolphinColumnWidget*>::iterator end = m_columns.end();
+ for (QList<DolphinColumnWidget*>::iterator it = start; it != end; ++it) {
+ (*it)->deleteLater();
+ }
+ m_columns.erase(start, end);
+ m_index = 0;
+ m_columns[0]->setActive(true);
+ assureVisibleActiveColumn();
+}
+
#include "dolphincolumnview.moc"
#ifndef DOLPHINCOLUMNVIEW_H
#define DOLPHINCOLUMNVIEW_H
+#include <kurl.h>
+
#include <QAbstractItemView>
#include <QList>
#include <QStyleOption>
class DolphinColumnWidget;
class DolphinController;
class DolphinModel;
-class KUrl;
class QAbstractProxyModel;
class QTimeLine;
virtual QModelIndex indexAt(const QPoint& point) const;
virtual void scrollTo(const QModelIndex& index, ScrollHint hint = EnsureVisible);
virtual QRect visualRect(const QModelIndex& index) const;
- virtual void setModel(QAbstractItemModel* model);
/** Inverts the selection of the currently active column. */
void invertSelection();
*/
void reload();
+ /**
+ * Adjusts the root URL of the first column and removes all
+ * other columns.
+ */
+ void setRootUrl(const KUrl& url);
+
+ /** Returns the URL of the first column. */
+ KUrl rootUrl() const;
+
public slots:
/**
* Shows the column which represents the URL \a url. If the column
*/
void requestActivation(DolphinColumnWidget* column);
+ /** Removes all columns except of the root column. */
+ void removeAllColumns();
+
private:
DolphinController* m_controller;
bool m_restoreActiveColumnFocus;
QList<DolphinColumnWidget*> m_columns;
QTimeLine* m_animation;
- DolphinModel* m_dolphinModel;
- QAbstractProxyModel* m_proxyModel;
-
friend class DolphinColumnWidget;
};
activate();
- connect(this, SIGNAL(entered(const QModelIndex&)),
- m_view->m_controller, SLOT(emitItemEntered(const QModelIndex&)));
- connect(this, SIGNAL(viewportEntered()),
- m_view->m_controller, SLOT(emitViewportEntered()));
connect(this, SIGNAL(viewportEntered()),
m_view->m_controller, SLOT(emitViewportEntered()));
-
connect(this, SIGNAL(entered(const QModelIndex&)),
this, SLOT(slotEntered(const QModelIndex&)));
}
void DolphinColumnWidget::triggerItem(const QModelIndex& index)
{
+ const KFileItem item = m_dolphinModel->itemForIndex(m_proxyModel->mapToSource(index));
+ m_view->m_controller->triggerItem(item);
+ /*
const Qt::KeyboardModifiers modifier = QApplication::keyboardModifiers();
if ((modifier & Qt::ShiftModifier) || (modifier & Qt::ControlModifier)) {
// items are selected by the user, hence don't trigger the
m_view->m_controller->setUrl(url);
} else if (item.isFile()) {
item.run();
- }
+ }*/
}
void DolphinColumnWidget::generatePreviews(const KFileItemList& items)
painter.restore();
}
-void DolphinController::triggerItem(const QModelIndex& index)
+void DolphinController::triggerItem(const KFileItem& item)
{
- emit itemTriggered(index);
+ emit itemTriggered(item);
}
void DolphinController::emitItemEntered(const KFileItem& item)
/**
* Emits the signal itemTriggered(). The method should be invoked by the
* controller parent whenever the user has triggered an item. */
- void triggerItem(const QModelIndex& index);
+ void triggerItem(const KFileItem& item);
/**
* Emits the signal itemEntered(). The method should be invoked by
void additionalInfoCountChanged(int count);
/**
- * Is emitted if the item with the index \a index should be triggered.
+ * Is emitted if the item \a item should be triggered.
* Usually triggering on a directory opens the directory, triggering
- * on a file opens the corresponding application.
- * Emitted with an invalid \a index when clicking on the viewport itself.
+ * on a file opens the corresponding application. The item is null
+ * (see KFileItem::isNull()), when clicking on the viewport itself.
*/
- void itemTriggered(const QModelIndex& index);
+ void itemTriggered(const KFileItem& item);
/**
* Is emitted if the mouse cursor has entered the item
// RETURN-key in keyPressEvent().
if (KGlobalSettings::singleClick()) {
connect(this, SIGNAL(clicked(const QModelIndex&)),
- this, SLOT(slotItemActivated(const QModelIndex&)));
+ this, SLOT(triggerItem(const QModelIndex&)));
} else {
connect(this, SIGNAL(doubleClicked(const QModelIndex&)),
- this, SLOT(slotItemActivated(const QModelIndex&)));
+ this, SLOT(triggerItem(const QModelIndex&)));
}
connect(this, SIGNAL(entered(const QModelIndex&)),
this, SLOT(slotEntered(const QModelIndex&)));
const QItemSelectionModel* selModel = selectionModel();
const QModelIndex currentIndex = selModel->currentIndex();
- const bool triggerItem = currentIndex.isValid()
- && (event->key() == Qt::Key_Return)
- && (selModel->selectedIndexes().count() <= 1);
- if (triggerItem) {
- m_controller->triggerItem(currentIndex);
+ const bool trigger = currentIndex.isValid()
+ && (event->key() == Qt::Key_Return)
+ && (selModel->selectedIndexes().count() <= 1);
+ if (trigger) {
+ triggerItem(currentIndex);
}
}
}
}
-void DolphinDetailsView::slotItemActivated(const QModelIndex& index)
+void DolphinDetailsView::triggerItem(const QModelIndex& index)
{
+ const KFileItem item = itemForIndex(index);
if (index.isValid() && (index.column() == KDirModel::Name)) {
- m_controller->triggerItem(index);
+ m_controller->triggerItem(item);
} else {
clearSelection();
- m_controller->emitItemEntered(itemForIndex(index));
+ m_controller->emitItemEntered(item);
}
}
/**
* Called by QTreeView when an item is activated (clicked or double-clicked)
*/
- void slotItemActivated(const QModelIndex& index);
+ void triggerItem(const QModelIndex& index);
/**
* Opens a context menu at the position \a pos and allows to
// RETURN-key in keyPressEvent().
if (KGlobalSettings::singleClick()) {
connect(this, SIGNAL(clicked(const QModelIndex&)),
- controller, SLOT(triggerItem(const QModelIndex&)));
+ this, SLOT(triggerItem(const QModelIndex&)));
} else {
connect(this, SIGNAL(doubleClicked(const QModelIndex&)),
- controller, SLOT(triggerItem(const QModelIndex&)));
+ this, SLOT(triggerItem(const QModelIndex&)));
}
connect(this, SIGNAL(viewportEntered()),
controller, SLOT(emitViewportEntered()));
const QItemSelectionModel* selModel = selectionModel();
const QModelIndex currentIndex = selModel->currentIndex();
- const bool triggerItem = currentIndex.isValid()
- && (event->key() == Qt::Key_Return)
- && (selModel->selectedIndexes().count() <= 1);
- if (triggerItem) {
- m_controller->triggerItem(currentIndex);
+ const bool trigger = currentIndex.isValid()
+ && (event->key() == Qt::Key_Return)
+ && (selModel->selectedIndexes().count() <= 1);
+ if (trigger) {
+ triggerItem(currentIndex);
}
}
-void DolphinIconsView::slotEntered(const QModelIndex& index)
+void DolphinIconsView::triggerItem(const QModelIndex& index)
{
- QAbstractProxyModel* proxyModel = static_cast<QAbstractProxyModel*>(model());
- KDirModel* dirModel = static_cast<KDirModel*>(proxyModel->sourceModel());
- const QModelIndex dirIndex = proxyModel->mapToSource(index);
+ m_controller->triggerItem(itemForIndex(index));
+}
- const KFileItem item = dirModel->itemForIndex(dirIndex);
- m_controller->emitItemEntered(item);
+void DolphinIconsView::slotEntered(const QModelIndex& index)
+{
+ m_controller->emitItemEntered(itemForIndex(index));
}
void DolphinIconsView::slotShowPreviewChanged(bool showPreview)
m_controller->setZoomOutPossible(isZoomOutPossible());
}
+KFileItem DolphinIconsView::itemForIndex(const QModelIndex& index) const
+{
+ QAbstractProxyModel* proxyModel = static_cast<QAbstractProxyModel*>(model());
+ KDirModel* dirModel = static_cast<KDirModel*>(proxyModel->sourceModel());
+ const QModelIndex dirIndex = proxyModel->mapToSource(index);
+ return dirModel->itemForIndex(dirIndex);
+}
+
+
#include "dolphiniconsview.moc"
#include <kcategorizedview.h>
+#include <kfileitem.h>
+
#include <QSize>
#include <QStyleOption>
virtual void keyPressEvent(QKeyEvent* event);
private slots:
+ void triggerItem(const QModelIndex& index);
void slotEntered(const QModelIndex& index);
void slotShowPreviewChanged(bool show);
void slotAdditionalInfoCountChanged(int count);
*/
void updateGridSize(bool showPreview, int additionalInfoCount);
+ KFileItem itemForIndex(const QModelIndex& index) const;
+
private:
DolphinController* m_controller;
DolphinCategoryDrawer* m_categoryDrawer;
this, SLOT(updateSorting(DolphinView::Sorting)));
connect(m_controller, SIGNAL(sortOrderChanged(Qt::SortOrder)),
this, SLOT(updateSortOrder(Qt::SortOrder)));
- connect(m_controller, SIGNAL(itemTriggered(const QModelIndex&)),
- this, SLOT(triggerItem(const QModelIndex&)));
+ connect(m_controller, SIGNAL(itemTriggered(const KFileItem&)),
+ this, SLOT(triggerItem(const KFileItem&)));
connect(m_controller, SIGNAL(activated()),
this, SLOT(activate()));
connect(m_controller, SIGNAL(itemEntered(const KFileItem&)),
KUrl DolphinView::rootUrl() const
{
- return isColumnViewActive() ? m_dirLister->url() : url();
+ return isColumnViewActive() ? m_columnView->rootUrl() : url();
}
void DolphinView::setActive(bool active)
// that the view properties have been changed or deleted in the meantime, so
// it cannot be asserted that really a column view has been created:
if (itemView() == m_columnView) {
+ m_columnView->setRootUrl(rootUrl);
m_columnView->showColumn(url);
}
} else {
setActive(true);
}
-void DolphinView::triggerItem(const QModelIndex& index)
+void DolphinView::triggerItem(const KFileItem& item)
{
- Q_ASSERT(index.isValid());
-
const Qt::KeyboardModifiers modifier = QApplication::keyboardModifiers();
if ((modifier & Qt::ShiftModifier) || (modifier & Qt::ControlModifier)) {
// items are selected by the user, hence don't trigger the
return;
}
- const KFileItem item = m_dolphinModel->itemForIndex(m_proxyModel->mapToSource(index));
-
if (item.isNull()) {
return;
}
m_dirLister->stop();
m_dirLister->openUrl(url, reload ? KDirLister::Reload : KDirLister::NoFlags);
- if (isColumnViewActive() && reload) {
- // reloading the directory lister is not enough in the case of the
+ if (isColumnViewActive()) {
+ // adjusting the directory lister is not enough in the case of the
// column view, as each column has its own directory lister internally...
- m_columnView->reload();
+ if (reload) {
+ m_columnView->reload();
+ } else {
+ m_columnView->showColumn(url);
+ }
}
}
void DolphinView::applyViewProperties(const KUrl& url)
{
- if (isColumnViewActive() && m_dirLister->url().isParentOf(url)) {
+ if (isColumnViewActive() && rootUrl().isParentOf(url)) {
// The column view is active, hence don't apply the view properties
// of sub directories (represented by columns) to the view. The
// view always represents the properties of the first column.
void activate();
/**
- * If the item specified by \a index is a directory, then this
+ * If the item \a item is a directory, then this
* directory will be loaded. If the item is a file, the corresponding
* application will get started.
*/
- void triggerItem(const QModelIndex& index);
+ void triggerItem(const KFileItem& index);
/**
* Generates a preview image for each file item in \a items.