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 &&
*/
KItemListWidget* widgetForPos(const QPointF& pos) const;
+ /**
+ * @return Widget that should receive a drop event if an item is dropped at \a pos. 0 is returned
+ * if no widget should receive a drop event at the position.
+ *
+ * While widgetForPos() returns a widget if \a pos is anywhere inside the hover highlight area of the widget,
+ * widgetForDropPos() only returns a widget if \a pos is directly above the widget (widget->contains(pos) == true).
+ */
+ KItemListWidget* widgetForDropPos(const QPointF& pos) const;
+
/**
* Updates m_keyboardAnchorIndex and m_keyboardAnchorPos. If no anchor is
* set, it will be adjusted to the current item. If it is set it will be