]> cloud.milkyroute.net Git - dolphin.git/blobdiff - src/panels/folders/folderspanel.cpp
Fix style-issues in items when not using Oxygen
[dolphin.git] / src / panels / folders / folderspanel.cpp
index 484d8c2ed4f19180f13727c40ec6dd336d7b0b1c..bb2198d487ea0ee4d2697cfdfda19955527ffd9b 100644 (file)
 
 #include <QApplication>
 #include <QBoxLayout>
+#include <QDropEvent>
+#include <QGraphicsSceneDragDropEvent>
 #include <QGraphicsView>
 #include <QPropertyAnimation>
 #include <QTimer>
 
+#include <views/draganddrophelper.h>
 #include <views/renamedialog.h>
 
 #include <KDebug>
@@ -73,8 +76,7 @@ void FoldersPanel::setHiddenFilesShown(bool show)
     if (m_dirLister) {
         KFileItemModel* model = fileItemModel();
         const QSet<KUrl> expandedUrls = model->expandedUrls();
-        m_dirLister->setShowingDotFiles(show);
-        m_dirLister->openUrl(m_dirLister->url(), KDirLister::Reload);
+        model->setShowHiddenFiles(show);
         model->setExpanded(expandedUrls);
     }
 }
@@ -86,7 +88,7 @@ bool FoldersPanel::hiddenFilesShown() const
 
 void FoldersPanel::setAutoScrolling(bool enable)
 {
-    //m_treeView->setAutoHorizontalScroll(enable);
+    // TODO: Not supported yet in Dolphin 2.0
     FoldersPanelSettings::setAutoScrolling(enable);
 }
 
@@ -143,7 +145,6 @@ void FoldersPanel::showEvent(QShowEvent* event)
         m_dirLister->setMainWindow(window());
         m_dirLister->setDelayedMimeTypes(true);
         m_dirLister->setAutoErrorHandlingEnabled(false, this);
-        m_dirLister->setShowingDotFiles(FoldersPanelSettings::hiddenFilesShown());
 
         KFileItemListView* view  = new KFileItemListView();
         view->setWidgetCreator(new KItemListWidgetCreator<KFileItemListWidget>());
@@ -162,6 +163,7 @@ void FoldersPanel::showEvent(QShowEvent* event)
         view->setOpacity(0);
 
         KFileItemModel* model = new KFileItemModel(m_dirLister, this);
+        model->setShowHiddenFiles(FoldersPanelSettings::hiddenFilesShown());
         // Use a QueuedConnection to give the view the possibility to react first on the
         // finished loading.
         connect(model, SIGNAL(loadingCompleted()), this, SLOT(slotLoadingCompleted()), Qt::QueuedConnection);
@@ -171,11 +173,13 @@ void FoldersPanel::showEvent(QShowEvent* event)
         m_controller->setView(view);
         m_controller->setModel(model);
         m_controller->setSelectionBehavior(KItemListController::SingleSelection);
+        m_controller->setAutoActivationDelay(750);
 
         connect(m_controller, SIGNAL(itemActivated(int)), this, SLOT(slotItemActivated(int)));
         connect(m_controller, SIGNAL(itemMiddleClicked(int)), this, SLOT(slotItemMiddleClicked(int)));
         connect(m_controller, SIGNAL(itemContextMenuRequested(int,QPointF)), this, SLOT(slotItemContextMenuRequested(int,QPointF)));
         connect(m_controller, SIGNAL(viewContextMenuRequested(QPointF)), this, SLOT(slotViewContextMenuRequested(QPointF)));
+        connect(m_controller, SIGNAL(itemDropEvent(int,QGraphicsSceneDragDropEvent*)), this, SLOT(slotItemDropEvent(int,QGraphicsSceneDragDropEvent*)));
 
         // TODO: Check whether it makes sense to make an explicit API for KItemListContainer
         // to make the background transparent.
@@ -207,7 +211,6 @@ void FoldersPanel::keyPressEvent(QKeyEvent* event)
     const int key = event->key();
     if ((key == Qt::Key_Enter) || (key == Qt::Key_Return)) {
         event->accept();
-        //updateActiveView(m_treeView->currentIndex());
     } else {
         Panel::keyPressEvent(event);
     }
@@ -253,6 +256,29 @@ void FoldersPanel::slotViewContextMenuRequested(const QPointF& pos)
     }
 }
 
+void FoldersPanel::slotItemDropEvent(int index, QGraphicsSceneDragDropEvent* event)
+{
+    if (index >= 0) {
+        KFileItemModel* model = fileItemModel();
+        KFileItem destItem = model->fileItem(index);
+        if (destItem.isNull()) {
+            destItem = model->rootItem();
+            if (destItem.isNull()) {
+                kWarning() << "No destination item available for drop operation.";
+                return;
+            }
+        }
+
+        QDropEvent dropEvent(event->pos().toPoint(),
+                             event->possibleActions(),
+                             event->mimeData(),
+                             event->buttons(),
+                             event->modifiers());
+
+        DragAndDropHelper::dropUrls(destItem, &dropEvent);
+    }
+}
+
 void FoldersPanel::slotLoadingCompleted()
 {
     if (m_controller->view()->opacity() == 0) {
@@ -274,22 +300,6 @@ void FoldersPanel::slotLoadingCompleted()
     m_updateCurrentItem = false;
 }
 
-void FoldersPanel::slotHorizontalScrollBarMoved(int value)
-{
-    Q_UNUSED(value);
-    // Disable the auto-scrolling until the vertical scrollbar has
-    // been moved by the user.
-    //m_treeView->setAutoHorizontalScroll(false);
-}
-
-void FoldersPanel::slotVerticalScrollBarMoved(int value)
-{
-    Q_UNUSED(value);
-    // Enable the auto-scrolling again (it might have been disabled by
-    // moving the horizontal scrollbar).
-    //m_treeView->setAutoHorizontalScroll(FoldersPanelSettings::autoScrolling());
-}
-
 void FoldersPanel::startFadeInAnimation()
 {
     QPropertyAnimation* anim = new QPropertyAnimation(m_controller->view(), "opacity", this);