]> cloud.milkyroute.net Git - dolphin.git/blobdiff - src/dolphiniconsview.cpp
Simplify DolphinController: don't remember the show-preview state in the controller...
[dolphin.git] / src / dolphiniconsview.cpp
index dbf03491ea80e65df09f2d2172227b1703026547..30e47da899fc3be77dc2438977bd5f5a39f758a8 100644 (file)
@@ -1,6 +1,5 @@
 /***************************************************************************
- *   Copyright (C) 2006 by Peter Penz                                      *
- *   peter.penz@gmx.at                                                     *
+ *   Copyright (C) 2006 by Peter Penz (peter.penz@gmx.at)                  *
  *                                                                         *
  *   This program is free software; you can redistribute it and/or modify  *
  *   it under the terms of the GNU General Public License as published by  *
  *   You should have received a copy of the GNU General Public License     *
  *   along with this program; if not, write to the                         *
  *   Free Software Foundation, Inc.,                                       *
- *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
+ *   51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA            *
  ***************************************************************************/
 
 #include "dolphiniconsview.h"
-#include <qpainter.h>
-//Added by qt3to4:
-#include <QDragMoveEvent>
-#include <QDropEvent>
-#include <Q3ValueList>
-#include <QPixmap>
-#include <QMouseEvent>
-#include <QDragEnterEvent>
-#include <kiconeffect.h>
-#include <kapplication.h>
-#include <qobject.h>
-#include <kglobalsettings.h>
-#include <qclipboard.h>
-#include <assert.h>
-#include <kaction.h>
-#include <kstdaction.h>
-#include <kfileitem.h>
-#include <kactioncollection.h>
-
-#include "dolphinview.h"
-#include "viewproperties.h"
-#include "dolphin.h"
-#include "dolphinstatusbar.h"
+
+#include "dolphincategorydrawer.h"
+#include "dolphincontroller.h"
 #include "dolphinsettings.h"
-#include "iconsmodesettings.h"
 
-DolphinIconsView::DolphinIconsView(DolphinView* parent, LayoutMode layoutMode) :
-    KFileIconView(parent, 0),
-    m_previewIconSize(-1),
-    m_layoutMode(layoutMode),
-    m_dolphinView(parent)
-{
-    setAcceptDrops(true);
-    setMode(K3IconView::Execute);
-    setSelectionMode(KFile::Extended);
-    Dolphin& dolphin = Dolphin::mainWin();
-
-    connect(this, SIGNAL(onItem(Q3IconViewItem*)),
-            this, SLOT(slotOnItem(Q3IconViewItem*)));
-    connect(this, SIGNAL(onViewport()),
-            this, SLOT(slotOnViewport()));
-    connect(this, SIGNAL(contextMenuRequested(Q3IconViewItem*, const QPoint&)),
-            this, SLOT(slotContextMenuRequested(Q3IconViewItem*, const QPoint&)));
-    connect(this, SIGNAL(selectionChanged()),
-            &dolphin, SLOT(slotSelectionChanged()));
-    connect(&dolphin, SIGNAL(activeViewChanged()),
-            this, SLOT(slotActivationUpdate()));
-    connect(this, SIGNAL(itemRenamed(Q3IconViewItem*, const QString&)),
-            this, SLOT(slotItemRenamed(Q3IconViewItem*, const QString&)));
-    connect(this, SIGNAL(dropped(QDropEvent*, const KURL::List&, const KURL&)),
-            parent, SLOT(slotURLListDropped(QDropEvent*, const KURL::List&, const KURL&)));
-
-    QClipboard* clipboard = QApplication::clipboard();
-    connect(clipboard, SIGNAL(dataChanged()),
-            this, SLOT(slotUpdateDisabledItems()));
-
-    // KFileIconView creates two actions for zooming, which are directly connected to the
-    // slots KFileIconView::zoomIn() and KFileIconView::zoomOut(). As this behavior is not
-    // wanted and the slots are not virtual, the actions are disabled here.
-    KAction* zoomInAction = actionCollection()->action("zoomIn");
-    assert(zoomInAction != 0);
-    zoomInAction->setEnabled(false);
-
-    KAction* zoomOutAction = actionCollection()->action("zoomOut");
-    assert(zoomOutAction != 0);
-    zoomOutAction->setEnabled(false);
-
-    setItemsMovable(true);
-    setWordWrapIconText(true);
-    if (m_layoutMode == Previews) {
-        showPreviews();
-    }
-    refreshSettings();
-}
+#include "dolphin_iconsmodesettings.h"
 
-DolphinIconsView::~DolphinIconsView()
-{
-}
+#include <kdialog.h>
+#include <kdirmodel.h>
+
+#include <QAbstractProxyModel>
+#include <QApplication>
+#include <QPainter>
+#include <QPoint>
 
-void DolphinIconsView::setLayoutMode(LayoutMode mode)
+DolphinIconsView::DolphinIconsView(QWidget* parent, DolphinController* controller) :
+    KCategorizedView(parent),
+    m_controller(controller),
+    m_categoryDrawer(0),
+    m_itemSize(),
+    m_dragging(false),
+    m_dropRect()
 {
-    if (m_layoutMode != mode) {
-        m_layoutMode = mode;
-        refreshSettings();
+    Q_ASSERT(controller != 0);
+    setViewMode(QListView::IconMode);
+    setResizeMode(QListView::Adjust);
+    setSpacing(KDialog::spacingHint());
+    setMouseTracking(true);
+    viewport()->setAttribute(Qt::WA_Hover);
+
+    // TODO: Connecting to the signal 'activated()' is not possible, as kstyle
+    // does not forward the single vs. doubleclick to it yet (KDE 4.1?). Hence it is
+    // necessary connecting the signal 'singleClick()' or 'doubleClick' and to handle the
+    // RETURN-key in keyPressEvent().
+    if (KGlobalSettings::singleClick()) {
+        connect(this, SIGNAL(clicked(const QModelIndex&)),
+                this, SLOT(triggerItem(const QModelIndex&)));
+    } else {
+        connect(this, SIGNAL(doubleClicked(const QModelIndex&)),
+                this, SLOT(triggerItem(const QModelIndex&)));
     }
+    connect(this, SIGNAL(viewportEntered()),
+            controller, SLOT(emitViewportEntered()));
+    connect(controller, SIGNAL(zoomIn()),
+            this, SLOT(zoomIn()));
+    connect(controller, SIGNAL(zoomOut()),
+            this, SLOT(zoomOut()));
+
+    const DolphinView* view = controller->dolphinView();
+    connect(view, SIGNAL(showPreviewChanged()),
+            this, SLOT(slotShowPreviewChanged()));
+    connect(view, SIGNAL(additionalInfoChanged(const KFileItemDelegate::InformationList&)),
+            this, SLOT(slotAdditionalInfoChanged(const KFileItemDelegate::InformationList&)));
+
+    connect(this, SIGNAL(entered(const QModelIndex&)),
+            this, SLOT(slotEntered(const QModelIndex&)));
+
+    // apply the icons mode settings to the widget
+    const IconsModeSettings* settings = DolphinSettings::instance().iconsModeSettings();
+    Q_ASSERT(settings != 0);
+
+    m_viewOptions = KCategorizedView::viewOptions();
+    m_viewOptions.showDecorationSelected = true;
+
+    QFont font(settings->fontFamily(), settings->fontSize());
+    font.setItalic(settings->italicFont());
+    font.setBold(settings->boldFont());
+    m_viewOptions.font = font;
+
+    setWordWrap(settings->numberOfTextlines() > 1);
+    updateGridSize(view->showPreview(), 0);
+
+    if (settings->arrangement() == QListView::TopToBottom) {
+        setFlow(QListView::LeftToRight);
+        m_viewOptions.decorationPosition = QStyleOptionViewItem::Top;
+    } else {
+        setFlow(QListView::TopToBottom);
+        m_viewOptions.decorationPosition = QStyleOptionViewItem::Left;
+        m_viewOptions.displayAlignment = Qt::AlignLeft | Qt::AlignVCenter;
+    }
+
+    m_categoryDrawer = new DolphinCategoryDrawer();
+    setCategoryDrawer(m_categoryDrawer);
+
+    setFocus();
 }
 
-void DolphinIconsView::beginItemUpdates()
+DolphinIconsView::~DolphinIconsView()
 {
+    delete m_categoryDrawer;
+    m_categoryDrawer = 0;
 }
 
-void DolphinIconsView::endItemUpdates()
+QRect DolphinIconsView::visualRect(const QModelIndex& index) const
 {
-    arrangeItemsInGrid();
+    const bool leftToRightFlow = (flow() == QListView::LeftToRight);
 
-    // TODO: KFileIconView does not emit any signal when the preview
-    // has been finished. Using a delay of 300 ms is a temporary workaround
-    // until the DolphinIconsView will implement the previews by it's own in
-    // future releases.
-    QTimer::singleShot(300, this, SLOT(slotUpdateDisabledItems()));
+    QRect itemRect = KCategorizedView::visualRect(index);
+    const int maxWidth  = m_itemSize.width();
+    const int maxHeight = m_itemSize.height();
 
-    const KFileIconViewItem* item = static_cast<const KFileIconViewItem*>(firstItem());
-    if (item != 0) {
-        setCurrentItem(item->fileInfo());
+    if (itemRect.width() > maxWidth) {
+        // assure that the maximum item width is not exceeded
+        if (leftToRightFlow) {
+            const int left = itemRect.left() + (itemRect.width() - maxWidth) / 2;
+            itemRect.setLeft(left);
+        }
+        itemRect.setWidth(maxWidth);
     }
 
-    int index = 0;
-    const Q3ValueList<URLNavigator::HistoryElem> history = m_dolphinView->urlHistory(index);
-    if (!history.isEmpty()) {
-        KFileView* fileView = static_cast<KFileView*>(this);
-        fileView->setCurrentItem(history[index].currentFileName());
-        setContentsPos(history[index].contentsX(), history[index].contentsY());
+    if (itemRect.height() > maxHeight) {
+        // assure that the maximum item height is not exceeded
+        if (!leftToRightFlow) {
+            const int top = itemRect.top() + (itemRect.height() - maxHeight) / 2;
+            itemRect.setTop(top);
+        }
+        itemRect.setHeight(maxHeight);
     }
+
+    return itemRect;
 }
 
-void DolphinIconsView::refreshSettings()
+QStyleOptionViewItem DolphinIconsView::viewOptions() const
 {
-    const IconsModeSettings* settings = DolphinSettings::instance().iconsModeSettings();
-    assert(settings != 0);
-
-    setIconSize(settings->iconSize());
-
-    const Q3IconView::Arrangement arrangement = settings->arrangement() == "LeftToRight" ? // TODO: use enum directly in settings
-                                               Q3IconView::LeftToRight : Q3IconView::TopToBottom;
-    const Q3IconView::ItemTextPos textPos = (arrangement == Q3IconView::LeftToRight) ?
-                                           Q3IconView::Bottom :
-                                           Q3IconView::Right;
-    setArrangement(arrangement);
-    setItemTextPos(textPos);
-
-    // TODO: tempory crash; will get changed anyway for KDE 4
-    /*setGridX(settings->gridWidth());
-    setGridY(settings->gridHeight());
-    setSpacing(settings->gridSpacing());*/
-
-    QFont adjustedFont(font());
-    adjustedFont.setFamily(settings->fontFamily());
-    adjustedFont.setPointSize(settings->fontSize());
-    setFont(adjustedFont);
-    setIconTextHeight(settings->numberOfTexlines());
-
-    if (m_layoutMode == Previews) {
-        // There is no getter method for the current size in KFileIconView. To
-        // prevent a flickering the current size is stored in m_previewIconSize and
-        // setPreviewSize is only invoked if the size really has changed.
-        showPreviews();
-
-        const int size = settings->previewSize();
-        if (size != m_previewIconSize) {
-            m_previewIconSize = size;
-            setPreviewSize(size);
-        }
-    }
+    return m_viewOptions;
 }
 
-void DolphinIconsView::zoomIn()
+void DolphinIconsView::contextMenuEvent(QContextMenuEvent* event)
 {
-    if (isZoomInPossible()) {
-        IconsModeSettings* settings = DolphinSettings::instance().iconsModeSettings();
-        const int textWidthHint = DolphinSettings::instance().textWidthHint(); // TODO: remove for KDE4
-
-        const int iconSize = increasedIconSize(settings->iconSize());
-        settings->setIconSize(iconSize);
+    KCategorizedView::contextMenuEvent(event);
+    m_controller->triggerContextMenuRequest(event->pos());
+}
 
-        if (m_layoutMode == Previews) {
-            const int previewSize = increasedIconSize(settings->previewSize());
-            settings->setPreviewSize(previewSize);
+void DolphinIconsView::mousePressEvent(QMouseEvent* event)
+{
+    m_controller->requestActivation();
+    if (!indexAt(event->pos()).isValid()) {
+        const Qt::KeyboardModifiers modifier = QApplication::keyboardModifiers();
+        if (!(modifier & Qt::ShiftModifier) && !(modifier & Qt::ControlModifier)) {
+            clearSelection();
         }
-
-        DolphinSettings::instance().calculateGridSize(textWidthHint); // TODO: remove for KDE4
-        ItemEffectsManager::zoomIn();
     }
+
+    KCategorizedView::mousePressEvent(event);
 }
 
-void DolphinIconsView::zoomOut()
+void DolphinIconsView::dragEnterEvent(QDragEnterEvent* event)
 {
-    if (isZoomOutPossible()) {
-        IconsModeSettings* settings = DolphinSettings::instance().iconsModeSettings();
-        const int textWidthHint = DolphinSettings::instance().textWidthHint(); // TODO: remove for KDE4
-
-        const int iconSize = decreasedIconSize(settings->iconSize());
-        settings->setIconSize(iconSize);
-
-        if (m_layoutMode == Previews) {
-            const int previewSize = decreasedIconSize(settings->previewSize());
-            settings->setPreviewSize(previewSize);
-        }
-
-        DolphinSettings::instance().calculateGridSize(textWidthHint); // TODO: remove for KDE4
-        ItemEffectsManager::zoomOut();
+    if (event->mimeData()->hasUrls()) {
+        event->acceptProposedAction();
     }
+    m_dragging = true;
 }
 
-bool DolphinIconsView::isZoomInPossible() const
+void DolphinIconsView::dragLeaveEvent(QDragLeaveEvent* event)
 {
-    IconsModeSettings* settings = DolphinSettings::instance().iconsModeSettings();
-    const int size = (m_layoutMode == Icons) ? settings->iconSize() : settings->previewSize();
-    return size < K3Icon::SizeEnormous;
+    KCategorizedView::dragLeaveEvent(event);
+
+    // TODO: remove this code when the issue #160611 is solved in Qt 4.4
+    m_dragging = false;
+    setDirtyRegion(m_dropRect);
 }
 
-bool DolphinIconsView::isZoomOutPossible() const
+void DolphinIconsView::dragMoveEvent(QDragMoveEvent* event)
 {
-    IconsModeSettings* settings = DolphinSettings::instance().iconsModeSettings();
-    return settings->iconSize() > K3Icon::SizeSmall;
+    KCategorizedView::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::arrangeItemsInGrid( bool updated )
+void DolphinIconsView::dropEvent(QDropEvent* event)
 {
-
-    KFileIconView::arrangeItemsInGrid(updated);
-
-    if (m_layoutMode == Previews) {
-        // The class KFileIconView has a bug when the size of the previews differs from the size
-        // of the icons: For specific MIME types the y-position and the height is calculated in
-        // a wrong manner. The following code bypasses this issue. No bugreport has been submitted
-        // as this functionality is not used by any KDE3 application and the core developers are
-        // busy enough for KDE4 now :-)
-
-        KFileIconViewItem* item = static_cast<KFileIconViewItem*>(Q3IconView::firstItem());
-        QString mimetype;
-        while (item != 0) {
-            mimetype = item->fileInfo()->mimetype();
-            const bool fixSize = mimetype.contains("text") ||
-                                 mimetype.contains("application/x-");
-            if (fixSize) {
-                item->setPixmapSize(QSize(m_previewIconSize, m_previewIconSize));
+    if (!selectionModel()->isSelected(indexAt(event->pos()))) {
+        const KUrl::List urls = KUrl::List::fromMimeData(event->mimeData());
+        if (!urls.isEmpty()) {
+            const QModelIndex index = indexAt(event->pos());
+            if (index.isValid()) {
+                const KFileItem item = itemForIndex(index);
+                m_controller->indicateDroppedUrls(urls,
+                                                  m_controller->url(),
+                                                  item,
+                                                  event->source());
+                event->acceptProposedAction();
             }
-            item = static_cast<KFileIconViewItem *>(item->nextItem());
         }
     }
-}
 
-void DolphinIconsView::setContextPixmap(void* context,
-                                        const QPixmap& pixmap)
-{
-    reinterpret_cast<KFileIconViewItem*>(context)->setPixmap(pixmap);
+    KCategorizedView::dropEvent(event);
+    m_dragging = false;
 }
 
-const QPixmap* DolphinIconsView::contextPixmap(void* context)
+void DolphinIconsView::paintEvent(QPaintEvent* event)
 {
-    return reinterpret_cast<KFileIconViewItem*>(context)->pixmap();
-}
+    KCategorizedView::paintEvent(event);
 
-void* DolphinIconsView::firstContext()
-{
-    return reinterpret_cast<void*>(firstItem());
+    // 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::nextContext(void* context)
+void DolphinIconsView::keyPressEvent(QKeyEvent* event)
 {
-    KFileIconViewItem* iconViewItem = reinterpret_cast<KFileIconViewItem*>(context);
-    return reinterpret_cast<void*>(iconViewItem->nextItem());
+    KCategorizedView::keyPressEvent(event);
+
+    const QItemSelectionModel* selModel = selectionModel();
+    const QModelIndex currentIndex = selModel->currentIndex();
+    const bool trigger = currentIndex.isValid()
+                         && (event->key() == Qt::Key_Return)
+                         && (selModel->selectedIndexes().count() <= 1);
+    if (trigger) {
+        triggerItem(currentIndex);
+    }
 }
 
-KFileItem* DolphinIconsView::contextFileInfo(void* context)
+void DolphinIconsView::triggerItem(const QModelIndex& index)
 {
-    return reinterpret_cast<KFileIconViewItem*>(context)->fileInfo();
+    m_controller->triggerItem(itemForIndex(index));
 }
 
-void DolphinIconsView::contentsMousePressEvent(QMouseEvent* event)
+void DolphinIconsView::slotEntered(const QModelIndex& index)
 {
-    KFileIconView::contentsMousePressEvent(event);
-    resetActivatedItem();
-    emit signalRequestActivation();
-    m_dolphinView->statusBar()->clear();
+    m_controller->emitItemEntered(itemForIndex(index));
 }
 
-void DolphinIconsView::contentsMouseReleaseEvent(QMouseEvent* event)
+void DolphinIconsView::slotShowPreviewChanged()
 {
-    KFileIconView::contentsMouseReleaseEvent(event);
-
-    // The KFileIconView does not send any selectionChanged signal if
-    // a selection is done by using the "select-during-button-pressed" feature.
-    // Hence inform Dolphin about the selection change manually:
-    Dolphin::mainWin().slotSelectionChanged();
+    const DolphinView* view = m_controller->dolphinView();
+    const int infoCount = view->additionalInfo().count();
+    updateGridSize(view->showPreview(), infoCount);
 }
 
-void DolphinIconsView::drawBackground(QPainter* painter, const QRect& rect)
+void DolphinIconsView::slotAdditionalInfoChanged(const KFileItemDelegate::InformationList& info)
 {
-    if (m_dolphinView->isActive()) {
-        KFileIconView::drawBackground(painter, rect);
-    }
-    else {
-        const QBrush brush(colorGroup().background());
-        painter->fillRect(0, 0, width(), height(), brush);
-    }
+    const bool showPreview = m_controller->dolphinView()->showPreview();
+    updateGridSize(showPreview, info.count());
 }
 
-Q3DragObject* DolphinIconsView::dragObject()
+void DolphinIconsView::zoomIn()
 {
-    KUrl::List urls;
-    QListIterator<KFileItem*> it(*KFileView::selectedItems());
-    while (it.hasNext()) {
-        KFileItem *item = it.next();
-        urls.append(item->url());
-    }
-
-    QPixmap pixmap;
-    if(urls.count() > 1) {
-        pixmap = DesktopIcon("kmultiple", iconSize());
-    }
-    else {
-        KFileIconViewItem* item = static_cast<KFileIconViewItem*>(currentItem());
-        if ((item != 0) && (item->pixmap() != 0)) {
-            pixmap = *(item->pixmap());
-        }
-    }
+    if (isZoomInPossible()) {
+        IconsModeSettings* settings = DolphinSettings::instance().iconsModeSettings();
 
-    if (pixmap.isNull()) {
-        pixmap = currentFileItem()->pixmap(iconSize());
-    }
+        const int oldIconSize = settings->iconSize();
+        int newIconSize = oldIconSize;
 
-    /* This should be ported to QMimeData
-    Q3DragObject* dragObj = new KURLDrag(urls, widget());
-    dragObj->setPixmap(pixmap);
-    return dragObj;
-    */
-    return 0;
-}
+        const bool showPreview = m_controller->dolphinView()->showPreview();
+        if (showPreview) {
+            const int previewSize = increasedIconSize(settings->previewSize());
+            settings->setPreviewSize(previewSize);
+        } else {
+            newIconSize = increasedIconSize(oldIconSize);
+            settings->setIconSize(newIconSize);
+            if (settings->previewSize() < newIconSize) {
+                // assure that the preview size is always >= the icon size
+                settings->setPreviewSize(newIconSize);
+            }
+        }
 
-void DolphinIconsView::contentsDragEnterEvent(QDragEnterEvent* event)
-{
-    // TODO: The method KFileIconView::contentsDragEnterEvent() does
-    // not allow drag and drop inside itself, which prevents the possability
-    // to move a file into a directory. As the method KFileIconView::acceptDrag()
-    // is not virtual, we must overwrite the method
-    // KFileIconView::contentsDragEnterEvent() and do some cut/copy/paste for this
-    // usecase. Corresponding to the documentation the method KFileIconView::acceptDrag()
-    // will get virtual in KDE 4, which will simplify the code.
-
-    if (event->source() != this) {
-        KFileIconView::contentsDragEnterEvent(event);
-        return;
-    }
+        // increase also the grid size
+        const int diff = newIconSize - oldIconSize;
+        settings->setItemWidth(settings->itemWidth() + diff);
+        settings->setItemHeight(settings->itemHeight() + diff);
 
-    KUrl::List uriList = KUrl::List::fromMimeData( event->mimeData() );
-    const bool accept = !uriList.isEmpty() &&
-                        (event->action() == QDropEvent::Copy ||
-                         event->action() == QDropEvent::Move ||
-                         event->action() == QDropEvent::Link );
-    if (accept) {
-        event->acceptAction();
-    }
-    else {
-        event->ignore();
+        const int infoCount = m_controller->dolphinView()->additionalInfo().count();
+        updateGridSize(showPreview, infoCount);
     }
 }
 
-void DolphinIconsView::contentsDragMoveEvent(QDragMoveEvent* event)
+void DolphinIconsView::zoomOut()
 {
-    KFileIconView::contentsDragMoveEvent(event);
-
-    // If a dragging is done above a directory, show the icon as 'active' for
-    // a visual feedback
-    KFileIconViewItem* item = static_cast<KFileIconViewItem*>(findItem(contentsToViewport(event->pos())));
-
-    bool showActive = false;
-    if (item != 0) {
-        const KFileItem* fileInfo = item->fileInfo();
-        showActive = (fileInfo != 0) && fileInfo->isDir();
-    }
-
-    if (showActive) {
-        slotOnItem(item);
-    }
-    else {
-        slotOnViewport();
-    }
-}
+    if (isZoomOutPossible()) {
+        IconsModeSettings* settings = DolphinSettings::instance().iconsModeSettings();
 
-void DolphinIconsView::contentsDropEvent(QDropEvent* event)
-{
-    // TODO: Most of the following code is a copy of
-    // KFileIconView::contentsDropEvent. See comment in
-    // DolphinIconsView::contentsDragEnterEvent for details.
+        const int oldIconSize = settings->iconSize();
+        int newIconSize = oldIconSize;
 
-    if (event->source() != this) {
-        KFileIconView::contentsDropEvent(event);
-        return;
-    }
+        const bool showPreview = m_controller->dolphinView()->showPreview();
+        if (showPreview) {
+            const int previewSize = decreasedIconSize(settings->previewSize());
+            settings->setPreviewSize(previewSize);
+            if (settings->iconSize() > previewSize) {
+                // assure that the icon size is always <= the preview size
+                newIconSize = previewSize;
+                settings->setIconSize(newIconSize);
+            }
+        } else {
+            newIconSize = decreasedIconSize(settings->iconSize());
+            settings->setIconSize(newIconSize);
+        }
 
-    KFileIconViewItem* item = static_cast<KFileIconViewItem*>(findItem(contentsToViewport(event->pos())));
-    KUrl::List urls = KUrl::List::fromMimeData( event->mimeData() );
-    const bool accept = !urls.isEmpty() &&
-                        (event->action() == QDropEvent::Copy ||
-                         event->action() == QDropEvent::Move ||
-                         event->action() == QDropEvent::Link ) &&
-                        (item != 0);
-    if (!accept) {
-        return;
-    }
+        // decrease also the grid size
+        const int diff = oldIconSize - newIconSize;
+        settings->setItemWidth(settings->itemWidth() - diff);
+        settings->setItemHeight(settings->itemHeight() - diff);
 
-    KFileItem* fileItem = item->fileInfo();
-    if (!fileItem->isDir()) {
-        // the file is not a directory, hence don't accept any drop
-        return;
-    }
-    emit dropped(event, fileItem);
-    if (!urls.isEmpty()) {
-        emit dropped(event, urls, fileItem != 0 ? fileItem->url() : KUrl());
-        sig->dropURLs(fileItem, event, urls);
+        const int infoCount = m_controller->dolphinView()->additionalInfo().count();
+        updateGridSize(showPreview, infoCount);
     }
 }
 
-void DolphinIconsView::slotOnItem(Q3IconViewItem* item)
+bool DolphinIconsView::isZoomInPossible() const
 {
-    assert(item != 0);
-    activateItem(reinterpret_cast<void*>(item));
-
-    KFileItem* fileItem = static_cast<KFileIconViewItem*>(item)->fileInfo();
-    m_dolphinView->requestItemInfo(fileItem->url());
+    IconsModeSettings* settings = DolphinSettings::instance().iconsModeSettings();
+    const bool showPreview = m_controller->dolphinView()->showPreview();
+    const int size = showPreview ? settings->previewSize() : settings->iconSize();
+    return size < KIconLoader::SizeEnormous;
 }
 
-void DolphinIconsView::slotOnViewport()
+bool DolphinIconsView::isZoomOutPossible() const
 {
-    resetActivatedItem();
-    m_dolphinView->requestItemInfo(KUrl());
+    IconsModeSettings* settings = DolphinSettings::instance().iconsModeSettings();
+    const bool showPreview = m_controller->dolphinView()->showPreview();
+    const int size = showPreview ? settings->previewSize() : settings->iconSize();
+    return size > KIconLoader::SizeSmall;
 }
 
-void DolphinIconsView::slotContextMenuRequested(Q3IconViewItem* item,
-                                                const QPoint& pos)
+int DolphinIconsView::increasedIconSize(int size) const
 {
-    KFileItem* fileInfo = 0;
-    if (item != 0) {
-        fileInfo = static_cast<KFileIconViewItem*>(item)->fileInfo();
+    int incSize = 0;
+    switch (size) {
+    case KIconLoader::SizeSmall:       incSize = KIconLoader::SizeSmallMedium; break;
+    case KIconLoader::SizeSmallMedium: incSize = KIconLoader::SizeMedium; break;
+    case KIconLoader::SizeMedium:      incSize = KIconLoader::SizeLarge; break;
+    case KIconLoader::SizeLarge:       incSize = KIconLoader::SizeHuge; break;
+    case KIconLoader::SizeHuge:        incSize = KIconLoader::SizeEnormous; break;
+    default: Q_ASSERT(false); break;
     }
-    m_dolphinView->openContextMenu(fileInfo, pos);
+    return incSize;
 }
 
-void DolphinIconsView::slotItemRenamed(Q3IconViewItem* item,
-                                       const QString& name)
+int DolphinIconsView::decreasedIconSize(int size) const
 {
-    KFileItem* fileInfo = static_cast<KFileIconViewItem*>(item)->fileInfo();
-    m_dolphinView->rename(KUrl(fileInfo->url()), name);
+    int decSize = 0;
+    switch (size) {
+    case KIconLoader::SizeSmallMedium: decSize = KIconLoader::SizeSmall; break;
+    case KIconLoader::SizeMedium: decSize = KIconLoader::SizeSmallMedium; break;
+    case KIconLoader::SizeLarge: decSize = KIconLoader::SizeMedium; break;
+    case KIconLoader::SizeHuge: decSize = KIconLoader::SizeLarge; break;
+    case KIconLoader::SizeEnormous: decSize = KIconLoader::SizeHuge; break;
+    default: Q_ASSERT(false); break;
+    }
+    return decSize;
 }
 
-void DolphinIconsView::slotActivationUpdate()
+void DolphinIconsView::updateGridSize(bool showPreview, int additionalInfoCount)
 {
-    update();
+    const IconsModeSettings* settings = DolphinSettings::instance().iconsModeSettings();
+    Q_ASSERT(settings != 0);
 
-    // TODO: there must be a simpler way to say
-    // "update all children"
-    const QList<QObject*> list = children();
-    if (list.isEmpty()) {
-        return;
-    }
+    int itemWidth = settings->itemWidth();
+    int itemHeight = settings->itemHeight();
+    int size = settings->iconSize();
 
-    QListIterator<QObject*> it(list);
-    QObject* object = 0;
-    while (it.hasNext()) {
-        object = it.next();
-        if (object->inherits("QWidget")) {
-            QWidget* widget = static_cast<QWidget*>(object);
-            widget->update();
-        }
+    if (showPreview) {
+        const int previewSize = settings->previewSize();
+        const int diff = previewSize - size;
+        Q_ASSERT(diff >= 0);
+        itemWidth  += diff;
+        itemHeight += diff;
+
+        size = previewSize;
     }
-}
 
-void DolphinIconsView::slotUpdateDisabledItems()
-{
-    updateDisabledItems();
-}
+    Q_ASSERT(additionalInfoCount >= 0);
+    itemHeight += additionalInfoCount * m_viewOptions.font.pointSize() * 2;
 
-int DolphinIconsView::increasedIconSize(int size) const
-{
-    int incSize = 0;
-    switch (size) {
-        case K3Icon::SizeSmall:       incSize = K3Icon::SizeSmallMedium; break;
-        case K3Icon::SizeSmallMedium: incSize = K3Icon::SizeMedium; break;
-        case K3Icon::SizeMedium:      incSize = K3Icon::SizeLarge; break;
-        case K3Icon::SizeLarge:       incSize = K3Icon::SizeHuge; break;
-        case K3Icon::SizeHuge:        incSize = K3Icon::SizeEnormous; break;
-        default: assert(false); break;
+    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);
     }
-    return incSize;
+
+    const int spacing = settings->gridSpacing();
+    setGridSize(QSize(itemWidth + spacing, itemHeight + spacing));
+
+    m_itemSize = QSize(itemWidth, itemHeight);
+
+    m_controller->setZoomInPossible(isZoomInPossible());
+    m_controller->setZoomOutPossible(isZoomOutPossible());
 }
 
-int DolphinIconsView::decreasedIconSize(int size) const
+KFileItem DolphinIconsView::itemForIndex(const QModelIndex& index) const
 {
-    int decSize = 0;
-    switch (size) {
-        case K3Icon::SizeSmallMedium: decSize = K3Icon::SizeSmall; break;
-        case K3Icon::SizeMedium: decSize = K3Icon::SizeSmallMedium; break;
-        case K3Icon::SizeLarge: decSize = K3Icon::SizeMedium; break;
-        case K3Icon::SizeHuge: decSize = K3Icon::SizeLarge; break;
-        case K3Icon::SizeEnormous: decSize = K3Icon::SizeHuge; break;
-        default: assert(false); break;
-    }
-    return decSize;
+    QAbstractProxyModel* proxyModel = static_cast<QAbstractProxyModel*>(model());
+    KDirModel* dirModel = static_cast<KDirModel*>(proxyModel->sourceModel());
+    const QModelIndex dirIndex = proxyModel->mapToSource(index);
+    return dirModel->itemForIndex(dirIndex);
 }
 
+
 #include "dolphiniconsview.moc"