]> cloud.milkyroute.net Git - dolphin.git/blobdiff - src/dolphiniconsview.cpp
New and powerful KListView. Still pending class renaming. There are two
[dolphin.git] / src / dolphiniconsview.cpp
index 73b6313909de27ac6a721530af99c26d1369a6a7..cf5be61ef5d9042c3348a3fd2c3085554e8c7102 100644 (file)
 
 #include "dolphin_iconsmodesettings.h"
 
-#include <kdirmodel.h>
-#include <kfileitem.h>
-#include <kfileitemdelegate.h>
-
-#include <QtGui/QAbstractProxyModel>
-#include <QtCore/QPoint>
+#include <QAbstractProxyModel>
+#include <QApplication>
+#include <QPainter>
+#include <QPoint>
 
 DolphinIconsView::DolphinIconsView(QWidget* parent, DolphinController* controller) :
     KListView(parent),
-    m_controller(controller)
+    m_controller(controller),
+    m_dragging(false)
 {
     Q_ASSERT(controller != 0);
     setViewMode(QListView::IconMode);
     setResizeMode(QListView::Adjust);
-
+    setSpacing(10);
     setMouseTracking(true);
     viewport()->setAttribute(Qt::WA_Hover);
 
@@ -105,10 +104,17 @@ void DolphinIconsView::contextMenuEvent(QContextMenuEvent* event)
     m_controller->triggerContextMenuRequest(event->pos());
 }
 
-void DolphinIconsView::mouseReleaseEvent(QMouseEvent* event)
+void DolphinIconsView::mousePressEvent(QMouseEvent* event)
 {
-    KListView::mouseReleaseEvent(event);
     m_controller->triggerActivation();
+    if (!indexAt(event->pos()).isValid()) {
+        const Qt::KeyboardModifiers modifier = QApplication::keyboardModifiers();
+        if (!(modifier & Qt::ShiftModifier) && !(modifier & Qt::ControlModifier)) {
+            clearSelection();
+        }
+    }
+
+    KListView::mousePressEvent(event);
 }
 
 void DolphinIconsView::dragEnterEvent(QDragEnterEvent* event)
@@ -116,6 +122,27 @@ void DolphinIconsView::dragEnterEvent(QDragEnterEvent* event)
     if (event->mimeData()->hasUrls()) {
         event->acceptProposedAction();
     }
+    m_dragging = true;
+}
+
+void DolphinIconsView::dragLeaveEvent(QDragLeaveEvent* event)
+{
+    KListView::dragLeaveEvent(event);
+
+    // TODO: remove this code when the issue #160611 is solved in Qt 4.4
+    m_dragging = false;
+    setDirtyRegion(m_dropRect);
+}
+
+void DolphinIconsView::dragMoveEvent(QDragMoveEvent* event)
+{
+    KListView::dragMoveEvent(event);
+
+    // TODO: remove this code when the issue #160611 is solved in Qt 4.4
+    const QModelIndex index = indexAt(event->pos());
+    setDirtyRegion(m_dropRect);
+    m_dropRect = visualRect(index);
+    setDirtyRegion(m_dropRect);
 }
 
 void DolphinIconsView::dropEvent(QDropEvent* event)
@@ -128,6 +155,18 @@ void DolphinIconsView::dropEvent(QDropEvent* event)
         event->acceptProposedAction();
     }
     KListView::dropEvent(event);
+    m_dragging = false;
+}
+
+void DolphinIconsView::paintEvent(QPaintEvent* event)
+{
+    KListView::paintEvent(event);
+
+    // TODO: remove this code when the issue #160611 is solved in Qt 4.4
+    if (m_dragging) {
+        const QBrush& brush = m_viewOptions.palette.brush(QPalette::Normal, QPalette::Highlight);
+        DolphinController::drawHoverIndication(viewport(), m_dropRect, brush);
+    }
 }
 
 void DolphinIconsView::slotShowPreviewChanged(bool showPreview)