]> cloud.milkyroute.net Git - dolphin.git/blobdiff - src/kitemviews/kitemlistcontroller.cpp
DolphinView zoom with CTRL+MouseWheel REVIEW: 102490
[dolphin.git] / src / kitemviews / kitemlistcontroller.cpp
index 207535ce13d2689a77f20498c883a172069f5d80..09c7d8d46487b8449af1d6b9f9805a18d44c7ff3 100644 (file)
@@ -48,7 +48,8 @@ KItemListController::KItemListController(QObject* parent) :
     m_pressedMousePos(),
     m_oldSelection()
 {
-    connect(m_keyboardManager, SIGNAL(requestItemActivation(QString,bool)), this, SLOT(slotKeyboardActivationRequested(QString,bool)));
+    connect(m_keyboardManager, SIGNAL(changeCurrentItem(QString,bool)),
+            this, SLOT(slotChangeCurrentItem(QString,bool)));
 }
 
 KItemListController::~KItemListController()
@@ -200,6 +201,11 @@ 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();
@@ -232,7 +238,7 @@ bool KItemListController::keyPressEvent(QKeyEvent* event)
     return true;
 }
 
-void KItemListController::slotKeyboardActivationRequested(const QString& text, bool searchFromNextItem)
+void KItemListController::slotChangeCurrentItem(const QString& text, bool searchFromNextItem)
 {
     if (!m_model) {
         return;
@@ -240,7 +246,7 @@ void KItemListController::slotKeyboardActivationRequested(const QString& text, b
     const int currentIndex = m_selectionManager->currentItem();
     int index;
     if (searchFromNextItem) {
-         index = m_model->indexForKeyboardSearch(text, (currentIndex + 1) % m_model->count());
+        index = m_model->indexForKeyboardSearch(text, (currentIndex + 1) % m_model->count());
     }
     else {
         index = m_model->indexForKeyboardSearch(text, currentIndex);
@@ -301,6 +307,11 @@ bool KItemListController::mousePressEvent(QGraphicsSceneMouseEvent* event, const
             if (controlPressed) {
                 m_selectionManager->setSelected(m_pressedIndex, 1, KItemListSelectionManager::Toggle);
                 m_selectionManager->beginAnchoredSelection(m_pressedIndex);
+            } else if (event->buttons() & Qt::RightButton) {
+                // Only clear the selection if a context menu is requested above a non-selected item
+                if (!m_selectionManager->selectedItems().contains(m_pressedIndex)) {
+                    m_selectionManager->setSelectedItems(QSet<int>() << m_pressedIndex);
+                }
             } else if (!shiftPressed || !m_selectionManager->isAnchoredSelectionActive()) {
                 // Select the pressed item and start a new anchored selection
                 m_selectionManager->setSelected(m_pressedIndex, 1, KItemListSelectionManager::Select);
@@ -315,6 +326,10 @@ bool KItemListController::mousePressEvent(QGraphicsSceneMouseEvent* event, const
 
         return true;
     } else {
+        if (event->buttons() & Qt::RightButton) {
+            m_selectionManager->clearSelection();
+        }
+
         KItemListRubberBand* rubberBand = m_view->rubberBand();
         QPointF startPos = m_pressedMousePos;
         if (m_view->scrollOrientation() == Qt::Vertical) {
@@ -386,7 +401,7 @@ bool KItemListController::mouseReleaseEvent(QGraphicsSceneMouseEvent* event, con
     const bool shiftOrControlPressed = event->modifiers() & Qt::ShiftModifier ||
                                        event->modifiers() & Qt::ControlModifier;
 
-    bool clearSelection = !shiftOrControlPressed && !m_dragging && !(event->button() == Qt::RightButton);
+    bool clearSelection = !shiftOrControlPressed && !m_dragging && event->button() != Qt::RightButton;
 
     KItemListRubberBand* rubberBand = m_view->rubberBand();
     if (rubberBand->isActive()) {
@@ -411,18 +426,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();
@@ -439,11 +460,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;
 }