]> cloud.milkyroute.net Git - dolphin.git/commitdiff
fixed most regressions due to the previous column-view refactoring
authorPeter Penz <peter.penz19@gmail.com>
Fri, 5 Oct 2007 22:32:13 +0000 (22:32 +0000)
committerPeter Penz <peter.penz19@gmail.com>
Fri, 5 Oct 2007 22:32:13 +0000 (22:32 +0000)
svn path=/trunk/KDE/kdebase/apps/; revision=721706

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

index b8be24bf04ca83467615b32550df485ed1b9e157..5af15c56b8160053904ae90714c1bafc6f79a1cc 100644 (file)
@@ -47,9 +47,7 @@ DolphinColumnView::DolphinColumnView(QWidget* parent, DolphinController* control
     m_index(-1),
     m_contentX(0),
     m_columns(),
-    m_animation(0),
-    m_dolphinModel(0),
-    m_proxyModel(0)
+    m_animation(0)
 {
     Q_ASSERT(controller != 0);
 
@@ -66,8 +64,6 @@ DolphinColumnView::DolphinColumnView(QWidget* parent, DolphinController* control
             this, SLOT(zoomIn()));
     connect(controller, SIGNAL(zoomOut()),
             this, SLOT(zoomOut()));
-    connect(controller, SIGNAL(urlChanged(const KUrl&)),
-            this, SLOT(showColumn(const KUrl&)));
     connect(controller, SIGNAL(showHiddenFilesChanged(bool)),
             this, SLOT(slotShowHiddenFilesChanged(bool)));
     connect(controller, SIGNAL(showPreviewChanged(bool)),
@@ -123,13 +119,6 @@ QRect DolphinColumnView::visualRect(const QModelIndex& index) const
     return activeColumn()->visualRect(index);
 }
 
-void DolphinColumnView::setModel(QAbstractItemModel* model)
-{
-    m_proxyModel = static_cast<QAbstractProxyModel*>(model);
-    m_dolphinModel = static_cast<DolphinModel*>(m_proxyModel->sourceModel());
-    QAbstractItemView::setModel(model);
-}
-
 void DolphinColumnView::invertSelection()
 {
     QItemSelectionModel* selectionModel = activeColumn()->selectionModel();
@@ -150,34 +139,25 @@ void DolphinColumnView::reload()
     }
 }
 
+void DolphinColumnView::setRootUrl(const KUrl& url)
+{
+    removeAllColumns();
+    m_columns[0]->setUrl(url);
+}
+
+KUrl DolphinColumnView::rootUrl() const
+{
+    return m_columns[0]->url();
+}
+
 void DolphinColumnView::showColumn(const KUrl& url)
 {
     const KUrl& rootUrl = m_columns[0]->url();
     if (!rootUrl.isParentOf(url)) {
-        // the URL is no child URL of the column view, hence clear all columns
-        // and reset the root column
-        QList<DolphinColumnWidget*>::iterator start = m_columns.begin() + 1;
-        QList<DolphinColumnWidget*>::iterator end = m_columns.end();
-        for (QList<DolphinColumnWidget*>::iterator it = start; it != end; ++it) {
-            (*it)->deleteLater();
-        }
-        m_columns.erase(start, end);
-        m_index = 0;
-        m_columns[0]->setActive(true);
-        m_columns[0]->setUrl(url);
-        assureVisibleActiveColumn();
+        setRootUrl(url);
         return;
     }
 
-    KDirLister* dirLister = m_dolphinModel->dirLister();
-    const KUrl dirListerUrl = dirLister->url();
-    if (dirListerUrl != rootUrl) {
-        // It is possible that root URL of the directory lister is adjusted
-        // after creating the column widget (e. g. when restoring the history
-        // having a different root URL than the controller indicates).
-        m_columns[0]->setUrl(dirListerUrl);
-    }
-
     int columnIndex = 0;
     foreach (DolphinColumnWidget* column, m_columns) {
         if (column->url() == url) {
@@ -231,9 +211,6 @@ void DolphinColumnView::showColumn(const KUrl& url)
             ++slashIndex;
 
             const KUrl childUrl = KUrl(path);
-            const QModelIndex dirIndex = m_dolphinModel->indexForUrl(KUrl(path));
-            const QModelIndex proxyIndex = m_proxyModel->mapFromSource(dirIndex);
-
             m_columns[columnIndex]->setChildUrl(childUrl);
             columnIndex++;
 
@@ -248,10 +225,6 @@ void DolphinColumnView::showColumn(const KUrl& url)
             column->show();
             layoutColumns();
             updateScrollBar();
-
-            // the layout is finished, now let the column be invisible until it
-            // gets a valid root index due to expandToActiveUrl()
-            //column->hide();
         }
     }
 
@@ -514,4 +487,17 @@ void DolphinColumnView::requestActivation(DolphinColumnWidget* column)
     }
 }
 
+void DolphinColumnView::removeAllColumns()
+{
+    QList<DolphinColumnWidget*>::iterator start = m_columns.begin() + 1;
+    QList<DolphinColumnWidget*>::iterator end = m_columns.end();
+    for (QList<DolphinColumnWidget*>::iterator it = start; it != end; ++it) {
+        (*it)->deleteLater();
+    }
+    m_columns.erase(start, end);
+    m_index = 0;
+    m_columns[0]->setActive(true);
+    assureVisibleActiveColumn();
+}
+
 #include "dolphincolumnview.moc"
index b473e790ee3c7e145bda238eb922a9b2e5141993..6837815a0eae1431e1af7707bca10299f6f83a4f 100644 (file)
@@ -20,6 +20,8 @@
 #ifndef DOLPHINCOLUMNVIEW_H
 #define DOLPHINCOLUMNVIEW_H
 
+#include <kurl.h>
+
 #include <QAbstractItemView>
 #include <QList>
 #include <QStyleOption>
@@ -27,7 +29,6 @@
 class DolphinColumnWidget;
 class DolphinController;
 class DolphinModel;
-class KUrl;
 class QAbstractProxyModel;
 class QTimeLine;
 
@@ -48,7 +49,6 @@ public:
     virtual QModelIndex indexAt(const QPoint& point) const;
     virtual void scrollTo(const QModelIndex& index, ScrollHint hint = EnsureVisible);
     virtual QRect visualRect(const QModelIndex& index) const;
-    virtual void setModel(QAbstractItemModel* model);
 
     /** Inverts the selection of the currently active column. */
     void invertSelection();
@@ -60,6 +60,15 @@ public:
      */
     void reload();
 
+    /**
+     * Adjusts the root URL of the first column and removes all
+     * other columns.
+     */
+    void setRootUrl(const KUrl& url);
+
+    /** Returns the URL of the first column. */
+    KUrl rootUrl() const;
+
 public slots:
     /**
      * Shows the column which represents the URL \a url. If the column
@@ -132,6 +141,9 @@ private:
      */
     void requestActivation(DolphinColumnWidget* column);
 
+    /** Removes all columns except of the root column. */
+    void removeAllColumns();
+
 private:
     DolphinController* m_controller;
     bool m_restoreActiveColumnFocus;
@@ -140,9 +152,6 @@ private:
     QList<DolphinColumnWidget*> m_columns;
     QTimeLine* m_animation;
 
-    DolphinModel* m_dolphinModel;
-    QAbstractProxyModel* m_proxyModel;
-
     friend class DolphinColumnWidget;
 };
 
index 94bee2beef43947d01809a2469746d7680bb281d..4c6faaceae00d1c27109a24a280b77750ea3cfa3 100644 (file)
@@ -101,13 +101,8 @@ DolphinColumnWidget::DolphinColumnWidget(QWidget* parent,
 
     activate();
 
-    connect(this, SIGNAL(entered(const QModelIndex&)),
-            m_view->m_controller, SLOT(emitItemEntered(const QModelIndex&)));
-    connect(this, SIGNAL(viewportEntered()),
-            m_view->m_controller, SLOT(emitViewportEntered()));
     connect(this, SIGNAL(viewportEntered()),
             m_view->m_controller, SLOT(emitViewportEntered()));
-
     connect(this, SIGNAL(entered(const QModelIndex&)),
             this, SLOT(slotEntered(const QModelIndex&)));
 
@@ -305,6 +300,9 @@ void DolphinColumnWidget::selectionChanged(const QItemSelection& selected, const
 }
 void DolphinColumnWidget::triggerItem(const QModelIndex& index)
 {
+    const KFileItem item = m_dolphinModel->itemForIndex(m_proxyModel->mapToSource(index));
+    m_view->m_controller->triggerItem(item);
+    /*
     const Qt::KeyboardModifiers modifier = QApplication::keyboardModifiers();
     if ((modifier & Qt::ShiftModifier) || (modifier & Qt::ControlModifier)) {
         // items are selected by the user, hence don't trigger the
@@ -321,7 +319,7 @@ void DolphinColumnWidget::triggerItem(const QModelIndex& index)
         m_view->m_controller->setUrl(url);
     } else if (item.isFile()) {
         item.run();
-    }
+    }*/
 }
 
 void DolphinColumnWidget::generatePreviews(const KFileItemList& items)
index 4666e617b5a12dcfc81ba1fc4a1b825c2e10fbe9..59cc20f0f9133052dffc40b504d7786831f069d4 100644 (file)
@@ -135,9 +135,9 @@ void DolphinController::drawHoverIndication(QWidget* widget,
     painter.restore();
 }
 
-void DolphinController::triggerItem(const QModelIndex& index)
+void DolphinController::triggerItem(const KFileItem& item)
 {
-    emit itemTriggered(index);
+    emit itemTriggered(item);
 }
 
 void DolphinController::emitItemEntered(const KFileItem& item)
index 3a2720471a127f5f020c264718bcdc6424af451a..31b80e7bffa4028188a9d0c64eb60f505594efbc 100644 (file)
@@ -100,7 +100,7 @@ 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 QModelIndex& index);
+    void triggerItem(const KFileItem& item);
 
     /**
      * Emits the signal itemEntered(). The method should be invoked by
@@ -171,12 +171,12 @@ signals:
     void additionalInfoCountChanged(int count);
 
     /**
-     * Is emitted if the item with the index \a index should be triggered.
+     * Is emitted if the item \a item should be triggered.
      * Usually triggering on a directory opens the directory, triggering
-     * on a file opens the corresponding application.
-     * Emitted with an invalid \a index when clicking on the viewport itself.
+     * on a file opens the corresponding application. The item is null
+     * (see KFileItem::isNull()), when clicking on the viewport itself.
      */
-    void itemTriggered(const QModelIndex& index);
+    void itemTriggered(const KFileItem& item);
 
     /**
      * Is emitted if the mouse cursor has entered the item
index 078f51bf1ac41aa084fa41f16983173ae0485377..6cd9fbaf9a000a8c37f53148b50ada6c1f9ee0b9 100644 (file)
@@ -84,10 +84,10 @@ DolphinDetailsView::DolphinDetailsView(QWidget* parent, DolphinController* contr
     // RETURN-key in keyPressEvent().
     if (KGlobalSettings::singleClick()) {
         connect(this, SIGNAL(clicked(const QModelIndex&)),
-                this, SLOT(slotItemActivated(const QModelIndex&)));
+                this, SLOT(triggerItem(const QModelIndex&)));
     } else {
         connect(this, SIGNAL(doubleClicked(const QModelIndex&)),
-                this, SLOT(slotItemActivated(const QModelIndex&)));
+                this, SLOT(triggerItem(const QModelIndex&)));
     }
     connect(this, SIGNAL(entered(const QModelIndex&)),
             this, SLOT(slotEntered(const QModelIndex&)));
@@ -317,11 +317,11 @@ void DolphinDetailsView::keyPressEvent(QKeyEvent* event)
 
     const QItemSelectionModel* selModel = selectionModel();
     const QModelIndex currentIndex = selModel->currentIndex();
-    const bool triggerItem = currentIndex.isValid()
-                             && (event->key() == Qt::Key_Return)
-                             && (selModel->selectedIndexes().count() <= 1);
-    if (triggerItem) {
-        m_controller->triggerItem(currentIndex);
+    const bool trigger = currentIndex.isValid()
+                         && (event->key() == Qt::Key_Return)
+                         && (selModel->selectedIndexes().count() <= 1);
+    if (trigger) {
+        triggerItem(currentIndex);
     }
 }
 
@@ -434,13 +434,14 @@ void DolphinDetailsView::zoomOut()
     }
 }
 
-void DolphinDetailsView::slotItemActivated(const QModelIndex& index)
+void DolphinDetailsView::triggerItem(const QModelIndex& index)
 {
+    const KFileItem item = itemForIndex(index);
     if (index.isValid() && (index.column() == KDirModel::Name)) {
-        m_controller->triggerItem(index);
+        m_controller->triggerItem(item);
     } else {
         clearSelection();
-        m_controller->emitItemEntered(itemForIndex(index));
+        m_controller->emitItemEntered(item);
     }
 }
 
index 06cd9a83335ead816bb19bfba00de6d8882b32ca..c8fd90aa81d879aeecaeac32b30b1b9369ff7801 100644 (file)
@@ -108,7 +108,7 @@ private slots:
     /**
      * Called by QTreeView when an item is activated (clicked or double-clicked)
      */
-    void slotItemActivated(const QModelIndex& index);
+    void triggerItem(const QModelIndex& index);
 
     /**
      * Opens a context menu at the position \a pos and allows to
index 042c9a76c84a1c15de46e2ceadba98d3fc18a171..f1ad25e3dd62b9300b119e44e511d3fcf80b58c6 100644 (file)
@@ -54,10 +54,10 @@ DolphinIconsView::DolphinIconsView(QWidget* parent, DolphinController* controlle
     // RETURN-key in keyPressEvent().
     if (KGlobalSettings::singleClick()) {
         connect(this, SIGNAL(clicked(const QModelIndex&)),
-                controller, SLOT(triggerItem(const QModelIndex&)));
+                this, SLOT(triggerItem(const QModelIndex&)));
     } else {
         connect(this, SIGNAL(doubleClicked(const QModelIndex&)),
-                controller, SLOT(triggerItem(const QModelIndex&)));
+                this, SLOT(triggerItem(const QModelIndex&)));
     }
     connect(this, SIGNAL(viewportEntered()),
             controller, SLOT(emitViewportEntered()));
@@ -222,22 +222,22 @@ void DolphinIconsView::keyPressEvent(QKeyEvent* event)
 
     const QItemSelectionModel* selModel = selectionModel();
     const QModelIndex currentIndex = selModel->currentIndex();
-    const bool triggerItem = currentIndex.isValid()
-                             && (event->key() == Qt::Key_Return)
-                             && (selModel->selectedIndexes().count() <= 1);
-    if (triggerItem) {
-        m_controller->triggerItem(currentIndex);
+    const bool trigger = currentIndex.isValid()
+                         && (event->key() == Qt::Key_Return)
+                         && (selModel->selectedIndexes().count() <= 1);
+    if (trigger) {
+        triggerItem(currentIndex);
     }
 }
 
-void DolphinIconsView::slotEntered(const QModelIndex& index)
+void DolphinIconsView::triggerItem(const QModelIndex& index)
 {
-    QAbstractProxyModel* proxyModel = static_cast<QAbstractProxyModel*>(model());
-    KDirModel* dirModel = static_cast<KDirModel*>(proxyModel->sourceModel());
-    const QModelIndex dirIndex = proxyModel->mapToSource(index);
+    m_controller->triggerItem(itemForIndex(index));
+}
 
-    const KFileItem item = dirModel->itemForIndex(dirIndex);
-    m_controller->emitItemEntered(item);
+void DolphinIconsView::slotEntered(const QModelIndex& index)
+{
+    m_controller->emitItemEntered(itemForIndex(index));
 }
 
 void DolphinIconsView::slotShowPreviewChanged(bool showPreview)
@@ -393,4 +393,13 @@ 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);
+}
+
+
 #include "dolphiniconsview.moc"
index a95163f3aacac9f1795b7ccfcb37a64540c0b6c3..5838a98dd7ff167dcea8ed5eb4f1034608002b0c 100644 (file)
@@ -22,6 +22,8 @@
 
 #include <kcategorizedview.h>
 
+#include <kfileitem.h>
+
 #include <QSize>
 #include <QStyleOption>
 
@@ -59,6 +61,7 @@ protected:
     virtual void keyPressEvent(QKeyEvent* event);
 
 private slots:
+    void triggerItem(const QModelIndex& index);
     void slotEntered(const QModelIndex& index);
     void slotShowPreviewChanged(bool show);
     void slotAdditionalInfoCountChanged(int count);
@@ -81,6 +84,8 @@ private:
      */
     void updateGridSize(bool showPreview, int additionalInfoCount);
 
+    KFileItem itemForIndex(const QModelIndex& index) const;
+
 private:
     DolphinController* m_controller;
     DolphinCategoryDrawer* m_categoryDrawer;
index ad760fb134a55967ca9038af7f9c9ba08d12118b..53d8acae50fc5f06bdb05eea862c4f1c611e51b1 100644 (file)
@@ -98,8 +98,8 @@ DolphinView::DolphinView(QWidget* parent,
             this, SLOT(updateSorting(DolphinView::Sorting)));
     connect(m_controller, SIGNAL(sortOrderChanged(Qt::SortOrder)),
             this, SLOT(updateSortOrder(Qt::SortOrder)));
-    connect(m_controller, SIGNAL(itemTriggered(const QModelIndex&)),
-            this, SLOT(triggerItem(const QModelIndex&)));
+    connect(m_controller, SIGNAL(itemTriggered(const KFileItem&)),
+            this, SLOT(triggerItem(const KFileItem&)));
     connect(m_controller, SIGNAL(activated()),
             this, SLOT(activate()));
     connect(m_controller, SIGNAL(itemEntered(const KFileItem&)),
@@ -122,7 +122,7 @@ const KUrl& DolphinView::url() const
 
 KUrl DolphinView::rootUrl() const
 {
-    return isColumnViewActive() ? m_dirLister->url() : url();
+    return isColumnViewActive() ? m_columnView->rootUrl() : url();
 }
 
 void DolphinView::setActive(bool active)
@@ -457,6 +457,7 @@ void DolphinView::updateView(const KUrl& url, const KUrl& rootUrl)
         // that the view properties have been changed or deleted in the meantime, so
         // it cannot be asserted that really a column view has been created:
         if (itemView() == m_columnView) {
+            m_columnView->setRootUrl(rootUrl);
             m_columnView->showColumn(url);
         }
     } else {
@@ -484,10 +485,8 @@ void DolphinView::activate()
     setActive(true);
 }
 
-void DolphinView::triggerItem(const QModelIndex& index)
+void DolphinView::triggerItem(const KFileItem& item)
 {
-    Q_ASSERT(index.isValid());
-
     const Qt::KeyboardModifiers modifier = QApplication::keyboardModifiers();
     if ((modifier & Qt::ShiftModifier) || (modifier & Qt::ControlModifier)) {
         // items are selected by the user, hence don't trigger the
@@ -495,8 +494,6 @@ void DolphinView::triggerItem(const QModelIndex& index)
         return;
     }
 
-    const KFileItem item = m_dolphinModel->itemForIndex(m_proxyModel->mapToSource(index));
-
     if (item.isNull()) {
         return;
     }
@@ -558,10 +555,14 @@ void DolphinView::loadDirectory(const KUrl& url, bool reload)
     m_dirLister->stop();
     m_dirLister->openUrl(url, reload ? KDirLister::Reload : KDirLister::NoFlags);
 
-    if (isColumnViewActive() && reload) {
-        // reloading the directory lister is not enough in the case of the
+    if (isColumnViewActive()) {
+        // adjusting the directory lister is not enough in the case of the
         // column view, as each column has its own directory lister internally...
-        m_columnView->reload();
+        if (reload) {
+            m_columnView->reload();
+        } else {
+            m_columnView->showColumn(url);
+        }
     }
 }
 
@@ -576,7 +577,7 @@ KUrl DolphinView::viewPropertiesUrl() const
 
 void DolphinView::applyViewProperties(const KUrl& url)
 {
-    if (isColumnViewActive() && m_dirLister->url().isParentOf(url)) {
+    if (isColumnViewActive() && rootUrl().isParentOf(url)) {
         // The column view is active, hence don't apply the view properties
         // of sub directories (represented by columns) to the view. The
         // view always represents the properties of the first column.
index d9d2f5cca33c4827341bc3180d6b4d1efb3e66ff..2f3bdadb48d47cab4474b2959e334fa00936fd0f 100644 (file)
@@ -418,11 +418,11 @@ private slots:
     void activate();
 
     /**
-     * If the item specified by \a index is a directory, then this
+     * If the item \a item is a directory, then this
      * directory will be loaded. If the  item is a file, the corresponding
      * application will get started.
      */
-    void triggerItem(const QModelIndex& index);
+    void triggerItem(const KFileItem& index);
 
     /**
      * Generates a preview image for each file item in \a items.