]> cloud.milkyroute.net Git - dolphin.git/commitdiff
Enable "menu key" functionality
authorPeter Penz <peter.penz19@gmail.com>
Wed, 7 Dec 2011 22:04:09 +0000 (23:04 +0100)
committerPeter Penz <peter.penz19@gmail.com>
Wed, 7 Dec 2011 22:10:00 +0000 (23:10 +0100)
Bring back the functionality that a context-menu is opened if the "menu key" has been pressed. In opposite to Dolphin 1.7 the context-menu is shown above the selected item and not on the (probably unrelated) mouse position.

A new method KItemListView::itemContextRect() has been introduced: The method is now also used as reference for tooltips which fixes the issue that tooltips had a wrong horizontal alignment in the details-view.

BUG: 288366
FIXED-IN: 4.8.0

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

index e77de292ae48c2edb4df098fc816059b50a95d8d..90127aa17f8d79f5b61c58a0585b2852196e8b88 100644 (file)
@@ -30,7 +30,9 @@
 #include <QApplication>
 #include <QDrag>
 #include <QEvent>
+#include <QGraphicsScene>
 #include <QGraphicsSceneEvent>
+#include <QGraphicsView>
 #include <QMimeData>
 #include <QTimer>
 
@@ -218,8 +220,7 @@ bool KItemListController::keyPressEvent(QKeyEvent* event)
         if (index + itemsPerRow < itemCount) {
             // We are not in the last row yet.
             index += itemsPerRow;
-        }
-        else {
+        } else {
             // We are either in the last row already, or we are in the second-last row,
             // and there is no item below the current item.
             // In the latter case, we jump to the very last item.
@@ -250,8 +251,33 @@ bool KItemListController::keyPressEvent(QKeyEvent* event)
             m_selectionManager->endAnchoredSelection();
             m_selectionManager->setSelected(index, 1, KItemListSelectionManager::Toggle);
             m_selectionManager->beginAnchoredSelection(index);
-            break;
+        } else {
+            m_keyboardManager->addKeys(event->text());
         }
+        break;
+
+    case Qt::Key_Menu: {
+        // Emit the signal itemContextMenuRequested() in case if at least one
+        // item is selected. Otherwise the signal viewContextMenuRequested() will be emitted.
+        const QSet<int> selectedItems = m_selectionManager->selectedItems();
+        int index = -1;
+        if (selectedItems.count() >= 2) {
+            const int currentItemIndex = m_selectionManager->currentItem();
+            index = selectedItems.contains(currentItemIndex)
+                    ? currentItemIndex : selectedItems.toList().first();
+        } else if (selectedItems.count() == 1) {
+            index = selectedItems.toList().first();
+        }
+
+        if (index >= 0) {
+            const QRectF contextRect = m_view->itemContextRect(index);
+            const QPointF pos(m_view->scene()->views().first()->mapToGlobal(contextRect.bottomRight().toPoint()));
+            emit itemContextMenuRequested(index, pos);
+        } else {
+            emit viewContextMenuRequested(QCursor::pos());
+        }
+        break;
+    }
 
     default:
         m_keyboardManager->addKeys(event->text());
index c4c1e31676e304b06d067ce31c240b70712fefe6..d1786273ccae90bd8ab1290cebd38bdeb7d49875 100644 (file)
@@ -437,6 +437,19 @@ QRectF KItemListView::itemRect(int index) const
     return m_layouter->itemRect(index);
 }
 
+QRectF KItemListView::itemContextRect(int index) const
+{
+    QRectF contextRect;
+
+    const KItemListWidget* widget = m_visibleItems.value(index);
+    if (widget) {
+        contextRect = widget->iconRect() | widget->textRect();
+        contextRect.translate(itemRect(index).topLeft());
+    }
+
+    return contextRect;
+}
+
 void KItemListView::scrollToItem(int index)
 {
     const QRectF viewGeometry = geometry();
index 1da0cd7d22bfdfdd813b5be99efbaf61b74c36f8..e44d557b930d72dd178dddb6c14fc97934350804 100644 (file)
@@ -184,6 +184,18 @@ public:
      */
     QRectF itemRect(int index) const;
 
+    /**
+     * @return The context rectangle of the item relative to the top/left of
+     *         the currently visible area (see KItemListView::offset()). The
+     *         context rectangle is defined by by the united rectangle of
+     *         the icon rectangle and the text rectangle (see KItemListWidget::iconRect()
+     *         and KItemListWidget::textRect()) and is useful as reference for e.g. aligning
+     *         a tooltip or a context-menu for an item. Note that a context rectangle will
+     *         only be returned for (at least partly) visible items. An empty rectangle will
+     *         be returned for fully invisible items.
+     */
+    QRectF itemContextRect(int index) const;
+
     /**
      * Scrolls to the item with the index \a index so that the item
      * will be fully visible.
index d839c61a3b73abae2e331d792f08bda57f35bd5d..8730746534d5e5ad157110b99078222c1a18d105 100644 (file)
@@ -802,7 +802,7 @@ void DolphinView::slotItemHovered(int index)
     const KFileItem item = fileItemModel()->fileItem(index);
 
     if (GeneralSettings::showToolTips()) {
-        QRectF itemRect = m_container->controller()->view()->itemRect(index);
+        QRectF itemRect = m_container->controller()->view()->itemContextRect(index);
         const QPoint pos = m_container->mapToGlobal(itemRect.topLeft().toPoint());
         itemRect.moveTo(pos);