]> cloud.milkyroute.net Git - dolphin.git/blobdiff - src/dolphiniconsview.cpp
Make use of the error messages coming from the places model.
[dolphin.git] / src / dolphiniconsview.cpp
index 6d2ca66a0c682638043e0650bd09aac82bde9524..50d7f311e92284b9ebc5b0d62c470cf44b616545 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,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)
@@ -162,8 +202,8 @@ void DolphinIconsView::zoomIn()
 
         // increase also the grid size
         const int diff = newIconSize - oldIconSize;
-        settings->setGridWidth(settings->gridWidth() + diff);
-        settings->setGridHeight(settings->gridHeight() + diff);
+        settings->setItemWidth(settings->itemWidth() + diff);
+        settings->setItemHeight(settings->itemHeight() + diff);
 
         updateGridSize(showPreview, m_controller->showAdditionalInfo());
     }
@@ -193,8 +233,8 @@ void DolphinIconsView::zoomOut()
 
         // decrease also the grid size
         const int diff = oldIconSize - newIconSize;
-        settings->setGridWidth(settings->gridWidth() - diff);
-        settings->setGridHeight(settings->gridHeight() - diff);
+        settings->setItemWidth(settings->itemWidth() - diff);
+        settings->setItemHeight(settings->itemHeight() - diff);
 
         updateGridSize(showPreview, m_controller->showAdditionalInfo());
     }
@@ -249,26 +289,35 @@ void DolphinIconsView::updateGridSize(bool showPreview, bool showAdditionalInfo)
     const IconsModeSettings* settings = DolphinSettings::instance().iconsModeSettings();
     Q_ASSERT(settings != 0);
 
-    int gridWidth = settings->gridWidth();
-    int gridHeight = settings->gridHeight();
+    int itemWidth = settings->itemWidth();
+    int itemHeight = settings->itemHeight();
     int size = settings->iconSize();
 
     if (showPreview) {
         const int previewSize = settings->previewSize();
         const int diff = previewSize - size;
         Q_ASSERT(diff >= 0);
-        gridWidth  += diff;
-        gridHeight += diff;
+        itemWidth  += diff;
+        itemHeight += diff;
 
         size = previewSize;
     }
 
     if (showAdditionalInfo) {
-        gridHeight += m_viewOptions.font.pointSize() * 2;
+        itemHeight += m_viewOptions.font.pointSize() * 2;
+    }
+
+    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);
     }
 
-    m_viewOptions.decorationSize = QSize(size, size);
-    setGridSize(QSize(gridWidth, gridHeight));
+    const int spacing = settings->gridSpacing();
+    setGridSize(QSize(itemWidth + spacing, itemHeight + spacing));
 
     m_controller->setZoomInPossible(isZoomInPossible());
     m_controller->setZoomOutPossible(isZoomOutPossible());