Let the DolphinController be aware on which QAbstractItemView instance he is working. This allows to connect signals from the view implementations (icons view, details view, column view) directly to the slots of the DolphinController without a helper slot.

svn path=/trunk/KDE/kdebase/apps/; revision=777737
This commit is contained in:
Peter Penz 2008-02-21 12:49:11 +00:00
parent e287058acb
commit 188754a3e5
10 changed files with 73 additions and 74 deletions

View file

@ -555,6 +555,7 @@ void DolphinColumnView::assureVisibleActiveColumn()
void DolphinColumnView::requestActivation(DolphinColumnWidget* column)
{
m_controller->setItemView(column);
if (column->isActive()) {
assureVisibleActiveColumn();
} else {

View file

@ -277,7 +277,8 @@ void DolphinColumnWidget::dragMoveEvent(QDragMoveEvent* event)
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);
}
@ -295,7 +296,8 @@ 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 = 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);
@ -344,13 +346,15 @@ void DolphinColumnWidget::mousePressEvent(QMouseEvent* event)
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);
}
@ -361,6 +365,7 @@ void DolphinColumnWidget::contextMenuEvent(QContextMenuEvent* event)
// 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);
}
}
@ -370,7 +375,7 @@ void DolphinColumnWidget::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;
}
QListView::wheelEvent(event);
}
@ -384,14 +389,10 @@ void DolphinColumnWidget::selectionChanged(const QItemSelection& selected, const
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()
@ -402,6 +403,7 @@ void DolphinColumnWidget::requestActivation()
m_view->m_controller->triggerUrlChangeRequest(m_url);
selectionModel()->clear();
}
Q_ASSERT(m_view->m_controller->itemView() == this);
}
void DolphinColumnWidget::updateFont()
@ -423,10 +425,10 @@ void DolphinColumnWidget::activate()
// 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())

View file

@ -113,17 +113,8 @@ protected:
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:

View file

@ -27,7 +27,8 @@ DolphinController::DolphinController(DolphinView* dolphinView) :
m_zoomInPossible(false),
m_zoomOutPossible(false),
m_url(),
m_dolphinView(dolphinView)
m_dolphinView(dolphinView),
m_itemView(0)
{
}
@ -43,6 +44,11 @@ void DolphinController::setUrl(const KUrl& url)
}
}
void DolphinController::setItemView(QAbstractItemView* view)
{
m_itemView = view;
}
void DolphinController::triggerUrlChangeRequest(const KUrl& url)
{
if (m_url != url) {
@ -99,9 +105,11 @@ void DolphinController::triggerZoomOut()
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)
@ -109,33 +117,35 @@ void DolphinController::handleKeyPressEvent(QKeyEvent* event, QAbstractItemView*
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);
}

View file

@ -41,13 +41,15 @@ class QWidget;
* 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:
@ -95,6 +97,15 @@ public:
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
@ -199,12 +210,12 @@ public:
* 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:
/**
@ -212,14 +223,14 @@ 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
@ -337,6 +348,7 @@ private:
bool m_zoomOutPossible;
KUrl m_url;
DolphinView* m_dolphinView;
QAbstractItemView* m_itemView;
};
inline const DolphinView* DolphinController::dolphinView() const
@ -349,6 +361,11 @@ inline const KUrl& DolphinController::url() const
return m_url;
}
inline QAbstractItemView* DolphinController::itemView() const
{
return m_itemView;
}
inline void DolphinController::setZoomInPossible(bool possible)
{
m_zoomInPossible = possible;

View file

@ -97,7 +97,7 @@ DolphinDetailsView::DolphinDetailsView(QWidget* parent, DolphinController* contr
// 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()),
@ -107,7 +107,7 @@ DolphinDetailsView::DolphinDetailsView(QWidget* parent, DolphinController* contr
}
} 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&)));
@ -310,7 +310,7 @@ void DolphinDetailsView::dragMoveEvent(QDragMoveEvent* event)
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 {
@ -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 = m_controller->itemForIndex(index, this);
item = m_controller->itemForIndex(index);
}
m_controller->indicateDroppedUrls(urls,
m_controller->url(),
@ -372,7 +372,7 @@ void DolphinDetailsView::paintEvent(QPaintEvent* event)
void DolphinDetailsView::keyPressEvent(QKeyEvent* event)
{
QTreeView::keyPressEvent(event);
m_controller->handleKeyPressEvent(event, this);
m_controller->handleKeyPressEvent(event);
}
void DolphinDetailsView::resizeEvent(QResizeEvent* event)
@ -420,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(index, this);
m_controller->emitItemEntered(index);
}
else {
m_controller->emitViewportEntered();
@ -470,11 +470,6 @@ void DolphinDetailsView::zoomOut()
}
}
void DolphinDetailsView::triggerItem(const QModelIndex& index)
{
m_controller->triggerItem(index, this);
}
void DolphinDetailsView::configureColumns(const QPoint& pos)
{
KMenu popup(this);

View file

@ -106,11 +106,6 @@ private slots:
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.

View file

@ -66,7 +66,7 @@ DolphinIconsView::DolphinIconsView(QWidget* parent, DolphinController* controlle
// 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()),
@ -76,8 +76,10 @@ DolphinIconsView::DolphinIconsView(QWidget* parent, DolphinController* controlle
}
} 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()),
@ -91,9 +93,6 @@ DolphinIconsView::DolphinIconsView(QWidget* parent, DolphinController* controlle
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);
@ -244,7 +243,7 @@ void DolphinIconsView::dragMoveEvent(QDragMoveEvent* event)
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 {
@ -265,7 +264,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 = m_controller->itemForIndex(index, this);
const KFileItem item = m_controller->itemForIndex(index);
m_controller->indicateDroppedUrls(urls,
m_controller->url(),
item);
@ -292,7 +291,7 @@ void DolphinIconsView::paintEvent(QPaintEvent* event)
void DolphinIconsView::keyPressEvent(QKeyEvent* event)
{
KCategorizedView::keyPressEvent(event);
m_controller->handleKeyPressEvent(event, this);
m_controller->handleKeyPressEvent(event);
}
void DolphinIconsView::wheelEvent(QWheelEvent* event)
@ -318,16 +317,6 @@ 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();

View file

@ -65,8 +65,6 @@ protected:
virtual void wheelEvent(QWheelEvent* event);
private slots:
void triggerItem(const QModelIndex& index);
void slotEntered(const QModelIndex& index);
void slotShowPreviewChanged();
void slotAdditionalInfoChanged();
void zoomIn();

View file

@ -897,6 +897,7 @@ void DolphinView::createView()
}
Q_ASSERT(view != 0);
m_controller->setItemView(view);
m_fileItemDelegate = new KFileItemDelegate(view);
view->setItemDelegate(m_fileItemDelegate);