]> cloud.milkyroute.net Git - dolphin.git/blobdiff - src/dolphiniconsview.cpp
Blend in a toggle button when hovering items. This allows selecting items without...
[dolphin.git] / src / dolphiniconsview.cpp
index 0c888d8714ca9f566828d8414eabb596cba294aa..18d4accec5291f74bb85c1c26523d07f82bf8cfa 100644 (file)
@@ -23,7 +23,9 @@
 #include "dolphincontroller.h"
 #include "dolphinsettings.h"
 #include "dolphin_iconsmodesettings.h"
+#include "dolphin_generalsettings.h"
 #include "draganddrophelper.h"
+#include "selectionmanager.h"
 
 #include <kcategorizedsortfilterproxymodel.h>
 #include <kdialog.h>
@@ -33,6 +35,7 @@
 #include <QApplication>
 #include <QPainter>
 #include <QPoint>
+#include <QScrollBar>
 
 DolphinIconsView::DolphinIconsView(QWidget* parent, DolphinController* controller) :
     KCategorizedView(parent),
@@ -64,6 +67,11 @@ DolphinIconsView::DolphinIconsView(QWidget* parent, DolphinController* controlle
     if (KGlobalSettings::singleClick()) {
         connect(this, SIGNAL(clicked(const QModelIndex&)),
                 this, SLOT(triggerItem(const QModelIndex&)));
+        if (DolphinSettings::instance().generalSettings()->showSelectionToggle()) {
+            SelectionManager* selManager = new SelectionManager(this);
+            connect(selManager, SIGNAL(selectionChanged()),
+                    this, SLOT(requestActivation()));
+        }
     } else {
         connect(this, SIGNAL(doubleClicked(const QModelIndex&)),
                 this, SLOT(triggerItem(const QModelIndex&)));
@@ -78,8 +86,8 @@ DolphinIconsView::DolphinIconsView(QWidget* parent, DolphinController* controlle
     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(view, SIGNAL(additionalInfoChanged()),
+            this, SLOT(slotAdditionalInfoChanged()));
 
     connect(this, SIGNAL(entered(const QModelIndex&)),
             this, SLOT(slotEntered(const QModelIndex&)));
@@ -225,17 +233,16 @@ void DolphinIconsView::dragMoveEvent(QDragMoveEvent* event)
     setDirtyRegion(m_dropRect);
 
     m_dropRect.setSize(QSize()); // set as invalid
-    bool destIsDir = false;
     if (index.isValid()) {
         const KFileItem item = itemForIndex(index);
         if (!item.isNull() && item.isDir()) {
             m_dropRect = visualRect(index);
-            destIsDir = true;
+        } else {
+            m_dropRect.setSize(QSize()); // set as invalid
         }
-    } else { // dropping on viewport
-        destIsDir = true;
     }
-    if (destIsDir && event->mimeData()->hasUrls()) {
+    if (event->mimeData()->hasUrls()) {
+        // accept url drops, independently from the destination item
         event->acceptProposedAction();
     }
 
@@ -268,7 +275,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 = viewOptions().palette.brush(QPalette::Normal, QPalette::Highlight);
-        DragAndDropHelper::drawHoverIndication(viewport(), m_dropRect, brush);
+        DragAndDropHelper::drawHoverIndication(this, m_dropRect, brush);
     }
 }
 
@@ -286,6 +293,25 @@ void DolphinIconsView::keyPressEvent(QKeyEvent* event)
     }
 }
 
+void DolphinIconsView::wheelEvent(QWheelEvent* event)
+{
+    KCategorizedView::wheelEvent(event);
+
+    // if the icons are aligned left to right, the vertical wheel event should
+    // be applied to the horizontal scrollbar
+    const IconsModeSettings* settings = DolphinSettings::instance().iconsModeSettings();
+    const bool scrollHorizontal = (event->orientation() == Qt::Vertical) &&
+                                  (settings->arrangement() == QListView::LeftToRight);
+    if (scrollHorizontal) {
+        QWheelEvent horizEvent(event->pos(),
+                               event->delta(),
+                               event->buttons(),
+                               event->modifiers(),
+                               Qt::Horizontal);
+        QApplication::sendEvent(horizontalScrollBar(), &horizEvent);
+    }
+}
+
 void DolphinIconsView::triggerItem(const QModelIndex& index)
 {
     m_controller->triggerItem(itemForIndex(index));
@@ -302,15 +328,11 @@ void DolphinIconsView::slotShowPreviewChanged()
     updateGridSize(view->showPreview(), additionalInfoCount());
 }
 
-void DolphinIconsView::slotAdditionalInfoChanged(const KFileItemDelegate::InformationList& info)
+void DolphinIconsView::slotAdditionalInfoChanged()
 {
-    const IconsModeSettings* settings = DolphinSettings::instance().iconsModeSettings();
-    if (!settings->showAdditionalInfo()) {
-        return;
-    }
-
-    const bool showPreview = m_controller->dolphinView()->showPreview();
-    updateGridSize(showPreview, info.count());
+    const DolphinView* view = m_controller->dolphinView();
+    const bool showPreview = view->showPreview();
+    updateGridSize(showPreview, view->additionalInfo().count());
 }
 
 void DolphinIconsView::zoomIn()
@@ -374,6 +396,11 @@ void DolphinIconsView::zoomOut()
     }
 }
 
+void DolphinIconsView::requestActivation()
+{
+    m_controller->requestActivation();
+}
+
 bool DolphinIconsView::isZoomInPossible() const
 {
     IconsModeSettings* settings = DolphinSettings::instance().iconsModeSettings();
@@ -436,6 +463,7 @@ void DolphinIconsView::updateGridSize(bool showPreview, int additionalInfoCount)
 
         size = previewSize;
     }
+    setIconSize(QSize(size, size));
 
     Q_ASSERT(additionalInfoCount >= 0);
     itemHeight += additionalInfoCount * m_font.pointSize() * 2;
@@ -469,8 +497,7 @@ KFileItem DolphinIconsView::itemForIndex(const QModelIndex& index) const
 int DolphinIconsView::additionalInfoCount() const
 {
     const DolphinView* view = m_controller->dolphinView();
-    const IconsModeSettings* settings = DolphinSettings::instance().iconsModeSettings();
-    return settings->showAdditionalInfo() ? view->additionalInfo().count() : 0;
+    return view->additionalInfo().count();
 }
 
 #include "dolphiniconsview.moc"