From: Peter Penz Date: Thu, 21 Feb 2008 12:49:11 +0000 (+0000) Subject: Let the DolphinController be aware on which QAbstractItemView instance he is working... X-Git-Url: https://cloud.milkyroute.net/gitweb/dolphin.git/commitdiff_plain/188754a3e5b298683b88fbe6786c524c172ed6a9 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 --- diff --git a/src/dolphincolumnview.cpp b/src/dolphincolumnview.cpp index 7257cd830..b0ce52172 100644 --- a/src/dolphincolumnview.cpp +++ b/src/dolphincolumnview.cpp @@ -555,6 +555,7 @@ void DolphinColumnView::assureVisibleActiveColumn() void DolphinColumnView::requestActivation(DolphinColumnWidget* column) { + m_controller->setItemView(column); if (column->isActive()) { assureVisibleActiveColumn(); } else { diff --git a/src/dolphincolumnwidget.cpp b/src/dolphincolumnwidget.cpp index 6f4f10d36..ca4db00c7 100644 --- a/src/dolphincolumnwidget.cpp +++ b/src/dolphincolumnwidget.cpp @@ -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()) diff --git a/src/dolphincolumnwidget.h b/src/dolphincolumnwidget.h index 78f0d3ccb..b8113cd6f 100644 --- a/src/dolphincolumnwidget.h +++ b/src/dolphincolumnwidget.h @@ -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: diff --git a/src/dolphincontroller.cpp b/src/dolphincontroller.cpp index 1bd59fffa..a0aa1d895 100644 --- a/src/dolphincontroller.cpp +++ b/src/dolphincontroller.cpp @@ -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(view->model()); + Q_ASSERT(m_itemView != 0); + + QAbstractProxyModel* proxyModel = static_cast(m_itemView->model()); KDirModel* dirModel = static_cast(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); } diff --git a/src/dolphincontroller.h b/src/dolphincontroller.h index 17e0a4a71..9703e5f1b 100644 --- a/src/dolphincontroller.h +++ b/src/dolphincontroller.h @@ -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; diff --git a/src/dolphindetailsview.cpp b/src/dolphindetailsview.cpp index f364900b6..b17164d8b 100644 --- a/src/dolphindetailsview.cpp +++ b/src/dolphindetailsview.cpp @@ -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); diff --git a/src/dolphindetailsview.h b/src/dolphindetailsview.h index 92c451e63..14e995f6b 100644 --- a/src/dolphindetailsview.h +++ b/src/dolphindetailsview.h @@ -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. diff --git a/src/dolphiniconsview.cpp b/src/dolphiniconsview.cpp index f51671e8a..bb3d242b9 100644 --- a/src/dolphiniconsview.cpp +++ b/src/dolphiniconsview.cpp @@ -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(); diff --git a/src/dolphiniconsview.h b/src/dolphiniconsview.h index f1210a97d..20d41051a 100644 --- a/src/dolphiniconsview.h +++ b/src/dolphiniconsview.h @@ -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(); diff --git a/src/dolphinview.cpp b/src/dolphinview.cpp index 5ce9cb6e1..6f351e63b 100644 --- a/src/dolphinview.cpp +++ b/src/dolphinview.cpp @@ -897,6 +897,7 @@ void DolphinView::createView() } Q_ASSERT(view != 0); + m_controller->setItemView(view); m_fileItemDelegate = new KFileItemDelegate(view); view->setItemDelegate(m_fileItemDelegate);