]> cloud.milkyroute.net Git - dolphin.git/commitdiff
Let the DolphinController be aware on which QAbstractItemView instance he is working...
authorPeter Penz <peter.penz19@gmail.com>
Thu, 21 Feb 2008 12:49:11 +0000 (12:49 +0000)
committerPeter Penz <peter.penz19@gmail.com>
Thu, 21 Feb 2008 12:49:11 +0000 (12:49 +0000)
svn path=/trunk/KDE/kdebase/apps/; revision=777737

src/dolphincolumnview.cpp
src/dolphincolumnwidget.cpp
src/dolphincolumnwidget.h
src/dolphincontroller.cpp
src/dolphincontroller.h
src/dolphindetailsview.cpp
src/dolphindetailsview.h
src/dolphiniconsview.cpp
src/dolphiniconsview.h
src/dolphinview.cpp

index 7257cd8301ec9d0d722d9d73ca383c00ff703be8..b0ce521728d0d9b946c67fd15aa2a1910e4fb46a 100644 (file)
@@ -555,6 +555,7 @@ void DolphinColumnView::assureVisibleActiveColumn()
 
 void DolphinColumnView::requestActivation(DolphinColumnWidget* column)
 {
+    m_controller->setItemView(column);
     if (column->isActive()) {
         assureVisibleActiveColumn();
     } else {
index 6f4f10d364df15ecfbc6018937d450dac6f5c36b..ca4db00c72a5e9d16aea95f8947dd81023141f64 100644 (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())
index 78f0d3ccb06868e1d07442f2e8be55e097c7d256..b8113cd6f373481218903e5c710bd1ff6f228336 100644 (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:
index 1bd59fffaf8150707295572c81e459d112bc407e..a0aa1d895ddda92e95c428fd8b9c8dd0b467dbe4 100644 (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);
     }
index 17e0a4a71431fe9cd91c42a5c445919f177f1b8a..9703e5f1b85823673d9a74e13b67e8499006a6f7 100644 (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;
index f364900b6b7f9c12829e9a68c5bba6566162c7a6..b17164d8b60c1b211a8bef531dd9dfab0a36f4b2 100644 (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);
index 92c451e63138b70a4d2735ecf73972b75b7c557f..14e995f6b75806276392cc80bbbf952996d62667 100644 (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.
index f51671e8a5a3f3e2b5bb25ac2c7d5785d539f534..bb3d242b98556efdc76bb49a51d1ab5b130565cd 100644 (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();
index f1210a97de80e67487f99a949582f78ea3ad036e..20d41051abddb738533ac60980022f541dff3fee 100644 (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();
index 5ce9cb6e17ec2372c2c3ed97d7e906669789a70a..6f351e63b97573955e20bf6d53826eeebcd453ce 100644 (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);