]> cloud.milkyroute.net Git - dolphin.git/blobdiff - src/kitemviews/kitemlistcontroller.cpp
Fixed a trivial bug that was breaking build.
[dolphin.git] / src / kitemviews / kitemlistcontroller.cpp
index 5eae95e6dda8afe2876e8f525b7efb26c63c6c47..615cc9c6d04a0b6db9c46a2500d160b9942785b7 100644 (file)
@@ -25,6 +25,7 @@
 #include "kitemlistview.h"
 #include "kitemlistrubberband_p.h"
 #include "kitemlistselectionmanager.h"
+#include "kitemlistkeyboardsearchmanager_p.h"
 
 #include <QApplication>
 #include <QDrag>
@@ -42,10 +43,12 @@ KItemListController::KItemListController(QObject* parent) :
     m_model(0),
     m_view(0),
     m_selectionManager(new KItemListSelectionManager(this)),
+    m_keyboardManager(new KItemListKeyboardSearchManager(this)),
     m_pressedIndex(-1),
     m_pressedMousePos(),
     m_oldSelection()
 {
+    connect(m_keyboardManager, SIGNAL(requestItemActivation(QString,bool)), this, SLOT(slotKeyboardActivationRequested(QString,bool)));
 }
 
 KItemListController::~KItemListController()
@@ -197,15 +200,22 @@ bool KItemListController::keyPressEvent(QKeyEvent* event)
         }
         break;
 
+    case Qt::Key_Enter:
+    case Qt::Key_Return:
+        emit itemActivated(index);
+        break;
+
     case Qt::Key_Space:
         if (controlPressed) {
             m_selectionManager->endAnchoredSelection();
             m_selectionManager->setSelected(index, 1, KItemListSelectionManager::Toggle);
             m_selectionManager->beginAnchoredSelection(index);
+            break;
         }
 
     default:
-        break;
+        m_keyboardManager->addKeys(event->text());
+        return false;
     }
 
     if (m_selectionManager->currentItem() != index) {
@@ -227,6 +237,27 @@ bool KItemListController::keyPressEvent(QKeyEvent* event)
     return true;
 }
 
+void KItemListController::slotKeyboardActivationRequested(const QString& text, bool searchFromNextItem)
+{
+    if (!m_model) {
+        return;
+    }
+    const int currentIndex = m_selectionManager->currentItem();
+    int index;
+    if (searchFromNextItem) {
+        index = m_model->indexForKeyboardSearch(text, (currentIndex + 1) % m_model->count());
+    }
+    else {
+        index = m_model->indexForKeyboardSearch(text, currentIndex);
+    }
+    if (index >= 0) {
+        m_selectionManager->setCurrentItem(index);
+        m_selectionManager->clearSelection();
+        m_selectionManager->setSelected(index, 1);
+        m_selectionManager->beginAnchoredSelection(index);
+    }
+}
+
 bool KItemListController::inputMethodEvent(QInputMethodEvent* event)
 {
     Q_UNUSED(event);
@@ -385,18 +416,24 @@ bool KItemListController::mouseReleaseEvent(QGraphicsSceneMouseEvent* event, con
             m_selectionManager->setSelectedItems(QSet<int>() << index);
         }
 
-        bool emitItemClicked = true;
         if (event->button() & Qt::LeftButton) {
+            bool emitItemActivated = true;
             if (m_view->isAboveExpansionToggle(index, pos)) {
                 emit itemExpansionToggleClicked(index);
-                emitItemClicked = false;
-            } else if (shiftOrControlPressed || !KGlobalSettings::singleClick()) {
-                emitItemClicked = false;
+                emitItemActivated = false;
+            } else if (shiftOrControlPressed) {
+                // The mouse click should only update the selection, not trigger the item
+                emitItemActivated = false;
+            } else if (!KGlobalSettings::singleClick()) {
+                emitItemActivated = false;
             }
-        }
-
-        if (emitItemClicked) {
-            emit itemClicked(index, event->button());
+            if (emitItemActivated) {
+                emit itemActivated(index);
+            }
+        } else if (event->button() & Qt::MidButton) {
+            emit itemMiddleClicked(index);
+        } else if (event->button() & Qt::RightButton) {
+            emit contextMenuRequested(index, QPointF(event->pos()));
         }
     } else if (clearSelection) {
         m_selectionManager->clearSelection();
@@ -413,11 +450,11 @@ bool KItemListController::mouseDoubleClickEvent(QGraphicsSceneMouseEvent* event,
     const QPointF pos = transform.map(event->pos());
     const int index = m_view->itemAt(pos);
 
-    bool emitItemClicked = !KGlobalSettings::singleClick() &&
+    bool emitItemActivated = !KGlobalSettings::singleClick() &&
                            (event->button() & Qt::LeftButton) &&
                            index >= 0 && index < m_model->count();
-    if (emitItemClicked) {
-        emit itemClicked(index, event->button());
+    if (emitItemActivated) {
+        emit itemActivated(index);
     }
     return false;
 }
@@ -678,7 +715,16 @@ void KItemListController::slotRubberBandChanged()
         }
     } while (!selectionFinished);
 
-    m_selectionManager->setSelectedItems(selectedItems + m_oldSelection);
+    if (QApplication::keyboardModifiers() & Qt::ControlModifier) {
+        // If Control is pressed, the selection state of all items in the rubberband is toggled.
+        // Therefore, the new selection contains:
+        // 1. All previously selected items which are not inside the rubberband, and
+        // 2. all items inside the rubberband which have not been selected previously.
+        m_selectionManager->setSelectedItems((m_oldSelection - selectedItems) + (selectedItems - m_oldSelection));
+    }
+    else {
+        m_selectionManager->setSelectedItems(selectedItems + m_oldSelection);
+    }
 }
 
 bool KItemListController::startDragging()