KItemListWidget* oldHoveredWidget = hoveredWidget();
const QPointF pos = transform.map(event->pos());
- KItemListWidget* newHoveredWidget = widgetForPos(pos);
+ KItemListWidget* newHoveredWidget = widgetForDropPos(pos);
if (oldHoveredWidget != newHoveredWidget) {
m_autoActivationTimer->stop();
Q_EMIT aboveItemDropEvent(dropAboveIndex, event);
} else if (!event->mimeData()->hasFormat(m_model->blacklistItemDropEventMimeType())) {
// Something has been dropped on an item or on an empty part of the view.
- Q_EMIT itemDropEvent(m_view->itemAt(pos).value_or(-1), event);
+ const KItemListWidget *receivingWidget = widgetForDropPos(pos);
+ if (receivingWidget) {
+ Q_EMIT itemDropEvent(receivingWidget->index(), event);
+ } else {
+ Q_EMIT itemDropEvent(-1, event);
+ }
}
QAccessibleEvent accessibilityEvent(view(), QAccessible::DragDropEnd);
return nullptr;
}
+KItemListWidget* KItemListController::widgetForDropPos(const QPointF& pos) const
+{
+ Q_ASSERT(m_view);
+
+ const auto widgets = m_view->visibleItemListWidgets();
+ for (KItemListWidget* widget : widgets) {
+ const QPointF mappedPos = widget->mapFromItem(m_view, pos);
+ if (widget->contains(mappedPos)) {
+ return widget;
+ }
+ }
+
+ return nullptr;
+}
+
void KItemListController::updateKeyboardAnchor()
{
const bool validAnchor = m_keyboardAnchorIndex >= 0 &&
const bool shiftPressed = modifiers & Qt::ShiftModifier;
const bool controlPressed = modifiers & Qt::ControlModifier;
+ const bool leftClick = buttons & Qt::LeftButton;
const bool rightClick = buttons & Qt::RightButton;
// The previous selection is cleared if either
}
if (m_pressedIndex.has_value()) {
+ // The hover highlight area of an item is being pressed.
m_selectionManager->setCurrentItem(m_pressedIndex.value());
const auto row = m_view->m_visibleItems.value(m_pressedIndex.value()); // anything outside of row.contains() will be the empty region of the row rect
const bool hitTargetIsRowEmptyRegion = !row->contains(row->mapFromItem(m_view, pos));
bool createRubberBand = (hitTargetIsRowEmptyRegion && m_selectionManager->selectedItems().isEmpty());
if (rightClick && hitTargetIsRowEmptyRegion) {
- // we got a right click outside the text rect, default to action on the current url and not the pressed item
- Q_EMIT itemContextMenuRequested(m_pressedIndex.value(), screenPos);
+ // We have a right click outside the icon and text rect but within the hover highlight area
+ // but it is unclear if this means that a selection rectangle for an item was clicked or the background of the view.
+ if (m_selectionManager->selectedItems().contains(m_pressedIndex.value())) {
+ // The selection rectangle for an item was clicked
+ Q_EMIT itemContextMenuRequested(m_pressedIndex.value(), screenPos);
+ } else {
+ row->setHovered(false); // Removes the hover highlight so the context menu doesn't look like it applies to the row.
+ Q_EMIT viewContextMenuRequested(screenPos);
+ }
return true;
}
break;
case MultiSelection:
- if (controlPressed && !shiftPressed) {
- // A mouse button press is happening on an item while control is pressed. This either means a user wants to:
+ if (controlPressed && !shiftPressed && leftClick) {
+ // A left mouse button press is happening on an item while control is pressed. This either means a user wants to:
// - toggle the selection of item(s) or
// - they want to begin a drag on the item(s) to copy them.
// We rule out the latter, if the item is not clicked directly and was unselected previously.