]> cloud.milkyroute.net Git - dolphin.git/blobdiff - src/dolphinview.cpp
assure that the autoresizing still works in combination with the "automatically expan...
[dolphin.git] / src / dolphinview.cpp
index 2c4efca602b31a6fc5ce7cfa77af3604f6c7d0b5..3e1cddfdac683f7445a24e2aa08cad4b6a6af3fd 100644 (file)
@@ -31,7 +31,6 @@
 #include <kactioncollection.h>
 #include <kcolorscheme.h>
 #include <kdirlister.h>
-#include <kfileitemdelegate.h>
 #include <kfilepreviewgenerator.h>
 #include <kiconeffect.h>
 #include <klocale.h>
 #include <ktoggleaction.h>
 #include <kurl.h>
 
-#include "dolphindropcontroller.h"
 #include "dolphinmodel.h"
 #include "dolphincolumnview.h"
 #include "dolphincontroller.h"
+#include "dolphinfileitemdelegate.h"
 #include "dolphinsortfilterproxymodel.h"
 #include "dolphindetailsview.h"
 #include "dolphin_detailsmodesettings.h"
 #include "dolphiniconsview.h"
 #include "dolphinsettings.h"
 #include "dolphin_generalsettings.h"
+#include "draganddrophelper.h"
 #include "folderexpander.h"
 #include "renamedialog.h"
 #include "tooltipmanager.h"
@@ -90,7 +90,8 @@ DolphinView::DolphinView(QWidget* parent,
     m_previewGenerator(0),
     m_toolTipManager(0),
     m_rootUrl(),
-    m_currentItemUrl()
+    m_currentItemUrl(),
+    m_expandedViews()
 {
     m_topLayout = new QVBoxLayout(this);
     m_topLayout->setSpacing(0);
@@ -126,7 +127,7 @@ DolphinView::DolphinView(QWidget* parent,
             this, SLOT(clearHoverInformation()));
 
     connect(m_dirLister, SIGNAL(redirection(KUrl, KUrl)),
-            this, SLOT(slotRedirection(KUrl, KUrl)));
+            this, SIGNAL(redirection(KUrl, KUrl)));
     connect(m_dirLister, SIGNAL(completed()),
             this, SLOT(restoreCurrentItem()));
 
@@ -136,6 +137,7 @@ DolphinView::DolphinView(QWidget* parent,
 
 DolphinView::~DolphinView()
 {
+    deleteExpandedViews();
 }
 
 const KUrl& DolphinView::url() const
@@ -439,6 +441,7 @@ void DolphinView::reload()
 void DolphinView::refresh()
 {
     const bool oldActivationState = m_active;
+    const int oldZoomLevel = m_controller->zoomLevel();
     m_active = true;
 
     createView();
@@ -446,6 +449,7 @@ void DolphinView::refresh()
     reload();
 
     setActive(oldActivationState);
+    updateZoomLevel(oldZoomLevel);
 }
 
 void DolphinView::updateView(const KUrl& url, const KUrl& rootUrl)
@@ -808,8 +812,25 @@ void DolphinView::wheelEvent(QWheelEvent* event)
 
 bool DolphinView::eventFilter(QObject* watched, QEvent* event)
 {
-    if ((watched == itemView()) && (event->type() == QEvent::FocusIn)) {
-        m_controller->requestActivation();
+    switch (event->type()) {
+    case QEvent::FocusIn:
+        if (watched == itemView()) {
+            m_controller->requestActivation();
+        }
+        break;
+        
+    case QEvent::MouseButtonPress:
+        if ((watched == itemView()->viewport()) && (m_expandedViews.count() > 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.
+            deleteExpandedViews();
+        }
+        break;
+    default:
+        break;
     }
 
     return QWidget::eventFilter(watched, event);
@@ -871,7 +892,7 @@ void DolphinView::dropUrls(const KFileItem& destItem,
                            const KUrl& destPath,
                            QDropEvent* event)
 {
-    DolphinDropController::dropUrls(destItem, destPath, event, this);
+    DragAndDropHelper::dropUrls(destItem, destPath, event, this);
 }
 
 void DolphinView::updateSorting(DolphinView::Sorting sorting)
@@ -1027,13 +1048,6 @@ void DolphinView::slotDeleteFileFinished(KJob* job)
     }
 }
 
-void DolphinView::slotRedirection(const KUrl& oldUrl, const KUrl& newUrl)
-{
-    if (oldUrl == m_controller->url()) {
-        m_controller->setUrl(newUrl);
-    }
-}
-
 void DolphinView::slotRequestUrlChange(const KUrl& url)
 {
     emit requestUrlChange(url);
@@ -1054,6 +1068,16 @@ void DolphinView::restoreCurrentItem()
     }
 }
 
+void DolphinView::enterDir(const QModelIndex& index, QAbstractItemView* view)
+{
+    // Deleting a view that is the root of a drag operation is not allowed, otherwise
+    // the dragging gets automatically cancelled by Qt. So before entering a new
+    // directory, the current view is remembered in m_expandedViews and deleted
+    // later when the drag operation has been finished (see DolphinView::eventFilter()).
+    m_expandedViews.append(view);
+    m_controller->triggerItem(index);
+}
+
 void DolphinView::loadDirectory(const KUrl& url, bool reload)
 {
     if (!url.isValid()) {
@@ -1192,6 +1216,7 @@ void DolphinView::createView()
 
     Q_ASSERT(view != 0);
     view->installEventFilter(this);
+    view->viewport()->installEventFilter(this);
 
     if (m_mode != ColumnView) {
         // Give the view the ability to auto-expand its directories on hovering
@@ -1203,14 +1228,15 @@ void DolphinView::createView()
 
         FolderExpander* folderExpander = new FolderExpander(view, m_proxyModel);
         folderExpander->setEnabled(enabled);
-        connect(folderExpander, SIGNAL(enterDir(const QModelIndex&)),
-                m_controller, SLOT(triggerItem(const QModelIndex&)));
+        connect(folderExpander, SIGNAL(enterDir(const QModelIndex&, QAbstractItemView*)),
+                this, SLOT(enterDir(const QModelIndex&, QAbstractItemView*)));
     }
 
     m_controller->setItemView(view);
 
-    m_fileItemDelegate = new KFileItemDelegate(view);
+    m_fileItemDelegate = new DolphinFileItemDelegate(view);
     m_fileItemDelegate->setShowToolTipWhenElided(false);
+    m_fileItemDelegate->setMinimizedNameColumn(m_mode == DetailsView);
     view->setItemDelegate(m_fileItemDelegate);
 
     view->setModel(m_proxyModel);
@@ -1231,6 +1257,8 @@ void DolphinView::createView()
 
     if (DolphinSettings::instance().generalSettings()->showToolTips()) {
         m_toolTipManager = new ToolTipManager(view, m_proxyModel);
+        connect(m_controller, SIGNAL(hideToolTip()),
+                m_toolTipManager, SLOT(hideTip()));
     }
 
     m_topLayout->insertWidget(1, view);
@@ -1255,8 +1283,21 @@ void DolphinView::deleteView()
 
         m_topLayout->removeWidget(view);
         view->close();
-        view->deleteLater();
+        
+        bool deleteView = true;
+        foreach (const QAbstractItemView* expandedView, m_expandedViews) {
+            if (view == expandedView) {
+                // the current view got already expanded and must stay alive
+                // until the dragging has been completed
+                deleteView = false;
+                break;
+            }
+        }
+        if (deleteView) {
+            view->deleteLater();
+        }
         view = 0;
+        
         m_iconsView = 0;
         m_detailsView = 0;
         m_columnView = 0;
@@ -1327,6 +1368,17 @@ KUrl::List DolphinView::simplifiedSelectedUrls() const
     return list;
 }
 
+void DolphinView::deleteExpandedViews()
+{
+    const QAbstractItemView* view = itemView();
+    foreach (QAbstractItemView* expandedView, m_expandedViews) {
+        if (expandedView != view) {
+            expandedView->deleteLater();
+        }
+    }
+    m_expandedViews.clear();
+}
+
 bool DolphinView::itemsExpandable() const
 {
     return (m_detailsView != 0) && m_detailsView->itemsExpandable();