mirror of
https://invent.kde.org/system/dolphin
synced 2024-09-20 00:41:23 +00:00
Prevent code duplication by moving the duplications into the DolphinController.
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
This commit is contained in:
parent
c735913801
commit
e287058acb
|
@ -277,7 +277,7 @@ void DolphinColumnWidget::dragMoveEvent(QDragMoveEvent* event)
|
|||
|
||||
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);
|
||||
}
|
||||
|
@ -295,7 +295,7 @@ void DolphinColumnWidget::dropEvent(QDropEvent* event)
|
|||
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);
|
||||
|
@ -344,21 +344,7 @@ void DolphinColumnWidget::mousePressEvent(QMouseEvent* event)
|
|||
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)
|
||||
|
@ -400,15 +386,12 @@ void DolphinColumnWidget::selectionChanged(const QItemSelection& selected, const
|
|||
|
||||
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()
|
||||
|
@ -473,11 +456,4 @@ void DolphinColumnWidget::deactivate()
|
|||
updateBackground();
|
||||
}
|
||||
|
||||
KFileItem DolphinColumnWidget::itemForIndex(const QModelIndex& index) const
|
||||
{
|
||||
const QModelIndex dirIndex = m_proxyModel->mapToSource(index);
|
||||
return m_dolphinModel->itemForIndex(dirIndex);
|
||||
}
|
||||
|
||||
|
||||
#include "dolphincolumnwidget.moc"
|
||||
|
|
|
@ -133,8 +133,6 @@ private:
|
|||
/** Used by DolphinColumnWidget::setActive(). */
|
||||
void deactivate();
|
||||
|
||||
KFileItem itemForIndex(const QModelIndex& index) const;
|
||||
|
||||
private:
|
||||
bool m_active;
|
||||
DolphinColumnView* m_view;
|
||||
|
|
|
@ -19,6 +19,9 @@
|
|||
|
||||
#include "dolphincontroller.h"
|
||||
|
||||
#include <kdirmodel.h>
|
||||
#include <QAbstractProxyModel>
|
||||
|
||||
DolphinController::DolphinController(DolphinView* dolphinView) :
|
||||
QObject(dolphinView),
|
||||
m_zoomInPossible(false),
|
||||
|
@ -96,14 +99,46 @@ void DolphinController::triggerZoomOut()
|
|||
emit zoomOut();
|
||||
}
|
||||
|
||||
void DolphinController::triggerItem(const KFileItem& item)
|
||||
void DolphinController::handleKeyPressEvent(QKeyEvent* event, QAbstractItemView* view)
|
||||
{
|
||||
emit itemTriggered(item);
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void DolphinController::emitItemEntered(const KFileItem& item)
|
||||
KFileItem DolphinController::itemForIndex(const QModelIndex& index, QAbstractItemView* view) const
|
||||
{
|
||||
emit itemEntered(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::triggerItem(const QModelIndex& index, QAbstractItemView* view)
|
||||
{
|
||||
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()
|
||||
|
|
|
@ -25,6 +25,7 @@
|
|||
#include <QtCore/QObject>
|
||||
#include <libdolphin_export.h>
|
||||
|
||||
class QAbstractItemView;
|
||||
class DolphinView;
|
||||
class KUrl;
|
||||
class QBrush;
|
||||
|
@ -59,6 +60,7 @@ class QWidget;
|
|||
* - setZoomInPossible()
|
||||
* - setZoomOutPossible()
|
||||
* - triggerItem()
|
||||
* - handleKeyPressEvent()
|
||||
* - emitItemEntered()
|
||||
* - emitViewportEntered()
|
||||
*
|
||||
|
@ -192,17 +194,32 @@ public:
|
|||
void setZoomOutPossible(bool possible);
|
||||
bool isZoomOutPossible() 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);
|
||||
* 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);
|
||||
|
||||
/**
|
||||
* Emits the signal itemEntered(). The method should be invoked by
|
||||
* the controller parent whenever the mouse cursor is above an item.
|
||||
* Returns the file item for the proxy index \a index of the view \a view.
|
||||
*/
|
||||
void emitItemEntered(const KFileItem& item);
|
||||
KFileItem itemForIndex(const QModelIndex& index, QAbstractItemView* view) const;
|
||||
|
||||
public slots:
|
||||
/**
|
||||
* 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() 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);
|
||||
|
||||
/**
|
||||
* Emits the signal viewportEntered(). The method should be invoked by
|
||||
|
|
|
@ -310,7 +310,7 @@ void DolphinDetailsView::dragMoveEvent(QDragMoveEvent* event)
|
|||
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 {
|
||||
|
@ -333,7 +333,7 @@ void DolphinDetailsView::dropEvent(QDropEvent* event)
|
|||
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(),
|
||||
|
@ -372,21 +372,7 @@ void DolphinDetailsView::paintEvent(QPaintEvent* event)
|
|||
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)
|
||||
|
@ -434,7 +420,7 @@ void DolphinDetailsView::slotEntered(const QModelIndex& index)
|
|||
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();
|
||||
|
@ -486,13 +472,7 @@ void DolphinDetailsView::zoomOut()
|
|||
|
||||
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)
|
||||
|
@ -618,14 +598,6 @@ QPoint DolphinDetailsView::contentsPos() const
|
|||
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;
|
||||
|
|
|
@ -150,8 +150,6 @@ private:
|
|||
/** 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;
|
||||
|
||||
/**
|
||||
|
|
|
@ -244,7 +244,7 @@ void DolphinIconsView::dragMoveEvent(QDragMoveEvent* event)
|
|||
|
||||
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 {
|
||||
|
@ -265,7 +265,7 @@ void DolphinIconsView::dropEvent(QDropEvent* event)
|
|||
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);
|
||||
|
@ -292,21 +292,7 @@ void DolphinIconsView::paintEvent(QPaintEvent* event)
|
|||
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)
|
||||
|
@ -314,7 +300,7 @@ 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
|
||||
|
@ -334,12 +320,12 @@ void DolphinIconsView::wheelEvent(QWheelEvent* event)
|
|||
|
||||
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()
|
||||
|
@ -516,14 +502,6 @@ void DolphinIconsView::updateGridSize(bool showPreview, int additionalInfoCount)
|
|||
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();
|
||||
|
|
|
@ -90,8 +90,6 @@ private:
|
|||
*/
|
||||
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.
|
||||
|
|
Loading…
Reference in a new issue