]> cloud.milkyroute.net Git - dolphin.git/blobdiff - src/dolphiniconsview.cpp
there's no need having 2-liners inside their own method when this method is only...
[dolphin.git] / src / dolphiniconsview.cpp
index 95ea011b03aa83a2514ce3c3f6b069398dba0929..fbb5f31c6f9c2e8d23ab8ffbdb3e6543b6328ffd 100644 (file)
@@ -23,6 +23,7 @@
 #include "dolphincontroller.h"
 #include "dolphinsettings.h"
 #include "dolphin_iconsmodesettings.h"
+#include "draganddrophelper.h"
 
 #include <kcategorizedsortfilterproxymodel.h>
 #include <kdialog.h>
@@ -45,7 +46,10 @@ DolphinIconsView::DolphinIconsView(QWidget* parent, DolphinController* controlle
     setViewMode(QListView::IconMode);
     setResizeMode(QListView::Adjust);
     setSpacing(KDialog::spacingHint());
-    setMovement(QListView::Snap);
+    setMovement(QListView::Static);
+    setDragEnabled(true);
+    viewport()->setAcceptDrops(true);
+
     setMouseTracking(true);
     viewport()->setAttribute(Qt::WA_Hover);
 
@@ -140,12 +144,12 @@ QRect DolphinIconsView::visualRect(const QModelIndex& index) const
 
     KCategorizedSortFilterProxyModel* proxyModel = dynamic_cast<KCategorizedSortFilterProxyModel*>(model());
     if (leftToRightFlow && !proxyModel->isCategorizedModel()) {
-        // TODO: This workaround bypasses a layout issue in QListView::visualRect(), where
-        // the horizontal position of items might get calculated in a wrong manner when the item
-        // name is too long. I'll try create a patch for Qt but as Dolphin must also work with
-        // Qt 4.3.0 this workaround must get applied at least for KDE 4.0.
+        // TODO: QListView::visualRect() calculates a wrong position of the items under
+        // certain circumstances (e. g. if the text is too long). This issue is bypassed
+        // by the following code (I'll try create a patch for Qt but as Dolphin must also work with
+        // Qt 4.3.0 this workaround must get applied at least for KDE 4.0).
         const IconsModeSettings* settings = DolphinSettings::instance().iconsModeSettings();
-        const int margin = settings->gridSpacing() / 2;
+        const int margin = settings->gridSpacing();
         const int gridWidth = gridSize().width();
         const int gridIndex = (itemRect.left() - margin + 1) / gridWidth;
         itemRect.moveLeft(gridIndex * gridWidth + margin);
@@ -162,9 +166,7 @@ QStyleOptionViewItem DolphinIconsView::viewOptions() const
 void DolphinIconsView::contextMenuEvent(QContextMenuEvent* event)
 {
     KCategorizedView::contextMenuEvent(event);
-    if (selectionModel()->hasSelection()) {
-        m_controller->triggerContextMenuRequest(event->pos());
-    }
+    m_controller->triggerContextMenuRequest(event->pos());
 }
 
 void DolphinIconsView::mousePressEvent(QMouseEvent* event)
@@ -180,6 +182,14 @@ void DolphinIconsView::mousePressEvent(QMouseEvent* event)
     KCategorizedView::mousePressEvent(event);
 }
 
+void DolphinIconsView::startDrag(Qt::DropActions supportedActions)
+{
+    // TODO: invoking KCategorizedView::startDrag() should not be necessary, we'll
+    // fix this in KDE 4.1
+    KCategorizedView::startDrag(supportedActions);
+    DragAndDropHelper::startDrag(this, supportedActions);
+}
+
 void DolphinIconsView::dragEnterEvent(QDragEnterEvent* event)
 {
     if (event->mimeData()->hasUrls()) {
@@ -227,6 +237,7 @@ void DolphinIconsView::dropEvent(QDropEvent* event)
     }
 
     KCategorizedView::dropEvent(event);
+
     m_dragging = false;
 }
 
@@ -237,7 +248,7 @@ void DolphinIconsView::paintEvent(QPaintEvent* 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);
+        DragAndDropHelper::drawHoverIndication(viewport(), m_dropRect, brush);
     }
 }
 
@@ -417,7 +428,7 @@ void DolphinIconsView::updateGridSize(bool showPreview, int additionalInfoCount)
     }
 
     const int spacing = settings->gridSpacing();
-    setGridSize(QSize(itemWidth + spacing, itemHeight + spacing));
+    setGridSize(QSize(itemWidth + spacing * 2, itemHeight + spacing));
 
     m_itemSize = QSize(itemWidth, itemHeight);
 
@@ -433,5 +444,4 @@ KFileItem DolphinIconsView::itemForIndex(const QModelIndex& index) const
     return dirModel->itemForIndex(dirIndex);
 }
 
-
 #include "dolphiniconsview.moc"