]> cloud.milkyroute.net Git - dolphin.git/commitdiff
Added the functionality to activate items by pressing 'enter' or 'return' key on...
authorTirtha Chatterjee <tirtha.p.chatterjee@gmail.com>
Mon, 29 Aug 2011 15:43:36 +0000 (21:13 +0530)
committerTirtha Chatterjee <tirtha.p.chatterjee@gmail.com>
Mon, 29 Aug 2011 15:43:36 +0000 (21:13 +0530)
REVIEW: 102450

src/kitemviews/kitemlistcontroller.cpp
src/kitemviews/kitemlistcontroller.h
src/views/dolphinview.cpp
src/views/dolphinview.h

index 207535ce13d2689a77f20498c883a172069f5d80..615cc9c6d04a0b6db9c46a2500d160b9942785b7 100644 (file)
@@ -200,6 +200,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();
@@ -240,7 +245,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);
@@ -411,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();
@@ -439,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;
 }
index 04d49854e348ef05610304fc0b2d18e497a0ca9d..2e33948aa7fa5ab1bfdd1e45428e93f7745d6ded 100644 (file)
@@ -105,13 +105,14 @@ public:
     virtual bool processEvent(QEvent* event, const QTransform& transform);
 
 signals:
-    void itemClicked(int index, Qt::MouseButton button);
+    void itemActivated(int index);
+    void itemMiddleClicked(int index);
+    void contextMenuRequested(int index, const QPointF& pos);
 
     /**
      * Is emitted if the item with the index \p index gets hovered.
      */
     void itemHovered(int index);
-
     /**
      * Is emitted if the item with the index \p index gets unhovered.
      * It is assured that the signal itemHovered() for this index
index 959e4da6e2e049a88084b28068a321c7d9e8ebbb..5cb3d90b539e477c0762e7e0973218c8a40dcdb6 100644 (file)
@@ -164,8 +164,10 @@ DolphinView::DolphinView(const KUrl& url, QWidget* parent) :
 
     KItemListController* controller = m_container->controller();
     controller->setSelectionBehavior(KItemListController::MultiSelection);
-    connect(controller, SIGNAL(itemClicked(int,Qt::MouseButton)),
-            this, SLOT(slotItemClicked(int,Qt::MouseButton)));
+    connect(controller, SIGNAL(itemActivated(int)),
+            this, SLOT(slotItemActivated(int)));
+    connect(controller, SIGNAL(itemMiddleClicked(int)), this, SLOT(slotItemMiddleClicked(int)));
+    connect(controller, SIGNAL(contextMenuRequested(int,QPointF)), this, SLOT(slotContextMenuRequested(int,QPointF)));
     connect(controller, SIGNAL(itemExpansionToggleClicked(int)), this, SLOT(slotItemExpansionToggleClicked(int)));
     connect(controller, SIGNAL(itemHovered(int)), this, SLOT(slotItemHovered(int)));
     connect(controller, SIGNAL(itemUnhovered(int)), this, SLOT(slotItemUnhovered(int)));
@@ -677,7 +679,7 @@ void DolphinView::contextMenuEvent(QContextMenuEvent* event)
     const KItemListView* view = m_container->controller()->view();
     if (view->itemAt(pos) < 0) {
         // Only open the context-menu if the cursor is above the viewport
-        // (the context-menu for items is handled in slotItemClicked())
+        // (the context-menu for items is handled in slotContextMenuRequested())
         requestContextMenu(KFileItem(), url(), QList<QAction*>());
     }
 }
@@ -687,22 +689,42 @@ void DolphinView::activate()
     setActive(true);
 }
 
-void DolphinView::slotItemClicked(int index, Qt::MouseButton button)
+void DolphinView::slotItemActivated(int index)
+{
+    const QSet<int> selectedItems = m_container->controller()->selectionManager()->selectedItems();
+    if (selectedItems.isEmpty())
+        return;
+    if (selectedItems.count() == 1) {
+        emit itemTriggered(fileItemModel()->fileItem(index)); // caught by DolphinViewContainer or DolphinPart
+    }
+    else {
+        foreach (int i, selectedItems) {
+            const KFileItem fileItem;
+            fileItem = fileItemModel()->fileItem(i);
+            if (fileItem.isDir()) {
+                emit tabRequested(fileItem.url());
+            } else {
+                emit itemTriggered(fileItem);
+            }
+        }
+    }
+}
+
+void DolphinView::slotItemMiddleClicked(int index)
 {
     const KFileItem item = fileItemModel()->fileItem(index);
+    if (item.isDir() || isTabsForFilesEnabled()) {
+        emit tabRequested(item.url());
+    }
+}
 
-    if (button & Qt::LeftButton) {
-        emit itemTriggered(item); // caught by DolphinViewContainer or DolphinPart
-    } else if (button & Qt::MidButton) {
-        if (item.isDir() || isTabsForFilesEnabled()) {
-            emit tabRequested(item.url());
-        }
-    } else if (button & Qt::RightButton) {
-        if (GeneralSettings::showToolTips()) {
-            m_toolTipManager->hideToolTip();
-        }
-        emit requestContextMenu(item, url(), QList<QAction*>());
+void DolphinView::slotContextMenuRequested(int index, const QPointF& pos)
+{
+    if (GeneralSettings::showToolTips()) {
+        m_toolTipManager->hideToolTip();
     }
+    const KFileItem item = fileItemModel()->fileItem(index);
+    emit requestContextMenu(item, url(), QList<QAction*>());
 }
 
 void DolphinView::slotItemExpansionToggleClicked(int index)
index 437f12f3919bc269a3f6aba0e7629ccfdff4f9d4..7a2db688952b420729b33c4564b2105cfbc6df9e 100644 (file)
@@ -552,7 +552,9 @@ private slots:
      */
     void activate();
 
-    void slotItemClicked(int index, Qt::MouseButton button);
+    void slotItemActivated(int index);
+    void slotItemMiddleClicked(int index);
+    void slotContextMenuRequested(int index, const QPointF& pos);
     void slotItemExpansionToggleClicked(int index);
     void slotItemHovered(int index);
     void slotItemUnhovered(int index);