diff options
| author | Peter Penz <[email protected]> | 2011-12-07 23:04:09 +0100 |
|---|---|---|
| committer | Peter Penz <[email protected]> | 2011-12-07 23:10:00 +0100 |
| commit | b358e9928049575cf3118f3950caf52bfa003404 (patch) | |
| tree | dca93a2c2d8c55c20b7beae93000756ad765dd43 /src/kitemviews/kitemlistcontroller.cpp | |
| parent | 5a3e79e4ed7167e2bffb19b2a37db5184a643eee (diff) | |
Enable "menu key" functionality
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
Diffstat (limited to 'src/kitemviews/kitemlistcontroller.cpp')
| -rw-r--r-- | src/kitemviews/kitemlistcontroller.cpp | 32 |
1 files changed, 29 insertions, 3 deletions
diff --git a/src/kitemviews/kitemlistcontroller.cpp b/src/kitemviews/kitemlistcontroller.cpp index e77de292a..90127aa17 100644 --- a/src/kitemviews/kitemlistcontroller.cpp +++ b/src/kitemviews/kitemlistcontroller.cpp @@ -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()); |
