#include <QApplication>
#include <QDrag>
#include <QEvent>
+#include <QGraphicsScene>
#include <QGraphicsSceneEvent>
+#include <QGraphicsView>
#include <QMimeData>
#include <QTimer>
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.
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());
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();
*/
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.
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);