]> cloud.milkyroute.net Git - dolphin.git/blobdiff - src/dolphincolumnviewcontainer.cpp
get_servicemenu added to dolphinpart
[dolphin.git] / src / dolphincolumnviewcontainer.cpp
index ca9cfe0f1035faa3f60dd79e9798361db5475e51..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
@@ -83,12 +85,12 @@ QAbstractItemView* DolphinColumnViewContainer::activeColumn() const
     return m_columns[m_index];
 }
 
-bool DolphinColumnViewContainer::showColumn(const KUrl& url)
+void DolphinColumnViewContainer::showColumn(const KUrl& url)
 {
     if (!rootUrl().isParentOf(url)) {
         removeAllColumns();
         m_columns[0]->setUrl(url);
-        return false;
+        return;
     }
 
     int columnIndex = 0;
@@ -97,7 +99,7 @@ bool DolphinColumnViewContainer::showColumn(const KUrl& url)
             // the column represents already the requested URL, hence activate it
             requestActivation(column);
             layoutColumns();
-            return false;
+            return;
         } else if (!column->url().isParentOf(url)) {
             // the column is no parent of the requested URL, hence
             // just delete all remaining columns
@@ -168,8 +170,6 @@ bool DolphinColumnViewContainer::showColumn(const KUrl& url)
     m_index = columnIndex;
     m_columns[m_index]->setActive(true);
     assureVisibleActiveColumn();
-
-    return true;
 }
 
 void DolphinColumnViewContainer::mousePressEvent(QMouseEvent* event)
@@ -178,6 +178,15 @@ void DolphinColumnViewContainer::mousePressEvent(QMouseEvent* event)
     QScrollArea::mousePressEvent(event);
 }
 
+void DolphinColumnViewContainer::keyPressEvent(QKeyEvent* event)
+{
+    if (event->key() == Qt::Key_Left) {
+        setActiveColumnIndex(m_index - 1);
+    } else {
+        QScrollArea::keyPressEvent(event);
+    }
+}
+
 void DolphinColumnViewContainer::resizeEvent(QResizeEvent* event)
 {
     QScrollArea::resizeEvent(event);
@@ -226,7 +235,7 @@ void DolphinColumnViewContainer::updateColumnsBackground(bool active)
 
 void DolphinColumnViewContainer::setActiveColumnIndex(int index)
 {
-    if (m_index == index) {
+    if ((m_index == index) || (index < 0) || (index >= m_columns.count())) {
         return;
     }
 
@@ -351,18 +360,38 @@ 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();
     }
 }