]> cloud.milkyroute.net Git - dolphin.git/blobdiff - src/sidebartreeview.cpp
reset the URL candidate if a resizing is done
[dolphin.git] / src / sidebartreeview.cpp
index 52f207a78f6d9a9cda286b9b68d01e31a8b8714f..d580cbf6de2c453f5775fa21edcbfb802f15902c 100644 (file)
@@ -21,6 +21,7 @@
 
 #include "dolphincontroller.h"
 #include "dolphinmodel.h"
+#include "draganddrophelper.h"
 
 #include <kfileitemdelegate.h>
 #include <QKeyEvent>
@@ -41,8 +42,15 @@ SidebarTreeView::SidebarTreeView(QWidget* parent) :
     setDragDropMode(QAbstractItemView::DragDrop);
     setDropIndicatorShown(false);
     setAutoExpandDelay(300);
+
+// TODO: Remove this check when 4.3.2 is released and KDE requires it... this
+//       check avoids a division by zero happening on versions before 4.3.1.
+//       Right now KDE in theory can be shipped with Qt 4.3.0 and above.
+//       ereslibre
+#if (QT_VERSION >= QT_VERSION_CHECK(4, 3, 2) || defined(QT_KDE_QT_COPY))
     setVerticalScrollMode(QListView::ScrollPerPixel);
     setHorizontalScrollMode(QListView::ScrollPerPixel);
+#endif
 
     viewport()->setAttribute(Qt::WA_Hover);
 
@@ -73,21 +81,37 @@ bool SidebarTreeView::event(QEvent* event)
         header()->hide();
     }
     else if (event->type() == QEvent::UpdateRequest) {
+        // TODO: Remove this check when 4.3.2 is released and KDE requires it... this
+        //       check avoids a division by zero happening on versions before 4.3.1.
+        //       Right now KDE in theory can be shipped with Qt 4.3.0 and above.
+        //       ereslibre
+#if (QT_VERSION >= QT_VERSION_CHECK(4, 3, 2) || defined(QT_KDE_QT_COPY))
         // a wheel movement will scroll 1 item
         if (model()->rowCount() > 0) {
             verticalScrollBar()->setSingleStep(sizeHintForRow(0) / 3);
         }
+#endif
+    }
+    else if (event->type() == QEvent::MetaCall) {
+        resizeColumnToContents(DolphinModel::Name);
     }
 
     return QTreeView::event(event);
 }
 
+void SidebarTreeView::startDrag(Qt::DropActions supportedActions)
+{
+    DragAndDropHelper::startDrag(this, supportedActions);
+}
+
 void SidebarTreeView::dragEnterEvent(QDragEnterEvent* event)
 {
+    QTreeView::dragEnterEvent(event);
+
     if (event->mimeData()->hasUrls()) {
         event->acceptProposedAction();
     }
-    QTreeView::dragEnterEvent(event);
+
     m_dragging = true;
 }
 
@@ -109,6 +133,11 @@ void SidebarTreeView::dragMoveEvent(QDragMoveEvent* event)
     setDirtyRegion(m_dropRect);
     m_dropRect = visualRect(index);
     setDirtyRegion(m_dropRect);
+
+    if (event->mimeData()->hasUrls()) {
+        // accept url drops, independently from the destination item
+        event->acceptProposedAction();
+    }
 }
 
 void SidebarTreeView::dropEvent(QDropEvent* event)
@@ -133,7 +162,7 @@ void SidebarTreeView::paintEvent(QPaintEvent* event)
     // TODO: remove this code when the issue #160611 is solved in Qt 4.4
     if (m_dragging) {
         const QBrush& brush = palette().brush(QPalette::Normal, QPalette::Highlight);
-        DolphinController::drawHoverIndication(viewport(), m_dropRect, brush);
+        DragAndDropHelper::drawHoverIndication(this, m_dropRect, brush);
     }
 }