Maybe it might be a good idea to let the DolphinController be aware also about his QAbstractItemView -> it might be possible to directly connect signals of the dolphin view implementations with the controller. I'll check this...
(I did not backport this cleanup as I think it has too many changes to be handled as bugfix)
CCMAIL: faure@kde.org
CCMAIL: edulix@gmail.com
svn path=/trunk/KDE/kdebase/apps/; revision=777719
m_dropRect.setSize(QSize()); // set as invalid
if (index.isValid()) {
- const KFileItem item = itemForIndex(index);
+ const KFileItem item = m_view->m_controller->itemForIndex(index, this);
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 = itemForIndex(index);
+ const KFileItem item = m_view->m_controller->itemForIndex(index, this);
m_view->m_controller->indicateDroppedUrls(urls,
url(),
item);
void DolphinColumnWidget::keyPressEvent(QKeyEvent* event)
{
QListView::keyPressEvent(event);
-
- const QItemSelectionModel* selModel = selectionModel();
- const QModelIndex currentIndex = selModel->currentIndex();
- const bool trigger = currentIndex.isValid()
- && (event->key() == Qt::Key_Return)
- && (selModel->selectedIndexes().count() > 0);
- if(trigger) {
- const QModelIndexList indexList = selModel->selectedIndexes();
- foreach (const QModelIndex &index, indexList) {
- KFileItem item = itemForIndex(index);
- if (!item.isNull()) {
- triggerItem(index);
- }
- }
- }
+ m_view->m_controller->handleKeyPressEvent(event, this);
}
void DolphinColumnWidget::contextMenuEvent(QContextMenuEvent* event)
void DolphinColumnWidget::triggerItem(const QModelIndex& index)
{
- const KFileItem item = itemForIndex(index);
- m_view->m_controller->triggerItem(item);
+ m_view->m_controller->triggerItem(index, this);
}
void DolphinColumnWidget::slotEntered(const QModelIndex& index)
{
- const QModelIndex dirIndex = m_proxyModel->mapToSource(index);
- const KFileItem item = m_dolphinModel->itemForIndex(dirIndex);
- m_view->m_controller->emitItemEntered(item);
+ m_view->m_controller->emitItemEntered(index, this);
}
void DolphinColumnWidget::requestActivation()
updateBackground();
}
-KFileItem DolphinColumnWidget::itemForIndex(const QModelIndex& index) const
-{
- const QModelIndex dirIndex = m_proxyModel->mapToSource(index);
- return m_dolphinModel->itemForIndex(dirIndex);
-}
-
-
#include "dolphincolumnwidget.moc"
/** Used by DolphinColumnWidget::setActive(). */
void deactivate();
- KFileItem itemForIndex(const QModelIndex& index) const;
-
private:
bool m_active;
DolphinColumnView* m_view;
#include "dolphincontroller.h"
+#include <kdirmodel.h>
+#include <QAbstractProxyModel>
+
DolphinController::DolphinController(DolphinView* dolphinView) :
QObject(dolphinView),
m_zoomInPossible(false),
emit zoomOut();
}
-void DolphinController::triggerItem(const KFileItem& item)
+void DolphinController::handleKeyPressEvent(QKeyEvent* event, QAbstractItemView* view)
+{
+ const QItemSelectionModel* selModel = view->selectionModel();
+ const QModelIndex currentIndex = selModel->currentIndex();
+ const bool trigger = currentIndex.isValid()
+ && (event->key() == Qt::Key_Return)
+ && (selModel->selectedIndexes().count() > 0);
+ if (trigger) {
+ const QModelIndexList indexList = selModel->selectedIndexes();
+ foreach (const QModelIndex& index, indexList) {
+ triggerItem(index, view);
+ }
+ }
+}
+
+KFileItem DolphinController::itemForIndex(const QModelIndex& index, QAbstractItemView* view) const
{
- emit itemTriggered(item);
+ QAbstractProxyModel* proxyModel = static_cast<QAbstractProxyModel*>(view->model());
+ KDirModel* dirModel = static_cast<KDirModel*>(proxyModel->sourceModel());
+ const QModelIndex dirIndex = proxyModel->mapToSource(index);
+ return dirModel->itemForIndex(dirIndex);
}
-void DolphinController::emitItemEntered(const KFileItem& item)
+void DolphinController::triggerItem(const QModelIndex& index, QAbstractItemView* view)
{
- emit itemEntered(item);
+ const KFileItem item = itemForIndex(index, view);
+ if (index.isValid() && (index.column() == KDirModel::Name)) {
+ emit itemTriggered(item);
+ } else {
+ view->clearSelection();
+ emit itemEntered(item);
+ }
+}
+
+void DolphinController::emitItemEntered(const QModelIndex& index, QAbstractItemView* view)
+{
+ KFileItem item = itemForIndex(index, view);
+ if (!item.isNull()) {
+ emit itemEntered(item);
+ }
}
void DolphinController::emitViewportEntered()
#include <QtCore/QObject>
#include <libdolphin_export.h>
+class QAbstractItemView;
class DolphinView;
class KUrl;
class QBrush;
* - setZoomInPossible()
* - setZoomOutPossible()
* - triggerItem()
+ * - handleKeyPressEvent()
* - emitItemEntered()
* - emitViewportEntered()
*
void setZoomOutPossible(bool possible);
bool isZoomOutPossible() const;
+ /**
+ * Should be invoked in each view implementation whenever a key has been
+ * 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);
+
+ /**
+ * Returns the file item for the proxy index \a index of the view \a view.
+ */
+ KFileItem itemForIndex(const QModelIndex& index, QAbstractItemView* view) const;
+
public slots:
/**
- * Emits the signal itemTriggered(). The method should be invoked by the
- * controller parent whenever the user has triggered an item. */
- void triggerItem(const KFileItem& item);
+ * Emits the signal itemTriggered() if the file item for the index \a index
+ * 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);
/**
- * Emits the signal itemEntered(). The method should be invoked by
- * the controller parent whenever the mouse cursor is above an item.
+ * 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 KFileItem& item);
+ void emitItemEntered(const QModelIndex& index, QAbstractItemView* view);
/**
* Emits the signal viewportEntered(). The method should be invoked by
m_dragging = false;
} else {
m_dragging = true;
- const KFileItem item = itemForIndex(index);
+ const KFileItem item = m_controller->itemForIndex(index, this);
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 = itemForIndex(index);
+ item = m_controller->itemForIndex(index, this);
}
m_controller->indicateDroppedUrls(urls,
m_controller->url(),
void DolphinDetailsView::keyPressEvent(QKeyEvent* event)
{
QTreeView::keyPressEvent(event);
-
- const QItemSelectionModel* selModel = selectionModel();
- const QModelIndex currentIndex = selModel->currentIndex();
- const bool trigger = currentIndex.isValid()
- && (event->key() == Qt::Key_Return)
- && (selModel->selectedIndexes().count() > 0);
- if(trigger) {
- const QModelIndexList indexList = selModel->selectedIndexes();
- foreach (const QModelIndex &index, indexList) {
- KFileItem item = itemForIndex(index);
- if (!item.isNull()) {
- triggerItem(index);
- }
- }
- }
+ m_controller->handleKeyPressEvent(event, this);
}
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(itemForIndex(index));
+ m_controller->emitItemEntered(index, this);
}
else {
m_controller->emitViewportEntered();
void DolphinDetailsView::triggerItem(const QModelIndex& index)
{
- const KFileItem item = itemForIndex(index);
- if (index.isValid() && (index.column() == KDirModel::Name)) {
- m_controller->triggerItem(item);
- } else {
- clearSelection();
- m_controller->emitItemEntered(item);
- }
+ m_controller->triggerItem(index, this);
}
void DolphinDetailsView::configureColumns(const QPoint& pos)
return QPoint(0, y);
}
-KFileItem DolphinDetailsView::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);
-}
-
KFileItemDelegate::Information DolphinDetailsView::infoForColumn(int columnIndex) const
{
KFileItemDelegate::Information info = KFileItemDelegate::NoInformation;
/** Return the upper left position in pixels of the viewport content. */
QPoint contentsPos() const;
- KFileItem itemForIndex(const QModelIndex& index) const;
-
KFileItemDelegate::Information infoForColumn(int columnIndex) const;
/**
m_dropRect.setSize(QSize()); // set as invalid
if (index.isValid()) {
- const KFileItem item = itemForIndex(index);
+ const KFileItem item = m_controller->itemForIndex(index, this);
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 = itemForIndex(index);
+ const KFileItem item = m_controller->itemForIndex(index, this);
m_controller->indicateDroppedUrls(urls,
m_controller->url(),
item);
void DolphinIconsView::keyPressEvent(QKeyEvent* event)
{
KCategorizedView::keyPressEvent(event);
-
- const QItemSelectionModel* selModel = selectionModel();
- const QModelIndex currentIndex = selModel->currentIndex();
- const bool trigger = currentIndex.isValid()
- && (event->key() == Qt::Key_Return)
- && (selModel->selectedIndexes().count() > 0);
- if(trigger) {
- const QModelIndexList indexList = selModel->selectedIndexes();
- foreach (const QModelIndex &index, indexList) {
- KFileItem item = itemForIndex(index);
- if (!item.isNull()) {
- triggerItem(index);
- }
- }
- }
+ m_controller->handleKeyPressEvent(event, this);
}
void DolphinIconsView::wheelEvent(QWheelEvent* event)
// let Ctrl+wheel events propagate to the DolphinView for icon zooming
if ((event->modifiers() & Qt::ControlModifier) == Qt::ControlModifier) {
event->ignore();
- return;
+ return;
}
KCategorizedView::wheelEvent(event);
// if the icons are aligned left to right, the vertical wheel event should
void DolphinIconsView::triggerItem(const QModelIndex& index)
{
- m_controller->triggerItem(itemForIndex(index));
+ m_controller->triggerItem(index, this);
}
void DolphinIconsView::slotEntered(const QModelIndex& index)
{
- m_controller->emitItemEntered(itemForIndex(index));
+ m_controller->emitItemEntered(index, this);
}
void DolphinIconsView::slotShowPreviewChanged()
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);
-}
-
int DolphinIconsView::additionalInfoCount() const
{
const DolphinView* view = m_controller->dolphinView();
*/
void updateGridSize(bool showPreview, int additionalInfoCount);
- KFileItem itemForIndex(const QModelIndex& index) const;
-
/**
* Returns the number of additional information lines that should
* be shown below the item name.