]> cloud.milkyroute.net Git - dolphin.git/commitdiff
Restore "open folders automatically when dragging items above it" (it had been tempor...
authorPeter Penz <peter.penz19@gmail.com>
Sun, 30 Aug 2009 20:49:34 +0000 (20:49 +0000)
committerPeter Penz <peter.penz19@gmail.com>
Sun, 30 Aug 2009 20:49:34 +0000 (20:49 +0000)
svn path=/trunk/KDE/kdebase/apps/; revision=1017531

src/dolphincolumnviewcontainer.cpp
src/dolphincolumnviewcontainer.h
src/dolphindetailsview.cpp
src/dolphinview.cpp
src/dolphinview.h
src/folderexpander.cpp
src/viewextensionsfactory.cpp
src/viewextensionsfactory.h

index c1b51280b30a3465e7047652f04f5b2556c85808..3e067d413d26b2399c316661b9358c5836eed19d 100644 (file)
@@ -22,6 +22,7 @@
 #include "dolphincolumnview.h"
 #include "dolphincontroller.h"
 #include "dolphinsortfilterproxymodel.h"
+#include "draganddrophelper.h"
 #include "settings/dolphinsettings.h"
 
 #include "dolphin_columnmodesettings.h"
@@ -39,7 +40,8 @@ DolphinColumnViewContainer::DolphinColumnViewContainer(QWidget* parent,
     m_contentX(0),
     m_columns(),
     m_emptyViewport(0),
-    m_animation(0)
+    m_animation(0),
+    m_dragSource(0)
 {
     Q_ASSERT(controller != 0);
 
@@ -48,8 +50,6 @@ DolphinColumnViewContainer::DolphinColumnViewContainer(QWidget* parent,
     setFrameShape(QFrame::NoFrame);
     setLayoutDirection(Qt::LeftToRight);
 
-    //connect(this, SIGNAL(viewportEntered()),
-    //        controller, SLOT(emitViewportEntered()));
     connect(controller, SIGNAL(activationChanged(bool)),
             this, SLOT(updateColumnsBackground(bool)));
 
@@ -71,6 +71,8 @@ DolphinColumnViewContainer::DolphinColumnViewContainer(QWidget* parent,
 
 DolphinColumnViewContainer::~DolphinColumnViewContainer()
 {
+    delete m_dragSource;
+    m_dragSource = 0;
 }
 
 KUrl DolphinColumnViewContainer::rootUrl() const
@@ -358,19 +360,37 @@ QPoint DolphinColumnViewContainer::columnPosition(DolphinColumnView* column, con
 
 void DolphinColumnViewContainer::deleteColumn(DolphinColumnView* column)
 {
-    if (column != 0) {
-        if (m_controller->itemView() == column) {
-            m_controller->setItemView(0);
+    if (column == 0) {
+        return;
+    }
+
+    if (m_controller->itemView() == column) {
+        m_controller->setItemView(0);
+    }
+    // deleteWhenNotDragSource(column) does not necessarily delete column,
+    // and we want its preview generator destroyed immediately.
+    column->hide();
+    // Prevent automatic destruction of column when this DolphinColumnViewContainer
+    // is destroyed.
+    column->setParent(0);
+    column->disconnect();
+
+    if (DragAndDropHelper::instance().isDragSource(column)) {
+        // The column is a drag source (the feature "Open folders
+        // during drag operations" is used). Deleting the view
+        // during an ongoing drag operation is not allowed, so
+        // this will postponed.
+        if (m_dragSource != 0) {
+            // the old stored view is obviously not the drag source anymore
+            m_dragSource->deleteLater();
+            m_dragSource = 0;
         }
-        // deleteWhenNotDragSource(column) does not necessarily delete column,
-        // and we want its preview generator destroyed immediately.
         column->hide();
-        // Prevent automatic destruction of column when this DolphinColumnViewContainer
-        // is destroyed.
         column->setParent(0);
         column->disconnect();
 
-        //emit requestColumnDeletion(column);
+        m_dragSource = column;
+    } else {
         column->deleteLater();
     }
 }
index 72a65b4a9b3d0416383415f3fef7611e76e29ece..626cd98a19e2981a2ec55ca3631c1f1f6d683e21 100644 (file)
@@ -58,13 +58,6 @@ public:
      */
     void showColumn(const KUrl& url);
 
-signals:
-    /**
-     * Requests that the given column be deleted at the discretion
-     * of the receiver of the signal.
-     */
-    void requestColumnDeletion(QAbstractItemView* column);
-
 protected:
     virtual void mousePressEvent(QMouseEvent* event);
     virtual void keyPressEvent(QKeyEvent* event);
@@ -132,6 +125,7 @@ private:
     QList<DolphinColumnView*> m_columns;
     QFrame* m_emptyViewport;
     QTimeLine* m_animation;
+    QAbstractItemView* m_dragSource;
 
     friend class DolphinColumnView;
 };
index f0671db55259b4a52bc1c61c7542a9801c604b44..088e5dc7ebb9d10d99157c149035acc8ea9ffb93 100644 (file)
@@ -153,6 +153,7 @@ DolphinDetailsView::DolphinDetailsView(QWidget* parent,
 
     m_extensionsFactory = new ViewExtensionsFactory(this, controller);
     m_extensionsFactory->fileItemDelegate()->setMinimizedNameColumn(true);
+    m_extensionsFactory->setAutoFolderExpandingEnabled(settings->expandableFolders());
 
     updateDecorationSize(view->showPreview());
 }
index 7e8b4e74fd2573cd10c5c0049257dc4c421f6358..dff8120c71edb4ac5f065a3d9ec3d8576185105c 100644 (file)
@@ -60,7 +60,6 @@
 #include "dolphiniconsview.h"
 #include "dolphin_generalsettings.h"
 #include "draganddrophelper.h"
-#include "folderexpander.h"
 #include "renamedialog.h"
 #include "settings/dolphinsettings.h"
 #include "viewproperties.h"
@@ -97,8 +96,7 @@ DolphinView::DolphinView(QWidget* parent,
     m_activeItemUrl(),
     m_createdItemUrl(),
     m_selectedItems(),
-    m_newFileNames(),
-    m_expandedDragSource(0)
+    m_newFileNames()
 {
     m_topLayout = new QVBoxLayout(this);
     m_topLayout->setSpacing(0);
@@ -161,8 +159,6 @@ DolphinView::DolphinView(QWidget* parent,
 
 DolphinView::~DolphinView()
 {
-    delete m_expandedDragSource;
-    m_expandedDragSource = 0;
 }
 
 const KUrl& DolphinView::url() const
@@ -854,18 +850,6 @@ bool DolphinView::eventFilter(QObject* watched, QEvent* event)
         }
         break;
 
-    case QEvent::MouseButtonPress:
-        if ((watched == m_viewAccessor.itemView()->viewport()) && (m_expandedDragSource != 0)) {
-            // Listening to a mousebutton press event to delete expanded views is a
-            // workaround, as it seems impossible for the FolderExpander to know when
-            // a dragging outside a view has been finished. However it works quite well:
-            // A mousebutton press event indicates that a drag operation must be
-            // finished already.
-            m_expandedDragSource->deleteLater();
-            m_expandedDragSource = 0;
-        }
-        break;
-
     case QEvent::DragEnter:
         if (watched == m_viewAccessor.itemView()->viewport()) {
             setActive(true);
@@ -1065,26 +1049,6 @@ bool DolphinView::itemsExpandable() const
     return m_viewAccessor.itemsExpandable();
 }
 
-void DolphinView::deleteWhenNotDragSource(QAbstractItemView *view)
-{
-    if (view == 0)
-        return;
-
-    if (DragAndDropHelper::instance().isDragSource(view)) {
-        // We must store for later deletion.
-        if (m_expandedDragSource != 0) {
-            // The old stored view is obviously not the drag source anymore.
-            m_expandedDragSource->deleteLater();
-            m_expandedDragSource = 0;
-        }
-        view->hide();
-        m_expandedDragSource = view;
-    }
-    else {
-        view->deleteLater();
-    }
-}
-
 void DolphinView::observeCreatedItem(const KUrl& url)
 {
     m_createdItemUrl = url;
@@ -1305,26 +1269,9 @@ void DolphinView::createView()
     view->installEventFilter(this);
     view->viewport()->installEventFilter(this);
 
-
-    /* TODO: enable folder expanding again later
-
-    if (m_mode != ColumnView) {
-        // Give the view the ability to auto-expand its directories on hovering
-        // (the column view takes care about this itself). If the details view
-        // uses expandable folders, the auto-expanding should be used always.
-        FolderExpander* folderExpander = new FolderExpander(view, m_viewAccessor.proxyModel());
-        folderExpander->setEnabled(m_viewAccessor.hasExpandableFolders());
-        connect(folderExpander, SIGNAL(enterDir(const QModelIndex&)),
-                m_controller, SLOT(triggerItem(const QModelIndex&)));
-
-    }
-    else {
-        // Listen out for requests to delete the current column.
-        connect(m_viewAccessor.columnsContainer(), SIGNAL(requestColumnDeletion(QAbstractItemView*)),
-                this, SLOT(deleteWhenNotDragSource(QAbstractItemView*)));
-    }*/
-
     m_controller->setItemView(view);
+    connect(m_controller, SIGNAL(selectionChanged()),
+            this, SLOT(emitDelayedSelectionChangedSignal()));
 
     // When changing the view mode, the selection is lost due to reinstantiating
     // a new item view with a custom selection model. Pass the ownership of the
@@ -1336,8 +1283,6 @@ void DolphinView::createView()
     }
     m_selectionModel->setParent(this);
 
-    connect(m_controller, SIGNAL(selectionChanged()),
-            this, SLOT(emitDelayedSelectionChangedSignal()));
     connect(view->verticalScrollBar(), SIGNAL(valueChanged(int)),
             this, SLOT(emitContentsMoved()));
     connect(view->horizontalScrollBar(), SIGNAL(valueChanged(int)),
@@ -1365,10 +1310,6 @@ void DolphinView::deleteView()
         m_controller->disconnect(view);
         view->disconnect();
 
-        // TODO: move this code into ViewAccessor::deleteView()
-        deleteWhenNotDragSource(view);
-        view = 0;
-
         m_viewAccessor.deleteView();
     }
 }
@@ -1417,10 +1358,17 @@ DolphinView::ViewAccessor::ViewAccessor(DolphinSortFilterProxyModel* proxyModel)
     m_iconsView(0),
     m_detailsView(0),
     m_columnsContainer(0),
-    m_proxyModel(proxyModel)
+    m_proxyModel(proxyModel),
+    m_dragSource(0)
 {
 }
 
+DolphinView::ViewAccessor::~ViewAccessor()
+{
+    delete m_dragSource;
+    m_dragSource = 0;
+}
+
 void DolphinView::ViewAccessor::createView(QWidget* parent,
                                            DolphinController* controller,
                                            Mode mode)
@@ -1447,9 +1395,25 @@ void DolphinView::ViewAccessor::createView(QWidget* parent,
 
 void DolphinView::ViewAccessor::deleteView()
 {
-    // TODO: Move the deleteWhenNotDragSource() code into the view
-    // accessor, so that creating and deleting is fully done by
-    // the view accessor.
+    QAbstractItemView* view = itemView();
+    if (view != 0) {
+        if (DragAndDropHelper::instance().isDragSource(view)) {
+            // The view is a drag source (the feature "Open folders
+            // during drag operations" is used). Deleting the view
+            // during an ongoing drag operation is not allowed, so
+            // this will postponed.
+            if (m_dragSource != 0) {
+                // the old stored view is obviously not the drag source anymore
+                m_dragSource->deleteLater();
+                m_dragSource = 0;
+            }
+            view->hide();
+            m_dragSource = view;
+        } else {
+            view->deleteLater();
+        }
+    }
+
     m_iconsView = 0;
     m_detailsView = 0;
 
@@ -1505,13 +1469,6 @@ bool DolphinView::ViewAccessor::supportsCategorizedSorting() const
     return m_iconsView != 0;
 }
 
-bool DolphinView::ViewAccessor::hasExpandableFolders() const
-{
-    const DolphinSettings& settings = DolphinSettings::instance();
-    return settings.generalSettings()->autoExpandFolders() ||
-           ((m_detailsView != 0) && settings.detailsModeSettings()->expandableFolders());
-}
-
 bool DolphinView::ViewAccessor::itemsExpandable() const
 {
     return (m_detailsView != 0) && m_detailsView->itemsExpandable();
@@ -1524,7 +1481,6 @@ bool DolphinView::ViewAccessor::reloadOnAdditionalInfoChange() const
     return m_detailsView != 0;
 }
 
-
 DolphinModel* DolphinView::ViewAccessor::dirModel() const
 {
     return static_cast<DolphinModel*>(proxyModel()->sourceModel());
index 822eb52b01281de855946db981ae0969984808f5..57bf5d2f9253dc569b928e46b76563895763976f 100644 (file)
@@ -674,13 +674,6 @@ private slots:
      */
     void slotRefreshItems();
 
-    /**
-     * If \a view can be positively identified as not being the source for the
-     * current drag operation, deleteLater() it immediately.  Else stores
-     * it for later deletion.
-     */
-    void deleteWhenNotDragSource(QAbstractItemView* view);
-
     /**
      * Observes the item with the URL \a url. As soon as the directory
      * model indicates that the item is available, the item will
@@ -761,6 +754,7 @@ private:
     {
     public:
         ViewAccessor(DolphinSortFilterProxyModel* proxyModel);
+        ~ViewAccessor();
 
         void createView(QWidget* parent, DolphinController* controller, Mode mode);
         void deleteView();
@@ -784,7 +778,6 @@ private:
         KUrl rootUrl() const;
 
         bool supportsCategorizedSorting() const;
-        bool hasExpandableFolders() const;
         bool itemsExpandable() const;
 
         /**
@@ -803,6 +796,7 @@ private:
         DolphinDetailsView* m_detailsView;
         DolphinColumnViewContainer* m_columnsContainer;
         DolphinSortFilterProxyModel* m_proxyModel;
+        QAbstractItemView* m_dragSource;
     };
 
     bool m_active : 1;
@@ -836,8 +830,6 @@ private:
      * slotDirListerCompleted().
      */
     QSet<QString> m_newFileNames;
-
-    QAbstractItemView* m_expandedDragSource; // TODO: move to ViewAccessor
 };
 
 /// Allow using DolphinView::Mode in QVariant
index 7fe775944e4fc5ae99db87d27fa68f1fb8b73e1c..a2dfb137b29a2bfdc4c4ab45f7c2f5b807408e94 100644 (file)
  ***************************************************************************/
 
 #include "folderexpander.h"
-#include "dolphinview.h"
-
-#include "settings/dolphinsettings.h"
-#include "dolphin_generalsettings.h"
 
 #include <QtCore/QTimer>
 #include <QtGui/QAbstractItemView>
@@ -43,20 +39,15 @@ FolderExpander::FolderExpander(QAbstractItemView *view, QSortFilterProxyModel *p
     m_autoExpandTriggerTimer(0),
     m_autoExpandPos()
 {
-    // Validation.  If these fail, the event filter is never
-    // installed on the view and the FolderExpander is inactive.
     if (m_view == 0)  {
-        kWarning() << "Need a view!";
-        return; // Not valid.
+        return;
     }
     if (m_proxyModel == 0)  {
-        kWarning() << "Need a proxyModel!";
-        return; // Not valid.
+        return;
     }
-    KDirModel *m_dirModel = qobject_cast< KDirModel* >( m_proxyModel->sourceModel() );
+    KDirModel *m_dirModel = qobject_cast<KDirModel*>(m_proxyModel->sourceModel());
     if (m_dirModel == 0) {
-        kWarning() << "Expected m_proxyModel's sourceModel() to be a KDirModel!";
-        return; // Not valid.
+        return;
     }
 
     // Initialise auto-expand timer.
index b8606d65bfff1aeb2ab7fea2499d708c431d008d..a6555ae0be792b56f9b8701583cc41895ef9ee41 100644 (file)
@@ -24,6 +24,7 @@
 #include "dolphinsortfilterproxymodel.h"
 #include "dolphinview.h"
 #include "dolphinviewautoscroller.h"
+#include "folderexpander.h"
 #include "selectionmanager.h"
 #include "settings/dolphinsettings.h"
 #include "tooltips/tooltipmanager.h"
@@ -114,6 +115,15 @@ ViewExtensionsFactory::ViewExtensionsFactory(QAbstractItemView* view,
     connect(view->selectionModel(), SIGNAL(selectionChanged(const QItemSelection&, const QItemSelection&)),
             controller, SLOT(emitSelectionChanged()));
 
+    // Give the view the ability to auto-expand its directories on hovering
+    // (the column view takes care about this itself). If the details view
+    // uses expandable folders, the auto-expanding should be used always.
+    m_folderExpander = new FolderExpander(view, proxyModel());
+    m_folderExpander->setEnabled(settings->autoExpandFolders());
+    connect(m_folderExpander, SIGNAL(enterDir(const QModelIndex&)),
+            controller, SLOT(triggerItem(const QModelIndex&)));
+
+    // react on namefilter changes
     connect(controller, SIGNAL(nameFilterChanged(const QString&)),
             this, SLOT(slotNameFilterChanged(const QString&)));
 
@@ -134,6 +144,16 @@ DolphinFileItemDelegate* ViewExtensionsFactory::fileItemDelegate() const
     return m_fileItemDelegate;
 }
 
+void ViewExtensionsFactory::setAutoFolderExpandingEnabled(bool enabled)
+{
+    m_folderExpander->setEnabled(enabled);
+}
+
+bool ViewExtensionsFactory::autoFolderExpandingEnabled() const
+{
+    return m_folderExpander->enabled();
+}
+
 bool ViewExtensionsFactory::eventFilter(QObject* watched, QEvent* event)
 {
     Q_UNUSED(watched);
index ddc1cf581c1519a4f573145c3197164c747fcc7b..9187c10e3aa2c88872bb6d741164d1c8bcf4944e 100644 (file)
@@ -29,6 +29,7 @@ class DolphinFileItemDelegate;
 class DolphinSortFilterProxyModel;
 class DolphinViewAutoScroller;
 class KFilePreviewGenerator;
+class FolderExpander;
 class QModelIndex;
 class SelectionManager;
 class ToolTipManager;
@@ -62,6 +63,13 @@ public:
 
     DolphinFileItemDelegate* fileItemDelegate() const;
 
+    /**
+     * Enables the automatically expanding of a folder when dragging
+     * items above the folder.
+     */
+    void setAutoFolderExpandingEnabled(bool enabled);
+    bool autoFolderExpandingEnabled() const;
+
 protected:
     virtual bool eventFilter(QObject* watched, QEvent* event);
 
@@ -89,6 +97,7 @@ private:
     DolphinViewAutoScroller* m_autoScroller;
     DolphinFileItemDelegate* m_fileItemDelegate;   
     VersionControlObserver* m_versionControlObserver;
+    FolderExpander* m_folderExpander;
 };
 
 #endif