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
This commit is contained in:
Peter Penz 2011-12-07 23:04:09 +01:00
parent 5a3e79e4ed
commit b358e99280
4 changed files with 55 additions and 4 deletions

View 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());

View 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();

View 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.

View 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);