void DolphinColumnView::requestActivation(DolphinColumnWidget* column)
{
+ m_controller->setItemView(column);
if (column->isActive()) {
assureVisibleActiveColumn();
} else {
m_dropRect.setSize(QSize()); // set as invalid
if (index.isValid()) {
- const KFileItem item = m_view->m_controller->itemForIndex(index, this);
+ m_view->m_controller->setItemView(this);
+ const KFileItem item = m_view->m_controller->itemForIndex(index);
if (!item.isNull() && item.isDir()) {
m_dropRect = visualRect(index);
}
const KUrl::List urls = KUrl::List::fromMimeData(event->mimeData());
if (!urls.isEmpty()) {
const QModelIndex index = indexAt(event->pos());
- const KFileItem item = m_view->m_controller->itemForIndex(index, this);
+ m_view->m_controller->setItemView(this);
+ const KFileItem item = m_view->m_controller->itemForIndex(index);
m_view->m_controller->indicateDroppedUrls(urls,
url(),
item);
void DolphinColumnWidget::keyPressEvent(QKeyEvent* event)
{
QListView::keyPressEvent(event);
- m_view->m_controller->handleKeyPressEvent(event, this);
+ Q_ASSERT(m_view->m_controller->itemView() == this);
+ m_view->m_controller->handleKeyPressEvent(event);
}
void DolphinColumnWidget::contextMenuEvent(QContextMenuEvent* event)
{
if (!m_active) {
m_view->requestActivation(this);
+ Q_ASSERT(m_view->m_controller->itemView() == this);
m_view->m_controller->triggerUrlChangeRequest(m_url);
}
// Only open a context menu above an item or if the mouse is above
// the active column.
const QPoint pos = m_view->viewport()->mapFromGlobal(event->globalPos());
+ Q_ASSERT(m_view->m_controller->itemView() == this);
m_view->m_controller->triggerContextMenuRequest(pos);
}
}
// let Ctrl+wheel events propagate to the DolphinView for icon zooming
if ((event->modifiers() & Qt::ControlModifier) == Qt::ControlModifier) {
event->ignore();
- return;
+ return;
}
QListView::wheelEvent(event);
}
selModel->select(deselected, QItemSelectionModel::Deselect);
}
-void DolphinColumnWidget::triggerItem(const QModelIndex& index)
-{
- m_view->m_controller->triggerItem(index, this);
-}
-
void DolphinColumnWidget::slotEntered(const QModelIndex& index)
{
- m_view->m_controller->emitItemEntered(index, this);
+ m_view->m_controller->setItemView(this);
+ m_view->m_controller->emitItemEntered(index);
}
void DolphinColumnWidget::requestActivation()
m_view->m_controller->triggerUrlChangeRequest(m_url);
selectionModel()->clear();
}
+ Q_ASSERT(m_view->m_controller->itemView() == this);
}
void DolphinColumnWidget::updateFont()
// necessary connecting the signal 'singleClick()' or 'doubleClick'.
if (KGlobalSettings::singleClick()) {
connect(this, SIGNAL(clicked(const QModelIndex&)),
- this, SLOT(triggerItem(const QModelIndex&)));
+ m_view->m_controller, SLOT(triggerItem(const QModelIndex&)));
} else {
connect(this, SIGNAL(doubleClicked(const QModelIndex&)),
- this, SLOT(triggerItem(const QModelIndex&)));
+ m_view->m_controller, SLOT(triggerItem(const QModelIndex&)));
}
if (selectionModel() && selectionModel()->currentIndex().isValid())
virtual void selectionChanged(const QItemSelection& selected, const QItemSelection& deselected);
private slots:
- /**
- * If the item specified by \a index is a directory, then this
- * directory will be loaded in a new column. If the item is a
- * file, the corresponding application will get started.
- */
- void triggerItem(const QModelIndex& index);
-
void slotEntered(const QModelIndex& index);
-
void requestActivation();
-
void updateFont();
private:
m_zoomInPossible(false),
m_zoomOutPossible(false),
m_url(),
- m_dolphinView(dolphinView)
+ m_dolphinView(dolphinView),
+ m_itemView(0)
{
}
}
}
+void DolphinController::setItemView(QAbstractItemView* view)
+{
+ m_itemView = view;
+}
+
void DolphinController::triggerUrlChangeRequest(const KUrl& url)
{
if (m_url != url) {
emit zoomOut();
}
-void DolphinController::handleKeyPressEvent(QKeyEvent* event, QAbstractItemView* view)
+void DolphinController::handleKeyPressEvent(QKeyEvent* event)
{
- const QItemSelectionModel* selModel = view->selectionModel();
+ Q_ASSERT(m_itemView != 0);
+
+ const QItemSelectionModel* selModel = m_itemView->selectionModel();
const QModelIndex currentIndex = selModel->currentIndex();
const bool trigger = currentIndex.isValid()
&& (event->key() == Qt::Key_Return)
if (trigger) {
const QModelIndexList indexList = selModel->selectedIndexes();
foreach (const QModelIndex& index, indexList) {
- triggerItem(index, view);
+ triggerItem(index);
}
}
}
-KFileItem DolphinController::itemForIndex(const QModelIndex& index, QAbstractItemView* view) const
+KFileItem DolphinController::itemForIndex(const QModelIndex& index) const
{
- QAbstractProxyModel* proxyModel = static_cast<QAbstractProxyModel*>(view->model());
+ Q_ASSERT(m_itemView != 0);
+
+ QAbstractProxyModel* proxyModel = static_cast<QAbstractProxyModel*>(m_itemView->model());
KDirModel* dirModel = static_cast<KDirModel*>(proxyModel->sourceModel());
const QModelIndex dirIndex = proxyModel->mapToSource(index);
return dirModel->itemForIndex(dirIndex);
}
-void DolphinController::triggerItem(const QModelIndex& index, QAbstractItemView* view)
+void DolphinController::triggerItem(const QModelIndex& index)
{
- const KFileItem item = itemForIndex(index, view);
+ const KFileItem item = itemForIndex(index);
if (index.isValid() && (index.column() == KDirModel::Name)) {
emit itemTriggered(item);
} else {
- view->clearSelection();
+ m_itemView->clearSelection();
emit itemEntered(item);
}
}
-void DolphinController::emitItemEntered(const QModelIndex& index, QAbstractItemView* view)
+void DolphinController::emitItemEntered(const QModelIndex& index)
{
- KFileItem item = itemForIndex(index, view);
+ KFileItem item = itemForIndex(index);
if (!item.isNull()) {
emit itemEntered(item);
}
* implementations.
*
* The abstract Dolphin view (see DolphinView) represents the parent of the controller.
+ * The lifetime of the controller is equal to the lifetime of the Dolphin view.
* The controller is passed to the current view implementation
* (see DolphinIconsView, DolphinDetailsView and DolphinColumnView)
- * by passing it in the constructor:
+ * by passing it in the constructor and informing the controller about the change
+ * of the view implementation:
*
* \code
- * DolphinController* controller = new DolphinController(dolphinView);
* QAbstractItemView* view = new DolphinIconsView(parent, controller);
+ * controller->setItemView(view);
* \endcode
*
* The communication of the view implementations to the abstract view is done by:
void setUrl(const KUrl& url);
const KUrl& url() const;
+ /**
+ * Changes the current item view where the controller is working. This
+ * is only necessary for views like the tree view, where internally
+ * several QAbstractItemView instances are used.
+ */
+ void setItemView(QAbstractItemView* view);
+
+ QAbstractItemView* itemView() const;
+
/**
* Allows a view implementation to request an URL change to \a url.
* The signal requestUrlChange() is emitted and the abstract Dolphin view
* pressed. If the selection model of \a view is not empty and
* the return key has been pressed, the selected items will get triggered.
*/
- void handleKeyPressEvent(QKeyEvent* event, QAbstractItemView* view);
+ void handleKeyPressEvent(QKeyEvent* event);
/**
* Returns the file item for the proxy index \a index of the view \a view.
*/
- KFileItem itemForIndex(const QModelIndex& index, QAbstractItemView* view) const;
+ KFileItem itemForIndex(const QModelIndex& index) const;
public slots:
/**
* is not null. The method should be invoked by the
* controller parent whenever the user has triggered an item.
*/
- void triggerItem(const QModelIndex& index, QAbstractItemView* view);
+ void triggerItem(const QModelIndex& index);
/**
* Emits the signal itemEntered() if the file item for the index \a index
* is not null. The method should be invoked by the controller parent
* whenever the mouse cursor is above an item.
*/
- void emitItemEntered(const QModelIndex& index, QAbstractItemView* view);
+ void emitItemEntered(const QModelIndex& index);
/**
* Emits the signal viewportEntered(). The method should be invoked by
bool m_zoomOutPossible;
KUrl m_url;
DolphinView* m_dolphinView;
+ QAbstractItemView* m_itemView;
};
inline const DolphinView* DolphinController::dolphinView() const
return m_url;
}
+inline QAbstractItemView* DolphinController::itemView() const
+{
+ return m_itemView;
+}
+
inline void DolphinController::setZoomInPossible(bool possible)
{
m_zoomInPossible = possible;
// RETURN-key in keyPressEvent().
if (KGlobalSettings::singleClick()) {
connect(this, SIGNAL(clicked(const QModelIndex&)),
- this, SLOT(triggerItem(const QModelIndex&)));
+ controller, SLOT(triggerItem(const QModelIndex&)));
if (DolphinSettings::instance().generalSettings()->showSelectionToggle()) {
SelectionManager* selManager = new SelectionManager(this);
connect(selManager, SIGNAL(selectionChanged()),
}
} else {
connect(this, SIGNAL(doubleClicked(const QModelIndex&)),
- this, SLOT(triggerItem(const QModelIndex&)));
+ controller, SLOT(triggerItem(const QModelIndex&)));
}
connect(this, SIGNAL(entered(const QModelIndex&)),
this, SLOT(slotEntered(const QModelIndex&)));
m_dragging = false;
} else {
m_dragging = true;
- const KFileItem item = m_controller->itemForIndex(index, this);
+ const KFileItem item = m_controller->itemForIndex(index);
if (!item.isNull() && item.isDir()) {
m_dropRect = visualRect(index);
} else {
const QModelIndex index = indexAt(event->pos());
KFileItem item;
if (index.isValid() && (index.column() == DolphinModel::Name)) {
- item = m_controller->itemForIndex(index, this);
+ item = m_controller->itemForIndex(index);
}
m_controller->indicateDroppedUrls(urls,
m_controller->url(),
void DolphinDetailsView::keyPressEvent(QKeyEvent* event)
{
QTreeView::keyPressEvent(event);
- m_controller->handleKeyPressEvent(event, this);
+ m_controller->handleKeyPressEvent(event);
}
void DolphinDetailsView::resizeEvent(QResizeEvent* event)
const QPoint pos = viewport()->mapFromGlobal(QCursor::pos());
const int nameColumnWidth = header()->sectionSize(DolphinModel::Name);
if (pos.x() < nameColumnWidth) {
- m_controller->emitItemEntered(index, this);
+ m_controller->emitItemEntered(index);
}
else {
m_controller->emitViewportEntered();
}
}
-void DolphinDetailsView::triggerItem(const QModelIndex& index)
-{
- m_controller->triggerItem(index, this);
-}
-
void DolphinDetailsView::configureColumns(const QPoint& pos)
{
KMenu popup(this);
void zoomIn();
void zoomOut();
- /**
- * Called by QTreeView when an item is activated (clicked or double-clicked)
- */
- void triggerItem(const QModelIndex& index);
-
/**
* Opens a context menu at the position \a pos and allows to
* configure the visibility of the header columns.
// RETURN-key in keyPressEvent().
if (KGlobalSettings::singleClick()) {
connect(this, SIGNAL(clicked(const QModelIndex&)),
- this, SLOT(triggerItem(const QModelIndex&)));
+ controller, SLOT(triggerItem(const QModelIndex&)));
if (DolphinSettings::instance().generalSettings()->showSelectionToggle()) {
SelectionManager* selManager = new SelectionManager(this);
connect(selManager, SIGNAL(selectionChanged()),
}
} else {
connect(this, SIGNAL(doubleClicked(const QModelIndex&)),
- this, SLOT(triggerItem(const QModelIndex&)));
+ controller, SLOT(triggerItem(const QModelIndex&)));
}
+ connect(this, SIGNAL(entered(const QModelIndex&)),
+ controller, SLOT(emitItemEntered(const QModelIndex&)));
connect(this, SIGNAL(viewportEntered()),
controller, SLOT(emitViewportEntered()));
connect(controller, SIGNAL(zoomIn()),
connect(view, SIGNAL(additionalInfoChanged()),
this, SLOT(slotAdditionalInfoChanged()));
- connect(this, SIGNAL(entered(const QModelIndex&)),
- this, SLOT(slotEntered(const QModelIndex&)));
-
// apply the icons mode settings to the widget
const IconsModeSettings* settings = DolphinSettings::instance().iconsModeSettings();
Q_ASSERT(settings != 0);
m_dropRect.setSize(QSize()); // set as invalid
if (index.isValid()) {
- const KFileItem item = m_controller->itemForIndex(index, this);
+ const KFileItem item = m_controller->itemForIndex(index);
if (!item.isNull() && item.isDir()) {
m_dropRect = visualRect(index);
} else {
const KUrl::List urls = KUrl::List::fromMimeData(event->mimeData());
if (!urls.isEmpty()) {
const QModelIndex index = indexAt(event->pos());
- const KFileItem item = m_controller->itemForIndex(index, this);
+ const KFileItem item = m_controller->itemForIndex(index);
m_controller->indicateDroppedUrls(urls,
m_controller->url(),
item);
void DolphinIconsView::keyPressEvent(QKeyEvent* event)
{
KCategorizedView::keyPressEvent(event);
- m_controller->handleKeyPressEvent(event, this);
+ m_controller->handleKeyPressEvent(event);
}
void DolphinIconsView::wheelEvent(QWheelEvent* event)
}
}
-void DolphinIconsView::triggerItem(const QModelIndex& index)
-{
- m_controller->triggerItem(index, this);
-}
-
-void DolphinIconsView::slotEntered(const QModelIndex& index)
-{
- m_controller->emitItemEntered(index, this);
-}
-
void DolphinIconsView::slotShowPreviewChanged()
{
const DolphinView* view = m_controller->dolphinView();
virtual void wheelEvent(QWheelEvent* event);
private slots:
- void triggerItem(const QModelIndex& index);
- void slotEntered(const QModelIndex& index);
void slotShowPreviewChanged();
void slotAdditionalInfoChanged();
void zoomIn();
}
Q_ASSERT(view != 0);
+ m_controller->setItemView(view);
m_fileItemDelegate = new KFileItemDelegate(view);
view->setItemDelegate(m_fileItemDelegate);