]> cloud.milkyroute.net Git - dolphin.git/blobdiff - src/dolphiniconsview.cpp
Instead of using the ListMode of the icon view for the left to right alignment, still...
[dolphin.git] / src / dolphiniconsview.cpp
index 98d1a05b12f48aed15925320eb27a4620c9c25fd..d89bb365040cada6efe19be047e2ceb39595a74c 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  *
  ***************************************************************************/
 
 #include "dolphiniconsview.h"
-#include "dolphinview.h"
 
+#include "dolphincontroller.h"
+#include "dolphinsettings.h"
+
+#include "dolphin_iconsmodesettings.h"
+
+#include <assert.h>
 #include <kdirmodel.h>
 #include <kfileitem.h>
 
-DolphinIconsView::DolphinIconsView(DolphinView* parent) :
+#include <QAbstractProxyModel>
+
+DolphinIconsView::DolphinIconsView(QWidget* parent, DolphinController* controller) :
     QListView(parent),
-    m_parentView( parent )
+    m_controller(controller)
 {
+    assert(controller != 0);
+    setViewMode(QListView::IconMode);
     setResizeMode(QListView::Adjust);
+
+    connect(this, SIGNAL(clicked(const QModelIndex&)),
+            controller, SLOT(triggerItem(const QModelIndex&)));
+
+    // apply the icons mode settings to the widget
+    const IconsModeSettings* settings = DolphinSettings::instance().iconsModeSettings();
+    assert(settings != 0);
+
+    setGridSize(QSize(settings->gridWidth(), settings->gridHeight()));
+    setSpacing(settings->gridSpacing());
+
+    m_viewOptions = QListView::viewOptions();
+    m_viewOptions.font = QFont(settings->fontFamily(), settings->fontSize());
+    const int iconSize = settings->iconSize();
+    m_viewOptions.decorationSize = QSize(iconSize, iconSize);
+
+    if (settings->arrangement() == QListView::TopToBottom) {
+        setFlow(QListView::TopToBottom);
+        m_viewOptions.decorationPosition = QStyleOptionViewItem::Top;
+    }
+    else {
+        setFlow(QListView::LeftToRight);
+        m_viewOptions.decorationPosition = QStyleOptionViewItem::Left;
+    }
 }
 
 DolphinIconsView::~DolphinIconsView()
@@ -37,38 +69,38 @@ DolphinIconsView::~DolphinIconsView()
 
 QStyleOptionViewItem DolphinIconsView::viewOptions() const
 {
-    return QListView::viewOptions();
-
-    // TODO: the view options should been read from the settings;
-    // the following code is just for testing...
-    //QStyleOptionViewItem options = QListView::viewOptions();
-    //options.decorationAlignment = Qt::AlignRight;
-    //options.decorationPosition = QStyleOptionViewItem::Right;
-    //options.decorationSize = QSize(100, 100);
-    //options.showDecorationSelected = true;
-    //options.state = QStyle::State_MouseOver;
-    //return options;
+    return m_viewOptions;
 }
 
 void DolphinIconsView::contextMenuEvent(QContextMenuEvent* event)
 {
     QListView::contextMenuEvent(event);
+    m_controller->triggerContextMenuRequest(event->pos());
+}
 
-    KFileItem* item = 0;
+void DolphinIconsView::mouseReleaseEvent(QMouseEvent* event)
+{
+    QListView::mouseReleaseEvent(event);
+    m_controller->triggerActivation();
+}
 
-    const QModelIndex index = indexAt(event->pos());
-    if (index.isValid()) {
-        KDirModel* dirModel = static_cast<KDirModel*>(model());
-        item = dirModel->itemForIndex(index);
+void DolphinIconsView::dragEnterEvent(QDragEnterEvent* event)
+{
+    if (event->mimeData()->hasUrls()) {
+        event->acceptProposedAction();
     }
-
-    m_parentView->openContextMenu(item, event->globalPos());
 }
 
-void DolphinIconsView::mouseReleaseEvent(QMouseEvent* event)
+void DolphinIconsView::dropEvent(QDropEvent* event)
 {
-    QListView::mouseReleaseEvent(event);
-    m_parentView->declareViewActive();
+    const KUrl::List urls = KUrl::List::fromMimeData(event->mimeData());
+    if (urls.isEmpty() || (event->source() == this)) {
+        QListView::dropEvent(event);
+    }
+    else {
+        event->acceptProposedAction();
+        m_controller->indicateDroppedUrls(urls, event->pos());
+    }
 }
 
 #include "dolphiniconsview.moc"