]> cloud.milkyroute.net Git - dolphin.git/blobdiff - src/dolphiniconsview.cpp
fixed some activation issues in combination with split views
[dolphin.git] / src / dolphiniconsview.cpp
index c80a58b6b3dd4629c7fe9f71c03db46aad929914..d21ffba32752ebfd42b8257a7a5aab67125dcd78 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);
@@ -86,6 +85,7 @@ DolphinIconsView::DolphinIconsView(QWidget* parent, DolphinController* controlle
     } else {
         setFlow(QListView::TopToBottom);
         m_viewOptions.decorationPosition = QStyleOptionViewItem::Left;
+        m_viewOptions.displayAlignment = Qt::AlignLeft | Qt::AlignVCenter;
     }
 }
 
@@ -104,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)
@@ -115,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)
@@ -127,6 +155,24 @@ void DolphinIconsView::dropEvent(QDropEvent* event)
         event->acceptProposedAction();
     }
     KListView::dropEvent(event);
+    m_dragging = false;
+}
+
+void DolphinIconsView::paintEvent(QPaintEvent* event)
+{
+    KListView::paintEvent(event);
+
+    if (m_dragging) {
+        // TODO: remove this code when the issue #160611 is solved in Qt 4.4
+        QPainter painter(viewport());
+        painter.save();
+        QBrush brush(m_viewOptions.palette.brush(QPalette::Normal, QPalette::Highlight));
+        QColor color = brush.color();
+        color.setAlpha(64);
+        brush.setColor(color);
+        painter.fillRect(m_dropRect, brush);
+        painter.restore();
+    }
 }
 
 void DolphinIconsView::slotShowPreviewChanged(bool showPreview)
@@ -267,10 +313,14 @@ void DolphinIconsView::updateGridSize(bool showPreview, bool showAdditionalInfo)
         itemHeight += m_viewOptions.font.pointSize() * 2;
     }
 
-    // The decoration width indirectly defines the maximum
-    // width for the text wrapping. To use the maximum item width
-    // for text wrapping, it is used as decoration width.
-    m_viewOptions.decorationSize = QSize(itemWidth, size);
+    if (settings->arrangement() == QListView::TopToBottom) {
+        // The decoration width indirectly defines the maximum
+        // width for the text wrapping. To use the maximum item width
+        // for text wrapping, it is used as decoration width.
+        m_viewOptions.decorationSize = QSize(itemWidth, size);
+    } else {
+        m_viewOptions.decorationSize = QSize(size, size);
+    }
 
     const int spacing = settings->gridSpacing();
     setGridSize(QSize(itemWidth + spacing, itemHeight + spacing));