]> cloud.milkyroute.net Git - dolphin.git/blobdiff - src/dolphiniconsview.cpp
reactivate ScrollPerPixel again, as the Qt-patch for "divide by zero" has been applie...
[dolphin.git] / src / dolphiniconsview.cpp
index 394dae3177a19ec1f5a774f0f60c8b254c27d61d..3da04c113a69cbd46dde69239519b5f13dc2483d 100644 (file)
@@ -19,9 +19,9 @@
 
 #include "dolphiniconsview.h"
 
+#include "dolphincategorydrawer.h"
 #include "dolphincontroller.h"
 #include "dolphinsettings.h"
-#include "dolphinitemcategorizer.h"
 
 #include "dolphin_iconsmodesettings.h"
 
@@ -35,6 +35,7 @@
 DolphinIconsView::DolphinIconsView(QWidget* parent, DolphinController* controller) :
     KCategorizedView(parent),
     m_controller(controller),
+    m_categoryDrawer(0),
     m_itemSize(),
     m_dragging(false),
     m_dropRect()
@@ -46,6 +47,10 @@ DolphinIconsView::DolphinIconsView(QWidget* parent, DolphinController* controlle
     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&)),
                 controller, SLOT(triggerItem(const QModelIndex&)));
@@ -89,43 +94,44 @@ DolphinIconsView::DolphinIconsView(QWidget* parent, DolphinController* controlle
         m_viewOptions.decorationPosition = QStyleOptionViewItem::Left;
         m_viewOptions.displayAlignment = Qt::AlignLeft | Qt::AlignVCenter;
     }
+
+    m_categoryDrawer = new DolphinCategoryDrawer();
+    setCategoryDrawer(m_categoryDrawer);
 }
 
 DolphinIconsView::~DolphinIconsView()
 {
+    delete m_categoryDrawer;
+    m_categoryDrawer = 0;
 }
 
 QRect DolphinIconsView::visualRect(const QModelIndex& index) const
 {
-    if (itemCategorizer() == 0) {
-        const bool leftToRightFlow = (flow() == QListView::LeftToRight);
-
-        QRect itemRect = KCategorizedView::visualRect(index);
-        const int maxWidth  = m_itemSize.width();
-        const int maxHeight = m_itemSize.height();
-
-        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);
-        }
+    const bool leftToRightFlow = (flow() == QListView::LeftToRight);
 
-        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);
+    QRect itemRect = KCategorizedView::visualRect(index);
+    const int maxWidth  = m_itemSize.width();
+    const int maxHeight = m_itemSize.height();
+
+    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);
+    }
 
-        return itemRect;
+    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 KCategorizedView::visualRect(index);
+    return itemRect;
 }
 
 QStyleOptionViewItem DolphinIconsView::viewOptions() const
@@ -186,11 +192,13 @@ void DolphinIconsView::dropEvent(QDropEvent* event)
         const KUrl::List urls = KUrl::List::fromMimeData(event->mimeData());
         if (!urls.isEmpty()) {
             m_controller->indicateDroppedUrls(urls,
+                                              m_controller->url(),
                                               indexAt(event->pos()),
                                               event->source());
             event->acceptProposedAction();
         }
     }
+
     KCategorizedView::dropEvent(event);
     m_dragging = false;
 }
@@ -206,6 +214,20 @@ void DolphinIconsView::paintEvent(QPaintEvent* event)
     }
 }
 
+void DolphinIconsView::keyPressEvent(QKeyEvent* event)
+{
+    KCategorizedView::keyPressEvent(event);
+
+    const QItemSelectionModel* selModel = selectionModel();
+    const QModelIndex currentIndex = selModel->currentIndex();
+    const bool triggerItem = currentIndex.isValid()
+                             && (event->key() == Qt::Key_Return)
+                             && (selModel->selectedIndexes().count() <= 1);
+    if (triggerItem) {
+        m_controller->triggerItem(currentIndex);
+    }
+}
+
 void DolphinIconsView::slotShowPreviewChanged(bool showPreview)
 {
     updateGridSize(showPreview, m_controller->showAdditionalInfo());