]> cloud.milkyroute.net Git - dolphin.git/blobdiff - src/dolphiniconsview.cpp
Allow turning off the feature that additional information might be shown in the icons...
[dolphin.git] / src / dolphiniconsview.cpp
index ea553c8bee1b299f8943fe4a6d0990170c4bc39b..2bb21cb79a6859de0c6e8dd6efbedf2344ee146a 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,10 +144,10 @@ 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();
         const int gridWidth = gridSize().width();
@@ -178,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()) {
@@ -202,10 +214,13 @@ void DolphinIconsView::dragMoveEvent(QDragMoveEvent* event)
     // TODO: remove this code when the issue #160611 is solved in Qt 4.4
     const QModelIndex index = indexAt(event->pos());
     setDirtyRegion(m_dropRect);
-    if (itemForIndex(index).isDir()) {
-        m_dropRect = visualRect(index);
-    } else {
-        m_dropRect.setSize(QSize()); // set as invalid
+
+    m_dropRect.setSize(QSize()); // set as invalid
+    if (index.isValid()) {
+        const KFileItem item = itemForIndex(index);
+        if (!item.isNull() && item.isDir()) {
+            m_dropRect = visualRect(index);
+        }
     }
     setDirtyRegion(m_dropRect);
 }
@@ -225,6 +240,7 @@ void DolphinIconsView::dropEvent(QDropEvent* event)
     }
 
     KCategorizedView::dropEvent(event);
+
     m_dragging = false;
 }
 
@@ -235,7 +251,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);
     }
 }
 
@@ -266,12 +282,16 @@ void DolphinIconsView::slotEntered(const QModelIndex& index)
 void DolphinIconsView::slotShowPreviewChanged()
 {
     const DolphinView* view = m_controller->dolphinView();
-    const int infoCount = view->additionalInfo().count();
-    updateGridSize(view->showPreview(), infoCount);
+    updateGridSize(view->showPreview(), additionalInfoCount());
 }
 
 void DolphinIconsView::slotAdditionalInfoChanged(const KFileItemDelegate::InformationList& info)
 {
+    const IconsModeSettings* settings = DolphinSettings::instance().iconsModeSettings();
+    if (!settings->showAdditionalInfo()) {
+        return;
+    }
+
     const bool showPreview = m_controller->dolphinView()->showPreview();
     updateGridSize(showPreview, info.count());
 }
@@ -302,8 +322,7 @@ void DolphinIconsView::zoomIn()
         settings->setItemWidth(settings->itemWidth() + diff);
         settings->setItemHeight(settings->itemHeight() + diff);
 
-        const int infoCount = m_controller->dolphinView()->additionalInfo().count();
-        updateGridSize(showPreview, infoCount);
+        updateGridSize(showPreview, additionalInfoCount());
     }
 }
 
@@ -334,8 +353,7 @@ void DolphinIconsView::zoomOut()
         settings->setItemWidth(settings->itemWidth() - diff);
         settings->setItemHeight(settings->itemHeight() - diff);
 
-        const int infoCount = m_controller->dolphinView()->additionalInfo().count();
-        updateGridSize(showPreview, infoCount);
+        updateGridSize(showPreview, additionalInfoCount());
     }
 }
 
@@ -431,5 +449,11 @@ KFileItem DolphinIconsView::itemForIndex(const QModelIndex& index) const
     return dirModel->itemForIndex(dirIndex);
 }
 
+int DolphinIconsView::additionalInfoCount() const
+{
+    const DolphinView* view = m_controller->dolphinView();
+    const IconsModeSettings* settings = DolphinSettings::instance().iconsModeSettings();
+    return settings->showAdditionalInfo() ? view->additionalInfo().count() : 0;
+}
 
 #include "dolphiniconsview.moc"