]> cloud.milkyroute.net Git - dolphin.git/blobdiff - src/dolphiniconsview.cpp
Also allow to use the selection toggle when double click is used. This allows to...
[dolphin.git] / src / dolphiniconsview.cpp
index dd83de37ecb383fb9d1c552c21511527a70f86af..059ce89ab1c6b2907386ca75de64bbdf28131ea2 100644 (file)
 
 #include <QAbstractProxyModel>
 #include <QApplication>
-#include <QPainter>
-#include <QPoint>
 #include <QScrollBar>
 
 DolphinIconsView::DolphinIconsView(QWidget* parent, DolphinController* controller) :
     KCategorizedView(parent),
+    m_enableScrollTo(false),
     m_controller(controller),
+    m_selectionManager(0),
     m_categoryDrawer(0),
     m_font(),
     m_decorationSize(),
@@ -55,6 +55,7 @@ DolphinIconsView::DolphinIconsView(QWidget* parent, DolphinController* controlle
     setSpacing(KDialog::spacingHint());
     setMovement(QListView::Static);
     setDragEnabled(true);
+    setEditTriggers(QAbstractItemView::NoEditTriggers);
     viewport()->setAcceptDrops(true);
 
     setMouseTracking(true);
@@ -66,17 +67,19 @@ DolphinIconsView::DolphinIconsView(QWidget* parent, DolphinController* controlle
     if (KGlobalSettings::singleClick()) {
         connect(this, SIGNAL(clicked(const QModelIndex&)),
                 controller, SLOT(triggerItem(const QModelIndex&)));
-        if (DolphinSettings::instance().generalSettings()->showSelectionToggle()) {
-            SelectionManager* selManager = new SelectionManager(this);
-            connect(selManager, SIGNAL(selectionChanged()),
-                    this, SLOT(requestActivation()));
-            connect(m_controller, SIGNAL(urlChanged(const KUrl&)),
-                    selManager, SLOT(reset()));
-        }
     } else {
         connect(this, SIGNAL(doubleClicked(const QModelIndex&)),
                 controller, SLOT(triggerItem(const QModelIndex&)));
     }
+
+    if (DolphinSettings::instance().generalSettings()->showSelectionToggle()) {
+        m_selectionManager = new SelectionManager(this);
+        connect(m_selectionManager, SIGNAL(selectionChanged()),
+                this, SLOT(requestActivation()));
+        connect(m_controller, SIGNAL(urlChanged(const KUrl&)),
+                m_selectionManager, SLOT(reset()));
+    }
+
     connect(this, SIGNAL(entered(const QModelIndex&)),
             controller, SLOT(emitItemEntered(const QModelIndex&)));
     connect(this, SIGNAL(viewportEntered()),
@@ -133,6 +136,19 @@ DolphinIconsView::~DolphinIconsView()
     m_categoryDrawer = 0;
 }
 
+void DolphinIconsView::scrollTo(const QModelIndex& index, ScrollHint hint)
+{
+    // Enable the QListView implementation of scrollTo() only if it has been
+    // triggered by a key press. Otherwise QAbstractItemView wants to scroll to the current
+    // index each time the layout has been changed. This becomes an issue when
+    // previews are loaded and the scrollbar is used: the scrollbar will always
+    // be reset to 0 on each new preview.
+    if (m_enableScrollTo || (state() != QAbstractItemView::NoState)) {
+        KCategorizedView::scrollTo(index, hint);
+        m_enableScrollTo = false;
+    }
+}
+
 void DolphinIconsView::dataChanged(const QModelIndex& topLeft, const QModelIndex& bottomRight)
 {
     KCategorizedView::dataChanged(topLeft, bottomRight);
@@ -165,7 +181,20 @@ void DolphinIconsView::contextMenuEvent(QContextMenuEvent* event)
 void DolphinIconsView::mousePressEvent(QMouseEvent* event)
 {
     m_controller->requestActivation();
-    if (!indexAt(event->pos()).isValid()) {
+    const QModelIndex index = indexAt(event->pos());
+    if (index.isValid() && (event->button() == Qt::LeftButton)) {
+        // TODO: It should not be necessary to manually set the dragging state, but I could
+        // not reproduce this issue with a Qt-only example yet to find the root cause.
+        // Issue description: start Dolphin, split the view and drag an item from the
+        // inactive view to the active view by a very fast mouse movement. Result:
+        // the item gets selected instead of being dragged...
+        setState(QAbstractItemView::DraggingState);
+    }
+
+    if (!index.isValid()) {
+        if (QApplication::mouseButtons() & Qt::MidButton) {
+            m_controller->replaceUrlByClipboard();
+        }
         const Qt::KeyboardModifiers modifier = QApplication::keyboardModifiers();
         if (!(modifier & Qt::ShiftModifier) && !(modifier & Qt::ControlModifier)) {
             clearSelection();
@@ -242,10 +271,15 @@ void DolphinIconsView::keyPressEvent(QKeyEvent* event)
 {
     KCategorizedView::keyPressEvent(event);
     m_controller->handleKeyPressEvent(event);
+    m_enableScrollTo = true; // see DolphinIconsView::scrollTo()
 }
 
 void DolphinIconsView::wheelEvent(QWheelEvent* event)
 {
+    if (m_selectionManager != 0) {
+        m_selectionManager->reset();
+    }
+
     // let Ctrl+wheel events propagate to the DolphinView for icon zooming
     if (event->modifiers() & Qt::ControlModifier) {
         event->ignore();
@@ -275,6 +309,15 @@ void DolphinIconsView::showEvent(QShowEvent* event)
     KCategorizedView::showEvent(event);
 }
 
+void DolphinIconsView::leaveEvent(QEvent* event)
+{
+    KCategorizedView::leaveEvent(event);
+    // if the mouse is above an item and moved very fast outside the widget,
+    // no viewportEntered() signal might be emitted although the mouse has been moved
+    // above the viewport
+    m_controller->emitViewportEntered();
+}
+
 void DolphinIconsView::slotShowPreviewChanged()
 {
     const DolphinView* view = m_controller->dolphinView();
@@ -443,6 +486,10 @@ void DolphinIconsView::updateGridSize(bool showPreview, int additionalInfoCount)
     if (delegate != 0) {
         delegate->setMaximumSize(m_itemSize);
     }
+
+    if (m_selectionManager != 0) {
+        m_selectionManager->reset();
+    }
 }
 
 int DolphinIconsView::additionalInfoCount() const